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

StephanH
Valued Contributor III

Hmm,

so it still remains two options cslayton, either your version is too old or the license type is wrong.

As MIG has already asked. Which version and which type (Basic, Standard, Advanced) do you use?

 

Regards

Stephan

 

 

Regards Stephan

Miguel-Angel_RO
Valued Contributor II

Sorry I crossed fingers...It is 8.5.1

Mig

StephanH
Valued Contributor III

Hello Mig,

 

is your version 8.1.5 correct or do you meen 8.5.1?

 

I can see the workflow on 8.4.4.x and 8.5.1.60 with ADV license but not an a 8.3.1.9 with Standard license.

Maybe the license is the difference if you have realy a old 8.1x.

 

Regards

Stephan

 

 

Regards Stephan

Miguel-Angel_RO
Valued Contributor II

FYI

I’m running 8.1.5

GTM-P2G8KFN