xenapi: ensure all calls to agent get logged
In some cases, a call to an agent wouldn't get logged since the caller was expected to log and not all did this. Move this to the callee so the caller doesn't need to do anything extra. Change-Id: Ie16a372187c9215028475522eef53bca9a5cf4d8
This commit is contained in:
parent
c60e2e8f30
commit
cc18149b63
@ -100,6 +100,8 @@ def _get_agent_version(session, instance, vm_ref):
|
||||
def get_agent_version(session, instance, vm_ref):
|
||||
"""Get the version of the agent running on the VM instance."""
|
||||
|
||||
LOG.debug(_('Querying agent version'), instance=instance)
|
||||
|
||||
# The agent can be slow to start for a variety of reasons. On Windows,
|
||||
# it will generally perform a setup process on first boot that can
|
||||
# take a couple of minutes and then reboot. On Linux, the system can
|
||||
@ -118,11 +120,14 @@ def get_agent_version(session, instance, vm_ref):
|
||||
return None
|
||||
|
||||
|
||||
def agent_update(session, instance, vm_ref, url, md5sum):
|
||||
def agent_update(session, instance, vm_ref, agent_build):
|
||||
"""Update agent on the VM instance."""
|
||||
|
||||
LOG.info(_('Updating agent to %s'), agent_build['version'],
|
||||
instance=instance)
|
||||
|
||||
# Send the encrypted password
|
||||
args = {'url': url, 'md5sum': md5sum}
|
||||
args = {'url': agent_build['url'], 'md5sum': agent_build['md5hash']}
|
||||
resp = _call_agent(session, instance, vm_ref, 'agentupdate', args)
|
||||
if resp['returncode'] != '0':
|
||||
LOG.error(_('Failed to update agent: %(resp)r'), locals(),
|
||||
@ -140,6 +145,8 @@ def set_admin_password(session, instance, vm_ref, new_pass):
|
||||
We're using a simple Diffie-Hellman class instead of a more advanced
|
||||
library (such as M2Crypto) for compatibility with the agent code.
|
||||
"""
|
||||
LOG.debug(_('Setting admin password'), instance=instance)
|
||||
|
||||
dh = SimpleDH()
|
||||
|
||||
# Exchange keys
|
||||
@ -175,6 +182,8 @@ def set_admin_password(session, instance, vm_ref, new_pass):
|
||||
|
||||
|
||||
def inject_file(session, instance, vm_ref, path, contents):
|
||||
LOG.debug(_('Injecting file path: %r'), path, instance=instance)
|
||||
|
||||
# Files/paths must be base64-encoded for transmission to agent
|
||||
b64_path = base64.b64encode(path)
|
||||
b64_contents = base64.b64encode(contents)
|
||||
@ -193,6 +202,8 @@ def inject_file(session, instance, vm_ref, path, contents):
|
||||
|
||||
|
||||
def resetnetwork(session, instance, vm_ref):
|
||||
LOG.debug(_('Resetting network'), instance=instance)
|
||||
|
||||
resp = _call_agent(session, instance, vm_ref, 'resetnetwork')
|
||||
if resp['returncode'] != '0':
|
||||
LOG.error(_('Failed to reset network: %(resp)r'), locals(),
|
||||
|
@ -493,7 +493,6 @@ class VMOps(object):
|
||||
|
||||
# Update agent, if necessary
|
||||
# This also waits until the agent starts
|
||||
LOG.debug(_("Querying agent version"), instance=instance)
|
||||
version = agent.get_agent_version(self._session, instance, vm_ref)
|
||||
if version:
|
||||
LOG.info(_('Instance agent version: %s'), version,
|
||||
@ -501,10 +500,7 @@ class VMOps(object):
|
||||
|
||||
if (version and agent_build and
|
||||
cmp_version(version, agent_build['version']) < 0):
|
||||
LOG.info(_('Updating Agent to %s'), agent_build['version'],
|
||||
instance=instance)
|
||||
agent.agent_update(self._session, instance, vm_ref,
|
||||
agent_build['url'], agent_build['md5hash'])
|
||||
agent.agent_update(self._session, instance, vm_ref, agent_build)
|
||||
|
||||
# if the guest agent is not available, configure the
|
||||
# instance, but skip the admin password configuration
|
||||
@ -523,20 +519,16 @@ class VMOps(object):
|
||||
injected_files = []
|
||||
# Inject any files, if specified
|
||||
for path, contents in instance['injected_files']:
|
||||
LOG.debug(_("Injecting file path: '%s'") % path,
|
||||
instance=instance)
|
||||
agent.inject_file(self._session, instance, vm_ref,
|
||||
path, contents)
|
||||
|
||||
admin_password = instance['admin_pass']
|
||||
# Set admin password, if necessary
|
||||
if admin_password and not no_agent:
|
||||
LOG.debug(_("Setting admin password"), instance=instance)
|
||||
agent.set_admin_password(self._session, instance, vm_ref,
|
||||
admin_password)
|
||||
|
||||
# Reset network config
|
||||
LOG.debug(_("Resetting network"), instance=instance)
|
||||
agent.resetnetwork(self._session, instance, vm_ref)
|
||||
|
||||
# Set VCPU weight
|
||||
|
Loading…
Reference in New Issue
Block a user