Class: OvirtSDK4::SnapshotsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Snapshot) add(snapshot, opts = {})

Adds a new snapshot.

Parameters:

Returns:



17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
# File 'lib/ovirtsdk4/services.rb', line 17841

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

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

Returns:



17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
# File 'lib/ovirtsdk4/services.rb', line 17876

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



17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
# File 'lib/ovirtsdk4/services.rb', line 17916

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

- (SnapshotService) snapshot_service(id)

Locates the snapshot service.

Parameters:

  • id (String)

    The identifier of the snapshot.

Returns:



17905
17906
17907
# File 'lib/ovirtsdk4/services.rb', line 17905

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


17932
17933
17934
# File 'lib/ovirtsdk4/services.rb', line 17932

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