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 19692 def initialize(connection, path) @connection = connection @path = path end
Get the role.
GET /ovirt-engine/api/roles/123
You will receive XML response like this one:
<role id=“123”>
<name>MyRole</name> <description>MyRole description</description> <link href="/ovirt-engine/api/roles/123/permits" rel="permits"/> <administrative>true</administrative> <mutable>false</mutable>
</role>
@param opts [Hash] Additional options.
@return [Role]
# File lib/ovirtsdk4/services.rb, line 19722 def get(opts = {}) query = {} request = HttpRequest.new(method: :GET, url: @path, query: query) response = @connection.send(request) case response.code when 200 begin reader = XmlReader.new(response.body) return RoleReader.read_one(reader) ensure reader.close end else check_fault(response) end end
Sub-resource locator method, returns permits service.
@return [PermitsService] A reference to `permits` service.
# File lib/ovirtsdk4/services.rb, line 19834 def permits_service PermitsService.new(@connection, "#{@path}/permits") end
Removes the role.
To remove the role you need to know its id, then send request like this:
DELETE /ovirt-engine/api/roles/{role_id}
@param opts [Hash] Additional options.
@option opts [Boolean] :async Indicates if the remove should be performed asynchronously.
# File lib/ovirtsdk4/services.rb, line 19752 def remove(opts = {}) query = {} value = opts[:async] unless value.nil? value = Writer.render_boolean(value) query['async'] = value end request = HttpRequest.new(method: :DELETE, url: @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 19845 def service(path) if path.nil? || path == '' return self end if path == 'permits' return permits_service end if path.start_with?('permits/') return permits_service.service(path[8..-1]) end raise Error.new("The path \"#{path}\" doesn't correspond to any service") end
Returns an string representation of this service.
@return [String]
# File lib/ovirtsdk4/services.rb, line 19863 def to_s "#<#{RoleService}:#{@path}>" end
Updates a role. You are allowed to update `name`, `description` and `administrative` attributes after role is created. Within this endpoint you can't add or remove roles permits you need to use <<services/permits, service>> that manages permits of role.
For example to update role's `name`, `description` and `administrative` attributes send a request like this:
PUT /ovirt-engine/api/roles/123
With a request body like this:
<role>
<name>MyNewRoleName</name> <description>My new description of the role</description> <administrative>true</administrative>
</group>
@param role [Role] Updated role. @param opts [Hash] Additional options.
@option opts [Boolean] :async Indicates if the update should be performed asynchronously.
@return [Role]
# File lib/ovirtsdk4/services.rb, line 19796 def update(role, opts = {}) if role.is_a?(Hash) role = OvirtSDK4::Role.new(role) end query = {} value = opts[:async] unless value.nil? value = Writer.render_boolean(value) query['async'] = value end request = HttpRequest.new(method: :PUT, url: @path, query: query) begin writer = XmlWriter.new(nil, true) RoleWriter.write_one(role, writer) request.body = writer.string ensure writer.close end response = @connection.send(request) case response.code when 200 begin reader = XmlReader.new(response.body) return RoleReader.read_one(reader) ensure reader.close end return result else check_fault(response) end end