Class: OvirtSDK4::AffinityGroupVmsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Vm) add(vm, opts = {})

Adds a new vm.

Parameters:

Returns:



943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
# File 'lib/ovirtsdk4/services.rb', line 943

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

- (Array<Vm>) 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 virtual machines to return. If not specified all the virtual machines are returned.

Returns:

  • (Array<Vm>)


979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
# File 'lib/ovirtsdk4/services.rb', line 979

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 VmReader.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.



1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
# File 'lib/ovirtsdk4/services.rb', line 1019

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


1035
1036
1037
# File 'lib/ovirtsdk4/services.rb', line 1035

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

- (AffinityGroupVmService) vm_service(id)

Locates the vm service.

Parameters:

  • id (String)

    The identifier of the vm.

Returns:



1008
1009
1010
# File 'lib/ovirtsdk4/services.rb', line 1008

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