def run(cls, info): from bootstrapvz.common.tools import sed_i getcreds_path = os.path.join(info.root, 'etc/init.d/ec2-get-credentials') username = info.manifest.plugins['admin_user']['username'] sed_i(getcreds_path, "username='******'", "username='******'".format(username=username))
def run(cls, info): expand_root_script = os.path.join(ASSETS_DIR, 'expand-root.sh') expand_root_service = os.path.join(ASSETS_DIR, 'expand-root.service') expand_root_script_dest = os.path.join(info.root, 'usr/bin/expand-root.sh') expand_root_service_dest = os.path.join( info.root, 'lib/systemd/system/expand-root.service') filesystem_type = info.manifest.plugins['expand_root'].get( 'filesystem_type') root_device = info.manifest.plugins['expand_root'].get('root_device') root_partition = info.manifest.plugins['expand_root'].get( 'root_partition') # Copy files over shutil.copy(expand_root_script, expand_root_script_dest) os.chmod(expand_root_script_dest, 0750) shutil.copy(expand_root_service, expand_root_service_dest) # Expand out options into expand-root.sh script. opts = '%s %s %s' % (root_device, root_partition, filesystem_type) sed_i(expand_root_service_dest, r'^ExecStart=/usr/bin/expand-root.sh.*$', 'ExecStart=/usr/bin/expand-root.sh %s' % opts) # Enable systemd service log_check_call([ 'chroot', info.root, 'systemctl', 'enable', 'expand-root.service' ])
def run(cls, info): vagrantfile_source = os.path.join(assets, 'Vagrantfile') vagrantfile = os.path.join(info._vagrant['folder'], 'Vagrantfile') shutil.copy(vagrantfile_source, vagrantfile) import random mac_address = '080027{mac:06X}'.format(mac=random.randrange(16 ** 6)) from bootstrapvz.common.tools import sed_i sed_i(vagrantfile, '\\[MAC_ADDRESS\\]', mac_address) metadata_source = os.path.join(assets, 'metadata.json') metadata = os.path.join(info._vagrant['folder'], 'metadata.json') shutil.copy(metadata_source, metadata) from bootstrapvz.common.tools import log_check_call disk_name = 'box-disk1.' + info.volume.extension disk_link = os.path.join(info._vagrant['folder'], disk_name) log_check_call(['ln', '-s', info.volume.image_path, disk_link]) ovf_path = os.path.join(info._vagrant['folder'], 'box.ovf') cls.write_ovf(info, ovf_path, mac_address, disk_name) box_files = os.listdir(info._vagrant['folder']) log_check_call(['tar', '--create', '--gzip', '--dereference', '--file', info._vagrant['box_path'], '--directory', info._vagrant['folder']] + box_files ) import logging logging.getLogger(__name__).info('The vagrant box has been placed at ' + info._vagrant['box_path'])
def run(cls, info): import os from bootstrapvz.common.tools import sed_i grub_config = os.path.join(info.root, 'etc/default/grub') sed_i(grub_config, r'^(GRUB_CMDLINE_LINUX*=".*)"\s*$', r'\1console=ttyS0 earlyprintk=ttyS0 rootdelay=300"') sed_i(grub_config, r'^.*(GRUB_TIMEOUT=).*$', r'GRUB_TIMEOUT=0')
def run(cls, info): vagrantfile_source = os.path.join(assets, 'Vagrantfile') vagrantfile = os.path.join(info._vagrant['folder'], 'Vagrantfile') shutil.copy(vagrantfile_source, vagrantfile) import random mac_address = '080027{mac:06X}'.format(mac=random.randrange(16**6)) from bootstrapvz.common.tools import sed_i sed_i(vagrantfile, '\\[MAC_ADDRESS\\]', mac_address) metadata_source = os.path.join(assets, 'metadata.json') metadata = os.path.join(info._vagrant['folder'], 'metadata.json') shutil.copy(metadata_source, metadata) from bootstrapvz.common.tools import log_check_call disk_name = 'box-disk1.' + info.volume.extension disk_link = os.path.join(info._vagrant['folder'], disk_name) log_check_call(['ln', '-s', info.volume.image_path, disk_link]) ovf_path = os.path.join(info._vagrant['folder'], 'box.ovf') cls.write_ovf(info, ovf_path, mac_address, disk_name) box_files = os.listdir(info._vagrant['folder']) log_check_call([ 'tar', '--create', '--gzip', '--dereference', '--file', info._vagrant['box_path'], '--directory', info._vagrant['folder'] ] + box_files) import logging logging.getLogger(__name__).info( 'The vagrant box has been placed at ' + info._vagrant['box_path'])
def run(cls, info): # Download bootstrap script bootstrap_script = os.path.join(info.root, 'install_salt.sh') with open(bootstrap_script, 'w') as f: d = urllib.urlopen('http://bootstrap.saltstack.org') f.write(d.read()) # This is needed since bootstrap doesn't handle -X for debian distros properly. # We disable checking for running services at end since we do not start them. sed_i(bootstrap_script, 'install_debian_check_services', "disabled_debian_check_services") bootstrap_command = [ 'chroot', info.root, 'bash', 'install_salt.sh', '-X' ] if 'master' in info.manifest.plugins['salt']: bootstrap_command.extend( ['-A', info.manifest.plugins['salt']['master']]) install_source = info.manifest.plugins['salt']['install_source'] bootstrap_command.append(install_source) if install_source == 'git' and ('version' in info.manifest.plugins['salt']): bootstrap_command.append(info.manifest.plugins['salt']['version']) log_check_call(bootstrap_command)
def run(cls, info): from bootstrapvz.common.tools import log_check_call import os waagent_version = info.manifest.provider['waagent']['version'] waagent_file = 'WALinuxAgent-' + waagent_version + '.tar.gz' waagent_url = 'https://github.com/Azure/WALinuxAgent/archive/' + waagent_file log_check_call(['wget', '-P', info.root, waagent_url]) waagent_directory = os.path.join(info.root, 'root') log_check_call([ 'tar', 'xaf', os.path.join(info.root, waagent_file), '-C', waagent_directory ]) os.remove(os.path.join(info.root, waagent_file)) waagent_script = '/root/WALinuxAgent-WALinuxAgent-' + waagent_version + '/waagent' log_check_call( ['chroot', info.root, 'cp', waagent_script, '/usr/sbin/waagent']) log_check_call( ['chroot', info.root, 'chmod', '755', '/usr/sbin/waagent']) log_check_call(['chroot', info.root, 'waagent', '-install']) if info.manifest.provider['waagent'].get('conf', False): if os.path.isfile(info.manifest.provider['waagent']['conf']): log_check_call([ 'cp', info.manifest.provider['waagent']['conf'], os.path.join(info.root, 'etc/waagent.conf') ]) # The Azure Linux agent uses 'useradd' to add users, but SHELL # is set to /bin/sh by default. Set this to /bin/bash instead. from bootstrapvz.common.tools import sed_i useradd_config = os.path.join(info.root, 'etc/default/useradd') sed_i(useradd_config, r'^(SHELL=.*)', r'SHELL=/bin/bash')
def run(cls, info): # The dhcp client that ships with debian sets the DNS servers per default. # For dhcpcd in Wheezy and earlier we need to configure it to do that. if info.release_codename not in {'jessie', 'sid'}: from bootstrapvz.common.tools import sed_i dhcpcd = os.path.join(info.root, 'etc/default/dhcpcd') sed_i(dhcpcd, '^#*SET_DNS=.*', 'SET_DNS=\'yes\'')
def run(cls, info): # The dhcp client that ships with debian sets the DNS servers per default. # For dhcpcd in Wheezy and earlier we need to configure it to do that. from bootstrapvz.common.releases import wheezy if info.manifest.release <= wheezy: from bootstrapvz.common.tools import sed_i dhcpcd = os.path.join(info.root, 'etc/default/dhcpcd') sed_i(dhcpcd, '^#*SET_DNS=.*', 'SET_DNS=\'yes\'')
def run(cls, info): from ..tools import sed_i inittab_path = os.path.join(info.root, 'etc/inittab') tty1 = '1:2345:respawn:/sbin/getty 38400 tty1' sed_i(inittab_path, '^' + tty1, '#' + tty1) ttyx = ':23:respawn:/sbin/getty 38400 tty' for i in range(2, 7): i = str(i) sed_i(inittab_path, '^' + i + ttyx + i, '#' + i + ttyx + i)
def run(cls, info): init_src = os.path.join(ASSETS_DIR, 'init.d/docker') info.initd['install']['docker'] = init_src default_src = os.path.join(ASSETS_DIR, 'default/docker') default_dest = os.path.join(info.root, 'etc/default/docker') shutil.copy(default_src, default_dest) docker_opts = info.manifest.plugins['docker_daemon'].get('docker_opts') if docker_opts: sed_i(default_dest, r'^#*DOCKER_OPTS=.*$', 'DOCKER_OPTS="%s"' % docker_opts)
def run(cls, info): hostname = info.manifest.system['hostname'].format(**info.manifest_vars) hostname_file_path = os.path.join(info.root, 'etc/hostname') with open(hostname_file_path, 'w') as hostname_file: hostname_file.write(hostname) hosts_path = os.path.join(info.root, 'etc/hosts') from bootstrapvz.common.tools import sed_i sed_i(hosts_path, '^127.0.0.1\tlocalhost$', '127.0.0.1\tlocalhost\n127.0.1.1\t' + hostname)
def run(cls, info): from bootstrapvz.common.tools import sed_i cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg') username = info.manifest.plugins['cloud_init']['username'] search = '^ name: debian$' replace = (' name: {username}\n' ' sudo: ALL=(ALL) NOPASSWD:ALL\n' ' shell: /bin/bash').format(username=username) sed_i(cloud_cfg, search, replace)
def run(cls, info): sshdconfig_path = os.path.join(info.root, 'etc/ssh/sshd_config') if os.path.exists(sshdconfig_path): from bootstrapvz.common.tools import sed_i sed_i(sshdconfig_path, '^#?PermitRootLogin .*', 'PermitRootLogin no') else: import logging logging.getLogger(__name__).warn('The OpenSSH server has not been installed, ' 'not disabling SSH root login.')
def run(cls, info): sshdconfig_path = os.path.join(info.root, 'etc/ssh/sshd_config') if os.path.exists(sshdconfig_path): from bootstrapvz.common.tools import sed_i sed_i(sshdconfig_path, '^PermitRootLogin .*', 'PermitRootLogin no') else: import logging logging.getLogger(__name__).warn('The OpenSSH server has not been installed, ' 'not disabling SSH root login.')
def run(cls, info): from bootstrapvz.common.releases import squeeze if info.manifest.release == squeeze: # On squeeze /etc/default/extlinux is generated when running extlinux-update log_check_call(['chroot', info.root, 'extlinux-update']) from bootstrapvz.common.tools import sed_i extlinux_def = os.path.join(info.root, 'etc/default/extlinux') sed_i(extlinux_def, r'^EXTLINUX_PARAMETERS="([^"]+)"$', r'EXTLINUX_PARAMETERS="\1 console=ttyS0"')
def run(cls, info): from bootstrapvz.common.tools import sed_i cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg') groups = info.manifest.plugins['cloud_init']['groups'] search = ('^ groups: \[adm, audio, cdrom, dialout, floppy, video,' ' plugdev, dip\]$') replace = (' groups: [adm, audio, cdrom, dialout, floppy, video,' ' plugdev, dip, {groups}]').format(groups=', '.join(groups)) sed_i(cloud_cfg, search, replace)
def run(cls, info): from bootstrapvz.common.tools import sed_i cloud_cfg = os.path.join(info.root, "etc/cloud/cloud.cfg") username = info.manifest.plugins["cloud_init"]["username"] search = "^ name: debian$" replace = (" name: {username}\n" " sudo: ALL=(ALL) NOPASSWD:ALL\n" " shell: /bin/bash").format( username=username ) sed_i(cloud_cfg, search, replace)
def run(cls, info): # The dhcp client that ships with debian sets the DNS servers per default. # For dhcpcd in Wheezy and earlier we need to configure it to do that. from bootstrapvz.common.releases import wheezy if info.manifest.release <= wheezy: from bootstrapvz.common.tools import sed_i dhcpcd = os.path.join(info.root, "etc/default/dhcpcd") sed_i(dhcpcd, "^#*SET_DNS=.*", "SET_DNS='yes'")
def run(cls, info): from subprocess import CalledProcessError from bootstrapvz.common.tools import log_check_call try: log_check_call(['chroot', info.root, 'dpkg-query', '-W', 'openssh-server']) from bootstrapvz.common.tools import sed_i sshdconfig_path = os.path.join(info.root, 'etc/ssh/sshd_config') sed_i(sshdconfig_path, 'PermitRootLogin yes', 'PermitRootLogin no') except CalledProcessError: import logging logging.getLogger(__name__).warn('The OpenSSH server has not been installed, ' 'not disabling SSH root login.')
def run(cls, info): from subprocess import CalledProcessError from bootstrapvz.common.tools import log_check_call try: log_check_call( ['chroot', info.root, 'dpkg-query', '-W', 'openssh-server']) from bootstrapvz.common.tools import sed_i sshdconfig_path = os.path.join(info.root, 'etc/ssh/sshd_config') sed_i(sshdconfig_path, 'PermitRootLogin yes', 'PermitRootLogin no') except CalledProcessError: import logging logging.getLogger(__name__).warn( 'The OpenSSH server has not been installed, ' 'not disabling SSH root login.')
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): with open(os.path.join(info.root, 'etc/hostname')) as handle: hostname = handle.read().strip() with open(os.path.join(info.root, 'etc/hosts'), 'a') as handle: handle.write('127.0.0.1\t{hostname}\n'.format(hostname=hostname)) from shutil import copy pp_manifest = info.manifest.plugins['puppet']['manifest'] manifest_rel_dst = os.path.join('tmp', os.path.basename(pp_manifest)) manifest_dst = os.path.join(info.root, manifest_rel_dst) copy(pp_manifest, manifest_dst) manifest_path = os.path.join('/', manifest_rel_dst) log_check_call(['chroot', info.root, 'puppet', 'apply', '--verbose', '--debug', manifest_path]) os.remove(manifest_dst) hosts_path = os.path.join(info.root, 'etc/hosts') sed_i(hosts_path, '127.0.0.1\s*{hostname}\n?'.format(hostname=hostname), '')
def run(cls, info): from bootstrapvz.common.tools import sed_i grub_def = os.path.join(info.root, 'etc/default/grub') sed_i(grub_def, '^#GRUB_TERMINAL=console', 'GRUB_TERMINAL=console') sed_i(grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT="quiet"', 'GRUB_CMDLINE_LINUX_DEFAULT="console=hvc0"') sed_i(grub_def, '^GRUB_TIMEOUT=[0-9]+', 'GRUB_TIMEOUT=0\n' 'GRUB_HIDDEN_TIMEOUT=true') sed_i(grub_def, '^#GRUB_DISABLE_RECOVERY="true"', 'GRUB_DISABLE_RECOVERY="true"')
def run(cls, info): from bootstrapvz.common.tools import sed_i grub_config = os.path.join(info.root, "etc/default/grub") sed_i(grub_config, r"^(GRUB_CMDLINE_LINUX_DEFAULT=.*)", r'GRUB_CMDLINE_LINUX_DEFAULT=""') sed_i( grub_config, r'^(GRUB_CMDLINE_LINUX*=".*)"\s*$', r'\1console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300"', ) sed_i(grub_config, r"^(GRUB_HIDDEN_TIMEOUT=).*", r"#GRUB_HIDDEN_TIMEOUT=true") sed_i(grub_config, r"^.*(GRUB_TIMEOUT=).*$", r"GRUB_TIMEOUT=5")
def run(cls, info): from bootstrapvz.common.tools import sed_i grub_config = os.path.join(info.root, 'etc/default/grub') sed_i(grub_config, r'^(GRUB_CMDLINE_LINUX_DEFAULT=.*)', r'GRUB_CMDLINE_LINUX_DEFAULT=""') sed_i( grub_config, r'^(GRUB_CMDLINE_LINUX*=".*)"\s*$', r'\1console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300"' ) sed_i(grub_config, r'^(GRUB_HIDDEN_TIMEOUT=).*', r'#GRUB_HIDDEN_TIMEOUT=true') sed_i(grub_config, r'^.*(GRUB_TIMEOUT=).*$', r'GRUB_TIMEOUT=5')
def run(cls, info): vagrantfile_source = os.path.join(assets, 'Vagrantfile') vagrantfile = os.path.join(info._vagrant['folder'], 'Vagrantfile') shutil.copy(vagrantfile_source, vagrantfile) import random mac_address = '080027{mac:06X}'.format(mac=random.randrange(16**6)) from bootstrapvz.common.tools import sed_i sed_i(vagrantfile, '\\[MAC_ADDRESS\\]', mac_address) vagrant_provider = info.manifest.plugins['vagrant'].get( 'provider', 'virtualbox') metadata = {'provider': vagrant_provider} if vagrant_provider == 'libvirt': metadata['format'] = info.manifest.volume['backing'] virtual_size = info.volume.size.bytes.get_qty_in('G') metadata['virtual_size'] = virtual_size metadata_file = os.path.join(info._vagrant['folder'], 'metadata.json') with open(metadata_file, 'w') as f: json.dump(metadata, f) from bootstrapvz.common.tools import log_check_call if vagrant_provider == 'libvirt': disk_name = 'box.img' else: disk_name = 'box-disk1.' + info.volume.extension ovf_path = os.path.join(info._vagrant['folder'], 'box.ovf') cls.write_ovf(info, ovf_path, mac_address, disk_name) disk_link = os.path.join(info._vagrant['folder'], disk_name) log_check_call(['ln', '-s', info.volume.image_path, disk_link]) box_files = os.listdir(info._vagrant['folder']) log_check_call([ 'tar', '--create', '--gzip', '--dereference', '--file', info._vagrant['box_path'], '--directory', info._vagrant['folder'] ] + box_files) import logging logging.getLogger(__name__).info( 'The vagrant box has been placed at ' + info._vagrant['box_path'])
def run(cls, info): with open(os.path.join(info.root, "etc/hostname")) as handle: hostname = handle.read().strip() with open(os.path.join(info.root, "etc/hosts"), "a") as handle: handle.write("127.0.0.1\t{hostname}\n".format(hostname=hostname)) from shutil import copy pp_manifest = info.manifest.plugins["puppet"]["manifest"] manifest_rel_dst = os.path.join("tmp", os.path.basename(pp_manifest)) manifest_dst = os.path.join(info.root, manifest_rel_dst) copy(pp_manifest, manifest_dst) manifest_path = os.path.join("/", manifest_rel_dst) from bootstrapvz.common.tools import log_check_call log_check_call(["chroot", info.root, "puppet", "apply", manifest_path]) os.remove(manifest_dst) hosts_path = os.path.join(info.root, "etc/hosts") sed_i(hosts_path, "127.0.0.1\s*{hostname}\n?".format(hostname=hostname), "")
def run(cls, info): import stat x_all = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH grubd = os.path.join(info.root, "etc/grub.d") for cfg in [os.path.join(grubd, f) for f in os.listdir(grubd)]: os.chmod(cfg, os.stat(cfg).st_mode & ~x_all) from shutil import copy script_src = os.path.join(assets, "grub.d/40_custom") script_dst = os.path.join(info.root, "etc/grub.d/40_custom") copy(script_src, script_dst) os.chmod(script_dst, 0755) from bootstrapvz.base.fs.partitionmaps.none import NoPartitions if not isinstance(info.volume.partition_map, NoPartitions): from bootstrapvz.common.tools import sed_i root_idx = info.volume.partition_map.root.get_index() grub_device = "GRUB_DEVICE=/dev/xvda" + str(root_idx) sed_i(script_dst, "^GRUB_DEVICE=/dev/xvda$", grub_device) grub_root = "\troot (hd0,{idx})".format(idx=root_idx - 1) sed_i(script_dst, "^\troot \(hd0\)$", grub_root) if info.manifest.volume["backing"] == "s3": from bootstrapvz.common.tools import sed_i sed_i(script_dst, "^GRUB_DEVICE=/dev/xvda$", "GRUB_DEVICE=/dev/xvda1")
def run(cls, info): import stat x_all = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH grubd = os.path.join(info.root, 'etc/grub.d') for cfg in [os.path.join(grubd, f) for f in os.listdir(grubd)]: os.chmod(cfg, os.stat(cfg).st_mode & ~x_all) from shutil import copy script_src = os.path.join(assets, 'grub.d/40_custom') script_dst = os.path.join(info.root, 'etc/grub.d/40_custom') copy(script_src, script_dst) os.chmod(script_dst, 0o755) from bootstrapvz.base.fs.partitionmaps.none import NoPartitions if not isinstance(info.volume.partition_map, NoPartitions): from bootstrapvz.common.tools import sed_i root_idx = info.volume.partition_map.root.get_index() grub_device = 'GRUB_DEVICE=/dev/xvda' + str(root_idx) sed_i(script_dst, '^GRUB_DEVICE=/dev/xvda$', grub_device) grub_root = '\troot (hd0,{idx})'.format(idx=root_idx - 1) sed_i(script_dst, '^\troot \(hd0\)$', grub_root) if info.manifest.volume['backing'] == 's3': from bootstrapvz.common.tools import sed_i sed_i(script_dst, '^GRUB_DEVICE=/dev/xvda$', 'GRUB_DEVICE=/dev/xvda1')
def run(cls, info): # Download bootstrap script bootstrap_script = os.path.join(info.root, "install_salt.sh") with open(bootstrap_script, "w") as f: d = urllib.urlopen("http://bootstrap.saltstack.org") f.write(d.read()) # This is needed since bootstrap doesn't handle -X for debian distros properly. # We disable checking for running services at end since we do not start them. sed_i(bootstrap_script, "install_debian_check_services", "disabled_debian_check_services") bootstrap_command = ["chroot", info.root, "bash", "install_salt.sh", "-X"] if "master" in info.manifest.plugins["salt"]: bootstrap_command.extend(["-A", info.manifest.plugins["salt"]["master"]]) install_source = info.manifest.plugins["salt"]["install_source"] bootstrap_command.append(install_source) if install_source == "git" and ("version" in info.manifest.plugins["salt"]): bootstrap_command.append(info.manifest.plugins["salt"]["version"]) log_check_call(bootstrap_command)
def run(cls, info): # Download bootstrap script bootstrap_script = os.path.join(info.root, 'install_salt.sh') with open(bootstrap_script, 'w') as f: d = urllib.urlopen('http://bootstrap.saltstack.org') f.write(d.read()) # This is needed since bootstrap doesn't handle -X for debian distros properly. # We disable checking for running services at end since we do not start them. sed_i(bootstrap_script, 'install_debian_check_services', 'disabled_debian_check_services') bootstrap_command = ['chroot', info.root, 'bash', 'install_salt.sh', '-X'] if 'master' in info.manifest.plugins['salt']: bootstrap_command.extend(['-A', info.manifest.plugins['salt']['master']]) install_source = info.manifest.plugins['salt'].get('install_source', 'stable') bootstrap_command.append(install_source) if install_source == 'git' and ('version' in info.manifest.plugins['salt']): bootstrap_command.append(info.manifest.plugins['salt']['version']) log_check_call(bootstrap_command)
def run(cls, info): expand_root_script = os.path.join(ASSETS_DIR, 'expand-root.sh') expand_root_service = os.path.join(ASSETS_DIR, 'expand-root.service') expand_root_script_dest = os.path.join(info.root, 'usr/bin/expand-root.sh') expand_root_service_dest = os.path.join(info.root, 'lib/systemd/system/expand-root.service') filesystem_type = info.manifest.plugins['expand_root'].get('filesystem_type') root_device = info.manifest.plugins['expand_root'].get('root_device') root_partition = info.manifest.plugins['expand_root'].get('root_partition') # Copy files over shutil.copy(expand_root_script, expand_root_script_dest) os.chmod(expand_root_script_dest, 0750) shutil.copy(expand_root_service, expand_root_service_dest) # Expand out options into expand-root.sh script. opts = '%s %s %s' % (root_device, root_partition, filesystem_type) sed_i(expand_root_service_dest, r'^ExecStart=/usr/bin/expand-root.sh.*$', 'ExecStart=/usr/bin/expand-root.sh %s' % opts) # Enable systemd service log_check_call(['chroot', info.root, 'systemctl', 'enable', 'expand-root.service'])
def run(cls, info): from bootstrapvz.common.tools import log_check_call import os waagent_version = info.manifest.provider['waagent']['version'] waagent_file = 'WALinuxAgent-' + waagent_version + '.tar.gz' waagent_url = 'https://github.com/Azure/WALinuxAgent/archive/' + waagent_file log_check_call(['wget', '-P', info.root, waagent_url]) waagent_directory = os.path.join(info.root, 'root') log_check_call(['tar', 'xaf', os.path.join(info.root, waagent_file), '-C', waagent_directory]) os.remove(os.path.join(info.root, waagent_file)) waagent_script = '/root/WALinuxAgent-WALinuxAgent-' + waagent_version + '/waagent' log_check_call(['chroot', info.root, 'cp', waagent_script, '/usr/sbin/waagent']) log_check_call(['chroot', info.root, 'chmod', '755', '/usr/sbin/waagent']) log_check_call(['chroot', info.root, 'waagent', '-install']) if info.manifest.provider['waagent'].get('conf', False): if os.path.isfile(info.manifest.provider['waagent']['conf']): log_check_call(['cp', info.manifest.provider['waagent']['conf'], os.path.join(info.root, 'etc/waagent.conf')]) # The Azure Linux agent uses 'useradd' to add users, but SHELL # is set to /bin/sh by default. Set this to /bin/bash instead. from bootstrapvz.common.tools import sed_i useradd_config = os.path.join(info.root, 'etc/default/useradd') sed_i(useradd_config, r'^(SHELL=.*)', r'SHELL=/bin/bash')
def run(cls, info): from bootstrapvz.common.tools import sed_i grub_def = os.path.join(info.root, "etc/default/grub") sed_i(grub_def, "^#GRUB_TERMINAL=console", "GRUB_TERMINAL=console") sed_i(grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT="quiet"', 'GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"')
def run(cls, info): from bootstrapvz.common.tools import sed_i grub_def = os.path.join(info.root, 'etc/default/grub') sed_i(grub_def, '^#GRUB_TERMINAL=console', 'GRUB_TERMINAL=console') sed_i(grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT="quiet"', 'GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"')
def run(cls, info): # The dhcp client that ships with debian sets the DNS servers per default. # For dhcpcd we need to configure it to do that. from bootstrapvz.common.tools import sed_i dhcpcd = os.path.join(info.root, 'etc/default/dhcpcd') sed_i(dhcpcd, '^#*SET_DNS=.*', 'SET_DNS=\'yes\'')
def run(cls, info): from bootstrapvz.common.tools import sed_i script = os.path.join(info.root, 'etc/init.d/expand-root') sed_i(script, '/dev/xvda', '/dev/sda')
def run(cls, info): import stat rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) x_all = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH grubd = os.path.join(info.root, 'etc/grub.d') for cfg in [os.path.join(grubd, f) for f in os.listdir(grubd)]: os.chmod(cfg, os.stat(cfg).st_mode & ~x_all) from shutil import copy script_src = os.path.join(assets, 'grub.d/40_custom') script_dst = os.path.join(info.root, 'etc/grub.d/40_custom') copy(script_src, script_dst) os.chmod(script_dst, rwxr_xr_x) from bootstrapvz.base.fs.partitionmaps.none import NoPartitions if not isinstance(info.volume.partition_map, NoPartitions): from bootstrapvz.common.tools import sed_i root_idx = info.volume.partition_map.root.get_index() grub_device = 'GRUB_DEVICE=/dev/xvda' + str(root_idx) sed_i(script_dst, '^GRUB_DEVICE=/dev/xvda$', grub_device) grub_root = '\troot (hd0,{idx})'.format(idx=root_idx - 1) sed_i(script_dst, '^\troot \(hd0\)$', grub_root) if info.manifest.volume['backing'] == 's3': from bootstrapvz.common.tools import sed_i sed_i(script_dst, '^GRUB_DEVICE=/dev/xvda$', 'GRUB_DEVICE=/dev/xvda1') from bootstrapvz.common.tools import sed_i grub_def = os.path.join(info.root, 'etc/default/grub') sed_i(grub_def, '^GRUB_TIMEOUT=[0-9]+', 'GRUB_TIMEOUT=0\n' 'GRUB_HIDDEN_TIMEOUT=true') sed_i(grub_def, '^#GRUB_TERMINAL=console', 'GRUB_TERMINAL=console') sed_i( grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT=.*', 'GRUB_CMDLINE_LINUX_DEFAULT="consoleblank=0 console=hvc0 elevator=noop"' ) from bootstrapvz.common.tools import log_check_call log_check_call(['chroot', info.root, 'update-grub']) log_check_call([ 'chroot', info.root, 'ln', '--symbolic', '/boot/grub/grub.cfg', '/boot/grub/menu.lst' ])
def run(cls, info): from bootstrapvz.common.tools import sed_i grub_config = os.path.join(info.root, 'etc/default/grub') sed_i(grub_config, r'^(GRUB_CMDLINE_LINUX*=".*)"\s*$', r'\1console=ttyS0,38400n8 elevator=noop"') sed_i(grub_config, r'^.*(GRUB_TIMEOUT=).*$', r'GRUB_TIMEOUT=0')
def run(cls, info): from ..tools import sed_i sshd_config_path = os.path.join(info.root, 'etc/ssh/sshd_config') sed_i(sshd_config_path, '^#PasswordAuthentication yes', 'PasswordAuthentication no')
def run(cls, info): from bootstrapvz.common.tools import sed_i dhcpcd = os.path.join(info.root, 'etc/default/dhcpcd') sed_i(dhcpcd, '^#*SET_DNS=.*', 'SET_DNS=\'yes\'')
def run(cls, info): from bootstrapvz.common.tools import sed_i grub_config = os.path.join(info.root, 'etc/default/grub') sed_i(grub_config, r'^(GRUB_CMDLINE_LINUX*=".*)"\s*$', r'\1console=ttyS0,38400n8"') sed_i(grub_config, r'^.*(GRUB_TIMEOUT=).*$', r'GRUB_TIMEOUT=0')
def run(cls, info): from bootstrapvz.common.tools import sed_i extlinux_def = os.path.join(info.root, 'etc/default/extlinux') sed_i(extlinux_def, r'^EXTLINUX_PARAMETERS="([^"]+)"$', r'EXTLINUX_PARAMETERS="\1 console=ttyS0"')
def run(cls, info): from bootstrapvz.common.tools import sed_i script = os.path.join(info.root, 'etc/init.d/expand-root') sed_i(script, '/dev/loop0', '/dev/sda')
def run(cls, info): puppet_defaults = os.path.join(info.root, 'etc/defaults/puppet') sed_i(puppet_defaults, 'START=no', 'START=yes')