def run(cls, info): manifest = info.manifest.plugins['puppet']['manifest'] if not os.path.exists(manifest): msg = 'The manifest file {manifest} does not exist.'.format(manifest=manifest) raise TaskError(msg) if not os.path.isfile(manifest): msg = 'The manifest path {manifest} does not point to a file.'.format(manifest=manifest) raise TaskError(msg)
def run(cls, info): assets = info.manifest.plugins['puppet']['assets'] if not os.path.exists(assets): msg = 'The assets directory {assets} does not exist.'.format(assets=assets) raise TaskError(msg) if not os.path.isdir(assets): msg = 'The assets path {assets} does not point to a directory.'.format(assets=assets) raise TaskError(msg)
def run(cls, info): from bootstrapvz.common.exceptions import TaskError playbook = rel_path(info.manifest.path, info.manifest.plugins['ansible']['playbook']) if not os.path.exists(playbook): msg = 'The playbook file {playbook} does not exist.'.format(playbook=playbook) raise TaskError(msg) if not os.path.isfile(playbook): msg = 'The playbook path {playbook} does not point to a file.'.format(playbook=playbook) raise TaskError(msg)
def run(cls, info): from bootstrapvz.common.exceptions import TaskError assets = info.manifest.plugins['puppet']['assets'] if not os.path.exists(assets): msg = 'The assets directory {assets} does not exist.'.format(assets=assets) raise TaskError(msg) if not os.path.isdir(assets): msg = 'The assets path {assets} does not point to a directory.'.format(assets=assets) raise TaskError(msg)
def run(cls, info): from bootstrapvz.common.exceptions import TaskError manifest = info.manifest.plugins['puppet']['manifest'] if not os.path.exists(manifest): msg = 'The manifest file {manifest} does not exist.'.format( manifest=manifest) raise TaskError(msg) if not os.path.isfile(manifest): msg = 'The manifest path {manifest} does not point to a file.'.format( manifest=manifest) raise TaskError(msg)
def run(cls, info): from bootstrapvz.common.exceptions import TaskError from subprocess import CalledProcessError images = info.manifest.plugins['docker_daemon'].get('pull_images', []) retries = info.manifest.plugins['docker_daemon'].get( 'pull_images_retries', 10) bin_docker = os.path.join(info.root, 'usr/bin/docker') graph_dir = os.path.join(info.root, 'var/lib/docker') socket = 'unix://' + os.path.join(info.workspace, 'docker.sock') pidfile = os.path.join(info.workspace, 'docker.pid') try: # start docker daemon temporarly. daemon = subprocess.Popen([ bin_docker, '-d', '--graph', graph_dir, '-H', socket, '-p', pidfile ]) # wait for docker daemon to start. for _ in range(retries): try: log_check_call([bin_docker, '-H', socket, 'version']) break except CalledProcessError: time.sleep(1) for img in images: # docker load if tarball. if img.endswith('.tar.gz') or img.endswith('.tgz'): cmd = [bin_docker, '-H', socket, 'load', '-i', img] try: log_check_call(cmd) except CalledProcessError as e: msg = 'error {e} loading docker image {img}.'.format( img=img, e=e) raise TaskError(msg) # docker pull if image name. else: cmd = [bin_docker, '-H', socket, 'pull', img] try: log_check_call(cmd) except CalledProcessError as e: msg = 'error {e} pulling docker image {img}.'.format( img=img, e=e) raise TaskError(msg) finally: # shutdown docker daemon. daemon.terminate() os.remove(os.path.join(info.workspace, 'docker.sock'))
def run(cls, info): from bootstrapvz.common.exceptions import TaskError for file_entry in info.manifest.plugins['file_copy']['files']: srcfile = file_entry['src'] if not os.path.isfile(srcfile): msg = 'The source file %s does not exist.' % srcfile raise TaskError(msg)
def run(cls, info): if info.bootstrap_script is not None: from bootstrapvz.common.exceptions import TaskError raise TaskError('info.bootstrap_script seems to already be set ' 'and is conflicting with this task') bootstrap_script = os.path.join(info.workspace, 'bootstrap_script.sh') filter_script = os.path.join(info.workspace, 'bootstrap_files_filter.sh') excludes_file = os.path.join(info.workspace, 'debootstrap-excludes') shutil.copy(os.path.join(assets, 'bootstrap-script.sh'), bootstrap_script) shutil.copy(os.path.join(assets, 'bootstrap-files-filter.sh'), filter_script) sed_i(bootstrap_script, r'DEBOOTSTRAP_EXCLUDES_PATH', excludes_file) sed_i(bootstrap_script, r'BOOTSTRAP_FILES_FILTER_PATH', filter_script) # We exclude with patterns but include with fixed strings # The pattern matching when excluding is needed in order to filter # everything below e.g. /usr/share/locale but not the folder itself filter_lists = info._minimize_size['bootstrap_filter'] exclude_list = '\|'.join(map(lambda p: '.' + p + '.\+', filter_lists['exclude'])) include_list = '\n'.join(map(lambda p: '.' + p, filter_lists['include'])) sed_i(filter_script, r'EXCLUDE_PATTERN', exclude_list) sed_i(filter_script, r'INCLUDE_PATHS', include_list) os.chmod(filter_script, 0755) info.bootstrap_script = bootstrap_script info._minimize_size['filter_script'] = filter_script
def run(cls, info): guest_additions_path = rel_path( info.manifest.path, info.manifest.provider['guest_additions']) if not os.path.exists(guest_additions_path): msg = 'The file {file} does not exist.'.format( file=guest_additions_path) raise TaskError(msg)
def run(cls, info): ami_name = info.manifest.name.format(**info.manifest_vars) ami_description = info.manifest.provider['description'].format(**info.manifest_vars) images = info._ec2['connection'].describe_images(Owners=['self'])['Images'] for image in images: if 'Name' in image and ami_name == image['Name']: msg = 'An image by the name {ami_name} already exists.'.format(ami_name=ami_name) raise TaskError(msg) info._ec2['ami_name'] = ami_name info._ec2['ami_description'] = ami_description
def run(cls, info): ami_name = info.manifest.name.format(**info.manifest_vars) ami_description = info.manifest.provider['description'].format(**info.manifest_vars) images = info._ec2['connection'].get_all_images(owners=['self']) for image in images: if ami_name == image.name: msg = 'An image by the name {ami_name} already exists.'.format(ami_name=ami_name) raise TaskError(msg) info._ec2['ami_name'] = ami_name info._ec2['ami_description'] = ami_description
def run(cls, info): box_basename = info.manifest.image['name'].format(**info.manifest_vars) box_name = box_basename + '.box' box_path = os.path.join(info.manifest.bootstrapper['workspace'], box_name) if os.path.exists(box_path): from bootstrapvz.common.exceptions import TaskError msg = 'The vagrant box `{name}\' already exists at `{path}\''.format( name=box_name, path=box_path) raise TaskError(msg) info._vagrant['box_name'] = box_name info._vagrant['box_path'] = box_path
def run(cls, info): if info.manifest.release not in (jessie, wheezy, stretch, buster): msg = 'Debian {info.manifest.release} is not (yet) available in the Puppetlabs.com APT repository.' raise TaskError(msg)
def run(cls, info): from bootstrapvz.common.exceptions import TaskError if info.manifest.release not in (jessie, wheezy, stretch): msg = 'Debian {info.manifest.release} is not (yet) available in the Puppetlabs.com APT repository.' raise TaskError(msg)