Exemplo n.º 1
0
def poweronSwitch(switch):
    """Power on the switch based on user explicity"""
    db = dbase.connect_mongodb()
    switches = db.switches
    sw = switches.find_one({'switch_name': switch})

    print "Please sit back and relax will take around 10 min for the switch to come up...."
    print "(DO NOT CTRL+C)"
    pFunc.powerOn(sw, db, True)
    print "Switch %s is read for use" % switch
    return
Exemplo n.º 2
0
def showSwitch(switch):
    """Show the all or specified switch details in the database"""
    db = dbase.connect_mongodb()
    switches = db.switches

    if switch == 'all':
        for sw in switches.find():
            printDetails(sw)
    else:
        sw = switches.find_one({'switch_name': switch})
        if sw:
            printDetails(sw)
        else:
            print "Switch %s does not exist in database" % switch
    return
Exemplo n.º 3
0
def holdSwitch(switch):
    """Hold the switch i.e. do not donate it to lab or poweroff"""
    db = dbase.connect_mongodb()
    switches = db.switches

    if switches.find({'switch_name': switch}).count() == 0:
        print "Switch %s does not exist in the database" % switch
        sys.exit(0)

    sw = switches.find_one({'switch_name': switch})
    if str(sw['is_powered_on']).lower() == 'off':
        print "Switch %s cannot be held as its powered off/in sanities" % switch
        sys.exit(0)

    update_hold_testbed(db, switch=switch, reserve='yes')
    print "Switch %s has been held, will not be submitted for sanities or powered off until released" % switch
    return
Exemplo n.º 4
0
            'user': str(detail['user_mail'])
        }
        insertSws.append(switch)


def insertSwitch(file):
    insertSws = []
    with open(file) as f:
        try:
            sws = json.load(f)
        except Exception, e:
            print str(e)
            print "Issue in you JSON file please check and try again"
            sys.exit(1)

    db = dbase.connect_mongodb()
    switches = db.switches
    try:
        for sw, detail in sws.items():
            insertFunc(sw, detail, insertSws, switches)
        from_list = '*****@*****.**'
        to_list = ''
        mailer = email.ICEmail(from_list, to_list)
        for s in insertSws:
            sw_id = switches.insert_one(s).inserted_id
            print "Switch %s has been added to db....HURRAH....GO GREEN" % s[
                'switch_name']
            to_list = str(s['user'])
            mailer.set_to(to_list)
            subject = 'Welcome to iLab'
            if s['end_time'] == "":
Exemplo n.º 5
0
import ilabmail as email 
import utils as util

def printDetails(det):
    print_det = ""
    coln1 = "Switch Name"
    for key,val in det.items():
        coln2 = "%s # of cards" % (key)
        print_det = PrettyTable([coln1,coln2])
        print_det.align[coln1] = "l"
        print_det.width = 2
        for switch,number in val.items():
            print_det.add_row([switch,number])
        print print_det

if __name__ == '__main__':
    db = dbase.connect_mongodb()
    switch_details = db.switchdetail
    detail = {}
    
    for lc in defn.sw_types:
        detail[lc] = {}

        for sw in switch_details.find({'module':{"$regex":lc}}):
            if str(sw['switch_name']) in detail[lc].keys():
                detail[lc][str(sw['switch_name'])] += 1
            else:
                detail[lc][str(sw['switch_name'])] = 1
        
    printDetails(detail)