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


Python NetworkUtil.create_node_network方法代码示例

本文整理汇总了Python中ion.agents.platform.util.network_util.NetworkUtil.create_node_network方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkUtil.create_node_network方法的具体用法?Python NetworkUtil.create_node_network怎么用?Python NetworkUtil.create_node_network使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ion.agents.platform.util.network_util.NetworkUtil的用法示例。


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

示例1: test_create_node_network

# 需要导入模块: from ion.agents.platform.util.network_util import NetworkUtil [as 别名]
# 或者: from ion.agents.platform.util.network_util.NetworkUtil import create_node_network [as 别名]
    def test_create_node_network(self):

        # small valid map:
        plat_map = [('R', ''), ('a', 'R'), ]
        pnodes = NetworkUtil.create_node_network(plat_map)
        for p, q in plat_map: self.assertTrue(p in pnodes and q in pnodes)

        # duplicate 'a' but valid (same parent)
        plat_map = [('R', ''), ('a', 'R'), ('a', 'R')]
        NetworkUtil.create_node_network(plat_map)
        for p, q in plat_map: self.assertTrue(p in pnodes and q in pnodes)

        with self.assertRaises(PlatformDefinitionException):
            # invalid empty map
            plat_map = []
            NetworkUtil.create_node_network(plat_map)

        with self.assertRaises(PlatformDefinitionException):
            # no dummy root (id = '')
            plat_map = [('R', 'x')]
            NetworkUtil.create_node_network(plat_map)

        with self.assertRaises(PlatformDefinitionException):
            # multiple regular roots
            plat_map = [('R1', ''), ('R2', ''), ]
            NetworkUtil.create_node_network(plat_map)

        with self.assertRaises(PlatformDefinitionException):
            # duplicate 'a' but invalid (diff parents)
            plat_map = [('R', ''), ('a', 'R'), ('a', 'x')]
            NetworkUtil.create_node_network(plat_map)
开发者ID:blazetopher,项目名称:coi-services,代码行数:33,代码来源:test_network_util.py

示例2: build_network_definition

# 需要导入模块: from ion.agents.platform.util.network_util import NetworkUtil [as 别名]
# 或者: from ion.agents.platform.util.network_util.NetworkUtil import create_node_network [as 别名]
    def build_network_definition(rsn_oms):
        """
        Creates and returns a NetworkDefinition object reflecting the platform
        network definition reported by the RSN OMS Client object.
        The returned object will have as root the PlatformNode corresponding to the
        actual root of the whole newtork. You can use the `pnodes` property to
        access any node.

        @param rsn_oms RSN OMS Client object.
        @return NetworkDefinition object
        """
        if log.isEnabledFor(logging.DEBUG):
            log.debug("build_network_definition. rsn_oms class: %s",
                      rsn_oms.__class__.__name__)

        # platform types:
        platform_types = rsn_oms.config.get_platform_types()
        if log.isEnabledFor(logging.DEBUG):
            log.debug("got platform_types %s", str(platform_types))

        # platform map:
        map = rsn_oms.config.get_platform_map()
        if log.isEnabledFor(logging.DEBUG):
            log.debug("got platform map %s", str(map))

        # build topology:
        pnodes = NetworkUtil.create_node_network(map)
        dummy_root = pnodes['']
        root_pnode = pnodes[dummy_root.subplatforms.keys()[0]]
        if log.isEnabledFor(logging.DEBUG):
            log.debug("topology's root platform_id=%r", root_pnode.platform_id)

        # now, populate the attributes and ports for the platforms

        def build_attributes_and_ports(pnode):
            """
            Recursive routine to call set_attributes and set_ports on each pnode.
            """
            set_attributes(pnode)
            set_ports(pnode)

            for sub_platform_id, sub_pnode in pnode.subplatforms.iteritems():
                build_attributes_and_ports(sub_pnode)

        def set_attributes(pnode):
            platform_id = pnode.platform_id
            attr_infos = rsn_oms.attr.get_platform_attributes(platform_id)
            if not isinstance(attr_infos, dict):
                raise PlatformDriverException(
                    "%r: get_platform_attributes returned: %s" % (
                    platform_id, attr_infos))

            if log.isEnabledFor(logging.TRACE):
                log.trace("%r: attr_infos: %s", platform_id, attr_infos)

            if not platform_id in attr_infos:
                raise PlatformDriverException(
                    "%r: get_platform_attributes response does not "
                    "include entry for platform_id: %s" %(
                    platform_id, attr_infos))

            ret_infos = attr_infos[platform_id]
            for attrName, attr_defn in ret_infos.iteritems():
                attr = AttrNode(attrName, attr_defn)
                pnode.add_attribute(attr)

        def set_ports(pnode):
            platform_id = pnode.platform_id
            port_infos = rsn_oms.port.get_platform_ports(platform_id)
            if not isinstance(port_infos, dict):
                raise PlatformDriverException(
                    "%r: get_platform_ports response is not a dict: %s" % (
                    platform_id, port_infos))

            if log.isEnabledFor(logging.TRACE):
                log.trace("%r: port_infos: %s", platform_id, port_infos)

            if not platform_id in port_infos:
                raise PlatformDriverException(
                    "%r: get_platform_ports response does not include "
                    "platform_id: %s" % (platform_id, port_infos))

            ports = port_infos[platform_id]

            if not isinstance(ports, dict):
                raise PlatformDriverException(
                    "%r: get_platform_ports: entry for platform_id is "
                    "not a dict: %s" % (platform_id, ports))

            for port_id, dic in ports.iteritems():
                port = PortNode(port_id, dic['network'])
                port.set_state(dic['state'])
                pnode.add_port(port)

                # add connected instruments:
                instrs_res = rsn_oms.instr.get_connected_instruments(platform_id, port_id)
                if not isinstance(instrs_res, dict):
                    log.warn("%r: port_id=%r: get_connected_instruments "
                             "response is not a dict: %s" % (platform_id, port_id, instrs_res))
                    continue
#.........这里部分代码省略.........
开发者ID:MauriceManning,项目名称:coi-services,代码行数:103,代码来源:oms_util.py

示例3: str

# 需要导入模块: from ion.agents.platform.util.network_util import NetworkUtil [as 别名]
# 或者: from ion.agents.platform.util.network_util.NetworkUtil import create_node_network [as 别名]
            subprocess.call(dot_cmd.split())
            subprocess.call(open_cmd.split())
        except Exception, e:
            print "error generating diagrams: %s" % str(e)

    uri = os.getenv('OMS', "http://alice:[email protected]:9021/")

    #####
    import re
    if re.search('simulator', uri):
        from ion.agents.platform.rsn.oms_client_factory import CIOMSClientFactory
        oms = CIOMSClientFactory.create_instance(uri)
        print "ping() = %s"  % oms.ping()
        map = oms.get_platform_map()
        print "get_platform_map() = %s" % map
        pnodes = NetworkUtil.create_node_network(map)
        if not '' in pnodes:
            print "platform map does not include '' to indicate root platforms."
        else:
            dummy_root = pnodes['']
            gen_diagrams('sim_topology', dummy_root)
        sys.exit()
    #####


    proxy = xmlrpclib.ServerProxy(uri)

    retval = proxy.hello.ping()
    print "ping() = %s"  % retval

    retval = proxy.config.get_platform_map()
开发者ID:blazetopher,项目名称:coi-services,代码行数:33,代码来源:oms_simple.py


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