本文整理汇总了Python中quantum.agent.linux.utils.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: ensure_vxlan
def ensure_vxlan(self, network_id, physical_interface, vlan_id):
"""Create a vxlan unless it already exists."""
interface = self.get_vxlan_device_name(network_id)
if not self.device_exists(interface):
LOG.debug(_("Creating vxlan interface %(interface)s for "
"VLAN %(vlan_id)s on interface "
"%(physical_interface)s"),
locals())
cmd = ['ip', 'link', 'add', interface, 'type', 'vxlan',
'id', vlan_id, 'dev', physical_interface,
'group', cfg.CONF.VXLAN.vxlan_group]
if cfg.CONF.VXLAN.vxlan_ttl is not None:
cmd.extend(['ttl', cfg.CONF.VXLAN.vxlan_ttl])
if cfg.CONF.VXLAN.vxlan_tos is not None:
cmd.extend(['tos', cfg.CONF.VXLAN.vxlan_tos])
if len(cfg.CONF.VXLAN.vxlan_port) == 2:
cmd.extend(['port', cfg.CONF.VXLAN.vxlan_port[0],
cfg.CONF.VXLAN.vxlan_port[1]])
else:
LOG.error(_("Wrong vxlan_port value: %s !"),
",".join(cfg.CONF.VXLAN.vxlan_port))
if len(cfg.CONF.VXLAN.vxlan_local_ip):
cmd.extend(['local', cfg.CONF.VXLAN.vxlan_local_ip])
if utils.execute(cmd, root_helper=self.root_helper):
return
if utils.execute(['ip', 'link', 'set',
interface, 'up'], root_helper=self.root_helper):
return
LOG.debug(_("Done creating vxlan interface %s"), interface)
return interface
开发者ID:tpaszkowski,项目名称:quantum,代码行数:30,代码来源:linuxbridge_quantum_agent.py
示例2: spawn_process
def spawn_process(self):
"""Spawns a Dnsmasq process for the network."""
env = {
self.QUANTUM_NETWORK_ID_KEY: self.network.id,
self.QUANTUM_RELAY_SOCKET_PATH_KEY:
self.conf.dhcp_lease_relay_socket
}
cmd = [
'dnsmasq',
'--no-hosts',
'--no-resolv',
'--strict-order',
'--bind-interfaces',
'--interface=%s' % self.interface_name,
'--except-interface=lo',
'--pid-file=%s' % self.get_conf_file_name(
'pid', ensure_conf_dir=True),
#TODO (mark): calculate value from cidr (defaults to 150)
#'--dhcp-lease-max=%s' % ?,
'--dhcp-hostsfile=%s' % self._output_hosts_file(),
'--dhcp-optsfile=%s' % self._output_opts_file(),
'--dhcp-script=%s' % self._lease_relay_script_path(),
'--leasefile-ro',
]
for i, subnet in enumerate(self.network.subnets):
# if a subnet is specified to have dhcp disabled
if not subnet.enable_dhcp:
continue
if subnet.ip_version == 4:
mode = 'static'
else:
# TODO (mark): how do we indicate other options
# ra-only, slaac, ra-nameservers, and ra-stateless.
mode = 'static'
if self.version >= self.MINIMUM_VERSION:
set_tag = 'set:'
else:
set_tag = ''
cmd.append('--dhcp-range=%s%s,%s,%s,%ss' %
(set_tag, self._TAG_PREFIX % i,
netaddr.IPNetwork(subnet.cidr).network,
mode,
self.conf.dhcp_lease_time))
cmd.append('--conf-file=%s' % self.conf.dnsmasq_config_file)
if self.conf.dnsmasq_dns_server:
cmd.append('--server=%s' % self.conf.dnsmasq_dns_server)
if self.conf.dhcp_domain:
cmd.append('--domain=%s' % self.conf.dhcp_domain)
if self.namespace:
ip_wrapper = ip_lib.IPWrapper(self.root_helper, self.namespace)
ip_wrapper.netns.execute(cmd, addl_env=env)
else:
# For normal sudo prepend the env vars before command
cmd = ['%s=%s' % pair for pair in env.items()] + cmd
utils.execute(cmd, self.root_helper)
开发者ID:wallnerryan,项目名称:quantum_migrate,代码行数:60,代码来源:dhcp.py
示例3: test_clear_db_attribute
def test_clear_db_attribute(self):
pname = "tap77"
utils.execute(["ovs-vsctl", self.TO, "clear", "Port",
pname, "tag"], root_helper=self.root_helper)
self.mox.ReplayAll()
self.br.clear_db_attribute("Port", pname, "tag")
self.mox.VerifyAll()
开发者ID:StackOps,项目名称:quantum,代码行数:7,代码来源:test_ovs_lib.py
示例4: add_tap_interface
def add_tap_interface(self, network_id, vlan_id, tap_device_name):
"""
If a VIF has been plugged into a network, this function will
add the corresponding tap device to the relevant bridge
"""
if not tap_device_name:
return False
if not self.device_exists(tap_device_name):
LOG.debug("Tap device: %s does not exist on this host, skipped" %
tap_device_name)
return False
current_bridge_name = self.get_bridge_for_tap_device(tap_device_name)
bridge_name = self.get_bridge_name(network_id)
if bridge_name == current_bridge_name:
return False
LOG.debug("Adding device %s to bridge %s" % (tap_device_name,
bridge_name))
if current_bridge_name:
if utils.execute(['brctl', 'delif', current_bridge_name,
tap_device_name], root_helper=self.root_helper):
return False
self.ensure_vlan_bridge(network_id, vlan_id)
if utils.execute(['brctl', 'addif', bridge_name, tap_device_name],
root_helper=self.root_helper):
return False
LOG.debug("Done adding device %s to bridge %s" % (tap_device_name,
bridge_name))
return True
开发者ID:LuizOz,项目名称:quantum,代码行数:31,代码来源:linuxbridge_quantum_agent.py
示例5: ensure_vlan
def ensure_vlan(self, vlan_id):
"""Create a vlan unless it already exists."""
interface = self.get_subinterface_name(vlan_id)
if not self.device_exists(interface):
LOG.debug(
"Creating subinterface %s for VLAN %s on interface %s" % (interface, vlan_id, self.physical_interface)
)
if utils.execute(
[
"ip",
"link",
"add",
"link",
self.physical_interface,
"name",
interface,
"type",
"vlan",
"id",
vlan_id,
],
root_helper=self.root_helper,
):
return
if utils.execute(["ip", "link", "set", interface, "up"], root_helper=self.root_helper):
return
LOG.debug("Done creating subinterface %s" % interface)
return interface
开发者ID:vbannai,项目名称:quantum,代码行数:28,代码来源:linuxbridge_quantum_agent.py
示例6: device_exists
def device_exists(self, device):
"""Check if ethernet device exists."""
try:
utils.execute(["ip", "link", "show", "dev", device], root_helper=self.root_helper)
except RuntimeError:
return False
return True
开发者ID:vbannai,项目名称:quantum,代码行数:7,代码来源:linuxbridge_quantum_agent.py
示例7: plug
def plug(self, network_id, port_id, device_name, mac_address):
"""Plug in the interface."""
bridge = self.conf.ovs_integration_bridge
self.check_bridge_exists(bridge)
if not ip_lib.device_exists(device_name,
self.conf.root_helper,
namespace=network_id):
utils.execute(['ovs-vsctl',
'--', '--may-exist', 'add-port', bridge,
device_name,
'--', 'set', 'Interface', device_name,
'type=internal',
'--', 'set', 'Interface', device_name,
'external-ids:iface-id=%s' % port_id,
'--', 'set', 'Interface', device_name,
'external-ids:iface-status=active',
'--', 'set', 'Interface', device_name,
'external-ids:attached-mac=%s' %
mac_address],
self.conf.root_helper)
ip = ip_lib.IPWrapper(self.conf.root_helper)
device = ip.device(device_name)
device.link.set_address(mac_address)
if self.conf.network_device_mtu:
device.link.set_mtu(self.conf.network_device_mtu)
namespace = ip.ensure_namespace(network_id)
namespace.add_device_to_namespace(device)
device.link.set_up()
else:
LOG.error(_('Device %s already exists') % device)
开发者ID:vbannai,项目名称:quantum,代码行数:35,代码来源:interface.py
示例8: external_gateway_added
def external_gateway_added(self, ri, ex_gw_port, internal_cidrs):
interface_name = self.get_external_device_name(ex_gw_port['id'])
ex_gw_ip = ex_gw_port['fixed_ips'][0]['ip_address']
if not ip_lib.device_exists(interface_name,
root_helper=self.root_helper,
namespace=ri.ns_name()):
self.driver.plug(ex_gw_port['network_id'],
ex_gw_port['id'], interface_name,
ex_gw_port['mac_address'],
bridge=self.conf.external_network_bridge,
namespace=ri.ns_name(),
prefix=EXTERNAL_DEV_PREFIX)
self.driver.init_l3(interface_name, [ex_gw_port['ip_cidr']],
namespace=ri.ns_name())
ip_address = ex_gw_port['ip_cidr'].split('/')[0]
self._send_gratuitous_arp_packet(ri, interface_name, ip_address)
gw_ip = ex_gw_port['subnet']['gateway_ip']
if ex_gw_port['subnet']['gateway_ip']:
cmd = ['route', 'add', 'default', 'gw', gw_ip]
if self.conf.use_namespaces:
ip_wrapper = ip_lib.IPWrapper(self.root_helper,
namespace=ri.ns_name())
ip_wrapper.netns.execute(cmd, check_exit_code=False)
else:
utils.execute(cmd, check_exit_code=False,
root_helper=self.root_helper)
for (c, r) in self.external_gateway_nat_rules(ex_gw_ip,
internal_cidrs,
interface_name):
ri.iptables_manager.ipv4['nat'].add_rule(c, r)
ri.iptables_manager.apply()
开发者ID:bbrahmbhatt,项目名称:quantum,代码行数:34,代码来源:l3_agent.py
示例9: _test_get_vif_port_set
def _test_get_vif_port_set(self, is_xen):
utils.execute(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME],
root_helper=self.root_helper).AndReturn('tap99\ntun22')
if is_xen:
id_key = 'xs-vif-uuid'
else:
id_key = 'iface-id'
headings = ['name', 'external_ids']
data = [
# A vif port on this bridge:
['tap99', {id_key: 'tap99id', 'attached-mac': 'tap99mac'}],
# A vif port on another bridge:
['tap88', {id_key: 'tap88id', 'attached-mac': 'tap88id'}],
# Non-vif port on this bridge:
['tun22', {}],
]
utils.execute(["ovs-vsctl", self.TO, "--format=json",
"--", "--columns=name,external_ids",
"list", "Interface"],
root_helper=self.root_helper).AndReturn(
self._encode_ovs_json(headings, data))
if is_xen:
self.mox.StubOutWithMock(self.br, 'get_xapi_iface_id')
self.br.get_xapi_iface_id('tap99id').AndReturn('tap99id')
self.mox.ReplayAll()
port_set = self.br.get_vif_port_set()
self.assertEqual(set(['tap99id']), port_set)
self.mox.VerifyAll()
开发者ID:DestinyOneSystems,项目名称:quantum,代码行数:34,代码来源:test_ovs_lib.py
示例10: delete_vlan
def delete_vlan(self, interface):
if self.device_exists(interface):
LOG.debug("Deleting subinterface %s for vlan" % interface)
if utils.execute(["ip", "link", "set", interface, "down"], root_helper=self.root_helper):
return
if utils.execute(["ip", "link", "delete", interface], root_helper=self.root_helper):
return
LOG.debug("Done deleting subinterface %s" % interface)
开发者ID:vbannai,项目名称:quantum,代码行数:8,代码来源:linuxbridge_quantum_agent.py
示例11: test_iface_to_br_handles_ovs_vsctl_exception
def test_iface_to_br_handles_ovs_vsctl_exception(self):
iface = 'tap0'
root_helper = 'sudo'
utils.execute(["ovs-vsctl", self.TO, "iface-to-br", iface],
root_helper=root_helper).AndRaise(Exception)
self.mox.ReplayAll()
self.assertIsNone(ovs_lib.get_bridge_for_iface(root_helper, iface))
self.mox.VerifyAll()
开发者ID:DestinyOneSystems,项目名称:quantum,代码行数:9,代码来源:test_ovs_lib.py
示例12: kill_pids_in_file
def kill_pids_in_file(root_helper, pid_path):
if os.path.exists(pid_path):
with open(pid_path, "r") as pids:
for pid in pids:
pid = pid.strip()
try:
utils.execute(["kill", "-9", pid], root_helper)
except RuntimeError:
LOG.exception(_("Unable to kill haproxy process: %s"), pid)
开发者ID:kaiweifan,项目名称:vse-lbaas-plugin-poc,代码行数:9,代码来源:namespace_driver.py
示例13: test_get_bridges
def test_get_bridges(self):
bridges = ['br-int', 'br-ex']
root_helper = 'sudo'
utils.execute(["ovs-vsctl", self.TO, "list-br"],
root_helper=root_helper).AndReturn('br-int\nbr-ex\n')
self.mox.ReplayAll()
self.assertEqual(ovs_lib.get_bridges(root_helper), bridges)
self.mox.VerifyAll()
开发者ID:StackOps,项目名称:quantum,代码行数:9,代码来源:test_ovs_lib.py
示例14: test_delete_port
def test_delete_port(self):
pname = "tap5"
utils.execute(["ovs-vsctl", self.TO, "--", "--if-exists",
"del-port", self.BR_NAME, pname],
root_helper=self.root_helper)
self.mox.ReplayAll()
self.br.delete_port(pname)
self.mox.VerifyAll()
开发者ID:StackOps,项目名称:quantum,代码行数:9,代码来源:test_ovs_lib.py
示例15: test_count_flows
def test_count_flows(self):
utils.execute(["ovs-ofctl", "dump-flows", self.BR_NAME],
root_helper=self.root_helper).AndReturn('ignore'
'\nflow-1\n')
self.mox.ReplayAll()
# counts the number of flows as total lines of output - 2
self.assertEqual(self.br.count_flows(), 1)
self.mox.VerifyAll()
开发者ID:StackOps,项目名称:quantum,代码行数:9,代码来源:test_ovs_lib.py
示例16: test_get_datapath_id
def test_get_datapath_id(self):
datapath_id = '"0000b67f4fbcc149"'
utils.execute(["ovs-vsctl", self.TO, "get",
"Bridge", self.BR_NAME, "datapath_id"],
root_helper=self.root_helper).AndReturn(datapath_id)
self.mox.ReplayAll()
self.assertEqual(self.br.get_datapath_id(), datapath_id.strip('"'))
self.mox.VerifyAll()
开发者ID:StackOps,项目名称:quantum,代码行数:9,代码来源:test_ovs_lib.py
示例17: test_iface_to_br
def test_iface_to_br(self):
iface = 'tap0'
br = 'br-int'
root_helper = 'sudo'
utils.execute(["ovs-vsctl", self.TO, "iface-to-br", iface],
root_helper=root_helper).AndReturn('br-int')
self.mox.ReplayAll()
self.assertEqual(ovs_lib.get_bridge_for_iface(root_helper, iface), br)
self.mox.VerifyAll()
开发者ID:StackOps,项目名称:quantum,代码行数:10,代码来源:test_ovs_lib.py
示例18: test_reset_bridge
def test_reset_bridge(self):
utils.execute(["ovs-vsctl", self.TO, "--",
"--if-exists", "del-br", self.BR_NAME],
root_helper=self.root_helper)
utils.execute(["ovs-vsctl", self.TO, "add-br", self.BR_NAME],
root_helper=self.root_helper)
self.mox.ReplayAll()
self.br.reset_bridge()
self.mox.VerifyAll()
开发者ID:StackOps,项目名称:quantum,代码行数:10,代码来源:test_ovs_lib.py
示例19: enable
def enable(self, cmd_callback):
if not self.active:
cmd = cmd_callback(self.get_pid_file_name(ensure_pids_dir=True))
if self.namespace:
ip_wrapper = ip_lib.IPWrapper(self.root_helper, self.namespace)
ip_wrapper.netns.execute(cmd)
else:
# For normal sudo prepend the env vars before command
utils.execute(cmd, self.root_helper)
开发者ID:DestinyOneSystems,项目名称:quantum,代码行数:10,代码来源:external_process.py
示例20: test_get_vif_port_set_list_interface_error
def test_get_vif_port_set_list_interface_error(self):
utils.execute(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME],
root_helper=self.root_helper).AndRaise('tap99\n')
utils.execute(["ovs-vsctl", self.TO, "--format=json",
"--", "--columns=name,external_ids",
"list", "Interface"],
root_helper=self.root_helper).AndRaise(RuntimeError())
self.mox.ReplayAll()
self.assertEqual(set(), self.br.get_vif_port_set())
self.mox.VerifyAll()
开发者ID:DestinyOneSystems,项目名称:quantum,代码行数:10,代码来源:test_ovs_lib.py
注:本文中的quantum.agent.linux.utils.execute函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论