예제 #1
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)
예제 #2
0
def create_tap_dev(dev, mac_address=None):
    if not device_exists(dev):
        try:
            # First, try with 'ip'
            processutils.execute('ip', 'tuntap', 'add', dev, 'mode',
                                 'tap', check_exit_code=[0, 2, 254],
                                 run_as_root=True)
        except processutils.ProcessExecutionError:
            # Second option: tunctl
            processutils.execute('tunctl', '-b', '-t', dev,
                                 run_as_root=True)
        if mac_address:
            processutils.execute('ip', 'link', 'set', dev, 'address', mac_address,
                                 check_exit_code=[0, 2, 254],
                                 run_as_root=True)
        processutils.execute('ip', 'link', 'set', dev, 'up',
                             check_exit_code=[0, 2, 254],
                             run_as_root=True)