forked from python-oca/python-oca
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatastore.py
More file actions
70 lines (57 loc) · 1.84 KB
/
datastore.py
File metadata and controls
70 lines (57 loc) · 1.84 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
# -*- coding: UTF-8 -*-
from .pool import Pool, PoolElement, Template, extractString
class Datastore(PoolElement):
METHODS = {
# 'info' : 'datastore.info',
'allocate': 'datastore.allocate',
'delete': 'datastore.delete',
# 'enable' : 'datastore.enable',
# 'update' : 'datastore.update'
}
XML_TYPES = {
'id': int,
'name': extractString,
'uid': int,
'gid': int,
'uname': extractString,
'gname': extractString,
# 'permissions' : Permissions,
'ds_mad': extractString,
'tm_mad': extractString,
'base_path': extractString,
'type': int,
'disk_type': int,
# 'state' : ???,
'cluster_id': int,
'cluster': extractString,
'total_mb': int,
'free_mb': int,
'used_mb': int,
'image_ids': ['IMAGES', lambda images: [int(image_id.text) for image_id in images]],
'template': ['TEMPLATE', Template],
}
ELEMENT_NAME = 'DATASTORE'
@staticmethod
def allocate(client, datastore_template):
"""
Adds a datastore to the datastore list
Arguments
``datastore_template``
Template for the datastore to add
"""
datastore_id = client.call(Datastore.METHODS['allocate'], datastore_template)
return datastore_id
def __init__(self, xml, client):
super(Datastore, self).__init__(xml, client)
self._convert_types()
def __repr__(self):
return '<oca.Datastore("%s")>' % self.name
class DatastorePool(Pool):
METHODS = {
'info': 'datastorepool.info',
}
def __init__(self, client):
super(DatastorePool, self).__init__('DATASTORE_POOL', 'DATASTORE', client)
def _factory(self, xml):
c = Datastore(xml, self.client)
return c