def setUp(self): EC2MockHttp.test = self EC2NodeDriver.connectionCls.conn_classes = (None, EC2MockHttp) EC2MockHttp.use_param = 'Action' EC2MockHttp.type = None self.driver = EC2NodeDriver(*EC2_PARAMS, **{'region': self.region})
def __init__(self, key, secret=None, secure=True, host=None, port=None, region='us-east-1', **kwargs): if hasattr(self, '_region'): region = self._region details = AUTOSCALE_REGION_DETAILS[region] self.region_name = region self.api_name = details['api_name'] self.country = details['country'] host = host or details['endpoint'] self.signature_version = details.pop('signature_version', '2') if kwargs.get('ec2_driver'): self.ec2 = kwargs['ec2_driver'] else: self.ec2 = EC2NodeDriver(key, secret=secret, region=region, **kwargs) super(AutoScalingDriver, self).__init__(key=key, secret=secret, secure=secure, host=host, port=port, **kwargs)
def test_instantiate_driver_invalid_datacenters(self): for datacenter in ['invalid', 'nimbus']: try: EC2NodeDriver(*EC2_PARAMS, **{'datacenter': datacenter}) except ValueError: pass else: self.fail('Invalid region, but exception was not thrown')
def test_instantiate_driver_invalid_regions(self): for region in ['invalid', 'nimbus']: try: EC2NodeDriver(*EC2_PARAMS, **{'region': region}) except ValueError: pass else: self.fail('Invalid region, but exception was not thrown')
def setUp(self): EC2MockHttp.test = self EC2NodeDriver.connectionCls.conn_classes = (None, EC2MockHttp) EC2MockHttp.use_param = 'Action' EC2MockHttp.type = None self.driver = EC2NodeDriver(EC2_ACCESS_ID, EC2_SECRET)
def test_instantiate_driver_valid_datacenters(self): datacenters = REGION_DETAILS.keys() datacenters = [d for d in datacenters if d != 'nimbus'] for datacenter in datacenters: EC2NodeDriver(*EC2_PARAMS, **{'datacenter': datacenter})
def test_instantiate_driver_valid_regions(self): regions = REGION_DETAILS.keys() regions = [d for d in regions if d != 'nimbus'] for region in regions: EC2NodeDriver(*EC2_PARAMS, **{'region': region})
def test_instantiate_driver_valid_datacenters(self): datacenters = REGION_DETAILS.keys() datacenters.remove('nimbus') for datacenter in datacenters: EC2NodeDriver(*EC2_PARAMS, datacenter=datacenter)
def getLocations(provider, driverUno, driverDos, driverTres, driverCuatro): pass nodesProvider = '' if provider == "Digital Ocean": pass accessKey = driverUno driverDos = driverDos driverTres = driverTres driverCuatro = driverCuatro driver = DigitalOceanNodeDriver(accessKey) listLocations = driver.list_locations() nodelocations = [] for listLocation in listLocations: data = [] flag = False matches = re.search(r'[a-zA-Z]{0,}', listLocation.name) match = re.search(r'[a-zA-Z]{0,}[ ][a-zA-Z]{0,}', listLocation.name) if match: region = match.group() else: region = matches.group() for nodelocation in nodelocations: if nodelocation['city'] == region: datacenter = { 'id': listLocation.id, 'name': listLocation.name } nodelocation['datacenter'].append(datacenter) flag = True if flag != True: datacenter = {'id': listLocation.id, 'name': listLocation.name} data.append(datacenter) node = {'country': 'null', 'city': region, 'datacenter': data} nodelocations.append(node) nodesProvider = json.dumps(nodelocations) if provider == "EC2": pass accessId = driverUno secretKey = driverDos region = driverTres driverCuatro = driverCuatro driver = EC2NodeDriver(accessId, secretKey) listRegions = driver.list_regions() # print listRegions nodelocations = [] for listRegion in listRegions: region = listRegion if region == 'ap-south-1': pass region = 'ap-southeast-1' if region == 'us-east-2': pass region = 'us-east-1' if region == 'cn-north-1': pass region = 'us-east-1' if region == 'ca-central-1': pass region = 'us-east-1' if region == 'ap-northeast-2': pass region = 'ap-northeast-1' if region == 'us-gov-west-1': pass region = 'us-east-1' if region == 'eu-central-1': pass region = 'eu-west-1' if region == 'eu-west-2': pass region = 'eu-west-1' driverLocation = EC2NodeDriver(accessId, secretKey, None, None, None, region, None) listLocations = driverLocation.list_locations() # print region # print listLocations datacenterArray = [] for listLocation in listLocations: flag = False for nodelocation in nodelocations: if 'country' in nodelocation: if nodelocation['country'] == listLocation.country: datacenter = { 'id': listLocation.name, 'name': listLocation.name } datacenterArray.append(datacenter) flag = True if flag != True: datacenter = { 'id': listLocation.name, 'name': listLocation.name } datacenterArray.append(datacenter) regionName = getRegionName.regionsAmazon(listRegion) if regionName != 'null': regionID = { 'country': listLocation.country, 'city': regionName, 'datacenter': datacenterArray } nodelocations.append(regionID) nodesProvider = json.dumps(nodelocations) if provider == "Azure": pass tenantId = driverUno subscriptionId = driverDos applicationId = driverTres keyPaswd = driverCuatro driver = AzureNodeDriver(tenantId, subscriptionId, applicationId, keyPaswd) listLocations = driver.list_locations() nodelocations = [] for listLocation in listLocations: data = [] flag = False country = listLocation.country if country is not None: pass matches = country.partition(',') if matches[1] == ',': dos = matches[2] country = dos[1:len(dos)] city = matches[0] for nodelocation in nodelocations: if nodelocation['city'] == city: datacenter = { 'id': listLocation.id, 'name': listLocation.name } nodelocation['datacenter'].append(datacenter) flag = True if flag != True: datacenter = { 'id': listLocation.id, 'name': listLocation.name } data.append(datacenter) node = { 'country': country, 'city': city, 'datacenter': data } nodelocations.append(node) else: city = 'null' datacenter = { 'id': listLocation.id, 'name': listLocation.name } data.append(datacenter) node = { 'country': country, 'city': city, 'datacenter': data } nodelocations.append(node) else: city = getRegionName.regionsAzure(listLocation.name) country = 'null' datacenter = {'id': listLocation.id, 'name': listLocation.name} data.append(datacenter) node = {'country': country, 'city': city, 'datacenter': data} nodelocations.append(node) nodesProvider = json.dumps(nodelocations) if provider == "Linode": pass apiKey = driverUno driverDos = driverDos driverTres = driverTres driverCuatro = driverCuatro driver = DigitalOceanNodeDriver(apiKey) listLocations = driver.list_locations() nodesProvider = listLocations return nodesProvider
if flag != True: datacenter = {'id': listLocation.id, 'name': listLocation.name} data.append(datacenter) node = {'country': 'null', 'city': region, 'datacenter': data} nodelocations.append(node) print json.dumps(nodelocations) if provider == "EC2": pass accessId = sys.argv[2] secretKey = sys.argv[3] driverTres = sys.argv[4] driverCuatro = sys.argv[5] driver = EC2NodeDriver(accessId, secretKey) listRegions = driver.list_regions() # print listRegions nodelocations = [] for listRegion in listRegions: region = listRegion if region == 'ap-south-1': pass region = 'ap-southeast-1' if region == 'us-east-2': pass