Ejemplo n.º 1
0
def RunCollect(client, zone, opt=None):
    flav = getAvailFlav(client)
    cell = filterAz(client, zone)
    if cell != False:
        timeout = process_config('config', 'timeout')
        if opt == True:
            jobs = []
            r_outs = [Queue() for q in range(len(cell[0]))]
            for z, i in enumerate(cell[0]):
                # rate limit seems to kick in
                client = create_connection()
                p = threading.Thread(name=z,
                                     target=computeStats,
                                     args=(cell[1][z], flav, zone, i, client,
                                           r_outs[z], True))
                jobs.append(p)
                p.start()

            for p in jobs:
                p.join(int(timeout))
                if p.is_alive():
                    p.terminate()
                    return False

            html_array = []
            for q in r_outs:
                html_array.append(q.get())

            return html_array
        else:

            if opt in cell[1]:

                index_id = cell[1].index(opt)

            a_name = cell[0][index_id]

            return computeStats(opt,
                                flav,
                                zone,
                                a_name,
                                client,
                                r_outs=None,
                                opt=None)
    else:
        return False
Ejemplo n.º 2
0
def RunCollect(client, zone, opt=None):
    flav = getAvailFlav(client)
    cell = filterAz(client, zone)
    if cell != False:
        timeout = process_config('config', 'timeout')
        if opt == True:
            jobs = []
            r_outs = [Queue() for q in range(len(cell[0]))]
            for z, i in enumerate(cell[0]):
                # rate limit seems to kick in
                client =  create_connection()
                p = threading.Thread(name=z, target=computeStats,
                            args=(cell[1][z], flav,
                                    zone, i, client, r_outs[z],
                                    True))
                jobs.append(p)
                p.start()
    
            for p in jobs:
                p.join(int(timeout))
                if p.is_alive():
                    p.terminate()
                    return False
    
            html_array = []
            for q in r_outs:
                html_array.append(q.get())
    
            return html_array
        else:
            
            
            if opt in cell[1]:
                
                index_id = cell[1].index(opt)
                
            a_name = cell[0][index_id]
    
            return computeStats(opt, flav, zone, a_name, client,
                                            r_outs=None, opt=None)
    else:
        return False
Ejemplo n.º 3
0
def collect_data(client, zone, opt=None):
    vm_flavor = getAvailFlav(client)
    availability_zone = filterAz(client, zone)
    timeout = process_config('config', 'timeout')
    if availability_zone != False:
        if opt == True:
            thread_jobs = []
            result_queue = [Queue() for q in range(len(availability_zone[0]))]
            for key, value in enumerate(availability_zone[0]):
                client = create_connection()
                work_thread = threading.Thread(
                    name=key,
                    target=computeStats,
                    args=(availability_zone[1][key], vm_flavor, zone, value,
                          client, result_queue[key], True))
                thread_jobs.append(work_thread)
                work_thread.start()

            for data_thread in thread_jobs:
                data_thread.join(int(timeout))
                if data_thread.is_alive():
                    data_tread.terminate()
                    return false

            data_display = []
            for rq in result_queue:
                data_display.append(rq.get())

            return data_display
        else:
            if opt in cell[1]:
                index_id = cell[1].index(opt)
            az_name = cell[0][index_id]
            return computeStats(opt,
                                flav,
                                zone,
                                az_name,
                                client,
                                r_outs=None,
                                opt=None)
    else:
        return False
Ejemplo n.º 4
0
def collect_data(client, zone, opt=None):
    vm_flavor = getAvailFlav(client)
    availability_zone = filterAz(client, zone)
    timeout = process_config('config', 'timeout')
    if availability_zone != False:
        if opt == True:
            thread_jobs = [] 
            result_queue = [Queue() for q in range (len(availability_zone[0]))]
            for key, value in enumerate(availability_zone[0]):
                client = create_connection()
                work_thread = threading.Thread(name=key, target=computeStats,
                                               args=(availability_zone[1][key], vm_flavor,
                                               zone, value, client, result_queue[key],
                                               True))
                thread_jobs.append(work_thread)
                work_thread.start()
            
            for data_thread in thread_jobs:
                data_thread.join(int(timeout))
                if data_thread.is_alive():
                    data_tread.terminate()
                    return false
                
            data_display = []
            for rq in result_queue:
                data_display.append(rq.get())
            
            return data_display
        else:
            if opt in cell[1]:
               index_id = cell[1].index(opt)
            az_name = cell[0][index_id]
            return computeStats(opt, flav, zone, az_name, client,
                                            r_outs=None, opt=None)
    else:
        return False
Ejemplo n.º 5
0
def main():

    username = process_config('production', 'user')
    key = process_config('production', 'passwd')
    tenant_name = process_config('production', 'name')
    url = process_config('production', 'url')
    zone = process_config('config', 'zone')
    #client = createNovaConnection(username, key, tenant_name, url)
    client = create_connection()
    az = process_config('config', 'az')
    opt_ = get_args()

    if opt_.t is None:
        #data = RunCollect(client, zone, opt=True)
        data = collect_data(client, zone, opt=True)
        if data != False:
            data2 = CombineResource(data)
            if opt_.o is 'n':
                printOptions(data, data_2=data2, options='all')

            elif opt_.o == 'html':
                templateLoader(data, data2)

            elif opt_.o == 'csv':
                multiCSVNode(data)
                createCSVFileCloud(data2)

            elif opt_.o == 'both':
                templateLoader(data, data2)
                multiCSVNode(data)
                createCSVFileCloud(data2)

            elif opt_.o == 'email':
                file_l = templateLoader(data, data2, opt='email')
                email_user(file_l)
        else:
            print "Error!, failed to contact api server"
            return sys.exit(1)

    elif opt_.t in az:
        #data = RunCollect(client, zone, opt=opt_.t)
        data = collect_data(client, zone, opt=opt_.t)
        if data !=False:
            if opt_.o is 'n':
                printOptions(data)

            elif opt_.o == 'html':
                templateLoader(data, cell=opt_.t)

            elif opt_.o == 'csv':
                createCSVFileNode(data)

            elif opt_.o == 'both':
                templateLoader(data, cell=opt_.t)
                createCSVFileNode(data)

            elif opt_.o == 'email':
                file_l = templateLoader(data, cell=opt_.t, opt='email')
                email_user(file_l)
        else:
            print "Error!, failed to contact api server"
            return sys.exit(1)

    else:
        print "Error!, cell %s not found. Current cell %s " % (opt_.t,
                                                               az)
        return sys.exit(1)
Ejemplo n.º 6
0
def main():

    username = process_config('production', 'user')
    key = process_config('production', 'passwd')
    tenant_name = process_config('production', 'name')
    url = process_config('production', 'url')
    zone = process_config('config', 'zone')
    #client = createNovaConnection(username, key, tenant_name, url)
    client = create_connection()
    az = process_config('config', 'az')
    opt_ = get_args()

    if opt_.t is None:
        #data = RunCollect(client, zone, opt=True)
        data = collect_data(client, zone, opt=True)
        if data != False:
            data2 = CombineResource(data)
            if opt_.o is 'n':
                printOptions(data, data_2=data2, options='all')

            elif opt_.o == 'html':
                templateLoader(data, data2)

            elif opt_.o == 'csv':
                multiCSVNode(data)
                createCSVFileCloud(data2)

            elif opt_.o == 'both':
                templateLoader(data, data2)
                multiCSVNode(data)
                createCSVFileCloud(data2)

            elif opt_.o == 'email':
                file_l = templateLoader(data, data2, opt='email')
                email_user(file_l)
        else:
            print "Error!, failed to contact api server"
            return sys.exit(1)

    elif opt_.t in az:
        #data = RunCollect(client, zone, opt=opt_.t)
        data = collect_data(client, zone, opt=opt_.t)
        if data != False:
            if opt_.o is 'n':
                printOptions(data)

            elif opt_.o == 'html':
                templateLoader(data, cell=opt_.t)

            elif opt_.o == 'csv':
                createCSVFileNode(data)

            elif opt_.o == 'both':
                templateLoader(data, cell=opt_.t)
                createCSVFileNode(data)

            elif opt_.o == 'email':
                file_l = templateLoader(data, cell=opt_.t, opt='email')
                email_user(file_l)
        else:
            print "Error!, failed to contact api server"
            return sys.exit(1)

    else:
        print "Error!, cell %s not found. Current cell %s " % (opt_.t, az)
        return sys.exit(1)