예제 #1
0
def _ovs_set_if_external_id(args):
    interface = pluginlib.exists(args, 'interface')
    extneral_id = pluginlib.exists(args, 'extneral_id')
    value = pluginlib.exists(args, 'value')
    cmd_args = ['ovs-vsctl', 'set', 'Interface', interface,
                'external-ids:%s=%s' % (extneral_id, value)]
    return _run_command(cmd_args)
예제 #2
0
def _ovs_add_patch_port(args):
    bridge_name = pluginlib.exists(args, 'bridge_name')
    port_name = pluginlib.exists(args, 'port_name')
    peer_port_name = pluginlib.exists(args, 'peer_port_name')
    cmd_args = ['ovs-vsctl', '--', '--if-exists', 'del-port',
                port_name, '--', 'add-port', bridge_name, port_name,
                '--', 'set', 'interface', port_name,
                'type=patch', 'options:peer=%s' % peer_port_name]
    return _run_command(cmd_args)
예제 #3
0
def network_config(session, args):
    """network config functions"""
    cmd = pluginlib.exists(args, 'cmd')
    if not isinstance(cmd, basestring):
        msg = _("invalid command '%s'") % str(cmd)
        raise pluginlib.PluginError(msg)
        return
    if cmd not in ALLOWED_NETWORK_CMDS:
        msg = _("Dom0 execution of '%s' is not permitted") % cmd
        raise pluginlib.PluginError(msg)
        return
    cmd_args = pluginlib.exists(args, 'args')
    return ALLOWED_NETWORK_CMDS[cmd](cmd_args)
예제 #4
0
def iptables_config(session, args):
    # command should be either save or restore
    logging.debug("iptables_config:enter")
    logging.debug("iptables_config: args=%s", args)
    cmd_args = pluginlib.exists(args, 'cmd_args')
    logging.debug("iptables_config: cmd_args=%s", cmd_args)
    process_input = pluginlib.optional(args, 'process_input')
    logging.debug("iptables_config: process_input=%s", process_input)
    cmd = json.loads(cmd_args)
    cmd = map(str, cmd)

    # either execute iptable-save or iptables-restore
    # command must be only one of these two
    # process_input must be used only with iptables-restore
    if len(cmd) > 0 and cmd[0] in ('iptables-save',
                                   'iptables-restore',
                                   'ip6tables-save',
                                   'ip6tables-restore'):
        result = _run_command(cmd, process_input)
        ret_str = json.dumps(dict(out=result, err=''))
        logging.debug("iptables_config:exit")
        return ret_str
    # else don't do anything and return an error
    else:
        raise pluginlib.PluginError(_("Invalid iptables command"))
예제 #5
0
def _brctl_del_if(args):
    bridge_name = pluginlib.exists(args, 'bridge_name')
    if_name = pluginlib.exists(args, 'interface_name')
    cmd_args = ['brctl', 'delif', bridge_name, if_name]
    return _run_command(cmd_args)
예제 #6
0
def _brctl_set_stp(args):
    bridge_name = pluginlib.exists(args, 'bridge_name')
    option = pluginlib.exists(args, 'option')
    cmd_args = ['brctl', 'stp', bridge_name, option]
    return _run_command(cmd_args)
예제 #7
0
def _brctl_set_fd(args):
    bridge_name = pluginlib.exists(args, 'bridge_name')
    fd = pluginlib.exists(args, 'fd')
    cmd_args = ['brctl', 'setfd', bridge_name, fd]
    return _run_command(cmd_args)
예제 #8
0
def _brctl_del_br(args):
    bridge_name = pluginlib.exists(args, 'bridge_name')
    cmd_args = ['brctl', 'delbr', bridge_name]
    return _run_command(cmd_args)
예제 #9
0
def _ip_link_set_promisc(args):
    device_name = pluginlib.exists(args, 'device_name')
    option = pluginlib.exists(args, 'option')
    cmd_args = ['ip', 'link', 'set', device_name, 'promisc', option]
    return _run_command(cmd_args)
예제 #10
0
def _ip_link_add_veth_pair(args):
    dev1_name = pluginlib.exists(args, 'dev1_name')
    dev2_name = pluginlib.exists(args, 'dev2_name')
    cmd_args = ['ip', 'link', 'add', dev1_name, 'type', 'veth', 'peer',
                'name', dev2_name]
    return _run_command(cmd_args)
예제 #11
0
def _ip_link_del_dev(args):
    device_name = pluginlib.exists(args, 'device_name')
    cmd_args = ['ip', 'link', 'delete', device_name]
    return _run_command(cmd_args)
예제 #12
0
def _ovs_add_port(args):
    bridge_name = pluginlib.exists(args, 'bridge_name')
    port_name = pluginlib.exists(args, 'port_name')
    cmd_args = ['ovs-vsctl', '--', '--if-exists', 'del-port', port_name,
                '--', 'add-port', bridge_name, port_name]
    return _run_command(cmd_args)
예제 #13
0
def _ovs_del_br(args):
    bridge_name = pluginlib.exists(args, 'bridge_name')
    cmd_args = ['ovs-vsctl', '--', '--if-exists',
                'del-br', bridge_name]
    return _run_command(cmd_args)