summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMate Lakat <mate.lakat@citrix.com>2012-11-01 16:43:11 +0000
committerMate Lakat <mate.lakat@citrix.com>2012-11-01 18:08:04 +0000
commit184604edee5baf08bed94b1336d4f727a2978ecf (patch)
tree1f6453106a7c7a948c62e9cea3eabbe7fc6a2ef3
parent3b2e0c6009e60d2a77844dcbce3f9be53e931fbb (diff)
downloadnova-184604edee5baf08bed94b1336d4f727a2978ecf.tar.gz
nova-184604edee5baf08bed94b1336d4f727a2978ecf.tar.xz
nova-184604edee5baf08bed94b1336d4f727a2978ecf.zip
xenapi: Make agent optional
Related to blueprint xenapi-config-drive As config drive and agent are doing similar operations, this change makes it possible to disable agent, thus config drive could perform these operations. Change-Id: I3fa536cb0fb3b60ff5bc035be9d86afe35905240
-rw-r--r--nova/virt/xenapi/agent.py8
-rw-r--r--nova/virt/xenapi/vmops.py115
2 files changed, 74 insertions, 49 deletions
diff --git a/nova/virt/xenapi/agent.py b/nova/virt/xenapi/agent.py
index 0c17dccff..605c95cfd 100644
--- a/nova/virt/xenapi/agent.py
+++ b/nova/virt/xenapi/agent.py
@@ -49,6 +49,11 @@ xenapi_agent_opts = [
'configuration is not injected into the image. '
'Used if compute_driver=xenapi.XenAPIDriver and '
' flat_injected=True'),
+ cfg.StrOpt('xenapi_disable_agent',
+ default=False,
+ help='Disable XenAPI agent. Reduces the amount of time '
+ 'it takes nova to detect that a VM has started, when '
+ 'that VM does not have the agent installed'),
]
FLAGS = flags.FLAGS
@@ -244,6 +249,9 @@ def find_guest_agent(base_dir):
tries to locate a guest agent at the path
specificed by agent_rel_path
"""
+ if FLAGS.xenapi_disable_agent:
+ return False
+
agent_rel_path = FLAGS.xenapi_agent_path
agent_path = os.path.join(base_dir, agent_rel_path)
if os.path.isfile(agent_path):
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 1f8cafa3b..be143ed9b 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -156,8 +156,14 @@ class VMOps(object):
self.vif_driver = vif_impl(xenapi_session=self._session)
self.default_root_dev = '/dev/sda'
+ @property
+ def agent_enabled(self):
+ return not FLAGS.xenapi_disable_agent
+
def _get_agent(self, instance, vm_ref):
- return xapi_agent.XenAPIBasedAgent(self._session, instance, vm_ref)
+ if self.agent_enabled:
+ return xapi_agent.XenAPIBasedAgent(self._session, instance, vm_ref)
+ raise exception.NovaException(_("Error: Agent is disabled"))
def list_instances(self):
"""List VM instances."""
@@ -514,17 +520,6 @@ class VMOps(object):
self._start(instance, vm_ref)
ctx = nova_context.get_admin_context()
- agent_build = db.agent_build_get_by_triple(ctx, 'xen',
- instance['os_type'], instance['architecture'])
- if agent_build:
- LOG.info(_('Latest agent build for %(hypervisor)s/%(os)s'
- '/%(architecture)s is %(version)s') % agent_build)
- else:
- LOG.info(_('No agent build found for %(hypervisor)s/%(os)s'
- '/%(architecture)s') % {
- 'hypervisor': 'xen',
- 'os': instance['os_type'],
- 'architecture': instance['architecture']})
# Wait for boot to finish
LOG.debug(_('Waiting for instance state to become running'),
@@ -537,34 +532,47 @@ class VMOps(object):
greenthread.sleep(0.5)
- # Update agent, if necessary
- # This also waits until the agent starts
- agent = self._get_agent(instance, vm_ref)
- version = agent.get_agent_version()
- if version:
- LOG.info(_('Instance agent version: %s'), version,
- instance=instance)
-
- if (version and agent_build and
- cmp_version(version, agent_build['version']) < 0):
- agent.agent_update(agent_build)
-
- # if the guest agent is not available, configure the
- # instance, but skip the admin password configuration
- no_agent = version is None
-
- # Inject files, if necessary
- if injected_files:
- # Inject any files, if specified
- for path, contents in injected_files:
- agent.inject_file(path, contents)
-
- # Set admin password, if necessary
- if admin_password and not no_agent:
- agent.set_admin_password(admin_password)
-
- # Reset network config
- agent.resetnetwork()
+ if self.agent_enabled:
+ agent_build = db.agent_build_get_by_triple(
+ ctx, 'xen', instance['os_type'], instance['architecture'])
+ if agent_build:
+ LOG.info(_('Latest agent build for %(hypervisor)s/%(os)s'
+ '/%(architecture)s is %(version)s') % agent_build)
+ else:
+ LOG.info(_('No agent build found for %(hypervisor)s/%(os)s'
+ '/%(architecture)s') % {
+ 'hypervisor': 'xen',
+ 'os': instance['os_type'],
+ 'architecture': instance['architecture']})
+
+ # Update agent, if necessary
+ # This also waits until the agent starts
+ agent = self._get_agent(instance, vm_ref)
+ version = agent.get_agent_version()
+ if version:
+ LOG.info(_('Instance agent version: %s'), version,
+ instance=instance)
+
+ if (version and agent_build and
+ cmp_version(version, agent_build['version']) < 0):
+ agent.agent_update(agent_build)
+
+ # if the guest agent is not available, configure the
+ # instance, but skip the admin password configuration
+ no_agent = version is None
+
+ # Inject files, if necessary
+ if injected_files:
+ # Inject any files, if specified
+ for path, contents in injected_files:
+ agent.inject_file(path, contents)
+
+ # Set admin password, if necessary
+ if admin_password and not no_agent:
+ agent.set_admin_password(admin_password)
+
+ # Reset network config
+ agent.resetnetwork()
# Set VCPU weight
inst_type = db.instance_type_get(ctx, instance['instance_type_id'])
@@ -857,15 +865,21 @@ class VMOps(object):
def set_admin_password(self, instance, new_pass):
"""Set the root/admin password on the VM instance."""
- vm_ref = self._get_vm_opaque_ref(instance)
- agent = self._get_agent(instance, vm_ref)
- agent.set_admin_password(new_pass)
+ if self.agent_enabled:
+ vm_ref = self._get_vm_opaque_ref(instance)
+ agent = self._get_agent(instance, vm_ref)
+ agent.set_admin_password(new_pass)
+ else:
+ raise NotImplementedError()
def inject_file(self, instance, path, contents):
"""Write a file to the VM instance."""
- vm_ref = self._get_vm_opaque_ref(instance)
- agent = self._get_agent(instance, vm_ref)
- agent.inject_file(path, contents)
+ if self.agent_enabled:
+ vm_ref = self._get_vm_opaque_ref(instance)
+ agent = self._get_agent(instance, vm_ref)
+ agent.inject_file(path, contents)
+ else:
+ raise NotImplementedError()
@staticmethod
def _sanitize_xenstore_key(key):
@@ -1407,9 +1421,12 @@ class VMOps(object):
def reset_network(self, instance):
"""Calls resetnetwork method in agent."""
- vm_ref = self._get_vm_opaque_ref(instance)
- agent = self._get_agent(instance, vm_ref)
- agent.resetnetwork()
+ if self.agent_enabled:
+ vm_ref = self._get_vm_opaque_ref(instance)
+ agent = self._get_agent(instance, vm_ref)
+ agent.resetnetwork()
+ else:
+ raise NotImplementedError()
def inject_hostname(self, instance, vm_ref, hostname):
"""Inject the hostname of the instance into the xenstore."""