Lab2 EMC Python: Contact

import re

def main():

familyType = emc_vars[‘family’]

if familyType == ‘VSP Series’:
showCmd = ‘show sys-info’
result = emc_cli.send(showCmd)
output = result.getOutput()
match = re.search(‘SysLocation  : (.+)’, output)
location = match.group(1)

elif familyType == ‘Summit Series’:
showCmd = ‘show system’
result = emc_cli.send(showCmd)
output = result.getOutput()
match = re.search(‘SysLocation:      (.+)’, output)
location = match.group(1)
else:
raise RuntimeError(“Unexpected switch family type!!”)

print “Switch has location set to :”, location

if location == ‘Castle of Aarrgh’:
manager = ‘King Arthur’
elif location == ‘Bridge of Death’:
manager = ‘Lancelot’
elif location == ‘Castle Anthrax’:
manager = ‘Patsy’
elif location == ‘Swamp Castle’:
manager = ‘Sir Galahad’
else:
raise RuntimeError(“Unexpected location!!”)

if familyType == ‘VSP Series’:
emc_cli.send(‘enable’)
emc_cli.send(‘config term’)
cmd = ‘snmp-server contact “‘+manager+'”‘
elif familyType == ‘Summit Series’:
cmd = ‘configure snmp sysContact “‘+manager+'”‘
else:
raise RuntimeError(“Unexpected switch family type!!”)

emc_cli.send(cmd)

print “Successfully set switch manager to:”, manager

main()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s