当前位置: 首页>>代码示例>>Python>>正文


Python utils.execute函数代码示例

本文整理汇总了Python中neutron.agent.linux.utils.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_or_update_class

    def add_or_update_class(self,nsname=None,devname=None,parent_classid=None,curent_classid=None,rate=None,ceil=None ):
        """
        add or update class  qos  bandwidth
        :param nsname:
        :param devname:
        :param parent_classid: "1:1"
        :param curent_classid: "1:10"
        :param rate: 10000Kbit
        :param ceil:10000Kbit
        :return:0 :class sfq not exist
        """

        LOG.debug(_('add_or_update_class in call,nsname %s,devname %s,curent_class %s,rate %s' %(nsname,devname,curent_classid,rate)))
        cmd=[]
        nscmd=[]
        if nsname is not None:
            nscmd=["ip","netns","exec",nsname]
            cmd.extend(nscmd)
        is_exist=self.check_class(nsname,devname,"class htb "+curent_classid)
        #print "add_class"
        #print is_exist
        if is_exist==-1 :#class not exist
           cmd.extend(["tc","class","add","dev",devname,"parent",parent_classid,"classid",curent_classid,"htb","rate",rate,"ceil",ceil])
           utils.execute(cmd,self.root_helper)
           return 0
        else:#class is exist ,update class rate
           cmd.extend(["tc","class","replace","dev",devname,"parent",parent_classid,"classid",curent_classid,"htb","rate",rate,"ceil",ceil])
           utils.execute(cmd,self.root_helper)
        return 1
开发者ID:xiongmeng1108,项目名称:openstack_gcloud,代码行数:29,代码来源:tc_lib_new.py

示例2: external_gateway_added

    def external_gateway_added(self, ri, ex_gw_port,
                               interface_name, internal_cidrs):

        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)
开发者ID:674009287,项目名称:neutron,代码行数:27,代码来源:l3_agent.py

示例3: vxlan_ucast_supported

    def vxlan_ucast_supported(self):
        if not cfg.CONF.VXLAN.l2_population:
            return False
        if not ip_lib.iproute_arg_supported(
                ['bridge', 'fdb'], 'append'):
            LOG.warning(_LW('Option "%(option)s" must be supported by command '
                            '"%(command)s" to enable %(mode)s mode'),
                        {'option': 'append',
                         'command': 'bridge fdb',
                         'mode': 'VXLAN UCAST'})
            return False

        test_iface = None
        for seg_id in moves.range(1, p_const.MAX_VXLAN_VNI + 1):
            if not ip_lib.device_exists(
                    self.get_vxlan_device_name(seg_id)):
                test_iface = self.ensure_vxlan(seg_id)
                break
        else:
            LOG.error(_LE('No valid Segmentation ID to perform UCAST test.'))
            return False

        try:
            utils.execute(
                cmd=['bridge', 'fdb', 'append', constants.FLOODING_ENTRY[0],
                     'dev', test_iface, 'dst', '1.1.1.1'],
                run_as_root=True, log_fail_as_error=False)
            return True
        except RuntimeError:
            return False
        finally:
            self.delete_vxlan(test_iface)
开发者ID:rajeshmohan,项目名称:neutron,代码行数:32,代码来源:linuxbridge_neutron_agent.py

示例4: delete_vlan_bridge

    def delete_vlan_bridge(self, bridge_name):
        if self.device_exists(bridge_name):
            interfaces_on_bridge = self.get_interfaces_on_bridge(bridge_name)
            for interface in interfaces_on_bridge:
                self.remove_interface(bridge_name, interface)

                if interface.startswith(VXLAN_INTERFACE_PREFIX):
                    self.delete_vxlan(interface)
                    continue

                for physical_interface in self.interface_mappings.itervalues():
                    if physical_interface == interface:
                        # This is a flat network => return IP's from bridge to
                        # interface
                        ips, gateway = self.get_interface_details(bridge_name)
                        self.update_interface_ip_details(interface,
                                                         bridge_name,
                                                         ips, gateway)
                    elif interface.startswith(physical_interface):
                        self.delete_vlan(interface)

            LOG.debug(_("Deleting bridge %s"), bridge_name)
            if utils.execute(['ip', 'link', 'set', bridge_name, 'down'],
                             root_helper=self.root_helper):
                return
            if utils.execute(['brctl', 'delbr', bridge_name],
                             root_helper=self.root_helper):
                return
            LOG.debug(_("Done deleting bridge %s"), bridge_name)

        else:
            LOG.error(_("Cannot delete bridge %s, does not exist"),
                      bridge_name)
开发者ID:noelbk,项目名称:neutron-juniper,代码行数:33,代码来源:linuxbridge_neutron_agent.py

示例5: plug

    def plug(self, network_id, port_id, device_name, mac_address,
             bridge=None, namespace=None, prefix=None):
        """This method is called by the Dhcp agent or by the L3 agent
        when a new network is created
        """
        if not ip_lib.device_exists(device_name,
                                    self.root_helper,
                                    namespace=namespace):
            ip = ip_lib.IPWrapper(self.root_helper)
            tap_name = device_name.replace(prefix or n_const.TAP_DEVICE_PREFIX,
                                           n_const.TAP_DEVICE_PREFIX)

            # Create ns_dev in a namespace if one is configured.
            root_dev, ns_dev = ip.add_veth(tap_name, device_name,
                                           namespace2=namespace)

            ns_dev.link.set_address(mac_address)

            # Add an interface created by ovs to the namespace.
            namespace_obj = ip.ensure_namespace(namespace)
            namespace_obj.add_device_to_namespace(ns_dev)

            ns_dev.link.set_up()
            root_dev.link.set_up()

            cmd = ['mm-ctl', '--bind-port', port_id, device_name]
            utils.execute(cmd, self.root_helper)

        else:
            LOG.info(_LI("Device %s already exists"), device_name)
开发者ID:noironetworks,项目名称:neutron2,代码行数:30,代码来源:interface.py

示例6: vxlan_ucast_supported

    def vxlan_ucast_supported(self):
        if not cfg.CONF.VXLAN.l2_population:
            return False
        if not ip_lib.iproute_arg_supported(["bridge", "fdb"], "append"):
            LOG.warning(
                _LW('Option "%(option)s" must be supported by command ' '"%(command)s" to enable %(mode)s mode'),
                {"option": "append", "command": "bridge fdb", "mode": "VXLAN UCAST"},
            )
            return False

        test_iface = None
        for seg_id in moves.range(1, p_const.MAX_VXLAN_VNI + 1):
            if ip_lib.device_exists(self.get_vxlan_device_name(seg_id)) or ip_lib.vxlan_in_use(seg_id):
                continue
            test_iface = self.ensure_vxlan(seg_id)
            break
        else:
            LOG.error(_LE("No valid Segmentation ID to perform UCAST test."))
            return False

        try:
            utils.execute(
                cmd=["bridge", "fdb", "append", constants.FLOODING_ENTRY[0], "dev", test_iface, "dst", "1.1.1.1"],
                run_as_root=True,
                log_fail_as_error=False,
            )
            return True
        except RuntimeError:
            return False
        finally:
            self.delete_interface(test_iface)
开发者ID:FedericoRessi,项目名称:neutron,代码行数:31,代码来源:linuxbridge_neutron_agent.py

示例7: spawn_process

    def spawn_process(self):
        """Spawns a Dnsmasq process for the network."""
        env = {self.NEUTRON_NETWORK_ID_KEY: self.network.id}

        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),
            "--dhcp-hostsfile=%s" % self._output_hosts_file(),
            "--dhcp-optsfile=%s" % self._output_opts_file(),
            "--leasefile-ro",
        ]

        possible_leases = 0
        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 = ""

            cidr = netaddr.IPNetwork(subnet.cidr)

            cmd.append(
                "--dhcp-range=%s%s,%s,%s,%ss"
                % (set_tag, self._TAG_PREFIX % i, cidr.network, mode, self.conf.dhcp_lease_duration)
            )
            possible_leases += cidr.size

        # Cap the limit because creating lots of subnets can inflate
        # this possible lease cap.
        cmd.append("--dhcp-lease-max=%d" % min(possible_leases, self.conf.dnsmasq_lease_max))

        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.network.namespace:
            ip_wrapper = ip_lib.IPWrapper(self.root_helper, self.network.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:home-dog,项目名称:neutron,代码行数:60,代码来源:dhcp.py

示例8: check_command

 def check_command(self, cmd, error_text, skip_msg, run_as_root=False):
     try:
         utils.execute(cmd, run_as_root=run_as_root)
     except RuntimeError as e:
         if error_text in str(e) and not self.fail_on_missing_deps:
             self.skipTest(skip_msg)
         raise
开发者ID:insequent,项目名称:neutron,代码行数:7,代码来源:base.py

示例9: setup_physical_bridges

    def setup_physical_bridges(self, bridge_mappings):
        """Setup the physical network bridges.

        Creates physical network bridges and links them to the
        integration bridge using veths.

        :param bridge_mappings: map physical network names to bridge names.
        """
        self.phys_brs = {}
        self.int_ofports = {}
        self.phys_ofports = {}
        ip_wrapper = ip_lib.IPWrapper(self.root_helper)
        for physical_network, bridge in bridge_mappings.iteritems():
            LOG.info(
                _("Mapping physical network %(physical_network)s to " "bridge %(bridge)s"),
                {"physical_network": physical_network, "bridge": bridge},
            )
            # setup physical bridge
            if not ip_lib.device_exists(bridge, self.root_helper):
                LOG.error(
                    _(
                        "Bridge %(bridge)s for physical network "
                        "%(physical_network)s does not exist. Agent "
                        "terminated!"
                    ),
                    {"physical_network": physical_network, "bridge": bridge},
                )
                sys.exit(1)
            br = ovs_lib.OVSBridge(bridge, self.root_helper)
            br.remove_all_flows()
            br.add_flow(priority=1, actions="normal")
            self.phys_brs[physical_network] = br

            # create veth to patch physical bridge with integration bridge
            int_veth_name = constants.VETH_INTEGRATION_PREFIX + bridge
            self.int_br.delete_port(int_veth_name)
            phys_veth_name = constants.VETH_PHYSICAL_PREFIX + bridge
            br.delete_port(phys_veth_name)
            if ip_lib.device_exists(int_veth_name, self.root_helper):
                ip_lib.IPDevice(int_veth_name, self.root_helper).link.delete()
                # Give udev a chance to process its rules here, to avoid
                # race conditions between commands launched by udev rules
                # and the subsequent call to ip_wrapper.add_veth
                utils.execute(["/sbin/udevadm", "settle", "--timeout=10"])
            int_veth, phys_veth = ip_wrapper.add_veth(int_veth_name, phys_veth_name)
            self.int_ofports[physical_network] = self.int_br.add_port(int_veth)
            self.phys_ofports[physical_network] = br.add_port(phys_veth)

            # block all untranslated traffic over veth between bridges
            self.int_br.add_flow(priority=2, in_port=self.int_ofports[physical_network], actions="drop")
            br.add_flow(priority=2, in_port=self.phys_ofports[physical_network], actions="drop")

            # enable veth to pass traffic
            int_veth.link.set_up()
            phys_veth.link.set_up()

            if self.veth_mtu:
                # set up mtu size for veth interfaces
                int_veth.link.set_mtu(self.veth_mtu)
                phys_veth.link.set_mtu(self.veth_mtu)
开发者ID:vnaum,项目名称:neutron,代码行数:60,代码来源:ovs_neutron_agent.py

示例10: add_root_qdisc

 def add_root_qdisc(device, namespace, root_helper=None):
     """Add the root htb qdisc for device."""
     cmd = ['tc', 'qdisc', 'add', 'dev', device, 'root', 'handle',
            '1:0', 'htb', 'default', 'fffe']
     if namespace:
         cmd = ['ip', 'netns', 'exec', namespace] + cmd
     linux_utils.execute(cmd, root_helper=root_helper)
开发者ID:eayunstack,项目名称:neutron-qos,代码行数:7,代码来源:tc_manager.py

示例11: destroy_root_qdisc

 def destroy_root_qdisc(device, namespace, root_helper=None):
     """Delete the root htb qdisc for device."""
     cmd = ['tc', 'qdisc', 'del', 'dev', device, 'root']
     if namespace:
         cmd = ['ip', 'netns', 'exec', namespace] + cmd
     linux_utils.execute(cmd, root_helper=root_helper,
                         check_exit_code=False)
开发者ID:eayunstack,项目名称:neutron-qos,代码行数:7,代码来源:tc_manager.py

示例12: _is_pingable

def _is_pingable(ip):
    """Checks whether an IP address is reachable by pinging.

    Use linux utils to execute the ping (ICMP ECHO) command.
    Sends 5 packets with an interval of 0.2 seconds and timeout of 1
    seconds. Runtime error implies unreachability else IP is pingable.
    :param ip: IP to check
    :return: bool - True or False depending on pingability.
    """
    if not ip:
       LOG.warning("inputing ip adress is None")
       return False

    #ip = '10.0.88.138'
    ping_cmd = ['ping',
                '-c', '5',
                '-W', '1',
                '-i', '0.2',
                ip]
    try:
        linux_utils.execute(ping_cmd, check_exit_code=True)
        return True
    except RuntimeError:
        LOG.warning("Cannot ping ip address: %s", ip)
        return False
开发者ID:CingHu,项目名称:neutron-ustack,代码行数:25,代码来源:device_status.py

示例13: del_flow

    def del_flow(self,nsname = None,devname=None, classid=None,src_ip=None):
        """

        :param nsname:
        :param devname:
        :param classid: "1:10"
        :param src_ip: "192.168.10.100"
        :return:
        """
        LOG.debug(_('del_flow classid %s,src_ip %s'%(classid,src_ip)))
        cmd=nscmd=[]
        if nsname is not None:
            nscmd=["ip","netns","exec",nsname]
            cmd.extend(nscmd)
        cmd.extend(["tc","filter","show","dev",devname])
        output=utils.execute(cmd,self.root_helper)
        res=self._re_match_src_ip_filter(output,class_id=classid,src_ip=src_ip)
        if res:
            filter_perf_info=res[:res.index(" fh")]
            rule_set=filter_perf_info.split(" ")
            del_cmd=nscmd
            del_cmd.extend(["tc","filter","del","dev",devname])
            del_cmd.extend(rule_set)
            #print rule_set
            output=utils.execute(del_cmd,self.root_helper)
开发者ID:xiongmeng1108,项目名称:openstack_gcloud,代码行数:25,代码来源:tc_lib_new.py

示例14: _enable_netfilter_for_bridges

    def _enable_netfilter_for_bridges(self):
        # we only need to set these values once, but it has to be when
        # we create a bridge; before that the bridge module might not
        # be loaded and the proc values aren't there.
        if self._enabled_netfilter_for_bridges:
            return
        else:
            self._enabled_netfilter_for_bridges = True

        # These proc values ensure that netfilter is enabled on
        # bridges; essential for enforcing security groups rules with
        # OVS Hybrid.  Distributions can differ on whether this is
        # enabled by default or not (Ubuntu - yes, Redhat - no, for
        # example).
        LOG.debug("Enabling netfilter for bridges")
        entries = utils.execute(['sysctl', '-N', 'net.bridge'],
                                run_as_root=True).splitlines()
        for proto in ('arp', 'ip', 'ip6'):
            knob = 'net.bridge.bridge-nf-call-%stables' % proto
            if 'net.bridge.bridge-nf-call-%stables' % proto not in entries:
                raise SystemExit(
                    _("sysctl value %s not present on this system.") % knob)
            enabled = utils.execute(['sysctl', '-b', knob])
            if enabled != '1':
                versionutils.report_deprecated_feature(
                    LOG,
                    _LW('Bridge firewalling is disabled; enabling to make '
                        'iptables firewall work. This may not work in future '
                        'releases.'))
                utils.execute(
                    ['sysctl', '-w', '%s=1' % knob], run_as_root=True)
开发者ID:sebrandon1,项目名称:neutron,代码行数:31,代码来源:iptables_firewall.py

示例15: copy_and_overwrite

 def copy_and_overwrite(self, from_path, to_path):
     # NOTE(toabctl): the agent may run as non-root user, so rm/copy as root
     if os.path.exists(to_path):
         utils.execute(
             cmd=["rm", "-rf", to_path], run_as_root=True)
     utils.execute(
         cmd=["cp", "-a", from_path, to_path], run_as_root=True)
开发者ID:openstack,项目名称:neutron-vpnaas,代码行数:7,代码来源:strongswan_ipsec.py


注:本文中的neutron.agent.linux.utils.execute函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。