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 8215 def initialize(connection, path) @connection = connection @path = path end
Executes the `activate` method.
# File lib/ovirtsdk4/services.rb, line 8223 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
Adds given list of bricks to the volume, and updates the database accordingly. The properties `serverId` and `brickDir`are required.
@param bricks [Array<GlusterBrick>]
@return [Array<GlusterBrick>]
# File lib/ovirtsdk4/services.rb, line 8251 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 request = Request.new(:method => :POST, :path => @path) begin writer = XmlWriter.new(nil, true) GlusterBrickWriter.write_many(bricks, writer, 'bricks') 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
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 8393 def brick_service(id) return GlusterBrickService.new(@connection, "#{@path}/#{id}") end
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 8291 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
Executes the `migrate` method.
# File lib/ovirtsdk4/services.rb, line 8316 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
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 8345 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
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 8404 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
Executes the `stop_migrate` method.
# File lib/ovirtsdk4/services.rb, line 8366 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
Returns an string representation of this service.
@return [String]
# File lib/ovirtsdk4/services.rb, line 8420 def to_s return "#<#{GlusterBricksService}:#{@path}>" end