|
| 1 | +# -*- coding: UTF-8 -*- |
| 2 | +from pool import Pool, PoolElement, Template |
| 3 | + |
| 4 | +class Datastore(PoolElement): |
| 5 | + METHODS = { |
| 6 | + #'info' : 'datastore.info', |
| 7 | + 'allocate' : 'datastore.allocate', |
| 8 | + 'delete' : 'datastore.delete', |
| 9 | + #'enable' : 'datastore.enable', |
| 10 | + #'update' : 'datastore.update' |
| 11 | + } |
| 12 | + |
| 13 | + XML_TYPES = { |
| 14 | + 'id' : int, |
| 15 | + 'name' : str, |
| 16 | + 'uid' : int, |
| 17 | + 'gid' : int, |
| 18 | + 'uname' : str, |
| 19 | + 'gname' : str, |
| 20 | + #'permissions' : Permissions, |
| 21 | + 'ds_mad' : str, |
| 22 | + 'tm_mad' : str, |
| 23 | + 'base_path' : str, |
| 24 | + 'type' : int, |
| 25 | + 'disk_type' : int, |
| 26 | + #'state' : ???, |
| 27 | + 'cluster_id' : int, |
| 28 | + 'cluster' : lambda element: element if isinstance(element, str) else '', |
| 29 | + 'total_mb' : int, |
| 30 | + 'free_mb' : int, |
| 31 | + 'used_mb' : int, |
| 32 | + 'image_ids' : ['IMAGES', lambda images: map(lambda image_id: int(image_id.text), images)], |
| 33 | + 'template' : ['TEMPLATE', Template], |
| 34 | + } |
| 35 | + |
| 36 | + ELEMENT_NAME = 'DATASTORE' |
| 37 | + |
| 38 | + @staticmethod |
| 39 | + def allocate(client, datastore_template): |
| 40 | + ''' |
| 41 | + Adds a datastore to the datastore list |
| 42 | +
|
| 43 | + Arguments |
| 44 | +
|
| 45 | + ``datastore_template`` |
| 46 | + Template for the datastore to add |
| 47 | + ''' |
| 48 | + datastore_id = client.call(Datastore.METHODS['allocate'], datastore_template) |
| 49 | + return datastore_id |
| 50 | + |
| 51 | + def __init__(self, xml, client): |
| 52 | + super(Datastore, self).__init__(xml, client) |
| 53 | + self._convert_types() |
| 54 | + |
| 55 | + def __repr__(self): |
| 56 | + return '<oca.Datastore("%s")>' % self.name |
| 57 | + |
| 58 | + |
| 59 | +class DatastorePool(Pool): |
| 60 | + METHODS = { |
| 61 | + 'info' : 'datastorepool.info', |
| 62 | + } |
| 63 | + |
| 64 | + def __init__(self, client): |
| 65 | + super(DatastorePool, self).__init__('DATASTORE_POOL', 'DATASTORE', client) |
| 66 | + |
| 67 | + def _factory(self, xml): |
| 68 | + c = Datastore(xml, self.client) |
| 69 | + return c |
0 commit comments