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 09:10 AM
If you enable the Multi-Device menu option for the script, it can then be executed against 2 (or more) switches at the same time. What happens then is that your script gets executed simultaneously against multiple switches (i.e. you get multiple threads of the same script) each instance will have the same inputs but will operate against a different switch IP.
So that will work; the problem is if you need those instances to get inputs from each other, as there is no mechanism in XMC to exchange data between those threads.
Another approach is to use workflows (not scripts) and let the workflow take both switch IPs from the start (so 1 single workflow thread) and then have parallel activities within the workflow, on both switches; here it is possible to exchange data inside the workflow.
10-15-2020 08:05 AM
It’s too early for me
10-15-2020 07:56 AM
Hey Mig,
I have also suggested this above
10-15-2020 07:14 AM
cslayton,
Did checked the standard workflow for this on the XMC?
It is located at Tasks/Workflows/System Workflows/Syste/Config/LAG-MLAG/Configure ISC and MLAG Peers on EXOS
Regards
Mig
10-15-2020 05:24 AM
Hello cslyton,
Regarding your original question. You have among others the following options:
Regards
Stephan