def test_risque(self): # Speed(risqueString='10/100/1000T-SW-A') # Speed(risqueString='100/1000T-SW-A') # Speed(risqueString='100/1000/2.5G/5G/10G-SW-A') gigSpeed = Speed(risqueString='10/100/1000T-SW-A') self.assertIsNotNone(gigSpeed) self.assertIs(gigSpeed.duplex, Speed.DUPLEX_AUTO) self.assertEqual(gigSpeed.speedTuple[0], 10) self.assertEqual(gigSpeed.speedTuple[1], 100) self.assertEqual(gigSpeed.speedTuple[2], 1000) tenHundred = Speed(risqueString='100/1000T-SW-A') self.assertIsNotNone(tenHundred) self.assertIs(tenHundred.duplex, Speed.DUPLEX_AUTO) self.assertEqual(tenHundred.speedTuple[1], 100) self.assertEqual(tenHundred.speedTuple[2], 1000) tenGig = Speed(risqueString='100/1000/2.5G/5G/10G-SW-A') self.assertIsNotNone(tenGig) self.assertIs(tenGig.duplex, Speed.DUPLEX_AUTO) self.assertEqual(tenGig.speedTuple[1], 100) self.assertEqual(tenGig.speedTuple[2], 1000) self.assertEqual(tenGig.speedTuple[3], 2500) self.assertEqual(tenGig.speedTuple[4], 5000) self.assertEqual(tenGig.speedTuple[5], 10000) with self.assertRaises(AttributeError) as cm: Speed(risqueString='') self.assertEqual(cm.exception.message, "Risque String is not supported! Error: Speed")
def __trunkDeactivate(self, iosConnection, provider, pic): interface = provider.getSwitchInterface() if iosConnection.isFexHost: # print "Can't modify trunk port on a FEX host" self.logger.logError("Can't modify trunk port on a FEX host") return False switchConfig = iosConnection.getConfig(interface, flatten=False) self.logger.logBefore(pic.name, interface, switchConfig) description = iosConnection.getDescription(interface, switchConfig) if description is None or description != pic.getDescription(): self.logger.logError("Can't modify trunk port on a FEX host") # print "DESCRIPTIONS DON'T MATCH ON MODIFY - PIC: {0}, provider: {1}".format(pic.name, provider) iosConnection.enterConfigMode() iosConnection.enterInterfaceConfig(interface) # Shutdown port iosConnection.shutdown() # Switchport trunk allowed vlan 1 iosConnection.setTaggedVlans(Vlan.Vlan1()) iosConnection.setNativeVlan(Vlan.Vlan1()) # no speed iosConnection.setSpeed(Speed.NoSpeed()) iosConnection.leaveInterfaceConfig() iosConnection.leaveConfigMode() self.hostChanged = True
def __basicDeactivate(self, iosConnection, provider, pic): interface = None if iosConnection.isFexHost: interface = iosConnection.findFexInterface(pic, provider) else: interface = provider.getSwitchInterface() switchConfig = iosConnection.getConfig(interface, flatten=False) self.logger.logBefore(pic.name, interface, switchConfig) description = iosConnection.getDescription(interface, switchConfig) if description is None or description != pic.getDescription(): # print "DESCRIPTIONS DON'T MATCH ON MODIFY - PIC: {0}, provider: {1}".format(pic.name, provider) self.logger.logWarning( "DESCRIPTIONS DON'T MATCH ON MODIFY - PIC: {0}, provider: {1}". format(pic.name, provider), True) iosConnection.enterConfigMode() iosConnection.enterInterfaceConfig(interface) # Shutdown port iosConnection.shutdown() # Switchport access vlan 1 iosConnection.setVlan(Vlan.Vlan1()) # no speed iosConnection.setSpeed(Speed.NoSpeed()) iosConnection.leaveInterfaceConfig() iosConnection.leaveConfigMode() self.hostChanged = True
def test_name(self): # Speed(name='10') # Speed(name='Gigabit') tenSpeed = Speed(name='10') self.assertIsNotNone(tenSpeed) self.assertIs(tenSpeed.name, Speed.NAME_TEN) self.assertIs(tenSpeed.duplex, Speed.DUPLEX_AUTO) self.assertEqual(tenSpeed.speedTuple[0], 10) gigSpeed = Speed(name='Gigabit') self.assertIsNotNone(gigSpeed) self.assertIs(gigSpeed.name, Speed.NAME_GIGABIT) self.assertIs(gigSpeed.duplex, Speed.DUPLEX_AUTO) self.assertEqual(gigSpeed.speedTuple[0], 10) self.assertEqual(gigSpeed.speedTuple[1], 100) self.assertEqual(gigSpeed.speedTuple[2], 1000) with self.assertRaises(AttributeError) as cm: Speed(name='') self.assertEqual(cm.exception.message, "name is an invalid type")
def __init__(self, vlan, speed): if type(speed) is not str or vlan is None: raise AttributeError("PICConfig given null attributes") if type(vlan) is str: self.vlan = Vlan(risqueString=vlan) self.vlanList = False elif isinstance(vlan, list): self.trunk = True self.vlan = [] for v in vlan: self.vlan.append(Vlan(risqueString=v)) self.vlanList = True self.speed = Speed(risqueString=speed)
def test_switch(self): # Speed(switchString='speed auto 10 100') # Speed(switchString='speed 1000') # Speed(switchString='speed auto 100 1000') # Speed(switchString='') tenHundred = Speed(switchString='speed auto 10 100') self.assertIsNotNone(tenHundred) self.assertIs(tenHundred.speedAuto, True) self.assertEqual(tenHundred.speedTuple[0], 10) self.assertEqual(tenHundred.speedTuple[1], 100) self.assertEqual(tenHundred.speedTuple[2], 0) self.assertEqual(tenHundred.speedTuple[3], 0) self.assertEqual(tenHundred.speedTuple[4], 0) self.assertEqual(tenHundred.speedTuple[5], 0) thousand = Speed(switchString='speed 1000') self.assertIsNotNone(thousand) self.assertIs(thousand.speedAuto, False) self.assertEqual(thousand.speedTuple[0], 0) self.assertEqual(thousand.speedTuple[1], 0) self.assertEqual(thousand.speedTuple[2], 1000) self.assertEqual(thousand.speedTuple[3], 0) self.assertEqual(thousand.speedTuple[4], 0) self.assertEqual(thousand.speedTuple[5], 0) hundredThousand = Speed(switchString='speed auto 100 1000') self.assertIsNotNone(hundredThousand) self.assertIs(hundredThousand.speedAuto, True) self.assertEqual(hundredThousand.speedTuple[0], 0) self.assertEqual(hundredThousand.speedTuple[1], 100) self.assertEqual(hundredThousand.speedTuple[2], 1000) self.assertEqual(hundredThousand.speedTuple[3], 0) self.assertEqual(hundredThousand.speedTuple[4], 0) self.assertEqual(hundredThousand.speedTuple[5], 0) empty = Speed(switchString='') self.assertIsNotNone(empty) self.assertIs(empty.speedAuto, True) self.assertEqual(empty.speedTuple[1], 0) self.assertEqual(empty.speedTuple[2], 0)
def loads(self, noaa_string): ''' load in a report (or set) from a string ''' self.raw = noaa_string self.weather_station = noaa_string[4:10] self.wban = noaa_string[10:15] expected_length = int(noaa_string[0:4]) + self.PREAMBLE_LENGTH actual_length = len(noaa_string) if actual_length != expected_length: msg = "Non matching lengths. Expected %d, got %d" % ( expected_length, actual_length) raise ish_reportException(msg) try: self.datetime = datetime.strptime(noaa_string[15:27], '%Y%m%d%H%M') except ValueError: ''' some cases, we get 2400 hours, which is really the next day, so this is a workaround for those cases ''' time = noaa_string[15:27] time = time.replace("2400", "2300") self.datetime = datetime.strptime(time, '%Y%m%d%H%M') self.datetime += timedelta(hours=1) self.report_type = ReportType(noaa_string[41:46].strip()) self.latitude = float(noaa_string[28:34]) / self.GEO_SCALE self.longitude = float(noaa_string[34:41]) / self.GEO_SCALE self.elevation = int(noaa_string[46:51]) ''' other mandatory fields ''' self.wind_direction = Direction(noaa_string[60:63], Direction.RADIANS, noaa_string[63:64]) self.wind_observation_direction_type = noaa_string[64:64] self.wind_speed = Speed( int(noaa_string[65:69]) / float(self.SPEED_SCALE), Speed.METERSPERSECOND, noaa_string[69:70]) self.sky_ceiling = Distance(int(noaa_string[70:75]), Distance.METERS, noaa_string[75:76]) self.sky_ceiling_determination = noaa_string[76:77] self.visibility_distance = Distance(int(noaa_string[78:84]), Distance.METERS, noaa_string[84:85]) self.visibility_variability = noaa_string[85:86] self.visibility_variability_quality = noaa_string[86:87] self.air_temperature = Temperature( int(noaa_string[87:92]) / self.TEMPERATURE_SCALE, Units.CELSIUS, noaa_string[92:93]) self.dew_point = Temperature( int(noaa_string[93:98]) / self.TEMPERATURE_SCALE, Units.CELSIUS, noaa_string[98:99]) self.humidity = Humidity(str(self.air_temperature), str(self.dew_point)) self.sea_level_pressure = Pressure( int(noaa_string[99:104]) / self.PRESSURE_SCALE, Pressure.HECTOPASCALS, noaa_string[104:104]) ''' handle the additional fields ''' additional = noaa_string[105:108] if additional == 'ADD': position = 108 while position < expected_length: try: (position, (addl_code, addl_string)) = self._get_component( noaa_string, position) self._additional[addl_code] = addl_string except ish_reportException, err: ''' this catches when we move to remarks section ''' break
from Speed import Speed vc = Speed("./", "sample.mp4", 60.0, [10, -10], [400, 345, 332], [0.00, 3.66, 7.32], 0.4669, 0.0, 4.27) # Find the heat map/heat trace of the video. vc.find_trace() # Estimate vehicle counts, distance, and speeds using DBSCAN and convex hull. vc.analyze_trace() # Visualize the estimation results in form of histogram and video overlay. vc.inspect_dynamics()
def __basicActivate(self, iosConnection, provider, pic): interface = None if iosConnection.isFexHost: interface = iosConnection.findFexInterface(pic, provider) else: interface = provider.getSwitchInterface() risqueConfig = pic.getConfig() switchConfig = iosConnection.getConfig(interface, flatten=False) upsCount = 0 upsDevice = None self.logger.logBefore(pic.name, interface, switchConfig) switchGlobalVoiceVlan = iosConnection.findVoiceVlan() if provider.uplink: # print "Provider is an uplink port, not supported yet!" self.logger.logError( "Provider is an uplink port, not supported yet!", True) return if pic.isUPS(): upsCount = iosConnection.getUPSCount() upsDevice = provider.getUPSTypeFromProvider(provider) iosConnection.enterConfigMode() iosConnection.enterInterfaceConfig(interface) if iosConnection.isInterfaceEmpty(switchConfig): # Apply base config iosConnection.applyBaseTemplate(iosConnection.getBaseTemplate()) # Set Description if pic.isUPS(): # 70136 # stew-215a-apc1500rm-01 fixedUPSCount = "0{0}".format(upsCount + 1) if (upsCount + 1) < 10 else str( upsCount + 1) # add leading zeroes newDescription = "{0}-{1}-{2}-{3}".format(provider.building, provider.TR, upsDevice, fixedUPSCount) iosConnection.setDescription(newDescription) else: iosConnection.setDescription(pic.getDescription()) # Set access mode iosConnection.setSwitchportMode("access") # Set speed if pic.isAP(): if "Gi" in provider.intType: iosConnection.setSpeed(risqueConfig.speed) # set duplex iosConnection.setDuplex(Speed.DUPLEX_FULL) elif "Te" in provider.intType or "Tw" in provider.intType: iosConnection.setSpeed(Speed.SpeedAutoObject()) else: iosConnection.setSpeed(risqueConfig.speed) else: iosConnection.setSpeed(risqueConfig.speed) # Set vlan iosConnection.setVlan(risqueConfig.vlan) # Set voice vlan if risqueConfig.voiceVlan is not None: iosConnection.setVoiceVlan(risqueConfig.voiceVlan) else: self.logger.logWarning( "Risque does not have a voice vlan for {0}".format(pic.name), True) if switchGlobalVoiceVlan is None: self.logger.logError( "Unable to retrieve voice vlan for switch", False) else: iosConnection.setVoiceVlan(switchGlobalVoiceVlan) self.logger.logInfo( "Set voice vlan for {0} to {1}".format( pic.name, switchGlobalVoiceVlan), False) # set power for AP if pic.isAP() and "3750" in provider.switchType: iosConnection.setPower(20000) # Set no shut iosConnection.shutdown(no=True) iosConnection.leaveInterfaceConfig() iosConnection.leaveConfigMode() self.hostChanged = True