From 8bdc99128fc889b0c33235ec5400eb1f06a3a08f Mon Sep 17 00:00:00 2001 From: M35a2 <49795550+M35a2@users.noreply.github.com> Date: Wed, 20 Oct 2021 15:38:09 -0600 Subject: [PATCH 1/3] fixed readability / adjusted for login.yaml --- .../breakout-to-secureCRT-session/readme.md | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/scripts/breakout-to-secureCRT-session/readme.md b/scripts/breakout-to-secureCRT-session/readme.md index 62ec45b..9cfa5f8 100644 --- a/scripts/breakout-to-secureCRT-session/readme.md +++ b/scripts/breakout-to-secureCRT-session/readme.md @@ -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... ![alt text](https://github.com/M35a2/CML-Breakout-SecureCRT-Session/blob/main/Capture.PNG?raw=true) +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. \ No newline at end of file +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 + From 19185fda09d9ef3c9da25732f09b2680f7683806 Mon Sep 17 00:00:00 2001 From: M35a2 <49795550+M35a2@users.noreply.github.com> Date: Wed, 20 Oct 2021 15:39:08 -0600 Subject: [PATCH 2/3] Create login.yaml --- scripts/breakout-to-secureCRT-session/login.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 scripts/breakout-to-secureCRT-session/login.yaml diff --git a/scripts/breakout-to-secureCRT-session/login.yaml b/scripts/breakout-to-secureCRT-session/login.yaml new file mode 100644 index 0000000..1b5ca63 --- /dev/null +++ b/scripts/breakout-to-secureCRT-session/login.yaml @@ -0,0 +1,5 @@ +#Connectivity Info +cmlServer: cml.domain.com +lab: 53b3fe +username: admin +password: password From 8adac17baee0bfc5f8755cebf9123eb3ebe5a35e Mon Sep 17 00:00:00 2001 From: M35a2 <49795550+M35a2@users.noreply.github.com> Date: Wed, 20 Oct 2021 15:40:57 -0600 Subject: [PATCH 3/3] added support for more default devices added support for: unmanaged switches asav ftdv server alpine coreos desktop ubuntu --- scripts/breakout-to-secureCRT-session/main.py | 63 ++++++++++++++----- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/scripts/breakout-to-secureCRT-session/main.py b/scripts/breakout-to-secureCRT-session/main.py index 6ef1dcb..664e3c3 100644 --- a/scripts/breakout-to-secureCRT-session/main.py +++ b/scripts/breakout-to-secureCRT-session/main.py @@ -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...")