• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyeapi.load_config函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: connect

    def connect(self):
        if self.config is not None:
            pyeapi.load_config(self.config)

        config = dict()

        if self.connection is not None:
            config = pyeapi.config_for(self.connection)
            if not config:
                msg = 'Connection name "{}" not found'.format(self.connection)

        for key in self.__attributes__:
            if getattr(self, key) is not None:
                config[key] = getattr(self, key)

        if 'transport' not in config:
            raise ValueError('Connection must define a transport')

        connection = pyeapi.client.make_connection(**config)
        node = pyeapi.client.Node(connection, **config)

        try:
            node.enable('show version')
        except (pyeapi.eapilib.ConnectionError, pyeapi.eapilib.CommandError):
            raise ValueError('unable to connect to {}'.format(node))
        return node
开发者ID:RichardBotham,项目名称:ansible-eos,代码行数:26,代码来源:eos_stp_interface.py


示例2: __init__

	def __init__(self, num=0):
		sw = ['core1', 'sw1', 'sw2', 'sw3', 'sw4', 'sw5', 'spine1', 'spine2']
		name = sw[num]
		# Config for switch access filepath
		conf = 'eapi.conf'
		self.sw = sw
		self.name = name
		self.conf = conf
		pyeapi.load_config(conf)
		try:
			node = pyeapi.connect_to(sw[num])
			node.enable('show hostname')
			node.conf('hostname %s' % sw[num])
			self.node = node
		except Exception:
			print ('* Failed to connect to switch! Check config at \'/%s\' *' % conf)
开发者ID:vlall,项目名称:pyrista,代码行数:16,代码来源:pyrista.py


示例3: connect

    def connect(self):
        if self.params["config"]:
            pyeapi.load_config(self.params["config"])

        config = dict()

        if self.params["connection"]:
            config = pyeapi.config_for(self.params["connection"])
            if not config:
                msg = 'Connection name "%s" not found' % self.params["connection"]
                self.fail(msg)

        if self.params["username"]:
            config["username"] = self.params["username"]

        if self.params["password"]:
            config["password"] = self.params["password"]

        if self.params["transport"]:
            config["transport"] = self.params["transport"]

        if self.params["port"]:
            config["port"] = self.params["port"]

        if self.params["host"]:
            config["host"] = self.params["host"]

        if "transport" not in config:
            self.fail("Connection must define a transport")

        connection = pyeapi.client.make_connection(**config)
        self.log("Creating connection with autorefresh=%s" % self._autorefresh)
        node = pyeapi.client.Node(connection, autorefresh=self._autorefresh, **config)

        try:
            resp = node.enable("show version")
            self.debug("eos_version", resp[0]["result"]["version"])
            self.debug("eos_model", resp[0]["result"]["modelName"])
        except (pyeapi.eapilib.ConnectionError, pyeapi.eapilib.CommandError):
            self.fail("unable to connect to %s" % node)
        else:
            self.log("Connected to node %s" % node)
            self.debug("node", str(node))

        return node
开发者ID:RichardBotham,项目名称:ansible-eos,代码行数:45,代码来源:eos_varp_interface.py


示例4: connect

    def connect(self):
        if self.params['config']:
            pyeapi.load_config(self.params['config'])

        config = dict()

        if self.params['connection']:
            config = pyeapi.config_for(self.params['connection'])
            if not config:
                msg = 'Connection name "%s" not found' % self.params['connection']
                self.fail(msg)

        if self.params['username']:
            config['username'] = self.params['username']

        if self.params['password']:
            config['password'] = self.params['password']

        if self.params['transport']:
            config['transport'] = self.params['transport']

        if self.params['port']:
            config['port'] = self.params['port']

        if self.params['host']:
            config['host'] = self.params['host']

        if 'transport' not in config:
            self.fail('Connection must define a transport')

        connection = pyeapi.client.make_connection(**config)
        node = pyeapi.client.Node(connection)

        try:
            node.enable('show version')
        except (pyeapi.eapilib.ConnectionError, pyeapi.eapilib.CommandError):
            self.fail('unable to connect to %s' % node)
        else:
            self.log('Connected to node %s' % node)
            self.debug('node', str(node))

        return node
开发者ID:rodecker,项目名称:ansible-eos,代码行数:42,代码来源:eos_ethernet.py


示例5: setup

def setup():
    pyeapi.load_config(os.path.join(here, 'fixtures/eapi.conf'))
    for name in pyeapi.client.config.connections:
        if name != 'localhost':
            nodes[name] = pyeapi.connect_to(name)

    assert len(nodes) > 0, 'no test nodes loaded, does eapi.conf exist?'

    modules = os.environ.get('ANSIBLE_TEST_CASES')

    testcases_home = os.path.join(here, 'testcases')
    filenames = os.listdir(testcases_home)

    for module in filter_modules(modules, filenames):
        path = os.path.join(testcases_home, module)
        definition = yaml.load(open(path))

        defaults = definition.get('defaults', {})
        for testcase in definition['testcases']:
            kwargs = defaults.copy()
            kwargs.update(testcase)
            testcases.append(TestCase(**kwargs))
开发者ID:RichardBotham,项目名称:ansible-eos,代码行数:22,代码来源:test_module.py


示例6:

 try:
     conn = pymongo.MongoClient('10.0.0.0', 27017)
 except pymongo.errors.ConnectionFailure, e:
     print "Could not connect to MongoDB: %s" % e
 # connecting to the database named neteng
 db = conn.neteng
 # load predefined listing of nodes and values of the format:
 # each device
 #[connection:$DEVICE_NAME]
 #host: $IP
 # once per file
 #[DEFAULT]
 #username: $USER
 #password: $PASS
 #transport: https
 pyeapi.load_config('~/.eapi.conf')
 #reset collection ileaf spine eleaf icore
 db.drop_collection('ileaf_ospf')
 db.drop_collection('spine_ospf')
 db.drop_collection('eleaf_ospf')
 db.drop_collection('icore_ospf')
 threads = []
 # loop through ileaf arista devices
 for il in ileaf:
     t = threading.Thread(target=ileaf_collect, args=(il,))
     threads.append(t)
     t.start()
 # loop through spine arista devices
 for sp in spine:
     t = threading.Thread(target=spine_collect, args=(sp,))
     threads.append(t)
开发者ID:shanecon,项目名称:arista,代码行数:31,代码来源:arista_ospf_extractor.py


示例7:

#!/usr/bin/env python

import pyeapi

pyeapi.load_config('nodes.conf')
node = pyeapi.connect_to('veos01')

output = node.enable('show version')

print 'My System MAC address is', output[0]['result']['systemMacAddress']
开发者ID:CullyB,项目名称:pyeapi,代码行数:10,代码来源:sysmac.py


示例8:

#!/usr/bin/env python

import pyeapi
from pprint import pprint

pyeapi.load_config("nodes.conf")
switch = pyeapi.connect_to('pynet-sw3')

data_returned = switch.enable('show interfaces')

interfaces = data_returned[0].get("result").get('interfaces')

for interface, data in interfaces.items():
    if not data.get('interfaceCounters'):
        del interfaces[interface]

print '{:<12} {:<9} {:<9}'.format('Interface','inOctets','outOctets')
for interface, data in interfaces.items():
    in_octets = data['interfaceCounters']['inOctets']
    out_octets = data['interfaceCounters']['outOctets']
    print '{:<12} {:<9} {:<9}'.format(interface, in_octets, out_octets)
开发者ID:brandune,项目名称:pynet_test,代码行数:21,代码来源:exercise31.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyearth.Earth类代码示例发布时间:2022-05-25
下一篇:
Python pyeapi.connect_to函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap