class OpenNebula::User

Constants

CIPHER_AUTH

Driver name for default core authentication

CORE_AUTH

Driver name for default core authentication

INVALID_NAME_CHARS

Same as User.cc

INVALID_PASS_CHARS
SELF
SSH_AUTH

Driver name for ssh authentication

USER_METHODS

Constants and Class Methods

X509_AUTH

Driver name for x509 authentication

X509_PROXY_AUTH

Driver name for x509 proxy authentication

Public Class Methods

build_xml(pe_id=nil) click to toggle source

Creates a User description with just its identifier this method should be used to create plain User objects. id the id of the user

Example:

user = User.new(User.build_xml(3),rpc_client)
# File lib/opennebula/user.rb, line 70
def User.build_xml(pe_id=nil)
    if pe_id
        user_xml = "<USER><ID>#{pe_id}</ID></USER>"
    else
        user_xml = "<USER></USER>"
    end

    XMLElement.build_xml(user_xml, 'USER')
end
new(xml, client) click to toggle source

Class constructor

Calls superclass method OpenNebula::PoolElement::new
# File lib/opennebula/user.rb, line 81
def initialize(xml, client)
    super(xml,client)

    @client = client
end

Public Instance Methods

addgroup(gid) click to toggle source

Adds the User to a secondary group @param gid [Integer] the new group id. @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/user.rb, line 171
def addgroup(gid)
    return call(USER_METHODS[:addgroup], @pe_id, gid)
end
allocate(username, password, driver=nil, gids=[]) click to toggle source

Allocates a new User in OpenNebula

username Name of the new user.

password Password for the new user @param username Username for the new user. @param password Password for the new user @param driver Auth driver for the new user. @param gids Group IDs. The first ID will be used as the main group. This array can be empty, in which case the default group will be used.

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method OpenNebula::PoolElement#allocate
# File lib/opennebula/user.rb, line 111
def allocate(username, password, driver=nil, gids=[])
    driver = CORE_AUTH if driver.nil?
    super(USER_METHODS[:allocate], username, password, driver, gids)
end
chauth(auth, password="") click to toggle source

Changes the auth driver and the password of the given User

@param auth [String] the new auth driver @param password [String] the new password. If it is an empty string,

the user password is not changed

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/user.rb, line 191
def chauth(auth, password="")
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(USER_METHODS[:chauth],@pe_id, auth, password)
    rc = nil if !OpenNebula.is_error?(rc)

    return rc
end
chgrp(gid) click to toggle source

Changes the primary group

gid

Integer the new group id. Set to -1 to leave the current one

return

nil in case of success or an Error object

# File lib/opennebula/user.rb, line 158
def chgrp(gid)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(USER_METHODS[:chgrp],@pe_id, gid)
    rc = nil if !OpenNebula.is_error?(rc)

    return rc
end
delete() click to toggle source

Deletes the User

Calls superclass method OpenNebula::PoolElement#delete
# File lib/opennebula/user.rb, line 129
def delete()
    super(USER_METHODS[:delete])
end
delgroup(gid) click to toggle source

Removes the User from a secondary group. Fails if the group is the main one @param gid [Integer] the group id. @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/user.rb, line 180
def delgroup(gid)
    return call(USER_METHODS[:delgroup], @pe_id, gid)
end
disable() click to toggle source

Disable the User

# File lib/opennebula/user.rb, line 139
def disable()
    set_enabled(false)
end
enable() click to toggle source

Enable the User

# File lib/opennebula/user.rb, line 134
def enable()
    set_enabled(true)
end
gid() click to toggle source

Returns the group identifier

return

Integer the element's group ID

# File lib/opennebula/user.rb, line 235
def gid
    self['GID'].to_i
end
groups() click to toggle source

Returns a list with all the group IDs for the user including primary

return

Array with the group ID's (as integers)

# File lib/opennebula/user.rb, line 241
def groups
    all_groups = self.retrieve_elements("GROUPS/ID")
    all_groups.collect! {|x| x.to_i}
end
info(decrypt = false) click to toggle source

Retrieves the information of the given User.

Calls superclass method OpenNebula::PoolElement#info
# File lib/opennebula/user.rb, line 92
def info(decrypt = false)
    super(USER_METHODS[:info], 'USER', decrypt)
end
Also aliased as: info!
info!(decrypt = false)
Alias for: info
login(uname, token, expire, egid = -1) click to toggle source

Sets the LOGIN_TOKEN for the user

@param uname [String] of the user @param token [String] the login token, if empty OpenNebula will

generate one

@param expire [String] valid period of the token in secs. If == 0

the token will be reset

@param egid [Integer] Effective GID to use with this token. To use the current GID and user groups set it to -1 @return [String, OpenNebula::Error] token in case of success, Error

otherwise
# File lib/opennebula/user.rb, line 225
def login(uname, token, expire, egid = -1)
    return @client.call(USER_METHODS[:login], uname, token, expire, egid)
end
passwd(password) click to toggle source

Changes the password of the given User

password String containing the new password

# File lib/opennebula/user.rb, line 146
def passwd(password)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(USER_METHODS[:passwd], @pe_id, password)
    rc = nil if !OpenNebula.is_error?(rc)

    return rc
end
set_quota(quota) click to toggle source

Sets the user quota limits @param quota [String] a template (XML or txt) with the new quota limits

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/user.rb, line 205
def set_quota(quota)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(USER_METHODS[:quota],@pe_id, quota)
    rc = nil if !OpenNebula.is_error?(rc)

    return rc
end
update(new_template, append=false) click to toggle source

Replaces the template contents

@param new_template [String] New template contents @param append [true, false] True to append new attributes instead of

replace the whole template

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method OpenNebula::PoolElement#update
# File lib/opennebula/user.rb, line 124
def update(new_template, append=false)
    super(USER_METHODS[:update], new_template, append ? 1 : 0)
end

Private Instance Methods

set_enabled(enabled) click to toggle source
# File lib/opennebula/user.rb, line 248
def set_enabled(enabled)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(USER_METHODS[:enable], @pe_id, enabled)
    rc = nil if !OpenNebula.is_error?(rc)

    return rc
end