10-14-2020 08:50 PM
I’m writing a python script to create MLAG port. Since the config will vary slightly between 2 devices, is it possible to write this in a single script and apply to 2 devices?
Here is my script so far.
#@METADATASTART
#@ScriptDescription "Create mLAG Port"
#@DetailDescriptionStart
##############################################################################
#
# Purpose: Create mLAG Port
#
# Version : 1.0
#
##############################################################################
#@DetailDescriptionEnd
#
#@SectionStart ( description = "mLAG Section")
#@VariableFieldLabel (
# description = "mLAG VLAN Name",
# type = String,
# scope = global,
# required = yes,
# value = "mLAG-ISL",
# name = "MlagName"
# )
#
#@SectionEnd
#@VariableFieldLabel (
# description = "mLAG VLAN ID",
# type = String,
# scope = global,
# required = yes,
# value = "4092",
# name = "MlagId"
# )
#
#@SectionEnd
#@SectionStart ( description = "mLAG ISL Port")
#@VariableFieldLabel (
# description = "mLAG ISL Port",
# type = String,
# scope = global,
# required = yes,
# value = "port_number",
# name = "MlagPort"
# )
#@SectionEnd
#@SectionStart ( description = "mLAG Peer")
#@VariableFieldLabel (
# description = "mLAG Peer",
# type = String,
# scope = global,
# required = yes,
# value = "peer_switch",
# name = "MlagPeer"
# )
#@MetaDataEnd
import re
import commands
def allowedSigns(tagged_vlans):
reg = re.compile(r'[^0-9,]')
string = reg.search(tagged_vlans)
return not bool(string)
def vlanCheck(tagged_vlans):
if allowedSigns(tagged_vlans) == True:
vlanList = tagged_vlans.split(",")
for v in vlanList:
if int(v) > 4094 or int(v) < 1 or int(v) == 4051 or int(v) == 4052:
print "Error not a valid vlan id" + v
return False
else:
print "Wrong character in vlan list, use only digits and \",\" as separator, please!"
return False
return True
def main():
varMlagName = emc_vars["MlagName"]
varMlagId = emc_vars["MlagId"]
varMlagPort = emc_vars["MlagPort"]
varMlagPeer = emc_vars["MlagPeer"]
#varDeviceName = emc_vars["deviceName"]
if "port" in emc_vars:
ports = emc_vars["port"]
else:
print "Please select at least one PORT if you start the script"
return 0
print("The name of the device is :" + emc_vars["deviceName"])
#create mlag if needed#
cli_result = emc_cli.send("disable clipaging")
cli_result = emc_cli.send("show mlag peer")
mlag = cli_result.getOutput()
mlag_vlan = re.findall(r"VLAN\s+:\s\S{3,15}", mlag)
mlagid = [s.strip('VLAN : ') for s in mlag_vlan]
if mlagid:
print("mLAG id is: ", mlagid)
else:
print("mLAG does not exist. Creating ISC...")
cli_result = emc_cli.send("create vlan " + varMlagName)
cli_result = emc_cli.send("configure vlan " + varMlagName + " tag " + varMlagId)
cli_result = emc_cli.send("configure vlan " + varMlagName + " add ports " + varMlagPort + " tagged")
cli_result = emc_cli.send("configure vlan " + varMlagName + " ipaddress 169.254.40.93 255.255.255.252")
cli_result = emc_cli.send("enable sharing " + ports + " grouping " + ports + " algorithm address-based L3_L4") #create LACP option#
cli_result = emc_cli.send("create mlag peer " + varMlagPeer)
cli_result = emc_cli.send("configure mlag peer " + varMlagPeer + " ipaddress 169.254.40.94 vr VR-Default")
cli_result = emc_cli.send("enable mlag port " + ports + " peer " + varMlagPeer + " id 1")
main()
10-15-2020 05:16 AM
Hello cslayton,
did you see the the System Workflow “Configure ISC and MLAG Peers on EXOS” (in System Workflows->Config->LAG-MLAG)?
Maybe that Workflow do the work for you. Or did you miss something?
Regards
Stephan