Пример #1
0
def convert_file_database(last_id):
    ea_read = open('snap.dat','r')
    ed = EADatabase()
    ed.simple_db_test()
    ed.simple_db_test()
    for line in ea_read:
        eam = EAMeasurement()
        eam.parse_measurement(line)
        ed.ins_device_sql(last_id, eam.snapshot.dev_manufacturer, eam.snapshot.chassis_type, eam.power_measurement)
        for comp in eam.snapshot.components:
            ed.ins_component_sql(last_id,comp)
        last_id = last_id+1
Пример #2
0
def convert_file_database(last_id):
    ea_read = open('snap.dat', 'r')
    ed = EADatabase()
    ed.simple_db_test()
    ed.simple_db_test()
    for line in ea_read:
        eam = EAMeasurement()
        eam.parse_measurement(line)
        ed.ins_device_sql(last_id, eam.snapshot.dev_manufacturer,
                          eam.snapshot.chassis_type, eam.power_measurement)
        for comp in eam.snapshot.components:
            ed.ins_component_sql(last_id, comp)
        last_id = last_id + 1
Пример #3
0
    def run_audit_file(self, filename):
        # Pull in comparative snapshots
        print "Run Audit"
        pwr_m = []
        fsnap = open('snap.dat', 'r')
        print "Loading measurements"
        for line in fsnap:
            eam = EAMeasurement()
            eam.parse_measurement(line)
            pwr_m.append(eam)
        print "Done loading"
        # Match snapshots in community database to those seen
        # by the parser
        no_match = []
        nm_num  = 0
        pwr_consumption = 0.0
        num_devices = 0
        names_count = {}
        power_pie = {}
        no_chassis_type = 0
        for d in self.device_snapshots:
            num_devices = num_devices+1
            #print d.chassis_type
            ppc = 0.0
            if not d or d.chassis_type == "":
                no_chassis_type = no_chassis_type+1
                continue
            if not d.is_stack_switch:
                if d.chassis_type.lower() in names_count:
                    names_count[d.chassis_type.lower()] =  names_count[d.chassis_type.lower()]+1
                else:
                    names_count[d.chassis_type.lower()] = 1
            nm = True
            if d.is_stack_switch:
                num_devices = num_devices-1
                for c in d.components:
                    if c.type == "stack":
                        num_devices = num_devices+1
                        if c.name.lower() in names_count:
                            names_count[c.name.lower()] =  names_count[c.name.lower()]+1
                        else:
                            names_count[c.name.lower()] = 1
                        #Check the measured devices
                        nm = True
                        for m in pwr_m:
                            if(m.snapshot.dev_comp_match(c)):
                                pwr_consumption = pwr_consumption+m.power_measurement
                                if c.name.lower() in power_pie:
                                    power_pie[c.name.lower()] =  power_pie[c.name.lower()]+m.power_measurement
                                else:
                                    power_pie[c.name.lower()] = m.power_measurement
                                nm = False
                                for m_comp in m.snapshot.components:
                                    if m_comp.name == "ppcost":
                                        ppc = m_comp.power
                                        break
                                break
                        if nm:
                            nm_num = nm_num+1
                            if c.name not in no_match:
                                no_match.append(c.name)            
            #[JPC]: multiple measurements from the same device currently will result in pathological behavior
            nm = True
            for m in pwr_m:
                if d.dev_match(m.snapshot):
                    if not d.is_stack_switch: #Already added chassis costs
                        pwr_consumption = pwr_consumption + m.power_measurement
                        if d.chassis_type.lower() in power_pie:
                            power_pie[d.chassis_type.lower()] =  power_pie[d.chassis_type.lower()]+m.power_measurement
                        else:
                            power_pie[d.chassis_type.lower()] = m.power_measurement
                        
                    #Check for components
                    # d is the test snapshot
                    # m is the measured snapshot
                    # Find per port cost
                    for m_comp in m.snapshot.components:
                        if m_comp.name == "ppcost":
                            ppc = m_comp.power
                            break
                    # No per port cost
                    if ppc == 0.0:
                        nm = False
                        break
                    # Add per port costs to overall power cost
                   
                    for tc in d.components:
                        if "thernet" in tc.name or "thernet" in tc.type or "thernet" in tc.desc:
                            pwr_consumption = pwr_consumption + ppc
                            if d.chassis_type.lower() in power_pie:
                                power_pie[d.chassis_type.lower()] =  power_pie[d.chassis_type.lower()]+ppc
                            else:
                                power_pie[d.chassis_type.lower()] = ppc
                            
                    nm = False
                    break
            if nm:
                if d.is_stack_switch == False:
                    nm_num = nm_num+1
                if d.chassis_type not in no_match:
                    no_match.append(d.chassis_type)

        #[JPC] Separate the print from the Audit function
        
        
        blarg = 0
        for k,v in names_count.iteritems():
            blarg = blarg+1
            print k,v
        print "---"
        for k1,v1 in power_pie.iteritems():
            print k1,v1
        print "---"
        print "Type of devices: "+str(blarg)

        #for i in no_match:
        #    print i
        print "Type Count: "+str(blarg)
        print str(len(no_match))+" Device types without a match:"
        print str(nm_num)+" Devices without a match:"
        print "Length of device array:"+str(len(self.device_snapshots))
        print "Audit Num Devices: "+str(num_devices)
        print "Audit Power Consumption: "+str(pwr_consumption)
        print "No Chassis Type: "+str(no_chassis_type)