From b1263cb1129b30a600e9731174a2994d83844fb0 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Mon, 22 Jun 2015 23:50:42 +0200 Subject: [PATCH 1/8] Add initial cluster support. Clusters can be listed, created and deleted. Host creation now accepts the new cluster_id parameter. If no cluster_id is passed to host.allocate, the host is not assigned to a cluster. --- oca/__init__.py | 4 ++- oca/cluster.py | 56 ++++++++++++++++++++++++++++++ oca/host.py | 4 +-- oca/tests/fixtures/cluster.xml | 20 +++++++++++ oca/tests/fixtures/clusterpool.xml | 24 +++++++++++++ oca/tests/test_cluster.py | 32 +++++++++++++++++ oca/tests/test_clusterpool.py | 20 +++++++++++ 7 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 oca/cluster.py create mode 100644 oca/tests/fixtures/cluster.xml create mode 100644 oca/tests/fixtures/clusterpool.xml create mode 100644 oca/tests/test_cluster.py create mode 100644 oca/tests/test_clusterpool.py diff --git a/oca/__init__.py b/oca/__init__.py index cd8e7f1..e45107d 100644 --- a/oca/__init__.py +++ b/oca/__init__.py @@ -14,6 +14,7 @@ from group import Group, GroupPool from template import VmTemplate, VmTemplatePool from exceptions import OpenNebulaException +from cluster import Cluster, ClusterPool CONNECTED = -3 @@ -123,5 +124,6 @@ def call(self, function, *args): __all__ = [Client, OpenNebulaException, Host, HostPool, VirtualMachine, VirtualMachinePool, User, UserPool, Image, ImagePool, VirtualNetwork, VirtualNetworkPool, - Group, GroupPool, VmTemplate, VmTemplatePool, ALL, CONNECTED] + Group, GroupPool, VmTemplate, VmTemplatePool, ALL, CONNECTED, + Cluster, ClusterPool] diff --git a/oca/cluster.py b/oca/cluster.py new file mode 100644 index 0000000..43bb36c --- /dev/null +++ b/oca/cluster.py @@ -0,0 +1,56 @@ +# -*- coding: UTF-8 -*- +from pool import Pool, PoolElement, Template + +class Cluster(PoolElement): + METHODS = { + #'info' : 'cluster.info', + 'allocate' : 'cluster.allocate', + 'delete' : 'cluster.delete', + #'enable' : 'cluster.enable', + #'update' : 'cluster.update' + } + + XML_TYPES = { + 'id' : int, + 'name' : str, + 'host_ids' : ['HOSTS', lambda hosts: map(lambda host_id: int(host_id.text), hosts)], + 'datastore_ids' : ['DATASTORES', lambda datastores: map(lambda datastore_id: int(datastore_id.text), datastores)], + 'vnet_ids' : ['VNETS', lambda vnets: map(lambda vnet_id: int(vnet_id.text), 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 '' % 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 + diff --git a/oca/host.py b/oca/host.py index 762eff9..7bbd0b3 100644 --- a/oca/host.py +++ b/oca/host.py @@ -46,7 +46,7 @@ class Host(PoolElement): ELEMENT_NAME = 'HOST' @staticmethod - def allocate(client, hostname, im, vmm, tm): + def allocate(client, hostname, im, vmm, tm, cluster_id=-1): ''' Adds a host to the host list @@ -64,7 +64,7 @@ def allocate(client, hostname, im, vmm, tm): ``tm`` Transfer manager ''' - host_id = client.call(Host.METHODS['allocate'], hostname, im, vmm, tm) + host_id = client.call(Host.METHODS['allocate'], hostname, im, vmm, tm, cluster_id) return host_id def __init__(self, xml, client): diff --git a/oca/tests/fixtures/cluster.xml b/oca/tests/fixtures/cluster.xml new file mode 100644 index 0000000..33853b6 --- /dev/null +++ b/oca/tests/fixtures/cluster.xml @@ -0,0 +1,20 @@ + + 101 + oneCluster + + 2 + 3 + + + 4 + 5 + + + 6 + 7 + + + diff --git a/oca/tests/fixtures/clusterpool.xml b/oca/tests/fixtures/clusterpool.xml new file mode 100644 index 0000000..7967dfa --- /dev/null +++ b/oca/tests/fixtures/clusterpool.xml @@ -0,0 +1,24 @@ + + + 101 + oneCluster + + + + + + + 102 + anotherCluster + + + + + + diff --git a/oca/tests/test_cluster.py b/oca/tests/test_cluster.py new file mode 100644 index 0000000..f7ba0b7 --- /dev/null +++ b/oca/tests/test_cluster.py @@ -0,0 +1,32 @@ +# -*- coding: UTF-8 -*- +import os + +from mock import Mock + +import oca + + +class TestCluster: + def setUp(self): + self.client = oca.Client('test:test') + self.xml = open(os.path.join(os.path.dirname(oca.__file__), + 'tests/fixtures/cluster.xml')).read() + + def test_allocate(self): + self.client.call = Mock(return_value=3) + assert oca.Cluster.allocate(self.client, 'test') == 3 + + def test_repr(self): + self.client.call = Mock() + cluster = oca.Cluster(self.xml, self.client) + assert repr(cluster) == '' + + def test_convert_types(self): + cluster = oca.Cluster(self.xml, None) + cluster._convert_types() + assert cluster.id == 101 + assert cluster.name == "oneCluster" + assert cluster.host_ids == [2,3] + assert cluster.datastore_ids == [4,5] + assert cluster.vnet_ids == [6,7] + assert cluster.template.reserved_cpu is None diff --git a/oca/tests/test_clusterpool.py b/oca/tests/test_clusterpool.py new file mode 100644 index 0000000..35543ce --- /dev/null +++ b/oca/tests/test_clusterpool.py @@ -0,0 +1,20 @@ +# -*- coding: UTF-8 -*- +import os + +from mock import Mock + +import oca + + +class TestClusterPool: + def setUp(self): + self.client = oca.Client('test:test') + self.xml = open(os.path.join(os.path.dirname(oca.__file__), + 'tests/fixtures/clusterpool.xml')).read() + + def test_info(self): + self.client.call = Mock(return_value=self.xml) + pool = oca.ClusterPool(self.client) + pool.info() + assert len(pool) == 2 + assert pool[1].name == "anotherCluster" From 147d4b824a55bb8587db37c5c048ca7bb2c669f4 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 23 Jun 2015 15:56:28 +0200 Subject: [PATCH 2/8] Add basic Datastore implementation including tests --- oca/__init__.py | 3 +- oca/datastore.py | 69 ++++++++++++++++++++++++ oca/tests/fixtures/datastore.xml | 42 +++++++++++++++ oca/tests/fixtures/datastorepool.xml | 79 ++++++++++++++++++++++++++++ oca/tests/test_datastore.py | 44 ++++++++++++++++ oca/tests/test_integration.py | 13 +++++ 6 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 oca/datastore.py create mode 100644 oca/tests/fixtures/datastore.xml create mode 100644 oca/tests/fixtures/datastorepool.xml create mode 100644 oca/tests/test_datastore.py create mode 100644 oca/tests/test_integration.py diff --git a/oca/__init__.py b/oca/__init__.py index e45107d..352e982 100644 --- a/oca/__init__.py +++ b/oca/__init__.py @@ -15,6 +15,7 @@ from template import VmTemplate, VmTemplatePool from exceptions import OpenNebulaException from cluster import Cluster, ClusterPool +from datastore import Datastore, DatastorePool CONNECTED = -3 @@ -125,5 +126,5 @@ def call(self, function, *args): VirtualMachinePool, User, UserPool, Image, ImagePool, VirtualNetwork, VirtualNetworkPool, Group, GroupPool, VmTemplate, VmTemplatePool, ALL, CONNECTED, - Cluster, ClusterPool] + Cluster, ClusterPool, Datastore, DatastorePool] diff --git a/oca/datastore.py b/oca/datastore.py new file mode 100644 index 0000000..514db26 --- /dev/null +++ b/oca/datastore.py @@ -0,0 +1,69 @@ +# -*- coding: UTF-8 -*- +from pool import Pool, PoolElement, Template + +class Datastore(PoolElement): + METHODS = { + #'info' : 'datastore.info', + 'allocate' : 'datastore.allocate', + 'delete' : 'datastore.delete', + #'enable' : 'datastore.enable', + #'update' : 'datastore.update' + } + + XML_TYPES = { + 'id' : int, + 'name' : str, + 'uid' : int, + 'gid' : int, + 'uname' : str, + 'gname' : str, + #'permissions' : Permissions, + 'ds_mad' : str, + 'tm_mad' : str, + 'base_path' : str, + 'type' : int, + 'disk_type' : int, + #'state' : ???, + 'cluster_id' : int, + 'cluster' : lambda element: element if isinstance(element, str) else '', + 'total_mb' : int, + 'free_mb' : int, + 'used_mb' : int, + 'image_ids' : ['IMAGES', lambda images: map(lambda image_id: int(image_id.text), 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 '' % 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 diff --git a/oca/tests/fixtures/datastore.xml b/oca/tests/fixtures/datastore.xml new file mode 100644 index 0000000..863fc61 --- /dev/null +++ b/oca/tests/fixtures/datastore.xml @@ -0,0 +1,42 @@ + + 100 + 0 + 0 + oneadmin + oneadmin + Custom-DS + + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + + + + + 0 + 0 + 0 + -1 + + 9952 + 8999 + 425 + + 2 + 3 + + + diff --git a/oca/tests/fixtures/datastorepool.xml b/oca/tests/fixtures/datastorepool.xml new file mode 100644 index 0000000..88fa4b2 --- /dev/null +++ b/oca/tests/fixtures/datastorepool.xml @@ -0,0 +1,79 @@ + + + 0 + 0 + 0 + oneadmin + oneadmin + system + + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + + + + + 1 + 0 + 0 + -1 + test + 0 + 0 + 0 + + + + + 1 + 0 + 0 + oneadmin + oneadmin + default + + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + + + + + 0 + 0 + 0 + -1 + + 9952 + 8999 + 425 + + + + diff --git a/oca/tests/test_datastore.py b/oca/tests/test_datastore.py new file mode 100644 index 0000000..3c6c860 --- /dev/null +++ b/oca/tests/test_datastore.py @@ -0,0 +1,44 @@ +# -*- coding: UTF-8 -*- +import os + +from mock import Mock + +import oca + + +class TestDatastore: + def setUp(self): + self.client = oca.Client('test:test') + self.xml = open(os.path.join(os.path.dirname(oca.__file__), + 'tests/fixtures/datastore.xml')).read() + + def test_allocate(self): + self.client.call = Mock(return_value=3) + assert oca.Datastore.allocate(self.client, 'test') == 3 + + def test_repr(self): + self.client.call = Mock() + datastore = oca.Datastore(self.xml, self.client) + assert repr(datastore) == '' + + def test_convert_types(self): + cluster = oca.Datastore(self.xml, None) + cluster._convert_types() + assert cluster.id == 100 + assert cluster.name == "Custom-DS" + assert cluster.uid == 0 + assert cluster.gid == 0 + assert cluster.uname == 'oneadmin' + assert cluster.gname == 'oneadmin' + assert cluster.ds_mad == 'fs' + assert cluster.tm_mad == 'ssh' + assert cluster.base_path == '/var/lib/one//datastores/100' + assert cluster.type == 0 + assert cluster.disk_type == 0 + assert cluster.cluster_id == -1 + assert cluster.cluster == "" + assert cluster.total_mb == 9952 + assert cluster.free_mb == 8999 + assert cluster.used_mb == 425 + assert cluster.image_ids == [2,3] + assert cluster.template.disk_type == 'FILE' diff --git a/oca/tests/test_integration.py b/oca/tests/test_integration.py new file mode 100644 index 0000000..73f5134 --- /dev/null +++ b/oca/tests/test_integration.py @@ -0,0 +1,13 @@ +import oca + +class TestIntegration: + def setUp(self): + self.client = oca.Client("oneadmin:one", "http://localhost:2633/RPC2") + cp = oca.ClusterPool(self.client) + cp.info() + for cluster in cp: + cluster.delete() + + def test_integration(self): + self.cluster_id = oca.Cluster.allocate(self.client, "IT-Cluster") + #self.datastore_id = oca. From fab2a69026e0195143906ff1b2526a5a822551e7 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 23 Jun 2015 16:15:07 +0200 Subject: [PATCH 3/8] Disable integration test until we can really execute it --- oca/tests/test_integration.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/oca/tests/test_integration.py b/oca/tests/test_integration.py index 73f5134..a7093d4 100644 --- a/oca/tests/test_integration.py +++ b/oca/tests/test_integration.py @@ -1,13 +1,14 @@ import oca class TestIntegration: - def setUp(self): - self.client = oca.Client("oneadmin:one", "http://localhost:2633/RPC2") - cp = oca.ClusterPool(self.client) - cp.info() - for cluster in cp: - cluster.delete() + #def setUp(self): + # self.client = oca.Client("oneadmin:one", "http://localhost:2633/RPC2") + # cp = oca.ClusterPool(self.client) + # cp.info() + # for cluster in cp: + # cluster.delete() - def test_integration(self): - self.cluster_id = oca.Cluster.allocate(self.client, "IT-Cluster") - #self.datastore_id = oca. + #def test_integration(self): + # self.cluster_id = oca.Cluster.allocate(self.client, "IT-Cluster") + # #self.datastore_id = oca. + pass From 1a6d5d185be61ea4c5599d056e6420ac9956357d Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 23 Jun 2015 20:54:41 +0200 Subject: [PATCH 4/8] Update Host definition, bugfix handling of empty strings --- oca/cluster.py | 4 +-- oca/datastore.py | 16 ++++++------ oca/group.py | 4 +-- oca/host.py | 44 ++++++++++++++++++++------------- oca/pool.py | 7 +++++- oca/tests/fixtures/host.xml | 3 +++ oca/tests/fixtures/hostpool.xml | 4 +++ 7 files changed, 52 insertions(+), 30 deletions(-) diff --git a/oca/cluster.py b/oca/cluster.py index 43bb36c..7001faf 100644 --- a/oca/cluster.py +++ b/oca/cluster.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -from pool import Pool, PoolElement, Template +from pool import Pool, PoolElement, Template, extractString class Cluster(PoolElement): METHODS = { @@ -12,7 +12,7 @@ class Cluster(PoolElement): XML_TYPES = { 'id' : int, - 'name' : str, + 'name' : extractString, 'host_ids' : ['HOSTS', lambda hosts: map(lambda host_id: int(host_id.text), hosts)], 'datastore_ids' : ['DATASTORES', lambda datastores: map(lambda datastore_id: int(datastore_id.text), datastores)], 'vnet_ids' : ['VNETS', lambda vnets: map(lambda vnet_id: int(vnet_id.text), vnets)], diff --git a/oca/datastore.py b/oca/datastore.py index 514db26..edc71ff 100644 --- a/oca/datastore.py +++ b/oca/datastore.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -from pool import Pool, PoolElement, Template +from pool import Pool, PoolElement, Template, extractString class Datastore(PoolElement): METHODS = { @@ -12,20 +12,20 @@ class Datastore(PoolElement): XML_TYPES = { 'id' : int, - 'name' : str, + 'name' : extractString, 'uid' : int, 'gid' : int, - 'uname' : str, - 'gname' : str, + 'uname' : extractString, + 'gname' : extractString, #'permissions' : Permissions, - 'ds_mad' : str, - 'tm_mad' : str, - 'base_path' : str, + 'ds_mad' : extractString, + 'tm_mad' : extractString, + 'base_path' : extractString, 'type' : int, 'disk_type' : int, #'state' : ???, 'cluster_id' : int, - 'cluster' : lambda element: element if isinstance(element, str) else '', + 'cluster' : extractString, 'total_mb' : int, 'free_mb' : int, 'used_mb' : int, diff --git a/oca/group.py b/oca/group.py index c10ed9c..e678e07 100644 --- a/oca/group.py +++ b/oca/group.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -from pool import Pool, PoolElement, Template +from pool import Pool, PoolElement, Template, extractString class Group(PoolElement): @@ -11,7 +11,7 @@ class Group(PoolElement): XML_TYPES = { 'id' : int, - 'name' : str, + 'name' : extractString, 'template' : ['TEMPLATE', Template], 'users' : ['USERS', lambda users: [int(i.text) for i in users]], #'resource_providers': handled separately diff --git a/oca/host.py b/oca/host.py index 7bbd0b3..2318220 100644 --- a/oca/host.py +++ b/oca/host.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -from pool import Pool, PoolElement, Template +from pool import Pool, PoolElement, Template, extractString class HostShare(Template): @@ -17,30 +17,40 @@ class Host(PoolElement): } INIT = 0 - MONITORING = 1 + MONITORING_MONITORED = 1 # Currently monitoring, previously MONITORED MONITORED = 2 ERROR = 3 DISABLED = 4 - HOST_STATES = ['INIT', 'MONITORING', 'MONITORED', 'ERROR', 'DISABLED'] + MONITORING_ERROR = 5 # Currently monitoring, previously ERROR + MONITORING_INIT = 6 # Currently monitoring, previously initialized + MONITORING_DISABLED = 7 # Currently monitoring, previously DISABLED + HOST_STATES = ['INIT', 'MONITORING_MONITORED', 'MONITORED', 'ERROR', 'DISABLED', + 'MONITORING_ERROR', 'MONITORING_INIT', 'MONITORING_DISABLED'] SHORT_HOST_STATES = { - 'INIT' : 'on', - 'MONITORING' : 'on', - 'MONITORED' : 'on', - 'ERROR' : 'err', - 'DISABLED' : 'off' + 'INIT': 'on', + 'MONITORING_MONITORED': 'on', + 'MONITORED': 'on', + 'ERROR': 'err', + 'DISABLED': 'off', + 'MONITORING_ERROR': 'on', + 'MONITORING_INIT': 'on', + 'MONITORING_DISABLED': 'on', } XML_TYPES = { - 'id' : int, - 'name' : str, - 'state' : int, - 'im_mad' : str, - 'vm_mad' : str, - 'last_mon_time' : int, - 'vm_ids' : ['VMS', lambda vms: map(lambda vmid: int(vmid.text), vms)], - 'template' : ['TEMPLATE', Template], - 'host_share' : ['HOST_SHARE', HostShare], + 'id': int, + 'name': extractString, + 'state': int, + 'im_mad': extractString, + 'vm_mad': extractString, + 'vn_mad': extractString, + 'last_mon_time': int, + 'cluster': extractString, + 'cluster_id': int, + 'vm_ids': ['VMS', lambda vms: map(lambda vmid: int(vmid.text), vms)], + 'template': ['TEMPLATE', Template], + 'host_share': ['HOST_SHARE', HostShare], } ELEMENT_NAME = 'HOST' diff --git a/oca/pool.py b/oca/pool.py index 313aad0..08759e2 100644 --- a/oca/pool.py +++ b/oca/pool.py @@ -12,6 +12,11 @@ class WrongNameError(OpenNebulaException): class WrongIdError(OpenNebulaException): pass +def extractString(xml_or_string): + if isinstance(xml_or_string, str): + return xml_or_string + else: + return xml_or_string.text or '' class Template(object): def __init__(self, xml_element, multiple=[]): @@ -60,7 +65,7 @@ def __getitem__(self, key): else: return value else: - raise IndexError() + raise IndexError("Key {0} not found!".format(key)) def __getattr__(self, name): try: diff --git a/oca/tests/fixtures/host.xml b/oca/tests/fixtures/host.xml index a0214e1..9c1d411 100644 --- a/oca/tests/fixtures/host.xml +++ b/oca/tests/fixtures/host.xml @@ -4,8 +4,11 @@ 2 im_dummy vmm_dummy + vn_dummy tm_dummy 1277733596 + + -1 0 0 diff --git a/oca/tests/fixtures/hostpool.xml b/oca/tests/fixtures/hostpool.xml index 86aba17..0c8fb33 100644 --- a/oca/tests/fixtures/hostpool.xml +++ b/oca/tests/fixtures/hostpool.xml @@ -5,9 +5,11 @@ 2 im_dummy vmm_dummy + vn_dummy tm_dummy 1277912461 default + 1 0 0 @@ -33,9 +35,11 @@ 2 im_dummy vmm_dummy + vn_dummy tm_dummy 1277912461 default + 1 1 0 From a0cb6e81e2561257e68884f99b1bf5375d8bd521 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 23 Jun 2015 21:17:27 +0200 Subject: [PATCH 5/8] Update image definition for OpenNebula 4.10 --- oca/image.py | 22 +++- oca/tests/fixtures/image.xml | 50 ++++++--- oca/tests/fixtures/imagepool.xml | 181 +++++++++++++++++++------------ 3 files changed, 166 insertions(+), 87 deletions(-) diff --git a/oca/image.py b/oca/image.py index 65939ca..963b798 100644 --- a/oca/image.py +++ b/oca/image.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -from pool import Pool, PoolElement, Template +from pool import Pool, PoolElement, Template, extractString class Image(PoolElement): @@ -18,16 +18,26 @@ class Image(PoolElement): 'id' : int, 'uid' : int, 'gid' : int, - 'uname' : str, - 'gname' : str, - 'name' : str, + 'uname' : extractString, + 'gname' : extractString, + 'name' : extractString, + #'permissions' : ???, 'type' : int, - 'public' : int, + 'disk_type' : int, 'persistent' : int, 'regtime' : int, - 'source' : str, + 'source' : extractString, + 'path' : extractString, + 'fstype' : extractString, + 'size' : int, 'state' : int, 'running_vms' : int, + 'cloning_ops' : int, + 'cloning_id' : int, + 'datastore_id': int, + 'datastore' : extractString, + 'vm_ids' : ["VMS", lambda vms: map(lambda vm_id: int(vm_id.text), vms)], + 'clone_ids' : ["CLONES", lambda clones: map(lambda clone_id: int(clone_id.text), clones)], 'template' : ['TEMPLATE', Template], } diff --git a/oca/tests/fixtures/image.xml b/oca/tests/fixtures/image.xml index 4f935fc..8fb2b2f 100644 --- a/oca/tests/fixtures/image.xml +++ b/oca/tests/fixtures/image.xml @@ -1,16 +1,38 @@ - 1 - 0 - 0 - oneadmin - oneadmin - MATLAB install CD - 1 - 0 - 0 - 1287503867 - /home/cmartin/trabajo/one.git/one/install/var//images/21df7c80e4357f20dc737e3f60dd7048ddc6a510 - 3 - 0 - + 1 + 0 + 0 + oneadmin + oneadmin + MATLAB install CD + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 2 + 0 + 0 + 1435086617 + + + + 400 + 1 + 0 + 0 + -1 + 1 + default + + + diff --git a/oca/tests/fixtures/imagepool.xml b/oca/tests/fixtures/imagepool.xml index 8541fed..294867b 100644 --- a/oca/tests/fixtures/imagepool.xml +++ b/oca/tests/fixtures/imagepool.xml @@ -1,69 +1,116 @@ - - 1 - 0 - 0 - oneadmin - oneadmin - oneadmin - MATLAB install CD - 1 - 0 - 0 - 1287503867 - /home/cmartin/trabajo/one.git/one/install/var//images/21df7c80e4357f20dc737e3f60dd7048ddc6a510 - 3 - 0 - - - - 4 - 0 - 0 - oneadmin - oneadmin - oneadmin - A - 0 - 0 - 0 - 1287503968 - /home/cmartin/trabajo/one.git/one/install/var//images/259456c9ae128117780f6866e8df8d1010f13f76 - 3 - 0 - - - - 5 - 0 - 0 - oneadmin - oneadmin - oneadmin - test_07 - 2 - 0 - 0 - 1287503984 - /home/cmartin/trabajo/one.git/one/install/var//images/12db97fabdd3eed843eca5edb1f5845650e52af6 - 1 - 0 - - + + 0 + 0 + 0 + oneadmin + oneadmin + data + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 2 + 0 + 0 + 1435086617 + + + + 400 + 1 + 0 + 0 + -1 + 1 + default + + + + + + 1 + 0 + 0 + oneadmin + oneadmin + data2 + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 2 + 0 + 0 + 1435086683 + + + + 200 + 1 + 0 + 0 + -1 + 1 + default + + + + + + 2 + 0 + 0 + oneadmin + oneadmin + data3 + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 2 + 0 + 0 + 1435086941 + + + + 200 + 1 + 0 + 0 + -1 + 1 + default + + + + From 0b62b4d5924af4983d300c41633d6efddf24c8c0 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 23 Jun 2015 22:48:05 +0200 Subject: [PATCH 6/8] Iterate over pool elements with correct tag type only --- oca/group.py | 2 +- oca/image.py | 2 +- oca/pool.py | 2 +- oca/template.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/oca/group.py b/oca/group.py index e678e07..3803fbb 100644 --- a/oca/group.py +++ b/oca/group.py @@ -54,7 +54,7 @@ class GroupPool(Pool): } def __init__(self, client): - super(GroupPool, self).__init__('GROUP_POOL', 'POOL', client) + super(GroupPool, self).__init__('GROUP_POOL', 'GROUP', client) def _factory(self, xml): i = Group(xml, self.client) diff --git a/oca/image.py b/oca/image.py index 963b798..648c001 100644 --- a/oca/image.py +++ b/oca/image.py @@ -186,7 +186,7 @@ class ImagePool(Pool): } def __init__(self, client): - super(ImagePool, self).__init__('IMAGE_POOL', 'POOL', client) + super(ImagePool, self).__init__('IMAGE_POOL', 'IMAGE', client) def _factory(self, xml): i = Image(xml, self.client) diff --git a/oca/pool.py b/oca/pool.py index 08759e2..8a0603f 100644 --- a/oca/pool.py +++ b/oca/pool.py @@ -108,7 +108,7 @@ def info(self, filter=-3, range_start=-1, range_end=-1, *args): data = self.client.call(self.METHODS['info'], filter, range_start, range_end, *args) self._initialize_xml(data, self.pool_name) - for element in self.xml: + for element in self.xml.findall(self.element_name): self.append(self._factory(element)) def _factory(self): diff --git a/oca/template.py b/oca/template.py index 60d6541..531b81b 100644 --- a/oca/template.py +++ b/oca/template.py @@ -95,7 +95,7 @@ class VmTemplatePool(Pool): } def __init__(self, client): - super(VmTemplatePool, self).__init__('VMTEMPLATE_POOL', 'POOL', client) + super(VmTemplatePool, self).__init__('VMTEMPLATE_POOL', 'VMTEMPLATE', client) #def info(self, From 9dbc8eff1ac4c1ab85c38a2a4d76cd1aa59a1506 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 23 Jun 2015 22:49:07 +0200 Subject: [PATCH 7/8] Update user to OpenNebula 4.10 specification --- oca/tests/fixtures/user.xml | 16 +++++++--- oca/tests/fixtures/userpool.xml | 52 ++++++++++++++++++++++++++++----- oca/user.py | 36 ++++++++++++++--------- 3 files changed, 78 insertions(+), 26 deletions(-) diff --git a/oca/tests/fixtures/user.xml b/oca/tests/fixtures/user.xml index 59a6bcf..5fa11da 100644 --- a/oca/tests/fixtures/user.xml +++ b/oca/tests/fixtures/user.xml @@ -1,8 +1,16 @@ 3 - 1 - users + 0 + + 0 + + oneadmin dan - d22a12348334v33f71ba846572d25250d40701e72 - 0 + fe05bcdcdc4928012781a5f1a2a77cbb5398e106 + core + 1 + + diff --git a/oca/tests/fixtures/userpool.xml b/oca/tests/fixtures/userpool.xml index f28c68a..d0cfa8a 100644 --- a/oca/tests/fixtures/userpool.xml +++ b/oca/tests/fixtures/userpool.xml @@ -1,18 +1,54 @@ 0 - 1 - users + 0 + + 0 + + oneadmin oneadmin - f13a1234833436f71ab846572d251c0d40391e72 + fe05bcdcdc4928012781a5f1a2a77cbb5398e106 + core 1 + + + + 0 + + + + + 1 - 1 - users - dan - d22a12348334v33f71ba846572d25250d40701e72 - 0 + 0 + + 0 + + oneadmin + serveradmin + f9f3c8912fc6cc53012d743ded329c4f5fb035a5 + server_cipher + 1 + + + + 1 + + + + + + + + + + + diff --git a/oca/user.py b/oca/user.py index ec75c24..fda0b8c 100644 --- a/oca/user.py +++ b/oca/user.py @@ -1,23 +1,31 @@ # -*- coding: UTF-8 -*- -from pool import Pool, PoolElement +from pool import Pool, PoolElement, Template, extractString class User(PoolElement): METHODS = { - 'info' : 'user.info', - 'allocate' : 'user.allocate', - 'delete' : 'user.delete', - 'passwd' : 'user.passwd', - 'chgrp' : 'user.chgrp' + 'info': 'user.info', + 'allocate': 'user.allocate', + 'delete': 'user.delete', + 'passwd': 'user.passwd', + 'chgrp': 'user.chgrp' } XML_TYPES = { - 'id' : int, - 'gid' : int, - 'name' : str, - 'gname' : str, - 'password' : str, - 'enabled' : bool, + 'id': int, + 'gid': int, + 'group_ids': ['GROUPS', lambda group_ids: map(lambda group_id: int(group_id.text), group_ids)], + 'gname': extractString, + 'name': extractString, + 'password': extractString, + 'auth_driver': extractString, + 'enabled': bool, + 'template': ['TEMPLATE', Template], + #'datastore_quota': handled separately # see http://dev.opennebula.org/issues/3849 + #'network_quota': handled separately # see http://dev.opennebula.org/issues/3849 + #'vm_quota': handled separately # see http://dev.opennebula.org/issues/3849 + #'image_quota' # see http://dev.opennebula.org/issues/3849 + #'default_user_quotas' # see http://dev.opennebula.org/issues/3849 } ELEMENT_NAME = 'USER' @@ -64,11 +72,11 @@ def __repr__(self): class UserPool(Pool): METHODS = { - 'info' : 'userpool.info', + 'info': 'userpool.info', } def __init__(self, client): - super(UserPool, self).__init__('USER_POOL', 'POOL', client) + super(UserPool, self).__init__('USER_POOL', 'USER', client) def _factory(self, xml): u = User(xml, self.client) From 4b0d2c9442b0b637f634a8fba48a2aebfa565537 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 23 Jun 2015 23:13:25 +0200 Subject: [PATCH 8/8] Update vm to OpenNebula 4.10 specification --- oca/tests/fixtures/vm.xml | 136 +++++++++++++++-------------- oca/tests/fixtures/vmpool.xml | 158 ++++++++++++++++++++++++++++------ oca/vm.py | 117 ++++++++++++------------- 3 files changed, 260 insertions(+), 151 deletions(-) diff --git a/oca/tests/fixtures/vm.xml b/oca/tests/fixtures/vm.xml index 13ee63a..81cc236 100644 --- a/oca/tests/fixtures/vm.xml +++ b/oca/tests/fixtures/vm.xml @@ -1,67 +1,73 @@ - 6 - 0 - 0 - oneadmin - oneadmin - vm-example - 1277729095 - 3 - 3 - 1277375180 - 0 - dummy - 512 - 1 - 12345 - 0 - - - - - - - 0 - dummyhost - 0 - 1277375186 - 0 - 1277375186 - 1277375186 - 1277375186 - 0 - 0 - 0 - 0 - - + 6 + 0 + 0 + oneadmin + oneadmin + vm-example + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 1277729095 + 3 + 3 + 0 + 1277375180 + 0 + dummy + 512 + 1 + 12345 + 0 + + + + + + + 0 + dummyhost + 0 + 1277375186 + 0 + 1277375186 + 1277375186 + 1277375186 + 0 + 0 + 0 + 0 + + diff --git a/oca/tests/fixtures/vmpool.xml b/oca/tests/fixtures/vmpool.xml index 2676133..1dd6cba 100644 --- a/oca/tests/fixtures/vmpool.xml +++ b/oca/tests/fixtures/vmpool.xml @@ -5,11 +5,22 @@ 0 oneadmin oneadmin - oneadmin vm-example - 1277910006 + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 1277729095 3 3 + 0 1277375180 0 dummy @@ -17,7 +28,30 @@ 1 12345 0 - + @@ -42,30 +76,64 @@ 0 oneadmin oneadmin - oneadmin vm-in - 1277910006 + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 1277729095 3 3 - 1277377464 + 0 + 1277375180 0 dummy - 1024 - 2 + 512 + 1 12345 0 - + 0 - thost + dummyhost 0 - 1277377466 + 1277375186 0 - 1277377466 - 1277377466 - 1277377466 + 1277375186 + 1277375186 + 1277375186 0 0 0 @@ -79,30 +147,64 @@ 0 oneadmin oneadmin - oneadmin - vmext - 1277910006 - 4 - 5 - 1277377533 + vm-in + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 1277729095 + 3 + 3 + 0 + 1277375180 0 - thost - 256 + dummy + 512 1 12345 0 - + 0 - thost + dummyhost 0 - 1277377556 + 1277375186 0 - 1277377556 - 1277377556 - 1277377556 + 1277375186 + 1277375186 + 1277375186 0 0 0 diff --git a/oca/vm.py b/oca/vm.py index a7db753..7f33abd 100644 --- a/oca/vm.py +++ b/oca/vm.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -from pool import Pool, PoolElement, Template +from pool import Pool, PoolElement, Template, extractString class History(Template): @@ -9,15 +9,15 @@ def __repr__(self): class VirtualMachine(PoolElement): METHODS = { - 'info' : 'vm.info', - 'allocate' : 'vm.allocate', - 'action' : 'vm.action', - 'migrate' : 'vm.migrate', - 'deploy' : 'vm.deploy', - 'savedisk' : 'vm.savedisk', - 'delete' : 'vm.delete', - 'chown' : 'vm.chown', - 'update' : 'vm.update', + 'info': 'vm.info', + 'allocate': 'vm.allocate', + 'action': 'vm.action', + 'migrate': 'vm.migrate', + 'deploy': 'vm.deploy', + 'savedisk': 'vm.savedisk', + 'delete': 'vm.delete', + 'chown': 'vm.chown', + 'update': 'vm.update', } INIT = 0 @@ -32,14 +32,14 @@ class VirtualMachine(PoolElement): 'SUSPENDED', 'DONE', 'FAILED'] SHORT_VM_STATES = { - 'INIT' : 'init', - 'PENDING' : 'pend', - 'HOLD' : 'hold', - 'ACTIVE' : 'actv', - 'STOPPED' : 'stop', - 'SUSPENDED' : 'susp', - 'DONE' : 'done', - 'FAILED' : 'fail' + 'INIT': 'init', + 'PENDING': 'pend', + 'HOLD': 'hold', + 'ACTIVE': 'actv', + 'STOPPED': 'stop', + 'SUSPENDED': 'susp', + 'DONE': 'done', + 'FAILED': 'fail' } LCM_STATE = ['LCM_INIT', 'PROLOG', 'BOOT', 'RUNNING', 'MIGRATE', @@ -48,56 +48,57 @@ class VirtualMachine(PoolElement): 'SHUTDOWN', 'CANCEL', 'FAILURE', 'DELETE', 'UNKNOWN'] SHORT_LCM_STATES = { - 'LCM_INIT' : 'init', - 'PROLOG' : 'prol', - 'BOOT' : 'boot', - 'RUNNING' : 'runn', - 'MIGRATE' : 'migr', - 'SAVE_STOP' : 'save', - 'SAVE_SUSPEND' : 'save', - 'SAVE_MIGRATE' : 'save', + 'LCM_INIT': 'init', + 'PROLOG': 'prol', + 'BOOT': 'boot', + 'RUNNING': 'runn', + 'MIGRATE': 'migr', + 'SAVE_STOP': 'save', + 'SAVE_SUSPEND': 'save', + 'SAVE_MIGRATE': 'save', 'PROLOG_MIGRATE': 'migr', - 'PROLOG_RESUME' : 'prol', - 'EPILOG_STOP' : 'epil', - 'EPILOG' : 'epil', - 'SHUTDOWN' : 'shut', - 'CANCEL' : 'shut', - 'FAILURE' : 'fail', - 'DELETE' : 'dele', - 'UNKNOWN' : 'unkn', + 'PROLOG_RESUME': 'prol', + 'EPILOG_STOP': 'epil', + 'EPILOG': 'epil', + 'SHUTDOWN': 'shut', + 'CANCEL': 'shut', + 'FAILURE': 'fail', + 'DELETE': 'dele', + 'UNKNOWN': 'unkn', } MIGRATE_REASON = ['NONE', 'ERROR', 'STOP_RESUME', 'USER', 'CANCEL'] SHORT_MIGRATE_REASON = { - 'NONE' : 'none', - 'ERROR' : 'erro', - 'STOP_RESUME' : 'stop', - 'USER' : 'user', - 'CANCEL' : 'canc' + 'NONE': 'none', + 'ERROR': 'erro', + 'STOP_RESUME': 'stop', + 'USER': 'user', + 'CANCEL': 'canc' } XML_TYPES = { - 'id' : int, - 'uid' : int, - 'gid' : int, - 'uname' : str, - 'gname' : str, - 'name' : str, - 'deploy_id' : str, - 'last_poll' : int, - 'state' : int, - 'lcm_state' : int, - 'stime' : int, - 'etime' : int, - 'deploy_id' : str, - 'memory' : int, - 'cpu' : int, - 'net_tx' : int, - 'net_rx' : int, - 'template' : ['TEMPLATE', Template, ['NIC', 'DISK']], + 'id': int, + 'uid': int, + 'gid': int, + 'uname': extractString, + 'gname': extractString, + 'name': extractString, + #'permissions': ???, + 'last_poll': int, + 'state': int, + 'lcm_state': int, + 'resched': int, + 'stime': int, + 'etime': int, + 'deploy_id': extractString, + 'memory': int, + 'cpu': int, + 'net_tx': int, + 'net_rx': int, + 'template': ['TEMPLATE', Template, ['NIC', 'DISK']], 'user_template': ['USER_TEMPLATE', Template], - 'history_records' : ['HISTORY_RECORDS', lambda x: [History(i) + 'history_records': ['HISTORY_RECORDS', lambda x: [History(i) for i in x] if x is not None else []], }