Add image logging

Log stdout/stderr from the image build process.  Use the provider
and image name in the log selector so that admins can route
appropriately (or at least grep).

Change-Id: I7bc74ebfca3184340b51b083695b3441f0924e83
This commit is contained in:
James E. Blair 2013-08-29 16:05:35 -07:00
parent 1e190f5d57
commit b1b8a569ef
3 changed files with 25 additions and 18 deletions

View File

@ -401,7 +401,10 @@ class ImageUpdater(threading.Thread):
(server_id, self.snap_image.id))
def bootstrapServer(self, server, key):
ssh_kwargs = {}
log = logging.getLogger("nodepool.image.build.%s.%s" %
(self.provider.name, self.image.name))
ssh_kwargs = dict(log=log)
if key:
ssh_kwargs['pkey'] = key
else:
@ -429,11 +432,9 @@ class ImageUpdater(threading.Thread):
for k, v in os.environ.items():
if k.startswith('NODEPOOL_'):
env_vars += ' %s="%s"' % (k, v)
r = host.ssh("run setup script",
host.ssh("run setup script",
"cd /opt/nodepool-scripts && %s ./%s" %
(env_vars, self.image.setup))
if not r:
raise Exception("Unable to run setup scripts")
class ConfigValue(object):

View File

@ -50,7 +50,7 @@ def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
if e[0] not in [errno.ECONNREFUSED, errno.EHOSTUNREACH]:
log.exception('Exception while testing ssh access:')
out = client.ssh("test ssh access", "echo access okay")
out = client.ssh("test ssh access", "echo access okay", output=True)
if "access okay" in out:
return client
return None

View File

@ -19,34 +19,40 @@
# limitations under the License.
import paramiko
import sys
class SSHClient(object):
def __init__(self, ip, username, password=None, pkey=None,
key_filename=None):
key_filename=None, log=None):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
client.connect(ip, username=username, password=password, pkey=pkey,
key_filename=key_filename)
self.client = client
self.log = log
def ssh(self, action, command):
def ssh(self, action, command, output=False):
if self.log:
self.log.info(command)
stdin, stdout, stderr = self.client.exec_command(command)
print command
output = ''
for x in stdout:
output += x
sys.stdout.write(x)
out = ''
for line in stdout:
if output:
out += line
if self.log:
self.log.info(line.rstrip())
for line in stderr:
if self.log:
self.log.error(line.rstrip())
ret = stdout.channel.recv_exit_status()
print stderr.read()
if ret:
raise Exception("Unable to %s" % action)
return output
return out
def scp(self, source, dest):
print 'copy', source, dest
if self.log:
self.log.info("Copy %s -> %s" % (source, dest))
ftp = self.client.open_sftp()
ftp.put(source, dest)
ftp.close()