Class: OvirtSDK4::JobsService

Inherits:
Service
  • Object
show all
Defined in:
lib/ovirtsdk4/services.rb,
lib/ovirtsdk4/services.rb

Instance Method Summary (collapse)

Instance Method Details

- (Job) add(job, opts = {})

Adds a new job.

Parameters:

Returns:



11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
# File 'lib/ovirtsdk4/services.rb', line 11723

def add(job, opts = {})
  if job.is_a?(Hash)
    job = OvirtSDK4::Job.new(job)
  end
  request = Request.new(:method => :POST, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    JobWriter.write_one(job, writer, 'job')
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 201, 202
    begin
      reader = XmlReader.new(response.body)
      return JobReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (JobService) job_service(id)

Locates the job service.

Parameters:

  • id (String)

    The identifier of the job.

Returns:

  • (JobService)

    A reference to the job service.



11787
11788
11789
# File 'lib/ovirtsdk4/services.rb', line 11787

def job_service(id)
  return JobService.new(@connection, "#{@path}/#{id}")
end

- (Array<Job>) list(opts = {})

Returns the representation of the object managed by this service.

Parameters:

  • opts (Hash) (defaults to: {})

    Additional options.

Options Hash (opts):

  • :max (Integer)

    Sets the maximum number of jobs to return. If not specified all the jobs are returned.

Returns:



11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
# File 'lib/ovirtsdk4/services.rb', line 11758

def list(opts = {})
  query = {}
  value = opts[:max]
  unless value.nil?
    value = Writer.render_integer(value)
    query['max'] = value
  end
  request = Request.new(:method => :GET, :path => @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) service(path)

Locates the service corresponding to the given path.

Parameters:

  • path (String)

    The path of the service.

Returns:

  • (Service)

    A reference to the service.



11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
# File 'lib/ovirtsdk4/services.rb', line 11798

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


11814
11815
11816
# File 'lib/ovirtsdk4/services.rb', line 11814

def to_s
  return "#<#{JobsService}:#{@path}>"
end