summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorBrian Lamar <brian.lamar@rackspace.com>2011-04-21 16:18:49 -0400
committerBrian Lamar <brian.lamar@rackspace.com>2011-04-21 16:18:49 -0400
commit18388b26c0e28df103d07ad0cc28fd9bfaab6416 (patch)
tree526b9004c1f6c7eeb82dcff2aa96a6b4f7596bac /nova/compute
parent6c037c5c639249556fcadd871d8af91760b50e90 (diff)
parentbec71bed9450d13202fdd7f54946e1376b271a2c (diff)
Merged trunk and fixed api servers conflict.
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/manager.py236
1 files changed, 105 insertions, 131 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 46f910b27..d1e6692b3 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -17,8 +17,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-"""
-Handles all processes relating to instances (guest vms).
+"""Handles all processes relating to instances (guest vms).
The :py:class:`ComputeManager` class is a :py:class:`nova.manager.Manager` that
handles RPC calls relating to creating instances. It is responsible for
@@ -33,6 +32,7 @@ terminating it.
by :func:`nova.utils.import_object`
:volume_manager: Name of class that handles persistent storage, loaded by
:func:`nova.utils.import_object`
+
"""
import datetime
@@ -55,6 +55,7 @@ from nova import utils
from nova.compute import power_state
from nova.virt import driver
+
FLAGS = flags.FLAGS
flags.DEFINE_string('instances_path', '$state_path/instances',
'where instances are stored on disk')
@@ -74,19 +75,14 @@ flags.DEFINE_integer("rescue_timeout", 0,
"Automatically unrescue an instance after N seconds."
" Set to 0 to disable.")
+
LOG = logging.getLogger('nova.compute.manager')
def checks_instance_lock(function):
- """
- decorator used for preventing action against locked instances
- unless, of course, you happen to be admin
-
- """
-
+ """Decorator to prevent action against locked instances for non-admins."""
@functools.wraps(function)
def decorated_function(self, context, instance_id, *args, **kwargs):
-
LOG.info(_("check_instance_lock: decorating: |%s|"), function,
context=context)
LOG.info(_("check_instance_lock: arguments: |%(self)s| |%(context)s|"
@@ -112,7 +108,6 @@ def checks_instance_lock(function):
class ComputeManager(manager.SchedulerDependentManager):
-
"""Manages the running instances from creation to destruction."""
def __init__(self, compute_driver=None, *args, **kwargs):
@@ -136,9 +131,7 @@ class ComputeManager(manager.SchedulerDependentManager):
*args, **kwargs)
def init_host(self):
- """Do any initialization that needs to be run if this is a
- standalone service.
- """
+ """Initialization for a standalone compute service."""
self.driver.init_host(host=self.host)
def _update_state(self, context, instance_id, state=None):
@@ -169,16 +162,18 @@ class ComputeManager(manager.SchedulerDependentManager):
self.db.instance_update(context, instance_id, data)
def get_console_topic(self, context, **kwargs):
- """Retrieves the console host for a project on this host
- Currently this is just set in the flags for each compute
- host."""
+ """Retrieves the console host for a project on this host.
+
+ Currently this is just set in the flags for each compute host.
+
+ """
#TODO(mdragon): perhaps make this variable by console_type?
return self.db.queue_get_for(context,
FLAGS.console_topic,
FLAGS.console_host)
def get_network_topic(self, context, **kwargs):
- """Retrieves the network host for a project on this host"""
+ """Retrieves the network host for a project on this host."""
# TODO(vish): This method should be memoized. This will make
# the call to get_network_host cheaper, so that
# it can pas messages instead of checking the db
@@ -195,15 +190,23 @@ class ComputeManager(manager.SchedulerDependentManager):
return self.driver.get_console_pool_info(console_type)
@exception.wrap_exception
- def refresh_security_group_rules(self, context,
- security_group_id, **kwargs):
- """This call passes straight through to the virtualization driver."""
+ def refresh_security_group_rules(self, context, security_group_id,
+ **kwargs):
+ """Tell the virtualization driver to refresh security group rules.
+
+ Passes straight through to the virtualization driver.
+
+ """
return self.driver.refresh_security_group_rules(security_group_id)
@exception.wrap_exception
def refresh_security_group_members(self, context,
security_group_id, **kwargs):
- """This call passes straight through to the virtualization driver."""
+ """Tell the virtualization driver to refresh security group members.
+
+ Passes straight through to the virtualization driver.
+
+ """
return self.driver.refresh_security_group_members(security_group_id)
@exception.wrap_exception
@@ -257,7 +260,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def terminate_instance(self, context, instance_id):
- """Terminate an instance on this machine."""
+ """Terminate an instance on this host."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.audit(_("Terminating instance %s"), instance_id, context=context)
@@ -332,7 +335,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def reboot_instance(self, context, instance_id):
- """Reboot an instance on this server."""
+ """Reboot an instance on this host."""
context = context.elevated()
self._update_state(context, instance_id)
instance_ref = self.db.instance_get(context, instance_id)
@@ -356,7 +359,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
def snapshot_instance(self, context, instance_id, image_id):
- """Snapshot an instance on this server."""
+ """Snapshot an instance on this host."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
@@ -379,7 +382,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def set_admin_password(self, context, instance_id, new_pass=None):
- """Set the root/admin password for an instance on this server."""
+ """Set the root/admin password for an instance on this host."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
instance_id = instance_ref['id']
@@ -400,7 +403,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def inject_file(self, context, instance_id, path, file_contents):
- """Write a file to the specified path on an instance on this server"""
+ """Write a file to the specified path in an instance on this host."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
instance_id = instance_ref['id']
@@ -418,44 +421,34 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def rescue_instance(self, context, instance_id):
- """Rescue an instance on this server."""
+ """Rescue an instance on this host."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.audit(_('instance %s: rescuing'), instance_id, context=context)
- self.db.instance_set_state(
- context,
- instance_id,
- power_state.NOSTATE,
- 'rescuing')
+ self.db.instance_set_state(context,
+ instance_id,
+ power_state.NOSTATE,
+ 'rescuing')
self.network_manager.setup_compute_network(context, instance_id)
- self.driver.rescue(
- instance_ref,
- lambda result: self._update_state_callback(
- self,
- context,
- instance_id,
- result))
+ _update_state = lambda result: self._update_state_callback(
+ self, context, instance_id, result)
+ self.driver.rescue(instance_ref, _update_state)
self._update_state(context, instance_id)
@exception.wrap_exception
@checks_instance_lock
def unrescue_instance(self, context, instance_id):
- """Rescue an instance on this server."""
+ """Rescue an instance on this host."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.audit(_('instance %s: unrescuing'), instance_id, context=context)
- self.db.instance_set_state(
- context,
- instance_id,
- power_state.NOSTATE,
- 'unrescuing')
- self.driver.unrescue(
- instance_ref,
- lambda result: self._update_state_callback(
- self,
- context,
- instance_id,
- result))
+ self.db.instance_set_state(context,
+ instance_id,
+ power_state.NOSTATE,
+ 'unrescuing')
+ _update_state = lambda result: self._update_state_callback(
+ self, context, instance_id, result)
+ self.driver.unrescue(instance_ref, _update_state)
self._update_state(context, instance_id)
@staticmethod
@@ -466,7 +459,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def confirm_resize(self, context, instance_id, migration_id):
- """Destroys the source instance"""
+ """Destroys the source instance."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
self.driver.destroy(instance_ref)
@@ -474,9 +467,12 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def revert_resize(self, context, instance_id, migration_id):
- """Destroys the new instance on the destination machine,
- reverts the model changes, and powers on the old
- instance on the source machine"""
+ """Destroys the new instance on the destination machine.
+
+ Reverts the model changes, and powers on the old instance on the
+ source machine.
+
+ """
instance_ref = self.db.instance_get(context, instance_id)
migration_ref = self.db.migration_get(context, migration_id)
@@ -493,9 +489,12 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def finish_revert_resize(self, context, instance_id, migration_id):
- """Finishes the second half of reverting a resize, powering back on
- the source instance and reverting the resized attributes in the
- database"""
+ """Finishes the second half of reverting a resize.
+
+ Power back on the source instance and revert the resized attributes
+ in the database.
+
+ """
instance_ref = self.db.instance_get(context, instance_id)
migration_ref = self.db.migration_get(context, migration_id)
instance_type = self.db.instance_type_get_by_flavor_id(context,
@@ -515,8 +514,11 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def prep_resize(self, context, instance_id, flavor_id):
- """Initiates the process of moving a running instance to another
- host, possibly changing the RAM and disk size in the process"""
+ """Initiates the process of moving a running instance to another host.
+
+ Possibly changes the RAM and disk size in the process.
+
+ """
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
if instance_ref['host'] == FLAGS.host:
@@ -548,35 +550,38 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def resize_instance(self, context, instance_id, migration_id):
- """Starts the migration of a running instance to another host"""
+ """Starts the migration of a running instance to another host."""
migration_ref = self.db.migration_get(context, migration_id)
instance_ref = self.db.instance_get(context, instance_id)
- self.db.migration_update(context, migration_id,
- {'status': 'migrating', })
-
- disk_info = self.driver.migrate_disk_and_power_off(instance_ref,
- migration_ref['dest_host'])
- self.db.migration_update(context, migration_id,
- {'status': 'post-migrating', })
-
- # Make sure the service exists before sending a message.
- _service = self.db.service_get_by_host_and_topic(context,
- migration_ref['dest_compute'], FLAGS.compute_topic)
- topic = self.db.queue_get_for(context, FLAGS.compute_topic,
- migration_ref['dest_compute'])
- rpc.cast(context, topic,
- {'method': 'finish_resize',
- 'args': {
- 'migration_id': migration_id,
- 'instance_id': instance_id,
- 'disk_info': disk_info, },
- })
+ self.db.migration_update(context,
+ migration_id,
+ {'status': 'migrating'})
+
+ disk_info = self.driver.migrate_disk_and_power_off(
+ instance_ref, migration_ref['dest_host'])
+ self.db.migration_update(context,
+ migration_id,
+ {'status': 'post-migrating'})
+
+ service = self.db.service_get_by_host_and_topic(
+ context, migration_ref['dest_compute'], FLAGS.compute_topic)
+ topic = self.db.queue_get_for(context,
+ FLAGS.compute_topic,
+ migration_ref['dest_compute'])
+ rpc.cast(context, topic, {'method': 'finish_resize',
+ 'args': {'migration_id': migration_id,
+ 'instance_id': instance_id,
+ 'disk_info': disk_info}})
@exception.wrap_exception
@checks_instance_lock
def finish_resize(self, context, instance_id, migration_id, disk_info):
- """Completes the migration process by setting up the newly transferred
- disk and turning on the instance on its new host machine"""
+ """Completes the migration process.
+
+ Sets up the newly transferred disk and turns on the instance at its
+ new host machine.
+
+ """
migration_ref = self.db.migration_get(context, migration_id)
instance_ref = self.db.instance_get(context,
migration_ref['instance_id'])
@@ -601,7 +606,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def pause_instance(self, context, instance_id):
- """Pause an instance on this server."""
+ """Pause an instance on this host."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.audit(_('instance %s: pausing'), instance_id, context=context)
@@ -618,7 +623,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def unpause_instance(self, context, instance_id):
- """Unpause a paused instance on this server."""
+ """Unpause a paused instance on this host."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.audit(_('instance %s: unpausing'), instance_id, context=context)
@@ -634,7 +639,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
def get_diagnostics(self, context, instance_id):
- """Retrieve diagnostics for an instance on this server."""
+ """Retrieve diagnostics for an instance on this host."""
instance_ref = self.db.instance_get(context, instance_id)
if instance_ref["state"] == power_state.RUNNING:
@@ -645,10 +650,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def suspend_instance(self, context, instance_id):
- """
- suspend the instance with instance_id
-
- """
+ """Suspend the given instance."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.audit(_('instance %s: suspending'), instance_id, context=context)
@@ -664,10 +666,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
def resume_instance(self, context, instance_id):
- """
- resume the suspended instance with instance_id
-
- """
+ """Resume the given suspended instance."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.audit(_('instance %s: resuming'), instance_id, context=context)
@@ -682,10 +681,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
def lock_instance(self, context, instance_id):
- """
- lock the instance with instance_id
-
- """
+ """Lock the given instance."""
context = context.elevated()
LOG.debug(_('instance %s: locking'), instance_id, context=context)
@@ -693,10 +689,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
def unlock_instance(self, context, instance_id):
- """
- unlock the instance with instance_id
-
- """
+ """Unlock the given instance."""
context = context.elevated()
LOG.debug(_('instance %s: unlocking'), instance_id, context=context)
@@ -704,10 +697,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
def get_lock(self, context, instance_id):
- """
- return the boolean state of (instance with instance_id)'s lock
-
- """
+ """Return the boolean state of the given instance's lock."""
context = context.elevated()
LOG.debug(_('instance %s: getting locked state'), instance_id,
context=context)
@@ -716,10 +706,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@checks_instance_lock
def reset_network(self, context, instance_id):
- """
- Reset networking on the instance.
-
- """
+ """Reset networking on the given instance."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.debug(_('instance %s: reset network'), instance_id,
@@ -728,10 +715,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@checks_instance_lock
def inject_network_info(self, context, instance_id):
- """
- Inject network info for the instance.
-
- """
+ """Inject network info for the given instance."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.debug(_('instance %s: inject network info'), instance_id,
@@ -740,7 +724,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
def get_console_output(self, context, instance_id):
- """Send the console output for an instance."""
+ """Send the console output for the given instance."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.audit(_("Get console output for instance %s"), instance_id,
@@ -749,20 +733,18 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
def get_ajax_console(self, context, instance_id):
- """Return connection information for an ajax console"""
+ """Return connection information for an ajax console."""
context = context.elevated()
LOG.debug(_("instance %s: getting ajax console"), instance_id)
instance_ref = self.db.instance_get(context, instance_id)
-
return self.driver.get_ajax_console(instance_ref)
@exception.wrap_exception
def get_vnc_console(self, context, instance_id):
- """Return connection information for an vnc console."""
+ """Return connection information for a vnc console."""
context = context.elevated()
LOG.debug(_("instance %s: getting vnc console"), instance_id)
instance_ref = self.db.instance_get(context, instance_id)
-
return self.driver.get_vnc_console(instance_ref)
@checks_instance_lock
@@ -816,7 +798,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
def compare_cpu(self, context, cpu_info):
- """Checks the host cpu is compatible to a cpu given by xml.
+ """Checks that the host cpu is compatible with a cpu given by xml.
:param context: security context
:param cpu_info: json string obtained from virConnect.getCapabilities
@@ -837,7 +819,6 @@ class ComputeManager(manager.SchedulerDependentManager):
:returns: tmpfile name(basename)
"""
-
dirpath = FLAGS.instances_path
fd, tmp_file = tempfile.mkstemp(dir=dirpath)
LOG.debug(_("Creating tmpfile %s to notify to other "
@@ -854,7 +835,6 @@ class ComputeManager(manager.SchedulerDependentManager):
:param filename: confirm existence of FLAGS.instances_path/thisfile
"""
-
tmp_file = os.path.join(FLAGS.instances_path, filename)
if not os.path.exists(tmp_file):
raise exception.NotFound(_('%s not found') % tmp_file)
@@ -867,7 +847,6 @@ class ComputeManager(manager.SchedulerDependentManager):
:param filename: remove existence of FLAGS.instances_path/thisfile
"""
-
tmp_file = os.path.join(FLAGS.instances_path, filename)
os.remove(tmp_file)
@@ -879,7 +858,6 @@ class ComputeManager(manager.SchedulerDependentManager):
:returns: See driver.update_available_resource()
"""
-
return self.driver.update_available_resource(context, self.host)
def pre_live_migration(self, context, instance_id, time=None):
@@ -889,7 +867,6 @@ class ComputeManager(manager.SchedulerDependentManager):
:param instance_id: nova.db.sqlalchemy.models.Instance.Id
"""
-
if not time:
time = greenthread
@@ -948,7 +925,6 @@ class ComputeManager(manager.SchedulerDependentManager):
:param dest: destination host
"""
-
# Get instance for error handling.
instance_ref = self.db.instance_get(context, instance_id)
i_name = instance_ref.name
@@ -1044,12 +1020,10 @@ class ComputeManager(manager.SchedulerDependentManager):
:param ctxt: security context
:param instance_id: nova.db.sqlalchemy.models.Instance.Id
- :param host:
- DB column value is updated by this hostname.
- if none, the host instance currently running is selected.
+ :param host: DB column value is updated by this hostname.
+ If none, the host instance currently running is selected.
"""
-
if not host:
host = instance_ref['host']