class JunosSpace::Platform::Job
Public Instance Methods
info(job)
click to toggle source
info(job)
Returns information about the job 'job'. This information is returned in a Hash with the job ID, name, percentage complete, status, job type, summary, user who issued the job, and the time the job was started.
# File lib/junos-space-api/platform/job.rb, line 58 def info(job) result = {} begin res = RestClient.get("#{JunosSpace.base_uri}#{@@job_uri}/#{job}") doc = Nokogiri::XML::Document.parse(res) doc.xpath('//job').each do |job| result["id"] = job.xpath('id').text result["name"] = job.xpath('name').text result["percent"] = job.xpath('percent').text result["status"] = job.xpath('status').text result["job-type"] = job.xpath('jobType').text result["summary"] = job.xpath('summary').text result["time"] = job.xpath('scheduledStartTime').text result["user"] = job.xpath('user').text end return result rescue RestClient::Unauthorized result['status'] = '401 Error - Auth failure (bad username/password).' return result rescue RestClient::ResourceNotFound result['status'] = "404 Error - No job found with ID: #{job}." return result end end
list(status = '')
click to toggle source
list(status)
Returns a Hash of all of the jobs in Space with the status 'status'. Where 'status' can be one of: 'success', 'failure', 'inprogress', or 'cancelled'. If no status is given, then all of the jobs are returned. The name of the job is the key, and the ID is the value.
# File lib/junos-space-api/platform/job.rb, line 17 def list(status = '') result = {} begin res = RestClient.get("#{JunosSpace.base_uri}#{@@job_uri}") doc = Nokogiri::XML::Document.parse(res) if status doc.xpath("//job[contains(translate(status, '#{@@ucase}', '#{@@dcase}'), translate('#{status}', '#{@@ucase}', '#{@@dcase}'))]").each do |job| name = job.xpath('name').text id = job.xpath('@key').text result[name] = id end if result.size == 0 result['status'] = "No jobs found with status: #{status.downcase}." end else doc.xpath("//job").each do |job| name = job.xpath('name').text id = job.xpath('@key').text result[name] = id end end return result rescue RestClient::Unauthorized result['status'] = '401 Error - Auth failure (bad username/password).' return result end end