def fromDB(dbCursor): #make static providers = [] providers.append(Provider(0.925, 1.124, 0, 0, 0, 0, [], [])) providers.append(Provider(1.133, 1.009, 0, 0, 0, 0, [], [])) providers.append(Provider(1.875, 2.005, 0, 0, 0, 0, [], [])) return providers
def sender(): ConnRabbitMQ = Provider.OpenConnRabbitMQ() channel = ConnRabbitMQ.channel() # 创建频道 while True: dic = Provider.messagequeue.get() queuetype = dic['queuetype'] message = dic['message'] task = json.dumps(message, ensure_ascii=False).encode('utf-8') if not ConnRabbitMQ.is_open: ConnRabbitMQ = Provider.OpenConnRabbitMQ() channel = ConnRabbitMQ.channel() if queuetype == 'work': try: channel.basic_publish(exchange='', routing_key=MQQueueWorker, body=task) except pika.exceptions.ConnectionClosed: ConnRabbitMQ = Provider.OpenConnRabbitMQ() channel = ConnRabbitMQ.channel() channel.basic_publish(exchange='', routing_key=MQQueueWorker, body=task) elif queuetype == 'finish': try: channel.basic_publish(exchange='', routing_key=MQQueueFinish, body=task) except pika.exceptions.ConnectionClosed: ConnRabbitMQ = Provider.OpenConnRabbitMQ() channel = ConnRabbitMQ.channel() channel.basic_publish(exchange='', routing_key=MQQueueFinish, body=task)
def run(): config_exo = { 'access': 'EXO84e091ac6a22bf8fb7b916f2', 'secret': '-DU8_52ivubZb0-hdrx788GKtbTjw7r32LUOlFKV_VA' } config_aws = {'access': '', 'secret': ''} provider_exo = Provider(name='exoscale', config=config_exo, region='') provider_aws = Provider(name='aws', config=config_aws, region='us-east-1') semaphore = threading.BoundedSemaphore(2) instance_exo = Instance(provider_exo, 'test', 'Medium', 'Linux Ubuntu 18.04 LTS 64-bit') instance_aws = Instance(provider_aws, 'COCA-BENCH', 't2.micro', 'ami-0a313d6098716f372') key = RSA.generate(2048) keypair = (key.exportKey('PEM'), key.publickey().exportKey('OpenSSH')) benchmark_exo = Benchmark(instance_exo, keypair, semaphore) # benchmark_aws = Benchmark(instance_aws, keypair, semaphore) print "start tests" benchmark_exo.start() # benchmark_aws.start() print "wait threads" benchmark_exo.join() # benchmark_aws.join() print "end"
def test_switch(self): # GigabitEthernet1/0/9 # Gi3/0/12 # Te1/1/3 # Te2/3/16 # FastEthernet0/1 provider1 = Provider(switchString='GigabitEthernet1/0/9') self.assertIsNotNone(provider1) self.assertEqual(provider1.switch, 1) self.assertEqual(provider1.port, 9) self.assertEqual(provider1.intType, "Gi") self.assertFalse(provider1.uplink) provider2 = Provider(switchString='Gi3/0/12') self.assertIsNotNone(provider2) self.assertEqual(provider2.switch, 3) self.assertEqual(provider2.port, 12) self.assertEqual(provider2.intType, "Gi") self.assertFalse(provider2.uplink) provider3 = Provider(switchString='Te1/1/3') self.assertIsNotNone(provider3) self.assertEqual(provider3.switch, 1) self.assertEqual(provider3.port, 3) self.assertEqual(provider3.intType, "Te") self.assertTrue(provider3.uplink) with self.assertRaises(AttributeError) as cm: Provider(switchString='Te2/3/16') self.assertEqual(cm.exception.message, "switchString is a line card, not supported!") provider4 = Provider(switchString='FastEthernet0/1') self.assertIsNotNone(provider4) self.assertEqual(provider4.switch, 0) self.assertEqual(provider4.port, 1) self.assertEqual(provider4.intType, "Fa") self.assertFalse(provider4.uplink) provider5 = Provider(switchString="Gi103/1/0/9") self.assertIsNotNone(provider5) self.assertEqual(provider5.switch, 103) self.assertEqual(provider5.port, 9) self.assertEqual(provider5.intType, "Gi") self.assertFalse(provider5.uplink) self.assertTrue(provider5.fex) provider6 = Provider(switchString="Gi101/1/0/11") self.assertIsNotNone(provider6) self.assertEqual(provider6.switch, 101) self.assertEqual(provider6.port, 11) self.assertEqual(provider6.intType, "Gi") self.assertFalse(provider6.uplink) self.assertTrue(provider6.fex) # with self.assertRaises(AttributeError) as cm: # Provider(switchString='gi104/1/0/6') # self.assertEqual(cm.exception.message, "switchString is a FEX port, not supported!") with self.assertRaises(AttributeError) as cm: Provider(switchString='') self.assertEqual(cm.exception.message, "switchString is an invalid provider")
def startmission(self): ConnRabbitMQ = Provider.OpenConnRabbitMQ() channel = ConnRabbitMQ.channel() # 创建频道 dic = self.package('startdown_list') if dic: task = json.dumps(dic, ensure_ascii=False).encode('utf-8') channel.basic_publish(exchange='', routing_key=MQQueueFinish, body=task)
def test_fiberLinksFromRisque(self): provider1 = Provider( risqueString='pvab-40-c9348uxm-01:01-01-03-Te1/1/3') self.assertEqual(provider1.intType, 'Te') self.assertEqual(provider1.switch, 1) self.assertEqual(provider1.stack, 1) self.assertEqual(provider1.port, 3) self.assertTrue(provider1.uplink)
def __init__(self, name, currentProvider, newProvider, action): # if name is None or newProvider is None or action is None: # raise AttributeError("PIC given null attributes") self.name = name self.action = action if currentProvider is not None: try: self.currentProvider = Provider(risqueString=currentProvider) except: self.currentProvider = None if newProvider is not None: try: self.newProvider = Provider(risqueString=newProvider) except: print("Failed to parse newProvider") self.newProvider = None self.__isValidAction()
def __init__( self, fileName, topLevelService, defaultRadiusInMiles, count=-1): # if count isn't specified then import all providers g = Geocoder.Geocoder() t = AddTopLevel.AddTopLevel() with codecs.open(fileName, 'r', 'utf-8') as f: providersData = json.load(f) for tally, providerObj in enumerate(providersData): provider = Provider(providerObj) if len(provider.topLevelServices ) == 0: # if topLevelServices not in json file tls = t.addToProvider(provider) provider.topLevelServices = tls if not topLevelService in provider.topLevelServices: # if this provider doesn't have the particular topLevelService, don't append it continue if provider.longitude is None: # if coords not in json file latlon = g.geocode(provider.address) provider.setLatLon(latlon[0], latlon[1]) if provider.getRadius() == None: provider.ru = float( defaultRadiusInMiles ) / 69.0 #convert to degrees. there are approximately 69 miles in 1 degree latitude. self.providers.append(provider) tally += 1 if tally == count: break
def test_getHosts(self): provider1 = Provider(risqueString='hamp-gu01a-c3750ep-01:04-Gi4/0/18') self.assertEqual(Provider.getHostFromProvider(provider1), "hamp-gu01a-c3750ep-01.tcom.purdue.edu") provider2 = Provider(risqueString="stew-b20c-c3850-02:01-Gi1/0/37") self.assertEqual(Provider.getHostFromProvider(provider2), "stew-b20c-c3850-02.tcom.purdue.edu") provider3 = Provider(risqueString='yong-464-c3750ep-01:01-Gi1/0/1') self.assertEqual(Provider.getHostFromProvider(provider3), "yong-464-c3750ep-01.tcom.purdue.edu") provider4 = Provider(risqueString='jnsn-b099f-c3750ep-01:01-Gi1/0/21') self.assertEqual(Provider.getHostFromProvider(provider4), "jnsn-b099f-c3750ep-01.tcom.purdue.edu")
def calcMMD(self, geneSerial, data): customers = [] for item in data.CUSTOMERS: tmp = Customer() tmp.x = copy.deepcopy(item.x) tmp.y = copy.deepcopy(item.y) tmp.demand = copy.deepcopy(item.demand) customers.append(tmp) providers = [] sigmaCost = 0 sigmaCapacity = 0 sigmaDemand = 0 mmd = -1000.00 for i in range(0, len(geneSerial)): tmpProvider = Provider() tmpProvider.x = copy.deepcopy(data.PROVIDERS[i].x) tmpProvider.y = copy.deepcopy(data.PROVIDERS[i].y) tmpProvider.capacity = copy.deepcopy( data.PROVIDERS[i].capacity[geneSerial[i]]) tmpProvider.cost = copy.deepcopy( data.PROVIDERS[i].cost[geneSerial[i]]) sigmaCost = sigmaCost + tmpProvider.cost sigmaCapacity = sigmaCapacity + tmpProvider.capacity providers.append(tmpProvider) for item in customers: sigmaDemand = sigmaDemand + item.demand if sigmaCapacity >= sigmaDemand: swapchainsolver = SwapChainSolver(providers, customers) mmd = swapchainsolver.Solver() return mmd
def Work(): ConnRabbitMQ = Provider.OpenConnRabbitMQ() channel = ConnRabbitMQ.channel() # 创建频道 channel.basic_qos(prefetch_size=0, prefetch_count=1, all_channels=True) # no_ack=True 开启自动确认,不然消费后的消息会一直留在队列里面 # no_ack = no_manual_ack = auto_ack;不手动应答,开启自动应答模式 channel.basic_consume(ConsumerWorkCallback, queue=MQQueueWorker, no_ack=False) print('Wait Message Work ...') channel.start_consuming()
def Finish(): ConnRabbitMQ = Provider.OpenConnRabbitMQ() channel = ConnRabbitMQ.channel() # 创建频道 channel.basic_qos(prefetch_size=0, prefetch_count=1, global_qos=True) # no_ack=True 开启自动确认,不然消费后的消息会一直留在队列里面 # no_ack = no_manual_ack = auto_ack;不手动应答,开启自动应答模式 channel.basic_consume(on_message_callback=ConsumerFinCallback, queue=MQQueueFinish, auto_ack=False) print('Wait Message Finish...') channel.start_consuming()
def run(): parser = argparse.ArgumentParser(description='Run benchmarks in all instances defined by the config file') parser.add_argument("providers", help='Configuration file describing providers') parser.add_argument("instances", help='Configuration file describing instances to create and benchmark') parser.add_argument("--nThreads", type=int, help='Number of threads to start') parser.add_argument("--keyLength", type=int, default=2048, help='Length of the generated SSH key') args = parser.parse_args() key = RSA.generate(2048) keypair = (key.exportKey('PEM'), key.publickey().exportKey('OpenSSH')) pkey_name = "coca-bench.pem" os.system("chmod 777 " + pkey_name) file1 = open(pkey_name, "w") file1.write(keypair[0]) file1.close() os.system("chmod 400 " + pkey_name) providers_config = ConfigParser.ConfigParser() providers_config.read(args.providers) instances_config = ConfigParser.ConfigParser() instances_config.read(args.instances) nthreads = len(instances_config.sections()) if args.nThreads is not None: nthreads = args.nThreads semaphore = threading.BoundedSemaphore(nthreads) jobs = list() for instance_name in instances_config.sections(): provider_name = instances_config.get(instance_name, "provider") flavor = instances_config.get(instance_name, "flavor") image = instances_config.get(instance_name, "image") provider_data = dict(providers_config.items(provider_name)) username = None if instances_config.has_option(instance_name, "username"): username = instances_config.get(instance_name, "username") region = instances_config.get(instance_name, "region") provider = Provider(provider_name, region, provider_data) instance = Instance(provider, instance_name, flavor, image, username) bench = Benchmark(instance, keypair, semaphore) jobs.append(bench) for job in jobs: job.start() for job in jobs: job.join() print("all threads are finished")
def create_provider_objects(): ''' This function will create provider objects from a read file and return a nested list ''' # Declare Variables provider_list = [] contents = read_file('Providers Table.csv') # Create Client Objects for x in range(0, len(contents)): provider_list.append( Provider(contents[x][0], contents[x][1], contents[x][2])) return provider_list
def test_risque(self): # hamp-gu01a-c3750ep-01:04-Gi4/0/18 # arms-3163-c3750ep-01:01-Gi1/0/27 # crtn-3035b-c3850mg-02:06-Gi6/0/23 provider1 = Provider(risqueString='hamp-gu01a-c3750ep-01:04-Gi4/0/18') self.assertIsNotNone(provider1) self.assertEqual(provider1.building, "hamp") self.assertEqual(provider1.TR, "gu01a") self.assertEqual(provider1.switchType, "c3750ep") self.assertEqual(provider1.intType, "Gi") self.assertEqual(provider1.switch, 4) self.assertEqual(provider1.port, 18) self.assertEqual(provider1.stack, 1) provider2 = Provider(risqueString='arms-3163-c3750ep-01:01-Gi1/0/27') self.assertIsNotNone(provider2) self.assertEqual(provider2.building, "arms") self.assertEqual(provider2.TR, "3163") self.assertEqual(provider2.switchType, "c3750ep") self.assertEqual(provider2.intType, "Gi") self.assertEqual(provider2.switch, 1) self.assertEqual(provider2.port, 27) self.assertEqual(provider2.stack, 1) provider3 = Provider(risqueString='crtn-3035b-c3850mg-02:06-Gi6/0/23') self.assertIsNotNone(provider3) self.assertEqual(provider3.building, "crtn") self.assertEqual(provider3.TR, "3035b") self.assertEqual(provider3.switchType, "c3850mg") self.assertEqual(provider3.intType, "Gi") self.assertEqual(provider3.switch, 6) self.assertEqual(provider3.port, 23) self.assertEqual(provider3.stack, 2) provider4 = Provider(risqueString='gcmb-100-c3560cg-01-Gi0/6') self.assertIsNotNone(provider4) self.assertEqual(provider4.building, "gcmb") self.assertEqual(provider4.TR, "100") self.assertEqual(provider4.switchType, "c3560cg") self.assertEqual(provider4.intType, "Gi") self.assertEqual(provider4.switch, 0) self.assertEqual(provider4.port, 6) self.assertEqual(provider4.stack, 1) provider5 = Provider(risqueString="pgw-101cabnw-c3560cx-01-Gi1/0/1") self.assertIsNotNone(provider5) self.assertEqual(provider5.building, "pgw") self.assertEqual(provider5.TR, "101cabnw") self.assertEqual(provider5.switchType, "c3560cx") self.assertEqual(provider5.intType, "Gi") self.assertEqual(provider5.switch, 1) self.assertEqual(provider5.port, 1) self.assertEqual(provider5.stack, 1) with self.assertRaises(AttributeError) as cm: Provider(risqueString='') self.assertEqual(cm.exception.message, "risqueString is not a valid provider!")
def calcFitnessWithSurrogate(self, geneSerial, data, D): """ usage ChromosomeNumber,geneSerial,data,D return fitness for this1 Chromosome """ alpha = self.m_Alpha beta = self.m_Beta # alpha and beta are weight factor customers = [] fitness = 0 for item in data.CUSTOMERS: tmp = Customer() tmp.x = copy.deepcopy(item.x) tmp.y = copy.deepcopy(item.y) tmp.demand = copy.deepcopy(item.demand) customers.append(tmp) providers = [] sigmaCost = 0 sigmaCapacity = 0 sigmaDemand = 0 mmd = self.m_D * 1000.0 for i in range(0, len(geneSerial)): tmpProvider = Provider() tmpProvider.x = copy.deepcopy(data.PROVIDERS[i].x) tmpProvider.y = copy.deepcopy(data.PROVIDERS[i].y) tmpProvider.capacity = copy.deepcopy( data.PROVIDERS[i].capacity[geneSerial[i]]) tmpProvider.cost = copy.deepcopy( data.PROVIDERS[i].cost[geneSerial[i]]) sigmaCost = sigmaCost + tmpProvider.cost sigmaCapacity = sigmaCapacity + tmpProvider.capacity providers.append(tmpProvider) for item in customers: sigmaDemand = sigmaDemand + item.demand if sigmaCapacity >= sigmaDemand: x = np.array(geneSerial).reshape(1, -1) mmd = self.m_Surrogate.predict(x)[0] if mmd > D: fitness = -1000 elif mmd > 0: if sigmaCost != 0: fitness = float(4.0 / sigmaCost) else: fitness = 8.0 else: fitness = -6.0 else: fitness = -8.0 # print"fitness,mmd,sigmaCapacity,sigmaCost,sigmaDemand:",fitness,mmd,sigmaCapacity,sigmaCost,sigmaDemand return math.exp(fitness), mmd, sigmaCapacity, sigmaCost, sigmaDemand
def calcFitness(self, geneSerial, data, D): """ usage ChromosomeNumber,geneSerial,data,D return fitness for this1 Chromosome """ alpha = self.m_Alpha beta = self.m_Beta # alpha and beta are weight factor customers = [] fitness = 0 for item in data.CUSTOMERS: tmp = Customer() tmp.x = copy.deepcopy(item.x) tmp.y = copy.deepcopy(item.y) tmp.demand = copy.deepcopy(item.demand) customers.append(tmp) providers = [] sigmaCost = 0 sigmaCapacity = 0 sigmaDemand = 0 mmd = self.m_D * 1000.0 for i in range(0, len(geneSerial)): tmpProvider = Provider() tmpProvider.x = copy.deepcopy(data.PROVIDERS[i].x) tmpProvider.y = copy.deepcopy(data.PROVIDERS[i].y) tmpProvider.capacity = copy.deepcopy( data.PROVIDERS[i].capacity[geneSerial[i]]) tmpProvider.cost = copy.deepcopy( data.PROVIDERS[i].cost[geneSerial[i]]) sigmaCost = sigmaCost + tmpProvider.cost sigmaCapacity = sigmaCapacity + tmpProvider.capacity providers.append(tmpProvider) for item in customers: sigmaDemand = sigmaDemand + item.demand if sigmaCapacity >= sigmaDemand: swapchainsolver = SwapChainSolver(providers, customers) mmd = swapchainsolver.Solver() if mmd > D: fitness = -4.0 else: if sigmaCost != 0: fitness = float(4.0 / sigmaCost) else: fitness = 8.0 else: fitness = -8.0 # print("fitness,mmd,sigmaCapacity,sigmaCost,sigmaDemand:",fitness,mmd,sigmaCapacity,sigmaCost,sigmaDemand) return math.exp(fitness), mmd, sigmaCapacity, sigmaCost, sigmaDemand
def __init__(self, _name, _domain, _cc_index): Provider.__init__(self, _name, _domain, _cc_index)
proxies = get_proxy() # threadsssss start = time.time() if args.verify: providers = json.load(open('config.json', 'r'))['providers'] pall = [p for x in providers.values() for p in x] print(f'Processing {len(pall)} providers, please wait!\n') with ThreadPoolExecutor(max_workers=len(pall)) as executor: for config in pall: executor.submit( bomber, Provider(target, proxy=proxies, verbose=True, cc=str(args.country), config=config)) else: with ThreadPoolExecutor(max_workers=no_of_threads) as executor: for i in range(no_of_sms): p = Provider(target, proxy=proxies, verbose=args.verbose, cc=str(args.country)) executor.submit(bomber, p) end = time.time() # finalize print(f'\nSuccess: {success} | Failed: {failed}') print(f'Took {end-start:.2f}s to complete')
from starlette.applications import Starlette from starlette.staticfiles import StaticFiles from starlette.responses import HTMLResponse from starlette.responses import JSONResponse from starlette.templating import Jinja2Templates from Provider import Provider templates = Jinja2Templates(directory="templates") # not srtictly necessary app = Starlette(debug=True) app.mount("/static", StaticFiles(directory="statics"), name="static") p = Provider() @app.route("/") async def homepage(request): template = "index.html" context = {"request": request} return templates.TemplateResponse(template, context) @app.route("/oai") async def oai(request): q = request.query_params print("GH") if (err := p.validate_request(q)): return err if q['verb'] == "GetRecord": r = p.getRecord(request) elif q['verb'] == "Identify": r = p.identify(request)
from Provider import Provider a = Provider(risqueString='nlsn-b195e-c3750ep-01:01-Gi1/0/13') print(Provider.getHostFromProvider(a))
p.config['name'])) not args.verbose and not args.verify and print( f'Bombing : {success+fails}/{no_of_sms} | Success: {success} | Failed: {fails}', end='\r') # threadsssss start = time.time() if args.verify: conf = json.load(open('config.json', 'r'))['providers'] for key, value in conf.items(): if args.country and key != 'multi' and str(args.country) != key: continue for i in value: p = Provider(target, proxy=proxies, verbose=True, cc=str(args.country)) p.config = i p._headers() bomber(p) else: with ThreadPoolExecutor(max_workers=no_of_threads) as executor: for i in range(no_of_sms): p = Provider(target, proxy=proxies, verbose=args.verbose, cc=str(args.country)) executor.submit(bomber, (p)) end = time.time() # finalize
def main(): Provider.toCoordinates("175 5th Avenue NYC")
print(f'{dash}') print('[i] target [' + target + ']') print('[i] threads [' + str(no_of_threads) + ']') print('[i] sms [' + str(no_of_sms) + ']') print(f'{dash}\n') #threadsssss threads = [] for i in range(no_of_threads): t = Thread(target=bomber) t.start() threads.append(t) #bombing target with random providers for i in range(no_of_sms): q.put(Provider(target)) # block until all tasks are done q.join() # stop workers for i in range(no_of_threads): q.put(None) for t in threads: t.join() #finalize print(f'\n\n{dash}') print('[i] all completed') print('[i] ' + str(success) + ' succeed') print('[i] ' + str(fails) + ' failed')
from Provider import Provider from cloudmesh.common.util import path_expand # # TODO # location = path_expand(".cloudmesh/cloudmesh.yaml") p = Provider(service="azure", config=location) print(p.credentials)