def print_dns(client, name): for server in client.servers.list(): if server.name != name: continue ip4 = utils.get_public_ip(server) ip6 = utils.get_public_ip(server, 6) href = utils.get_href(server) print print "Run the following commands to set up DNS:" print print ". ~root/rackdns-venv/bin/activate" print print ("rackdns rdns-create --name %s \\\n" " --data %s \\\n" " --server-href %s \\\n" " --ttl 3600" % ( server.name, ip6, href)) print print ("rackdns rdns-create --name %s \\\n" " --data %s \\\n" " --server-href %s \\\n" " --ttl 3600" % ( server.name, ip4, href)) print print ". ~root/ci-launch/openstack-rs-nova.sh" print print ("rackdns record-create --name %s \\\n" " --type AAAA --data %s \\\n" " --ttl 3600 openstack.org" % ( server.name, ip6)) print print ("rackdns record-create --name %s \\\n" " --type A --data %s \\\n" " --ttl 3600 openstack.org" % ( server.name, ip4))
def check_machine(jenkins, client, machine, error_counts): try: server = client.servers.get(machine.external_id) except: print "Unable to get server detail, will retry" traceback.print_exc() return if server.status == "ACTIVE": ip = utils.get_public_ip(server) if not ip and "os-floating-ips" in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") machine.ip = ip print "Machine %s is running, testing ssh" % machine.id if utils.ssh_connect(ip, "jenkins"): print "Adding machine %s to Jenkins" % machine.id create_jenkins_node(jenkins, machine) print "Machine %s is ready" % machine.id machine.state = vmdatabase.READY return elif not server.status.startswith("BUILD"): count = error_counts.get(machine.id, 0) count += 1 error_counts[machine.id] = count print "Machine %s is in error %s (%s/5)" % (machine.id, server.status, count) if count >= 5: raise Exception("Too many errors querying machine %s" % machine.id) else: if time.time() - machine.state_time >= ABANDON_TIMEOUT: raise Exception("Waited too long for machine %s" % machine.id)
def bootstrap_server(provider, server, admin_pass, key): client = server.manager.api ip = utils.get_public_ip(server) if not ip and "os-floating-ips" in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs["pkey"] = key else: ssh_kwargs["password"] = admin_pass for username in ["root", "ubuntu"]: client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if client: break if not client: raise Exception("Unable to log in via SSH") # hpcloud can't reliably set the hostname gerrit_url = "https://review.openstack.org/p/openstack-infra/config.git" client.ssh("set hostname", "sudo hostname %s" % server.name) client.ssh( "get puppet repo deb", "sudo /usr/bin/wget " "http://apt.puppetlabs.com/puppetlabs-release-" "`lsb_release -c -s`.deb -O /root/puppet-repo.deb", ) client.ssh("install puppet repo deb", "sudo dpkg -i /root/puppet-repo.deb") client.ssh("update apt cache", "sudo apt-get update") client.ssh( "upgrading system packages", "sudo DEBIAN_FRONTEND=noninteractive apt-get " '--option "Dpkg::Options::=--force-confold"' " --assume-yes dist-upgrade", ) client.ssh( "install git and puppet", "sudo DEBIAN_FRONTEND=noninteractive apt-get " '--option "Dpkg::Options::=--force-confold"' " --assume-yes install git puppet", ) client.ssh("clone puppret repo", "sudo git clone %s /root/config" % gerrit_url) client.ssh("install puppet modules", "sudo /bin/bash /root/config/install_modules.sh") client.ssh( "run puppet", "sudo puppet apply --modulepath=/root/config/modules:" "/etc/puppet/modules " '-e "%s"' % PUPPET_CLASS, )
def bootstrap_server(name, server, admin_pass, key, environment): client = server.manager.api ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if not key: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") ssh_client.ssh('sudo hostname `curl http://169.254.169.254/2009-04-04/meta-data/hostname`' % name) if username != 'root': ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, 'root', ssh_kwargs, timeout=600) ssh_client.ssh('git clone https://github.com/emonty/config') ssh_client.ssh('sudo bash -x config/install_modules.sh') ssh_client.ssh('sudo puppet apply' ' --modulepath=`pwd`/config/modules:/etc/puppet/modules' ' config/manifests/site.pp')
def check_machine(jenkins, client, machine, error_counts): try: server = client.servers.get(machine.external_id) except: print "Unable to get server detail, will retry" traceback.print_exc() return if server.status == 'ACTIVE': ip = utils.get_public_ip(server) if not ip and 'os-floating-ips' in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") machine.ip = ip print "Machine %s is running, testing ssh" % machine.id if utils.ssh_connect(ip, 'jenkins'): if statsd: dt = int((time.time() - machine.state_time) * 1000) key = 'devstack.launch.%s' % machine.base_image.provider.name statsd.timing(key, dt) statsd.incr(key) print "Adding machine %s to Jenkins" % machine.id create_jenkins_node(jenkins, machine) print "Machine %s is ready" % machine.id machine.state = vmdatabase.READY return elif not server.status.startswith('BUILD'): count = error_counts.get(machine.id, 0) count += 1 error_counts[machine.id] = count print "Machine %s is in error %s (%s/5)" % (machine.id, server.status, count) if count >= 5: if statsd: statsd.incr('devstack.error.%s' % machine.base_image.provider.name) raise Exception("Too many errors querying machine %s" % machine.id) else: if time.time() - machine.state_time >= ABANDON_TIMEOUT: if statsd: statsd.incr('devstack.timeout.%s' % machine.base_image.provider.name) raise Exception("Waited too long for machine %s" % machine.id)
def bootstrap_server(server, admin_pass, key, cert): client = server.manager.api ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") if username != 'root': ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, 'root', ssh_kwargs, timeout=600) ssh_client.ssh("apt-get update") ssh_client.ssh("DEBIAN_FRONTEND=noninteractive apt-get --option" " 'Dpkg::Options::=--force-confold'" " --assume-yes upgrade") ssh_client.ssh("apt-get install -y --force-yes puppet") certname = cert[:0-len('.pem')] ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys") ssh_client.ssh("chown -R puppet:root /var/lib/puppet/ssl") ssh_client.ssh("chmod 0771 /var/lib/puppet/ssl") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/certs") ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys") for ssldir in ['/var/lib/puppet/ssl/certs/', '/var/lib/puppet/ssl/private_keys/', '/var/lib/puppet/ssl/public_keys/']: ssh_client.scp(os.path.join(ssldir, cert), os.path.join(ssldir, cert)) ssh_client.scp("/var/lib/puppet/ssl/crl.pem", "/var/lib/puppet/ssl/crl.pem") ssh_client.scp("/var/lib/puppet/ssl/certs/ca.pem", "/var/lib/puppet/ssl/certs/ca.pem") ssh_client.ssh("puppet agent " "--server ci-puppetmaster.openstack.org " "--no-daemonize --verbose --onetime " "--certname %s" % certname)
def bootstrap_server(server, admin_pass, key, cert, environment): client = server.manager.api ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") if username != 'root': ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, 'root', ssh_kwargs, timeout=600) ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'install_puppet.sh'), 'install_puppet.sh') ssh_client.ssh('bash -x install_puppet.sh') certname = cert[:0-len('.pem')] ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys") ssh_client.ssh("chown -R puppet:root /var/lib/puppet/ssl") ssh_client.ssh("chmod 0771 /var/lib/puppet/ssl") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/certs") ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys") for ssldir in ['/var/lib/puppet/ssl/certs/', '/var/lib/puppet/ssl/private_keys/', '/var/lib/puppet/ssl/public_keys/']: ssh_client.scp(os.path.join(ssldir, cert), os.path.join(ssldir, cert)) ssh_client.scp("/var/lib/puppet/ssl/crl.pem", "/var/lib/puppet/ssl/crl.pem") ssh_client.scp("/var/lib/puppet/ssl/certs/ca.pem", "/var/lib/puppet/ssl/certs/ca.pem") ssh_client.ssh("puppet agent " "--environment %s " "--server ci-puppetmaster.openstack.org " "--no-daemonize --verbose --onetime --pluginsync true " "--certname %s" % (environment, certname))
def bootstrap_server(provider, server, admin_pass, key): client = server.manager.api ip = utils.get_public_ip(server) if not ip and 'os-floating-ips' in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if client: break if not client: raise Exception("Unable to log in via SSH") # hpcloud can't reliably set the hostname gerrit_url = 'https://review.openstack.org/p/openstack/' \ 'openstack-ci-puppet.git' client.ssh("set hostname", "sudo hostname %s" % server.name) client.ssh("update apt cache", "sudo apt-get update") client.ssh("upgrading system packages", 'sudo DEBIAN_FRONTEND=noninteractive apt-get ' '--option "Dpkg::Options::=--force-confold"' ' --assume-yes upgrade') client.ssh("install git and puppet", 'sudo DEBIAN_FRONTEND=noninteractive apt-get ' '--option "Dpkg::Options::=--force-confold"' ' --assume-yes install git puppet') client.ssh("clone puppret repo", "sudo git clone %s /root/openstack-ci-puppet" % gerrit_url) client.ssh("run puppet", "sudo puppet apply " "--modulepath=/root/openstack-ci-puppet/modules" "/root/openstack-ci-puppet/manifests/site.pp")
def configure_server(server, branches): client = SSHClient(utils.get_public_ip(server), 'jenkins') client.ssh('make file cache directory', 'mkdir -p ~/cache/files') client.ssh('make pip cache directory', 'mkdir -p ~/cache/pip') client.ssh('install build-essential', 'sudo DEBIAN_FRONTEND=noninteractive ' 'apt-get --option "Dpkg::Options::=--force-confold"' ' --assume-yes install build-essential python-dev ' 'linux-headers-virtual linux-headers-`uname -r`') for branch_data in branches: if branch_data['debs']: client.ssh('cache debs for branch %s' % branch_data['name'], 'sudo apt-get -y -d install %s' % ' '.join(branch_data['debs'])) if branch_data['pips']: venv = client.ssh('get temp dir for venv', 'mktemp -d').strip() client.ssh('create venv', 'virtualenv --no-site-packages %s' % venv) client.ssh('cache pips for branch %s' % branch_data['name'], 'source %s/bin/activate && ' 'PIP_DOWNLOAD_CACHE=~/cache/pip pip install %s' % (venv, ' '.join(branch_data['pips']))) client.ssh('remove venv', 'rm -fr %s' % venv) for url in branch_data['images']: fname = url.split('/')[-1] try: client.ssh('check for %s' % fname, 'ls ~/cache/files/%s' % fname) except: client.ssh('download image %s' % fname, 'wget -nv -c %s -O ~/cache/files/%s' % (url, fname)) client.ssh('clear workspace', 'rm -rf ~/workspace-cache') client.ssh('make workspace', 'mkdir -p ~/workspace-cache') for project in PROJECTS: sp = project.split('/')[0] client.ssh('clone %s' % project, 'cd ~/workspace-cache && ' 'git clone https://review.openstack.org/p/%s' % project) script = os.environ.get('DEVSTACK_GATE_CUSTOM_SCRIPT', '') if script and os.path.isfile(script): bn = os.path.basename(script) client.scp(script, '/tmp/%s' % bn) client.ssh('run custom script %s' % bn, 'chmod +x /tmp/%s && sudo /tmp/%s' % (bn, bn)) client.ssh('sync', 'sync && sleep 5')
def configure_server(server, branches): client = SSHClient(utils.get_public_ip(server), "jenkins") client.ssh("make file cache directory", "mkdir -p ~/cache/files") client.ssh("make pip cache directory", "mkdir -p ~/cache/pip") client.ssh( "install build-essential", "sudo DEBIAN_FRONTEND=noninteractive " 'apt-get --option "Dpkg::Options::=--force-confold"' " --assume-yes install build-essential python-dev " "linux-headers-virtual linux-headers-`uname -r`", ) for branch_data in branches: if branch_data["debs"]: client.ssh( "cache debs for branch %s" % branch_data["name"], "sudo apt-get -y -d install %s" % " ".join(branch_data["debs"]), ) if branch_data["pips"]: venv = client.ssh("get temp dir for venv", "mktemp -d").strip() client.ssh("create venv", "virtualenv --no-site-packages %s" % venv) client.ssh( "cache pips for branch %s" % branch_data["name"], "source %s/bin/activate && " "PIP_DOWNLOAD_CACHE=~/cache/pip pip install %s" % (venv, " ".join(branch_data["pips"])), ) client.ssh("remove venv", "rm -fr %s" % venv) for url in branch_data["images"]: fname = url.split("/")[-1] try: client.ssh("check for %s" % fname, "ls ~/cache/files/%s" % fname) except: client.ssh("download image %s" % fname, "wget -nv -c %s -O ~/cache/files/%s" % (url, fname)) client.ssh("clear workspace", "rm -rf ~/workspace-cache") client.ssh("make workspace", "mkdir -p ~/workspace-cache") for project in PROJECTS: client.ssh( "clone %s" % project, "cd ~/workspace-cache && " "git clone https://review.openstack.org/p/%s" % project ) script = os.environ.get("DEVSTACK_GATE_CUSTOM_SCRIPT", "") if script and os.path.isfile(script): bn = os.path.basename(script) client.scp(script, "/tmp/%s" % bn) client.ssh("run custom script %s" % bn, "chmod +x /tmp/%s && sudo /tmp/%s" % (bn, bn)) client.ssh("sync", "sync && sleep 5")
def check_ip(): """ Retrieves the current public IP and updates the local file if it changed. """ if not os.path.isfile(paths.publip_ip_file): utils.create_empty_file(paths.publip_ip_file) with open(paths.publip_ip_file, 'r') as ip_file: with open(paths.publip_ip_file + '2', 'w+') as new_ip_file: old_ip = ip_file.read().rstrip('\n') new_ip = utils.get_public_ip() if old_ip != new_ip: LOG.info('New PublicIP: %s.', new_ip) new_ip_file.write(new_ip + os.linesep) os.rename(paths.publip_ip_file + '2', paths.publip_ip_file) email_utils.write_basic_email('We got a new IP.', 'The new IP is ' + str(new_ip))
def print_dns(client, name, dns_tool): for server in client.servers.list(): if server.name != name: continue domain = server.name.split('.', 1)[1] ip4 = utils.get_public_ip(server) ip6 = utils.get_public_ip(server, 6) href = utils.get_href(server) print print "Run the following commands to set up DNS:" print print ". ~root/rackdns-venv/bin/activate" print print ("%s rdns-create --name %s \\\n" " --data %s \\\n" " --server-href %s \\\n" " --ttl 3600 %s" % ( dns_tool, server.name, ip6, href, domain)) print print ("%s rdns-create --name %s \\\n" " --data %s \\\n" " --server-href %s \\\n" " --ttl 3600 %s" % ( dns_tool, server.name, ip4, href, domain)) print print ". ~root/ci-launch/openstack-rs-nova.sh" print print ("%s record-create --name %s \\\n" " --type AAAA --data %s \\\n" " --ttl 3600 %s" % ( dns_tool, server.name, ip6, domain)) print print ("%s record-create --name %s \\\n" " --type A --data %s \\\n" " --ttl 3600 %s" % ( dns_tool, server.name, ip4, domain))
def bootstrap_server(server, admin_pass, key, cert, environment, name, puppetmaster, volume): ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") if username != 'root': ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, 'root', ssh_kwargs, timeout=600) if IPV6: ssh_client.ssh('ping6 -c5 -Q 0x10 review.openstack.org ' '|| ping6 -c5 -Q 0x10 wiki.openstack.org') ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'make_swap.sh'), 'make_swap.sh') ssh_client.ssh('bash -x make_swap.sh') if volume: ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'mount_volume.sh'), 'mount_volume.sh') ssh_client.ssh('bash -x mount_volume.sh') # BH: Life seems better with this faked FQDN. It's not real. ssh_client.ssh('echo "10.242.0.208 ci-puppetmaster.openstacklocal" \ >> /etc/hosts') ssh_client.ssh('echo "%s" > /etc/hostname && service hostname restart' % name) # BH: this should be in the puppet: ssh_client.ssh('mkdir /var/www') ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'install_puppet.sh'), 'install_puppet.sh') # install correct puppet ssh_client.ssh('export PUPPET_VERSION=2.7 && bash -x install_puppet.sh') certname = cert[:(0 - len('.pem'))] ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys") ssh_client.ssh("chown -R puppet:root /var/lib/puppet/ssl") ssh_client.ssh("chown -R puppet:puppet /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0771 /var/lib/puppet/ssl") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/certs") ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys") for ssldir in ['/var/lib/puppet/ssl/certs/', '/var/lib/puppet/ssl/private_keys/', '/var/lib/puppet/ssl/public_keys/']: ssh_client.scp(os.path.join(ssldir, cert), os.path.join(ssldir, cert)) ssh_client.scp("/var/lib/puppet/ssl/crl.pem", "/var/lib/puppet/ssl/crl.pem") ssh_client.scp("/var/lib/puppet/ssl/certs/ca.pem", "/var/lib/puppet/ssl/certs/ca.pem") ssh_client.ssh("puppet agent " "--environment %s " "--server %s " "--no-daemonize --verbose --onetime --pluginsync true " "--certname %s" % (environment, puppetmaster, certname)) ssh_client.ssh("reboot")
##!/usr/bin/env python # -*- coding: utf-8 -*- import argparse import utils from utils import RG_NAME, UBUNTUGPU_VM parser = argparse.ArgumentParser() parser.add_argument("--start", action="store_true", help="start ubuntugpu machines") parser.add_argument("--stop", action="store_true", help="stop ubuntugpu machines") parser.add_argument("--remove", action="store_true", help="remove ubuntugpu VM and disks") args = parser.parse_args() assert args.start or args.stop or args.remove assert not (args.start and args.stop and args.remove) if args.start: action_func = utils.start_vm elif args.stop: action_func = utils.deallocate_vm elif args.remove: action_func = utils.remove_vm_and_disks if args.remove: # remove orphaned disks (to make sure) utils.remove_orphaned_disks(RG_NAME) action_func(UBUNTUGPU_VM, RG_NAME) if args.start: print("ubuntugpu public IP: {}".format(utils.get_public_ip("ip_ubuntugpu", RG_NAME)))
def bootstrap_server(server, admin_pass, key, cert, environment, name, puppetmaster, volume, floating_ip_pool): ip = utils.get_public_ip(server, floating_ip_pool=floating_ip_pool) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu', 'centos']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") # cloud-init puts the "please log in as user foo" message and # subsequent exit() in root's authorized_keys -- overwrite it with # a normal version to get root login working again. if username != 'root': ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, 'root', ssh_kwargs, timeout=600) if IPV6: ssh_client.ssh('ping6 -c5 -Q 0x10 review.openstack.org ' '|| ping6 -c5 -Q 0x10 wiki.openstack.org') ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'make_swap.sh'), 'make_swap.sh') ssh_client.ssh('bash -x make_swap.sh') if volume: ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'mount_volume.sh'), 'mount_volume.sh') ssh_client.ssh('bash -x mount_volume.sh') ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'install_puppet.sh'), 'install_puppet.sh') ssh_client.ssh('bash -x install_puppet.sh') certname = cert[:(0 - len('.pem'))] ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys") ssh_client.ssh("chown -R puppet:root /var/lib/puppet/ssl") ssh_client.ssh("chown -R puppet:puppet /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0771 /var/lib/puppet/ssl") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/certs") ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys") for ssldir in [ '/var/lib/puppet/ssl/certs/', '/var/lib/puppet/ssl/private_keys/', '/var/lib/puppet/ssl/public_keys/' ]: ssh_client.scp(os.path.join(ssldir, cert), os.path.join(ssldir, cert)) ssh_client.scp("/var/lib/puppet/ssl/crl.pem", "/var/lib/puppet/ssl/crl.pem") ssh_client.scp("/var/lib/puppet/ssl/certs/ca.pem", "/var/lib/puppet/ssl/certs/ca.pem") (rc, output) = ssh_client.ssh( "puppet agent " "--environment %s " "--server %s " "--detailed-exitcodes " "--no-daemonize --verbose --onetime --pluginsync true " "--certname %s" % (environment, puppetmaster, certname), error_ok=True) utils.interpret_puppet_exitcodes(rc, output) ssh_client.ssh("reboot")
def bootstrap_server(server, admin_pass, key, cert, environment, name, salt_priv, salt_pub): client = server.manager.api ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") if username != 'root': ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, 'root', ssh_kwargs, timeout=600) ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'install_puppet.sh'), 'install_puppet.sh') ssh_client.ssh('bash -x install_puppet.sh') certname = cert[:0 - len('.pem')] ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys") ssh_client.ssh("chown -R puppet:root /var/lib/puppet/ssl") ssh_client.ssh("chmod 0771 /var/lib/puppet/ssl") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/certs") ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys") # Assuming salt-master is running on the puppetmaster shutil.copyfile(salt_pub, os.path.join(SALT_MASTER_PKI, 'minions', name)) ssh_client.ssh('mkdir -p {0}'.format(SALT_MINION_PKI)) ssh_client.scp(salt_pub, os.path.join(SALT_MINION_PKI, 'minion.pub')) ssh_client.scp(salt_priv, os.path.join(SALT_MINION_PKI, 'minion.pem')) for ssldir in [ '/var/lib/puppet/ssl/certs/', '/var/lib/puppet/ssl/private_keys/', '/var/lib/puppet/ssl/public_keys/' ]: ssh_client.scp(os.path.join(ssldir, cert), os.path.join(ssldir, cert)) ssh_client.scp("/var/lib/puppet/ssl/crl.pem", "/var/lib/puppet/ssl/crl.pem") ssh_client.scp("/var/lib/puppet/ssl/certs/ca.pem", "/var/lib/puppet/ssl/certs/ca.pem") ssh_client.ssh("puppet agent " "--environment %s " "--server ci-puppetmaster.openstack.org " "--no-daemonize --verbose --onetime --pluginsync true " "--certname %s" % (environment, certname))
parser.add_argument("--user", action="store", help="account name, for example student1", required=True) parser.add_argument("--start", action="store_true", help="start cluster machines") parser.add_argument("--stop", action="store_true", help="stop cluster machines") parser.add_argument("--remove", action="store_true", help="remove cluster VMs and disks") parser.add_argument("--jobs", type=int, action="store", help="number of parallel jobs") args = parser.parse_args() student_name = args.user rg_name = utils.get_student_resource_group(student_name) assert args.start or args.stop or args.remove assert not (args.start and args.stop and args.remove) if args.start: action_func = utils.start_vm elif args.stop: action_func = utils.deallocate_vm elif args.remove: action_func = utils.remove_vm_and_disks if args.remove: # remove orphaned disks (to make sure) utils.remove_orphaned_disks(rg_name) Parallel(n_jobs=args.jobs or 3, backend="threading")( delayed(action_func)("cluster{0}".format(idx), rg_name) for idx in [1, 2, 3] ) if args.start: print("cluster1 public IP: {}".format(utils.get_public_ip("ip_cluster1", rg_name)))
# create VM https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-sizes IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \ "/resourceGroups/" + RG_NAME + "/providers/Microsoft.Compute/images/" + \ CLUSTER_IMAGE.format(idx) data_disks = "255 255 255 255" if idx == 1: cloud_init_fn = cloud_init_fill_template( "configs/cloud_init_cluster_master_template.txt", user_pass) else: cloud_init_fn = "configs/cloud_init_cluster_slave.txt" utils.create_vm(VM_NAME, RG_NAME, REGION, IMAGE_NAME, NIC_NAME, VM_SIZE, None, OS_DISK_NAME, user_pass, cloud_init_fn, data_disks, "Standard_LRS") if RESIZE_OS_DISK: utils.deallocate_vm(VM_NAME, RG_NAME) utils.resize_managed_disk(RG_NAME, OS_DISK_NAME, OS_DISK_SIZE) utils.start_vm(VM_NAME, RG_NAME) user_pass = utils.generate_pass() Parallel(n_jobs=args.jobs or 3, backend="threading")(delayed(create_cluster_node)(idx, user_pass) for idx in [1, 2, 3]) print("cluster1 public IP: {}".format( utils.get_public_ip("ip_cluster1", RG_NAME))) print("password:", user_pass)
MAIN_DB, PROBABILITIES, get_public_ip, check_internet, MAIN_DB_MIN_SIZE, get_seconds_to_wait, USE_SLEEP_SCHEDULE, reddit_bot_action, get_current_epoch, COMMENTS_DISABLED, ) try: if not check_internet(): log.error("internet check failed, do we have network?") ip = get_public_ip() log.info("My public IP address is: {}".format(ip)) except Exception as e: log.error("counld not check external ip") RATE_LIMIT = 0 NEED_TO_WAIT = 0 log.info("------------new bot run--------------") log.info("user is " + str(reddit.api.user.me(use_cache=True))) reddit_bot = [ reddit_bot_action("shadowcheck", reddit.shadow_check, PROBABILITIES["SHADOWCHECK"], 0), reddit_bot_action("karmacheck", set_user_karma, PROBABILITIES["KARMACHECK"], 0), reddit_bot_action("dbcheck", set_db_size, PROBABILITIES["DBCHECK"], 0),
def run(self): mtu = self._tun.mtu r = [self._tun, self._sock] w = [] x = [] send_info = '' recv_packet = '' send_packet = '' while True: r, w, x = select.select(r, w, x) if self._tun in r: print 'tun read triggered' send_packet = self._tun.read(mtu) print 'read' + str(send_packet) + 'from tunnel' if self._sock in r: recv_packet, addr = self._sock.recvfrom(65535) auth = utils.recv_auth(self._sock, addr, recv_packet) exists = utils.check_if_addr_exists(addr) if exists != None: # first get client address clientIP = IP(recv_packet) # authorization packet if auth == True: if clientIP: # get message queue and send one by one recv_packets = utils.get_messages_for_client( clientIP.src) if recv_packets != None and (addr[0] != SERVER_UDP_IP): for send_pkt in recv_packets: self._sock.sendto(send_pkt, addr) utils.clear_messages(addr) recv_packet = '' recv_packets = '' else: utils.receive_non_auth_message(recv_packet) if clientIP: print 'sender: ' + str( clientIP.src) + ' receiver: ' + str( clientIP.dst) # add to queue for client utils.message_for_client(clientIP.dst, recv_packet) recv_packets = utils.get_messages_for_client( clientIP.dst) print 'recv packets - ' + str(recv_packets) if recv_packets != None and str( clientIP.dst) != '10.10.0.1': for send_pkt in recv_packets: dest = utils.get_public_ip(clientIP.dst) self._sock.sendto(send_pkt, dest) utils.clear_messages(addr) if str(clientIP.dst) != '10.10.0.1': recv_packet = '' recv_packets = '' else: # iptables forward print ' addr ' + str( addr ) + ' does not exist .. iptables will forward the data:' + str( recv_packet) + 'if it could' raddr = addr[0] rport = addr[1] #aesobj = amitcrypto.AESCipher(key) #self._sock.sendto(aesobj.encrypt(data),(raddr,rport)) self._sock.sendto(recv_packet, (raddr, rport)) if self._tun in w: print 'no encryption yet, writing to tunnel' # Encryption ? self._tun.write(recv_packet) recv_packet = '' if self._sock in w: ip_pkt = IP(send_packet) send_addr = utils.get_public_ip(ip_pkt.dst) self._sock.sendto(send_packet, send_addr) send_packet = '' r = [] w = [] if recv_packet: print 'tun appended to w' w.append(self._tun) else: r.append(self._sock) if send_packet: w.append(self._sock) else: print 'appending self._tun to r' r.append(self._tun)
def bootstrap_server(server, admin_pass, key, cert, environment, name, salt_priv, salt_pub, puppetmaster): ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") if username != 'root': ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, 'root', ssh_kwargs, timeout=600) if IPV6: ssh_client.ssh('ping6 -c5 -Q 0x10 review.opencontrail.org ' '|| ping6 -c5 -Q 0x10 wiki.opencontrail.org') ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'install_puppet.sh'), 'install_puppet.sh') ssh_client.ssh('bash -x install_puppet.sh') certname = cert[:(0 - len('.pem'))] ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys") ssh_client.ssh("chown -R puppet:root /var/lib/puppet/ssl") ssh_client.ssh("chmod 0771 /var/lib/puppet/ssl") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/certs") ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys") if salt_pub and salt_priv: # Assuming salt-master is running on the puppetmaster shutil.copyfile(salt_pub, os.path.join(SALT_MASTER_PKI, 'minions', name)) ssh_client.ssh('mkdir -p {0}'.format(SALT_MINION_PKI)) ssh_client.scp(salt_pub, os.path.join(SALT_MINION_PKI, 'minion.pub')) ssh_client.scp(salt_priv, os.path.join(SALT_MINION_PKI, 'minion.pem')) for ssldir in ['/var/lib/puppet/ssl/certs/', '/var/lib/puppet/ssl/private_keys/', '/var/lib/puppet/ssl/public_keys/']: ssh_client.scp(os.path.join(ssldir, cert), os.path.join(ssldir, cert)) ssh_client.scp("/var/lib/puppet/ssl/crl.pem", "/var/lib/puppet/ssl/crl.pem") ssh_client.scp("/var/lib/puppet/ssl/certs/ca.pem", "/var/lib/puppet/ssl/certs/ca.pem") ssh_client.ssh("puppet agent " "--environment %s " "--server %s " "--no-daemonize --verbose --onetime --pluginsync true " "--certname %s" % (environment, puppetmaster, certname)) ssh_client.ssh("reboot")
IP = "10.0.1.10" if args.create_aux: # create public IP utils.create_public_ip(IP_NAME, RG_NAME) # Create network card with fixed private IP utils.create_nic_with_private_ip(NIC_NAME, RG_NAME, VNET_NAME, SUBNET_NAME, NSG_NAME, IP_NAME, INT_DNS_NAME, IP) # create VM VM_NAME = INT_DNS_NAME IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \ "/resourceGroups/" + RG_NAME + "/providers/Microsoft.Compute/images/" + UBUNTUGPU_IMAGE data_disks = "255 255 255 255" user_pass = utils.generate_pass() cloud_init_fn = cloud_init_fill_template( "configs/cloud_init_ubuntugpu_template.txt", user_pass) utils.create_vm(VM_NAME, RG_NAME, REGION, IMAGE_NAME, NIC_NAME, VM_SIZE, None, OS_DISK_NAME, user_pass, cloud_init_fn, data_disks) if RESIZE_OS_DISK: utils.deallocate_vm(VM_NAME, RG_NAME) utils.resize_managed_disk(RG_NAME, OS_DISK_NAME, OS_DISK_SIZE) utils.start_vm(VM_NAME, RG_NAME) print("ubuntugpu public IP: {}".format(utils.get_public_ip(IP_NAME, RG_NAME))) print("password:", user_pass)
def bootstrap_server(server, admin_pass, key, cert, environment, name, puppetmaster, volume): ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") if username != 'root': ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, 'root', ssh_kwargs, timeout=600) if IPV6: ssh_client.ssh('ping6 -c5 -Q 0x10 review.openstack.org ' '|| ping6 -c5 -Q 0x10 wiki.openstack.org') ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'make_swap.sh'), 'make_swap.sh') ssh_client.ssh('bash -x make_swap.sh') if volume: ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'mount_volume.sh'), 'mount_volume.sh') ssh_client.ssh('bash -x mount_volume.sh') ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'install_puppet.sh'), 'install_puppet.sh') ssh_client.ssh('bash -x install_puppet.sh') certname = cert[:(0 - len('.pem'))] ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys") ssh_client.ssh("chown -R puppet:root /var/lib/puppet/ssl") ssh_client.ssh("chown -R puppet:puppet /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0771 /var/lib/puppet/ssl") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/certs") ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys") for ssldir in [ '/var/lib/puppet/ssl/certs/', '/var/lib/puppet/ssl/private_keys/', '/var/lib/puppet/ssl/public_keys/' ]: ssh_client.scp(os.path.join(ssldir, cert), os.path.join(ssldir, cert)) ssh_client.scp("/var/lib/puppet/ssl/crl.pem", "/var/lib/puppet/ssl/crl.pem") ssh_client.scp("/var/lib/puppet/ssl/certs/ca.pem", "/var/lib/puppet/ssl/certs/ca.pem") ssh_client.ssh("puppet agent " "--environment %s " "--server %s " "--no-daemonize --verbose --onetime --pluginsync true " "--certname %s" % (environment, puppetmaster, certname)) ssh_client.ssh("reboot")
def bootstrap_server(server, admin_pass, key, cert, environment, name, salt_priv, salt_pub, puppetmaster): client = server.manager.api ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs["pkey"] = key else: ssh_kwargs["password"] = admin_pass for username in ["root", "ubuntu"]: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") if username != "root": ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, "root", ssh_kwargs, timeout=600) if IPV6: ssh_client.ssh("ping6 -c5 -Q 0x10 review.openstack.org " "|| ping6 -c5 -Q 0x10 wiki.openstack.org") ssh_client.scp(os.path.join(SCRIPT_DIR, "..", "install_puppet.sh"), "install_puppet.sh") ssh_client.ssh("bash -x install_puppet.sh") certname = cert[: 0 - len(".pem")] ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys") ssh_client.ssh("chown -R puppet:root /var/lib/puppet/ssl") ssh_client.ssh("chmod 0771 /var/lib/puppet/ssl") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/certs") ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys") if salt_pub and salt_priv: # Assuming salt-master is running on the puppetmaster shutil.copyfile(salt_pub, os.path.join(SALT_MASTER_PKI, "minions", name)) ssh_client.ssh("mkdir -p {0}".format(SALT_MINION_PKI)) ssh_client.scp(salt_pub, os.path.join(SALT_MINION_PKI, "minion.pub")) ssh_client.scp(salt_priv, os.path.join(SALT_MINION_PKI, "minion.pem")) for ssldir in [ "/var/lib/puppet/ssl/certs/", "/var/lib/puppet/ssl/private_keys/", "/var/lib/puppet/ssl/public_keys/", ]: ssh_client.scp(os.path.join(ssldir, cert), os.path.join(ssldir, cert)) ssh_client.scp("/var/lib/puppet/ssl/crl.pem", "/var/lib/puppet/ssl/crl.pem") ssh_client.scp("/var/lib/puppet/ssl/certs/ca.pem", "/var/lib/puppet/ssl/certs/ca.pem") ssh_client.ssh( "puppet agent " "--environment %s " "--server %s " "--no-daemonize --verbose --onetime --pluginsync true " "--certname %s" % (environment, puppetmaster, certname) ) ssh_client.ssh("reboot")
4. Start All in Ambari 5. Change SparkContext settings More workers: sc = get_spark_context(executorsPerNode=16, memoryPerExecutor=6144) More memory per worker: sc = get_spark_context(executorsPerNode=8, memoryPerExecutor=12288) Even more memory per worker (huge ALS workload maybe): sc = get_spark_context(executorsPerNode=4, memoryPerExecutor=24576) """ parser = argparse.ArgumentParser() parser.add_argument("--user", action="store", help="account name, for example student1", required=True) args = parser.parse_args() student_name = args.user rg_name = utils.get_student_resource_group(student_name) new_size = "Standard_DS14_v2_Promo" # Standard DS14 v2 Promo (16 cores, 112 GB memory) Parallel(n_jobs=3, backend="threading")( delayed(resize_VM)("cluster{0}".format(idx), rg_name, new_size) for idx in [1, 2, 3]) print("cluster1 public IP: {}".format( utils.get_public_ip("ip_cluster1", rg_name)))
if args.create_aux: # create public IP utils.create_public_ip(IP_NAME, rg_name) # Create network card with fixed private IP utils.create_nic_with_private_ip(NIC_NAME, rg_name, VNET_NAME, SUBNET_NAME, NSG_NAME, IP_NAME, INT_DNS_NAME, IP) # create VM VM_NAME = INT_DNS_NAME IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \ "/resourceGroups/admin_resources/providers/Microsoft.Compute/images/ubuntu_gpu_image1_" + region data_disks = "255 255 255 255" user_pass = utils.generate_pass() cloud_init_fn = cloud_init_fill_template( "configs/cloud_init_ubuntugpu_template.txt", user_pass) utils.create_vm(VM_NAME, rg_name, region, IMAGE_NAME, NIC_NAME, vm_size, None, OS_DISK_NAME, user_pass, cloud_init_fn, data_disks) if RESIZE_OS_DISK: utils.deallocate_vm(VM_NAME, rg_name) utils.resize_managed_disk(rg_name, OS_DISK_NAME, OS_DISK_SIZE) utils.start_vm(VM_NAME, rg_name) print("ubuntugpu public IP: {}".format( utils.get_public_ip("ip_ubuntugpu", rg_name))) print("password:", user_pass)
def bootstrap_server(server, admin_pass, key, cert, environment, name, puppetmaster, volume, floating_ip_pool): ip = utils.get_public_ip(server, floating_ip_pool=floating_ip_pool) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu', 'centos']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: break if not ssh_client: raise Exception("Unable to log in via SSH") # cloud-init puts the "please log in as user foo" message and # subsequent exit() in root's authorized_keys -- overwrite it with # a normal version to get root login working again. if username != 'root': ssh_client.ssh("sudo cp ~/.ssh/authorized_keys" " ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chmod 644 ~root/.ssh/authorized_keys") ssh_client.ssh("sudo chown root.root ~root/.ssh/authorized_keys") ssh_client = utils.ssh_connect(ip, 'root', ssh_kwargs, timeout=600) if IPV6: ssh_client.ssh('ping6 -c5 -Q 0x10 review.openstack.org ' '|| ping6 -c5 -Q 0x10 wiki.openstack.org') ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'make_swap.sh'), 'make_swap.sh') ssh_client.ssh('bash -x make_swap.sh') if volume: ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'mount_volume.sh'), 'mount_volume.sh') ssh_client.ssh('bash -x mount_volume.sh') ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'install_puppet.sh'), 'install_puppet.sh') ssh_client.ssh('bash -x install_puppet.sh') certname = cert[:(0 - len('.pem'))] ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys") ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys") ssh_client.ssh("chown -R puppet:root /var/lib/puppet/ssl") ssh_client.ssh("chown -R puppet:puppet /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0771 /var/lib/puppet/ssl") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/certs") ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys") ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys") for ssldir in ['/var/lib/puppet/ssl/certs/', '/var/lib/puppet/ssl/private_keys/', '/var/lib/puppet/ssl/public_keys/']: ssh_client.scp(os.path.join(ssldir, cert), os.path.join(ssldir, cert)) ssh_client.scp("/var/lib/puppet/ssl/crl.pem", "/var/lib/puppet/ssl/crl.pem") ssh_client.scp("/var/lib/puppet/ssl/certs/ca.pem", "/var/lib/puppet/ssl/certs/ca.pem") (rc, output) = ssh_client.ssh( "puppet agent " "--environment %s " "--server %s " "--detailed-exitcodes " "--no-daemonize --verbose --onetime --pluginsync true " "--certname %s" % (environment, puppetmaster, certname), error_ok=True) utils.interpret_puppet_exitcodes(rc, output) ssh_client.ssh("reboot")
import utils from utils import RG_NAME, CLUSTER_VM parser = argparse.ArgumentParser() parser.add_argument("--start", action="store_true", help="start cluster machines") parser.add_argument("--stop", action="store_true", help="stop cluster machines") parser.add_argument("--remove", action="store_true", help="remove cluster VMs and disks") parser.add_argument("--jobs", type=int, action="store", help="number of parallel jobs") args = parser.parse_args() assert args.start or args.stop or args.remove assert not (args.start and args.stop and args.remove) if args.start: action_func = utils.start_vm elif args.stop: action_func = utils.deallocate_vm elif args.remove: action_func = utils.remove_vm_and_disks if args.remove: # remove orphaned disks (to make sure) utils.remove_orphaned_disks(RG_NAME) Parallel(n_jobs=args.jobs or 3, backend="threading")( delayed(action_func)(CLUSTER_VM.format(idx), RG_NAME) for idx in [1, 2, 3] ) if args.start: print("cluster1 public IP: {}".format(utils.get_public_ip("ip_cluster1", RG_NAME)))