-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathuser.py
More file actions
77 lines (59 loc) · 1.78 KB
/
Copy pathuser.py
File metadata and controls
77 lines (59 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: UTF-8 -*-
from pool import Pool, PoolElement
class User(PoolElement):
METHODS = {
'info' : 'user.info',
'allocate' : 'user.allocate',
'delete' : 'user.delete',
'passwd' : 'user.passwd',
'chgrp' : 'user.chgrp'
}
XML_TYPES = {
'id' : int,
'gid' : int,
'name' : str,
'gname' : str,
'password' : str,
'enabled' : bool,
}
ELEMENT_NAME = 'USER'
@staticmethod
def allocate(client, user, password):
'''
allocates a new user in OpenNebula
``user``
username for the new user
``password``
password for the new user
'''
user_id = client.call(User.METHODS['allocate'], user, password)
return user_id
def __init__(self, xml, client):
super(User, self).__init__(xml, client)
self.id = self['ID'] if self['ID'] else None
def change_passwd(self, new_password):
'''
Changes the password for the given user.
``new_password``
The new password
'''
self.client.call(User.METHODS['passwd'], self.id, new_password)
def chgrp(self, gid):
'''
Changes the main group
``gid``
New group id. Set to -1 to leave the current one
'''
self.client.call(User.METHODS['chgrp'], self.id, gid)
def __repr__(self):
return '<oca.User("%s")>' % self.name
class UserPool(Pool):
METHODS = {
'info' : 'userpool.info',
}
def __init__(self, client):
super(UserPool, self).__init__('USER_POOL', 'POOL', client)
def _factory(self, xml):
u = User(xml, self.client)
u._convert_types()
return u