Exemplo n.º 1
0
def mapsenable(pol, al, ml):
    """
        enable MAPS with policy         pol
                         actions list   al
                         email list     ml
                         
        -- this function will enable MAPS only if you want to
        change the policy use mapspolicy()
        
    """

    m = anturlar.Maps()
    m.enable(pol)
    m.actions(al)
    m.email_cfg(ml)

    return 0
def capture_switch_info(extend_name="", fid=128):
    """
    
    
    """

    si = anturlar.SwitchInfo()
    mi = anturlar.Maps()
    fi = anturlar.FlowV()
    fcr = anturlar.FcrInfo()

    vdx = si.nos_check()
    switch_ip = si.ipaddress()
    switch_cp_ips = si.cp_ipaddrs_get()

    license_list = si.getLicense()
    ls_list = si.ls()
    first_ls = si.ls_now()
    switch_id = si.switch_id()
    fid_now = si.currentFID()
    try:
        theswitch_name = si.switch_name()
    except IndexError:
        theswitch_name = "unknown"
        pass
    chassis_name = si.chassisname()
    director_pizza = si.director()
    vf_enabled = si.vf_enabled()
    sw_type = si.switch_type()
    base_sw = si.base_check()
    sim_ports = si.sim_ports()
    ex_ports = fcr.all_ex_ports()
    fcr_state = si.fcr_enabled()
    ports_and_ls = si.all_ports_fc_only()
    psw_reset_value = "YES"
    xisl_st_per_ls = si.allow_xisl()
    maps_policy_sum = mi.get_policies()
    maps_non_dflt_policy = mi.get_nondflt_policies()

    flow_per_ls = fi.flow_names()
    blades = si.blades()
    deflt_switch = si.default_switch()
    # sfp_info             = si.sfp_info()
    maps_email_cfg = mi.get_email_cfg()
    maps_actions = mi.get_actions()
    logical_groups = mi.logicalgroup_count()
    relay_server_info = mi.get_relay_server_info()
    credit_recov_info = mi.credit_recovery()
    dns_info = mi.dns_config_info()

    ###################################################################################################################
    ###################################################################################################################
    ####
    #### print the variables for review
    ####
    ###################################################################################################################
    ###################################################################################################################

    print("\n\n\n")
    print("SWITCH IP         :  %s  " % switch_ip)
    print("SWITCH NAME       :  %s  " % theswitch_name)
    # print("SWITCH DOMAIN     :  %s  " % domain_list)
    print("LS LIST           :  %s  " % ls_list)
    print("DEFAULT SWITCH    :  %s  " % deflt_switch)
    print("BASE SWITCH       :  %s  " % base_sw)
    print("EX_PORTS          :  %s  " % ex_ports)  ######################NEW
    print("VF SETTING        :  %s  " % vf_enabled)
    print("SWITCH TYPE       :  %s  " % sw_type)
    print("TIMEOUT VALUE     :  0   ")
    print("RESET PASSWORD    :  %s " % psw_reset_value)
    print("FCR ENABLED       :  %s " % fcr_state)
    print("BLADES            :  %s " % blades)
    print("LICENSE LIST      :  %s  " % license_list)

    #######################################################################################################################
    #######################################################################################################################
    #######################################################################################################################
    ####
    ####  Write to the file
    ####
    #######################################################################################################################
    #######################################################################################################################
    #######################################################################################################################

    # f = "%s%s%s" % ("logs/Switch_Info_cudc", switch_ip, "_%s.txt" % extend_name)
    f = "%s%s%s" % ("/home/runfromhere/logs/Switch_Info_cudc", switch_ip,
                    "_%s.txt" % extend_name)
    header = "%s%s%s%s" % ("\nSwitch_info_for_playback CAPTURE FILE \n", \
                           "", "", "==============================\n")
    ff = liabhar.FileStuff(f, 'w+b')  #### open the log file for writing
    ff.write(header)
    ###################################################################################################################
    ff.write("SWITCH IP                :  %s  \n" % switch_ip)
    ff.write("LS LIST                  :  %s  \n" % ls_list)
    ff.write("DEFAULT SWITCH           :  %s  \n" % deflt_switch)
    ff.write("BASE SWITCH              :  %s  \n" % base_sw)
    ff.write("EX_PORTS                 :  %s  \n" % ex_ports)
    ff.write("SWITCH NAME              :  %s  \n" % theswitch_name)
    ff.write("CHASSIS NAME             :  %s  \n" % chassis_name)
    ff.write("DIRECTOR STATUS          :  %s  \n" % director_pizza)
    ff.write("VF SETTING               :  %s  \n" % vf_enabled)
    ff.write("SWITCH TYPE              :  %s  \n" % sw_type)
    ff.write("TIMEOUT VALUE            :  0   \n")
    ff.write("RESET PASSWORD           :  %s  \n" % psw_reset_value)
    ff.write("FCR ENABLED              :  %s  \n" % fcr_state)
    ff.write("Ports                    :  %s  \n" % ports_and_ls)
    ff.write("SIM PORTS                :  %s  \n" % sim_ports)
    ff.write("Blades                   :  %s  \n" % blades)

    ff.write("LICENSE LIST             :  %s  \n" % license_list)
    #ff.write("SFP  INFO                :  %s  \n" % sfpinfo)
    ff.write("=" * 80)
    ff.write("\n")
    ff.write("MAPS POLICIES            :  %s  \n" % maps_policy_sum)
    ff.write("MAPS NON DFLT POLICIES   :  %s  \n" % maps_non_dflt_policy)
    ff.write("EMAIL CFG                :  %s  \n" % maps_email_cfg)
    ff.write("MAPS ACTIONS             :  %s  \n" % maps_actions)
    ff.write("LOGICAL GROUPS           :  %s  \n" % logical_groups)
    ff.write("RELAY SERVER HOST IP     :  %s  \n" % relay_server_info)
    ff.write("CREDIT RECOVERY INFO     :  %s  \n" % credit_recov_info)
    ff.write("DNS CONFIG INFO          :  %s  \n" % dns_info)
    ff.write("=" * 80)
    ff.write("\n")
    ff.write("FLOW CONFIGURATION       :  %s  \n" % flow_per_ls)
    ff.write("\n" * 2)
    ff.close()

    # cons_out             = anturlar.fos_cmd("setcontext %s " % fid_now)

    return (True)
Exemplo n.º 3
0
def fabric_switch_config_show():
    """
       document how this works here 
       
       1. Retreive a list of all of the switches in the FID passed at start of the test
       2. get Flow and MAPS basic setup information
       3. write to     logs/fabric_info_switch.txt
       
       
    """

    cons_out = anturlar.fos_cmd("")
    swtch = anturlar.SwitchInfo()
    fab = anturlar.FabricInfo()
    fab_ip_list = fab.ipv4_list()
    this_fid = swtch.currentFID()

    ###############################################################################
    ###############################################################################
    ####
    ####  write to the file the list of IP addresses that data will be captured for
    ####
    ###############################################################################
    ###############################################################################
    fname = "%s%s" % ("logs/fabric_info_logs/fabric_info_switch", ".txt"
                      )  #### %s string  %d number
    ff = liabhar.FileStuff(fname, 'w+b')
    ff.write(
        "#############################################################\r\n")
    ff.write(
        "#############################################################\r\n")
    ff.write("\r\n")
    for ip in fab_ip_list:
        ff.write(ip)
        ff.write("\r\n")
    ff.write(
        "#############################################################\r\n")
    ff.write(
        "#############################################################\r\n")
    ff.write(
        "#############################################################\r\n")
    ff.write(
        "#############################################################\r\n\r\n\r\n"
    )
    ff.close()

    m_info = anturlar.Maps()
    f_info = anturlar.FlowV()
    maps_config = anturlar.fos_cmd("mapsconfig --show")
    firmware_ver = check_version()
    s_name = m_info.switch_name()
    s_type = m_info.switch_type()
    ls_list = m_info.ls()
    switch_id = m_info.switch_id()
    ls_domain = m_info.ls_and_domain()
    chass_name = m_info.chassisname()
    vf_state = m_info.vf_enabled()

    ff = liabhar.FileStuff(fname, 'a+b')
    ff.write("Seed switch Info       \n")
    ff.write(
        "---------------------------------------------------------------------------------\n"
    )
    ff.write("Switch ipv4                     :    %s \r\n" % ip)
    ff.write("Chassis Name                :    %s \r\n" % chass_name)
    ff.write("Firmware version         :    %s \r\n" % firmware_ver)
    ff.write("Switch Name                  :    %s \r\n" % s_name)
    ff.write("Switch Type                    :    %s \r\n" % s_type)
    ff.write("VF State                          :    %s \r\n" % vf_state)
    ff.write("Logical Switches            :    %s \r\n" % ls_list)
    ff.write("Switch ID                         :    %s \r\n" % switch_id)
    ff.write("ls and domain                :    %s \r\n" % ls_domain)

    ###############################################################################
    ###############################################################################
    ####
    ####    loop through each switch in the fabric and collect and write the MAPS and Flow Info
    ####
    ###############################################################################
    for ip in fab_ip_list:
        tnn = anturlar.connect_tel_noparse(ip, 'root', 'password')
        cons_out = anturlar.fos_cmd("setcontext %s " % this_fid)

        m_info = anturlar.Maps()
        f_info = anturlar.FlowV()

        maps_config = anturlar.fos_cmd("mapsconfig --show")
        maps_policy_list = m_info.get_policies()
        maps_active_policy = m_info.get_active_policy()
        non_dflt_policy = m_info.get_nondflt_policies()
        flow_names = f_info.flow_names()
        flows_nondflt = f_info.get_nondflt_flows()
        flows_active = f_info.get_active_flows()
        #flow_cnfg                   = f_info.flow_config()
        flow_details = f_info.get_flow_details()

        anturlar.close_tel()
        #######
        #######  remove line switchname FID ?? root>
        #######
        m_no_root = s_name + ":FID" + str(this_fid) + ":root>"
        m = maps_config.replace(m_no_root, '')
        mc = m.lstrip()  #### remove leading white space
        #######
        #######  remove line switchname FID ?? root>
        #######
        ####
        ####  leave as capturing data for only one FID at a time
        ####  have a switch for all fid data
        ####
        ####
        seperator(ff, ip)

        ff.write(
            "---------------------------------------------------------------------\r\n"
        )
        #ff.write("MAPS config         :    %s \r\n" % maps_config)
        ff.write(
            "MAPS config                         :\r\n")  ## maps config header
        ff.write(mc)  ## write maps config
        ff.write(
            "\n---------------------------------------------------------------------\r\n"
        )
        ff.write("MAPS Policy List                :    %s \r\n" %
                 maps_policy_list)
        ff.write("MAPS Active Policy              :    %s \r\n" %
                 maps_active_policy)
        ff.write("MAPS Non Default Policy         :    %s \r\n" %
                 non_dflt_policy)
        ff.write(
            "---------------------------------------------------------------------\r\n"
        )
        ff.write("FLOW Names list                 :    %s \r\n" % flow_names)
        ff.write("FLOW non dflt Flows             :    %s \r\n" %
                 flows_nondflt)
        ff.write("FLOWs Active                    :    %s \r\n" % flows_active)
        ff.write("FLOW Details                    :    %s \r\n" % flow_details)
        ff.write(
            "---------------------------------------------------------------------\r\n"
        )

    ff = liabhar.FileStuff(fname, 'a+b')
    ff.write(
        "#####################################################################\r\n"
    )
    ff.write(
        "#####################################################################\r\n"
    )
    ff.write("##########\r\n")
    ff.write(
        "##########     FABRIC SWITCHES INFO                        ##########\r\n"
    )
    ff.write("##########\r\n")
    ff.write(
        "#####################################################################\r\n"
    )
    for ip in fab_ip_list:
        tnnn = anturlar.connect_tel_noparse(ip, 'root', 'password')
        firmware_ver = check_version()
        chass_name = m_info.chassisname()
        sf = "{0:18}   {1:25}   {2:25}"
        print(sf.format(str(ip), str(chass_name), str(firmware_ver)), file=ff)
    ff.write("\r\n")
    ff.write(
        "#####################################################################\r\n"
    )
    ff.write(
        "#####################################################################\r\n"
    )
    ff.write(
        "#####################################################################\r\n"
    )
    ff.write(
        "#####################################################################\r\n"
    )
    ff.write(
        "#####################################################################\r\n"
    )
    ff.close()
    print("\n")
    print("#" * 120)
    print(
        "\nFind the results in     logs/fabric_info_logs/fabric_info_switchtxt\n"
    )
    print("#" * 120)
    print("\n" * 10)

    return (True)
Exemplo n.º 4
0
def switch_config_show():
    """
      get information for a switch for each FID
      
      
      
    """

    cons_out = anturlar.fos_cmd("")
    swtch = anturlar.SwitchInfo()
    fab = anturlar.FabricInfo()
    #fab_ip_list = fab.ipv4_list()
    ip = swtch.ipaddress()
    this_fid = swtch.currentFID()

    fname = "%s%s" % ("logs/Switch_info_per_FID_", ".txt"
                      )  #### %s string  %d number
    ff = liabhar.FileStuff(fname, 'w+b')
    ff.write(
        "#############################################################\r\n")
    ff.close()

    tnn = anturlar.connect_tel_noparse(ip, 'root', 'password')
    ff = liabhar.FileStuff(fname, 'a+b')

    ls_list_fids = swtch.ls()
    m_info = anturlar.Maps()
    f_info = anturlar.FlowV()
    firmware_ver = check_version()

    s_type = m_info.switch_type()
    ls_list = m_info.ls()
    switch_id = m_info.switch_id()
    ls_domain = m_info.ls_and_domain()
    chass_name = m_info.chassisname()
    vf_state = m_info.vf_enabled()

    ff.write("Switch ipv4              :    %s \r\n" % ip)
    ff.write("Chassis Name             :    %s \r\n" % chass_name)
    ff.write("Firmware version         :    %s \r\n" % firmware_ver)
    #ff.write("Switch Name              :    %s \r\n" % s_name)
    ff.write("Switch Type              :    %s \r\n" % s_type)
    ff.write("VF State                 :    %s \r\n" % vf_state)
    ff.write("Logical Switches         :    %s \r\n" % ls_list)
    ff.write("Switch ID                :    %s \r\n" % switch_id)
    ff.write("ls and domain            :    %s \r\n" % ls_domain)

    print(ls_list_fids)
    for i in ls_list_fids:
        print(i)

    print("\n" * 10)
    for ls in ls_list_fids:

        cons_out = anturlar.fos_cmd("setcontext %s " % ls)
        s_name = m_info.switch_name()
        maps_policy_list = m_info.get_policies()
        maps_active_policy = m_info.get_active_policy()
        non_dflt_policy = m_info.get_nondflt_policies()
        flow_names = f_info.flow_names()
        flows_nondflt = f_info.get_nondflt_flows()
        flows_active = f_info.get_active_flows()
        flow_details = f_info.get_flow_details()
        #flow_cnfg           = f_info.flow_config()
        maps_config = anturlar.fos_cmd("mapsconfig --show")
        #######
        #######  remove line switchname FID ?? root>
        #######
        print("\n" * 4)
        print(maps_config)
        print("\n" * 4)
        m_no_root = s_name + ":FID" + str(ls) + ":root>"
        #m_no_name = maps_config.replace(s_name ,'')
        #m_no_fid = m_no_name.replace(str(this_fid), '')
        m = maps_config.replace(m_no_root, '')
        print("\n" * 4)
        print(m)
        print("\n" * 4)
        #######
        #######  remove line switchname FID ?? root>
        #######

        seperator_switch(ff, ls)
        ff.write("Switch Name              :    %s \r\n" % s_name)
        ff.write(
            "---------------------------------------------------------------------\r\n"
        )
        #ff.write("MAPS config         :    %s \r\n" % maps_config)
        ff.write("MAPS config              :   \r\n\r\n  %s \r\n" %
                 m)  ## maps config
        ff.write(
            "---------------------------------------------------------------------\r\n"
        )
        ff.write("MAPS Policy List         :    %s \r\n" % maps_policy_list)
        ff.write("MAPS Active Policy       :    %s \r\n" % maps_active_policy)
        ff.write("MAPS Non Default Policy  :    %s \r\n" % non_dflt_policy)
        ff.write(
            "---------------------------------------------------------------------\r\n"
        )
        ff.write("FLOW Names list          :    %s \r\n" % flow_names)
        ff.write("FLOW non dflt Flows      :    %s \r\n" % flows_nondflt)
        ff.write("FLOWs Active             :    %s \r\n" % flows_active)
        ff.write("FLOW Details             :    %s \r\n" % flow_details)
        ff.write(
            "---------------------------------------------------------------------\r\n"
        )

    ff.close()
    anturlar.close_tel()
Exemplo n.º 5
0
def main():

    global tn
    
#######################################################################################################################
####
#### 
####
#######################################################################################################################
    pa = parse_args(sys.argv)
    print(pa)
    #print(pa.chassis_name)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    #print(pa.firmware)
    print(pa.cmdprompt)
    print(pa.fid)
    print("@"*40)
    #sys.exit()
    
###################################################################################################################
###################################################################################################################
####
#### if user enter ip address then get the chassisname from the
####   SwitchMatrix file
#### then get the info from the SwitchMatrix file using the Chassis Name
#### 
#### 
####
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = console_info_from_ip(pa.ipaddr)
        
    cons_info         = console_info(pa.chassis_name)
    console_ip        = cons_info[0]
    console_port      = cons_info[1]
    console_ip_bkup   = cons_info[2]
    console_port_bkup = cons_info[3]
    power_pole_info   = pwr_pole_info(pa.chassis_name)    
    usr_pass          = get_user_and_pass(pa.chassis_name)
    user_name         = usr_pass[0]
    usr_psswd         = usr_pass[1]
    ipaddr_switch     = get_ip_from_file(pa.chassis_name)
 
 

    tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
    
    print("\r\n\r\nLICENSE ADD TO SWITCH \r\n\r\n")
    print(ipaddr_switch)
    
    en = anturlar.Maps()
    fab_stuff = anturlar.FabricInfo(en.currentFID())
    print("$$$$$$$$$$$$$$")
    print(fab_stuff)

    cons_out = anturlar.fos_cmd("setcontext %s" % pa.fid)
    cons_out = anturlar.fos_cmd("switchshow")
    
    #fabmems = fab_stuff.fabric_members()
    myzone_info = fab_stuff.zone_info(1)
    try:
        myzone = myzone_info[0][1]
    except IndexError:
        myzone = "NewZone"
    
    liabhar.JustSleep(10)
    cons_out = anturlar.fos_cmd("switchshow")
   
   
    add_zones(myzone)
    
    
    print(cons_out)
    
    anturlar.close_tel()
    dt = liabhar.dateTimeStuff()
    date_is = dt.current()
    print(date_is)
Exemplo n.º 6
0
def capture_switch_info(extend_name="", fid=128):
    """
    capture switch info to compare 
    
    """
    
    si = anturlar.SwitchInfo()
    mi = anturlar.Maps()
    fi = anturlar.FlowV()
    
    switch_ip            = si.ipaddress()
    switch_cp_ips        = si.cp_ipaddrs_get()
    license_list         = si.getLicense()
    ls_list              = si.ls()
    first_ls             = si.ls_now()
    switch_id            = si.switch_id()
    fid_now              = si.currentFID()
    chassis_name         = si.chassisname()
    director_pizza       = si.director()
    vf_enabled           = si.vf_enabled()
    sw_type              = si.switch_type()
    base_sw              = si.base_check()
    blades               = si.blades()
    deflt_switch         = si.default_switch()
    dns_info             = mi.dns_config_info()    
    
#######################################################################################################################
#######################################################################################################################
#######################################################################################################################
####
####  Write to the file
####
#######################################################################################################################
#######################################################################################################################
#######################################################################################################################
    
    f = "%s%s%s"%("logs/Switch_Info_cudc",switch_ip,"_%s.txt" % extend_name)
    header = "%s%s%s%s" % ("\nSwitch_info_for_playback CAPTURE FILE \n",\
                           "","", "==============================\n")  
    ff = liabhar.FileStuff(f, 'w+b')  #### open the log file for writing
    ff.write(header)
    ###################################################################################################################
   
    ff.write("SWITCH IP                 :  %s  \n" % switch_ip)
    ff.write("CP IP                        :  %s  \n"  % switch_cp_ips)
    ff.write("LICENSE LIST            :  %s  \n" % license_list)
    ff.write("LS LIST                     :  %s  \n" % ls_list)
    ff.write("LS Test Start            :  %s  \n"  % first_ls)
    ff.write("Switch ID                  :   %s  \n"  %  switch_id)
    ff.write("Current FID             :  %s  \n"  %  fid_now)
    ff.write("CHASSIS NAME         :  %s  \n" % chassis_name)
    ff.write("DIRECTOR STATUS     :  %s  \n" % director_pizza)
    ff.write("VF SETTING              :  %s  \n" % vf_enabled)
    ff.write("SWITCH TYPE            :  %s  \n" % sw_type)
    ff.write("BASE SWITCH             :  %s  \n" % base_sw)
    ff.write("Blades                       :  %s  \n" % blades) 
    ff.write("DEFAULT SWITCH        :  %s  \n" % deflt_switch)
    ff.write("DNS CONFIG INFO     :  %s  \n" % dns_info)

 
    for l in ls_list:
        cons_out             = anturlar.fos_cmd("setcontext %s " % l )
 
        try:
            theswitch_name   = si.switch_name()
        except IndexError:
            theswitch_name   = "unknown"
            pass
    
        sim_ports            = si.sim_ports()
        ports_and_ls        = si.all_ports_fc_only()
        xisl_st_per_ls              = si.allow_xisl()
        maps_policy_sum       = mi.get_policies()
        maps_non_dflt_policy = mi.get_nondflt_policies()
        flow_per_ls                 = fi.flow_names()
        maps_email_cfg         = mi.get_email_cfg()
        maps_actions             = mi.get_actions()
        logical_groups            = mi.logicalgroup_count()
        relay_server_info       = mi.get_relay_server_info()
        credit_recov_info       = mi.credit_recovery()
        sfpinfo                       = si.sfp_info()

        ff.write("="*80)
        ff.write("\n")
        ff.write("="*80)
        ff.write("\n")
        ff.write("FID  %s  \n" %  l)
        ff.write("SWITCH NAME              :  %s  \n" % theswitch_name)
        ff.write("SIM PORTS                :  %s  \n" % sim_ports)
        ff.write("Ports                    :  %s  \n" % ports_and_ls)
        ff.write("XISL state               :  %s  \n"  %  xisl_st_per_ls)
        ff.write("MAPS POLICIES            :  %s  \n" % maps_policy_sum )
        ff.write("MAPS NON DFLT POLICIES   :  %s  \n" % maps_non_dflt_policy)
        ff.write("FLOW CONFIGURATION       :  %s  \n" % flow_per_ls)
        ff.write("EMAIL CFG                :  %s  \n" % maps_email_cfg)
        ff.write("MAPS ACTIONS             :  %s  \n" % maps_actions)
        ff.write("LOGICAL GROUPS           :  %s  \n" % logical_groups)
        ff.write("RELAY SERVER HOST IP     :  %s  \n" % relay_server_info)
        ff.write("CREDIT RECOVERY INFO     :  %s  \n" % credit_recov_info)
        ff.write("SFP  INFO                :  %s  \n" % sfpinfo)
        ff.write("\n")

    ff.write("=END"*20)
    ff.write("\n")
    ff.close()
    
    cons_out             = anturlar.fos_cmd("setcontext %s " % fid_now)
    
    
    return(True)
Exemplo n.º 7
0
def fabric_switch_config_show():
    
    """
       document how this works here 
       
       1. Retreive a list of all of the switches in the FID passed during start
       2. get Flow and MAPS basic setup information
       
       
       
    """
    
    cons_out = anturlar.fos_cmd("")
    swtch = anturlar.SwitchInfo()
    fab = anturlar.FabricInfo()
    fab_ip_list = fab.ipv4_list()
    this_fid = swtch.currentFID()
    fname = "%s%s" % ("logs/fabric_info_switch" ,".txt")  #### %s string  %d number
    ff = liabhar.FileStuff(fname, 'w+b')
    ff.write("#############################################################\r\n")
    ff.write("#############################################################\r\n")
    ff.write("\r\n")
    for ip in fab_ip_list:
        ff.write(ip)
        ff.write("\r\n")
    ff.write("#############################################################\r\n")
    ff.write("#############################################################\r\n")
    ff.write("#############################################################\r\n")
    ff.write("#############################################################\r\n\r\n\r\n")
    ff.close()
    
    #ff = liabhar.FileStuff(fname, 'a+b')
    #for ip in fab_ip_list:
    #    tnnn = anturlar.connect_tel_noparse(ip, 'root', 'password')
    #    firmware_ver = check_version()
    #    
    #    ip_firm_ver_pair = "%s      %s" % ( ip,firmware_ver)
    # 
    #    ff.write("\r\n")
    #    ff.write(ip_firm_ver_pair)
    #
    #ff.write("\r\n")
    #ff.write("#############################################################\r\n")
    #ff.write("#############################################################\r\n")
    #ff.write("#############################################################\r\n")
    #ff.write("#############################################################\r\n")
    #ff.write("#############################################################\r\n")
    #ff.close()
    m_info              = anturlar.Maps()
    f_info              = anturlar.FlowV()
    maps_config         = anturlar.fos_cmd("mapsconfig --show")
    firmware_ver        = check_version()
    s_name              = m_info.switch_name()
    s_type              = m_info.switch_type()
    ls_list             = m_info.ls()
    switch_id           = m_info.switch_id()
    ls_domain           = m_info.ls_and_domain()
    chass_name          = m_info.chassisname()
    vf_state            = m_info.vf_enabled()
    
    ff = liabhar.FileStuff(fname, 'a+b')
    ff.write("Switch ipv4              :    %s \r\n" % ip)
    ff.write("Chassis Name             :    %s \r\n" % chass_name)
    ff.write("Firmware version         :    %s \r\n" % firmware_ver)
    ff.write("Switch Name              :    %s \r\n" % s_name)
    ff.write("Switch Type              :    %s \r\n" % s_type)
    ff.write("VF State                 :    %s \r\n" % vf_state)
    ff.write("Logical Switches         :    %s \r\n" % ls_list)
    ff.write("Switch ID                :    %s \r\n" % switch_id)
    ff.write("ls and domain            :    %s \r\n" % ls_domain)
    
    
    for ip in fab_ip_list:
        tnn = anturlar.connect_tel_noparse(ip, 'root', 'password')
        cons_out = anturlar.fos_cmd("setcontext %s " % this_fid)
        maps_policy_list    = m_info.get_policies()
        maps_active_policy  = m_info.get_active_policy()
        non_dflt_policy     = m_info.get_nondflt_policies()
        flow_names          = f_info.flow_names()
        flows_nondflt       = f_info.get_nondflt_flows()
        flows_active        = f_info.get_active_flows()
        #flow_cnfg           = f_info.flow_config()
        flow_details        = f_info.get_flow_details()
        
        
        anturlar.close_tel()
        
        
        
                
        #######
        #######  remove line switchname FID ?? root> 
        #######
        print("\n"*4)
        print(maps_config)
        print("\n"*4)
        m_no_root = s_name + ":FID" + str(this_fid) + ":root>"
        #m_no_name = maps_config.replace(s_name ,'')
        #m_no_fid = m_no_name.replace(str(this_fid), '')
        m = maps_config.replace(m_no_root, '')
        print("\n"*4)
        print(m)
        print("\n"*4)
        #######
        #######  remove line switchname FID ?? root> 
        #######
        
####
####  leave as capturing data for only one FID at a time
####  have a switch for all fid data
####
####

        seperator(ff, ip)

        ff.write("---------------------------------------------------------------------\r\n")
        #ff.write("MAPS config         :    %s \r\n" % maps_config)
        ff.write("MAPS config              :   \r\n  %s \r\n" % m)   ## maps config
        ff.write("---------------------------------------------------------------------\r\n")       
        ff.write("MAPS Policy List         :    %s \r\n" % maps_policy_list)
        ff.write("MAPS Active Policy       :    %s \r\n" % maps_active_policy)
        ff.write("MAPS Non Default Policy  :    %s \r\n" % non_dflt_policy)
        ff.write("---------------------------------------------------------------------\r\n")
        ff.write("FLOW Names list          :    %s \r\n" % flow_names)
        ff.write("FLOW non dflt Flows      :    %s \r\n" % flows_nondflt)
        ff.write("FLOWs Active             :    %s \r\n" % flows_active)
        ff.write("FLOW Details             :    %s \r\n" % flow_details)
        ff.write("---------------------------------------------------------------------\r\n")
        
        #ff.write("FLOW CONFIG         :   \r\n   %s \r\n" % flow_cnfg)
  
    
    ff = liabhar.FileStuff(fname, 'a+b')
    ff.write("#####################################################################\r\n")
    ff.write("#####################################################################\r\n")
    ff.write("##########\r\n")
    ff.write("##########     FABRIC SWITCHES INFO                        ##########\r\n")
    ff.write("##########\r\n")
    ff.write("#####################################################################\r\n")
    #for ip in fab_ip_list:
    #    tnnn = anturlar.connect_tel_noparse(ip, 'root', 'password')
    #    firmware_ver = check_version()
    #    m_info          = anturlar.Maps()
    #    chass_name      = m_info.chassisname()
    #    
    #    ip_firm_ver_pair = "%s\t\t%s\t\t%s " % ( ip,chass_name,firmware_ver)
    # 
    #    ff.write("\r\n")
    #    ff.write(ip_firm_ver_pair)
    #
    #ff.write("\n"*5)
        
    for ip in fab_ip_list:
        tnnn = anturlar.connect_tel_noparse(ip, 'root', 'password')
        firmware_ver = check_version()
        m_info          = anturlar.Maps()
        chass_name      = m_info.chassisname()
        sf = "{0:18}   {1:25}   {2:25}"
        print(sf.format( str(ip), str(chass_name), str(firmware_ver) ), file=ff)
        
    ff.write("\r\n")
    ff.write("#####################################################################\r\n")
    ff.write("#####################################################################\r\n")
    ff.write("#####################################################################\r\n")
    ff.write("#####################################################################\r\n")
    ff.write("#####################################################################\r\n")
    ff.close()
    
    return(True)
Exemplo n.º 8
0
def tc_22_2_1_2(ftp_ip, ftp_user, ftp_pass, clear=0):
    """
    Test Case(s)   22.2.1.2.1, 22.2.1.2.2, 22.2.1.2.3
    Title:      FCR Enable/Disable
    Feature:    FCR 
    Enabling and disabling the FCR service
        
    """
    ###########################################################################
    ####  todo -
    ####
    ####   1.  pass / fail for each step of test case
    ####       make the test_result a list of list [ step_0 pass ][step_2 fail]
    ####   2.  ignore chassis rules on a pizza box
    ####   3.  configupload will be tested as the config will be reset to default and then put back down
    ####
    ###########################################################################
    ####
    ####  steps
    ####
    ####  1. Do configupload
    ####  2. Do config default
    ####  3. Default status (tc 2.1.2.3)
    ####  4. FCR Functionality Persist (tc 2.1.2.1)
    ####  5. Config EX ports
    ####  6. FCR disable with EX/VEX ports enabled
    ####  7. Put switch back to original config
    ####
    #### start the test

    test_numb = "22.2.1.2"
    test_summary = "%s    FCR" % test_numb
    header = maps_tools.format_header(test_summary)
    test_result = ""

    p = anturlar.Maps()
    cs = anturlar.configSwitch()
    si = anturlar.SwitchInfo()
    fcrinfo = anturlar.FcrInfo()
    sut_ip = p.ipaddress()
    sw_rules = p.get_rules()
    sw_status = si.__sw_basic_info__()

    ###### set up the log file info
    ##f_path = '/home/RunFromHere/logs/%s_%s' % (test_numb, sut_ip)
    ##f = open(f_path, 'w+b')
    ##f.write(bytes(header, 'UTF-8'))
    ##
    ##### configupload
    ##cfgupload_status = cofra.cfgupload(ftp_ip, ftp_user, ftp_pass, clear = 0)
    ##if "Terminated" in cfgupload_status:
    ##    print("\n"+"#"*80+"\n")
    ##    print('Could not connect to remote host. Configupload failed')
    ##    print("#"*80+"\n")
    ##    f.write(bytes(cfgupload_status, 'UTF-8'))
    ##    sys.exit()
    ##else:
    ##    f.write(bytes(cfgupload_status, 'UTF-8'))
    ##
    ##### configdefault
    ##cfgdflt = cs.config_default()

    ### Check if FCR Status is disabled (default setting)
    fcr_status = si.fcr_enabled()
    ##if fcr_status is True:
    ##    print("\n"+"*"*80+"\n")
    ##    print('FC Routing Service is still enabled. Test Failed')
    ##    print("*"*80+"\n")
    ##    f.write(bytes(fcr_status, 'UTF-8'))
    ##    sys.exit()
    ##else:
    ##    print("\n"+"*"*80+"\n")
    ##    print('FC Routing Service is disabled as it should be.')
    ##    print("*"*80+"\n")
    ##    f.write(bytes(fcr_status, 'UTF-8'))

    # FCR Functionality Persist
    if fcr_status is True:
        print('FCR IS ENABLED')
    else:
        anturlar.fos_cmd("fosconfig --enable fcr")

    #fcr_state = fcrinfo.fcr_state_persist_enabled()
    #if fcr_state == True:
    #    print('TRUE')
    #else:
    #    print("FALSE")

    ####### This should be last bit of code as it puts switch back to starting config
    #cfgdownload_status = cofra.cfgdownload(ftp_ip, ftp_user, ftp_pass, clear = 0)
    #if "Terminated" in cfgdownload_status:
    #    print("\n"+"*"*80+"\n")
    #    print('Could not connect to remote host. Configdownload failed')
    #    print("*"*80+"\n")
    #    f.write(bytes(cfgdownload_status, 'UTF-8'))
    #else:
    #    f.write(bytes(cfgdownload_status, 'UTF-8'))
    #    f.write(bytes("\n"+"*"*80+"\n", 'UTF-8'))
    #    f.write(bytes("ALL TESTS PASSED\n", 'UTF-8'))
    #    f.write(bytes("*"*80+"\n", 'UTF-8'))
    #    f.close()
    #    print("*"*80+"\n")
    #    print("\n"+"*"*80+"\n")
    #    print("ALL TESTS PASSED\n")
    #    print("*"*80+"\n")
    #    state = si.switch_state()
    #    if state == "Offline":
    #        anturlar.fos_cmd("switchenable")
    #    else:
    #        pass
    sys.exit()

    ###############################################################################
    #STEVE'S EXAMPLE
    ####################

    #p = anturlar.Maps()
    #sut_ip = p.ipaddress()
    #sw_rules = p.get_rules()

    #### set up the log file info
    #f_path = '/home/run_from_here/logs/%s_%s' % (test_numb, sut_ip)
    #
    #f = liabhar.FileStuff(f_path, 'w+b')
    #f.write(header)

    #sw_rules = str(sw_rules)
    #sw_rules = sw_rules.replace("'", "") #### remove ' from string
    #sw_rules = sw_rules.replace("[", "") #### remove open bracket
    #sw_rules = sw_rules.replace("]", "") #### remove ending bracket
    df_rules = maps_tools.maps_default_rule()

    sw_rules = sw_rules.split()
    df_rules = df_rules.split()

    count_df = len(df_rules)
    count = len(sw_rules)
    if count < count_df:
        loop_count = count
    else:
        loop_count = count_df
    i = 0
    rule_differ = 0
    while i < loop_count:
        print("\n\ncomparing switch rule with default rule ")
        print("%s      %s " % (sw_rules[i], i))
        if sw_rules[i] not in df_rules:
            rule_differ += 1
            test_result += sw_rules[i]
            test_result += ' step1'
            test_result += ' Fail\n'
            print("\nFail Fail Fail Fail\n\n")

        i += 1

    print("The number of rules that differ are %s " % rule_differ)
    print("The number of additional rules on the switch %s " %
          (count - count_df))
    print(len(sw_rules))
    print(len(df_rules))
    #f.write(bytes(header, 'UTF-8'))
    #f.write(bytes("The number of rules that differ are %s \r\n" % rule_differ, 'UTF-8')
    f.write("The number of additional rules on the switch %s \r\n" %
            (count - count_df))
    f.write("Total number of switch rules    %s  \r\n" % len(sw_rules))
    f.write("Total number of default rules   %s  \r\n" % len(df_rules))

    if test_result == "":
        test_result = "PASS"

    print("=" * 80)
    print("\n\nTEST RESULTS FOR Test Case   25.01.01.03.01 ")
    print(test_result)
    f.write(maps_tools.format_results(test_summary, test_result))

    return (test_result)