Class: OvirtSDK4::HostsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Host) add(host, opts = {})

Creates a new host and adds it to the database. The host is created based on the properties of the host parameter. The name, address rootPassword properties are required.

Parameters:

Returns:



10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
# File 'lib/ovirtsdk4/services.rb', line 10115

def add(host, opts = {})
  if host.is_a?(Hash)
    host = OvirtSDK4::Host.new(host)
  end
  request = Request.new(:method => :POST, :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 201, 202
    begin
      reader = XmlReader.new(response.body)
      return HostReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (HostService) host_service(id)

Locates the host service.

Parameters:

  • id (String)

    The identifier of the host.

Returns:



10201
10202
10203
# File 'lib/ovirtsdk4/services.rb', line 10201

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

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

Returns the representation of the object managed by this service.

Parameters:

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

    Additional options.

Options Hash (opts):

  • :case_sensitive (Boolean)

    Indicates if the search performed using the search parameter should be performed taking case into account. The default value is true, which means that case is taken into account. If you want to search ignoring case set it to false.

  • :filter (Boolean)

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

  • :max (Integer)

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

  • :search (String)

    A query string used to restrict the returned hosts.

Returns:



10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
# File 'lib/ovirtsdk4/services.rb', line 10158

def list(opts = {})
  query = {}
  value = opts[:case_sensitive]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['case_sensitive'] = value
  end
  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
  value = opts[:search]
  unless value.nil?
    query['search'] = 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_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.



10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
# File 'lib/ovirtsdk4/services.rb', line 10212

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


10228
10229
10230
# File 'lib/ovirtsdk4/services.rb', line 10228

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