Network automation

Share your Config Push presets or discuss automation in general
SeanCTS
Posts: 60
Joined: Thu Nov 02, 2017 7:29 pm
Location: Orlando, FL

Thu May 10, 2018 2:26 pm

Works great!

Thank you for the latest update.
SeanCTS
Posts: 60
Joined: Thu Nov 02, 2017 7:29 pm
Location: Orlando, FL

Mon May 14, 2018 3:19 pm

Hmmm... still getting interaction errors. However copy/paste into console works.

Here is the script I'm running.

Code: Select all

###This Script will auto create vlans that are missing 
###Add the vlans you need to have in the newVlanArray variable by using "vlanid"="vlanName" and the script will do the rest
###BOF###
##Initialize variables

:global "physInterface" ether1;
:global "newVlanArray" {"104"="104-CHCMGMT";"116"="116-security";"152"="152-userdata";"160"="160-printers";"168"="168-voice";"176"="176-wireless"};
:global "oldVlanArray" [/interface vlan find];
:global "COUNTER1" 0;

##DO NOT CHANGE ANYTHING ELSE BELOW##
###
###
#Functions
#Create function to add all the vlans to the router

##
#Create Function to add a single vlan
:global "AddSingleVlan" do={
    /interface vlan add interface=$1 name=$2 vlan-id=$3;
    :put "VLAN $2 has been added";
}
###
:global "AddAllVlans" do={
    :foreach k,v in=$newVlanArray do={
    $AddSingleVlan $physInterface $v $k
    }

}

#Check to see if there are any vlans on router.  If not, add all vlans
#If vlans exists, check to see if each one exists and create the ones that do not

:if ([:len $oldVlanArray] < 1) do={
    :put "No Vlans are on this router";
    $AddAllVlans;
    :put "All New Vlans are now added";
} else={
    :put "VLANS exist, checking each one"
    :foreach k,v in=$newVlanArray do={
        :global newvlanid $k
        :global newvlanname $v
        :set "COUNTER1" 0
        :foreach item in=$oldVlanArray do={
            :global oldvlanname [/interface vlan get value-name=name number=$item]
            :global oldvlanid [/interface vlan get value-name=vlan-id number=$item]
            :if ($oldvlanid !=$k) do={:set "COUNTER1" ($COUNTER1 +1)}}
        :if ($COUNTER1 = [:len $oldVlanArray]) do={$AddSingleVlan $physInterface $newvlanname $newvlanid}
    }
}
:put "FINISHED ADDING VLANS"
###EOF###
User avatar
Tomas
Posts: 767
Joined: Sat Jun 25, 2016 12:33 pm

Mon May 14, 2018 8:56 pm

Found the issue, it was caused by nested blocks:

Code: Select all

{
  ... {
  }
}
Fix will be released in 1.7.2.
(going on on Tuesday or Wednesday)
SeanCTS
Posts: 60
Joined: Thu Nov 02, 2017 7:29 pm
Location: Orlando, FL

Tue May 15, 2018 2:14 am

Groovy. Thank you for your quick support. :)

Please come to Florida! I owe you lunch and drinks!
Post Reply