Class: IbmPowerHmc::HmcJob
- Inherits:
-
Object
- Object
- IbmPowerHmc::HmcJob
- Defined in:
- lib/ibm_power_hmc/apis/job.rb
Overview
HMC Job for long running operations.
Defined Under Namespace
Classes: JobFailed, JobNotStarted
Instance Attribute Summary collapse
-
#last_status ⇒ Hash
readonly
The job results returned by the HMC.
-
#results ⇒ Hash
readonly
The job results returned by the HMC.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete the job from the HMC.
-
#initialize(conn, method_url, operation, group, params = {}) ⇒ HmcJob
constructor
Construct a new HMC Job.
-
#run(timeout = 120, poll_interval = 0) ⇒ String
Run the job synchronously.
-
#start ⇒ String
Start the job asynchronously.
-
#status ⇒ String
Return the status of the job.
-
#wait(timeout = 120, poll_interval = 0) ⇒ String
Wait for the job to complete.
Constructor Details
#initialize(conn, method_url, operation, group, params = {}) ⇒ HmcJob
Construct a new HMC Job.
31 32 33 34 35 36 37 |
# File 'lib/ibm_power_hmc/apis/job.rb', line 31 def initialize(conn, method_url, operation, group, params = {}) @conn = conn @method_url = method_url @operation = operation @group = group @params = params end |
Instance Attribute Details
#last_status ⇒ Hash (readonly)
Returns The job results returned by the HMC.
55 56 57 |
# File 'lib/ibm_power_hmc/apis/job.rb', line 55 def last_status @last_status end |
#results ⇒ Hash (readonly)
Returns The job results returned by the HMC.
55 56 57 |
# File 'lib/ibm_power_hmc/apis/job.rb', line 55 def results @results end |
Instance Method Details
#delete ⇒ Object
Delete the job from the HMC.
110 111 112 113 114 115 |
# File 'lib/ibm_power_hmc/apis/job.rb', line 110 def delete raise JobNotStarted unless defined?(@href) @conn.request(:delete, @href) # Returns HTTP 204 if ok end |
#run(timeout = 120, poll_interval = 0) ⇒ String
Run the job synchronously.
99 100 101 102 103 104 105 |
# File 'lib/ibm_power_hmc/apis/job.rb', line 99 def run(timeout = 120, poll_interval = 0) start wait(timeout, poll_interval) raise JobFailed.new(@last_status), "Job failed" unless @last_status.status.eql?("COMPLETED_OK") ensure delete if defined?(@href) end |
#start ⇒ String
Start the job asynchronously.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ibm_power_hmc/apis/job.rb', line 43 def start headers = { :content_type => "application/vnd.ibm.powervm.web+xml; type=JobRequest" } jobreq = JobRequest.marshal({:operation => @operation, :group => @group, :params => @params}, WEB_XMLNS) response = @conn.request(:put, @method_url, headers, jobreq.xml.to_s) jobresp = Parser.new(response.body).object(:JobResponse) # Save the URL of the job (JobID is not sufficient as not all jobs are in uom). @href = jobresp.href.path end |
#status ⇒ String
Return the status of the job.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ibm_power_hmc/apis/job.rb', line 61 def status raise JobNotStarted unless defined?(@href) headers = { :content_type => "application/vnd.ibm.powervm.web+xml; type=JobRequest" } response = @conn.request(:get, @href, headers) @last_status = Parser.new(response.body).object(:JobResponse) @results = @last_status.results @last_status.status end |
#wait(timeout = 120, poll_interval = 0) ⇒ String
Wait for the job to complete.
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ibm_power_hmc/apis/job.rb', line 79 def wait(timeout = 120, poll_interval = 0) endtime = Time.now.utc + timeout auto = poll_interval == 0 poll_interval = 1 if auto while Time.now.utc < endtime status = self.status return status if status != "RUNNING" && status != "NOT_STARTED" poll_interval *= 2 if auto && poll_interval < 30 sleep(poll_interval) end "TIMEDOUT" end |