Class: OvirtSDK4::AssignedNetworksService

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:



2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
# File 'lib/ovirtsdk4/services.rb', line 2553

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):

  • :max (Integer)

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

Returns:



2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
# File 'lib/ovirtsdk4/services.rb', line 2588

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 NetworkReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (AssignedNetworkService) network_service(id)

Locates the network service.

Parameters:

  • id (String)

    The identifier of the network.

Returns:



2617
2618
2619
# File 'lib/ovirtsdk4/services.rb', line 2617

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



2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
# File 'lib/ovirtsdk4/services.rb', line 2628

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)


2644
2645
2646
# File 'lib/ovirtsdk4/services.rb', line 2644

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