Class: OvirtSDK4::NetworkAttachmentsService

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

Instance Method Summary (collapse)

Instance Method Details

- (NetworkAttachment) add(attachment, opts = {})

Adds a new attachment.

Parameters:

Returns:



12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
# File 'lib/ovirtsdk4/services.rb', line 12624

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

- (NetworkAttachmentService) attachment_service(id)

Locates the attachment service.

Parameters:

  • id (String)

    The identifier of the attachment.

Returns:



12688
12689
12690
# File 'lib/ovirtsdk4/services.rb', line 12688

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

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

Returns:



12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
# File 'lib/ovirtsdk4/services.rb', line 12659

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



12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
# File 'lib/ovirtsdk4/services.rb', line 12699

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


12715
12716
12717
# File 'lib/ovirtsdk4/services.rb', line 12715

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