class OvirtSDK4::HostService

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 28155
def initialize(connection, path)
  @connection = connection
  @path = path
end

Public Instance Methods

activate(opts = {}) click to toggle source

Executes the `activate` method.

# File lib/ovirtsdk4/services.rb, line 28163
def activate(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/activate",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
affinity_labels_service() click to toggle source

List of scheduling labels assigned to this host.

@return [AssignedAffinityLabelsService] A reference to `affinity_labels` service.

# File lib/ovirtsdk4/services.rb, line 28701
def affinity_labels_service
  return AssignedAffinityLabelsService.new(@connection, "#{@path}/affinitylabels")
end
approve(opts = {}) click to toggle source

Executes the `approve` method.

# File lib/ovirtsdk4/services.rb, line 28186
def approve(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/approve",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
commit_net_config(opts = {}) click to toggle source

Executes the `commit_net_config` method.

# File lib/ovirtsdk4/services.rb, line 28209
def commit_net_config(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/commitnetconfig",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
deactivate(opts = {}) click to toggle source

Executes the `deactivate` method.

# File lib/ovirtsdk4/services.rb, line 28232
def deactivate(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/deactivate",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
devices_service() click to toggle source

Locates the `devices` service.

@return [HostDevicesService] A reference to `devices` service.

# File lib/ovirtsdk4/services.rb, line 28709
def devices_service
  return HostDevicesService.new(@connection, "#{@path}/devices")
end
enroll_certificate(opts = {}) click to toggle source

Executes the `enroll_certificate` method.

# File lib/ovirtsdk4/services.rb, line 28255
def enroll_certificate(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/enrollcertificate",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
fence(opts = {}) click to toggle source

Executes the `fence` method.

# File lib/ovirtsdk4/services.rb, line 28278
def fence(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/fence",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
    return action.power_management
  else
    check_fault(response)
  end
end
fence_agents_service() click to toggle source

Locates the `fence_agents` service.

@return [FenceAgentsService] A reference to `fence_agents` service.

# File lib/ovirtsdk4/services.rb, line 28717
def fence_agents_service
  return FenceAgentsService.new(@connection, "#{@path}/fenceagents")
end
force_select_spm(opts = {}) click to toggle source

Executes the `force_select_spm` method.

# File lib/ovirtsdk4/services.rb, line 28302
def force_select_spm(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/forceselectspm",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
get(opts = {}) click to toggle source

Returns the representation of the object managed by this service.

@param opts [Hash] Additional options.

@option opts [Boolean] :filter Indicates if the results should be filtered according to the permissions of the user.

@return [Host]

# File lib/ovirtsdk4/services.rb, line 28331
def get(opts = {})
  query = {}
  value = opts[:filter]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['filter'] = 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 HostReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
hooks_service() click to toggle source

Locates the `hooks` service.

@return [HostHooksService] A reference to `hooks` service.

# File lib/ovirtsdk4/services.rb, line 28725
def hooks_service
  return HostHooksService.new(@connection, "#{@path}/hooks")
end
install(opts = {}) click to toggle source

Executes the `install` method.

# File lib/ovirtsdk4/services.rb, line 28356
def install(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/install",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
iscsi_discover(opts = {}) click to toggle source

Executes the `iscsi_discover` method.

# File lib/ovirtsdk4/services.rb, line 28379
def iscsi_discover(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/iscsidiscover",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
    return action.iscsi_targets
  else
    check_fault(response)
  end
end
iscsi_login(opts = {}) click to toggle source

Executes the `iscsi_login` method.

# File lib/ovirtsdk4/services.rb, line 28403
def iscsi_login(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/iscsilogin",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
katello_errata_service() click to toggle source

Locates the `katello_errata` service.

@return [KatelloErrataService] A reference to `katello_errata` service.

# File lib/ovirtsdk4/services.rb, line 28733
def katello_errata_service
  return KatelloErrataService.new(@connection, "#{@path}/katelloerrata")
end
network_attachments_service() click to toggle source

Locates the `network_attachments` service.

@return [NetworkAttachmentsService] A reference to `network_attachments` service.

# File lib/ovirtsdk4/services.rb, line 28741
def network_attachments_service
  return NetworkAttachmentsService.new(@connection, "#{@path}/networkattachments")
end
nics_service() click to toggle source

Locates the `nics` service.

@return [HostNicsService] A reference to `nics` service.

# File lib/ovirtsdk4/services.rb, line 28749
def nics_service
  return HostNicsService.new(@connection, "#{@path}/nics")
end
numa_nodes_service() click to toggle source

Locates the `numa_nodes` service.

@return [HostNumaNodesService] A reference to `numa_nodes` service.

# File lib/ovirtsdk4/services.rb, line 28757
def numa_nodes_service
  return HostNumaNodesService.new(@connection, "#{@path}/numanodes")
end
permissions_service() click to toggle source

Locates the `permissions` service.

@return [AssignedPermissionsService] A reference to `permissions` service.

# File lib/ovirtsdk4/services.rb, line 28765
def permissions_service
  return AssignedPermissionsService.new(@connection, "#{@path}/permissions")
end
refresh(opts = {}) click to toggle source

Executes the `refresh` method.

# File lib/ovirtsdk4/services.rb, line 28426
def refresh(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/refresh",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
remove(opts = {}) click to toggle source

Deletes the object managed by this service.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the remove should be performed asynchronously.

# File lib/ovirtsdk4/services.rb, line 28453
def remove(opts = {})
  query = {}
  value = opts[:async]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['async'] = value
  end
  request = Request.new(:method => :DELETE, :path => @path, :query => query)
  response = @connection.send(request)
  unless response.code == 200
    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 28816
def service(path)
  if path.nil? || path == ''
    return self
  end
  if path == 'affinitylabels'
    return affinity_labels_service
  end
  if path.start_with?('affinitylabels/')
    return affinity_labels_service.service(path[15..-1])
  end
  if path == 'devices'
    return devices_service
  end
  if path.start_with?('devices/')
    return devices_service.service(path[8..-1])
  end
  if path == 'fenceagents'
    return fence_agents_service
  end
  if path.start_with?('fenceagents/')
    return fence_agents_service.service(path[12..-1])
  end
  if path == 'hooks'
    return hooks_service
  end
  if path.start_with?('hooks/')
    return hooks_service.service(path[6..-1])
  end
  if path == 'katelloerrata'
    return katello_errata_service
  end
  if path.start_with?('katelloerrata/')
    return katello_errata_service.service(path[14..-1])
  end
  if path == 'networkattachments'
    return network_attachments_service
  end
  if path.start_with?('networkattachments/')
    return network_attachments_service.service(path[19..-1])
  end
  if path == 'nics'
    return nics_service
  end
  if path.start_with?('nics/')
    return nics_service.service(path[5..-1])
  end
  if path == 'numanodes'
    return numa_nodes_service
  end
  if path.start_with?('numanodes/')
    return numa_nodes_service.service(path[10..-1])
  end
  if path == 'permissions'
    return permissions_service
  end
  if path.start_with?('permissions/')
    return permissions_service.service(path[12..-1])
  end
  if path == 'statistics'
    return statistics_service
  end
  if path.start_with?('statistics/')
    return statistics_service.service(path[11..-1])
  end
  if path == 'storage'
    return storage_service
  end
  if path.start_with?('storage/')
    return storage_service.service(path[8..-1])
  end
  if path == 'storageconnectionextensions'
    return storage_connection_extensions_service
  end
  if path.start_with?('storageconnectionextensions/')
    return storage_connection_extensions_service.service(path[28..-1])
  end
  if path == 'tags'
    return tags_service
  end
  if path.start_with?('tags/')
    return tags_service.service(path[5..-1])
  end
  if path == 'unmanagednetworks'
    return unmanaged_networks_service
  end
  if path.start_with?('unmanagednetworks/')
    return unmanaged_networks_service.service(path[18..-1])
  end
  raise Error.new("The path \"#{path}\" doesn't correspond to any service")
end
setup_networks(opts = {}) click to toggle source

This method is used to change the configuration of the network interfaces of a host.

For example, lets assume that you have a host with three network interfaces `eth0`, `eth1` and `eth2` and that you want to configure a new bond using `eth0` and `eth1`, and put a VLAN on top of it. Using a simple shell script and the `curl` command line HTTP client that can be done as follows:

source

#!/bin/sh -ex

url=“engine.example.com/ovirt-engine/api” user=“admin@internal” password=“…”

curl \ –verbose \ –cacert /etc/pki/ovirt-engine/ca.pem \ –user “${user}:${password}” \ –request POST \ –header “Content-Type: application/xml” \ –header “Accept: application/xml” \ –data ' <action>

 <modified_bonds>
   <host_nic>
     <name>bond0</name>
     <bonding>
       <options>
         <option>
           <name>mode</name>
           <value>4</value>
         </option>
         <option>
           <name>miimon</name>
           <value>100</value>
         </option>
       </options>
       <slaves>
         <host_nic>
           <name>eth1</name>
         </host_nic>
         <host_nic>
           <name>eth2</name>
         </host_nic>
       </slaves>
     </bonding>
   </host_nic>
 </modified_bonds>
 <modified_network_attachments>
   <network_attachment>
     <network>
       <name>myvlan</name>
     </network>
     <host_nic>
       <name>bond0</name>
     </host_nic>
     <ip_address_assignments>
       <assignment_method>static</assignment_method>
       <ip_address_assignment>
         <ip>
           <address>192.168.122.10</address>
           <netmask>255.255.255.0</netmask>
         </ip>
       </ip_address_assignment>
     </ip_address_assignments>
   </network_attachment>
 </modified_network_attachments>
</action>

' \ “${url}/hosts/1ff7a191-2f3b-4eff-812b-9f91a30c3acc/setupnetworks”


Note that this is valid for version 4 of the API. In previous versions some elements were represented as XML attributes instead of XML elements. In particular the `options` and `ip` elements were represented as follows:

source,xml

<options name=“mode” value=“4”/> <options name=“miimon” value=“100”/> <ip address=“192.168.122.10” netmask=“255.255.255.0”/>


Using the Python SDK the same can be done with the following code:

source,python

host.setupnetworks(

params.Action(
  modified_bonds=params.HostNics(
    host_nic=[
      params.HostNIC(
        name="bond0",
        bonding=params.Bonding(
          options=params.Options(
            option=[
              params.Option(name="mode", value="4"),
              params.Option(name="miimon", value="100"),
            ],
          ),
          slaves=params.Slaves(
            host_nic=[
              params.HostNIC(name="eth1"),
              params.HostNIC(name="eth2"),
            ],
          ),
        ),
      ),
    ],
  ),
  modified_network_attachments=params.NetworkAttachments(
    network_attachment=[
      params.NetworkAttachment(
        network=params.Network(name="myvlan"),
        host_nic=params.HostNIC(name="bond0"),
        ip_address_assignments=params.IpAddressAssignments(
          ip_address_assignment=[
            params.IpAddressAssignment(
              assignment_method="static",
              ip=params.IP(
                address="192.168.122.10",
                netmask="255.255.255.0",
              ),
            ),
          ],
        ),
      ),
    ],
  ),
),

)


# File lib/ovirtsdk4/services.rb, line 28600
def setup_networks(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/setupnetworks",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
statistics_service() click to toggle source

Locates the `statistics` service.

@return [StatisticsService] A reference to `statistics` service.

# File lib/ovirtsdk4/services.rb, line 28773
def statistics_service
  return StatisticsService.new(@connection, "#{@path}/statistics")
end
storage_connection_extensions_service() click to toggle source

Locates the `storage_connection_extensions` service.

@return [StorageServerConnectionExtensionsService] A reference to `storage_connection_extensions` service.

# File lib/ovirtsdk4/services.rb, line 28789
def storage_connection_extensions_service
  return StorageServerConnectionExtensionsService.new(@connection, "#{@path}/storageconnectionextensions")
end
storage_service() click to toggle source

Locates the `storage` service.

@return [HostStorageService] A reference to `storage` service.

# File lib/ovirtsdk4/services.rb, line 28781
def storage_service
  return HostStorageService.new(@connection, "#{@path}/storage")
end
tags_service() click to toggle source

Locates the `tags` service.

@return [AssignedTagsService] A reference to `tags` service.

# File lib/ovirtsdk4/services.rb, line 28797
def tags_service
  return AssignedTagsService.new(@connection, "#{@path}/tags")
end
to_s() click to toggle source

Returns an string representation of this service.

@return [String]

# File lib/ovirtsdk4/services.rb, line 28912
def to_s
  return "#<#{HostService}:#{@path}>"
end
unmanaged_networks_service() click to toggle source

Locates the `unmanaged_networks` service.

@return [UnmanagedNetworksService] A reference to `unmanaged_networks` service.

# File lib/ovirtsdk4/services.rb, line 28805
def unmanaged_networks_service
  return UnmanagedNetworksService.new(@connection, "#{@path}/unmanagednetworks")
end
unregistered_storage_domains_discover(opts = {}) click to toggle source

Executes the `unregistered_storage_domains_discover` method.

# File lib/ovirtsdk4/services.rb, line 28623
def unregistered_storage_domains_discover(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/unregisteredstoragedomainsdiscover",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
    return action.storage_domains
  else
    check_fault(response)
  end
end
update(host) click to toggle source

Updates the object managed by this service.

# File lib/ovirtsdk4/services.rb, line 28647
def update(host)
  if host.is_a?(Hash)
    host = OvirtSDK4::Host.new(host)
  end
  request = Request.new(:method => :PUT, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    HostWriter.write_one(host, writer, 'host')
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return HostReader.read_one(reader)
    ensure
      reader.close
    end
    return result
  else
    check_fault(response)
  end
end
upgrade(opts = {}) click to toggle source

Executes the `upgrade` method.

# File lib/ovirtsdk4/services.rb, line 28677
def upgrade(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/upgrade",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end