forked from python-oca/python-oca
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster.py
More file actions
56 lines (43 loc) · 1.56 KB
/
cluster.py
File metadata and controls
56 lines (43 loc) · 1.56 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
# -*- coding: UTF-8 -*-
from .pool import Pool, PoolElement, Template, extractString
class Cluster(PoolElement):
METHODS = {
#'info' : 'cluster.info',
'allocate' : 'cluster.allocate',
'delete' : 'cluster.delete',
#'enable' : 'cluster.enable',
#'update' : 'cluster.update'
}
XML_TYPES = {
'id' : int,
'name' : extractString,
'host_ids' : ['HOSTS', lambda hosts: [int(host_id.text) for host_id in hosts]],
'datastore_ids' : ['DATASTORES', lambda datastores: [int(datastore_id.text) for datastore_id in datastores]],
'vnet_ids' : ['VNETS', lambda vnets: [int(vnet_id.text) for vnet_id in vnets]],
'template' : ['TEMPLATE', Template],
}
ELEMENT_NAME = 'CLUSTER'
@staticmethod
def allocate(client, cluster_name):
'''
Adds a cluster to the cluster list
Arguments
``cluster_name``
Clustername to add
'''
cluster_id = client.call(Cluster.METHODS['allocate'], cluster_name)
return cluster_id
def __init__(self, xml, client):
super(Cluster, self).__init__(xml, client)
self._convert_types()
def __repr__(self):
return '<oca.Cluster("%s")>' % self.name
class ClusterPool(Pool):
METHODS = {
'info' : 'clusterpool.info',
}
def __init__(self, client):
super(ClusterPool, self).__init__('CLUSTER_POOL', 'CLUSTER', client)
def _factory(self, xml):
c = Cluster(xml, self.client)
return c