Exemplo n.º 1
0
def command(host, user, password):
    server = Server(host, user, password)
    server.disable_known_hosts = True
    try:
        server.run("cd devstack && ./exercise.sh")
    finally:
        disconnect_all()
Exemplo n.º 2
0
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')
Exemplo n.º 3
0
def setup_license(host, user, password, pubkey, license_server):
    server = Server(host, user, password)
    server.disable_known_hosts = True

    logger.info("Setting licences")
    host_uuid = server.run("xe host-list --minimal")

    server.run(
        "xe host-apply-edition "
        'host-uuid=%s edition="platinum" '
        'license-server-address="%s" '
        'license-server-port="27000"' % (host_uuid, license_server)
    )
def command(host, service, user, password):
    server = Server(host, user, password)
    server.disable_known_hosts = True

    try:
        tempfile = server.run('tempfile')
        server.run('echo -ne "\\003\\x10\\015" > %s' % tempfile)
        server.run('screen -S stack -X bufferfile %s' % tempfile)
        server.run('screen -S stack -X readbuf')
        server.run('screen -S stack -p %s -X paste .' % service)
    finally:
        disconnect_all()
Exemplo n.º 5
0
def autostart_vm(args):
    xenhost = Server(args.host, args.xsuser, args.xspass)
    xenhost.disable_known_hosts = True

    vm_uuid = lib.vm_by_name(xenhost, args.vm_name)

    logger.info('Enabling auto_poweron on default pool')
    pool = xenhost.run('xe pool-list --minimal').strip()
    xenhost.run(
        'xe pool-param-set uuid={pool} other-config:auto_poweron=true'.format(
            pool=pool))

    logger.info('Enabling auto_poweron on guest')
    xenhost.run(
        'xe vm-param-set uuid={vm_uuid} other-config:auto_poweron=true'.format(
            vm_uuid=vm_uuid))
Exemplo n.º 6
0
class XenserverCore(object):
    def __init__(self, params):
        self.params = params
        self.server = Server(params.xenserver_core_host, 'root')
        self.server.disable_known_hosts = True

    @property
    def network_labels(self):
        return self.server.run('xe network-list params=name-label --minimal').split(',')

    @property
    def pif_devices(self):
        return self.server.run('xe pif-list params=device --minimal').split(',')

    def _get_network_uuid(self, network_name):
        network, = self.server.run(
            'xe network-list name-label={0} --minimal'.format(
                network_name)).split(',')

        return network

    def _get_pif_uuid(self, device):
        pif, = self.server.run(
            'xe pif-list device={0} --minimal'.format(
                device)).split(',')

        return pif

    def get_bridge_for_network(self, network_name):
        network = self._get_network_uuid(network_name)
        return self.server.run(
            'xe network-param-get param-name=bridge uuid={network}'.format(
                **locals()))

    def get_interfaces_of_bridge(self, bridge):
        brctl_out = self.server.run(
            'brctl show {0}'.format(bridge))
        lines = brctl_out.split('\n')[1:]
        return [line.split()[-1].strip() for line in lines]

    def add_interface_to_bridge(self, interface, bridge):
        self.server.run(
            'brctl addif {bridge} {interface}'.format(**locals()))

    def remove_interface_from_bridge(self, interface, bridge):
        self.server.run(
            'brctl delif {bridge} {interface}'.format(**locals()))
Exemplo n.º 7
0
def delete_vms(args):
    xenhost = Server(args.host, args.xsuser, args.xspass)
    xenhost.disable_known_hosts = True

    vm_uuids = xenhost.run("xe vm-list name-label={vm_name} --minimal".format(vm_name=args.vm_name))

    for vm_uuid in vm_uuids.split(","):
        delete_vm(xenhost, vm_uuid)
Exemplo n.º 8
0
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))
Exemplo n.º 9
0
def publish_tools(args):
    xenhost = Server(args.host, args.xsuser, args.xspass)
    xenhost.disable_known_hosts = True

    pbd_uuid = xenhost.run(
        'xe sr-list params=PBDs name-label="XenServer Tools" --minimal')

    device_config = xenhost.run(
        'xe pbd-param-get uuid={pbd_uuid} param-name=device-config'.format(
            pbd_uuid=pbd_uuid))

    location = None
    for config_item in device_config.split(';'):
        if 'location: ' in config_item:
            location = config_item.replace('location: ', '')
            break

    assert location

    filenames = xenhost.run('ls {location}'.format(location=location))

    tools_iso_basename = None
    for filename in filenames.split(' '):
        if 'tools' in filename:
            tools_iso_basename = filename
            break

    assert tools_iso_basename

    tools_iso_path = location + '/' + tools_iso_basename

    temp_dir = xenhost.run('mktemp -d')

    xenhost.run('mount -o loop {tools_iso_path} {temp_dir}'.format(
        tools_iso_path=tools_iso_path, temp_dir=temp_dir))

    xenhost.run('rm -rf /opt/xensource/www/tools')
    xenhost.run('mkdir /opt/xensource/www/tools')

    utilities = xenhost.run(
        'find {temp_dir} -name "xe-guest-utilities*"'.format(
            temp_dir=temp_dir)
    )

    guest_tool = None
    for utility_raw in utilities.split('\n'):
        utility = utility_raw.strip()
        if 'amd64' in utility and '.deb' in utility:
            guest_tool = utility

    assert guest_tool

    xenhost.run('cp {guest_tool} /opt/xensource/www/tools/amd64.deb'.format(
        guest_tool=guest_tool))

    xenhost.run('umount {temp_dir}'.format(temp_dir=temp_dir))
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
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')
Exemplo n.º 12
0
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))