Class: OvirtSDK4::SchedulingPoliciesService

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

Instance Method Summary (collapse)

Instance Method Details

- (SchedulingPolicy) add(policy, opts = {})

Adds a new policy.

Parameters:

Returns:



16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
# File 'lib/ovirtsdk4/services.rb', line 16755

def add(policy, opts = {})
  if policy.is_a?(Hash)
    policy = OvirtSDK4::SchedulingPolicy.new(policy)
  end
  request = Request.new(:method => :POST, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    SchedulingPolicyWriter.write_one(policy, writer, 'policy')
    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 SchedulingPolicyReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

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

Returns the representation of the object managed by this service.

Parameters:

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

    Additional options.

Options Hash (opts):

  • :filter (Boolean)

    Indicates if the results should be filtered according to the permissions of the user.

  • :max (Integer)

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

Returns:



16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
# File 'lib/ovirtsdk4/services.rb', line 16792

def list(opts = {})
  query = {}
  value = opts[:filter]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['filter'] = value
  end
  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 SchedulingPolicyReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (SchedulingPolicyService) policy_service(id)

Locates the policy service.

Parameters:

  • id (String)

    The identifier of the policy.

Returns:



16826
16827
16828
# File 'lib/ovirtsdk4/services.rb', line 16826

def policy_service(id)
  return SchedulingPolicyService.new(@connection, "#{@path}/#{id}")
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.



16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
# File 'lib/ovirtsdk4/services.rb', line 16837

def service(path)
  if path.nil? || path == ''
    return self
  end
  index = path.index('/')
  if index.nil?
    return policy_service(path)
  end
  return policy_service(path[0..(index - 1)]).service(path[(index +1)..-1])
end

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


16853
16854
16855
# File 'lib/ovirtsdk4/services.rb', line 16853

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