Ejemplo n.º 1
0
def doConfigRollBack(module, prompt, answer):
    host = module.params['host']
    server = module.params['serverip']
    username = module.params['serverusername']
    password = module.params['serverpassword']
    protocol = module.params['protocol'].lower()
    rcPath = module.params['rcpath']
    configType = module.params['configType']
    confPath = rcPath
    retVal = ''

    command = "copy " + protocol + " " + protocol + "://"
    command = command + username + "@" + server + "/" + confPath
    command = command + " " + configType + " vrf management\n"
    cnos.debugOutput(command + "\n")
    # cnos.checkForFirstTimeAccess(module, command, 'yes/no', 'yes')
    cmd = []
    if(protocol == "scp"):
        scp_cmd1 = [{'command': command, 'prompt': 'timeout:', 'answer': '0'}]
        scp_cmd2 = [{'command': '\n', 'prompt': 'Password:'******'answer': password}]
        cmd.extend(scp_cmd1)
        cmd.extend(scp_cmd2)
        if(configType == 'startup-config'):
            scp_cmd3 = [{'command': 'y', 'prompt': None, 'answer': None}]
            cmd.extend(scp_cmd3)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif(protocol == "sftp"):
        sftp_cmd = [{'command': command, 'prompt': 'Password:'******'answer': password}]
        cmd.extend(sftp_cmd)
        # cnos.debugOutput(configType + "\n")
        if(configType == 'startup-config'):
            sftp_cmd2 = [{'command': 'y', 'prompt': None, 'answer': None}]
            cmd.extend(sftp_cmd2)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif(protocol == "ftp"):
        ftp_cmd = [{'command': command, 'prompt': 'Password:'******'answer': password}]
        cmd.extend(ftp_cmd)
        if(configType == 'startup-config'):
            ftp_cmd2 = [{'command': 'y', 'prompt': None, 'answer': None}]
            cmd.extend(ftp_cmd2)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif(protocol == "tftp"):
        command = "copy " + protocol + " " + protocol
        command = command + "://" + server + "/" + confPath
        command = command + " " + configType + " vrf management\n"
        cnos.debugOutput(command)
        tftp_cmd = [{'command': command, 'prompt': None, 'answer': None}]
        cmd.extend(tftp_cmd)
        if(configType == 'startup-config'):
            tftp_cmd2 = [{'command': 'y', 'prompt': None, 'answer': None}]
            cmd.extend(tftp_cmd2)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    else:
        return "Error-110"

    return retVal
Ejemplo n.º 2
0
def doImageDownload(module, prompt, answer):
    protocol = module.params['protocol'].lower()
    server = module.params['serverip']
    imgPath = module.params['imgpath']
    imgType = module.params['imgtype']
    username = module.params['serverusername']
    password = module.params['serverpassword']
    retVal = ''
    command = "copy " + protocol + " " + protocol + "://" + username + "@"
    command = command + server + "/" + imgPath + " system-image "
    command = command + imgType + " vrf management"
    cmd = []
    if(protocol == "scp"):
        prompt = ['timeout', 'Confirm download operation', 'Password',
                  'Do you want to change that to the standby image']
        answer = ['240', 'y', password, 'y']
        scp_cmd = [{'command': command, 'prompt': prompt, 'answer': answer,
                    'check_all': True}]
        cmd.extend(scp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif(protocol == "sftp"):
        prompt = ['Confirm download operation', 'Password',
                  'Do you want to change that to the standby image']
        answer = ['y', password, 'y']
        sftp_cmd = [{'command': command, 'prompt': prompt, 'answer': answer,
                     'check_all': True}]
        cmd.extend(sftp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif(protocol == "ftp"):
        prompt = ['Confirm download operation', 'Password',
                  'Do you want to change that to the standby image']
        answer = ['y', password, 'y']
        ftp_cmd = [{'command': command, 'prompt': prompt, 'answer': answer,
                    'check_all': True}]
        cmd.extend(ftp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif(protocol == "tftp"):
        command = "copy " + protocol + " " + protocol + "://" + server
        command = command + "/" + imgPath + " system-image " + imgType
        command = command + + " vrf management"
        prompt = ['Confirm download operation',
                  'Do you want to change that to the standby image']
        answer = ['y', 'y']
        tftp_cmd = [{'command': command, 'prompt': prompt, 'answer': answer,
                     'check_all': True}]
        cmd.extend(tftp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    else:
        return "Error-110"

    return retVal
def checkVlanNameNotAssigned(module, prompt, answer):
    retVal = "ok"
    vlanId = module.params['vlanArg1']
    vlanName = module.params['vlanArg3']
    command = "show vlan id " + vlanId
    cmd = [{'command': command, 'prompt': None, 'answer': None}]
    retVal = str(cnos.run_cnos_commands(module, cmd))
    if (retVal.find('Error') != -1):
        command = "display vlan id " + vlanId
        retVal = str(cnos.run_cnos_commands(module, cmd))
    if (retVal.find(vlanName) != -1):
        return "Nok"
    else:
        return "ok"
Ejemplo n.º 4
0
def main():
    module = AnsibleModule(argument_spec=dict(
        outputfile=dict(required=True),
        host=dict(required=False),
        username=dict(required=False),
        password=dict(required=False, no_log=True),
        enablePassword=dict(required=False, no_log=True),
    ),
                           supports_check_mode=False)

    command = 'show running-config'
    outputfile = module.params['outputfile']
    output = ''
    cmd = [{'command': command, 'prompt': None, 'answer': None}]
    output = output + str(cnos.run_cnos_commands(module, cmd))
    # Save it into the file
    file = open(outputfile, "a")
    file.write(output)
    file.close()

    errorMsg = cnos.checkOutputForError(output)
    if (errorMsg is None):
        module.exit_json(changed=True,
                         msg="Running Configuration saved in file ")
    else:
        module.fail_json(msg=errorMsg)
Ejemplo n.º 5
0
def main():
    module = AnsibleModule(argument_spec=dict(
        outputfile=dict(required=True),
        host=dict(required=False),
        username=dict(required=False),
        password=dict(required=False, no_log=True),
        enablePassword=dict(required=False, no_log=True),
        deviceType=dict(required=True),
    ),
                           supports_check_mode=False)

    command = 'write erase'
    outputfile = module.params['outputfile']
    output = ''
    cmd = [{'command': command, 'prompt': '[n]', 'answer': 'y'}]
    output = output + str(cnos.run_cnos_commands(module, cmd))

    # Save it into the file
    file = open(outputfile, "a")
    file.write(output)
    file.close()

    errorMsg = cnos.checkOutputForError(output)
    if (errorMsg is None):
        module.exit_json(
            changed=True,
            msg="Switch Startup Config is Reset to Factory settings")
    else:
        module.fail_json(msg=errorMsg)
Ejemplo n.º 6
0
def portChannelConfig(module, prompt, answer):
    retVal = ''
    command = ''
    portChArg1 = module.params['interfaceArg1']
    portChArg2 = module.params['interfaceArg2']
    portChArg3 = module.params['interfaceArg3']
    if(portChArg1 == "port-channel" and prompt == "(config)#"):
        command = command + portChArg1 + " load-balance ethernet "
        if(portChArg2 == "destination-ip" or
           portChArg2 == "destination-mac" or
           portChArg2 == "destination-port" or
           portChArg2 == "source-dest-ip" or
           portChArg2 == "source-dest-mac" or
           portChArg2 == "source-dest-port" or
           portChArg2 == "source-interface" or
           portChArg2 == "source-ip" or
           portChArg2 == "source-mac" or
           portChArg2 == "source-port"):

            # debugOutput(portChArg2)
            command = command + portChArg2 + " "
            if(portChArg3 is None):
                command = command + ""
            elif(portChArg3 == "source-interface"):
                command = command + portChArg3
                cmd = [{'command': command, 'prompt': None, 'answer': None}]
                retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
            else:
                retVal = "Error-231"
                return retVal
        else:
            retVal = "Error-232"
            return retVal
def main():
    module = AnsibleModule(
        argument_spec=dict(
            outputfile=dict(required=True),
            host=dict(required=False),
            username=dict(required=False),
            password=dict(required=False, no_log=True),
            enablePassword=dict(required=False, no_log=True),
            deviceType=dict(required=True),),
        supports_check_mode=False)

    command = 'reload'
    outputfile = module.params['outputfile']
    output = ''
    cmd = [{'command': command, 'prompt': 'reboot system? (y/n): ',
            'answer': 'y'}]
    output = output + str(cnos.run_cnos_commands(module, cmd))

    # Save it into the file
    file = open(outputfile, "a")
    file.write(output)
    file.close()

    errorMsg = cnos.checkOutputForError(output)
    if(errorMsg in "Device Response Timed out"):
        module.exit_json(changed=True,
                         msg="Device is Reloading. Please wait...")
    else:
        module.fail_json(msg=errorMsg)
Ejemplo n.º 8
0
def main():
    module = AnsibleModule(argument_spec=dict(
        clicommand=dict(required=True),
        outputfile=dict(required=True),
        condition=dict(required=True),
        flag=dict(required=True),
        host=dict(required=False),
        deviceType=dict(required=True),
        username=dict(required=False),
        password=dict(required=False, no_log=True),
        enablePassword=dict(required=False, no_log=True),
    ),
                           supports_check_mode=False)

    condition = module.params['condition']
    flag = module.params['flag']
    cliCommand = module.params['clicommand']
    outputfile = module.params['outputfile']
    output = ''
    if (condition is None or condition != flag):
        module.exit_json(changed=True, msg="Command Skipped for this switch")
        return ''
    # Send the CLi command
    cmd = [{'command': cliCommand, 'prompt': None, 'answer': None}]
    output = output + str(cnos.run_cnos_commands(module, cmd))
    # Write to memory
    save_cmd = [{'command': 'save', 'prompt': None, 'answer': None}]
    cmd.extend(save_cmd)
    output = output + str(cnos.run_cnos_commands(module, cmd))

    # Save it into the file
    path = outputfile.rsplit('/', 1)
    # cnos.debugOutput(path[0])
    if not os.path.exists(path[0]):
        os.makedirs(path[0])
    file = open(outputfile, "a")
    file.write(output)
    file.close()

    # Logic to check when changes occur or not
    errorMsg = cnos.checkOutputForError(output)
    if (errorMsg is None):
        module.exit_json(changed=True,
                         msg="CLI Command executed and results saved in file ")
    else:
        module.fail_json(msg=errorMsg)
Ejemplo n.º 9
0
def main():
    module = AnsibleModule(argument_spec=dict(
        commandfile=dict(required=True),
        outputfile=dict(required=True),
        condition=dict(required=True),
        flag=dict(required=True),
        host=dict(required=False),
        deviceType=dict(required=True),
        username=dict(required=False),
        password=dict(required=False, no_log=True),
        enablePassword=dict(required=False, no_log=True),
    ),
                           supports_check_mode=False)

    condition = module.params['condition']
    flag = module.params['flag']
    commandfile = module.params['commandfile']
    outputfile = module.params['outputfile']

    output = ''
    if (condition is None or condition != flag):
        module.exit_json(changed=True, msg="Template Skipped for this switch")
        return " "
    # Send commands one by one
    f = open(commandfile, "r")
    cmd = []
    for line in f:
        # Omit the comment lines in template file
        if not line.startswith("#"):
            # cnos.debugOutput(line)
            command = line.strip()
            inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
            cmd.extend(inner_cmd)
    # Write to memory
    save_cmd = [{'command': 'save', 'prompt': None, 'answer': None}]
    cmd.extend(save_cmd)
    output = output + str(cnos.run_cnos_commands(module, cmd))
    # Write output to file
    path = outputfile.rsplit('/', 1)
    # cnos.debugOutput(path[0])
    if not os.path.exists(path[0]):
        os.makedirs(path[0])
    file = open(outputfile, "a")
    file.write(output)
    file.close()

    # Logic to check when changes occur or not
    errorMsg = cnos.checkOutputForError(output)
    if (errorMsg is None):
        module.exit_json(changed=True, msg="Template Applied")
    else:
        module.fail_json(msg=errorMsg)
def vlanAccessMapConfig(module, cmd):
    retVal = ''
    # Wait time to get response from server
    command = ''
    vlanArg3 = module.params['vlanArg3']
    vlanArg4 = module.params['vlanArg4']
    vlanArg5 = module.params['vlanArg5']
    deviceType = module.params['deviceType']
    if (vlanArg3 == "action"):
        command = command + vlanArg3 + ' '
        value = cnos.checkSanityofVariable(deviceType, "vlan_accessmap_action",
                                           vlanArg4)
        if (value == "ok"):
            command = command + vlanArg4
        else:
            retVal = "Error-135"
            return retVal
    elif (vlanArg3 == "match"):
        command = command + vlanArg3 + ' '
        if (vlanArg4 == "ip" or vlanArg4 == "mac"):
            command = command + vlanArg4 + ' address '
            value = cnos.checkSanityofVariable(deviceType,
                                               "vlan_access_map_name",
                                               vlanArg5)
            if (value == "ok"):
                command = command + vlanArg5
            else:
                retVal = "Error-136"
                return retVal
        else:
            retVal = "Error-137"
            return retVal
    elif (vlanArg3 == "statistics"):
        command = vlanArg3 + " per-entry"
    else:
        retVal = "Error-138"
        return retVal

    inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
    cmd.extend(inner_cmd)
    retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    # debugOutput(command)
    return retVal
Ejemplo n.º 11
0
def vlagConfig(module, prompt, answer):

    retVal = ''
    # vlag config command happens here.
    command = 'vlag '

    vlagArg1 = module.params['vlagArg1']
    vlagArg2 = module.params['vlagArg2']
    vlagArg3 = module.params['vlagArg3']
    vlagArg4 = module.params['vlagArg4']
    deviceType = module.params['deviceType']

    if (vlagArg1 == "enable"):
        # debugOutput("enable")
        command = command + vlagArg1 + " "

    elif (vlagArg1 == "auto-recovery"):
        # debugOutput("auto-recovery")
        command = command + vlagArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "vlag_auto_recovery",
                                           vlagArg2)
        if (value == "ok"):
            command = command + vlagArg2
        else:
            retVal = "Error-160"
            return retVal

    elif (vlagArg1 == "config-consistency"):
        # debugOutput("config-consistency")
        command = command + vlagArg1 + " "
        value = cnos.checkSanityofVariable(deviceType,
                                           "vlag_config_consistency", vlagArg2)
        if (value == "ok"):
            command = command + vlagArg2
        else:
            retVal = "Error-161"
            return retVal

    elif (vlagArg1 == "isl"):
        # debugOutput("isl")
        command = command + vlagArg1 + " port-channel "
        value = cnos.checkSanityofVariable(deviceType, "vlag_port_aggregation",
                                           vlagArg2)
        if (value == "ok"):
            command = command + vlagArg2
        else:
            retVal = "Error-162"
            return retVal

    elif (vlagArg1 == "mac-address-table"):
        # debugOutput("mac-address-table")
        command = command + vlagArg1 + " refresh"

    elif (vlagArg1 == "peer-gateway"):
        # debugOutput("peer-gateway")
        command = command + vlagArg1 + " "

    elif (vlagArg1 == "priority"):
        # debugOutput("priority")
        command = command + vlagArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "vlag_priority",
                                           vlagArg2)
        if (value == "ok"):
            command = command + vlagArg2
        else:
            retVal = "Error-163"
            return retVal

    elif (vlagArg1 == "startup-delay"):
        # debugOutput("startup-delay")
        command = command + vlagArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "vlag_startup_delay",
                                           vlagArg2)
        if (value == "ok"):
            command = command + vlagArg2
        else:
            retVal = "Error-164"
            return retVal

    elif (vlagArg1 == "tier-id"):
        # debugOutput("tier-id")
        command = command + vlagArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "vlag_tier_id",
                                           vlagArg2)
        if (value == "ok"):
            command = command + vlagArg2
        else:
            retVal = "Error-165"
            return retVal

    elif (vlagArg1 == "vrrp"):
        # debugOutput("vrrp")
        command = command + vlagArg1 + " active"

    elif (vlagArg1 == "instance"):
        # debugOutput("instance")
        command = command + vlagArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "vlag_instance",
                                           vlagArg2)
        if (value == "ok"):
            command = command + vlagArg2
            if (vlagArg3 is not None):
                command = command + " port-channel "
                value = cnos.checkSanityofVariable(deviceType,
                                                   "vlag_port_aggregation",
                                                   vlagArg3)
                if (value == "ok"):
                    command = command + vlagArg3
                else:
                    retVal = "Error-162"
                    return retVal
            else:
                command = command + " enable "
        else:
            retVal = "Error-166"
            return retVal

    elif (vlagArg1 == "hlthchk"):
        # debugOutput("hlthchk")
        command = command + vlagArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "vlag_hlthchk_options",
                                           vlagArg2)
        if (value == "ok"):
            if (vlagArg2 == "keepalive-attempts"):
                value = cnos.checkSanityofVariable(deviceType,
                                                   "vlag_keepalive_attempts",
                                                   vlagArg3)
                if (value == "ok"):
                    command = command + vlagArg2 + " " + vlagArg3
                else:
                    retVal = "Error-167"
                    return retVal
            elif (vlagArg2 == "keepalive-interval"):
                value = cnos.checkSanityofVariable(deviceType,
                                                   "vlag_keepalive_interval",
                                                   vlagArg3)
                if (value == "ok"):
                    command = command + vlagArg2 + " " + vlagArg3
                else:
                    retVal = "Error-168"
                    return retVal
            elif (vlagArg2 == "retry-interval"):
                value = cnos.checkSanityofVariable(deviceType,
                                                   "vlag_retry_interval",
                                                   vlagArg3)
                if (value == "ok"):
                    command = command + vlagArg2 + " " + vlagArg3
                else:
                    retVal = "Error-169"
                    return retVal
            elif (vlagArg2 == "peer-ip"):
                # Here I am not taking care of IPV6 option.
                value = cnos.checkSanityofVariable(deviceType, "vlag_peerip",
                                                   vlagArg3)
                if (value == "ok"):
                    command = command + vlagArg2 + " " + vlagArg3
                    if (vlagArg4 is not None):
                        value = cnos.checkSanityofVariable(
                            deviceType, "vlag_peerip_vrf", vlagArg4)
                        if (value == "ok"):
                            command = command + " vrf " + vlagArg4
                        else:
                            retVal = "Error-170"
                            return retVal
        else:
            retVal = "Error-171"
            return retVal

    else:
        retVal = "Error-172"
        return retVal

    # debugOutput(command)
    cmd = [{'command': command, 'prompt': None, 'answer': None}]
    retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    return retVal
Ejemplo n.º 12
0
def bgpConfig(module, cmd, prompt, answer):
    retVal = ''
    command = ''
    bgpArg1 = module.params['bgpArg1']
    bgpArg2 = module.params['bgpArg2']
    bgpArg3 = module.params['bgpArg3']
    bgpArg4 = module.params['bgpArg4']
    bgpArg5 = module.params['bgpArg5']
    bgpArg6 = module.params['bgpArg6']
    bgpArg7 = module.params['bgpArg7']
    bgpArg8 = module.params['bgpArg8']
    asNum = module.params['asNum']
    deviceType = module.params['deviceType']
    # cnos.debugOutput(bgpArg1)
    if(bgpArg1 == "address-family"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_address_family", bgpArg2)
        if(value == "ok"):
            command = command + bgpArg2 + " " + "unicast \n"
            # debugOutput(command)
            inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
            cmd.extend(inner_cmd)
            retVal = retVal + bgpAFConfig(module, cmd, prompt, answer)
            return retVal
        else:
            retVal = "Error-178"
            return retVal

    elif(bgpArg1 == "bestpath"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " "
        if(bgpArg2 == "always-compare-med"):
            # debugOutput(bgpArg2)
            command = command + bgpArg2
        elif(bgpArg2 == "compare-confed-aspath"):
            # debugOutput(bgpArg2)
            command = command + bgpArg2
        elif(bgpArg2 == "compare-routerid"):
            # debugOutput(bgpArg2)
            command = command + bgpArg2
        elif(bgpArg2 == "dont-compare-originator-id"):
            # debugOutput(bgpArg2)
            command = command + bgpArg2
        elif(bgpArg2 == "tie-break-on-age"):
            # debugOutput(bgpArg2)
            command = command + bgpArg2
        elif(bgpArg2 == "as-path"):
            # debugOutput(bgpArg2)
            command = command + bgpArg2 + " "
            if(bgpArg3 == "ignore" or bgpArg3 == "multipath-relax"):
                command = command + bgpArg3
            else:
                retVal = "Error-179"
                return retVal
        elif(bgpArg2 == "med"):
            # debugOutput(bgpArg2)
            command = command + bgpArg2 + " "
            if(bgpArg3 == "confed" or
               bgpArg3 == "missing-as-worst" or
               bgpArg3 == "non-deterministic" or
               bgpArg3 == "remove-recv-med" or
               bgpArg3 == "remove-send-med"):
                command = command + bgpArg3
            else:
                retVal = "Error-180"
                return retVal
        else:
            retVal = "Error-181"
            return retVal

    elif(bgpArg1 == "bgp"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " as-local-count "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_bgp_local_count", bgpArg2)
        if(value == "ok"):
            command = command + bgpArg2
        else:
            retVal = "Error-182"
            return retVal

    elif(bgpArg1 == "cluster-id"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "cluster_id_as_ip", bgpArg2)
        if(value == "ok"):
            command = command + bgpArg2
        else:
            value = cnos.checkSanityofVariable(
                deviceType, "cluster_id_as_number", bgpArg2)
            if(value == "ok"):
                command = command + bgpArg2
            else:
                retVal = "Error-183"
                return retVal

    elif(bgpArg1 == "confederation"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " "
        if(bgpArg2 == "identifier"):
            value = cnos.checkSanityofVariable(
                deviceType, "confederation_identifier", bgpArg3)
            if(value == "ok"):
                command = command + bgpArg2 + " " + bgpArg3 + "\n"
            else:
                retVal = "Error-184"
                return retVal
        elif(bgpArg2 == "peers"):
            value = cnos.checkSanityofVariable(
                deviceType, "confederation_peers_as", bgpArg3)
            if(value == "ok"):
                command = command + bgpArg2 + " " + bgpArg3
            else:
                retVal = "Error-185"
                return retVal
        else:
            retVal = "Error-186"
            return retVal

    elif(bgpArg1 == "enforce-first-as"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1

    elif(bgpArg1 == "fast-external-failover"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1

    elif(bgpArg1 == "graceful-restart"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " stalepath-time "
        value = cnos.checkSanityofVariable(
            deviceType, "stalepath_delay_value", bgpArg2)
        if(value == "ok"):
            command = command + bgpArg2
        else:
            retVal = "Error-187"
            return retVal

    elif(bgpArg1 == "graceful-restart-helper"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1

    elif(bgpArg1 == "log-neighbor-changes"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1

    elif(bgpArg1 == "maxas-limit"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "maxas_limit_as", bgpArg2)
        if(value == "ok"):
            command = command + bgpArg2
        else:
            retVal = "Error-188"
            return retVal

    elif(bgpArg1 == "neighbor"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "neighbor_ipaddress", bgpArg2)
        if(value == "ok"):
            command = command + bgpArg2
            if(bgpArg3 is not None):
                command = command + " remote-as "
                value = cnos.checkSanityofVariable(
                    deviceType, "neighbor_as", bgpArg3)
                if(value == "ok"):
                    # debugOutput(command)
                    command = command + bgpArg3
                    inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
                    cmd.extend(inner_cmd)
                    retVal = retVal + bgpNeighborConfig(module, cmd, prompt, answer)
                    return retVal
        else:
            retVal = "Error-189"
            return retVal

    elif(bgpArg1 == "router-id"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "router_id", bgpArg2)
        if(value == "ok"):
            command = command + bgpArg2
        else:
            retVal = "Error-190"
            return retVal

    elif(bgpArg1 == "shutdown"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1

    elif(bgpArg1 == "synchronization"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1

    elif(bgpArg1 == "timers"):
        # cnos.debugOutput(bgpArg3)
        command = command + bgpArg1 + " bgp "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_keepalive_interval", bgpArg2)
        if(value == "ok"):
            command = command + bgpArg2
        else:
            retVal = "Error-191"
            return retVal
        if(bgpArg3 is not None):
            value = cnos.checkSanityofVariable(deviceType, "bgp_holdtime", bgpArg3)
            if(value == "ok"):
                command = command + " " + bgpArg3
            else:
                retVal = "Error-192"
                return retVal
        else:
            retVal = "Error-192"
            return retVal

    elif(bgpArg1 == "vrf"):
        # debugOutput(bgpArg1)
        command = command + bgpArg1 + " default"
    else:
        # debugOutput(bgpArg1)
        retVal = "Error-192"
        return retVal
    # debugOutput(command)
    inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
    cmd.extend(inner_cmd)
    retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    command = "exit \n"
    # debugOutput(command)
    return retVal
Ejemplo n.º 13
0
def bgpAFConfig(module, cmd, prompt, answer):
    retVal = ''
    command = ''
    bgpAFArg1 = module.params['bgpArg3']
    bgpAFArg2 = module.params['bgpArg4']
    bgpAFArg3 = module.params['bgpArg5']
    bgpAFArg4 = module.params['bgpArg6']
    bgpAFArg5 = module.params['bgpArg7']
    bgpAFArg6 = module.params['bgpArg8']
    deviceType = module.params['deviceType']
    if(bgpAFArg1 == "aggregate-address"):
        command = command + bgpAFArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_aggregate_prefix", bgpAFArg2)
        if(value == "ok"):
            if(bgpAFArg2 is None):
                command = command.strip()
            elif(bgpAFArg2 == "as-set" or bgpAFArg2 == "summary-only"):
                command = command + bgpAFArg2 + " "
                if((bgpAFArg3 is not None) and (bgpAFArg2 == "as-set")):
                    command = command + "summary-only"
            else:
                retVal = "Error-297"
                return retVal
        else:
            retVal = "Error-296"
            return retVal

    elif(bgpAFArg1 == "client-to-client"):
        command = command + bgpAFArg1 + " reflection "

    elif(bgpAFArg1 == "dampening"):
        command = command + bgpAFArg1 + " "
        if(bgpAFArg2 == "route-map"):
            command = command + bgpAFArg2 + " "
            value = cnos.checkSanityofVariable(
                deviceType, "addrfamily_routemap_name", bgpAFArg3)
            if(value == "ok"):
                command = command + bgpAFArg3
            else:
                retVal = "Error-196"
                return retVal
        elif(bgpAFArg2 is not None):
            value = cnos.checkSanityofVariable(
                deviceType, "reachability_half_life", bgpAFArg2)
            if(value == "ok"):
                command = command + bgpAFArg2 + " "
                if(bgpAFArg3 is not None):
                    value1 = cnos.checkSanityofVariable(
                        deviceType, "start_reuse_route_value", bgpAFArg3)
                    value2 = cnos.checkSanityofVariable(
                        deviceType, "start_suppress_route_value", bgpAFArg4)
                    value3 = cnos.checkSanityofVariable(
                        deviceType, "max_duration_to_suppress_route",
                        bgpAFArg5)
                    if(value1 == "ok" and value2 == "ok" and value3 == "ok"):
                        command = command + bgpAFArg3 + " " + bgpAFArg4 + \
                            " " + bgpAFArg5 + " "
                        if(bgpAFArg6 is not None):
                            value = cnos.checkSanityofVariable(
                                deviceType,
                                "unreachability_halftime_for_penalty",
                                bgpAFArg6)
                            if(value == "ok"):
                                command = command + bgpAFArg6
                    else:
                        retVal = "Error-295"
                        return retVal
                else:
                    command = command.strip()
            else:
                retVal = "Error-294"
                return retVal

    elif(bgpAFArg1 == "distance"):
        command = command + bgpAFArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "distance_external_AS", bgpAFArg2)
        if(value == "ok"):
            command = command + bgpAFArg2 + " "
            value = cnos.checkSanityofVariable(
                deviceType, "distance_internal_AS", bgpAFArg3)
            if(value == "ok"):
                command = command + bgpAFArg3 + " "
                value = cnos.checkSanityofVariable(
                    deviceType, "distance_local_routes", bgpAFArg4)
                if(value == "ok"):
                    command = command + bgpAFArg4
                else:
                    retVal = "Error-291"
                    return retVal
            else:
                retVal = "Error-292"
                return retVal
        else:
            retVal = "Error-293"
            return retVal

    elif(bgpAFArg1 == "maximum-paths"):
        command = command + bgpAFArg1 + " "
        value = cnos.checkSanityofVariable(deviceType, "maxpath_option", bgpAFArg2)
        if(value == "ok"):
            command = command + bgpAFArg2 + " "
            value = cnos.checkSanityofVariable(
                deviceType, "maxpath_numbers", bgpAFArg3)
            if(value == "ok"):
                command = command + bgpAFArg3
            else:
                retVal = "Error-199"
                return retVal
        else:
            retVal = "Error-290"
            return retVal

    elif(bgpAFArg1 == "network"):
        command = command + bgpAFArg1 + " "
        if(bgpAFArg2 == "synchronization"):
            command = command + bgpAFArg2
        else:
            value = cnos.checkSanityofVariable(
                deviceType, "network_ip_prefix_with_mask", bgpAFArg2)
            if(value == "ok"):
                command = command + bgpAFArg2 + " "
                if(bgpAFArg3 is not None and bgpAFArg3 == "backdoor"):
                    command = command + bgpAFArg3
                elif(bgpAFArg3 is not None and bgpAFArg3 == "route-map"):
                    command = command + bgpAFArg3
                    value = cnos.checkSanityofVariable(
                        deviceType, "addrfamily_routemap_name", bgpAFArg4)
                    if(value == "ok"):
                        command = command + bgpAFArg4 + " "
                        if(bgpAFArg5 is not None and bgpAFArg5 == "backdoor"):
                            command = command + bgpAFArg5
                        else:
                            retVal = "Error-298"
                            return retVal
                    else:
                        retVal = "Error-196"
                        return retVal
                else:
                    command = command.strip()
            else:
                value = cnos.checkSanityofVariable(
                    deviceType, "network_ip_prefix_value", bgpAFArg2)
                if(value == "ok"):
                    command = command + bgpAFArg2 + " "
                    if(bgpAFArg3 is not None and bgpAFArg3 == "backdoor"):
                        command = command + bgpAFArg3
                    elif(bgpAFArg3 is not None and bgpAFArg3 == "route-map"):
                        command = command + bgpAFArg3
                        value = cnos.checkSanityofVariable(
                            deviceType, "addrfamily_routemap_name", bgpAFArg4)
                        if(value == "ok"):
                            command = command + bgpAFArg4 + " "
                            if(bgpAFArg5 is not None and
                                    bgpAFArg5 == "backdoor"):
                                command = command + bgpAFArg5
                            else:
                                retVal = "Error-298"
                                return retVal
                        else:
                            retVal = "Error-196"
                            return retVal
                    elif(bgpAFArg3 is not None and bgpAFArg3 == "mask"):
                        command = command + bgpAFArg3
                        value = cnos.checkSanityofVariable(
                            deviceType, "network_ip_prefix_mask", bgpAFArg4)
                        if(value == "ok"):
                            command = command + bgpAFArg4 + " "
                        else:
                            retVal = "Error-299"
                            return retVal
                    else:
                        command = command.strip()
                else:
                    retVal = "Error-300"
                    return retVal

    elif(bgpAFArg1 == "nexthop"):
        command = command + bgpAFArg1 + " trigger-delay critical "
        value = cnos.checkSanityofVariable(
            deviceType, "nexthop_crtitical_delay", bgpAFArg2)
        if(value == "ok"):
            command = command + bgpAFArg2 + " "
            value = cnos.checkSanityofVariable(
                deviceType, "nexthop_noncrtitical_delay", bgpAFArg3)
            if(value == "ok"):
                command = command + bgpAFArg3 + " "
            else:
                retVal = "Error-198"
                return retVal
        else:
            retVal = "Error-197"
            return retVal

    elif(bgpAFArg1 == "redistribute"):
        command = command + bgpAFArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "addrfamily_redistribute_option", bgpAFArg2)
        if(value == "ok"):
            if(bgpAFArg2 is not None):
                command = command + bgpAFArg2 + " " + "route-map "
                value = cnos.checkSanityofVariable(
                    deviceType, "addrfamily_routemap_name", bgpAFArg3)
                if(value == "ok"):
                    command = command + bgpAFArg3
                else:
                    retVal = "Error-196"
                    return retVal
        else:
            retVal = "Error-195"
            return retVal

    elif(bgpAFArg1 == "save" or bgpAFArg1 == "synchronization"):
        command = command + bgpAFArg1

    else:
        retVal = "Error-194"
        return retVal
    # debugOutput(command)
    inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
    cmd.extend(inner_cmd)
    retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    command = "exit \n"
    return retVal
Ejemplo n.º 14
0
def bgpNeighborAFConfig(module, cmd, prompt, answer):
    retVal = ''
    command = ''
    bgpNeighborAFArg1 = module.params['bgpArg6']
    bgpNeighborAFArg2 = module.params['bgpArg7']
    bgpNeighborAFArg3 = module.params['bgpArg8']
    deviceType = module.params['deviceType']
    if(bgpNeighborAFArg1 == "allowas-in"):
        command = command + bgpNeighborAFArg1 + " "
        if(bgpNeighborAFArg2 is not None):
            value = cnos.checkSanityofVariable(
                deviceType, "bgp_neighbor_af_occurances", bgpNeighborAFArg2)
            if(value == "ok"):
                command = command + bgpNeighborAFArg2
            else:
                retVal = "Error-325"
                return retVal
        else:
            command = command

    elif(bgpNeighborAFArg1 == "default-originate"):
        command = command + bgpNeighborAFArg1 + " "
        if(bgpNeighborAFArg2 is not None and bgpNeighborAFArg2 == "route-map"):
            command = command + bgpNeighborAFArg2 + " "
            value = cnos.checkSanityofVariable(
                deviceType, "bgp_neighbor_af_routemap", bgpNeighborAFArg2)
            if(value == "ok"):
                command = command + bgpNeighborAFArg3
            else:
                retVal = "Error-324"
                return retVal

    elif(bgpNeighborAFArg1 == "filter-list"):
        command = command + bgpNeighborAFArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_af_filtername", bgpNeighborAFArg2)
        if(value == "ok"):
            command = command + bgpNeighborAFArg2 + " "
            if(bgpNeighborAFArg3 == "in" or bgpNeighborAFArg3 == "out"):
                command = command + bgpNeighborAFArg3
            else:
                retVal = "Error-323"
                return retVal
        else:
            retVal = "Error-322"
            return retVal

    elif(bgpNeighborAFArg1 == "maximum-prefix"):
        command = command + bgpNeighborAFArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_af_maxprefix", bgpNeighborAFArg2)
        if(value == "ok"):
            command = command + bgpNeighborAFArg2 + " "
            if(bgpNeighborAFArg3 is not None):
                command = command + bgpNeighborAFArg3
            else:
                command = command.strip()
        else:
            retVal = "Error-326"
            return retVal

    elif(bgpNeighborAFArg1 == "next-hop-self"):
        command = command + bgpNeighborAFArg1

    elif(bgpNeighborAFArg1 == "prefix-list"):
        command = command + bgpNeighborAFArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_af_prefixname", bgpNeighborAFArg2)
        if(value == "ok"):
            command = command + bgpNeighborAFArg2 + " "
            if(bgpNeighborAFArg3 == "in" or bgpNeighborAFArg3 == "out"):
                command = command + bgpNeighborAFArg3
            else:
                retVal = "Error-321"
                return retVal
        else:
            retVal = "Error-320"
            return retVal

    elif(bgpNeighborAFArg1 == "route-map"):
        command = command + bgpNeighborAFArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_af_routemap", bgpNeighborAFArg2)
        if(value == "ok"):
            command = command + bgpNeighborAFArg2
        else:
            retVal = "Error-319"
            return retVal
    elif(bgpNeighborAFArg1 == "route-reflector-client"):
        command = command + bgpNeighborAFArg1

    elif(bgpNeighborAFArg1 == "send-community"):
        command = command + bgpNeighborAFArg1 + " "
        if(bgpNeighborAFArg2 is not None and bgpNeighborAFArg2 == "extended"):
            command = command + bgpNeighborAFArg2
        else:
            command = command

    elif(bgpNeighborAFArg1 == "soft-reconfiguration"):
        command = command + bgpNeighborAFArg1 + " inbound"

    elif(bgpNeighborAFArg1 == "unsuppress-map"):
        command = command + bgpNeighborAFArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_af_routemap", bgpNeighborAFArg2)
        if(value == "ok"):
            command = command + bgpNeighborAFArg2
        else:
            retVal = "Error-318"
            return retVal

    else:
        retVal = "Error-317"
        return retVal

    # debugOutput(command)
    inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
    cmd.extend(inner_cmd)
    retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    return retVal
Ejemplo n.º 15
0
def bgpNeighborConfig(module, cmd, prompt, answer):
    retVal = ''
    command = ''
    bgpNeighborArg1 = module.params['bgpArg4']
    bgpNeighborArg2 = module.params['bgpArg5']
    bgpNeighborArg3 = module.params['bgpArg6']
    bgpNeighborArg4 = module.params['bgpArg7']
    bgpNeighborArg5 = module.params['bgpArg8']
    deviceType = module.params['deviceType']

    if(bgpNeighborArg1 == "address-family"):
        command = command + bgpNeighborArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_address_family", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2 + " unicast"
            # debugOutput(command)
            inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
            cmd.extend(inner_cmd)
            retVal = retVal + bgpNeighborAFConfig(module, cmd, '(config-router-neighbor-af)#', answer)
            return retVal
        else:
            retVal = "Error-316"
            return retVal

    elif(bgpNeighborArg1 == "advertisement-interval"):
        command = command + bgpNeighborArg1

    elif(bgpNeighborArg1 == "bfd"):
        command = command + bgpNeighborArg1 + " "
        if(bgpNeighborArg2 is not None and bgpNeighborArg2 == "mutihop"):
            command = command + bgpNeighborArg2
        else:
            command = command

    elif(bgpNeighborArg1 == "connection-retry-time"):
        command = command + bgpNeighborArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_connection_retrytime", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2
        else:
            retVal = "Error-315"
            return retVal

    elif(bgpNeighborArg1 == "description"):
        command = command + bgpNeighborArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_description", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2
        else:
            retVal = "Error-314"
            return retVal

    elif(bgpNeighborArg1 == "disallow-infinite-holdtime"):
        command = command + bgpNeighborArg1

    elif(bgpNeighborArg1 == "dont-capability-negotiate"):
        command = command + bgpNeighborArg1

    elif(bgpNeighborArg1 == "dynamic-capability"):
        command = command + bgpNeighborArg1

    elif(bgpNeighborArg1 == "ebgp-multihop"):
        command = command + bgpNeighborArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_maxhopcount", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2
        else:
            retVal = "Error-313"
            return retVal

    elif(bgpNeighborArg1 == "interface"):
        command = command + bgpNeighborArg1 + " "
        # TBD

    elif(bgpNeighborArg1 == "local-as"):
        command = command + bgpNeighborArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_local_as", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2 + " "
            if(bgpNeighborArg3 is not None and
                    bgpNeighborArg3 == "no-prepend"):
                command = command + bgpNeighborArg3 + " "
                if(bgpNeighborArg4 is not None and
                        bgpNeighborArg4 == "replace-as"):
                    command = command + bgpNeighborArg4 + " "
                    if(bgpNeighborArg5 is not None and
                            bgpNeighborArg5 == "dual-as"):
                        command = command + bgpNeighborArg5
                    else:
                        command = command.strip()
                else:
                    command = command.strip()
            else:
                command = command.strip()
        else:
            retVal = "Error-312"
            return retVal

    elif(bgpNeighborArg1 == "maximum-peers"):
        command = command + bgpNeighborArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_maxpeers", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2
        else:
            retVal = "Error-311"
            return retVal

    elif(bgpNeighborArg1 == "password"):
        command = command + bgpNeighborArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_password", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2
        else:
            retVal = "Error-310"
            return retVal

    elif(bgpNeighborArg1 == "remove-private-AS"):
        command = command + bgpNeighborArg1

    elif(bgpNeighborArg1 == "timers"):
        command = command + bgpNeighborArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_timers_Keepalive", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2 + " "
            value = cnos.checkSanityofVariable(
                deviceType, "bgp_neighbor_timers_holdtime", bgpNeighborArg3)
            if(value == "ok"):
                command = command + bgpNeighborArg3
            else:
                retVal = "Error-309"
                return retVal
        else:
            retVal = "Error-308"
            return retVal

    elif(bgpNeighborArg1 == "transport"):
        command = command + bgpNeighborArg1 + " connection-mode passive "

    elif(bgpNeighborArg1 == "ttl-security"):
        command = command + bgpNeighborArg1 + " hops "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_ttl_hops", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2
        else:
            retVal = "Error-307"
            return retVal

    elif(bgpNeighborArg1 == "update-source"):
        command = command + bgpNeighborArg1 + " "
        if(bgpNeighborArg2 is not None):
            value = cnos.checkSanityofVariable(
                deviceType, "bgp_neighbor_update_options", bgpNeighborArg2)
            if(value == "ok"):
                command = command + bgpNeighborArg2 + " "
                if(bgpNeighborArg2 == "ethernet"):
                    value = cnos.checkSanityofVariable(
                        deviceType, "bgp_neighbor_update_ethernet",
                        bgpNeighborArg3)
                    if(value == "ok"):
                        command = command + bgpNeighborArg3
                    else:
                        retVal = "Error-304"
                        return retVal
                elif(bgpNeighborArg2 == "loopback"):
                    value = cnos.checkSanityofVariable(
                        deviceType, "bgp_neighbor_update_loopback",
                        bgpNeighborArg3)
                    if(value == "ok"):
                        command = command + bgpNeighborArg3
                    else:
                        retVal = "Error-305"
                        return retVal
                else:
                    value = cnos.checkSanityofVariable(
                        deviceType, "bgp_neighbor_update_vlan",
                        bgpNeighborArg3)
                    if(value == "ok"):
                        command = command + bgpNeighborArg3
                    else:
                        retVal = "Error-306"
                        return retVal
            else:
                command = command + bgpNeighborArg2
        else:
            retVal = "Error-303"
            return retVal

    elif(bgpNeighborArg1 == "weight"):
        command = command + bgpNeighborArg1 + " "
        value = cnos.checkSanityofVariable(
            deviceType, "bgp_neighbor_weight", bgpNeighborArg2)
        if(value == "ok"):
            command = command + bgpNeighborArg2
        else:
            retVal = "Error-302"
            return retVal

    else:
        retVal = "Error-301"
        return retVal

    # debugOutput(command)
    inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
    cmd.extend(inner_cmd)
    retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    command = "exit \n"
    return retVal
def vlanConfig(module, prompt, answer):

    retVal = ''
    # Wait time to get response from server
    vlanArg1 = module.params['vlanArg1']
    vlanArg2 = module.params['vlanArg2']
    vlanArg3 = module.params['vlanArg3']
    vlanArg4 = module.params['vlanArg4']
    vlanArg5 = module.params['vlanArg5']
    deviceType = module.params['deviceType']
    # vlan config command happens here.
    command = 'vlan '

    if (vlanArg1 == "access-map"):
        # debugOutput("access-map ")
        command = command + vlanArg1 + ' '
        value = cnos.checkSanityofVariable(deviceType, "vlan_access_map_name",
                                           vlanArg2)
        if (value == "ok"):
            command = command + vlanArg2
            # debugOutput(command)
            cmd = [{'command': command, 'prompt': None, 'answer': None}]
            retVal = retVal + vlanAccessMapConfig(module, cmd)
            return retVal
        else:
            retVal = "Error-130"
            return retVal

    elif (vlanArg1 == "dot1q"):
        # debugOutput("dot1q")
        command = command + vlanArg1 + " tag native "
        if (vlanArg2 is not None):
            value = cnos.checkSanityofVariable(deviceType, "vlan_dot1q_tag",
                                               vlanArg2)
            if (value == "ok"):
                command = command + vlanArg2
            else:
                retVal = "Error-131"
                return retVal

    elif (vlanArg1 == "filter"):
        # debugOutput( "filter")
        command = command + vlanArg1 + " "
        if (vlanArg2 is not None):
            value = cnos.checkSanityofVariable(deviceType, "vlan_filter_name",
                                               vlanArg2)
            if (value == "ok"):
                command = command + vlanArg2 + " vlan-list "
                value = cnos.checkSanityofVariable(deviceType, "vlan_id",
                                                   vlanArg3)
                if (value == "ok"):
                    command = command + vlanArg3
                else:
                    value = cnos.checkSanityofVariable(deviceType,
                                                       "vlan_id_range",
                                                       vlanArg3)
                    if (value == "ok"):
                        command = command + vlanArg3
                    else:
                        retVal = "Error-133"
                    return retVal
            else:
                retVal = "Error-132"
                return retVal

    else:
        value = cnos.checkSanityofVariable(deviceType, "vlan_id", vlanArg1)
        if (value == "ok"):
            retVal = createVlan(module, '(config-vlan)#', None)
            return retVal
        else:
            value = cnos.checkSanityofVariable(deviceType, "vlan_id_range",
                                               vlanArg1)
            if (value == "ok"):
                retVal = createVlan(module, '(config-vlan)#', None)
                return retVal
            retVal = "Error-133"
            return retVal

    # debugOutput(command)
    cmd = [{'command': command, 'prompt': None, 'answer': None}]
    retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    return retVal
def createVlan(module, prompt, answer):

    # vlan config command happens here. It creates if not present
    vlanArg1 = module.params['vlanArg1']
    vlanArg2 = module.params['vlanArg2']
    vlanArg3 = module.params['vlanArg3']
    vlanArg4 = module.params['vlanArg4']
    vlanArg5 = module.params['vlanArg5']
    deviceType = module.params['deviceType']
    retVal = ''
    command = 'vlan ' + vlanArg1
    # debugOutput(command)
    cmd = [{'command': command, 'prompt': None, 'answer': None}]
    command = ""
    if (vlanArg2 == "name"):
        # debugOutput("name")
        command = vlanArg2 + " "
        value = cnos.checkSanityofVariable(deviceType, "vlan_name", vlanArg3)
        if (value == "ok"):
            value = checkVlanNameNotAssigned(module, prompt, answer)
            if (value == "ok"):
                command = command + vlanArg3
            else:
                retVal = retVal + 'VLAN Name is already assigned \n'
                command = "\n"
        else:
            retVal = "Error-139"
            return retVal
    elif (vlanArg2 == "flood"):
        # debugOutput("flood")
        command = vlanArg2 + " "
        value = cnos.checkSanityofVariable(deviceType, "vlan_flood", vlanArg3)
        if (value == "ok"):
            command = command + vlanArg3
        else:
            retVal = "Error-140"
            return retVal

    elif (vlanArg2 == "state"):
        # debugOutput("state")
        command = vlanArg2 + " "
        value = cnos.checkSanityofVariable(deviceType, "vlan_state", vlanArg3)
        if (value == "ok"):
            command = command + vlanArg3
        else:
            retVal = "Error-141"
            return retVal

    elif (vlanArg2 == "ip"):
        # debugOutput("ip")
        command = vlanArg2 + " igmp snooping "
        # debugOutput("vlanArg3")
        if (vlanArg3 is None or vlanArg3 == ""):
            # debugOutput("None or empty")
            command = command.strip()
        elif (vlanArg3 == "fast-leave"):
            # debugOutput("fast-leave")
            command = command + vlanArg3

        elif (vlanArg3 == "last-member-query-interval"):
            # debugOutput("last-member-query-interval")
            command = command + vlanArg3 + " "
            value = cnos.checkSanityofVariable(
                deviceType, "vlan_last_member_query_interval", vlanArg4)
            if (value == "ok"):
                command = command + vlanArg4
            else:
                retVal = "Error-142"
                return retVal

        elif (vlanArg3 == "querier"):
            # debugOutput("querier")
            command = command + vlanArg3 + " "
            value = cnos.checkSanityofVariable(deviceType, "vlan_querier",
                                               vlanArg4)
            if (value == "ok"):
                command = command + vlanArg4
            else:
                retVal = "Error-143"
                return retVal
        elif (vlanArg3 == "querier-timeout"):
            # debugOutput("querier-timeout")
            command = command + vlanArg3 + " "
            value = cnos.checkSanityofVariable(deviceType,
                                               "vlan_querier_timeout",
                                               vlanArg4)
            if (value == "ok"):
                command = command + vlanArg4
            else:
                retVal = "Error-144"
                return retVal
        elif (vlanArg3 == "query-interval"):
            # debugOutput("query-interval")
            command = command + vlanArg3 + " "
            value = cnos.checkSanityofVariable(deviceType,
                                               "vlan_query_interval", vlanArg4)
            if (value == "ok"):
                command = command + vlanArg4
            else:
                retVal = "Error-145"
                return retVal
        elif (vlanArg3 == "query-max-response-time"):
            # debugOutput("query-max-response-time")
            command = command + vlanArg3 + " "
            value = cnos.checkSanityofVariable(deviceType,
                                               "vlan_query_max_response_time",
                                               vlanArg4)
            if (value == "ok"):
                command = command + vlanArg4
            else:
                retVal = "Error-146"
                return retVal
        elif (vlanArg3 == "report-suppression"):
            # debugOutput("report-suppression")
            command = command + vlanArg3

        elif (vlanArg3 == "robustness-variable"):
            # debugOutput("robustness-variable")
            command = command + vlanArg3 + " "
            value = cnos.checkSanityofVariable(deviceType,
                                               "vlan_startup_query_count",
                                               vlanArg4)
            if (value == "ok"):
                command = command + vlanArg4
            else:
                retVal = "Error-148"
                return retVal
        elif (vlanArg3 == "startup-query-interval"):
            # debugOutput("startup-query-interval")
            command = command + vlanArg3 + " "
            value = cnos.checkSanityofVariable(deviceType,
                                               "vlan_startup_query_interval",
                                               vlanArg4)
            if (value == "ok"):
                command = command + vlanArg4
            else:
                retVal = "Error-149"
                return retVal
        elif (vlanArg3 == "static-group"):
            retVal = "Error-102"
            return retVal
        elif (vlanArg3 == "version"):
            # debugOutput("version")
            command = command + vlanArg3 + " "
            value = cnos.checkSanityofVariable(deviceType,
                                               "vlan_snooping_version",
                                               vlanArg4)
            if (value == "ok"):
                command = command + vlanArg4
            else:
                retVal = "Error-150"
                return retVal
        elif (vlanArg3 == "mrouter"):
            # debugOutput("mrouter")
            command = command + vlanArg3 + " interface "
            if (vlanArg4 == "ethernet"):
                command = command + vlanArg4 + " "
                value = cnos.checkSanityofVariable(deviceType,
                                                   "vlan_ethernet_interface",
                                                   vlanArg5)
                if (value == "ok"):
                    command = command + vlanArg5
                else:
                    retVal = "Error-151"
                    return retVal
            elif (vlanArg4 == "port-aggregation"):
                command = command + vlanArg4 + " "
                value = cnos.checkSanityofVariable(deviceType,
                                                   "vlan_portagg_number",
                                                   vlanArg5)
                if (value == "ok"):
                    command = command + vlanArg5
                else:
                    retVal = "Error-152"
                    return retVal
            else:
                retVal = "Error-153"
                return retVal
        else:
            command = command + vlanArg3

    else:
        retVal = "Error-154"
        return retVal
    inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
    cmd.extend(inner_cmd)
    retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    # debugOutput(command)
    return retVal