def configure_esxi_network(esxi_info):
    """Provision ESXi server"""
    user = esxi_info["username"]
    ip = esxi_info["ip"]
    password = esxi_info["password"]
    assert user and ip and password, "User, password and IP of the ESXi server must be specified"

    mode = get_mode(esxi_info["contrail_vm"]["host"])
    if mode == "openstack":
        vm_pg = esxi_info["vm_port_group"]
        vm_switch = esxi_info["vm_vswitch"]
        vm_switch_mtu = esxi_info["vm_vswitch_mtu"]
        data_pg = esxi_info.get("data_port_group", None)
        data_switch = esxi_info.get("data_vswitch", None)
        data_nic = esxi_info.get("data_nic", None)
    fabric_pg = esxi_info["fabric_port_group"]
    fab_switch = esxi_info["fabric_vswitch"]
    uplink_nic = esxi_info["uplink_nic"]
    datacenter_mtu = esxi_info.get("datacenter_mtu", None)

    host_string = "%s@%s" % (user, ip)
    with settings(host_string=host_string, password=password, warn_only=True, shell="/bin/sh -l -c"):
        run("esxcli network vswitch standard add --vswitch-name=%s" % (fab_switch))
        run(
            "esxcli network vswitch standard portgroup add --portgroup-name=%s --vswitch-name=%s"
            % (fabric_pg, fab_switch)
        )
        if uplink_nic:
            run(
                "esxcli network vswitch standard uplink add --uplink-name=%s --vswitch-name=%s"
                % (uplink_nic, fab_switch)
            )
        if datacenter_mtu:
            run("esxcli network vswitch standard set -v %s -m %s" % (fab_switch, datacenter_mtu))
        if mode == "openstack":
            run("esxcli network vswitch standard add --vswitch-name=%s" % (vm_switch))
            run(
                "esxcli network vswitch standard portgroup add --portgroup-name=%s --vswitch-name=%s"
                % (vm_pg, vm_switch)
            )
            run("esxcli network vswitch standard set -v %s -m %s" % (vm_switch, vm_switch_mtu))
            run(
                "esxcli network vswitch standard policy security set --vswitch-name=%s --allow-promiscuous=1"
                % (vm_switch)
            )
            run("esxcli network vswitch standard portgroup set --portgroup-name=%s --vlan-id=4095" % (vm_pg))
            if data_switch:
                run("esxcli network vswitch standard add --vswitch-name=%s" % (data_switch))
            if data_nic:
                assert data_switch, "Data vSwitch must be specified to add data nic"
                run(
                    "esxcli network vswitch standard uplink add --uplink-name=%s --vswitch-name=%s"
                    % (data_nic, data_switch)
                )
            if data_pg:
                assert data_switch, "Data vSwitch must be specified to create data port group"
                run(
                    "esxcli network vswitch standard portgroup add --portgroup-name=%s --vswitch-name=%s"
                    % (data_pg, data_switch)
                )
def create_vmx(esxi_host, vm_name):
    """Creates vmx file for contrail compute VM (non vcenter env)"""
    fab_pg = esxi_host["fabric_port_group"]
    vm_pg = esxi_host["vm_port_group"]
    data_pg = esxi_host.get("data_port_group", None)
    mode = get_mode(esxi_host["contrail_vm"]["host"])
    vm_name = vm_name
    vm_mac = esxi_host["contrail_vm"]["mac"]
    assert vm_mac, "MAC address for contrail-compute-vm must be specified"

    if mode is "vcenter":
        eth0_type = "vmxnet3"
        ext_params = compute_vmx_template.vcenter_ext_template
    else:
        eth0_type = "e1000"
        ext_params = compute_vmx_template.esxi_eth1_template.safe_substitute({"__vm_pg__": vm_pg})

    if data_pg:
        data_intf = compute_vmx_template.esxi_eth2_template.safe_substitute({"__data_pg__": data_pg})
        ext_params += data_intf

    template_vals = {
        "__vm_name__": vm_name,
        "__vm_mac__": vm_mac,
        "__fab_pg__": fab_pg,
        "__eth0_type__": eth0_type,
        "__extension_params__": ext_params,
    }
    _, vmx_file = tempfile.mkstemp(prefix=vm_name)
    _template_substitute_write(compute_vmx_template.template, template_vals, vmx_file)
    print "VMX File %s created for VM %s" % (vmx_file, vm_name)
    return vmx_file
def create_esxi_compute_vm(esxi_host, vcenter_info, power_on):
    """Spawns contrail vm on openstack managed esxi server (non vcenter env)"""
    mode = get_mode(esxi_host["contrail_vm"]["host"])
    datastore = esxi_host["datastore"]
    if "vmdk_download_path" in esxi_host["contrail_vm"].keys():
        vmdk_download_path = esxi_host["contrail_vm"]["vmdk_download_path"]
        run("wget -O /tmp/ContrailVM-disk1.vmdk %s" % vmdk_download_path)
        vmdk = "/tmp/ContrailVM-disk1.vmdk"
    else:
        vmdk = esxi_host["contrail_vm"]["vmdk"]
        if vmdk is None:
            assert vmdk, "Contrail VM vmdk image or download path should be specified in testbed file"
    if mode is "openstack":
        vm_name = esxi_host["contrail_vm"]["name"]
    if mode is "vcenter":
        name = "ContrailVM"
        vm_name = name + "-" + vcenter_info["datacenter"] + "-" + esxi_host["ip"]
    vm_store = datastore + "/" + vm_name + "/"

    vmx_file = create_vmx(esxi_host, vm_name)
    with settings(
        host_string=esxi_host["username"] + "@" + esxi_host["ip"],
        password=esxi_host["password"],
        warn_only=True,
        shell="/bin/sh -l -c",
    ):
        vmid = run("vim-cmd vmsvc/getallvms | grep %s | awk '{print $1}'" % vm_name)
        if vmid:
            run("vim-cmd vmsvc/power.off %s" % vmid)
            run("vim-cmd vmsvc/unregister %s" % vmid)

        run("rm -rf %s" % vm_store)
        out = run("mkdir -p %s" % vm_store)
        if out.failed:
            raise Exception("Unable create %s on esxi host %s:%s" % (vm_store, esxi_host["ip"], out))
        dst_vmx = vm_store + vm_name + ".vmx"
        out = put(vmx_file, dst_vmx)
        os.remove(vmx_file)
        if out.failed:
            raise Exception("Unable to copy %s to %s on %s:%s" % (vmx_file, vm_store, esxi_host["ip"], out))
        if mode == "openstack":
            src_vmdk = "/var/tmp/%s" % os.path.split(vmdk)[-1]
        if mode == "vcenter":
            src_vmdk = "/var/tmp/ContrailVM-disk1.vmdk"
        dst_vmdk = vm_store + vm_name + ".vmdk"
        put(vmdk, src_vmdk)
        out = run('vmkfstools -i "%s" -d zeroedthick "%s"' % (src_vmdk, dst_vmdk))
        if out.failed:
            raise Exception("Unable to create vmdk on %s:%s" % (esxi_host["ip"], out))
        run("rm " + src_vmdk)
        out = run("vim-cmd solo/registervm " + dst_vmx)
        if out.failed:
            raise Exception("Unable to register VM %s on %s:%s" % (vm_name, esxi_host["ip"], out))

        if power_on == False:
            return

        out = run("vim-cmd vmsvc/power.on %s" % out)
        if out.failed:
            raise Exception("Unable to power on %s on %s:%s" % (vm_name, esxi_host["ip"], out))
def detach_vrouter_node(*args):
    """Detaches one/more compute node from the existing cluster."""
    cfgm_host = get_control_host_string(env.roledefs['cfgm'][0])
    cfgm_host_password = get_env_passwords(env.roledefs['cfgm'][0])
    cfgm_ip = hstr_to_ip(cfgm_host)
    nova_compute = "openstack-nova-compute"

    for host_string in args:
        with settings(host_string=host_string, warn_only=True):
            sudo("service supervisor-vrouter stop")
            if detect_ostype() in ['ubuntu']:
                nova_compute = "nova-compute"
            mode = get_mode(host_string)
            if (mode == 'vcenter'):
                nova_compute = ""
            if (nova_compute != ""):
                sudo("service %s stop" % nova_compute)
            compute_hostname = sudo("hostname")
        with settings(host_string=env.roledefs['cfgm'][0],
                      pasword=cfgm_host_password):
            sudo(
                "python /opt/contrail/utils/provision_vrouter.py --host_name %s --host_ip %s --api_server_ip %s --oper del %s"
                % (compute_hostname, host_string.split('@')[1], cfgm_ip,
                   get_mt_opts()))
    execute("restart_control")
def create_vmx (esxi_host, vm_name):
    '''Creates vmx file for contrail compute VM (non vcenter env)'''
    fab_pg = esxi_host['fabric_port_group']
    vm_pg = esxi_host['vm_port_group']
    data_pg = esxi_host.get('data_port_group', None)
    mode = get_mode(esxi_host['contrail_vm']['host'])
    vm_name = vm_name
    vm_mac = esxi_host['contrail_vm']['mac']
    assert vm_mac, "MAC address for contrail-compute-vm must be specified"

    if mode is 'vcenter':
        eth0_type = "vmxnet3"
        ext_params = compute_vmx_template.vcenter_ext_template
    else:
        eth0_type = "e1000"
        ext_params = compute_vmx_template.esxi_eth1_template.safe_substitute({'__vm_pg__' : vm_pg})

    if data_pg:
        data_intf = compute_vmx_template.esxi_eth2_template.safe_substitute({'__data_pg__' : data_pg})
        ext_params += data_intf

    template_vals = { '__vm_name__' : vm_name,
                      '__vm_mac__' : vm_mac,
                      '__fab_pg__' : fab_pg,
                      '__eth0_type__' : eth0_type,
                      '__extension_params__' : ext_params,
                    }
    _, vmx_file = tempfile.mkstemp(prefix=vm_name)
    _template_substitute_write(compute_vmx_template.template,
                               template_vals, vmx_file)
    print "VMX File %s created for VM %s" %(vmx_file, vm_name)
    return vmx_file
def create_esxi_compute_vm (esxi_host, vcenter_info, power_on):
    '''Spawns contrail vm on openstack managed esxi server (non vcenter env)'''
    mode = get_mode(esxi_host['contrail_vm']['host'])
    datastore = esxi_host['datastore']
    with settings(host_string = esxi_host['username'] + '@' + esxi_host['ip'],
                  password = esxi_host['password'], warn_only = True,
                  shell = '/bin/sh -l -c'):
        src_vmdk = "/var/tmp/ContrailVM-disk1.vmdk"
        if 'vmdk_download_path' in esxi_host['contrail_vm'].keys():
            vmdk_download_path = esxi_host['contrail_vm']['vmdk_download_path']
            run("wget -O %s %s" % (src_vmdk, vmdk_download_path))
        else:
            vmdk = esxi_host['contrail_vm']['vmdk']
            if vmdk is None:
                assert vmdk, "Contrail VM vmdk image or download path should be specified in testbed file"
            put(vmdk, src_vmdk)

        if mode is 'openstack':
            vm_name = esxi_host['contrail_vm']['name']
        if mode is 'vcenter':
            name = "ContrailVM"
            vm_name = name+"-"+vcenter_info['datacenter']+"-"+esxi_host['ip']
        vm_store = datastore + '/' + vm_name + '/'

        vmx_file = create_vmx(esxi_host, vm_name)
        vmid = run("vim-cmd vmsvc/getallvms | grep %s | awk \'{print $1}\'" % vm_name)
        if vmid:
            run("vim-cmd vmsvc/power.off %s" % vmid)
            run("vim-cmd vmsvc/unregister %s" % vmid)

        run("rm -rf %s" % vm_store)
        out = run("mkdir -p %s" % vm_store)
        if out.failed:
            raise Exception("Unable create %s on esxi host %s:%s" % (vm_store,
                                     esxi_host['ip'], out))
        dst_vmx = vm_store + vm_name + '.vmx'
        out = put(vmx_file, dst_vmx)
        os.remove(vmx_file)
        if out.failed:
            raise Exception("Unable to copy %s to %s on %s:%s" % (vmx_file,
                                     vm_store, esxi_host['ip'], out))
        dst_vmdk = vm_store + vm_name + '.vmdk'
        out = run('vmkfstools -i "%s" -d zeroedthick "%s"' % (src_vmdk, dst_vmdk))
        if out.failed:
            raise Exception("Unable to create vmdk on %s:%s" %
                                      (esxi_host['ip'], out))
        run('rm ' + src_vmdk)
        out = run("vim-cmd solo/registervm " + dst_vmx)
        if out.failed:
            raise Exception("Unable to register VM %s on %s:%s" % (vm_name,
                                      esxi_host['ip'], out))

        if (power_on == False):
            return

        out = run("vim-cmd vmsvc/power.on %s" % out)
        if out.failed:
            raise Exception("Unable to power on %s on %s:%s" % (vm_name,
                                      esxi_host['ip'], out))
Exemple #7
0
def install_vrouter_node(*args):
    """Installs nova compute and vrouter pkgs in one or list of nodes. USAGE:fab install_vrouter_node:[email protected],[email protected]"""
    for host_string in args:
        with settings(host_string=host_string):
            if get_mode(host_string) is 'vcenter':
                execute('install_only_vrouter_node', 'no', host_string)
            else:
                execute('install_only_vrouter_node', 'yes', host_string)
def install_vrouter_node(*args):
    """Installs nova compute and vrouter pkgs in one or list of nodes. USAGE:fab install_vrouter_node:[email protected],[email protected]"""
    for host_string in args:
        with settings(host_string=host_string):
            if get_mode(host_string) is 'vcenter':
                execute('install_only_vrouter_node', 'no', host_string)
            else:
                execute('install_only_vrouter_node', 'yes', host_string)
def configure_esxi_network(esxi_info):
    '''Provision ESXi server'''
    user = esxi_info['username']
    ip = esxi_info['ip']
    password = esxi_info['password']
    assert (user and ip and password
            ), "User, password and IP of the ESXi server must be specified"

    mode = get_mode(esxi_info['contrail_vm']['host'])
    if mode == 'openstack':
        vm_pg = esxi_info['vm_port_group']
        vm_switch = esxi_info['vm_vswitch']
        vm_switch_mtu = esxi_info['vm_vswitch_mtu']
        data_pg = esxi_info.get('data_port_group', None)
        data_switch = esxi_info.get('data_vswitch', None)
        data_nic = esxi_info.get('data_nic', None)
    fabric_pg = esxi_info['fabric_port_group']
    fab_switch = esxi_info['fabric_vswitch']
    uplink_nic = esxi_info['uplink_nic']
    datacenter_mtu = esxi_info.get('datacenter_mtu', None)

    host_string = '%s@%s' % (user, ip)
    with settings(host_string=host_string,
                  password=password,
                  warn_only=True,
                  shell='/bin/sh -l -c'):
        run('esxcli network vswitch standard add --vswitch-name=%s' %
            (fab_switch))
        run('esxcli network vswitch standard portgroup add --portgroup-name=%s --vswitch-name=%s'
            % (fabric_pg, fab_switch))
        if uplink_nic:
            run('esxcli network vswitch standard uplink add --uplink-name=%s --vswitch-name=%s'
                % (uplink_nic, fab_switch))
        if datacenter_mtu:
            run('esxcli network vswitch standard set -v %s -m %s' %
                (fab_switch, datacenter_mtu))
        if mode == 'openstack':
            run('esxcli network vswitch standard add --vswitch-name=%s' %
                (vm_switch))
            run('esxcli network vswitch standard portgroup add --portgroup-name=%s --vswitch-name=%s'
                % (vm_pg, vm_switch))
            run('esxcli network vswitch standard set -v %s -m %s' %
                (vm_switch, vm_switch_mtu))
            run('esxcli network vswitch standard policy security set --vswitch-name=%s --allow-promiscuous=1'
                % (vm_switch))
            run('esxcli network vswitch standard portgroup set --portgroup-name=%s --vlan-id=4095'
                % (vm_pg))
            if data_switch:
                run('esxcli network vswitch standard add --vswitch-name=%s' %
                    (data_switch))
            if data_nic:
                assert data_switch, "Data vSwitch must be specified to add data nic"
                run('esxcli network vswitch standard uplink add --uplink-name=%s --vswitch-name=%s'
                    % (data_nic, data_switch))
            if data_pg:
                assert data_switch, "Data vSwitch must be specified to create data port group"
                run('esxcli network vswitch standard portgroup add --portgroup-name=%s --vswitch-name=%s'
                    % (data_pg, data_switch))
def install_vrouter(manage_nova_compute='yes'):
    """Installs vrouter pkgs in all nodes defined in vrouter role."""
    if env.roledefs['compute']:
        # Nova compute need not required for TSN node
        if 'tsn' in env.roledefs.keys():
            if  env.host_string in env.roledefs['tsn']: manage_nova_compute='no'
        if get_mode(env.host_string) is 'vcenter': 
            manage_nova_compute='no'
        execute("install_only_vrouter_node", manage_nova_compute, env.host_string)
Exemple #11
0
def install_vrouter(manage_nova_compute='yes'):
    """Installs vrouter pkgs in all nodes defined in vrouter role."""
    if env.roledefs['compute']:
        # Nova compute need not required for TSN node
        if 'tsn' in env.roledefs.keys():
            if  env.host_string in env.roledefs['tsn']: manage_nova_compute='no'
        if get_mode(env.host_string) is 'vcenter': 
            manage_nova_compute='no'
        execute("install_only_vrouter_node", manage_nova_compute, env.host_string)
def install_vrouter(manage_nova_compute="yes"):
    """Installs vrouter pkgs in all nodes defined in vrouter role."""
    if env.roledefs["compute"]:
        # Nova compute need not required for TSN node
        if "tsn" in env.roledefs.keys():
            if env.host_string in env.roledefs["tsn"]:
                manage_nova_compute = "no"
        if get_mode(env.host_string) is "vcenter":
            manage_nova_compute = "no"
        execute("install_only_vrouter_node", manage_nova_compute, env.host_string)
def create_vmx(esxi_host, vm_name):
    '''Creates vmx file for contrail compute VM (non vcenter env)'''
    fab_pg = esxi_host['fabric_port_group']
    vm_pg = esxi_host['vm_port_group']
    data_pg = esxi_host.get('data_port_group', None)
    mode = get_mode(esxi_host['contrail_vm']['host'])
    vm_name = vm_name
    vm_mac = esxi_host['contrail_vm']['mac']
    assert vm_mac, "MAC address for contrail-compute-vm must be specified"

    cmd = "vmware -v"
    out = run(cmd)
    if out.failed:
        raise Exception("Unable to get the vmware version")
    esxi_version_info = str(out)
    esxi_version = esxi_version_info.split()[2][:3]
    version = float(esxi_version)
    if (version == 5.5):
        hw_version = 10
    elif (version >= 6.0):
        hw_version = 11
    else:
        hw_version = 9

    if mode is 'vcenter':
        eth0_type = "vmxnet3"
        ext_params = compute_vmx_template.vcenter_ext_template
    else:
        eth0_type = "e1000"
        ext_params = compute_vmx_template.esxi_eth1_template.safe_substitute(
            {'__vm_pg__': vm_pg})

    if data_pg:
        data_intf = compute_vmx_template.esxi_eth2_template.safe_substitute(
            {'__data_pg__': data_pg})
        ext_params += data_intf

    template_vals = {
        '__vm_name__': vm_name,
        '__hw_version__': hw_version,
        '__vm_mac__': vm_mac,
        '__fab_pg__': fab_pg,
        '__eth0_type__': eth0_type,
        '__extension_params__': ext_params,
    }
    _, vmx_file = tempfile.mkstemp(prefix=vm_name)
    _template_substitute_write(compute_vmx_template.template, template_vals,
                               vmx_file)
    print "VMX File %s created for VM %s" % (vmx_file, vm_name)
    return vmx_file
def install_ceilometer_compute_node(*args):
    """Installs ceilometer compute pkgs in one or list of nodes. USAGE:fab install_ceilometer_compute_node:[email protected],[email protected]"""
    for host_string in args:
        with settings(host_string=host_string):
            if not is_ceilometer_compute_install_supported():
                continue
            #Ceilometer not needed on vcenter ContraiVM
            if get_mode(env.host_string) == 'vcenter':
                continue
            pkgs = get_compute_ceilometer_pkgs()
            if pkgs:
                pkg_install(pkgs)
            else:
                act_os_type = detect_ostype()
                raise RuntimeError('Unspported OS type (%s)' % (act_os_type))
Exemple #15
0
def install_ceilometer_compute_node(*args):
    """Installs ceilometer compute pkgs in one or list of nodes. USAGE:fab install_ceilometer_compute_node:[email protected],[email protected]"""
    for host_string in args:
        with settings(host_string=host_string):
            if not is_ceilometer_compute_install_supported():
                continue
            #Ceilometer not needed on vcenter ContraiVM
            if get_mode(env.host_string) == 'vcenter':
                continue
            pkgs = get_compute_ceilometer_pkgs()
            if pkgs:
                pkg_install(pkgs)
            else:
                act_os_type = detect_ostype()
                raise RuntimeError('Unspported OS type (%s)' % (act_os_type))
def create_vmx (esxi_host, vm_name):
    '''Creates vmx file for contrail compute VM (non vcenter env)'''
    fab_pg = esxi_host['fabric_port_group']
    vm_pg = esxi_host['vm_port_group']
    data_pg = esxi_host.get('data_port_group', None)
    mode = get_mode(esxi_host['contrail_vm']['host'])
    vm_name = vm_name
    vm_mac = esxi_host['contrail_vm']['mac']
    assert vm_mac, "MAC address for contrail-compute-vm must be specified"

    cmd = "vmware -v"
    out = run(cmd)
    if out.failed:
        raise Exception("Unable to get the vmware version")
    esxi_version_info = str(out)
    esxi_version = esxi_version_info.split()[2][:3]
    version = float(esxi_version)
    if (version == 5.5):
         hw_version = 10
    elif (version >= 6.0):
         hw_version = 11
    else:
        hw_version = 9

    if mode is 'vcenter':
        eth0_type = "vmxnet3"
        ext_params = compute_vmx_template.vcenter_ext_template
    else:
        eth0_type = "e1000"
        ext_params = compute_vmx_template.esxi_eth1_template.safe_substitute({'__vm_pg__' : vm_pg})

    if data_pg:
        data_intf = compute_vmx_template.esxi_eth2_template.safe_substitute({'__data_pg__' : data_pg})
        ext_params += data_intf

    template_vals = { '__vm_name__' : vm_name,
                      '__hw_version__' : hw_version,
                      '__vm_mac__' : vm_mac,
                      '__fab_pg__' : fab_pg,
                      '__eth0_type__' : eth0_type,
                      '__extension_params__' : ext_params,
                    }
    _, vmx_file = tempfile.mkstemp(prefix=vm_name)
    _template_substitute_write(compute_vmx_template.template,
                               template_vals, vmx_file)
    print "VMX File %s created for VM %s" %(vmx_file, vm_name)
    return vmx_file
def configure_esxi_network(esxi_info):
    '''Provision ESXi server'''
    user = esxi_info['username']
    ip = esxi_info['ip']
    password = esxi_info['password']
    assert (user and ip and password), "User, password and IP of the ESXi server must be specified"

    mode = get_mode(esxi_info['contrail_vm']['host'])
    if mode == 'openstack':
        vm_pg = esxi_info['vm_port_group']
        vm_switch = esxi_info['vm_vswitch']
        vm_switch_mtu = esxi_info['vm_vswitch_mtu']
        data_pg = esxi_info.get('data_port_group', None)
        data_switch = esxi_info.get('data_vswitch', None)
        data_nic = esxi_info.get('data_nic', None)
    fabric_pg = esxi_info['fabric_port_group']
    fab_switch = esxi_info['fabric_vswitch']
    uplink_nic = esxi_info['uplink_nic']
    datacenter_mtu = esxi_info.get('datacenter_mtu', None)

    host_string = '%s@%s' %(user, ip)
    with settings(host_string = host_string, password = password, 
                    warn_only = True, shell = '/bin/sh -l -c'):
        run('esxcli network vswitch standard add --vswitch-name=%s' %(fab_switch))
        run('esxcli network vswitch standard portgroup add --portgroup-name=%s --vswitch-name=%s' %(fabric_pg, fab_switch))
        if uplink_nic:
            run('esxcli network vswitch standard uplink add --uplink-name=%s --vswitch-name=%s' %(uplink_nic, fab_switch))
        if datacenter_mtu:
            run('esxcli network vswitch standard set -v %s -m %s' % (fab_switch, datacenter_mtu))
        if mode == 'openstack':
            run('esxcli network vswitch standard add --vswitch-name=%s' %(vm_switch))
            run('esxcli network vswitch standard portgroup add --portgroup-name=%s --vswitch-name=%s' %(vm_pg, vm_switch))
            run('esxcli network vswitch standard set -v %s -m %s' % (vm_switch, vm_switch_mtu))
            run('esxcli network vswitch standard policy security set --vswitch-name=%s --allow-promiscuous=1' % (vm_switch))
            run('esxcli network vswitch standard portgroup set --portgroup-name=%s --vlan-id=4095' %(vm_pg))
            if data_switch:
                run('esxcli network vswitch standard add --vswitch-name=%s' %(data_switch))
            if data_nic:
                assert data_switch, "Data vSwitch must be specified to add data nic"
                run('esxcli network vswitch standard uplink add --uplink-name=%s --vswitch-name=%s' %(data_nic, data_switch))
            if data_pg:
                assert data_switch, "Data vSwitch must be specified to create data port group"
                run('esxcli network vswitch standard portgroup add --portgroup-name=%s --vswitch-name=%s' %(data_pg, data_switch))
Exemple #18
0
def detach_vrouter_node(*args):
    """Detaches one/more compute node from the existing cluster."""
    cfgm_host = get_control_host_string(env.roledefs['cfgm'][0])
    cfgm_host_password = get_env_passwords(env.roledefs['cfgm'][0])
    cfgm_ip = hstr_to_ip(cfgm_host)
    nova_compute = "openstack-nova-compute"

    for host_string in args:
        with settings(host_string=host_string, warn_only=True):
            sudo("service supervisor-vrouter stop")
            if detect_ostype() in ['ubuntu']:
                nova_compute = "nova-compute"
            mode = get_mode(host_string)
            if (mode == 'vcenter'):
                nova_compute = ""
            if (nova_compute != ""):
                sudo("service %s stop" % nova_compute)
            compute_hostname = sudo("hostname")
        with settings(host_string=env.roledefs['cfgm'][0], pasword=cfgm_host_password):
            sudo("python /opt/contrail/utils/provision_vrouter.py --host_name %s --host_ip %s --api_server_ip %s --oper del %s" %
                (compute_hostname, host_string.split('@')[1], cfgm_ip, get_mt_opts()))
    execute("restart_control")
def create_esxi_compute_vm(esxi_host, vcenter_info, power_on):
    '''Spawns contrail vm on openstack managed esxi server (non vcenter env)'''
    mode = get_mode(esxi_host['contrail_vm']['host'])
    datastore = esxi_host['datastore']
    with settings(host_string=esxi_host['username'] + '@' + esxi_host['ip'],
                  password=esxi_host['password'],
                  warn_only=True,
                  shell='/bin/sh -l -c'):
        src_vmdk = "/var/tmp/ContrailVM-disk1.vmdk"
        if 'vmdk_download_path' in esxi_host['contrail_vm'].keys():
            vmdk_download_path = esxi_host['contrail_vm']['vmdk_download_path']
            run("wget -O %s %s" % (src_vmdk, vmdk_download_path))
        else:
            vmdk = esxi_host['contrail_vm']['vmdk']
            if vmdk is None:
                assert vmdk, "Contrail VM vmdk image or download path should be specified in testbed file"
            put(vmdk, src_vmdk)

        if mode is 'openstack':
            vm_name = esxi_host['contrail_vm']['name']
        if mode is 'vcenter':
            name = "ContrailVM"
            vm_name = name + "-" + vcenter_info[
                'datacenter'] + "-" + esxi_host['ip']
        vm_store = datastore + '/' + vm_name + '/'

        vmx_file = create_vmx(esxi_host, vm_name)
        vmid = run("vim-cmd vmsvc/getallvms | grep %s | awk \'{print $1}\'" %
                   vm_name)
        if vmid:
            run("vim-cmd vmsvc/power.off %s" % vmid)
            run("vim-cmd vmsvc/unregister %s" % vmid)

        run("rm -rf %s" % vm_store)
        out = run("mkdir -p %s" % vm_store)
        if out.failed:
            raise Exception("Unable create %s on esxi host %s:%s" %
                            (vm_store, esxi_host['ip'], out))
        dst_vmx = vm_store + vm_name + '.vmx'
        out = put(vmx_file, dst_vmx)
        os.remove(vmx_file)
        if out.failed:
            raise Exception("Unable to copy %s to %s on %s:%s" %
                            (vmx_file, vm_store, esxi_host['ip'], out))
        dst_vmdk = vm_store + vm_name + '.vmdk'
        out = run('vmkfstools -i "%s" -d zeroedthick "%s"' %
                  (src_vmdk, dst_vmdk))
        if out.failed:
            raise Exception("Unable to create vmdk on %s:%s" %
                            (esxi_host['ip'], out))
        run('rm ' + src_vmdk)
        out = run("vim-cmd solo/registervm " + dst_vmx)
        if out.failed:
            raise Exception("Unable to register VM %s on %s:%s" %
                            (vm_name, esxi_host['ip'], out))

        if (power_on == False):
            return

        out = run("vim-cmd vmsvc/power.on %s" % out)
        if out.failed:
            raise Exception("Unable to power on %s on %s:%s" %
                            (vm_name, esxi_host['ip'], out))