def setUp(self):
     DigitalOceanNodeDriver.connectionCls.conn_class = \
         DigitalOceanMockHttp
     DigitalOceanMockHttp.type = None
     self.driver = DigitalOceanNodeDriver(*DIGITALOCEAN_v2_PARAMS)
Esempio n. 2
0
def deleteNode(provider,driverUno,driverDos,driverTres,driverCuatro,nodeId):
	pass
	nodesProvider = ''
	if provider == "Digital Ocean":
		pass
		accessKey = driverUno
		driverDos = driverDos
		driverTres = driverTres
		driverCuatro = driverCuatro
		nodeId = nodeId
		driver = DigitalOceanNodeDriver(accessKey)
		
		idsNodes = driver.list_nodes()

		for idNodes in idsNodes:
			#print idsNodes
			if idNodes.id == nodeId:
				pass
				idNod = idNodes
	#			print idNod
				nodeDelete = driver.destroy_node(idNod)

				types = 'terminated'

				node = checkStatus.checkStatus(driver, idNod.id, types)

				if node != 0:
					nodesProvider = nodeDelete

	if provider == "EC2":
		pass
		accessId = driverUno
		secretKey = driverDos
		region = driverTres
		driverCuatro = driverCuatro
		nodeId = nodeId
	#	driver = BaseEC2NodeDriver(accessId,secretKey,'eu-west-1')

		cls = get_driver(Provider.EC2)
		driver = cls(accessId, secretKey, region=region)

		idsNodes = driver.list_nodes()

		for idNodes in idsNodes:
			#print idsNodes
			if idNodes.id == nodeId:
				pass
				idNod = idNodes
	#			print idNod
				public_ips = driver.ex_describe_all_addresses(only_associated = True)

				for public_ip in public_ips:

					if public_ip.instance_id == idNod.id:
						ip = public_ip
						
						nodeDelete = driver.destroy_node(idNod)

						driver.ex_release_address(ip, domain = ip.domain)

						types = 'terminated'

						node = checkStatus.checkStatus(driver, idNod.id, types)

						if node != 0:
							nodesProvider = nodeDelete
						else:
							nodesProvider = 'null'

	if provider == "Azure":
		pass
		tenantId = driverUno
		subscriptionId = driverDos
		applicationId = driverTres
		keyPaswd = driverCuatro
		nodeId = nodeId
		driver = AzureNodeDriver(tenantId,subscriptionId,applicationId,keyPaswd)

		idsNodes = driver.list_nodes()

		for idNodes in idsNodes:
			#print idsNodes
			if idNodes.id == nodeId:
				pass
				idNod = idNodes
	#			print idNod

				nodeDelete = driver.destroy_node(idNod)

				types = 'terminated'

				node = checkStatus.checkStatus(driver, idNod.id, types)

				if node != 0:
					nodesProvider = nodeDelete



	if provider == "Linode":
		pass
		apiKey = driverUno
		driverDos = driverDos
		driverTres = driverTres
		driverCuatro = driverCuatro
		nodeId = nodeId
		driver = LinodeNodeDriver(apiKey)

		idsNodes = driver.list_nodes()

		for idNodes in idsNodes:
			#print idsNodes
			if idNodes.id == nodeId:
				pass
				idNod = idNodes
	#			print idNod
				nodeDelete = driver.destroy_node(idNod)

				types = 'terminated'

				node = checkStatus.checkStatus(driver, idNod.id, types)

				if node != 0:
					nodesProvider = nodeDelete

	return nodesProvider
Esempio n. 3
0
def shutdownNode(provider, driverUno, driverDos, driverTres, driverCuatro,
                 nodeId):
    pass
    nodesProvider = ''
    if provider == "Digital Ocean":
        pass
        accessKey = driverUno
        driverDos = driverDos
        driverTres = driverTres
        driverCuatro = driverCuatro
        nodeId = nodeId
        driver = DigitalOceanNodeDriver(accessKey)

        idsNodes = driver.list_nodes()

        for idNodes in idsNodes:
            #print idsNodes
            if idNodes.id == nodeId:
                pass
                idNod = idNodes
                #			print idNod
                nodeStopped = driver.ex_shutdown_node(idNod)

                types = 'stopped'

                node = checkStatus.checkStatus(driver, idNod.id, types)

                if node != 0:
                    nodesProvider = nodeStopped

    if provider == "EC2":
        pass
        accessId = driverUno
        secretKey = driverDos
        region = driverTres
        driverCuatro = driverCuatro
        nodeId = nodeId
        #	driver = BaseEC2NodeDriver(accessId,secretKey,'eu-west-1')

        cls = get_driver(Provider.EC2)
        driver = cls(accessId, secretKey, region=region)

        idsNodes = driver.list_nodes()

        for idNodes in idsNodes:
            #print idsNodes
            if idNodes.id == nodeId:
                pass
                idNod = idNodes
                #			print idNod
                nodeStopped = driver.ex_stop_node(idNod)

                types = 'stopped'

                node = checkStatus.checkStatus(driver, idNod.id, types)

                if node != 0:
                    nodesProvider = nodeStopped

    if provider == "Azure":
        pass
        tenantId = driverUno
        subscriptionId = driverDos
        applicationId = driverTres
        keyPaswd = driverCuatro
        nodeId = nodeId
        driver = AzureNodeDriver(tenantId, subscriptionId, applicationId,
                                 keyPaswd)

        idsNodes = driver.list_nodes()

        for idNodes in idsNodes:
            #print idsNodes
            if idNodes.id == nodeId:
                pass
                idNod = idNodes
                #			print idNod
                nodeStopped = driver.ex_stop_node(idNod)

                types = 'stopped'

                node = checkStatus.checkStatus(driver, idNod.id, types)

                if node != 0:
                    nodesProvider = nodeStopped

    if provider == "Linode":
        pass
        apiKey = driverUno
        driverDos = driverDos
        driverTres = driverTres
        driverCuatro = driverCuatro
        nodeId = nodeId
        driver = LinodeNodeDriver(apiKey)

        idsNodes = driver.list_nodes()

        for idNodes in idsNodes:
            #print idsNodes
            if idNodes.id == nodeId:
                pass
                idNod = idNodes
                #			print idNod
                nodeStopped = driver.ex_stop_node(idNod)

                types = 'stopped'

                node = checkStatus.checkStatus(driver, idNod.id, types)

                if node != 0:
                    nodesProvider = nodeStopped

    return nodesProvider
def resizeNode(provider, driverUno, driverDos, driverTres, driverCuatro, size,
               nodeId):
    pass
    nodesProvider = ''
    if provider == "Digital Ocean":
        pass
        accessKey = driverUno
        driverDos = driverDos
        driverTres = driverTres
        driverCuatro = driverCuatro
        size = size
        nodeId = nodeId
        driver = DigitalOceanNodeDriver(accessKey)

        idsNodes = driver.list_nodes()
        sizesNode = driver.list_sizes()

        for idNodes in idsNodes:
            #print idsNodes
            if idNodes.id == nodeId:
                pass
                idNod = idNodes
    #			print idNod

        for sizeNode in sizesNode:
            if sizeNode.name == size:
                pass
                sizeName = sizeNode

                nodesProvider = driver.resize_node(sizeName, idNod)

    if provider == "EC2":
        pass
        accessId = driverUno
        secretKey = driverDos
        region = driverTres
        driverCuatro = driverCuatro
        size = size
        nodeId = nodeId
        #	driver = BaseEC2NodeDriver(accessId,secretKey,'eu-west-1')

        cls = get_driver(Provider.EC2)
        driver = cls(accessId, secretKey, region=region)

        idsNodes = driver.list_nodes()
        sizesNode = driver.list_sizes()

        idNod = ''
        sizeName = ''

        for idNodes in idsNodes:
            #print idsNodes
            if idNodes.id == nodeId:
                pass
                idNod = idNodes
    #			print idNod

        for sizeNode in sizesNode:
            if sizeNode.id == size:
                pass
                sizeName = sizeNode

        nodesProvider = driver.ex_change_node_size(idNod, sizeName)
    if provider == "Azure":
        pass
        tenantId = driverUno
        subscriptionId = driverDos
        applicationId = driverTres
        keyPaswd = driverCuatro
        size = size
        nodeId = nodeId
        driver = AzureNodeDriver(tenantId, subscriptionId, applicationId,
                                 keyPaswd)

        idsNodes = driver.list_nodes()
        sizesNode = driver.list_sizes()

        for idNodes in idsNodes:
            #print idsNodes
            if idNodes.id == nodeId:
                pass
                idNod = idNodes
    #			print idNod

        for sizeNode in sizesNode:
            if sizeNode.name == size:
                pass
                sizeName = sizeNode

                nodesProvider = driver.resize_node(sizeName, idNod)

    if provider == "Linode":
        pass
        apiKey = driverUno
        driverDos = driverDos
        driverTres = driverTres
        driverCuatro = driverCuatro
        size = size
        nodeId = nodeId
        driver = LinodeNodeDriver(apiKey)

        idsNodes = driver.list_nodes()
        sizesNode = driver.list_sizes()

        for idNodes in idsNodes:
            #print idsNodes
            if idNodes.id == nodeId:
                pass
                idNod = idNodes
    #			print idNod

        for sizeNode in sizesNode:
            if sizeNode.name == size:
                pass
                sizeName = sizeNode

                nodesProvider = driver.ex_resize_node(sizeName, idNod)

    return nodesProvider
Esempio n. 5
0
 def setUp(self):
     DigitalOceanNodeDriver.connectionCls.conn_classes = \
         (None, DigitalOceanMockHttp)
     DigitalOceanMockHttp.type = None
     self.driver = DigitalOceanNodeDriver(*DIGITAL_OCEAN_PARAMS)
def getAllNodes(provider, driverUno, driverDos, driverTres, driverCuatro):
    pass
    nodesProvider = ''
    node = []
    if provider == "Digital Ocean":
        pass
        accessKey = driverUno
        driverDos = driverDos
        driverTres = driverTres
        driverCuatro = driverCuatro
        driver = DigitalOceanNodeDriver(accessKey)

        idsNodes = driver.list_nodes()

        for idNodes in idsNodes:
            #print idsNodes
            pass
            idNodes.extra = json.dumps(idNodes.extra)
            attr = {
                'id': idNodes.id,
                'name': idNodes.name,
                'state': idNodes.state,
                'public_ips': idNodes.public_ips,
                'private_ips': idNodes.private_ips,
                'provider': 'DigitalOcean',
                'extra': idNodes.extra
            }

            node.append(attr)

        nodesProvider = json.dumps(attr)
    if provider == "EC2":
        pass
        accessId = driverUno
        secretKey = driverDos
        region = driverTres
        driverCuatro = driverCuatro
        #	driver = BaseEC2NodeDriver(accessId,secretKey,'eu-west-1')

        cls = get_driver(Provider.EC2)
        driver = cls(accessId, secretKey, region=region)

        nodes = driver.list_nodes()

        nodeFunction = []
        for node in nodes:
            pass
            if node.state != 'terminated':

                v4 = []
                ips = {
                    'ipaddress': node.public_ips[0],
                    'gateway': 'NULL',
                    'mask': 'NULL',
                    'private_ip': node.private_ips[0]
                }

                v4.append(ips)

                network = {'v4': v4}

                extra = {
                    'launch_time': node.extra['launch_time'],
                    'instance_type': node.extra['instance_type'],
                    'network': network
                }

                attr = {
                    'id': node.id,
                    'region': region,
                    'name': node.name,
                    'state': node.state,
                    'public_ip': node.public_ips[0],
                    'provider': 'Amazon',
                    'extra': extra
                }

                nodeFunction.append(json.dumps(attr))
        nodesProvider = nodeFunction

    if provider == "Azure":
        pass
        tenantId = driverUno
        subscriptionId = driverDos
        applicationId = driverTres
        keyPaswd = driverCuatro
        driver = AzureNodeDriver(tenantId, subscriptionId, applicationId,
                                 keyPaswd)

        nodes = driver.list_nodes()

        print nodes

    if provider == "Linode":
        pass
        apiKey = driverUno
        driverDos = driverDos
        driverTres = driverTres
        driverCuatro = driverCuatro
        driver = LinodeNodeDriver(apiKey)

        nodes = driver.list_nodes()

        nodesProvider = nodes
    return nodesProvider
def createNode(provider, driverUno, driverDos, driverTres, driverCuatro, name,
               size, image, location, ex_network):
    pass
    nodesProvider = ''
    if provider == "Digital Ocean":
        pass
        accessKey = driverUno
        sshKey = driverDos
        driverTres = driverTres
        driverCuatro = driverCuatro
        driver = DigitalOceanNodeDriver(accessKey)

        sshKeyID = list()

        ssh = int(sshKey)
        keyPairs = driver.list_key_pairs()
        sizesNode = driver.list_sizes()
        imagesNode = driver.list_images()
        locationsNode = driver.list_locations()

        for keyPair in keyPairs:
            if keyPair.extra['id'] == ssh:
                pass
                sshKeyID.append(keyPair.extra['id'])

        for sizeNode in sizesNode:
            if sizeNode.name == size:
                pass
                sizeName = sizeNode

        for imageNode in imagesNode:
            if imageNode.id == image:
                pass
                imageId = imageNode

        for locationNode in locationsNode:
            if locationNode.id == location:
                pass
                locationId = locationNode

        idNodes = driver.create_node(name, sizeName, imageId, locationId, None,
                                     sshKeyID, None)
        idNodes.extra = json.dumps(idNodes.extra)
        attr = {
            'id': idNodes.id,
            'name': idNodes.name,
            'state': idNodes.state,
            'public_ips': idNodes.public_ips,
            'private_ips': idNodes.private_ips,
            'provider': 'DigitalOcean',
            'extra': idNodes.extra
        }

        nodesProvider = json.dumps(attr)
    if provider == "EC2":
        pass
        accessId = driverUno
        secretKey = driverDos
        region = driverTres
        driverCuatro = driverCuatro
        reg = region[0:len(region) - 1]
        #	driver = BaseEC2NodeDriver(accessId,secretKey,'eu-west-1')

        cls = get_driver(Provider.EC2)
        driver = cls(accessId, secretKey, region=reg)

        sizesNode = driver.list_sizes()
        imagesNode = driver.list_images()

        sizeName = ''
        imageId = ''

        for sizeNode in sizesNode:
            if sizeNode.id == size:
                pass
                sizeName = sizeNode

        for imageNode in imagesNode:
            if imageNode.name == image:
                pass
                imageId = imageNode

        nodeCreate = driver.create_node(name=name,
                                        image=imageId,
                                        size=sizeName)

        types = 'running'

        node = checkStatus.checkStatus(driver, nodeCreate.id, types)

        if node != 0:
            pass
            elastic = elasticIP.setElasticIP(driver, node.id)
            if elastic != 0:
                pass
                v4 = []
                ips = {
                    'ipaddress': elastic.ip,
                    'gateway': 'NULL',
                    'mask': 'NULL',
                    'private_ip': node.private_ips[0]
                }

                v4.append(ips)

                network = {'v4': v4}

                extra = {
                    'launch_time': node.extra['launch_time'],
                    'instance_type': node.extra['instance_type'],
                    'network': network
                }

                attr = {
                    'id': node.id,
                    'region': reg,
                    'name': node.name,
                    'state': node.state,
                    'public_ip': elastic.ip,
                    'provider': 'Amazon',
                    'extra': extra
                }

                print json.dumps(attr)
            else:
                v4 = []
                ips = {
                    'ipaddress': node.public_ips[0],
                    'gateway': 'NULL',
                    'mask': 'NULL',
                    'private_ip': node.private_ips[0]
                }

                v4.append(ips)

                network = {'v4': v4}

                extra = {
                    'launch_time': node.extra['launch_time'],
                    'instance_type': node.extra['instance_type'],
                    'network': network
                }

                attr = {
                    'id': node.id,
                    'region': region,
                    'name': node.name,
                    'state': node.state,
                    'public_ip': node.public_ips[0],
                    'provider': 'Amazon',
                    'extra': extra,
                    'elastic': '0'
                }

            nodesProvider = json.dumps(attr)

    if provider == "Azure":
        pass
        tenantId = driverUno
        subscriptionId = driverDos
        applicationId = driverTres
        keyPaswd = driverCuatro
        driver = AzureNodeDriver(tenantId, subscriptionId, applicationId,
                                 keyPaswd)

        locations = driver.list_locations()
        networks = driver.ex_list_networks()

        for network in networks:
            pass
            if network.name == ex_network:
                pass
                ex_network = network

        for loc in locations:
            pass
            if loc.id == location:
                pass
                locationID = loc

        sizesNode = driver.list_sizes(location=locationID)
        imagesNode = driver.list_images(location=locationID,
                                        ex_publisher=None,
                                        ex_offer=None,
                                        ex_sku=None,
                                        ex_version=None)
        for sizeNode in sizesNode:
            if sizeNode.name == size:
                pass
                sizeName = sizeNode

        for imageNode in imagesNode:
            if imageNode.id == image:
                pass
                imageId = imageNode

        nodeCreate = driver.create_node(name,
                                        sizeName,
                                        imageId,
                                        None,
                                        None,
                                        None,
                                        location=locationID,
                                        ex_network=ex_network,
                                        ex_subnet=None,
                                        ex_nic=None)

        types = 'running'

        node = checkStatus.checkStatus(driver, nodeCreate.id, types)

        if node != 0:
            pass
            v4 = []
            ips = {
                'ipaddress': node.public_ips,
                'gateway': 'NULL',
                'mask': 'NULL',
                'private_ip': node.private_ips
            }

            v4.append(ips)

            network = {'v4': v4}

            extra = {
                'instance_type':
                node.extra['properties']['hardwareProfile']['vmSize'],
                'network':
                network
            }

            attr = {
                'id': node.extra['properties']['vmId'],
                'region': node.extra['location'],
                'name': node.name,
                'state': node.state,
                'public_ip': node.public_ips,
                'provider': 'Azure Virtual machines',
                'extra': extra
            }

            nodesProvider = json.dumps(attr)

    if provider == "Linode":
        pass
        apiKey = driverUno
        driverDos = driverDos
        driverTres = driverTres
        driverCuatro = driverCuatro
        nodeId = nodeId
        driver = LinodeNodeDriver(apiKey)

        node = driver.create_node(name, image, size, auth, location)
        nodesProvider = json.dumps(node)

    return nodesProvider
def getNode(provider,driverUno,driverDos,driverTres,driverCuatro,nodeId):
	pass
	nodesProvider = ''
	if provider == "Digital Ocean":
		pass
		accessKey = driverUno
		driverDos = driverDos
		driverTres = driverTres
		driverCuatro = driverCuatro
		nodeId = nodeId
		driver = DigitalOceanNodeDriver(accessKey)
		
		idsNodes = driver.list_nodes()
		
		for idNodes in idsNodes:
		#print idsNodes
			if idNodes.id == nodeId:
				pass
				idNod = idNodes
	#			print idNod
				idNod.extra = json.dumps(idNod.extra);
				attr = {'id' : idNod.id, 'name' : idNod.name, 
				'state' : idNod.state, 'public_ips' : idNod.public_ips, 
				'private_ips' : idNod.private_ips, 'provider' : 'DigitalOcean',
				'extra' : idNod.extra}

				nodesProvider = json.dumps(attr)
	if provider == "EC2":
		pass
		accessId = driverUno
		secretKey = driverDos
		region = driverTres
		driverCuatro = driverCuatro
		nodeId = nodeId
	#	driver = BaseEC2NodeDriver(accessId,secretKey,'eu-west-1')

		cls = get_driver(Provider.EC2)
		driver = cls(accessId, secretKey, region=region)

		idsNodes = driver.list_nodes()

		for idNodes in idsNodes:
			#print idsNodes
			if idNodes.id == nodeId:
				pass
				node = idNodes

				if node.state == 'terminated':
					v4 = []
					ips = {'ipaddress' : node.public_ips, 'gateway' : 'NULL', 'mask' : 'NULL', 'private_ip' : node.private_ips}

					v4.append(ips)

					network = {'v4' : v4}


					extra = {'launch_time' : node.extra['launch_time'], 'instance_type' : node.extra['instance_type'],
					'network' : network}

					attr = {'id' : node.id, 'region' : region, 'name': node.name, 'state' : node.state, 
					'public_ip' : node.public_ips, 'provider' : 'Amazon', 'extra' : extra}
				if node.state != 'terminated':
					v4 = []
					ips = {'ipaddress' : node.public_ips[0], 'gateway' : 'NULL', 'mask' : 'NULL', 'private_ip' : node.private_ips[0]}

					v4.append(ips)

					network = {'v4' : v4}


					extra = {'launch_time' : node.extra['launch_time'], 'instance_type' : node.extra['instance_type'],
					'network' : network}

					attr = {'id' : node.id, 'region' : region, 'name': node.name, 'state' : node.state, 
					'public_ip' : node.public_ips[0], 'provider' : 'Amazon', 'extra' : extra} 

			nodesProvider = json.dumps(attr)
	if provider == "Azure":
		pass
		tenantId = driverUno
		subscriptionId = driverDos
		applicationId = driverTres
		keyPaswd = driverCuatro
		nodeId = nodeId
		driver = AzureNodeDriver(tenantId,subscriptionId,applicationId,keyPaswd)

		idsNodes = driver.list_nodes()

		for idNodes in idsNodes:
			#print idsNodes
			if idNodes.id == nodeId:
				pass
				node = idNodes
	#			print idNod
				v4 = []
				ips = {'ipaddress' : node.public_ips, 'gateway' : 'NULL', 'mask' : 'NULL', 'private_ip' : node.private_ips}

				v4.append(ips)

				network = {'v4' : v4}


				extra = {'instance_type' : node.extra['properties']['hardwareProfile']['vmSize'],
				'network' : network}

				attr = {'id' : node.extra['properties']['vmId'], 'region' : node.extra['location'], 'name': node.name, 'state' : node.state, 
				'public_ip' : node.public_ips, 'provider' : 'Azure Virtual machines', 'extra' : extra} 

				nodesProvider = json.dumps(node)

	if provider == "Linode":
		pass
		apiKey = driverUno
		driverDos = driverDos
		driverTres = driverTres
		driverCuatro = driverCuatro
		nodeId = nodeId
		driver = LinodeNodeDriver(apiKey)

		for idNodes in idsNodes:
			#print idsNodes
			if idNodes.id == nodeId:
				pass
				idNod = idNodes
	#			print idNod

				nodesProvider = json.dumps(idNod)

	return nodesProvider
Esempio n. 9
0
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
import getRegionName
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
from libcloud.compute.drivers.digitalocean import DigitalOceanNodeDriver
from libcloud.compute.drivers.azure_arm import AzureNodeDriver
from libcloud.compute.drivers.ec2 import BaseEC2NodeDriver, EC2NodeDriver
from libcloud.compute.drivers.linode import LinodeNodeDriver

provider = sys.argv[1]
if provider == "Digital Ocean":
    pass
    accessKey = sys.argv[2]
    sshKey = sys.argv[3]
    driverTres = sys.argv[4]
    driverCuatro = sys.argv[5]
    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()