diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-11-06 18:50:25 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-11-06 18:50:25 +0000 |
commit | 66a6fdd73f8fd095fa212f515407fd64fdbf805f (patch) | |
tree | 01376d3967dcb6affbf6a90c81f306688396f274 | |
parent | 5edb1c7af71810a5d22036630cb3e555a50a1038 (diff) | |
parent | 184604edee5baf08bed94b1336d4f727a2978ecf (diff) | |
download | nova-66a6fdd73f8fd095fa212f515407fd64fdbf805f.tar.gz nova-66a6fdd73f8fd095fa212f515407fd64fdbf805f.tar.xz nova-66a6fdd73f8fd095fa212f515407fd64fdbf805f.zip |
Merge "xenapi: Make agent optional"
-rw-r--r-- | nova/virt/xenapi/agent.py | 8 | ||||
-rw-r--r-- | nova/virt/xenapi/vmops.py | 115 |
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 7aa4a20ce..53d372839 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -157,8 +157,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.""" @@ -517,17 +523,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'), @@ -540,34 +535,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 vcpu_weight = instance['instance_type']['vcpu_weight'] @@ -860,15 +868,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): @@ -1422,9 +1436,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.""" |