|
| 1 | +# -*- coding: UTF-8 -*- |
| 2 | +from pool import Pool, PoolElement, Template |
| 3 | + |
| 4 | +class Cluster(PoolElement): |
| 5 | + METHODS = { |
| 6 | + #'info' : 'cluster.info', |
| 7 | + 'allocate' : 'cluster.allocate', |
| 8 | + 'delete' : 'cluster.delete', |
| 9 | + #'enable' : 'cluster.enable', |
| 10 | + #'update' : 'cluster.update' |
| 11 | + } |
| 12 | + |
| 13 | + XML_TYPES = { |
| 14 | + 'id' : int, |
| 15 | + 'name' : str, |
| 16 | + 'host_ids' : ['HOSTS', lambda hosts: map(lambda host_id: int(host_id.text), hosts)], |
| 17 | + 'datastore_ids' : ['DATASTORES', lambda datastores: map(lambda datastore_id: int(datastore_id.text), datastores)], |
| 18 | + 'vnet_ids' : ['VNETS', lambda vnets: map(lambda vnet_id: int(vnet_id.text), vnets)], |
| 19 | + 'template' : ['TEMPLATE', Template], |
| 20 | + } |
| 21 | + |
| 22 | + ELEMENT_NAME = 'CLUSTER' |
| 23 | + |
| 24 | + @staticmethod |
| 25 | + def allocate(client, cluster_name): |
| 26 | + ''' |
| 27 | + Adds a cluster to the cluster list |
| 28 | +
|
| 29 | + Arguments |
| 30 | +
|
| 31 | + ``cluster_name`` |
| 32 | + Clustername to add |
| 33 | + ''' |
| 34 | + cluster_id = client.call(Cluster.METHODS['allocate'], cluster_name) |
| 35 | + return cluster_id |
| 36 | + |
| 37 | + def __init__(self, xml, client): |
| 38 | + super(Cluster, self).__init__(xml, client) |
| 39 | + self._convert_types() |
| 40 | + |
| 41 | + def __repr__(self): |
| 42 | + return '<oca.Cluster("%s")>' % self.name |
| 43 | + |
| 44 | + |
| 45 | +class ClusterPool(Pool): |
| 46 | + METHODS = { |
| 47 | + 'info' : 'clusterpool.info', |
| 48 | + } |
| 49 | + |
| 50 | + def __init__(self, client): |
| 51 | + super(ClusterPool, self).__init__('CLUSTER_POOL', 'CLUSTER', client) |
| 52 | + |
| 53 | + def _factory(self, xml): |
| 54 | + c = Cluster(xml, self.client) |
| 55 | + return c |
| 56 | + |
0 commit comments