Class: OpenNebula::User

Inherits:
PoolElement show all
Defined in:
lib/opennebula/user.rb

Constant Summary collapse

USER_METHODS =

Constants and Class Methods

{
    :info     => "user.info",
    :allocate => "user.allocate",
    :delete   => "user.delete",
    :passwd   => "user.passwd",
    :chgrp    => "user.chgrp",
    :addgroup => "user.addgroup",
    :delgroup => "user.delgroup",
    :update   => "user.update",
    :chauth   => "user.chauth",
    :quota    => "user.quota",
    :login    => "user.login",
    :enable   => "user.enable",
    :disable  => "user.disable"
}
SELF =
-1
CORE_AUTH =

Driver name for default core authentication

"core"
CIPHER_AUTH =

Driver name for default core authentication

"server_cipher"
SSH_AUTH =

Driver name for ssh authentication

"ssh"
X509_AUTH =

Driver name for x509 authentication

"x509"
X509_PROXY_AUTH =

Driver name for x509 proxy authentication

"x509_proxy"
INVALID_NAME_CHARS =

Same as User.cc

[" ", ":", "\t", "\n", "\v", "\f", "\r"]
INVALID_PASS_CHARS =
[" ", "\t", "\n", "\v", "\f", "\r"]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolElement

#id, #name, new_with_id, #replace, #to_str

Methods inherited from XMLElement

#[], #add_element, #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #retrieve_xmlelements, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?

Constructor Details

#initialize(xml, client) ⇒ User

Class constructor



81
82
83
84
85
# File 'lib/opennebula/user.rb', line 81

def initialize(xml, client)
    super(xml,client)

    @client = client
end

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

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)


70
71
72
73
74
75
76
77
78
# 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

Instance Method Details

#addgroup(gid) ⇒ nil, OpenNebula::Error

Adds the User to a secondary group

Parameters:

  • gid (Integer)

    the new group id.

Returns:



171
172
173
# 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 = []) ⇒ nil, OpenNebula::Error

Allocates a new User in OpenNebula

username Name of the new user.

password Password for the new user This array can be empty, in which case the default group will be used.

Parameters:

  • username

    Username for the new user.

  • password

    Password for the new user

  • driver (defaults to: nil)

    Auth driver for the new user.

  • gids (defaults to: [])

    Group IDs. The first ID will be used as the main group.

Returns:



111
112
113
114
# 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 = "") ⇒ nil, OpenNebula::Error

Changes the auth driver and the password of the given User

Parameters:

  • auth (String)

    the new auth driver

  • password (String) (defaults to: "")

    the new password. If it is an empty string, the user password is not changed

Returns:



191
192
193
194
195
196
197
198
# 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) ⇒ Object

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



158
159
160
161
162
163
164
165
# 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

#deleteObject

Deletes the User



129
130
131
# File 'lib/opennebula/user.rb', line 129

def delete()
    super(USER_METHODS[:delete])
end

#delgroup(gid) ⇒ nil, OpenNebula::Error

Removes the User from a secondary group. Fails if the group is the main one

Parameters:

  • gid (Integer)

    the group id.

Returns:



180
181
182
# File 'lib/opennebula/user.rb', line 180

def delgroup(gid)
    return call(USER_METHODS[:delgroup], @pe_id, gid)
end

#disableObject

Disable the User



139
140
141
# File 'lib/opennebula/user.rb', line 139

def disable()
    set_enabled(false)
end

#enableObject

Enable the User



134
135
136
# File 'lib/opennebula/user.rb', line 134

def enable()
    set_enabled(true)
end

#gidObject

Returns the group identifier

return

Integer the element’s group ID



235
236
237
# File 'lib/opennebula/user.rb', line 235

def gid
    self['GID'].to_i
end

#groupsObject

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

return

Array with the group ID’s (as integers)



241
242
243
244
# File 'lib/opennebula/user.rb', line 241

def groups
    all_groups = self.retrieve_elements("GROUPS/ID")
    all_groups.collect! {|x| x.to_i}
end

#infoObject Also known as: info!

Retrieves the information of the given User.



92
93
94
# File 'lib/opennebula/user.rb', line 92

def info()
    super(USER_METHODS[:info], 'USER')
end

#login(uname, token, expire, egid = -1)) ⇒ String, OpenNebula::Error

Sets the LOGIN_TOKEN for the user

the current GID and user groups set it to -1

Parameters:

  • uname (String)

    of the user

  • token (String)

    the login token, if empty OpenNebula will generate one

  • expire (String)

    valid period of the token in secs. If == 0 the token will be reset

  • egid (Integer) (defaults to: -1))

    Effective GID to use with this token. To use

Returns:



225
226
227
# File 'lib/opennebula/user.rb', line 225

def (uname, token, expire, egid = -1)
    return @client.call(USER_METHODS[:login], uname, token, expire, egid)
end

#passwd(password) ⇒ Object

Changes the password of the given User

password String containing the new password



146
147
148
149
150
151
152
153
# 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) ⇒ nil, OpenNebula::Error

Sets the user quota limits

Parameters:

  • quota (String)

    a template (XML or txt) with the new quota limits

Returns:



205
206
207
208
209
210
211
212
# 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) ⇒ nil, OpenNebula::Error

Replaces the template contents

Parameters:

  • new_template (String)

    New template contents

  • append (true, false) (defaults to: false)

    True to append new attributes instead of replace the whole template

Returns:



124
125
126
# File 'lib/opennebula/user.rb', line 124

def update(new_template, append=false)
    super(USER_METHODS[:update], new_template, append ? 1 : 0)
end