Example #1
0
    def delete_volume(self):
        context = self._config.context
        # docker rm $container
        result = monitor_command(["docker", "rm", context.cloud["container"]])
        if not result.success:
            log.error('failure:{0.command} :{0.std_err}'.format(result.result))
            return False

        name = "{}/{}".format(self.registry(), context.ami.name)
        result = monitor_command(["docker", "rmi", name])
        if not result.success:
            log.error('failure:{0.command} :{0.std_err}'.format(result.result))
            return False
        return True
Example #2
0
    def delete_volume(self):
        context = self._config.context
        # docker rm $container
        result = monitor_command(["docker", "rm", context.cloud["container"]])
        if not result.success:
            log.error('failure:{0.command} :{0.std_err}'.format(result.result))
            return False

        name = "{}/{}".format(self.registry(), context.ami.name)
        result = monitor_command(["docker", "rmi", name])
        if not result.success:
            log.error('failure:{0.command} :{0.std_err}'.format(result.result))
            return False
        return True
Example #3
0
 def aptitude(operation, package):
     aptitude_result = monitor_command(
         ["aptitude", "--no-gui", "-y", operation, package])
     if not aptitude_result.success:
         log.debug('failure:{0.command} :{0.std_err}'.format(
             aptitude_result.result))
     return aptitude_result
Example #4
0
    def _bundle_image(self):
        context = self._config.context

        config = self._config.plugins[self.full_name]
        block_device_map = config.default_block_device_map
        root_device = config.default_root_device

        bdm = "root={0}".format(root_device)
        for bd in block_device_map:
            bdm += ",{0}={1}".format(bd[1], bd[0])
        bdm += ",ami={0}".format(root_device)

        cmd = ['ec2-bundle-image']
        cmd.extend(['-c', context.ami.get("cert", config.default_cert)])
        cmd.extend(['-k', context.ami.get("privatekey", config.default_privatekey)])
        cmd.extend(['-u', context.ami.get("ec2_user", str(config.default_ec2_user))])
        cmd.extend(['-i', self.image_location()])
        cmd.extend(['-d', self.tmpdir()])
        if context.base_ami.architecture:
            cmd.extend(['-r', context.base_ami.architecture])

        vm_type = context.ami.get("vm_type", "paravirtual")
        if vm_type == "paravirtual":
            if context.base_ami.kernel_id:
                cmd.extend(['--kernel', context.base_ami.kernel_id])
            if context.base_ami.ramdisk_id:
                cmd.extend(['--ramdisk', context.base_ami.ramdisk_id])
            cmd.extend(['-B', bdm])
        return monitor_command(cmd)
Example #5
0
    def _bundle_image(self):
        context = self._config.context

        config = self._config.plugins[self.full_name]
        block_device_map = config.default_block_device_map
        root_device = config.default_root_device

        bdm = "root={0}".format(root_device)
        for bd in block_device_map:
            bdm += ",{0}={1}".format(bd[1], bd[0])
        bdm += ",ami={0}".format(root_device)

        cmd = ['ec2-bundle-image']
        cmd.extend(['-c', context.ami.get("cert", config.default_cert)])
        cmd.extend(
            ['-k',
             context.ami.get("privatekey", config.default_privatekey)])
        cmd.extend(
            ['-u',
             context.ami.get("ec2_user", str(config.default_ec2_user))])
        cmd.extend(['-i', self.image_location()])
        cmd.extend(['-d', self.tmpdir()])
        if context.base_ami.architecture:
            cmd.extend(['-r', context.base_ami.architecture])

        vm_type = context.ami.get("vm_type", "paravirtual")
        if vm_type == "paravirtual":
            if context.base_ami.kernel_id:
                cmd.extend(['--kernel', context.base_ami.kernel_id])
            if context.base_ami.ramdisk_id:
                cmd.extend(['--ramdisk', context.base_ami.ramdisk_id])
            cmd.extend(['-B', bdm])
        return monitor_command(cmd)
Example #6
0
 def apt_get_install(*options):
     cmd = ['apt-get', '-y', 'install']
     cmd.extend(options)
     install_result = monitor_command(cmd)
     if not install_result.success:
         log.debug('failure:{0.command} :{0.std_err}'.format(install_result.result))
     return install_result
Example #7
0
 def allocate_base_volume(self, tag=True):
     context = self._config.context
     result = monitor_command(["docker", "pull", context.ami.base_image])
     if not result.success:
         log.error('failure:{0.command} :{0.std_err}'.format(result.result))
         return False
     return True
Example #8
0
    def attach_volume(self, blockdevice, tag=True):
        context = self._config.context
        result = monitor_command(["docker", "run", "-d", context.ami.base_image, "sleep", "infinity"])
        if not result.success:
            log.error('failure:{0.command} :{0.std_err}'.format(result.result))
            return False
        container = result.result.std_out.rstrip()
        context.cloud["container"] = container

        # # now we need to umount all the mount points that docker imports for us
        # with open("/proc/mounts") as f:
        #     mounts = f.readlines()
        # mountpoints = []
        # for mount in mounts:
        #     if container in mount:
        #         mountpoint = mount.split()[1]
        #         # keep the root mountpoint
        #         if mountpoint.endswith("/root"): continue
        #         if not mountpoint.startswith("/var/lib/docker/containers/"): continue
        #         mountpoints.append( mountpoint )
        # # unmount all the mountpoints in reverse order (in case we have mountpoints
        # # inside of mountpoints
        # for mountpoint in reversed(sorted(mountpoints)):
        #     result = unmount(mountpoint)
        #     if not result.success:
        #         log.error('failure:{0.command} :{0.std_err}'.format(result.result))
        #         return False
        return True
Example #9
0
    def attach_volume(self, blockdevice, tag=True):
        context = self._config.context
        result = monitor_command([
            "docker", "run", "-d", context.ami.base_image, "sleep", "infinity"
        ])
        if not result.success:
            log.error('failure:{0.command} :{0.std_err}'.format(result.result))
            return False
        container = result.result.std_out.rstrip()
        context.cloud["container"] = container

        # # now we need to umount all the mount points that docker imports for us
        # with open("/proc/mounts") as f:
        #     mounts = f.readlines()
        # mountpoints = []
        # for mount in mounts:
        #     if container in mount:
        #         mountpoint = mount.split()[1]
        #         # keep the root mountpoint
        #         if mountpoint.endswith("/root"): continue
        #         if not mountpoint.startswith("/var/lib/docker/containers/"): continue
        #         mountpoints.append( mountpoint )
        # # unmount all the mountpoints in reverse order (in case we have mountpoints
        # # inside of mountpoints
        # for mountpoint in reversed(sorted(mountpoints)):
        #     result = unmount(mountpoint)
        #     if not result.success:
        #         log.error('failure:{0.command} :{0.std_err}'.format(result.result))
        #         return False
        return True
Example #10
0
 def allocate_base_volume(self, tag=True):
     context = self._config.context
     result = monitor_command(["docker", "pull", context.ami.base_image])
     if not result.success:
         log.error('failure:{0.command} :{0.std_err}'.format(result.result))
         return False
     return True
Example #11
0
    def detach_volume(self, blockdevice):
        result = monitor_command(["docker", "kill", self._config.context.cloud["container"]])
        if not result.success:
            log.error('failure:{0.command} :{0.std_err}'.format(result.result))
            return False

        return True
Example #12
0
def rpm_query(package, queryformat, local=False):
    cmd = 'rpm -q --qf'.split()
    cmd.append(queryformat)
    if local:
        cmd.append('-p')
    cmd.append(package)
    return monitor_command(cmd)
Example #13
0
def rpm_query(package, queryformat, local=False):
    cmd = 'rpm -q --qf'.split()
    cmd.append(queryformat)
    if local:
        cmd.append('-p')
    cmd.append(package)
    return monitor_command(cmd)
Example #14
0
 def apt_get_install(*options):
     cmd = ['apt-get', '-y', 'install']
     cmd.extend(options)
     install_result = monitor_command(cmd)
     if not install_result.success:
         log.debug('failure:{0.command} :{0.std_err}'.format(
             install_result.result))
     return install_result
Example #15
0
    def detach_volume(self, blockdevice):
        result = monitor_command(
            ["docker", "kill", self._config.context.cloud["container"]])
        if not result.success:
            log.error('failure:{0.command} :{0.std_err}'.format(result.result))
            return False

        return True
Example #16
0
 def snapshot_volume(self, description=None):
     context = self._config.context
     name = "{}/{}".format(self.registry(), context.ami.name)
     result = monitor_command(["docker", "commit", self._config.context.cloud["container"], name])
     if not result.success:
         log.error('failure:{0.command} :{0.std_err}'.format(result.result))
         return False
     return True
Example #17
0
 def apt_get_update(self):
     self.apt_get_clean()
     dpkg_update = monitor_command(['apt-get', 'update'])
     if not dpkg_update.success:
         log.debug('failure: {0.command} :{0.std_err}'.format(dpkg_update.result))
         # trigger retry. expiring retries should fail the bake as this
         # exception will propagate out to the provisioning context handler
         raise AptProvisionerUpdateException('apt-get update failed')
     return dpkg_update
Example #18
0
 def _copy_volume(self):
     context = self._config.context
     tmpdir = self.tmpdir()
     if not isdir(tmpdir):
         makedirs(tmpdir)
     return monitor_command([
         "dd", "bs=65536", "if={0}".format(context.volume.dev),
         "of={0}".format(self.image_location())
     ])
Example #19
0
 def register_image(self, *args, **kwargs):
     context = self._config.context
     name = "{}/{}".format(self.registry(), context.ami.name)
     result = monitor_command(["docker", "push", name])
     if not result.success:
         log.error('failure:{0.command} :{0.std_err}'.format(result.result))
         return False
     log.info('Docker Image registered: {0}'.format(name))
     return True
Example #20
0
 def deb_query(package, queryformat, local=False):
     if local:
         cmd = 'dpkg-deb -W'.split()
         cmd.append('--showformat={0}'.format(queryformat))
     else:
         cmd = 'dpkg-query -W'.split()
         cmd.append('-f={0}'.format(queryformat))
     cmd.append(package)
     return monitor_command(cmd)
Example #21
0
 def deb_query(package, queryformat, local=False):
     if local:
         cmd = 'dpkg-deb -W'.split()
         cmd.append('--showformat={0}'.format(queryformat))
     else:
         cmd = 'dpkg-query -W'.split()
         cmd.append('-f={0}'.format(queryformat))
     cmd.append(package)
     return monitor_command(cmd)
Example #22
0
 def register_image(self, *args, **kwargs):
     context = self._config.context
     name = "{}/{}".format(self.registry(), context.ami.name)
     result = monitor_command(["docker", "push", name])
     if not result.success:
         log.error('failure:{0.command} :{0.std_err}'.format(result.result))
         return False
     log.info('Docker Image registered: {0}'.format(name))
     return True
Example #23
0
 def snapshot_volume(self, description=None):
     context = self._config.context
     name = "{}/{}".format(self.registry(), context.ami.name)
     result = monitor_command([
         "docker", "commit", self._config.context.cloud["container"], name
     ])
     if not result.success:
         log.error('failure:{0.command} :{0.std_err}'.format(result.result))
         return False
     return True
Example #24
0
 def apt_get_update(self):
     self.apt_get_clean()
     dpkg_update = monitor_command(['apt-get', 'update'])
     if not dpkg_update.success:
         log.debug('failure: {0.command} :{0.std_err}'.format(
             dpkg_update.result))
         # trigger retry. expiring retries should fail the bake as this
         # exception will propagate out to the provisioning context handler
         raise AptProvisionerUpdateException('apt-get update failed')
     return dpkg_update
Example #25
0
 def deb_query(package, queryformat, local=False):
     if local:
         cmd = 'dpkg-deb -W'.split()
         cmd.append('--showformat={0}'.format(queryformat))
     else:
         cmd = 'dpkg-query -W'.split()
         cmd.append('-f={0}'.format(queryformat))
     cmd.append(package)
     deb_query_result = monitor_command(cmd)
     if not deb_query_result.success:
         log.debug('failure:{0.command} :{0.std_err}'.format(deb_query_result.result))
     return deb_query_result
Example #26
0
 def deb_query(package, queryformat, local=False):
     if local:
         cmd = 'dpkg-deb -W'.split()
         cmd.append('--showformat={0}'.format(queryformat))
     else:
         cmd = 'dpkg-query -W'.split()
         cmd.append('-f={0}'.format(queryformat))
     cmd.append(package)
     deb_query_result = monitor_command(cmd)
     if not deb_query_result.success:
         log.debug('failure:{0.command} :{0.std_err}'.format(
             deb_query_result.result))
     return deb_query_result
Example #27
0
    def _upload_bundle(self):
        context = self._config.context

        provider = self._cloud._connection.provider
        ak = provider.get_access_key()
        sk = provider.get_secret_key()
        tk = provider.get_security_token()

        cmd = ['ec2-upload-bundle']
        cmd.extend(['-b', context.ami.bucket])
        cmd.extend(['-a', ak])
        cmd.extend(['-s', sk])
        if tk:
            cmd.extend(['-t', tk])
        cmd.extend(['-m', "{0}.manifest.xml".format(self.image_location())])
        cmd.extend(['--retry'])
        return monitor_command(cmd)
Example #28
0
    def _upload_bundle(self):
        context = self._config.context

        provider = self._cloud._connection.provider
        ak = provider.get_access_key()
        sk = provider.get_secret_key()
        tk = provider.get_security_token()

        cmd = ['ec2-upload-bundle']
        cmd.extend(['-b', context.ami.bucket])
        cmd.extend(['-a', ak])
        cmd.extend(['-s', sk])
        if tk:
            cmd.extend(['-t', tk])
        cmd.extend(['-m', "{0}.manifest.xml".format(self.image_location())])
        cmd.extend(['--retry'])
        return monitor_command(cmd)
Example #29
0
    def provision(self):
        context = self._config.context
        config = self._config.plugins[self.full_name]

        buri_base = config.get('buri_install', '/opt/buri')
        extra_vars = config.get('extravars', '')

        roles_param = ''
        roles_path = '{0}/local/roles'.format(buri_base)
        if os.path.exists(roles_path) and not os.path.isfile(roles_path):
            roles_param = 'ANSIBLE_ROLES_PATH={0} '.format(roles_path)

        log.info('Starting Buri')
        result = monitor_command('ANSIBLE_NOCOWS=1 {0}{1}/buri --extra-vars "{2}" aminator {3} {4}'.format(roles_param, buri_base, extra_vars, self._distro._mountpoint, context.package.arg))
        log.info('Buri Stopped')
        if not result.success:
            log.critical("Buri provisioning failed")
            return False
        log.info("Buri provisioning succeeded")
        self._store_package_metadata()
        return True
Example #30
0
    def _install_puppet(self):
        puppet_install_cmd = self._get_config_value('puppet_install_cmd', '')
        if puppet_install_cmd != '':
            log.info('Installing Puppet with command \'{0}\'.', format(puppet_install_cmd))
            monitor_command(puppet_install_cmd)
        else:
            if self._distro._name is 'redhat':
                log.info('Installing Puppet with yum.')
                yum_clean_metadata()
                monitor_command('yum --nogpgcheck -y install puppet')
            else:
                log.info('Installing Puppet with apt.')
                monitor_command('apt-get update')
                monitor_command('apt-get -y install puppet')

        puppet_hieradata = self._get_config_value('puppet_hieradata', '' )
        if puppet_hieradata != '':
            puppet_hiera_install_cmd = self._get_config_value('puppet_hiera_install_cmd', '')
            if puppet_hiera_install_cmd != '':
                log.info('Installing Hiera with \'{0}\'.', format(puppet_hiera_install_cmd))
                monitor_command(puppet_hiera_install_cmd)
            else:
                log.info('Installing Hiera Ruby gem.')
                monitor_command('gem install hiera')
Example #31
0
 def aptitude(operation, package):
     return monitor_command(["aptitude", "--no-gui", "-y", operation, package])
Example #32
0
def yum_clean_metadata(repos=None):
    clean = ['yum', 'clean', 'metadata']
    if repos:
        clean.extend(['--disablerepo', '*', '--enablerepo', ','.join(repos)])
    return monitor_command(clean)
Example #33
0
def yum_install(package):
    return monitor_command(['yum', '--nogpgcheck', '-y', 'install', package])
Example #34
0
 def apt_get_install(cls, package):
     return monitor_command(['apt-get', '-y', 'install', package])
Example #35
0
def puppet_agent( puppet_args, certname, puppet_master):
    return monitor_command("puppet agent --detailed-exitcodes --no-daemonize --logdest console --onetime --certname {0} --server {1}".format(certname, puppet_master,puppet_args))
Example #36
0
def run_script(script):
    return monitor_command(script)
Example #37
0
def run_script(script):
    return monitor_command(script)
Example #38
0
 def dpkg_install(package):
     dpkg_result = monitor_command(['dpkg', '-i', package])
     if not dpkg_result.success:
         log.debug('failure:{0.command} :{0.std_err}'.format(
             dpkg_result.result))
     return dpkg_result
Example #39
0
def puppet_apply( puppet_args, puppet_apply_file ):
    return monitor_command("puppet apply --detailed-exitcodes --logdest console --debug --verbose {0} {1}".format(puppet_args, puppet_apply_file))
Example #40
0
 def apt_get_clean():
     return monitor_command(['apt-get', 'clean'])
Example #41
0
def yum_install(package):
    return monitor_command(['yum', '--nogpgcheck', '-y', 'install', package])
Example #42
0
 def dpkg_install(package):
     return monitor_command(['dpkg', '-i', package])
Example #43
0
def yum_clean_metadata(repos=None):
    clean = ['yum', 'clean', 'metadata']
    if repos:
        clean.extend(['--disablerepo', '*', '--enablerepo', ','.join(repos)])
    return monitor_command(clean)
Example #44
0
def yum_localinstall(path):
    if not os.path.isfile(path):
        log.critical('Package {0} not found'.format(path))
        return None
    return monitor_command(['yum', '--nogpgcheck', '-y', 'localinstall', path])
Example #45
0
 def dpkg_install(package):
     return monitor_command(['dpkg', '-i', package])
Example #46
0
 def dpkg_install(package):
     dpkg_result = monitor_command(['dpkg', '-i', package])
     if not dpkg_result.success:
         log.debug('failure:{0.command} :{0.std_err}'.format(dpkg_result.result))
     return dpkg_result
Example #47
0
def generate_certificate(certname):
    log.debug('Generating certificate for {0}'.format(certname))
    return monitor_command(['puppetca','generate',certname])
Example #48
0
def yum_localinstall(path):
    if not os.path.isfile(path):
        log.critical('Package {0} not found'.format(path))
        return None
    return monitor_command(['yum', '--nogpgcheck', '-y', 'localinstall', path])
Example #49
0
 def apt_get_clean():
     return monitor_command(['apt-get', 'clean'])
Example #50
0
 def _copy_volume(self):
     context = self._config.context
     tmpdir = self.tmpdir()
     if not isdir(tmpdir):
         makedirs(tmpdir)
     return monitor_command(["dd", "bs=65536", "if={0}".format(context.volume.dev), "of={0}".format(self.image_location())])
Example #51
0
 def apt_get_install(cls, package):
     return monitor_command(['apt-get', '-y', 'install', package])