def _ovs_del_port(args): bridge_name = pluginlib.exists(args, 'bridge_name') port_name = pluginlib.exists(args, 'port_name') cmd_args = [ 'ovs-vsctl', '--', '--if-exists', 'del-port', bridge_name, port_name ] return _run_command(cmd_args)
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)
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)
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)
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)
def _ovs_create_port(args): bridge = pluginlib.exists(args, 'bridge') port = pluginlib.exists(args, 'port') iface_id = pluginlib.exists(args, 'iface-id') mac = pluginlib.exists(args, 'mac') status = pluginlib.exists(args, 'status') cmd_args = ['ovs-vsctl', '--', '--if-exists', 'del-port', port, '--', 'add-port', bridge, port, '--', 'set', 'Interface', port, 'external_ids:iface-id=%s' % iface_id, 'external_ids:iface-status=%s' % status, 'external_ids:attached-mac=%s' % mac, 'external_ids:xs-vif-uuid=%s' % iface_id] return _run_command(cmd_args)
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")
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)
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)
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)
def _brctl_del_br(args): bridge_name = pluginlib.exists(args, 'bridge_name') cmd_args = ['brctl', 'delbr', bridge_name] return _run_command(cmd_args)
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)
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)