From f5d7e38b8d70adf2e679deb31f3ee63f5ac57105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=9B=BD=E7=A5=A5?= Date: Fri, 15 Jul 2016 11:41:14 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E5=8C=85=E5=90=ABreturn=5Fcode=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + oca/__init__.py | 2 +- oca/exceptions.py | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2731c8f..ba797f1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.coverage oca.egg* .tox +.idea \ No newline at end of file diff --git a/oca/__init__.py b/oca/__init__.py index 3582129..553d65e 100644 --- a/oca/__init__.py +++ b/oca/__init__.py @@ -119,7 +119,7 @@ def call(self, function, *args): #connection error raise e if not is_success: - raise OpenNebulaException(data) + raise OpenNebulaException(data, return_code) return data def version(self): diff --git a/oca/exceptions.py b/oca/exceptions.py index c308d45..41d0b57 100644 --- a/oca/exceptions.py +++ b/oca/exceptions.py @@ -2,5 +2,6 @@ class OpenNebulaException(Exception): - pass - + def __init__(self, data, return_code): + self.return_code = return_code + super(OpenNebulaException, self).__init__(data) From b8f061923bcfa1fabebf56eddaa8217d1f1dc8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=9B=BD=E7=A5=A5?= Date: Tue, 19 Jul 2016 15:19:22 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oca/pool.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oca/pool.py b/oca/pool.py index 422dc01..e526255 100644 --- a/oca/pool.py +++ b/oca/pool.py @@ -13,7 +13,7 @@ class WrongIdError(OpenNebulaException): pass def extractString(xml_or_string): - if isinstance(xml_or_string, str): + if isinstance(xml_or_string, basestring): return xml_or_string else: return xml_or_string.text or '' @@ -53,7 +53,7 @@ def __init__(self, xml=None): def _initialize_xml(self, xml, root_element): hidden_character=u"\u200b" - self.xml = ET.fromstring(xml.replace(hidden_character,"")) + self.xml = ET.fromstring(xml.replace(hidden_character,"").encode("utf-8")) if self.xml.tag != root_element.upper(): self.xml = None self._convert_types() From 197c567d05010fb6dacdc26b67740df68117cbf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=9B=BD=E7=A5=A5?= Date: Tue, 19 Jul 2016 15:19:32 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=94=AF=E6=8C=81zone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oca/__init__.py | 3 ++- oca/zone.py | 35 +++++++++++++++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 oca/zone.py diff --git a/oca/__init__.py b/oca/__init__.py index 553d65e..3d827b1 100644 --- a/oca/__init__.py +++ b/oca/__init__.py @@ -16,6 +16,7 @@ from exceptions import OpenNebulaException from cluster import Cluster, ClusterPool from datastore import Datastore, DatastorePool +from zone import Zone, ZonePool CONNECTED = -3 @@ -132,5 +133,5 @@ def version(self): VirtualMachinePool, User, UserPool, Image, ImagePool, VirtualNetwork, VirtualNetworkPool, Group, GroupPool, VmTemplate, VmTemplatePool, ALL, CONNECTED, - Cluster, ClusterPool, Datastore, DatastorePool] + Cluster, ClusterPool, Datastore, DatastorePool, Zone, ZonePool] diff --git a/oca/zone.py b/oca/zone.py new file mode 100644 index 0000000..f4f9d5c --- /dev/null +++ b/oca/zone.py @@ -0,0 +1,35 @@ +# coding: utf-8 +from pool import Pool, PoolElement, Template, extractString + + +class Zone(PoolElement): + METHODS = { + } + + XML_TYPES = { + 'id': int, + 'name': extractString, + 'template': ['TEMPLATE', Template], + } + + ELEMENT_NAME = 'ZONE' + + def __init__(self, xml, client): + super(Zone, self).__init__(xml, client) + self._convert_types() + + def __repr__(self): + return '' % self.name + + +class ZonePool(Pool): + METHODS = { + 'info': 'zonepool.info', + } + + def __init__(self, client): + super(ZonePool, self).__init__('ZONE_POOL', 'ZONE', client) + + def _factory(self, xml): + c = Zone(xml, self.client) + return c diff --git a/setup.py b/setup.py index f7f83d4..8cea3d5 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -__version__ = '4.15.0a1' +__version__ = '4.15.anjuke7' import os From 4329801fc502842fbb6da62e2e141c72dfaf0cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=9B=BD=E7=A5=A5?= Date: Wed, 20 Jul 2016 19:00:08 +0800 Subject: [PATCH 4/9] =?UTF-8?q?template=E6=94=AF=E6=8C=81=20extra=20templa?= =?UTF-8?q?te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oca/template.py | 6 ++++-- setup.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/oca/template.py b/oca/template.py index 531b81b..d8823fa 100644 --- a/oca/template.py +++ b/oca/template.py @@ -76,14 +76,16 @@ def chown(self, uid=-1, gid=-1): ''' self.client.call(VmTemplate.METHODS['chown'], self.id, uid, gid) - def instantiate(self, name=''): + def instantiate(self, name='', extra_template=''): ''' Creates a VM instance from a VmTemplate ``name`` name of the VM instance ''' - self.client.call(VmTemplate.METHODS['instantiate'], self.id, name) + # id = self.client.call(VmTemplate.METHODS['instantiate'], self.id, name) + id = self.client.call(VmTemplate.METHODS['instantiate'], self.id, name, False, extra_template) + return id def __repr__(self): return '' % self.name diff --git a/setup.py b/setup.py index 8cea3d5..d88fd93 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -__version__ = '4.15.anjuke7' +__version__ = '4.15.anjuke11' import os From b7e8b80f7a2f561bc10ea4a9e86e0426201eed58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=9B=BD=E7=A5=A5?= Date: Fri, 22 Jul 2016 15:22:55 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fix=20bug:=20=E5=8F=AF=E4=BB=A5=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E7=9A=84=E6=98=BE=E7=A4=BAvmtemplate=E4=B8=AD?= =?UTF-8?q?=E7=9A=84disk,nic=E7=AD=89=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oca/template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oca/template.py b/oca/template.py index d8823fa..8471f6c 100644 --- a/oca/template.py +++ b/oca/template.py @@ -21,7 +21,7 @@ class VmTemplate(PoolElement): 'uname' : str, 'gname' : str, 'regtime' : int, - 'template' : ['TEMPLATE', Template] + 'template' : ['TEMPLATE', Template, ['DISK', 'OS', 'NIC', 'GRAPHICS', 'CONTEXT']] } ELEMENT_NAME = 'VMTEMPLATE' From 71cdc91f02543980a93693bcaada534378392004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=9B=BD=E7=A5=A5?= Date: Fri, 22 Jul 2016 15:23:14 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d88fd93..1f24dc4 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -__version__ = '4.15.anjuke11' +__version__ = '4.15.anjuke12' import os From 0fe5bc471acc86ce9fa89f7df717c7a2fe0c0e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=9B=BD=E7=A5=A5?= Date: Fri, 22 Jul 2016 16:17:07 +0800 Subject: [PATCH 7/9] fix bug --- oca/template.py | 4 ++-- oca/vm.py | 8 ++++++++ setup.py | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/oca/template.py b/oca/template.py index 8471f6c..7de3998 100644 --- a/oca/template.py +++ b/oca/template.py @@ -76,7 +76,7 @@ def chown(self, uid=-1, gid=-1): ''' self.client.call(VmTemplate.METHODS['chown'], self.id, uid, gid) - def instantiate(self, name='', extra_template=''): + def instantiate(self, name='', hold=False, extra_template=''): ''' Creates a VM instance from a VmTemplate @@ -84,7 +84,7 @@ def instantiate(self, name='', extra_template=''): name of the VM instance ''' # id = self.client.call(VmTemplate.METHODS['instantiate'], self.id, name) - id = self.client.call(VmTemplate.METHODS['instantiate'], self.id, name, False, extra_template) + id = self.client.call(VmTemplate.METHODS['instantiate'], self.id, name, hold, extra_template) return id def __repr__(self): diff --git a/oca/vm.py b/oca/vm.py index 765be98..9fd3930 100644 --- a/oca/vm.py +++ b/oca/vm.py @@ -18,6 +18,7 @@ class VirtualMachine(PoolElement): 'delete': 'vm.delete', 'chown': 'vm.chown', 'update': 'vm.update', + 'rename': 'vm.rename', } INIT = 0 @@ -248,6 +249,13 @@ def delete(self): ''' self._action('delete') + def rename(self, name): + ''' + Rename the VM. + ''' + data = self.client.call(self.METHODS['rename'], self.id, name) + return data + def _action(self, action): self.client.call(self.METHODS['action'], action, self.id) diff --git a/setup.py b/setup.py index 1f24dc4..879bbb9 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -__version__ = '4.15.anjuke12' +__version__ = '4.15.anjuke13' import os From 4e15ab1ca39b763a856411eb33e0ecc8bb73384a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=9B=BD=E7=A5=A5?= Date: Tue, 26 Jul 2016 16:07:07 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD:=20one.vm.actio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oca/vm.py | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/oca/vm.py b/oca/vm.py index 9fd3930..cc547a3 100644 --- a/oca/vm.py +++ b/oca/vm.py @@ -256,6 +256,13 @@ def rename(self, name): data = self.client.call(self.METHODS['rename'], self.id, name) return data + def action(self, action): + ''' + submits an action to be performed on a virtual machine. + ''' + data = self.client.call(self.METHODS['action'], action, self.id) + return data + def _action(self, action): self.client.call(self.METHODS['action'], action, self.id) diff --git a/setup.py b/setup.py index 879bbb9..5dd7065 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -__version__ = '4.15.anjuke13' +__version__ = '4.15.anjuke15' import os From 735ad63400de6bec0055178e9f87ead19a83a57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=9B=BD=E7=A5=A5?= Date: Wed, 27 Jul 2016 16:11:52 +0800 Subject: [PATCH 9/9] fix bug --- oca/vm.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/oca/vm.py b/oca/vm.py index cc547a3..86db87b 100644 --- a/oca/vm.py +++ b/oca/vm.py @@ -93,7 +93,7 @@ class VirtualMachine(PoolElement): 'stime': int, 'etime': int, 'deploy_id': extractString, - 'template': ['TEMPLATE', Template, ['NIC', 'DISK']], + 'template': ['TEMPLATE', Template, ['NIC', 'DISK', 'GRAPHICS']], 'user_template': ['USER_TEMPLATE', Template], 'history_records': ['HISTORY_RECORDS', lambda x: [History(i) for i in x] if x is not None else []], diff --git a/setup.py b/setup.py index 5dd7065..ed97fa7 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- -__version__ = '4.15.anjuke15' +__version__ = '4.15.anjuke16' import os