Class: OvirtSDK4::NetworksService

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

Instance Method Summary (collapse)

Instance Method Details

- (Network) add(network, opts = {})

Adds a new network.

Parameters:

Returns:



13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
# File 'lib/ovirtsdk4/services.rb', line 13095

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

- (Array<Network>) 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.

  • :max (Integer)

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

  • :search (String)

    A query string used to restrict the returned networks.

Returns:



13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
# File 'lib/ovirtsdk4/services.rb', line 13136

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

- (NetworkService) network_service(id)

Locates the network service.

Parameters:

  • id (String)

    The identifier of the network.

Returns:



13174
13175
13176
# File 'lib/ovirtsdk4/services.rb', line 13174

def network_service(id)
  return NetworkService.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.



13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
# File 'lib/ovirtsdk4/services.rb', line 13185

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


13201
13202
13203
# File 'lib/ovirtsdk4/services.rb', line 13201

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