class OvirtSDK4::GlusterBricksService

Public Class Methods

new(connection, path) click to toggle source

Creates a new implementation of the service.

@param connection [Connection] The connection to be used by this service.

@param path [String] The relative path of this service, for example `vms/123/disks`.

@api private

# File lib/ovirtsdk4/services.rb, line 8792
def initialize(connection, path)
  @connection = connection
  @path = path
end

Public Instance Methods

activate(opts = {}) click to toggle source

Executes the `activate` method.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the activation should be performed asynchronously.

@option opts [Array<GlusterBrick>] :bricks

# File lib/ovirtsdk4/services.rb, line 8806
def activate(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/activate",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
add(bricks, opts = {}) click to toggle source

Adds given list of bricks to the volume, and updates the database accordingly. The properties `serverId` and `brickDir`are required.

@param bricks [Array<GlusterBrick>] The list of bricks to be added to the volume

@param opts [Hash] Additional options.

@return [Array<GlusterBrick>]

# File lib/ovirtsdk4/services.rb, line 8836
def add(bricks, opts = {})
  if bricks.is_a?(Array)
    bricks = List.new(bricks)
    bricks.each_with_index do |value, index|
      if value.is_a?(Hash)
        bricks[index] = OvirtSDK4::GlusterBrick.new(value)
      end
    end
  end
  query = {}
  request = Request.new(:method => :POST, :path => @path, :query => query)
  begin
    writer = XmlWriter.new(nil, true)
    GlusterBrickWriter.write_many(bricks, writer)
    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 GlusterBrickReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
brick_service(id) click to toggle source

Locates the `brick` service.

@param id [String] The identifier of the `brick`.

@return [GlusterBrickService] A reference to the `brick` service.

# File lib/ovirtsdk4/services.rb, line 8989
def brick_service(id)
  return GlusterBrickService.new(@connection, "#{@path}/#{id}")
end
list(opts = {}) click to toggle source

Returns the representation of the object managed by this service.

@param opts [Hash] Additional options.

@option opts [Integer] :max Sets the maximum number of bricks to return. If not specified all the bricks are returned.

@return [Array<GlusterBrick>]

# File lib/ovirtsdk4/services.rb, line 8877
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 GlusterBrickReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
migrate(opts = {}) click to toggle source

Executes the `migrate` method.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the migration should be performed asynchronously.

@option opts [Array<GlusterBrick>] :bricks

# File lib/ovirtsdk4/services.rb, line 8908
def migrate(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/migrate",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
remove(opts = {}) click to toggle source

Removes the given list of bricks brick from the volume and deletes them from the database.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the remove should be performed asynchronously. @option opts [Array<GlusterBrick>] :bricks The list of bricks to be removed

# File lib/ovirtsdk4/services.rb, line 8935
def remove(opts = {})
  query = {}
  value = opts[:async]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['async'] = value
  end
  value = opts[:bricks]
  unless value.nil?
    query['bricks'] = value
  end
  request = Request.new(:method => :DELETE, :path => @path, :query => query)
  response = @connection.send(request)
  unless response.code == 200
    check_fault(response)
  end
end
service(path) click to toggle source

Locates the service corresponding to the given path.

@param path [String] The path of the service.

@return [Service] A reference to the service.

# File lib/ovirtsdk4/services.rb, line 9000
def service(path)
  if path.nil? || path == ''
    return self
  end
  index = path.index('/')
  if index.nil?
    return brick_service(path)
  end
  return brick_service(path[0..(index - 1)]).service(path[(index +1)..-1])
end
stop_migrate(opts = {}) click to toggle source

Executes the `stop_migrate` method.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the action should be performed asynchronously.

@option opts [Array<GlusterBrick>] :bricks

# File lib/ovirtsdk4/services.rb, line 8962
def stop_migrate(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/stopmigrate",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
to_s() click to toggle source

Returns an string representation of this service.

@return [String]

# File lib/ovirtsdk4/services.rb, line 9016
def to_s
  return "#<#{GlusterBricksService}:#{@path}>"
end