def test_vpn(self): # Se obtienen las credenciales auth_driver = VaultAuthDriver(VAULT_TOKEN_TEST) providers_cred = auth_driver.get_providers_info('secret/projectVPN/') # Se obtiene driver driver1 = Driver.create(providers_cred[0]) driver2 = Driver.create(providers_cred[1]) # Se crea la red 1 network1 = driver1.networking.create_network(name="Bas7ionVPC-VPN-1", cidr="10.0.0.0/16") # Se crea las subred de la red 1 subnet1 = network1.create_subnet(name="Bas7ionSubnet-VPN-1", cidr="10.0.1.0/24") # Se crea la maquina virtual driver1.baseCompute.create_vm(name="Bas7ionVM-VPN-1", subnet=subnet1) # Se crea la red 2 network2 = driver2.networking.create_network(name="Bas7ionVPC-VPN-2", cidr="20.0.0.0/16") # Se crea las subred de la red 2 subnet2 = network2.create_subnet(name="Bas7ionSubnet-VPN-2", cidr="20.0.1.0/24") # Se crea la maquina virtual driver2.baseCompute.create_vm(name="Bas7ionVM-VPN-2", subnet=subnet2) Networking.connect_networks(network1, network2)
def test_all_operations(self): auth_driver = VaultAuthDriver('9c2547a0-d02d-20e5-82dd-c3be23e02573') provider_creds = auth_driver.get_providers_info('secret/project1') # Se obtiene driver de AWS aws_driver = Driver.create(provider_creds[0]) # Se listan las imagenes aws_images = aws_driver.baseCompute.list_images() print "AWS Images: ", len(aws_images) # Se listan los tamanos aws_sizes = aws_driver.baseCompute.list_sizes() print "AWS Sizes: ", len(aws_sizes) # Se listan las VMs aws_vms = aws_driver.baseCompute.list_vms() print "AWS VMs: ", len(aws_vms) # Se obtiene driver de Azure azure_driver = Driver.create(provider_creds[1]) # Se listan las imagenes azure_images = azure_driver.baseCompute.list_images() print "Azure Images: ", len(azure_images) # Se listan los tamanos azure_sizes = azure_driver.baseCompute.list_sizes() print "Azure Sizes: ", len(azure_sizes) # Se listan las VMs azure_vms = azure_driver.baseCompute.list_vms() print "Azure VMs: ", len(azure_vms)
def test_caso_exito(self): # Se obtienen las credenciales auth_driver = VaultAuthDriver(VAULT_TOKEN_TEST) aws_cred_1 = auth_driver.get_provider_info('secret/project1/aws-us-west-2') aws_cred_2 = auth_driver.get_provider_info('secret/project1/azure-us-west') # Se obtiene driver driver1 = Driver.create(aws_cred_1) # # Se obtiene driver driver2 = Driver.create(aws_cred_2) # Se crea la red 1 network1 = driver1.networking.create_network(name="Bas7ionVPC-1", cidr="10.0.0.0/16") # Se crea la red 1 network2 = driver2.networking.create_network(name="Bas7ionVPC-2", cidr="10.1.0.0/16") # Se crea las subred de la red 1 subnet1 = network1.create_subnet(name="Bas7ionSubnet-1", cidr="10.0.1.0/24") # Se crea las subred de la red 1 subnet2 = network2.create_subnet(name="Bas7ionSubnet-2", cidr="10.1.1.0/24") # Se crea la maquina virtual vm_db = driver2.baseCompute.create_vm(name="Bas7ionVM-DB", image_id='Canonical:UbuntuServer:14.04.5-LTS:latest', subnet=subnet2) # Se crea la maquina virtual vm_app = driver1.baseCompute.create_vm(name="Bas7ionVM-App", image_id='ami-a042f4d8', subnet=subnet1) Networking.connect_networks(network1, network2) mysql_playbook_path = 'playbooks/bennojoy-mysql.yml' redmine_playbook_path = 'playbooks/bngsudheer-redmine.yml' redmine_application_port = '8080' vm_db.provision(playbook_path=mysql_playbook_path) redmine_parameters =\ { 'database_host': vm_db.private_ips[0], 'application_port': redmine_application_port } vm_app.provision(playbook_path=redmine_playbook_path, parameters=json.dumps(redmine_parameters), user='******') security_group = network1.list_security_groups()[0] security_group.allow_inbound_traffic(redmine_application_port)
def test_dns(self): auth_driver = VaultAuthDriver(VAULT_TOKEN_TEST) cred = auth_driver.get_provider_info('secret/projectDNS/cred1') # Se obtiene driver driver = Driver.create(cred) # Se crea la red network = driver.networking.create_network(name="Bas7ionNetwork-DNS", cidr="30.0.0.0/16") # Se crean las subredes subnet1 = network.create_subnet(name="Bas7ionSubnet1-DNS", cidr="30.0.1.0/24") subnet2 = network.create_subnet(name="Bas7ionSubnet2-DNS", cidr="30.0.2.0/24") # Se crean las maquinas virtuales vm1 = driver.baseCompute.create_vm(name="Bas7ionVM1-DNS", subnet=subnet1) vm2 = driver.baseCompute.create_vm(name="Bas7ionVM2-DNS", subnet=subnet2) # Se agregan los mombres de las VM vm1.add_hostname("Bas7ionVM1-DNS-hostname", "bas7ion.com") vm2.add_hostname("Bas7ionVM2-DNS-hostname", "bas7ion.com")
def create_azure_vm(self): auth_driver = VaultAuthDriver('token', 'bas7ion') provider_creds = auth_driver.get_providers_info() # Se obtiene driver de Azure azure_driver = Driver.create(provider_creds[1]) vm = azure_driver.baseCompute.create_vm()
def test_sprint_3(self): auth_driver = VaultAuthDriver('token', 'bas7ion') provider_creds = auth_driver.get_providers_info() # Se obtiene driver de AWS aws_driver = Driver.create(provider_creds[0]) # Se crea la red network = aws_driver.networking.create_network(name="Bas7ionNetwork", cidr="10.0.0.0/16") # Se crea gateway para la red gateway = aws_driver.networking.create_gateway("Bas7ionGateway") # Asocia el gateway con la red network.attach_gateway(gateway) # Se crean las subredes subnet1 = network.create_subnet(name="Bas7ionSubnet1", cidr="10.0.0.0/24") subnet2 = network.create_subnet(name="Bas7ionSubnet2", cidr="10.0.1.0/24") # Busco Default RouteTable route_table = network.list_route_tables()[0] # Se agrega entrada en la tabla de ruteo para visibilidad entre subredes route_table.create_subnet_association(subnet1) route_table.create_subnet_association(subnet2) # Se agrega entrada por defecto al gateway route_table.create_route('0.0.0.0/0', gateway) # Busco default security group security_group = network.list_security_groups()[0] # Abro puertos del ssh y telnet security_group.allow_inbound_traffic(22) security_group.allow_inbound_traffic(23) # Se crean las interfaces de red nic1 = subnet1.create_nic(name="Bas7ionNetworkInterface1", private_ip="10.0.0.5") nic2 = subnet2.create_nic(name="Bas7ionNetworkInterface2", private_ip="10.0.1.5") # Se crean las maquinas virtuales vm1 = aws_driver.baseCompute.create_vm(name="Bas7ionVM1", subnet=subnet1, key_pair_name='aws_node') vm2 = aws_driver.baseCompute.create_vm(name="Bas7ionVM2", subnet=subnet2, key_pair_name='aws_node') # Se asocian las interfaces a las vms vm1.attach_nic(nic1) vm2.attach_nic(nic2) # Se provisiona la vm1 con la receta de mysql vm1.provision('/Users/laureanok/Documents/Bas7ion/ansible-receipts/wrappers/jenkins.yml', ['-vvvv']) # Se provisiona la vm2 con la receta de tomcat vm2.provision('/Users/laureanok/Documents/Bas7ion/ansible-receipts/wrappers/gitlab.yml', ['-vvvv'])
def test_sprint_6(self): auth_driver = VaultAuthDriver('token', 'bas7ion') provider_creds = auth_driver.get_providers_info() # Se obtiene driver de Amazon aws_driver = Driver.create(provider_creds[0]) # Se crea la red en Amazon aws_bastion_vpc = aws_driver.networking.create_network( name="vpn_bastion_vpc", cidr="16.16.0.0/16") # Se crea la subred privada en Amazon aws_bastion_priv_subnet = aws_bastion_vpc.create_subnet( name="vpn_bastion_priv_subnet", cidr="16.16.2.0/24") # Se crea la maquina virtual en la subred privada en amazon aws_driver.baseCompute.create_vm( name="vpn_bastion_vm_priv", subnet=aws_bastion_priv_subnet, public_key_file_path= '/Volumes/Datos/Users/diegomendez29/.ssh/id_rsa.pub') # Se obtiene driver de Azure azure_driver = Driver.create(provider_creds[1]) # Se crea la red en Azure azure_bastion_vpc = azure_driver.networking.create_network( name="bastion_vpc", cidr="10.1.0.0/16") # Se crea la subred rn Azure azure_bastion_priv_subnet = azure_bastion_vpc.create_subnet( name="bastion_priv_subnet", cidr="10.1.2.0/24") # Se crean las maquinas virtuales azure_driver.baseCompute.create_vm( name="bastion_vm_priv", subnet=azure_bastion_priv_subnet, public_key_file_path= '/Volumes/Datos/Users/diegomendez29/.ssh/id_rsa.pub') aws_driver.networking.connect_networks(aws_bastion_vpc, azure_bastion_vpc)
def create_network(self): auth_driver = VaultAuthDriver('token', 'bas7ion') provider_creds = auth_driver.get_providers_info() # Se obtiene driver de Azure azure_driver = Driver.create(provider_creds[1]) # Se crea la red network = azure_driver.networking.create_network(name="Bas7ionNetwork", cidr="10.0.0.0/16") # Se crea la subred subnet = network.create_subnet(name="Bas7ionSubnet", cidr="10.0.0.0/24")
def sprint_4(self): auth_driver = VaultAuthDriver('be30f966-9953-ee20-5cad-db98d7e58494') provider_creds = auth_driver.get_providers_info('secret/project1') # Se obtiene driver de Azure azure_driver = Driver.create(provider_creds[1]) cloud_driver = azure_driver.get_cloud_driver() cloud_driver.ex_update_network(cidr_block="10.0.0.0/16", name="Bas7ionNetwork", resource_group=azure_driver.prop.resource_group, location_id=azure_driver.prop.location_id, dns_server="10.0.0.20")
def test_create_aws_network(self): auth_driver = VaultAuthDriver('e38fe1a8-68f4-f5f7-7039-862136f565f8') cred = auth_driver.get_provider_info('secret/project1/aws') # Se obtiene driver driver = Driver.create(cred) # Se crea la red network = driver.networking.create_network(name="Bas7ionNetwork", cidr="10.0.0.0/16") # Se crean las subredes subnet1 = network.create_subnet(name="Bas7ionSubnet1", cidr="10.0.1.0/24") subnet2 = network.create_subnet(name="Bas7ionSubnet2", cidr="10.0.2.0/24")
def test_create_local_network_gateway(self): auth_driver = VaultAuthDriver('token', 'bas7ion') provider_creds = auth_driver.get_providers_info() # Se obtiene driver de Azure azure_driver = Driver.create(provider_creds[1]) libcloud = azure_driver.get_cloud_driver() locations = libcloud.list_locations() location = [ l for l in locations if l.name == azure_driver.prop.location_id ][0] r = libcloud.ex_create_local_network_gateway("TestLocalNetworkGateway", "192.168.0.0/16", "52.89.14.84", "LibcloudRG071407", location=location)
def test_sprint_4(self): auth_driver = VaultAuthDriver('48116d15-9d2f-669e-a0c4-eb8e6a0cbf2b') secrets = auth_driver.get_provider_info('secret/project1/') # Se obtiene driver de Azure cloud_provider_driver = Driver.create(secrets[1]) # Se crea la red network = cloud_provider_driver.networking.create_network(name="Bas7ionNetwork", cidr="10.0.0.0/16") # Se crean las subredes subnet = network.create_subnet(name="Bas7ionSubnet1", cidr="10.0.0.16/28") # Se crea la VM vm = cloud_provider_driver.baseCompute.create_vm(name="Bas7ionVM1", subnet=subnet, public_key_file_path='/Users/laureanok/.ssh/id_rsa.pub') # Se provisiona la vm con una receta vm.provision(playbook_path='/Users/laureanok/Documents/Bas7ion/ansible-receipts/wrappers/mysql.yml', additional_options=['-vvvv'])
import math from bastion.authentication.vault import VaultAuthDriver from bastion.driver import Driver from bastion.networking.base import Networking from utils import VAULT_TOKEN_TEST start_time = time.time() # Se obtienen las credenciales auth_driver = VaultAuthDriver(VAULT_TOKEN_TEST) aws_cred = auth_driver.get_provider_info('secret/casoexito/aws') azure_cred = auth_driver.get_provider_info('secret/casoexito/azure') # Se obtiene driver de AWS driver_aws = Driver.create(aws_cred) # # Se obtiene driver de Azure driver_azure = Driver.create(azure_cred) # Se crea la red de AWS network_aws = driver_aws.networking.create_network(name="Bas7ionVPC-CE-App", cidr="200.0.0.0/16") # Se crea la red de Azure network_azure = driver_azure.networking.create_network(name="Bas7ionVPC-CE-DB", cidr="200.1.0.0/16") # Se crea las subred de AWS subnet_aws = network_aws.create_subnet(name="Bas7ionSubnet-CE-App", cidr="200.0.1.0/24")
def test_compute(self): auth_driver = VaultAuthDriver(VAULT_TOKEN_TEST) cred = auth_driver.get_provider_info('secret/credCompute') # Se obtiene driver driver = Driver.create(cred) # Se listan las imagenes images = driver.baseCompute.list_images() print "Images:" for image in images: text = "Id: " + image.id if image.name is not None: text = text + " Name: " + image.name print text # Se listan los tamanos sizes = driver.baseCompute.list_sizes() print "Sizes:" for size in sizes: text = "Id: " + size.id if size.name is not None: text = text + " Name: " + size.name print text # Create Virtual Machine vms1 = driver.baseCompute.create_vm(name="Bas7ionVM1-Compute") # Agrego una nueva interfaz a la VM subnet_ips = IPNetwork(vms1.subnet.cidr) new_private_ip = None index = 2 while new_private_ip is None: if subnet_ips[index] != vms1.private_ips[0]: new_private_ip = subnet_ips[index] index = index + 1 vms1.attach_nic(vms1.subnet.create_nic(new_private_ip, "Bas7ionVM1-Compute-nic2")) # Create Virtual Machine vms2 = driver.baseCompute.create_vm(name="Bas7ionVM2-Compute", add_public_ip=False) # Se listan las VMs vms = driver.baseCompute.baseCompute.list_vms() print "VMs:" for vm in vms: text = "Id: " + vm.id + " Name: " + vm.name print text # Se apaga la maquina virtual vms1.stop() # Se inicia la maquina virtual vms1.start() # Se reinicia la maquina virtual vms2.restart() # Se aproviciona la maquina virtual vms1.provision(playbook_path="playbooks/bennojoy-mysql.yml", user="******") # Se elimina la maquina virtual vms1.delete() vms2.delete()