Class: OvirtSDK4::GroupsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Group) add(group, opts = {})

Adds a new group.

Parameters:

Returns:



9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
# File 'lib/ovirtsdk4/services.rb', line 9366

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

- (GroupService) group_service(id)

Locates the group service.

Parameters:

  • id (String)

    The identifier of the group.

Returns:



9445
9446
9447
# File 'lib/ovirtsdk4/services.rb', line 9445

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

- (Array<Group>) list(opts = {})

Returns the representation of the object managed by this service.

Parameters:

  • opts (Hash) (defaults to: {})

    Additional options.

Options Hash (opts):

  • :case_sensitive (Boolean)

    Indicates if the search performed using the search parameter should be performed taking case into account. The default value is true, which means that case is taken into account. If you want to search ignoring case set it to false.

  • :max (Integer)

    Sets the maximum number of groups to return. If not specified all the groups are returned.

  • :search (String)

    A query string used to restrict the returned groups.

Returns:



9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
# File 'lib/ovirtsdk4/services.rb', line 9407

def list(opts = {})
  query = {}
  value = opts[:case_sensitive]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['case_sensitive'] = value
  end
  value = opts[:max]
  unless value.nil?
    value = Writer.render_integer(value)
    query['max'] = value
  end
  value = opts[:search]
  unless value.nil?
    query['search'] = 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 GroupReader.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.



9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
# File 'lib/ovirtsdk4/services.rb', line 9456

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


9472
9473
9474
# File 'lib/ovirtsdk4/services.rb', line 9472

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