diff options
| author | Armando Migliaccio <armando.migliaccio@citrix.com> | 2010-11-29 12:52:03 +0000 |
|---|---|---|
| committer | Armando Migliaccio <armando.migliaccio@citrix.com> | 2010-11-29 12:52:03 +0000 |
| commit | 9e34c9c7dc88d9e361c7f2d05e06b53ff68ee53f (patch) | |
| tree | 5b668e03fd1ebcfe71c9395556a480cd1d1cb9c9 | |
| parent | 9d26ad69bfeb88106a08f0f3f1e15ed621c18af2 (diff) | |
fixed deps
| -rw-r--r-- | nova/virt/xapi/__init__.py | 15 | ||||
| -rw-r--r-- | nova/virt/xapi/network_utils.py (renamed from nova/virt/xenapi/network_utils.py) | 16 | ||||
| -rw-r--r-- | nova/virt/xapi/novadeps.py (renamed from nova/virt/xenapi/novadeps.py) | 31 | ||||
| -rw-r--r-- | nova/virt/xapi/vm_utils.py (renamed from nova/virt/xenapi/vm_utils.py) | 36 | ||||
| -rw-r--r-- | nova/virt/xapi/vmops.py (renamed from nova/virt/xenapi/vmops.py) | 35 | ||||
| -rw-r--r-- | nova/virt/xapi/volumeops.py (renamed from nova/virt/xenapi/volumeops.py) | 4 | ||||
| -rw-r--r-- | nova/virt/xenapi.py | 11 |
7 files changed, 83 insertions, 65 deletions
diff --git a/nova/virt/xapi/__init__.py b/nova/virt/xapi/__init__.py new file mode 100644 index 000000000..3d598c463 --- /dev/null +++ b/nova/virt/xapi/__init__.py @@ -0,0 +1,15 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2010 Citrix Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. diff --git a/nova/virt/xenapi/network_utils.py b/nova/virt/xapi/network_utils.py index 83ade1389..b58b9159c 100644 --- a/nova/virt/xenapi/network_utils.py +++ b/nova/virt/xapi/network_utils.py @@ -15,19 +15,17 @@ # under the License. """ -Helper methods for operations related to the management of network records and +Helper methods for operations related to the management of network records and their attributes like bridges, PIFs, QoS, as well as their lookup functions. """ -import logging -import xmlrpclib - from twisted.internet import defer -from twisted.internet import reactor -from twisted.internet import task - - + + class NetworkHelper(): + def __init__(self, session): + return + @classmethod @defer.inlineCallbacks def find_network_with_bridge(self, session, bridge): @@ -39,4 +37,4 @@ class NetworkHelper(): elif len(networks) > 1: raise Exception('Found non-unique network for bridge %s' % bridge) else: - raise Exception('Found no network for bridge %s' % bridge)
\ No newline at end of file + raise Exception('Found no network for bridge %s' % bridge) diff --git a/nova/virt/xenapi/novadeps.py b/nova/virt/xapi/novadeps.py index a4e512263..8cb5e3246 100644 --- a/nova/virt/xenapi/novadeps.py +++ b/nova/virt/xapi/novadeps.py @@ -22,7 +22,7 @@ from nova import utils from nova.compute import power_state from nova.auth.manager import AuthManager from nova.compute import instance_types -from nova.virt import images +from nova.virt import images XENAPI_POWER_STATE = { 'Halted': power_state.SHUTDOWN, @@ -30,33 +30,34 @@ XENAPI_POWER_STATE = { 'Paused': power_state.PAUSED, 'Suspended': power_state.SHUTDOWN, # FIXME 'Crashed': power_state.CRASHED} - + + class Instance(object): @classmethod def get_name(self, instance): return instance.name - + @classmethod def get_type(self, instance): return instance_types.INSTANCE_TYPES[instance.instance_type] - + @classmethod def get_project(self, instance): return AuthManager().get_project(instance.project_id) - + @classmethod def get_project_id(self, instance): return instance.project_id - + @classmethod def get_image_id(self, instance): return instance.image_id - + @classmethod def get_kernel_id(self, instance): return instance.kernel_id - + @classmethod def get_ramdisk_id(self, instance): return instance.ramdisk_id @@ -64,28 +65,30 @@ class Instance(object): @classmethod def get_network(self, instance): return db.project_get_network(None, instance.project_id) - + @classmethod def get_mac(self, instance): return instance.mac_address - + @classmethod def get_user(self, instance): return AuthManager().get_user(instance.user_id) - + class Network(object): @classmethod def get_bridge(self, network): return network.bridge - + + class Image(object): @classmethod def get_url(self, image): return images.image_url(image) - + + class User(object): @classmethod @@ -94,4 +97,4 @@ class User(object): @classmethod def get_secret(self, user): - return user.secret
\ No newline at end of file + return user.secret diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xapi/vm_utils.py index a1b444e41..41f687ccb 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xapi/vm_utils.py @@ -15,35 +15,32 @@ # under the License. """ -Helper methods for operations related to the management of VM records and +Helper methods for operations related to the management of VM records and their attributes like VDIs, VIFs, as well as their lookup functions. """ import logging -import xmlrpclib from twisted.internet import defer -from twisted.internet import reactor -from twisted.internet import task -from nova import db -from nova import flags -from nova import process from nova import utils from novadeps import Instance from novadeps import Image from novadeps import User - - + + class VMHelper(): + def __init__(self, session): + return + @classmethod @defer.inlineCallbacks def create_vm(self, session, instance, kernel, ramdisk): """Create a VM record. Returns a Deferred that gives the new VM reference.""" - instance_type = Instance.get_type(instance) + instance_type = Instance.get_type(instance) mem = str(long(instance_type['memory_mb']) * 1024 * 1024) vcpus = str(instance_type['vcpus']) rec = { @@ -77,10 +74,11 @@ class VMHelper(): } logging.debug('Created VM %s...', Instance.get_name(instance)) vm_ref = yield session.call_xenapi('VM.create', rec) - logging.debug('Created VM %s as %s.', Instance.get_name(instance), vm_ref) + logging.debug('Created VM %s as %s.', + Instance.get_name(instance), vm_ref) defer.returnValue(vm_ref) - - @classmethod + + @classmethod @defer.inlineCallbacks def create_vbd(self, session, vm_ref, vdi_ref, userdevice, bootable): """Create a VBD record. Returns a Deferred that gives the new @@ -105,7 +103,7 @@ class VMHelper(): vdi_ref) defer.returnValue(vbd_ref) - @classmethod + @classmethod @defer.inlineCallbacks def create_vif(self, session, vm_ref, network_ref, mac_address): """Create a VIF record. Returns a Deferred that gives the new @@ -147,9 +145,9 @@ class VMHelper(): args['add_partition'] = 'true' task = yield session.async_call_plugin('objectstore', fn, args) uuid = yield session.wait_for_task(task) - defer.returnValue(uuid) - - @classmethod + defer.returnValue(uuid) + + @classmethod @utils.deferredToThread def lookup(self, session, i): return VMHelper.lookup_blocking(session, i) @@ -165,7 +163,7 @@ class VMHelper(): else: return vms[0] - @classmethod + @classmethod @utils.deferredToThread def lookup_vm_vdis(self, session, vm): return VMHelper.lookup_vm_vdis_blocking(session, vm) @@ -189,4 +187,4 @@ class VMHelper(): if len(vdis) > 0: return vdis else: - return None
\ No newline at end of file + return None diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xapi/vmops.py index c04a9f4ec..d6ea5e7db 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xapi/vmops.py @@ -19,24 +19,21 @@ Management class for VM-related functions (spawn, reboot, etc). """ import logging -import xmlrpclib from twisted.internet import defer -from twisted.internet import reactor -from twisted.internet import task - -import VMHelper -import NetworkHelper from novadeps import XENAPI_POWER_STATE -from novadeps import Auth from novadeps import Instance from novadeps import Network +from vm_utils import VMHelper +from network_utils import NetworkHelper + + class VMOps(object): def __init__(self, session): self._session = session - + def list_instances(self): return [self._session.get_xenapi().VM.get_name_label(vm) \ for vm in self._session.get_xenapi().VM.get_all()] @@ -48,9 +45,9 @@ class VMOps(object): raise Exception('Attempted to create non-unique name %s' % Instance.get_name(instance)) - network = Instance.get_network(instance) + bridge = Network.get_bridge(Instance.get_network(instance)) network_ref = \ - yield NetworkHelper.find_network_with_bridge(self._session, Network.get_bridge(network)) + yield NetworkHelper.find_network_with_bridge(self._session, bridge) user = Instance.get_user(instance) project = Instance.get_project(instance) @@ -61,14 +58,16 @@ class VMOps(object): ramdisk = yield VMHelper.fetch_image(self._session, Instance.get_ramdisk_id(instance), user, project, False) vdi_ref = yield self._session.call_xenapi('VDI.get_by_uuid', vdi_uuid) - - vm_ref = yield VMHelper.create_vm(self._session, instance, kernel, ramdisk) + vm_ref = yield VMHelper.create_vm(self._session, + instance, kernel, ramdisk) yield VMHelper.create_vbd(self._session, vm_ref, vdi_ref, 0, True) if network_ref: - yield VMHelper.create_vif(self._session, vm_ref, network_ref, Instance.get_mac(instance)) + yield VMHelper.create_vif(self._session, vm_ref, + network_ref, Instance.get_mac(instance)) logging.debug('Starting VM %s...', vm_ref) yield self._session.call_xenapi('VM.start', vm_ref, False, False) - logging.info('Spawning VM %s created %s.', Instance.get_name(instance), vm_ref) + logging.info('Spawning VM %s created %s.', Instance.get_name(instance), + vm_ref) @defer.inlineCallbacks def reboot(self, instance): @@ -89,7 +88,8 @@ class VMOps(object): # Get the VDIs related to the VM vdis = yield VMHelper.lookup_vm_vdis(self._session, vm) try: - task = yield self._session.call_xenapi('Async.VM.hard_shutdown', vm) + task = yield self._session.call_xenapi('Async.VM.hard_shutdown', + vm) yield self._session.wait_for_task(task) except Exception, exc: logging.warn(exc) @@ -97,7 +97,8 @@ class VMOps(object): if vdis: for vdi in vdis: try: - task = yield self._session.call_xenapi('Async.VDI.destroy', vdi) + task = yield self._session.call_xenapi('Async.VDI.destroy', + vdi) yield self._session.wait_for_task(task) except Exception, exc: logging.warn(exc) @@ -119,4 +120,4 @@ class VMOps(object): 'cpu_time': 0} def get_console_output(self, instance): - return 'FAKE CONSOLE OUTPUT'
\ No newline at end of file + return 'FAKE CONSOLE OUTPUT' diff --git a/nova/virt/xenapi/volumeops.py b/nova/virt/xapi/volumeops.py index fd316a0b8..23f79adf7 100644 --- a/nova/virt/xenapi/volumeops.py +++ b/nova/virt/xapi/volumeops.py @@ -19,7 +19,7 @@ Management class for Storage-related functions (attach, detach, etc). """ -class VMOps(object): +class VolumeOps(object): def __init__(self, session): self._session = session @@ -27,4 +27,4 @@ class VMOps(object): return True def detach_volume(self, instance_name, mountpoint): - return True
\ No newline at end of file + return True diff --git a/nova/virt/xenapi.py b/nova/virt/xenapi.py index 2f2cef75e..613f19f82 100644 --- a/nova/virt/xenapi.py +++ b/nova/virt/xenapi.py @@ -52,10 +52,13 @@ import xmlrpclib from twisted.internet import defer from twisted.internet import reactor -from twisted.internet import task +#from twisted.internet import task -from xenapi import VMOps -from xenapi import VolumeOps +from nova import flags +from nova import utils + +from xapi.vmops import VMOps +from xapi.volumeops import VolumeOps XenAPI = None @@ -151,7 +154,7 @@ class XenAPISession(object): for m in method.split('.'): f = f.__getattr__(m) return f(*args) - + @utils.deferredToThread def async_call_plugin(self, plugin, fn, args): """Call Async.host.call_plugin on a background thread. Returns a |
