def unplug_contrail_vif(port_id, dev_name=None, vnic_type=None, pci_dev=None,
                        vhostuser_socket=None, vhostuser_mode=None):
    """Call the vrouter port control script to unplug a vif

    :param port_id: VIF ID to unplug
    :param dev_name: Name of the TAP/device to unplug
    :param vnic_type: Selector for offload mode (e.g. direct)
    :param pci_dev: Virtual Function to assign for offloading
    :param vhostuser_socket: vhost-user socket path
    :param vhostuser_mode: vhost-user mode (client/server)
    """
    cmd = (
        'vrouter-port-control',
        '--oper=delete',
        '--uuid=%s' % port_id,
    )
    if dev_name:
        cmd += ('--tap_name=%s' % dev_name,)
    if vnic_type:
        cmd += ('--vnic_type=%s' % vnic_type,)
    if pci_dev:
        cmd += ('--pci_dev=%s' % pci_dev,)
    if vhostuser_socket:
        cmd += ('--vhostuser_socket=%s' % vhostuser_socket,)
    if vhostuser_mode is not None:
        cmd += ('--vhostuser_mode=%s' % vhostuser_mode,)
    try:
        env = dict(os.environ)
        env['PATH'] = env['PATH'] + ':/opt/plugin/bin'
        processutils.execute(*cmd, env_variables=env)
    except Exception as e:
        LOG.error(_LE("Unable to execute vrouter-port-control "
                      "%(args)s.  Exception: %(exception)s"),
                  {'args': cmd, 'exception': e})
        raise exception.VrouterPortControlError(args=cmd)
def plug_contrail_vif(vif_id, vm_id, net_id, project_id, ip_addr, ip6_addr,
                      vm_name, mac, dev_name, port_type, vif_type=None,
                      vnic_type=None, pci_dev=None, vhostuser_socket=None,
                      vhostuser_mode=None):
    """Call the vrouter port control script to plug a VIF

    :param vif_id: VIF ID to plug
    :param vm_id: Instance ID
    :param net_id: Network ID
    :param project_id: Project ID associated with the instance
    :param ip_addr: IPv4 address to assign to the interface
    :param ip6_addr: IPv6 address to assign to the interface
    :param vm_name: Display name of the instance
    :param mac: MAC address to assign to the interface
    :param dev_name: Name of the TAP/device to plug
    :param port_type: vrouter port type (e.g. NovaVMPort)
    :param vif_type: vrouter VIF type (e.g. VhostUser)
    :param vnic_type: Selector for offload mode (e.g. direct)
    :param pci_dev: Virtual Function to assign for offloading
    :param vhostuser_socket: vhost-user socket path
    :param vhostuser_mode: vhost-user mode (client/server)
    """
    cmd = (
        'vrouter-port-control',
        '--oper=add',
        '--uuid=%s' % vif_id,
        '--instance_uuid=%s' % vm_id,
        '--vn_uuid=%s' % net_id,
        '--vm_project_uuid=%s' % project_id,
        '--ip_address=%s' % ip_addr,
        '--ipv6_address=%s' % ip6_addr,
        '--vm_name=%s' % vm_name,
        '--mac=%s' % mac,
        '--tap_name=%s' % dev_name,
        '--port_type=%s' % port_type,
    )
    if vif_type:
        cmd += ('--vif_type=%s' % vif_type,)
    if vnic_type:
        cmd += ('--vnic_type=%s' % vnic_type,)
    if pci_dev:
        cmd += ('--pci_dev=%s' % pci_dev,)
    if vhostuser_socket:
        cmd += ('--vhostuser_socket=%s' % vhostuser_socket,)
    if vhostuser_mode is not None:
        cmd += ('--vhostuser_mode=%s' % vhostuser_mode,)
    cmd += (
        '--tx_vlan_id=%d' % -1,
        '--rx_vlan_id=%d' % -1,
    )
    try:
        env = dict(os.environ)
        env['PATH'] = env['PATH'] + ':/opt/plugin/bin'
        processutils.execute(*cmd, env_variables=env)
    except Exception as e:
        LOG.error(_LE("Unable to execute vrouter-port-control "
                      "%(args)s.  Exception: %(exception)s"),
                  {'args': cmd, 'exception': e})
        raise exception.VrouterPortControlError(args=cmd)
Example #3
0
def run_vrouter_port_control(args):
    try:
        processutils.execute("vrouter-port-control", args)
    except Exception as e:
        LOG.error(_LE("Unable to execute vrouter-port-control " +
                      "%(args)s.  Exception: %(exception)s"),
                  {'args': args, 'exception': e})
        raise exception.VrouterPortControlError(args=args)
Example #4
0
def run_vrouter_port_control(args):
    try:
        processutils.execute("vrouter-port-control", args)
    except Exception as e:
        LOG.error(
            _LE("Unable to execute vrouter-port-control " +
                "%(args)s.  Exception: %(exception)s"), {
                    'args': args,
                    'exception': e
                })
        raise exception.VrouterPortControlError(args=args)
Example #5
0
def delete_net_dev(dev):
    """Delete a network device only if it exists."""
    if device_exists(dev):
        try:
            processutils.execute('ip', 'link', 'delete', dev,
                                 check_exit_code=[0, 2, 254],
                                 run_as_root=True)
            LOG.debug("Net device removed: '%s'", dev)
        except processutils.ProcessExecutionError:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Failed removing net device: '%s'"), dev)
Example #6
0
def unplug_contrail_vif(port_id,
                        dev_name=None,
                        vnic_type=None,
                        pci_dev=None,
                        vhostuser_socket=None,
                        vhostuser_mode=None):
    """Call the vrouter port control script to unplug a vif

    :param port_id: VIF ID to unplug
    :param dev_name: Name of the TAP/device to unplug
    :param vnic_type: Selector for offload mode (e.g. direct)
    :param pci_dev: Virtual Function to assign for offloading
    :param vhostuser_socket: vhost-user socket path
    :param vhostuser_mode: vhost-user mode (client/server)
    """
    cmd = (
        'vrouter-port-control',
        '--oper=delete',
        '--uuid=%s' % port_id,
    )
    if dev_name:
        cmd += ('--tap_name=%s' % dev_name, )
    if vnic_type:
        cmd += ('--vnic_type=%s' % vnic_type, )
    if pci_dev:
        cmd += ('--pci_dev=%s' % pci_dev, )
    if vhostuser_socket:
        cmd += ('--vhostuser_socket=%s' % vhostuser_socket, )
    if vhostuser_mode is not None:
        cmd += ('--vhostuser_mode=%s' % vhostuser_mode, )
    try:
        env = dict(os.environ)
        env['PATH'] = env['PATH'] + ':/opt/plugin/bin'
        processutils.execute(*cmd, env_variables=env)
    except Exception as e:
        LOG.error(
            _LE("Unable to execute vrouter-port-control "
                "%(args)s.  Exception: %(exception)s"), {
                    'args': cmd,
                    'exception': e
                })
        raise exception.VrouterPortControlError(args=cmd)
Example #7
0
def plug_contrail_vif(vif_id,
                      vm_id,
                      net_id,
                      project_id,
                      ip_addr,
                      ip6_addr,
                      vm_name,
                      mac,
                      dev_name,
                      port_type,
                      vif_type=None,
                      vnic_type=None,
                      pci_dev=None,
                      vhostuser_socket=None,
                      vhostuser_mode=None):
    """Call the vrouter port control script to plug a VIF

    :param vif_id: VIF ID to plug
    :param vm_id: Instance ID
    :param net_id: Network ID
    :param project_id: Project ID associated with the instance
    :param ip_addr: IPv4 address to assign to the interface
    :param ip6_addr: IPv6 address to assign to the interface
    :param vm_name: Display name of the instance
    :param mac: MAC address to assign to the interface
    :param dev_name: Name of the TAP/device to plug
    :param port_type: vrouter port type (e.g. NovaVMPort)
    :param vif_type: vrouter VIF type (e.g. VhostUser)
    :param vnic_type: Selector for offload mode (e.g. direct)
    :param pci_dev: Virtual Function to assign for offloading
    :param vhostuser_socket: vhost-user socket path
    :param vhostuser_mode: vhost-user mode (client/server)
    """
    cmd = (
        'vrouter-port-control',
        '--oper=add',
        '--uuid=%s' % vif_id,
        '--instance_uuid=%s' % vm_id,
        '--vn_uuid=%s' % net_id,
        '--vm_project_uuid=%s' % project_id,
        '--ip_address=%s' % ip_addr,
        '--ipv6_address=%s' % ip6_addr,
        '--vm_name=%s' % vm_name,
        '--mac=%s' % mac,
        '--tap_name=%s' % dev_name,
        '--port_type=%s' % port_type,
    )
    if vif_type:
        cmd += ('--vif_type=%s' % vif_type, )
    if vnic_type:
        cmd += ('--vnic_type=%s' % vnic_type, )
    if pci_dev:
        cmd += ('--pci_dev=%s' % pci_dev, )
    if vhostuser_socket:
        cmd += ('--vhostuser_socket=%s' % vhostuser_socket, )
    if vhostuser_mode is not None:
        cmd += ('--vhostuser_mode=%s' % vhostuser_mode, )
    cmd += (
        '--tx_vlan_id=%d' % -1,
        '--rx_vlan_id=%d' % -1,
    )
    try:
        env = dict(os.environ)
        env['PATH'] = env['PATH'] + ':/opt/plugin/bin'
        processutils.execute(*cmd, env_variables=env)
    except Exception as e:
        LOG.error(
            _LE("Unable to execute vrouter-port-control "
                "%(args)s.  Exception: %(exception)s"), {
                    'args': cmd,
                    'exception': e
                })
        raise exception.VrouterPortControlError(args=cmd)