cancel
Showing results for 
Search instead for 
Did you mean: 

Create mLAG Port with XMC Python

Create mLAG Port with XMC Python

cslayton
New Contributor

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()

15 REPLIES 15

Ludovico_Steven
Extreme Employee

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.

Miguel-Angel_RO
Valued Contributor II

It’s too early for me 95e448731e8f445d887eaf69db18a4c0_1f60a.png

StephanH
Valued Contributor III

Hey Mig,

 

I have also suggested this above 7bc740d41c8d452e83ca7cc5e738d199_1f609.png

Regards Stephan

Miguel-Angel_RO
Valued Contributor II

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

StephanH
Valued Contributor III

Hello cslyton,

Regarding your original question. You have among others the following options:

  1. Either you select both partners (switches) at the beginning of your workflow that belong to your MLAG and use variables to make sure that the Config fits once for the left and once for the right (you can use the emc_vars to query which switch is currently configured).
  2. Or you can start the workflow with the first switch and then change the IP to the second switch and continue working with them. (How this works is described here: https://community.extremenetworks.com/extrememanagement-230297/set-switch-ip-at-runtime-in-workflow-...)

Regards

Stephan

 

 

Regards Stephan
GTM-P2G8KFN