class OvirtSDK4::JobsService

Public Class Methods

new(connection, path) click to toggle source

Creates a new implementation of the service.

@param connection [Connection] The connection to be used by this service.

@param path [String] The relative path of this service, for example `vms/123/disks`.

@api private

# File lib/ovirtsdk4/services.rb, line 14146
def initialize(connection, path)
  @connection = connection
  @path = path
end

Public Instance Methods

add(job, opts = {}) click to toggle source

Add an external job.

For example, to add a job with the following request:

source

POST /ovirt-engine/api/jobs


With the following request body:

source,xml

<job>

<description>Doing some work</description>
<auto_cleared>true</auto_cleared>

</job>


The response should look like:

source,xml

<job href=“/ovirt-engine/api/jobs/123” id=“123”>

<actions>
  <link href="/ovirt-engine/api/jobs/123/clear" rel="clear"/>
  <link href="/ovirt-engine/api/jobs/123/end" rel="end"/>
</actions>
<description>Doing some work</description>
<link href="/ovirt-engine/api/jobs/123/steps" rel="steps"/>
<auto_cleared>true</auto_cleared>
<external>true</external>
<last_updated>2016-12-13T02:15:42.130+02:00</last_updated>
<start_time>2016-12-13T02:15:42.130+02:00</start_time>
<status>started</status>
<owner href="/ovirt-engine/api/users/456" id="456"/>

</job>


@param job [Job] Job that will be added.

@param opts [Hash] Additional options.

@return [Job]

# File lib/ovirtsdk4/services.rb, line 14197
def add(job, opts = {})
  if job.is_a?(Hash)
    job = OvirtSDK4::Job.new(job)
  end
  query = {}
  request = HttpRequest.new(method: :POST, url: @path, query: query)
  begin
    writer = XmlWriter.new(nil, true)
    JobWriter.write_one(job, writer)
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 200, 201, 202
    begin
      reader = XmlReader.new(response.body)
      return JobReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
job_service(id) click to toggle source

Reference to the job service.

@param id [String] The identifier of the `job`.

@return [JobService] A reference to the `job` service.

# File lib/ovirtsdk4/services.rb, line 14291
def job_service(id)
  JobService.new(@connection, "#{@path}/#{id}")
end
list(opts = {}) click to toggle source

Retrieves the representation of the jobs.

source

GET /ovirt-engine/api/jobs


You will receive response in XML like this one:

source,xml

<jobs>

<job href="/ovirt-engine/api/jobs/123" id="123">
  <actions>
    <link href="/ovirt-engine/api/jobs/123/clear" rel="clear"/>
    <link href="/ovirt-engine/api/jobs/123/end" rel="end"/>
  </actions>
  <description>Adding Disk</description>
  <link href="/ovirt-engine/api/jobs/123/steps" rel="steps"/>
  <auto_cleared>true</auto_cleared>
  <end_time>2016-12-12T23:07:29.758+02:00</end_time>
  <external>false</external>
  <last_updated>2016-12-12T23:07:29.758+02:00</last_updated>
  <start_time>2016-12-12T23:07:26.593+02:00</start_time>
  <status>failed</status>
  <owner href="/ovirt-engine/api/users/456" id="456"/>
</job>
...

</jobs>


@param opts [Hash] Additional options.

@option opts [Integer] :max Sets the maximum number of jobs to return. If not specified all the jobs are returned.

@return [Array<Job>]

# File lib/ovirtsdk4/services.rb, line 14262
def list(opts = {})
  query = {}
  value = opts[:max]
  unless value.nil?
    value = Writer.render_integer(value)
    query['max'] = value
  end
  request = HttpRequest.new(method: :GET, url: @path, query: query)
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return JobReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
service(path) click to toggle source

Locates the service corresponding to the given path.

@param path [String] The path of the service.

@return [Service] A reference to the service.

# File lib/ovirtsdk4/services.rb, line 14302
def service(path)
  if path.nil? || path == ''
    return self
  end
  index = path.index('/')
  if index.nil?
    return job_service(path)
  end
  return job_service(path[0..(index - 1)]).service(path[(index +1)..-1])
end
to_s() click to toggle source

Returns an string representation of this service.

@return [String]

# File lib/ovirtsdk4/services.rb, line 14318
def to_s
  "#<#{JobsService}:#{@path}>"
end