11# -*- coding: UTF-8 -*-
2- from .pool import Pool , PoolElement , Template , extractString
2+ from .pool import Pool , PoolElement , Template , extractString , XMLElement
33
44
5+ class Quota (XMLElement ):
6+ def __init__ (self , xml ):
7+ super (Quota , self ).__init__ (xml )
8+ self ._convert_types ()
9+
10+
11+ class VMQuota (Quota ):
12+ XML_TYPES = {
13+ 'cpu' : int ,
14+ 'cpu_used' : int ,
15+ 'memory' : int ,
16+ 'memory_used' : int ,
17+ 'system_disk_size' : int ,
18+ 'system_disk_size_used' : int ,
19+ 'vms' : int ,
20+ 'vms_used' : int ,
21+ }
22+
23+
24+ class DatastoreQuota (Quota ):
25+ XML_TYPES = {
26+ 'images' : int ,
27+ 'images_used' : int ,
28+ 'size' : int ,
29+ 'size_used' : int ,
30+ }
31+
32+
33+ class NetworkQuota (Quota ):
34+ XML_TYPES = {
35+ 'leases' : int ,
36+ 'leases_used' : int ,
37+ }
38+
39+ class VMQuotaList (Quota ):
40+ XML_TYPES = {
41+ 'vm' : VMQuota ,
42+ }
43+
44+
45+ class DatastoreQuotaList (Quota ):
46+ XML_TYPES = {
47+ 'datastore' : DatastoreQuota ,
48+ }
49+
50+
51+ class NetworkQuotaList (Quota ):
52+ XML_TYPES = {
53+ 'network' : NetworkQuota ,
54+ }
55+
556class User (PoolElement ):
657 METHODS = {
758 'info' : 'user.info' ,
@@ -12,20 +63,18 @@ class User(PoolElement):
1263 }
1364
1465 XML_TYPES = {
15- 'id' : int ,
16- 'gid' : int ,
17- 'group_ids' : ['GROUPS' , lambda group_ids : [int (group_id .text ) for group_id in group_ids ]],
18- 'gname' : extractString ,
19- 'name' : extractString ,
20- 'password' : extractString ,
21- 'auth_driver' : extractString ,
22- 'enabled' : bool ,
23- 'template' : ['TEMPLATE' , Template ],
24- #'datastore_quota': handled separately # see http://dev.opennebula.org/issues/3849
25- #'network_quota': handled separately # see http://dev.opennebula.org/issues/3849
26- #'vm_quota': handled separately # see http://dev.opennebula.org/issues/3849
27- #'image_quota' # see http://dev.opennebula.org/issues/3849
28- #'default_user_quotas' # see http://dev.opennebula.org/issues/3849
66+ 'id' : int ,
67+ 'gid' : int ,
68+ 'group_ids' : ['GROUPS' , lambda group_ids : [int (group_id .text ) for group_id in group_ids ]],
69+ 'gname' : extractString ,
70+ 'name' : extractString ,
71+ 'password' : extractString ,
72+ 'auth_driver' : extractString ,
73+ 'enabled' : bool ,
74+ 'template' : ['TEMPLATE' , Template ],
75+ #'network_quota': handled separately # see http://dev.opennebula.org/issues/3849
76+ #'image_quota' # see http://dev.opennebula.org/issues/3849
77+ #'default_user_quotas' # see http://dev.opennebula.org/issues/3849
2978 }
3079
3180 ELEMENT_NAME = 'USER'
@@ -66,6 +115,21 @@ def chgrp(self, gid):
66115 '''
67116 self .client .call (User .METHODS ['chgrp' ], self .id , gid )
68117
118+ @property
119+ def vm_quota (self ):
120+ self .info ()
121+ return VMQuotaList (self .xml .find ('VM_QUOTA' )).vm
122+
123+ @property
124+ def datastore_quota (self ):
125+ self .info ()
126+ return DatastoreQuotaList (self .xml .find ('DATASTORE_QUOTA' )).datastore
127+
128+ @property
129+ def network_quota (self ):
130+ self .info ()
131+ return NetworkQuotaList (self .xml .find ('NETWORK_QUOTA' )).network
132+
69133 def __repr__ (self ):
70134 return '<oca.User("%s")>' % self .name
71135
0 commit comments