Class: OvirtSDK4::UsersService

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

Instance Method Summary (collapse)

Instance Method Details

- (User) add(user, opts = {})

Adds a new user.

Parameters:

Returns:



23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
# File 'lib/ovirtsdk4/services.rb', line 23024

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

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

  • :search (String)

    A query string used to restrict the returned users.

Returns:



23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
# File 'lib/ovirtsdk4/services.rb', line 23065

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



23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
# File 'lib/ovirtsdk4/services.rb', line 23114

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


23130
23131
23132
# File 'lib/ovirtsdk4/services.rb', line 23130

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

- (UserService) user_service(id)

Locates the user service.

Parameters:

  • id (String)

    The identifier of the user.

Returns:



23103
23104
23105
# File 'lib/ovirtsdk4/services.rb', line 23103

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