Class: OvirtSDK4::AffinityLabelVmsService

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 = {})

Add a label to a vm.

Parameters:

Returns:



1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
# File 'lib/ovirtsdk4/services.rb', line 1597

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 = {})

List all vms with the label.

Parameters:

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

    Additional options.

Returns:

  • (Array<Vm>)


1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
# File 'lib/ovirtsdk4/services.rb', line 1630

def list(opts = {})
  query = {}
  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.



1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
# File 'lib/ovirtsdk4/services.rb', line 1666

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)


1682
1683
1684
# File 'lib/ovirtsdk4/services.rb', line 1682

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

- (AffinityLabelVmService) vm_service(id)

A link to the specific label-vm assignment to allow label removal.

Parameters:

  • id (String)

    The identifier of the vm.

Returns:



1655
1656
1657
# File 'lib/ovirtsdk4/services.rb', line 1655

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