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

Miguel-Angel_RO
Valued Contributor II

cslayton,

The default Workflows are changing with the upgrades.

Extreme is adding features and new workflows.

I can export it and send it to you by email if you send me your email address by private message.

Another option is to upgrade.

Regards

 

Mig

cslayton
New Contributor

@Miguel-Angel RODRIGUEZ-GARCIA 

14692a78791a4455b1fe9b4f293320b8_26998843-5596-4798-a18c-b0b10ba79e91.png

 

Miguel-Angel_RO
Valued Contributor II

What version of XMC are you running?

Mig

cslayton
New Contributor

Thanks all for your replies!  I am new to XMC and completely missed the “workflow” section.  However, in my workflow tab I don’t see Configure ISC and MLAG Peers on EXOS. See screenshot.  I’m wondering if this is a permissions issue.

a8c767afe08541a1a7dafffcc5bdbb01_8c083382-4736-4f41-bdd0-fed1c4101a2c.png

 

PeterK
Contributor III

another way could to enable “orchestration mode” before doing portconfig. Than the switch is doing a sync by themself.

GTM-P2G8KFN