本文整理汇总了Python中jsonrpclib.Server.runCmds方法的典型用法代码示例。如果您正苦于以下问题:Python Server.runCmds方法的具体用法?Python Server.runCmds怎么用?Python Server.runCmds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonrpclib.Server
的用法示例。
在下文中一共展示了Server.runCmds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def main():
argument_spec = dict(
vlan_id=dict(required=True),
vlan_name=dict(),
host=dict(),
username=dict(required=True),
password=dict(required=True),
port=dict(required=False),
transport=dict(choices=['http', 'https'],required=False)
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
vlan_id = module.params['vlan_id']
vlan_name = module.params['vlan_name']
host = str(module.params['host'])
username = module.params['username']
password = module.params['password']
port = int(module.params['port'])
transport = module.params['transport']
conn = Server("https://%s:%[email protected]%s/command-api" %(username, password, host))
list_cmds = [ "enable", "configure" ]
list_cmds.append("vlan %s" %(vlan_id))
list_cmds.append("name %s" %(vlan_name))
conn.runCmds(1, list_cmds, "json")
module.exit_json(msg="Vlan created successfully")
示例2: remove_acl
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def remove_acl(ip_list):
adjacency_list = find_topology(ip_list)
for ip in adjacency_list.keys():
switch_cli = Server( "http://admin:[email protected]"+ip+"/command-api" )
configure_acl_response = switch_cli.runCmds( 1, ["enable","configure terminal","no ip access-list trace",])
for interface in adjacency_list[ip].values():
configure_acl_interface_response = switch_cli.runCmds( 1, ["enable","configure terminal",
"interface "+interface,
"no ip access-group trace in",
"end"])
示例3: main
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def main():
parser = argparse.ArgumentParser(description='Location,')
parser.add_argument('-location', choices=['dc1','dc2'],
help='Enter the colo location dc1|dc2')
parser.add_argument('-new_extension',
help='Enter name of extension to be added')
parser.add_argument('-old_extension',
help='Enter name of extension to be removed')
parser.add_argument('--scp', action='store_true',
help='SCP new extension to arista device. System exit once finished')
args = parser.parse_args()
if args.location == 'dc1':
hostlist = arista_devices_dc1()
elif args.location == 'dc2':
hostlist = arista_devices_dc2()
#----------------------------------------------------------------
# Configuration section
#----------------------------------------------------------------
EAPI_USERNAME = os.getenv("USER")
EAPI_PASSWORD = get_user_info()
EAPI_METHOD = 'https'
# Disable ssh HTTPS certificates checking by default
disable_https_cert()
if args.scp:
scp(hostlist,EAPI_USERNAME,EAPI_PASSWORD,args.new_extension)
# configuration loop
for host in hostlist:
switch = Server( '%s://%s:%[email protected]%s/command-api' %
( EAPI_METHOD, EAPI_USERNAME, EAPI_PASSWORD, host ) )
# uninstall extension
try:
rc = switch.runCmds( 1, [
'no extension %s' %args.old_extension ])
print( 'Host configured: %s extension removed' % ( host ) )
except:
print "Extension %s not installed on %s" %(args.old_extension, host)
# Pause 1 second between extension being uninstalled and removed
time.sleep(1)
# remove uninstalled extension from extension namespace
try:
rc = switch.runCmds( 1, [
'delete extension:%s' %args.old_extension ])
except:
print "Extension %s couldn't be deleted" %args.old_extension
# New extension logic
try:
rc = switch.runCmds( 1, [
'copy flash:%s extension:%s' %(args.new_extension,args.new_extension),
'extension %s' %args.new_extension ])
print( 'Host configured: %s extension added' % ( host ) )
except:
print "Extension %s already installed on %s" %(args.new_extension, host)
next
示例4: get_hostname
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def get_hostname(ip_list):
ip_to_hostname = {}
for ip in ip_list:
switch_cli = Server( "http://admin:[email protected]"+ip+"/command-api" )
response_hostname = switch_cli.runCmds( 1, ["show hostname"])
ip_to_hostname[ip] = response_hostname[0]["hostname"]
return ip_to_hostname
示例5: configure_acl
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def configure_acl(ip_list,vtep_list,udp_source_port):
adjacency_list = find_topology(ip_list)
for ip in adjacency_list.keys():
switch_cli = Server( "http://admin:[email protected]"+ip+"/command-api" )
configure_acl_response = switch_cli.runCmds( 1, ["enable","configure terminal","ip access-list trace",
"statistics per-entry",
"10 permit udp host "+vtep_list[0]+" eq "+udp_source_port+" host "+vtep_list[1],
"20 permit udp host "+vtep_list[1]+" eq "+udp_source_port+" host "+vtep_list[0],
"30 permit ip any any"])
for interface in adjacency_list[ip].values():
configure_acl_interface_response = switch_cli.runCmds( 1, ["enable","configure terminal",
"interface "+interface,
"ip access-group trace in",
"end"])
switch_acl_counters_old = get_statistics(ip_list)
return switch_acl_counters_old
示例6: main
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def main(args):
''' main '''
parser = OptionParser()
parser.add_option('-u', '--username', default='eapi', help='username')
parser.add_option('-p', '--password', default='', help='password')
parser.add_option('-P', '--port', default='8543', help='port')
parser.add_option('-D', '--debug', action='store_true', help='debug')
options, args = parser.parse_args()
for switch in args:
url = "https://{0}:{1}@{2}:{3}/command-api".format(
options.username, options.password, switch, options.port
)
request = Server(url)
response = request.runCmds(1, ["show interfaces"] )
if options.debug:
print json.dumps(response, indent=4, sort_keys=True)
interfaces = sorted(response[0]['interfaces'].keys())
print "Switch {0} interfaces:".format(switch)
print "{:20} {:<20} {:<20}".format("Interface", "inOctets", "outOctets")
for inf in interfaces:
data = response[0]['interfaces'][inf]
if 'interfaceCounters' in data:
print "{:20} {:<20} {:<20}".format(
inf, data['interfaceCounters']['inOctets'], data['interfaceCounters']['outOctets']
)
print
示例7: test_get_device_status_good
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def test_get_device_status_good(self):
""" Test get_device_status happy path
"""
from mock import MagicMock
from jsonrpclib import Server
device = dict(self.device)
sh_ver = dict(self.sh_ver)
# Arbitrary test valuse
model = "Monkey-bot"
timestamp = 1408034881.09
sh_ver['modelName'] = model
sh_ver['bootupTimestamp'] = timestamp
response = []
response.append(sh_ver)
device['eapi_obj'] = Server('https://arista:[email protected]:443/command-api')
device['eapi_obj'].runCmds = MagicMock(return_value=response)
#response = []
#response.append({})
#response[0][u'interfaceStatuses'] = self.int_status
app.get_device_status(device)
self.assertEqual(device['modelName'], model)
self.assertEqual(device['bootupTimestamp'], timestamp)
示例8: main
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def main():
parser = argparse.ArgumentParser(description='Location,Ipaddress')
parser.add_argument('-location', choices=['dc1','dc2'],
help='Enter the colo location dc1|dc2')
parser.add_argument('-ip', help='Enter switch ip address')
args = parser.parse_args()
if args.location == 'dc1':
hostlist = arista_devices_dc1()
elif args.location == 'dc2':
hostlist = arista_devices_dc2()
disable_https_cert()
#----------------------------------------------------------------
# Configuration section
#----------------------------------------------------------------
#-------------------Configuration - MUST Set ------------------------
EAPI_USERNAME = os.getenv("USER")
EAPI_PASSWORD = get_user_info()
# http or https method
EAPI_METHOD = 'https'
for host in hostlist:
switch = Server( '%s://%s:%[email protected]%s/command-api' %
( EAPI_METHOD, EAPI_USERNAME, EAPI_PASSWORD, host ) )
rc = switch.runCmds( 1, [ 'enable',
'configure',
'interface Vxlan1',
'vxlan flood vtep add %s' % args.ip ] )
print( 'Host configured: %s' % ( host ) )
示例9: add_vlans
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def add_vlans():
for switch in switches:
for vlanlist in vlans:
urlString = "http://{}:{}@{}/command-api".format(switchusername, switchpassword, switch)
switchReq = Server( urlString )
response = switchReq.runCmds( 1, ["enable", "configure", "vlan" +" "+ str(vlanlist)] )
print "adding vlans %s" % (vlanlist)
示例10: show_vlans
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def show_vlans():
for switch in switches:
urlString = "http://{}:{}@{}/command-api".format(switchusername, switchpassword, switch)
switchReq = Server( urlString )
response = switchReq.runCmds( 1, ["show vlan"] )
print "Showing the vlans on %s" % (switch)
print json.dumps(response, indent=4)
示例11: eApiShowInterfaces
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def eApiShowInterfaces():
switch = Server(commandApiUrl)
response = switch.runCmds( 1, ["show interfaces"])
if (request.query.callback):
return directFlowJsonp(request)
else:
return json.dumps(eApiDirectFlow(), indent=4, sort_keys=True)
示例12: get_ports
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def get_ports(ip_to_hostname):
ip_port_dict = {}
all_ports = []
for ip in ip_to_hostname.keys():
switch_cli = Server( "http://admin:[email protected]"+ip+"/command-api" )
response_lldp = switch_cli.runCmds( 1, ["enable","show lldp neighbors"])
port_list = []
for i in response_lldp[1]["lldpNeighbors"]:
if i["neighborDevice"] in ip_to_hostname.values():
port_list.append(i["port"])
if len(port_list) > 1:
portchannel_interface = switch_cli.runCmds( 1, ["show interfaces "+port_list[0]+" status"])
po_n = portchannel_interface[0]["interfaceStatuses"][port_list[0]]["vlanInformation"]["vlanExplanation"][3:]
port_list.append(po_n)
ip_port_dict[ip] = port_list
ip_port_dict["10.114.211.7"].append("Ethernet10")
ip_port_dict["10.114.211.5"].append("Ethernet9")
return ip_port_dict
示例13: find_neighbors
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def find_neighbors(): #Function makes sure that each and every API is actually running on each switches and can pull with the current password.
for switch in switches:
urlString = "http://%s:%[email protected]%s/command-api" % (switchusername, switchpassword, switch)
switchReq = Server( urlString )
response = switchReq.runCmds( 1, ["show lldp neighbors"] )
neighborresponse = response[0]["lldpNeighbors"]
nodes = neighborresponse
neighborlist = []
for neighbors in nodes:
iterateneighbors = neighbors['neighborDevice']
neighborlist.append(iterateneighbors)
print neighborlist
示例14: find_topology
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def find_topology(ip_list):
ip_to_hostname = get_hostname(ip_list)
adjacency_list = {}
for ip in ip_to_hostname.keys():
switch_cli = Server("http://admin:[email protected]"+ip+"/command-api")
response_lldp = switch_cli.runCmds(1,["enable","show lldp neighbors"])
adjacency_list[ip] = {}
#print ip
for index in range(len(response_lldp[1]["lldpNeighbors"])):
if (response_lldp[1]["lldpNeighbors"][index]['neighborDevice'] in ip_to_hostname.values()):
if (response_lldp[1]["lldpNeighbors"][index]['neighborDevice'] in adjacency_list[ip].keys()):
portchannel_interface = switch_cli.runCmds( 1, ["show interfaces "+response_lldp[1]["lldpNeighbors"][index]['port']+" status"])
po_n = portchannel_interface[0]["interfaceStatuses"][response_lldp[1]["lldpNeighbors"][index]['port']]["vlanInformation"]["vlanExplanation"][3:]
adjacency_list[ip][response_lldp[1]["lldpNeighbors"][index]['neighborDevice']] = po_n
else :
adjacency_list[ip][response_lldp[1]["lldpNeighbors"][index]['neighborDevice']] = response_lldp[1]["lldpNeighbors"][index]['port']
elif (response_lldp[1]["lldpNeighbors"][index]['neighborDevice'] == "localhost"):
adjacency_list[ip][response_lldp[1]["lldpNeighbors"][index]['neighborDevice']] = response_lldp[1]["lldpNeighbors"][index]['port']
return adjacency_list
示例15: test_get_intf_counters_default
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import runCmds [as 别名]
def test_get_intf_counters_default(self):
""" Test get_intf_counters with no interface specified
"""
from mock import MagicMock
from jsonrpclib import Server
switch = Server('https://arista:[email protected]:443/command-api')
response = []
response.append({})
response[0][u'interfaces'] = self.reference
switch.runCmds = MagicMock(return_value=response)
(propername, counters) = app.get_intf_counters(switch)
self.assertDictEqual(counters, self.reference['Management1'])