Class: JunosSpace::Platform::Job
- Inherits:
-
Object
- Object
- JunosSpace::Platform::Job
- Defined in:
- lib/junos-space-api/platform/job.rb
Constant Summary collapse
- @@job_uri =
'/api/space/job-management/jobs'
- @@ucase =
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- @@dcase =
'abcdefghijklmnopqrstuvwxyz'
Instance Method Summary collapse
-
#info(job) ⇒ Object
info(job).
-
#list(status) ⇒ Object
list(status).
Instance Method Details
#info(job) ⇒ Object
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.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# 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:: 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) ⇒ Object
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.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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:: result['status'] = '401 Error - Auth failure (bad username/password).' return result end end |