Class: OvirtSDK4::OpenstackSubnetsService

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

Instance Method Summary (collapse)

Instance Method Details

- (OpenStackSubnet) add(subnet, opts = {})

Adds a new subnet.

Parameters:

Returns:



14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
# File 'lib/ovirtsdk4/services.rb', line 14302

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

- (Array<OpenStackSubnet>) 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 sub-networks to return. If not specified all the sub-networks are returned.

Returns:



14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
# File 'lib/ovirtsdk4/services.rb', line 14337

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



14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
# File 'lib/ovirtsdk4/services.rb', line 14377

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

- (OpenstackSubnetService) subnet_service(id)

Locates the subnet service.

Parameters:

  • id (String)

    The identifier of the subnet.

Returns:



14366
14367
14368
# File 'lib/ovirtsdk4/services.rb', line 14366

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


14393
14394
14395
# File 'lib/ovirtsdk4/services.rb', line 14393

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