import cloud
import downburst
import openstack
+import os
log = logging.getLogger(__name__)
+def _logfile(ctx, shortname):
+ if (ctx.config.get('archive_path')):
+ return os.path.join(ctx.config['archive_path'],
+ shortname + '.downburst.log')
+
+
def create_if_vm(ctx, machine_name, _downburst=None):
"""
Use downburst to create a virtual machine
dbrst = _downburst or \
downburst.Downburst(name=machine_name, os_type=os_type,
- os_version=os_version, status=status_info)
+ os_version=os_version, status=status_info,
+ logfile=_logfile(ctx, shortname))
return dbrst.create()
dbrst = _downburst or \
downburst.Downburst(name=machine_name, os_type=None,
- os_version=None, status=status_info)
+ os_version=None, status=status_info,
+ logfile=_logfile(ctx, shortname))
return dbrst.destroy()
A class that provides methods for creating and destroying virtual machine
instances using downburst: https://github.com/ceph/downburst
"""
- def __init__(self, name, os_type, os_version, status=None, user='ubuntu'):
+ def __init__(self, name, os_type, os_version, status=None, user='ubuntu',
+ logfile=None):
self.name = name
self.shortname = decanonicalize_hostname(self.name)
self.os_type = os_type
self.config_path = None
self.user_path = None
self.user = user
+ self.logfile = logfile
self.host = decanonicalize_hostname(self.status['vm_host']['name'])
self.executable = downburst_executable()
if not self.user_path:
raise ValueError("I need a user_path!")
- args = [
- self.executable,
- '-c', self.host,
+ args = [self.executable, '-v', '-c', self.host]
+ if self.logfile:
+ args.extend(['-l', self.logfile])
+ args.extend([
'create',
'--wait',
'--meta-data=%s' % self.config_path,
'--user-data=%s' % self.user_path,
self.shortname,
- ]
+ ])
log.info("Provisioning a {distro} {distroversion} vps".format(
distro=self.os_type,
distroversion=self.os_version
if not executable:
log.error("No downburst executable found.")
return False
- args = [executable, '-c', self.host, 'destroy', self.shortname]
+ args = [executable, '-v', '-c', self.host]
+ if self.logfile:
+ args.extend(['-l', self.logfile])
+ args.extend(['destroy', self.shortname])
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,)
out, err = proc.communicate()