Skip to content

Commit

Permalink
Update exam scripts, add save script in login container (#482) (#484)
Browse files Browse the repository at this point in the history
Co-authored-by: richardap1 <richard.parkin@gmail.com>

Co-authored-by: richardap1 <richard.parkin@gmail.com>
  • Loading branch information
rparkinarista and richardap1 authored Sep 14, 2021
1 parent 757ce2d commit 6595c66
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nested-labvm/atd-docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
- /home/arista/arista-dir:/home/arista:rw
login:
container_name: atd-login
image: us.gcr.io/beta-atds/atddocker_login:2.0.5
image: us.gcr.io/beta-atds/atddocker_login:2.0.6
user: $ArID:$ArGD
restart: always
hostname: devbox
Expand Down
4 changes: 4 additions & 0 deletions nested-labvm/atd-docker/login/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ COPY src/resetVMs.py /usr/local/bin

COPY src/uploadExam.py /usr/local/bin

COPY src/saveRunning.py /usr/local/bin

RUN chmod +x /usr/local/bin/login.py

RUN chmod +x /usr/local/bin/resetVMs.py

RUN chmod +x /usr/local/bin/uploadExam.py

RUN chmod +x /usr/local/bin/saveRunning.py

RUN mkdir /usr/local/bin/ConfigureTopology

COPY src/ConfigureTopology/* /usr/local/bin/ConfigureTopology/
Expand Down
64 changes: 64 additions & 0 deletions nested-labvm/atd-docker/login/src/saveRunning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash/python

#Save running config on all switches

import jsonrpclib,ssl,sys
import yaml


#static files
labACCESS = '/etc/atd/ACCESS_INFO.yaml'



try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context

def saveRunningConfig(allHosts,labPassword):
for IPaddress in allHosts:
try:
#use eAPI to copy the running-config to start-config
switch = jsonrpclib.Server("https://arista:{password}@{ipaddress}/command-api".format(password = labPassword, ipaddress = IPaddress))
switch.runCmds( 1, [ "enable", "copy running-config startup-config" ] )
print("Done {0}".format(IPaddress))

except KeyboardInterrupt:
print("Caught Keyboard Interrupt - Exiting")
sys.exit()

except OSError as ERR :
# Socket Errors
print(ERR)



def readLabDetails():
# get the lab password and the topolgy in use
with open(labACCESS) as f:
labDetails = yaml.load(f,Loader=yaml.FullLoader)
return labDetails['login_info']['jump_host']['pw'], labDetails['topology']



def readAtdTopo(labTopology):
#get a list of all IP addresses in the topology
with open("/opt/atd/topologies/"+ labTopology +"/topo_build.yml") as f:
topology = yaml.load(f,Loader=yaml.FullLoader)
hosts = []
for a in topology['nodes']:
for key in a.keys():
hosts.append(a[key]['ip_addr'])
return hosts


def main():
labPassword, labTopology = readLabDetails()
allHosts = readAtdTopo(labTopology)
saveRunningConfig(allHosts,labPassword)

main()

119 changes: 105 additions & 14 deletions nested-labvm/atd-docker/login/src/uploadExam.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def getConfigletApplied(configletName,cookies):
return outputConfiglets

def grabCVPInfo(labPassword,folder):
print("Getting CVP details, this may take a few seconds")
cookies = cvpAuth(labPassword)
outputConfiglets = getConfiglets(cookies,folder)
for item in outputConfiglets['data']:
Expand All @@ -115,11 +116,12 @@ def grabCVPInfo(labPassword,folder):
completePath = os.path.join(folder, item['name'])
with open(completePath +".configlet", 'w') as f:
f.write(str(json.dump(appliedConfiglets, f, indent=4)))
print("CVP details saved")

def getUserInfo():
accept = "n"
emailCounter = 0
print("This script requires eAPI to be enabled and functioning. By default this should work, however if any of the settings have been modified it many not work correctly")
print("This script requires eAPI to be enabled and functioning. By default this should work, however if any of the settings have been modified it may not work correctly")
print("You should only upload once you have finished your exam. Once uploaded you will NOT be able to do it again without contacting Arista training or SDN-Pros.")
while accept != "y":
accept = input ("Do you accept this? (y/n) ")
Expand All @@ -145,6 +147,106 @@ def createUserFile(fullName,email,candidateID,folder,labName,labTopology):
print("Written user details to file")


def grabSwitchDetails(allHostsName,allHostsIP,folder,labPassword):
pingDone = 0
evpnNOTdone = 0
for name, ip in zip(reversed(allHostsName),reversed(allHostsIP)):
switch = jsonrpclib.Server("https://arista:{password}@{ipaddress}/command-api".format(password = labPassword, ipaddress = ip))
try:
config = switch.runCmds(1,["enable", "show running-config"],"text")
runConfig = (config[1]["output"])
mlag = switch.runCmds(1,["enable", "show mlag","show mlag config-sanity", "show mlag interfaces detail"],"text")
mlagOutput = "show mlag\n"
mlagOutput += (mlag[1]["output"])
mlagOutput += "\nshow mlag config-sanity\n"
mlagOutput += (mlag[2]["output"])
mlagOutput += "\nshow mlag interfaces detail\n"
mlagOutput += (mlag[3]["output"])
vxlan = switch.runCmds(1,["enable", "show vxlan address-table", "show mac address-table", "show vxlan flood vtep", "show vxlan vtep detail", "show vxlan vni summary", "show vxlan vni", "show vxlan config-sanity"],"text")
vxlanOutput = "show vxlan address-table\n"
vxlanOutput += (vxlan[1]["output"])
vxlanOutput += "\nshow mac address-table\n"
vxlanOutput += (vxlan[2]["output"])
vxlanOutput += "\nshow vxlan flood vtep\n"
vxlanOutput += (vxlan[3]["output"])
vxlanOutput += "\nshow vxlan vtep detail\n"
vxlanOutput += (vxlan[4]["output"])
vxlanOutput += "\nshow vxlan vni summary\n"
vxlanOutput += (vxlan[5]["output"])
vxlanOutput += "\nshow vxlan vni\n"
vxlanOutput += (vxlan[6]["output"])
vxlanOutput += "\nshow vxlan config-sanity\n"
vxlanOutput += (vxlan[7]["output"])
route = switch.runCmds(1,["enable", "show ip route"],"text")
routeOutput = (route[1]["output"])
bgpSum = switch.runCmds(1,["enable", "show ip bgp summary"],"text")
bgpSumOutput = (bgpSum[1]["output"])
if not "host" in name:
evpnSum = switch.runCmds(1,["enable", "show bgp evpn summary"],"text")
evpnSumOutput = (evpnSum[1]["output"])
evpnBGP = switch.runCmds(1,["enable", "show bgp evpn"],"text")
evpnBGPOutput = (evpnBGP[1]["output"])
evpnNOTdone = 1
intSum = switch.runCmds(1,["enable", "show ip interface brief"],"text")
intSumOutput = (intSum[1]["output"])
vlanSum = switch.runCmds(1,["enable", "show vlan"],"text")
vlanSumOutput = (vlanSum[1]["output"])
if "host1" in name:
pingSum = switch.runCmds(1,["enable", "ping 172.16.200.10"],"text")
pingSumOutput = (pingSum[1]["output"])
pingDone = 1
except Exception as e:
print(str(e))
print("Check eAPI is enabled on {switch}".format(switch = name))
else:
filename = str(name) + "-running" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(runConfig)
filename = str(name) + "-MLAG" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(mlagOutput)
filename = str(name) + "-Route" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(routeOutput)
filename = str(name) + "-BGPsummary" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(bgpSumOutput)
if evpnNOTdone == 1:
filename = str(name) + "-EVPNsummary" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(evpnSumOutput)
filename = str(name) + "-EVPN" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(evpnBGPOutput)
evpnNOTdone = 0
filename = str(name) + "-INTsummary" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(intSumOutput)
filename = str(name) + "-VXLAN" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(vxlanOutput)
filename = str(name) + "-VLANsummary" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(vlanSumOutput)
if pingDone == 1:
filename = str(name) + "-PINGsummary" + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(pingSumOutput)
pingDone = 0
print("Switch {switch} config and output saved".format(switch = name))




def main():
labPassword, labTopology, labName = readLabDetails()
Expand All @@ -157,25 +259,14 @@ def main():
os.makedirs(folder)
except OSError as exc: # Guard against race condition
raise
for name, ip in zip(allHostsName,allHostsIP):
switch = jsonrpclib.Server("https://arista:{password}@{ipaddress}/command-api".format(password = labPassword, ipaddress = ip))
try:
config = switch.runCmds(1,["enable", "show running-config"],"text")
runConfig = (config[1]["output"])
except:
print("Check eAPI is enabled on {switch}".format(switch = name))
else:
filename = str(name) + ".txt"
completePath = os.path.join(folder, filename)
with open(completePath, 'w') as f:
f.write(runConfig)
print("Switch {switch} config saved".format(switch = name))
grabSwitchDetails(allHostsName,allHostsIP,folder,labPassword)
tarFile = folder + "-" + candidateID
grabCVPInfo(labPassword,folder)
createUserFile(fullName,email,candidateID,folder,labName,labTopology)
print("This file will be created and uploaded " + tarFile)
with tarfile.open(tarFile, "w:gz") as tar:
tar.add(os.getcwd() + "/" + folder, arcname=os.path.basename(tarFile))
tar.add("apps/coder/",arcname=os.path.basename(tarFile))
ftpUpload(tarFile)


Expand Down

0 comments on commit 6595c66

Please sign in to comment.