本文整理汇总了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
示例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)
示例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
示例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
示例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))
示例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)
示例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']
示例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)