summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Leafe <ed@leafe.com>2011-01-06 06:45:14 -0600
committerEd Leafe <ed@leafe.com>2011-01-06 06:45:14 -0600
commita3e12f5eb92921acc622ea7bd9097edeea0d40fd (patch)
tree96d92e3c6eca0bc40ce9c2b1167e149725ddadf0
parent950f1b5c713eaeabd7cbd8141556cc1da3cc00b1 (diff)
Renamed 'set_root_password' to 'set_admin_password' globally.
-rw-r--r--nova/compute/api.py50
-rw-r--r--nova/compute/manager.py24
-rw-r--r--nova/tests/test_compute.py6
-rw-r--r--nova/virt/fake.py19
-rw-r--r--nova/virt/xenapi/vmops.py20
-rw-r--r--nova/virt/xenapi_conn.py6
6 files changed, 56 insertions, 69 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 1d21a4668..0a7b802d6 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -190,7 +190,7 @@ class ComputeAPI(base.Base):
"""
try:
db.security_group_get_by_name(context, context.project_id,
- 'default')
+ 'default')
except exception.NotFound:
values = {'name': 'default',
'description': 'default',
@@ -258,70 +258,54 @@ class ComputeAPI(base.Base):
return self.db.instance_get_by_internal_id(context, instance_id)
def _cast_compute_message(self, method, context, instance_id):
- """Generic handler for RPC calls."""
+ """Generic handler for RPC calls to compute."""
instance = self.get_instance(context, instance_id)
host = instance['host']
rpc.cast(context,
- self.db.queue_get_for(context, FLAGS.compute_topic, host),
- {"method": method,
- "args": {"instance_id": instance['id']}})
+ self.db.queue_get_for(context, FLAGS.compute_topic, host),
+ {'method': method, 'args': {'instance_id': instance['id']}})
def snapshot(self, context, instance_id, name):
"""Snapshot the given instance."""
- self._cast_compute_message("snapshot_instance", context, instance_id)
+ self._cast_compute_message('snapshot_instance', context, instance_id)
def reboot(self, context, instance_id):
"""Reboot the given instance."""
- self._cast_compute_message("reboot_instance", context, instance_id)
+ self._cast_compute_message('reboot_instance', context, instance_id)
def pause(self, context, instance_id):
"""Pause the given instance."""
- self._cast_compute_message("pause_instance", context, instance_id)
+ self._cast_compute_message('pause_instance', context, instance_id)
def unpause(self, context, instance_id):
"""Unpause the given instance."""
- self._cast_compute_message("unpause_instance", context, instance_id)
+ self._cast_compute_message('unpause_instance', context, instance_id)
def get_diagnostics(self, context, instance_id):
"""Retrieve diagnostics for the given instance."""
- instance = self.db.instance_get_by_internal_id(context, instance_id)
- host = instance["host"]
- return rpc.call(context,
- self.db.queue_get_for(context, FLAGS.compute_topic, host),
- {"method": "get_diagnostics",
- "args": {"instance_id": instance["id"]}})
+ self._cast_compute_message('get_diagnostics', context, instance_id)
def get_actions(self, context, instance_id):
"""Retrieve actions for the given instance."""
instance = self.db.instance_get_by_internal_id(context, instance_id)
- return self.db.instance_get_actions(context, instance["id"])
+ return self.db.instance_get_actions(context, instance['id'])
def suspend(self, context, instance_id):
"""suspend the instance with instance_id"""
- instance = self.db.instance_get_by_internal_id(context, instance_id)
- host = instance['host']
- rpc.cast(context,
- self.db.queue_get_for(context, FLAGS.compute_topic, host),
- {"method": "suspend_instance",
- "args": {"instance_id": instance['id']}})
+ self._cast_compute_message('suspend_instance', context, instance_id)
def resume(self, context, instance_id):
"""resume the instance with instance_id"""
- instance = self.db.instance_get_by_internal_id(context, instance_id)
- host = instance['host']
- rpc.cast(context,
- self.db.queue_get_for(context, FLAGS.compute_topic, host),
- {"method": "resume_instance",
- "args": {"instance_id": instance['id']}})
+ self._cast_compute_message('resume_instance', context, instance_id)
def rescue(self, context, instance_id):
"""Rescue the given instance."""
- self._cast_compute_message("rescue_instance", context, instance_id)
+ self._cast_compute_message('rescue_instance', context, instance_id)
def unrescue(self, context, instance_id):
"""Unrescue the given instance."""
- self._cast_compute_message("unrescue_instance", context, instance_id)
+ self._cast_compute_message('unrescue_instance', context, instance_id)
- def reset_root_password(self, context, instance_id):
- """Reset the root/admin pw for the given instance."""
- self._cast_compute_message("reset_root_password", context, instance_id)
+ def set_admin_password(self, context, instance_id):
+ """Set the root/admin password for the given instance."""
+ self._cast_compute_message('set_admin_password', context, instance_id)
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 6f4d14589..b8bf91530 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -53,6 +53,8 @@ flags.DEFINE_string('compute_driver', 'nova.virt.connection.get_connection',
'Driver to use for controlling virtualization')
flags.DEFINE_string('stub_network', False,
'Stub network related code')
+flags.DEFINE_integer('password_length', 12,
+ 'Length of generated admin passwords')
class ComputeManager(manager.Manager):
@@ -248,27 +250,27 @@ class ComputeManager(manager.Manager):
self.driver.snapshot(instance_ref, name)
@exception.wrap_exception
- def reset_root_password(self, context, instance_id, new_pass=None):
- """Reset the root/admin password for an instance on this server."""
+ def set_admin_password(self, context, instance_id, new_pass=None):
+ """Set the root/admin password for an instance on this server."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
self._update_state(context, instance_id)
if instance_ref['state'] != power_state.RUNNING:
logging.warn('trying to reset the password on a non-running '
- 'instance: %s (state: %s excepted: %s)',
- instance_ref['internal_id'],
- instance_ref['state'],
- power_state.RUNNING)
+ 'instance: %s (state: %s expected: %s)',
+ instance_ref['internal_id'],
+ instance_ref['state'],
+ power_state.RUNNING)
- logging.debug('instance %s: resetting root password',
+ logging.debug('instance %s: setting admin password',
instance_ref['name'])
self.db.instance_set_state(context, instance_id,
- power_state.NOSTATE, 'resetting_password')
+ power_state.NOSTATE, 'setting_password')
if new_pass is None:
- # Generate a random, 12-character password
- new_pass = self._generate_password(12)
- self.driver.reset_root_password(instance_ref, new_pass)
+ # Generate a random password
+ new_pass = self._generate_password(FLAGS.password_length)
+ self.driver.set_admin_password(instance_ref, new_pass)
self._update_state(context, instance_id)
def _generate_password(self, length=20):
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 7c258e636..88e14d7df 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -151,11 +151,11 @@ class ComputeTestCase(test.TestCase):
self.compute.reboot_instance(self.context, instance_id)
self.compute.terminate_instance(self.context, instance_id)
- def test_reset_root_password(self):
- """Ensure instance can have its root password reset"""
+ def test_set_admin_password(self):
+ """Ensure instance can have its admin password set"""
instance_id = self._create_instance()
self.compute.run_instance(self.context, instance_id)
- self.compute.reset_root_password(self.context, instance_id)
+ self.compute.set_admin_password(self.context, instance_id)
self.compute.terminate_instance(self.context, instance_id)
def test_snapshot(self):
diff --git a/nova/virt/fake.py b/nova/virt/fake.py
index 2b9cf1ca3..2d4b0a3d7 100644
--- a/nova/virt/fake.py
+++ b/nova/virt/fake.py
@@ -98,7 +98,7 @@ class FakeConnection(object):
the new instance.
The work will be done asynchronously. This function returns a
- Deferred that allows the caller to detect when it is complete.
+ task that allows the caller to detect when it is complete.
Once this successfully completes, the instance should be
running (power_state.RUNNING).
@@ -122,7 +122,7 @@ class FakeConnection(object):
The second parameter is the name of the snapshot.
The work will be done asynchronously. This function returns a
- Deferred that allows the caller to detect when it is complete.
+ task that allows the caller to detect when it is complete.
"""
pass
@@ -134,19 +134,20 @@ class FakeConnection(object):
and so the instance is being specified as instance.name.
The work will be done asynchronously. This function returns a
- Deferred that allows the caller to detect when it is complete.
+ task that allows the caller to detect when it is complete.
"""
pass
- def reset_root_password(self, instance, new_pass):
+ def set_admin_password(self, instance, new_pass):
"""
- Reset the root password on the specified instance.
+ Set the root password on the specified instance.
- The given parameter is an instance of nova.compute.service.Instance,
- and so the instance is being specified as instance.name.
+ The first parameter is an instance of nova.compute.service.Instance,
+ and so the instance is being specified as instance.name. The second
+ parameter is the value of the new password.
The work will be done asynchronously. This function returns a
- Deferred that allows the caller to detect when it is complete.
+ task that allows the caller to detect when it is complete.
"""
pass
@@ -194,7 +195,7 @@ class FakeConnection(object):
and so the instance is being specified as instance.name.
The work will be done asynchronously. This function returns a
- Deferred that allows the caller to detect when it is complete.
+ task that allows the caller to detect when it is complete.
"""
del self.instances[instance.name]
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index eaf8c7dff..64855001b 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -198,17 +198,16 @@ class VMOps(object):
task = self._session.call_xenapi('Async.VM.clean_reboot', vm)
self._session.wait_for_task(instance.id, task)
- def reset_root_password(self, instance, new_pass):
- """Reset the root/admin password on the VM instance. This is
- done via an agent running on the VM. Communication between
- nova and the agent is done via writing xenstore records. Since
- communication is done over the XenAPI RPC calls, we need to
- encrypt the password. We're using a simple Diffie-Hellman class
- instead of the more advanced one in M2Crypto for compatibility
- with the agent code.
+ def set_admin_password(self, instance, new_pass):
+ """Set the root/admin password on the VM instance. This is done via
+ an agent running on the VM. Communication between nova and the agent
+ is done via writing xenstore records. Since communication is done over
+ the XenAPI RPC calls, we need to encrypt the password. We're using a
+ simple Diffie-Hellman class instead of the more advanced one in
+ M2Crypto for compatibility with the agent code.
"""
- logging.error("ZZZZ RESET PASS CALLED")
+ logging.error("ZZZZ SET PASS CALLED")
# Need to uniquely identify this request.
transaction_id = str(uuid.uuid4())
@@ -219,7 +218,8 @@ class VMOps(object):
resp_dict = json.loads(resp)
# Successful return code from key_init is 'D0'
if resp_dict['returncode'] != 'D0':
- # There was some sort of error
+ # There was some sort of error; the message will contain
+ # a description of the error.
raise RuntimeError(resp_dict['message'])
agent_pub = int(resp_dict['message'])
dh.compute_shared(agent_pub)
diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py
index f4dd7055c..0cba2812d 100644
--- a/nova/virt/xenapi_conn.py
+++ b/nova/virt/xenapi_conn.py
@@ -144,9 +144,9 @@ class XenAPIConnection(object):
"""Reboot VM instance"""
self._vmops.reboot(instance)
- def reset_root_password(self, instance, new_pass):
- """Reset the root/admin password on the VM instance"""
- self._vmops.reset_root_password(instance, new_pass)
+ def set_admin_password(self, instance, new_pass):
+ """Set the root/admin password on the VM instance"""
+ self._vmops.set_admin_password(instance, new_pass)
def destroy(self, instance):
"""Destroy VM instance"""