Class: OvirtSDK4::SshPublicKeysService

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

Instance Method Summary (collapse)

Instance Method Details

- (SshPublicKey) add(key, opts = {})

Adds a new key.

Parameters:

Returns:



18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
# File 'lib/ovirtsdk4/services.rb', line 18077

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

- (SshPublicKeyService) key_service(id)

Locates the key service.

Parameters:

  • id (String)

    The identifier of the key.

Returns:



18141
18142
18143
# File 'lib/ovirtsdk4/services.rb', line 18141

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

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

Returns:



18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
# File 'lib/ovirtsdk4/services.rb', line 18112

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



18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
# File 'lib/ovirtsdk4/services.rb', line 18152

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


18168
18169
18170
# File 'lib/ovirtsdk4/services.rb', line 18168

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