mirror of
				https://github.com/CiscoDevNet/cml-community.git
				synced 2025-10-31 12:03:41 +00:00 
			
		
		
		
	Merge pull request #14 from M35a2/master
support for more default devices
This commit is contained in:
		
							
								
								
									
										5
									
								
								scripts/breakout-to-secureCRT-session/login.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								scripts/breakout-to-secureCRT-session/login.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| #Connectivity Info | ||||
| cmlServer: cml.domain.com | ||||
| lab: 53b3fe | ||||
| username: admin | ||||
| password: password | ||||
| @@ -1,18 +1,30 @@ | ||||
| import requests | ||||
| import json | ||||
| import os | ||||
| import yaml | ||||
| requests.packages.urllib3.disable_warnings() | ||||
| from cmlApiCalls import CML as cml | ||||
|  | ||||
| server = "cml.server.com" | ||||
| username = "admin" | ||||
| password = "CMLpassword123" | ||||
| lab = "53b3fe" | ||||
| user = os.getlogin() | ||||
| auth = cml.auth(server, username, password) | ||||
| allNodes = cml.getAllNodes(auth, server, lab) | ||||
| # print(allNodes) | ||||
| # get login information from login.yaml | ||||
| with open("login.yaml") as f: | ||||
|     login = yaml.safe_load(f.read()) | ||||
|  | ||||
| # set variable from yaml file | ||||
| server = login["cmlServer"] | ||||
| lab = login["lab"] | ||||
| username = login["username"] | ||||
| password = login["password"] | ||||
|  | ||||
| # get username for secureCRT directory | ||||
| user = os.getlogin() | ||||
|  | ||||
| # get authentication token from CML (funtion in cmlApiCalls.py) | ||||
| auth = cml.auth(server, username, password) | ||||
|  | ||||
| # get all nodes from the cml server (funtion in cmlApiCalls.py) | ||||
| allNodes = cml.getAllNodes(auth, server, lab) | ||||
| # print(allNodes) -- for troubleshooting | ||||
| N = True | ||||
| n_id = 0 | ||||
| port = 9000 | ||||
| try: | ||||
| @@ -24,14 +36,17 @@ except: | ||||
| while n_id < 100: | ||||
|     node_id = f"n{n_id}" | ||||
|     response = cml.getNodesByID(auth, server, lab, node_id) | ||||
|     # print(response) | ||||
|     # print(response) -- for troubleshooting | ||||
|     # if node does not exists, check the next node | ||||
|     if response == "end of list": | ||||
|         print("Node " + node_id + " does not exist, will check all nodes from n0 to n99.") | ||||
|         # increment node number | ||||
|         n_id = n_id + 1 | ||||
|  | ||||
|  | ||||
|     elif response.get("node_definition") == "external_connector": | ||||
|         # dont count external_connector as usable | ||||
|     # dont count devices that cannot be consoled into     | ||||
|     elif (response.get("node_definition") == "external_connector" or | ||||
|             response.get("node_definition") == "unmanaged_switch"): | ||||
|         # increment node number | ||||
|         n_id = n_id + 1     | ||||
|          | ||||
|     else: | ||||
| @@ -41,7 +56,9 @@ while n_id < 100: | ||||
|         # turn port number into hex | ||||
|         # strip "0x2233" and make it only 4 charators    | ||||
|         hexport = hex(port).split('x')[-1] | ||||
|         print("creating: " + node_label) | ||||
|         # node definition is also printed for troubleshooting | ||||
|         print("creating: " + node_label + " Node Definition: " + response.get("node_definition")) | ||||
|         # create a secureCRT Session | ||||
|         with open("config.ini", "r") as config: | ||||
|             temp = config.read() | ||||
|             temp = temp.replace("REPLACE", "0000" + hexport) | ||||
| @@ -49,13 +66,27 @@ while n_id < 100: | ||||
|             with open( location, "w") as config2write: | ||||
|                 config2write.write(temp) | ||||
|          | ||||
|         if response.get("node_definition") == "wan_emulator": | ||||
|             # add by 1 if wan_emulator | ||||
|         # if any custom nodes are added, and they dont add by 2 ports in the breakout tool | ||||
|         # add the node definition to the if statement below to only add by 1 port.  | ||||
|         if (response.get("node_definition") == "wan_emulator" or  | ||||
|                 response.get("node_definition") == "asav" or  | ||||
|                 response.get("node_definition") == "ftdv" or | ||||
|                 response.get("node_definition") == "server" or | ||||
|                 response.get("node_definition") == "alpine" or | ||||
|                 response.get("node_definition") == "coreos" or | ||||
|                 response.get("node_definition") == "desktop" or | ||||
|                 response.get("node_definition") == "ubuntu"): | ||||
|             # only add 1 to port number for the next device | ||||
|             port = port + 1 | ||||
|         # else add 2 to port number for the next device | ||||
|         else: | ||||
|             port = port + 2 | ||||
|         # increment node number     | ||||
|         n_id = n_id + 1 | ||||
|          | ||||
| #  | ||||
| print("Nodes 0-99 checked. if you need more, increase the number checked in the while loop") | ||||
| print("example change to: while n_id < 150:") | ||||
| print("exiting...")         | ||||
|              | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -14,15 +14,65 @@ Tested on: | ||||
| - secureCRT 9.0.2 | ||||
|  | ||||
| Variables to edit: | ||||
| on main.py edit server, username, password, and lab number.  | ||||
| in login.yaml edit the server name, username, password, and lab number.  | ||||
|  | ||||
| This python app will create a new folder and all the telnet sessions for the lab.  | ||||
| Port numbers are listed in front of the devices name so you can quickly bounce it off the breakout tool if something doesnt seem right... | ||||
|  | ||||
|  | ||||
|  | ||||
| to run the script: | ||||
| - edit the variables in login.yaml (note: you can find the lab number in the url when opening the lab on the cml server webpage) | ||||
| - run main.py file to start the program  | ||||
|  | ||||
| Example: | ||||
| ``` | ||||
| C:\Users\Admin\Documents\CML-Breakout-SecureCRT-Session> python .\main.py | ||||
| creating: internet Node Definition: iosv | ||||
| creating: csr-sdwan-3-1 Node Definition: csr1000v | ||||
| creating: csr-sdwan-4-1 Node Definition: csr1000v | ||||
| creating: wan-em-2 Node Definition: wan_emulator | ||||
| ...omitted... | ||||
| Node n98 does not exist, will check all nodes from n0 to n99. | ||||
| Node n99 does not exist, will check all nodes from n0 to n99. | ||||
| Nodes 0-99 checked. if you need more, increase the number checked in the while loop | ||||
| example: while n_id < 150: | ||||
| exiting... | ||||
| C:\Users\Admin\Documents\CML-Breakout-SecureCRT-Session> | ||||
| ``` | ||||
|  | ||||
| easist way to update a lab after adding/deleting devices is to just delete the lab folder in secureCRT, rerun the script, and restart secureCRT | ||||
|  | ||||
| Known issues: | ||||
| only tested on wan emulators, routers, switches...  | ||||
| i haven't tested on anything that requires VNC or breakout might handle differently than adding by two port numbers.  | ||||
| This has not been tested on every node type. | ||||
| Some nodes only add by 1 port number in the breakout tool, some add by 2. | ||||
| if you devices got out of order, check the breakout tool and see if it only added by one port after the device where it became out of order.  | ||||
| if so, you can add that node definition to the "if" statement starting on line 71 of main.py | ||||
| ``` | ||||
|         # if any custom nodes are added, and they dont add by 2 ports in the breakout tool | ||||
|         # add the node definition to the if statement below to only add by 1 port.  | ||||
|         if (response.get("node_definition") == "wan_emulator" or  | ||||
|                 response.get("node_definition") == "asav" or  | ||||
|                 response.get("node_definition") == "ftdv" or | ||||
|                 response.get("node_definition") == "server" or | ||||
|                 response.get("node_definition") == "alpine" or | ||||
|                 response.get("node_definition") == "coreos" or | ||||
|                 response.get("node_definition") == "desktop" or | ||||
|                 response.get("node_definition") == "ubuntu" or | ||||
|            ---> response.get("node_definition") == "CustomNode1" or | ||||
|            ---> response.get("node_definition") == "CustomNode2"): | ||||
|             # only add 1 to port number for the next device | ||||
|             port = port + 1 | ||||
| ``` | ||||
| the node definition is printed out with each item created so you know what the name is to add. | ||||
| Likewise, if there is a node that cannot be consoled into, add it to the "elif" statement on line 47 | ||||
| ``` | ||||
|     # dont count devices that cannot be consoled into     | ||||
|     elif (response.get("node_definition") == "external_connector" or | ||||
|             response.get("node_definition") == "unmanaged_switch" or | ||||
|             response.get("node_definition") == "some other node definition that doesnt have a console"): | ||||
|         # increment node number | ||||
|         n_id = n_id + 1     | ||||
| ``` | ||||
| Good luck | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user