Esempio n. 1
0
def portstatus(num, result, state):
    retry = ''
    pn = result.find("%s  %s" % (num, num))
    if pn > 0:
        if result.find(state, pn, pn+55) > 0:
            logging.info(result[pn:pn+55])
            status = 1
        else:
            logging.error(" port %s does not seem to be %s" % (num, state))
            status = 0
            logging.info("Will attempt 3x to bring the port online")
            if status != 1: 
                while retry <= 3:
                    retry = 0
                    cmd = 'switchshow'
                    logging.info("running cmd again")
                    result = sshclient(ip, user, passwd, cmd)
                    time.sleep(5)
                    if result.find(state, pn, pn+55) > 0:
                        logging.info(result[pn:pn+55])
                        logging.info("Port %s came back online, moving forward" % num)
                        status = 1
                        continue
                    else:
                        logging.error("port %s still does not seem to be %s" %(num, state))
                        status = 0
                        retry = retry + 1
                    if retry == 3:
                        break
                        return status
Esempio n. 2
0
                        status = 1
                        continue
                    else:
                        logging.error("port %s still does not seem to be %s" %(num, state))
                        status = 0
                        retry = retry + 1
                    if retry == 3:
                        break
                        return status
                     
 
while counter <= 10:
#The try/except code test if a connection can be made to host.  if not, it quits the script
    try:
        cmd = "switchshow"
        sshclient(ip, user, passwd, cmd)
    except:
        print "Cannot connect to host.  Please check connection"
        break
    else:
        print "There appears to be a connection to the Carbon switch"
    status = 0
    logging.info("Counter is %s" % counter) 
    for cmd in disable:
        result = sshclient(ip, user, passwd, cmd)
        if cmd == "switchshow":
            logging.info("Verifying ports are disabled")
            for num in nums:
                status = 1
                state = "Disabled"
                portstatus(num, result, state)