Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def wrapper(self, protocol):
api = pyeapi.connect(transport="http", host=protocol.host, port=protocol.conf["http"],
username=protocol.username, password=protocol.password, return_node=True)
test(self, protocol, api)
def test_unauthorized_user(self):
error_string = ('Unauthorized. Unable to authenticate user: Bad'
' username/password combination')
for dut in self.duts:
temp_node = pyeapi.connect(host=dut.settings['host'],
transport=dut.settings['transport'],
username='wrong', password='nope',
port=dut.settings['port'],
return_node=True)
try:
temp_node.run_commands('show version')
except pyeapi.eapilib.ConnectionError as err:
self.assertEqual(err.message, error_string)
def setUp(self):
conf = TEST_SWITCHES[self.switch_name]
self.node = pyeapi.connect(transport="http", host="127.0.0.1", port=conf["http"],
username="root", password="root", return_node=True)
self.connection = self.node.connection
def _connect(self):
self.node = pyeapi.connect(host=self.switch_descriptor.hostname,
username=self.switch_descriptor.username,
password=self.switch_descriptor.password,
port=self.switch_descriptor.port,
transport=self.transport,
return_node=True,
timeout=default_command_timeout)
'''
module = AnsibleModule(
argument_spec=dict(
host=dict(required=True),
port=dict(default=443, required=False),
username=dict(required=True),
password=dict(required=True),
transport=dict(default="https", required=False),
vlan_name=dict(required=True),
vlan_id=dict(required=True)
#vlan_state=dict(default='present',required=False),
),
supports_check_mode=True
)
connection=pyeapi.connect(host=module.params['host'],username=module.params['username'],password=module.params['password'], port=module.params['port'],transport=module.params['transport'])
switch=pyeapi.client.Node(connection)
network_admin = AristaNetworkAdmin(switch)
vlan=Vlan(module.params['vlan_id'],module.params['vlan_name'])
with open("/tmp/eapi.log","w+") as f:
if network_admin.vlan_exists(vlan):
f.write("Exists: " + str(network_admin.vlan_exists(vlan)) + "\n")
f.write("DEBUG: vlan %s with id %s exists \n" %(vlan.name,vlan.vlan_id))
module.exit_json(msg="vlan exists", changed=False)
else:
f.write("DEBUG: vlan %s with id %s does not exist or has a different name \n" %(vlan.name,vlan.vlan_id))
if module.check_mode:
if network_admin.vlan_exists(vlan):
f.write("Check Mode: Vlan already exists\n")
module.exit_json(msg="Vlan already exits",changed=False)
def __init__(self, host, username, password, transport="http", timeout=60, **kwargs):
super(EOSDevice, self).__init__(host, username, password, vendor="arista", device_type="arista_eos_eapi")
self.transport = transport
self.timeout = timeout
self.connection = eos_connect(transport, host=host, username=username, password=password, timeout=timeout)
self.native = EOSNative(self.connection)
#!/usr/bin/env python
import pyeapi
connection = pyeapi.connect(host='192.168.1.16')
output = connection.execute(['enable', 'show version'])
print 'My system MAC address is', output['result'][1]['systemMacAddress']