-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maxwell Schmitt <[email protected]>
- Loading branch information
0 parents
commit 0cbcdda
Showing
4 changed files
with
377 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#DEVTPLBUILD | ||
#Maxwell Schmitt ([email protected]) | ||
## Provided as-is -- allows you to build an xml file to import multiple devices in NSO | ||
|
||
### Using: | ||
Edit the python file's infile and outfile variable to what you'd prefer | ||
|
||
The infile's structure should look like: | ||
r1,127.0.0.1,10025,default,cisco-ios-xr | ||
r2,127.0.0.1,10026,default,cisco-ios-xr | ||
r3,127.0.0.1,10027,default,cisco-ios-xr | ||
r4,127.0.0.1,10028,default,cisco-ios-xr | ||
r5,127.0.0.1,10029,default,cisco-ios-xr | ||
r6,127.0.0.1,10030,default,cisco-ios-xr | ||
|
||
name (displayed in nso), device address, ssh port, authgroup (should already be setup in NSO), ned id. | ||
|
||
Then call like: | ||
python3 devtplbuild.py | ||
and import into NSO like: | ||
ncs_load -lm outfile | ||
|
||
|
||
Sample infile and outfile are included in the repo for you to analyze. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
''' | ||
DEVTPLBUILD | ||
Maxwell Schmitt | ||
([email protected]) | ||
**THIS SCRIPT IS PROVIDED AS-IS** | ||
''' | ||
|
||
import subprocess | ||
|
||
#Get the Fingerprint | ||
def sshscan(addr, port): | ||
keydata = subprocess.getoutput(["ssh-keyscan -p " + port + " " + addr]) | ||
keydata = keydata.split("ssh-rsa ")[1] | ||
return keydata | ||
|
||
#Generate the individual device template | ||
def tplgen(tpl, name, addr, port, keydata, authgroup, nedn): | ||
tpl = tpl.replace("\{name\}", name) | ||
tpl = tpl.replace("\{addr\}", addr) | ||
tpl = tpl.replace("\{port\}", port) | ||
tpl = tpl.replace("\{keydata\}", keydata) | ||
tpl = tpl.replace("\{authgroup\}", authgroup) | ||
tpl = tpl.replace("\{nedn\}", nedn.strip()) | ||
return tpl | ||
|
||
#Generate and concatenate the device templates | ||
def grandtplgen(tpl, dlist): | ||
grandtpl = '''''' | ||
for entry in dlist: | ||
grandtpl += tplgen(tpl, entry["name"], entry["addr"], entry["port"], entry["keydata"], entry["authgroup"], entry["nedn"]) | ||
return grandtpl | ||
|
||
#Read in from file and output a list of dictionaries with all info needed to generate templates | ||
def getdlist(ftr): | ||
infile = open(ftr, 'r') | ||
dlist = [] | ||
for line in infile: | ||
values = line.split(',') | ||
idlist = {} | ||
idlist["name"] = values[0] | ||
idlist["addr"] = values[1] | ||
idlist["port"] = values[2] | ||
idlist["keydata"] = sshscan(values[1], values[2]) | ||
idlist["authgroup"] = values[3] | ||
idlist["nedn"] = values[4] | ||
dlist.append(idlist) | ||
infile.close() | ||
return dlist | ||
|
||
#MAIN CODE BELOW | ||
|
||
enclosest = '<devices xmlns="http://tail-f.com/ns/ncs">\n' | ||
tpl = ''' | ||
<device> | ||
<name>\{name\}</name> | ||
<address>\{addr\}</address> | ||
<port>\{port\}</port> | ||
<ssh> | ||
<host-key> | ||
<algorithm>ssh-rsa</algorithm> | ||
<key-data>\{keydata\}</key-data> | ||
</host-key> | ||
</ssh> | ||
<state> | ||
<admin-state>unlocked</admin-state> | ||
</state> | ||
<authgroup>\{authgroup\}</authgroup> | ||
<device-type> | ||
<cli> | ||
<ned-id xmlns:\{nedn\}-id="http://tail-f.com/ned/\{nedn\}-id">\{nedn\}-id:\{nedn\}</ned-id> | ||
</cli> | ||
</device-type> | ||
</device>\n''' | ||
encloseend = "</devices>" | ||
|
||
infile = "in.txt" #modify the string to change the infile destination | ||
outfile = "out.xml" #modify the string to change the outfile destination | ||
grandtpl = grandtplgen(tpl, getdlist(infile)) | ||
grandout = enclosest + grandtpl + encloseend | ||
xmlout = open(outfile, 'w') | ||
xmlout.write(grandout) | ||
xmlout.close() | ||
|
||
print("Done!\nJust type ncs_load -lm " + outfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
r1,127.0.0.1,10025,default,cisco-ios-xr | ||
r2,127.0.0.1,10026,default,cisco-ios-xr | ||
r3,127.0.0.1,10027,default,cisco-ios-xr | ||
r4,127.0.0.1,10028,default,cisco-ios-xr | ||
r5,127.0.0.1,10029,default,cisco-ios-xr | ||
r6,127.0.0.1,10030,default,cisco-ios-xr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
<devices xmlns="http://tail-f.com/ns/ncs"> | ||
|
||
<device> | ||
|
||
<name>r1</name> | ||
|
||
<address>127.0.0.1</address> | ||
|
||
<port>10025</port> | ||
|
||
<ssh> | ||
|
||
<host-key> | ||
|
||
<algorithm>ssh-rsa</algorithm> | ||
|
||
<key-data>AAAAB3NzaC1yc2EAAAADAQABAAABAQCfwcpG2KIWUV0xyEimS59buyNoGJSDycB66tXd0cqNOxa6cHnKK7QAHRDrrPWu668yYou7HGiGeoKhN5lV1ztDvTNtpYYvU5aNYejBq+EoFABgX5pLjguyTW7JpTe6ZdlIcgrSqlldjNsMHEc8xmHq1lJDJDJeC4PzIgUMYxaNOiYa5rxTABvYBk8O2qrxFqDAT3ym9p50iYFIjTrkLVwBK3HPW+Qlto7gf/rUHDYUEhBb0s3HI63bd63VmD21CwxvYta693XIFOR5lgxQzTNvigvWoMfrbO7KcI1Jq0+tCtzMPVnVKqjH8KK+C4Qt7gIBVmYfEMZqLmeVUdAKRqNf</key-data> | ||
|
||
</host-key> | ||
|
||
</ssh> | ||
|
||
<state> | ||
|
||
<admin-state>unlocked</admin-state> | ||
|
||
</state> | ||
|
||
<authgroup>default</authgroup> | ||
|
||
<device-type> | ||
|
||
<cli> | ||
|
||
<ned-id xmlns:cisco-ios-xr-id="http://tail-f.com/ned/cisco-ios-xr-id">cisco-ios-xr-id:cisco-ios-xr</ned-id> | ||
|
||
</cli> | ||
|
||
</device-type> | ||
|
||
</device> | ||
|
||
<device> | ||
|
||
<name>r2</name> | ||
|
||
<address>127.0.0.1</address> | ||
|
||
<port>10026</port> | ||
|
||
<ssh> | ||
|
||
<host-key> | ||
|
||
<algorithm>ssh-rsa</algorithm> | ||
|
||
<key-data>AAAAB3NzaC1yc2EAAAADAQABAAABAQCfwcpG2KIWUV0xyEimS59buyNoGJSDycB66tXd0cqNOxa6cHnKK7QAHRDrrPWu668yYou7HGiGeoKhN5lV1ztDvTNtpYYvU5aNYejBq+EoFABgX5pLjguyTW7JpTe6ZdlIcgrSqlldjNsMHEc8xmHq1lJDJDJeC4PzIgUMYxaNOiYa5rxTABvYBk8O2qrxFqDAT3ym9p50iYFIjTrkLVwBK3HPW+Qlto7gf/rUHDYUEhBb0s3HI63bd63VmD21CwxvYta693XIFOR5lgxQzTNvigvWoMfrbO7KcI1Jq0+tCtzMPVnVKqjH8KK+C4Qt7gIBVmYfEMZqLmeVUdAKRqNf</key-data> | ||
|
||
</host-key> | ||
|
||
</ssh> | ||
|
||
<state> | ||
|
||
<admin-state>unlocked</admin-state> | ||
|
||
</state> | ||
|
||
<authgroup>default</authgroup> | ||
|
||
<device-type> | ||
|
||
<cli> | ||
|
||
<ned-id xmlns:cisco-ios-xr-id="http://tail-f.com/ned/cisco-ios-xr-id">cisco-ios-xr-id:cisco-ios-xr</ned-id> | ||
|
||
</cli> | ||
|
||
</device-type> | ||
|
||
</device> | ||
|
||
<device> | ||
|
||
<name>r3</name> | ||
|
||
<address>127.0.0.1</address> | ||
|
||
<port>10027</port> | ||
|
||
<ssh> | ||
|
||
<host-key> | ||
|
||
<algorithm>ssh-rsa</algorithm> | ||
|
||
<key-data>AAAAB3NzaC1yc2EAAAADAQABAAABAQCfwcpG2KIWUV0xyEimS59buyNoGJSDycB66tXd0cqNOxa6cHnKK7QAHRDrrPWu668yYou7HGiGeoKhN5lV1ztDvTNtpYYvU5aNYejBq+EoFABgX5pLjguyTW7JpTe6ZdlIcgrSqlldjNsMHEc8xmHq1lJDJDJeC4PzIgUMYxaNOiYa5rxTABvYBk8O2qrxFqDAT3ym9p50iYFIjTrkLVwBK3HPW+Qlto7gf/rUHDYUEhBb0s3HI63bd63VmD21CwxvYta693XIFOR5lgxQzTNvigvWoMfrbO7KcI1Jq0+tCtzMPVnVKqjH8KK+C4Qt7gIBVmYfEMZqLmeVUdAKRqNf</key-data> | ||
|
||
</host-key> | ||
|
||
</ssh> | ||
|
||
<state> | ||
|
||
<admin-state>unlocked</admin-state> | ||
|
||
</state> | ||
|
||
<authgroup>default</authgroup> | ||
|
||
<device-type> | ||
|
||
<cli> | ||
|
||
<ned-id xmlns:cisco-ios-xr-id="http://tail-f.com/ned/cisco-ios-xr-id">cisco-ios-xr-id:cisco-ios-xr</ned-id> | ||
|
||
</cli> | ||
|
||
</device-type> | ||
|
||
</device> | ||
|
||
<device> | ||
|
||
<name>r4</name> | ||
|
||
<address>127.0.0.1</address> | ||
|
||
<port>10028</port> | ||
|
||
<ssh> | ||
|
||
<host-key> | ||
|
||
<algorithm>ssh-rsa</algorithm> | ||
|
||
<key-data>AAAAB3NzaC1yc2EAAAADAQABAAABAQCfwcpG2KIWUV0xyEimS59buyNoGJSDycB66tXd0cqNOxa6cHnKK7QAHRDrrPWu668yYou7HGiGeoKhN5lV1ztDvTNtpYYvU5aNYejBq+EoFABgX5pLjguyTW7JpTe6ZdlIcgrSqlldjNsMHEc8xmHq1lJDJDJeC4PzIgUMYxaNOiYa5rxTABvYBk8O2qrxFqDAT3ym9p50iYFIjTrkLVwBK3HPW+Qlto7gf/rUHDYUEhBb0s3HI63bd63VmD21CwxvYta693XIFOR5lgxQzTNvigvWoMfrbO7KcI1Jq0+tCtzMPVnVKqjH8KK+C4Qt7gIBVmYfEMZqLmeVUdAKRqNf</key-data> | ||
|
||
</host-key> | ||
|
||
</ssh> | ||
|
||
<state> | ||
|
||
<admin-state>unlocked</admin-state> | ||
|
||
</state> | ||
|
||
<authgroup>default</authgroup> | ||
|
||
<device-type> | ||
|
||
<cli> | ||
|
||
<ned-id xmlns:cisco-ios-xr-id="http://tail-f.com/ned/cisco-ios-xr-id">cisco-ios-xr-id:cisco-ios-xr</ned-id> | ||
|
||
</cli> | ||
|
||
</device-type> | ||
|
||
</device> | ||
|
||
<device> | ||
|
||
<name>r5</name> | ||
|
||
<address>127.0.0.1</address> | ||
|
||
<port>10029</port> | ||
|
||
<ssh> | ||
|
||
<host-key> | ||
|
||
<algorithm>ssh-rsa</algorithm> | ||
|
||
<key-data>AAAAB3NzaC1yc2EAAAADAQABAAABAQCfwcpG2KIWUV0xyEimS59buyNoGJSDycB66tXd0cqNOxa6cHnKK7QAHRDrrPWu668yYou7HGiGeoKhN5lV1ztDvTNtpYYvU5aNYejBq+EoFABgX5pLjguyTW7JpTe6ZdlIcgrSqlldjNsMHEc8xmHq1lJDJDJeC4PzIgUMYxaNOiYa5rxTABvYBk8O2qrxFqDAT3ym9p50iYFIjTrkLVwBK3HPW+Qlto7gf/rUHDYUEhBb0s3HI63bd63VmD21CwxvYta693XIFOR5lgxQzTNvigvWoMfrbO7KcI1Jq0+tCtzMPVnVKqjH8KK+C4Qt7gIBVmYfEMZqLmeVUdAKRqNf</key-data> | ||
|
||
</host-key> | ||
|
||
</ssh> | ||
|
||
<state> | ||
|
||
<admin-state>unlocked</admin-state> | ||
|
||
</state> | ||
|
||
<authgroup>default</authgroup> | ||
|
||
<device-type> | ||
|
||
<cli> | ||
|
||
<ned-id xmlns:cisco-ios-xr-id="http://tail-f.com/ned/cisco-ios-xr-id">cisco-ios-xr-id:cisco-ios-xr</ned-id> | ||
|
||
</cli> | ||
|
||
</device-type> | ||
|
||
</device> | ||
|
||
<device> | ||
|
||
<name>r6</name> | ||
|
||
<address>127.0.0.1</address> | ||
|
||
<port>10030</port> | ||
|
||
<ssh> | ||
|
||
<host-key> | ||
|
||
<algorithm>ssh-rsa</algorithm> | ||
|
||
<key-data>AAAAB3NzaC1yc2EAAAADAQABAAABAQCfwcpG2KIWUV0xyEimS59buyNoGJSDycB66tXd0cqNOxa6cHnKK7QAHRDrrPWu668yYou7HGiGeoKhN5lV1ztDvTNtpYYvU5aNYejBq+EoFABgX5pLjguyTW7JpTe6ZdlIcgrSqlldjNsMHEc8xmHq1lJDJDJeC4PzIgUMYxaNOiYa5rxTABvYBk8O2qrxFqDAT3ym9p50iYFIjTrkLVwBK3HPW+Qlto7gf/rUHDYUEhBb0s3HI63bd63VmD21CwxvYta693XIFOR5lgxQzTNvigvWoMfrbO7KcI1Jq0+tCtzMPVnVKqjH8KK+C4Qt7gIBVmYfEMZqLmeVUdAKRqNf</key-data> | ||
|
||
</host-key> | ||
|
||
</ssh> | ||
|
||
<state> | ||
|
||
<admin-state>unlocked</admin-state> | ||
|
||
</state> | ||
|
||
<authgroup>default</authgroup> | ||
|
||
<device-type> | ||
|
||
<cli> | ||
|
||
<ned-id xmlns:cisco-ios-xr-id="http://tail-f.com/ned/cisco-ios-xr-id">cisco-ios-xr-id:cisco-ios-xr</ned-id> | ||
|
||
</cli> | ||
|
||
</device-type> | ||
|
||
</device> | ||
</devices> |