Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.coverage
oca.egg*
.tox
.idea
5 changes: 3 additions & 2 deletions oca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,7 +120,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):
Expand All @@ -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]

5 changes: 3 additions & 2 deletions oca/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@


class OpenNebulaException(Exception):
pass

def __init__(self, data, return_code):
self.return_code = return_code
super(OpenNebulaException, self).__init__(data)
4 changes: 2 additions & 2 deletions oca/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions oca/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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='', hold=False, 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, hold, extra_template)
return id

def __repr__(self):
return '<oca.VmTemplate("%s")>' % self.name
Expand Down
17 changes: 16 additions & 1 deletion oca/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class VirtualMachine(PoolElement):
'delete': 'vm.delete',
'chown': 'vm.chown',
'update': 'vm.update',
'rename': 'vm.rename',
}

INIT = 0
Expand Down Expand Up @@ -92,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 []],
Expand Down Expand Up @@ -248,6 +249,20 @@ 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):
'''
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)

Expand Down
35 changes: 35 additions & 0 deletions oca/zone.py
Original file line number Diff line number Diff line change
@@ -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 '<oca.Zone("%s")>' % 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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: UTF-8 -*-
__version__ = '4.15.0a1'
__version__ = '4.15.anjuke16'

import os

Expand Down