def vm_run(args): vm = Server(args.vm_ip, args.username, args.password) vm.verbose = args.verbose vm.disable_known_hosts = True if args.keyfile: vm.key_filenames.append(args.keyfile) vm.put(args.bash_script, 'vm_run.sh') logging.info("Running {bash_script} on remote system {ip}".format( bash_script=args.bash_script, ip=args.vm_ip)) vm.run('bash vm_run.sh')
def command(xenhost, xenpass, devstackpass, tempest_params, tempest_repo, tempest_branch, no_clone, devstack_ip, suite): if not devstack_ip: xen = Server(xenhost, 'root', xenpass) xen.disable_known_hosts = True while True: devstack_ip = get_devstack_ip(xen) if devstack_ip: break time.sleep(1) devstack = Server(devstack_ip, 'stack', devstackpass) devstack.disable_known_hosts = True do_clone = not no_clone if do_clone: devstack.run( "rm -rf /opt/stack/tempest") devstack.run( "cd /opt/stack && git clone %s" % tempest_repo) else: devstack.run( "cd /opt/stack/tempest && git pull") devstack.run( "cd /opt/stack/tempest && git checkout %s" % tempest_branch) devstack.run( "/opt/stack/devstack/tools/configure_tempest.sh") devstack.run( "sudo pip install -U nose || true") temp_ini_file = tempfile.NamedTemporaryFile(delete=False) temp_ini_file.close() tempest_conf = "/opt/stack/tempest/etc/tempest.conf" devstack.get(tempest_conf, temp_ini_file.name) edit_ini_file(temp_ini_file.name) devstack.put(temp_ini_file.name, tempest_conf) devstack.run( "rm -f " "/opt/stack/tempest/tempest/tests/compute/test_console_output.py") devstack.run( """cd /opt/stack/tempest && nosetests %s %s -v -e "test_change_server_password" """ % (suite, tempest_params)) disconnect_all()
def command(host, filename, user, password): server = Server(host, user, password) server.disable_known_hosts = True extra_config = sys.stdin.readlines() tmp = tempfile.NamedTemporaryFile(delete=False) tmp.file.close() try: server.get(filename, tmp.name) set_extra_config(tmp.name, extra_config) server.put(tmp.name, filename) finally: disconnect_all()
def _setup_ssh(host, user, password, pubkey): server = Server(host, user, password) server.disable_known_hosts = True logger.info("Clean out .ssh") server.run("rm -rf .ssh") server.run("mkdir .ssh") server.run("chmod 0755 .ssh") logger.info("Copy over public key") server.put(pubkey, ".ssh/authorized_keys") server.run("chmod 0600 .ssh/authorized_keys") logger.info("Generating new ssh key on host") server.run('ssh-keygen -t rsa -N "" -f .ssh/id_rsa') logger.info("Add generated key to known_hosts") server.run("cat .ssh/id_rsa.pub >> .ssh/authorized_keys") logger.info("Establishing a connection to cache host key") server.run('ssh -o "StrictHostKeyChecking no" localhost hostname')
def create_centos(options): template = 'CentOS 6 (64-bit)' xenhost = Server(options.xshost, options.xsuser, options.xspass) xenhost.disable_known_hosts = True template_uuid = lib.template_uuid(xenhost, template) vm = lib.clone_template(xenhost, template_uuid, options.vmname) if options.kickstart is None: virt_kickstart_path = os.path.join( os.path.dirname(boxes.__file__), "virt-kickstart") else: virt_kickstart_path = options.kickstart with open(virt_kickstart_path, 'rb') as virt_kickstart_file: virt_kickstart_contents = virt_kickstart_file.read() virt_kickstart_contents = virt_kickstart_contents.replace( '@install_repo@', options.install_repo).replace( '@rootpwd@', options.rootpwd) kickstart_fname = '{0}.kickstart'.format(vm) xenhost.put( StringIO.StringIO(virt_kickstart_contents), "/opt/xensource/www/{0}".format(kickstart_fname)) kickstart_url = "http://{0}/{1}".format(options.xshost, kickstart_fname) xenhost.run( 'xe vm-param-set uuid={0} is-a-template=false' .format(vm)) xenhost.run( 'xe vm-param-set uuid={0} name-description="{1}"' .format(vm, options.vmname)) xenhost.run( 'xe vm-memory-limits-set static-min={0}MiB static-max={0}MiB dynamic-min={0}MiB dynamic-max={0}MiB uuid={1}' .format(options.memsize, vm)) pool = xenhost.run( 'xe pool-list --minimal') sr = xenhost.run( 'xe pool-param-get uuid={0} param-name=default-SR' .format(pool)) vdi = xenhost.run( 'xe vdi-create name-label="boot-{vmname}" ' 'sr-uuid={sr} type=system virtual-size={hddsize}GiB' .format(sr=sr, hddsize=options.hddsize, vmname=options.vmname)) xenhost.run( 'xe vbd-create vm-uuid={0} vdi-uuid={1} device=0 bootable=true' .format(vm, vdi)) xenhost.run( 'xe vm-param-set uuid={0} other-config:install-repository={1}' .format(vm, options.install_repo)) xenhost.run( 'xe vm-param-set uuid={0} PV-args="ks={1} ksdevice=eth0"'.format( vm, kickstart_url) ) net = xenhost.run( 'xe network-list name-label="{0}" --minimal' .format(options.networklabel)) xenhost.run( 'xe vif-create network-uuid={0} vm-uuid={1} device=0' .format(net, vm)) xenhost.run( 'xe vm-start uuid={0}' .format(vm))
def command( user, xspass, host, suite, install_repo, preseed_file, vmname, hddsize, mac, fstype, usrpwd, packages, timezone, ntpserver, username, httpmirrorhost, httpmirrordirectory, memsize, bootoptions, httpmirrorproxy, networklabel, domain, ): template = "Ubuntu Lucid Lynx 10.04 (64-bit)" xenhost = Server(host, user, xspass) xenhost.disable_known_hosts = True template_uuid = lib.template_uuid(xenhost, template) vm = lib.clone_template(xenhost, template_uuid, vmname) xenhost.put(preseed_file, "/opt/xensource/www/{0}.preseed".format(vm)) preseed_url = "{0}/{1}.preseed".format(host, vm) xenhost.run("xe vm-param-set uuid={0} is-a-template=false".format(vm)) xenhost.run('xe vm-param-set uuid={0} name-description="{1}"'.format(vm, vmname)) xenhost.run( "xe vm-memory-limits-set static-min={0}MiB static-max={0}MiB dynamic-min={0}MiB dynamic-max={0}MiB uuid={1}".format( memsize, vm ) ) pool = xenhost.run("xe pool-list --minimal") sr = xenhost.run("xe pool-param-get uuid={0} param-name=default-SR".format(pool)) vdi = xenhost.run( 'xe vdi-create name-label="boot-{vmname}" ' "sr-uuid={sr} type=system virtual-size={hddsize}GiB".format(sr=sr, hddsize=hddsize, vmname=vmname) ) xenhost.run("xe vbd-create vm-uuid={0} vdi-uuid={1} device=0 bootable=true".format(vm, vdi)) xenhost.run("xe vm-param-set uuid={0} other-config:install-repository={1}".format(vm, install_repo)) if httpmirrorproxy: xenhost.run("xe vm-param-set uuid={0} other-config:install-proxy={1}".format(vm, httpmirrorproxy)) xenhost.run("xe vm-param-set uuid={0} other-config:debian-release={1}".format(vm, suite)) xenhost.run( textwrap.dedent( r""" xe vm-param-set uuid={0} PV-args="-- quiet console=hvc0 \ locale=en_GB \ keyboard-configuration/layoutcode=gb \ netcfg/choose_interface=eth0 \ netcfg/get_hostname={1} \ netcfg/get_domain={2} \ mirror/suite={4} \ mirror/udeb/suite={4} \ partman/default_filesystem={5} \ passwd/user-password={6} \ passwd/user-password-again={6} \ pkgsel/include={7} \ time/zone={8} \ clock-setup/ntp-server={9} \ passwd/username={10} \ mirror/http/hostname={11} \ mirror/http/directory={12} \ {13} \ auto url={3}" """.format( vm, vmname, domain, preseed_url, suite, fstype, usrpwd, packages, timezone, ntpserver, username, httpmirrorhost, httpmirrordirectory, bootoptions, ) ) ) net = xenhost.run('xe network-list name-label="{0}" --minimal'.format(networklabel)) additional_net_options = "mac={0}".format(mac) if mac else "" xenhost.run("xe vif-create network-uuid={0} vm-uuid={1} device=0 {2}".format(net, vm, additional_net_options)) xenhost.run("xe vm-start uuid={0}".format(vm))