def create_tenant(self,tenant_conf,tenant_index): tenant_name_pattern = tenant_conf['name'] tenant_name = re.sub("XXX",str(tenant_index),tenant_name_pattern) #tenant_obj = PerTenant(self.vnc_lib,self.connections,tenant_conf,tenant_index) #tenant_id = tenant_obj.tenant_project_obj.create(tenant_name) tenant_obj = ConfigProject(self.connections) tenant_id = tenant_obj.create(tenant_name) tenant_obj.tenant_id = tenant_id self.db.set_project_id(tenant_name,tenant_id) tenant_connections = tenant_obj.get_connections() tenant_obj.update_default_sg(uuid=tenant_id) import pdb;pdb.set_trace() ipam_name_pattern = tenant_conf['virtual_networks']['IPAM']['name'] vm_index = 0 tenant_obj.create_tenant_nova_client() vm_name_pattern = tenant_conf['virtual_networks']['virtual_machines']['name'] ipam_name_pattern = tenant_conf['virtual_networks']['IPAM']['name'] data_domain_name_pattern = tenant_conf['virtual_networks']['vDNS'][1]['domain_name'] vn_name_pattern = tenant_conf['virtual_networks']['data_vn_name'] vns_count = tenant_conf['virtual_networks']['count'] vm_count = tenant_conf['virtual_networks']['virtual_machines']['count'] data_ipam_name = re.sub('XXX',str(tenant_index),ipam_name_pattern) data_ipam_name = re.sub('ZZZ','2',data_ipam_name) data_ipam_name = re.sub('CCC','data',data_ipam_name) data_domain_name = re.sub('XXX',str(tenant_index),data_domain_name_pattern) data_domain_name = re.sub('ZZZ','2',data_domain_name) data_vdns_id = self.global_vdns[data_domain_name].get_uuid() ipam_list = self.vnc_lib.network_ipams_list()['network-ipams'] print "Existing IPAM list:",ipam_list ipam_delete_list = [data_ipam_name] for ipam in ipam_list: domain,project,fq_name = ipam['fq_name'] if fq_name in ipam_delete_list: obj = IPAM(tenant_connections) ipam_id = ipam['uuid'] obj.delete(ipam_id) self.db.delete_ipam(fq_name) ipam_obj = IPAM(tenant_connections) data_ipam_id = ipam_obj.create(data_ipam_name, data_vdns_id) print "DATA IPAM:",data_ipam_id policy_name_pattern = tenant_conf['policies']['name'] allow_rules_network = tenant_conf['policies']['rules']['allow_rules_network'] allow_rules_port = tenant_conf['policies']['rules']['allow_rules_port'] rules = [] for rule_index in xrange(len(allow_rules_network)): r = allow_rules_network[rule_index].split() src_nw = r[0] dst_nw = r[1] r = allow_rules_port[rule_index].split() src_port = r[0] dst_port = r[1] rule = { 'direction': '<>', 'simple_action': 'pass', 'protocol': 'any', 'src_ports': '%s'%src_port, 'dst_ports': '%s'%dst_port, 'source_network': '%s'%src_nw, 'dest_network': '%s'%dst_nw, } print "rule:",rule rules.append(rule) tenant_connections.quantum_h = tenant_connections.get_network_h() tenant_connections.api_server_inspect = tenant_connections.get_api_server_inspect_handles() policy_name = re.sub('XXX',str(tenant_index),policy_name_pattern) policy_obj = Policy(tenant_connections) policy_obj.policy_name = policy_name print "policy name:",policy_name policy_id = policy_obj.create(tenant_connections.inputs,policy_name,rules,tenant_connections) for vn_index in xrange(vns_count): vn_name = re.sub('XXX',str(tenant_index),vn_name_pattern) vn_name = re.sub('YYY',str(vn_index),vn_name) data_vn_name = re.sub('CCC','data',vn_name) vn_obj = VN(tenant_connections) self.vn_name = data_vn_name cidr = data_cidr_obj.get_next_cidr() print "CIDR:",cidr subnets = [{'cidr':cidr,'name':self.vn_name+"_subnet"}] print "creating VN:",self.vn_name,subnets,data_ipam_id data_vn_id = vn_obj.create(self.vn_name,subnets=subnets,ipam_id=data_ipam_id) vn_obj.vn_id = data_vn_id vn_obj.add_policy(policy_obj.fixture) for c in xrange(vm_count): vm_name = "vm%d"%vm_index vm_index += 1 vm_obj = virtual_machines(tenant_index,tenant_conf,tenant_connections) vm_obj.create_vm(vm_name,self.vn_name,vn_index,self.mgmt_vn_id,data_vn_id,self.glance_image) #queue.put(1) return tenant_obj
def setUp(self): tenants = self.test_conf['tenants'] tenant_count = tenants['count'] vns_count = tenants['virtual_networks']['count'] subnet_count = tenants['virtual_networks']['subnets'][0]['count'] vm_count = 1 tenant_name_prefix = tenants['name'] glance_image = self.global_conf['GLOBALS']['glance_image_name'] cidr_start = tenants['virtual_networks']['subnets'][0]['cidr'] cidr_obj = CIDR(cidr_start) vm_obj_list = [] self.connections.project_name = "admin" self.connections = ContrailConnections(inputs=inputs, logger=mylogger) auth_host = self.connections.inputs.get_auth_host() self.vnc_lib_fixture = VncLibHelper( username=self.connections.inputs.stack_user, password=self.connections.inputs.stack_password, domain=self.connections.inputs.domain_name, project=self.connections.project_name, inputs=self.connections.inputs, cfgm_ip=self.connections.inputs.cfgm_ip, api_port=self.connections.inputs.api_server_port, auth_host=auth_host) self.vnc_lib = self.vnc_lib_fixture.get_handle() admin_tenant_id = self.connections.get_auth_h().get_project_id( 'default_domain', 'admin') for tenant_index in xrange(tenant_count): self.connections.project_id = admin_tenant_id self.connections.inputs.project_name = "admin" self.connections.project_name = "admin" self.connections.project_fq_name = "admin" self.connections = ContrailConnections(inputs=inputs, logger=mylogger, project_name="admin") self.tenant_name = "%s_%d" % (tenant_name_prefix, tenant_index) tenant_obj = ConfigProject(self.connections) tenant_id = self.connections.get_auth_h().get_project_id( 'default_domain', self.tenant_name) if tenant_id: print "Tenant : %s available...cleaning it..." % self.tenant_name self.cleanup(tenant_obj, tenant_id) net_list = self.ostack_admin_obj.neutron_client.list_networks( )['networks'] subnet_list = self.ostack_admin_obj.neutron_client.list_subnets( )['subnets'] #shared_vnet_name = self.yaml_global_conf['virtual_network_shared']['name'] #shared_subnet_name = self.yaml_global_conf['virtual_network_shared']['subnets']['name'] #shared_subnet_cidr = self.yaml_global_conf['virtual_network_shared']['subnets']['cidr'] #shared_ipame_name = self.yaml_global_conf['IPAM']['name'] #for subnet in subnet_list: # if subnet["name"] == shared_subnet_name : # subnet_id = subnet['id'] # self.ostack_admin_obj.neutron_client.delete_subnet(subnet_id) #for net in net_list : # if net["name"] == shared_vnet_name : # net_id = net['id'] # self.ostack_admin_obj.neutron_client.delete_network(net_id) #ipam_list = self.vnc_lib.network_ipams_list()['network-ipams'] #print "Existing IPAM list:",ipam_list #ipam_delete_list = [shared_ipame_name] #for ipam in ipam_list: # domain,project,fq_name = ipam['fq_name'] # if fq_name in ipam_delete_list: # obj = IPAM(self.connections) # ipam_id = ipam['uuid'] # obj.delete(ipam_id) #self.shared_vn_id = global_configuration(self.yaml_global_conf,self.global_conf) for tenant_index in xrange(tenant_count): self.tenant_name = "%s_%d" % (tenant_name_prefix, tenant_index) tenant_id = tenant_obj.create(self.tenant_name) tenant_obj.update_default_sg() return self.connections = ContrailConnections( inputs=inputs, logger=mylogger, project_name=self.tenant_name) self.connections.inputs.project_name = self.tenant_name self.connections.project_name = self.tenant_name self.connections.project_fq_name = self.tenant_name self.connections.domain_name = self.tenant_name self.connections.project_id = tenant_id #self.vdns_name = "test1" #self.dns_domain = "test1" #self.domain_name = "default-domain" #self.vnc_lib_fixture = VncLibHelper( # username=self.connections.inputs.stack_user, password=self.connections.inputs.stack_password, # domain=self.domain_name, project=self.connections.project_name, # inputs=self.connections.inputs, cfgm_ip=self.connections.inputs.cfgm_ip, # api_port=self.connections.inputs.api_server_port, auth_host=auth_host) #self.vnc_lib = self.vnc_lib_fixture.get_handle() #tenant_vdns_id = self.add_virtual_dns(self.vdns_name,self.domain_name,self.dns_domain,self.dyn_updates,self.rec_order,\ # self.ttl,self.next_vdns,self.fip_record,self.external_visible,self.reverse_resolution) #ipam_obj = IPAM(self.connections) # #tenant_ipam_id = ipam_obj.create('T-%s-ipam'%self.tenant_name, tenant_vdns_id) #print "Tenant IPAM:",tenant_ipam_id tenant_ipam_id = None for vn_index in xrange(vns_count): vn_name = "%s_%d_VN_%d" % (tenant_name_prefix, tenant_index, vn_index) vn_obj = VN(self.connections) try: vn_id = self.connections.get_network_h().get_vn_id(vn_name) if vn_id: vn_obj.delete(vn_id) except: pass cidr = cidr_obj.get_next_cidr() subnets = [{'cidr': cidr, 'name': vn_name + "_subnet"}] vn_id = vn_obj.create(vn_name, subnets=subnets, ipam_id=tenant_ipam_id) for vm_index in xrange(vm_count): vm_name = "Tenant%dVN%dVM%d" % (tenant_index, vn_index, vm_index) vm_obj = self.create_vm(self.tenant_name, vm_name, self.shared_vn_id, vn_id, glance_image) for obj in vm_obj_list: obj.print_params()
def setUp(self): tenants = self.test_conf['tenants'] tenant_count = tenants['count'] vns_count = tenants['virtual_networks']['count'] subnet_count = tenants['virtual_networks']['subnets'][0]['count'] vm_count = 1 tenant_name_prefix = tenants['name'] glance_image = self.global_conf['GLOBALS']['glance_image_name'] cidr_start = tenants['virtual_networks']['subnets'][0]['cidr'] cidr_obj = CIDR(cidr_start) vm_obj_list = [] self.connections.project_name = "admin" self.connections = ContrailConnections(inputs=inputs, logger=mylogger) auth_host = self.connections.inputs.get_auth_host() self.vnc_lib_fixture = VncLibHelper( username=self.connections.inputs.stack_user, password=self.connections.inputs.stack_password, domain=self.connections.inputs.domain_name, project=self.connections.project_name, inputs=self.connections.inputs, cfgm_ip=self.connections.inputs.cfgm_ip, api_port=self.connections.inputs.api_server_port, auth_host=auth_host) self.vnc_lib = self.vnc_lib_fixture.get_handle() admin_tenant_id = self.connections.get_auth_h().get_project_id('default_domain','admin') for tenant_index in xrange(tenant_count): self.connections.project_id = admin_tenant_id self.connections.inputs.project_name = "admin" self.connections.project_name = "admin" self.connections.project_fq_name = "admin" self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name="admin") self.tenant_name = "%s_%d"%(tenant_name_prefix,tenant_index) tenant_obj = ConfigProject(self.connections) tenant_id = self.connections.get_auth_h().get_project_id('default_domain',self.tenant_name) if tenant_id: print "Tenant : %s available...cleaning it..."%self.tenant_name self.cleanup(tenant_obj,tenant_id) net_list = self.ostack_admin_obj.neutron_client.list_networks()['networks'] subnet_list = self.ostack_admin_obj.neutron_client.list_subnets()['subnets'] #shared_vnet_name = self.yaml_global_conf['virtual_network_shared']['name'] #shared_subnet_name = self.yaml_global_conf['virtual_network_shared']['subnets']['name'] #shared_subnet_cidr = self.yaml_global_conf['virtual_network_shared']['subnets']['cidr'] #shared_ipame_name = self.yaml_global_conf['IPAM']['name'] #for subnet in subnet_list: # if subnet["name"] == shared_subnet_name : # subnet_id = subnet['id'] # self.ostack_admin_obj.neutron_client.delete_subnet(subnet_id) #for net in net_list : # if net["name"] == shared_vnet_name : # net_id = net['id'] # self.ostack_admin_obj.neutron_client.delete_network(net_id) #ipam_list = self.vnc_lib.network_ipams_list()['network-ipams'] #print "Existing IPAM list:",ipam_list #ipam_delete_list = [shared_ipame_name] #for ipam in ipam_list: # domain,project,fq_name = ipam['fq_name'] # if fq_name in ipam_delete_list: # obj = IPAM(self.connections) # ipam_id = ipam['uuid'] # obj.delete(ipam_id) #self.shared_vn_id = global_configuration(self.yaml_global_conf,self.global_conf) for tenant_index in xrange(tenant_count): self.tenant_name = "%s_%d"%(tenant_name_prefix,tenant_index) tenant_id = tenant_obj.create(self.tenant_name) tenant_obj.update_default_sg() return self.connections = ContrailConnections(inputs=inputs, logger=mylogger,project_name=self.tenant_name) self.connections.inputs.project_name = self.tenant_name self.connections.project_name = self.tenant_name self.connections.project_fq_name = self.tenant_name self.connections.domain_name = self.tenant_name self.connections.project_id = tenant_id #self.vdns_name = "test1" #self.dns_domain = "test1" #self.domain_name = "default-domain" #self.vnc_lib_fixture = VncLibHelper( # username=self.connections.inputs.stack_user, password=self.connections.inputs.stack_password, # domain=self.domain_name, project=self.connections.project_name, # inputs=self.connections.inputs, cfgm_ip=self.connections.inputs.cfgm_ip, # api_port=self.connections.inputs.api_server_port, auth_host=auth_host) #self.vnc_lib = self.vnc_lib_fixture.get_handle() #tenant_vdns_id = self.add_virtual_dns(self.vdns_name,self.domain_name,self.dns_domain,self.dyn_updates,self.rec_order,\ # self.ttl,self.next_vdns,self.fip_record,self.external_visible,self.reverse_resolution) #ipam_obj = IPAM(self.connections) # #tenant_ipam_id = ipam_obj.create('T-%s-ipam'%self.tenant_name, tenant_vdns_id) #print "Tenant IPAM:",tenant_ipam_id tenant_ipam_id = None for vn_index in xrange(vns_count): vn_name = "%s_%d_VN_%d"%(tenant_name_prefix,tenant_index,vn_index) vn_obj = VN(self.connections) try: vn_id = self.connections.get_network_h().get_vn_id(vn_name) if vn_id: vn_obj.delete(vn_id) except: pass cidr = cidr_obj.get_next_cidr() subnets = [{'cidr':cidr,'name':vn_name+"_subnet"}] vn_id = vn_obj.create(vn_name,subnets=subnets,ipam_id=tenant_ipam_id) for vm_index in xrange(vm_count): vm_name = "Tenant%dVN%dVM%d"%(tenant_index,vn_index,vm_index) vm_obj = self.create_vm(self.tenant_name,vm_name,self.shared_vn_id,vn_id,glance_image) for obj in vm_obj_list: obj.print_params()
def create_tenant(self, tenant_conf, tenant_index): tenant_name_pattern = tenant_conf['name'] tenant_name = re.sub("XXX", str(tenant_index), tenant_name_pattern) #tenant_obj = PerTenant(self.vnc_lib,self.connections,tenant_conf,tenant_index) #tenant_id = tenant_obj.tenant_project_obj.create(tenant_name) tenant_obj = ConfigProject(self.connections) tenant_id = tenant_obj.create(tenant_name) tenant_obj.tenant_id = tenant_id self.db.set_project_id(tenant_name, tenant_id) tenant_connections = tenant_obj.get_connections() tenant_obj.update_default_sg(uuid=tenant_id) import pdb pdb.set_trace() ipam_name_pattern = tenant_conf['virtual_networks']['IPAM']['name'] vm_index = 0 tenant_obj.create_tenant_nova_client() vm_name_pattern = tenant_conf['virtual_networks']['virtual_machines'][ 'name'] ipam_name_pattern = tenant_conf['virtual_networks']['IPAM']['name'] data_domain_name_pattern = tenant_conf['virtual_networks']['vDNS'][1][ 'domain_name'] vn_name_pattern = tenant_conf['virtual_networks']['data_vn_name'] vns_count = tenant_conf['virtual_networks']['count'] vm_count = tenant_conf['virtual_networks']['virtual_machines']['count'] data_ipam_name = re.sub('XXX', str(tenant_index), ipam_name_pattern) data_ipam_name = re.sub('ZZZ', '2', data_ipam_name) data_ipam_name = re.sub('CCC', 'data', data_ipam_name) data_domain_name = re.sub('XXX', str(tenant_index), data_domain_name_pattern) data_domain_name = re.sub('ZZZ', '2', data_domain_name) data_vdns_id = self.global_vdns[data_domain_name].get_uuid() ipam_list = self.vnc_lib.network_ipams_list()['network-ipams'] print "Existing IPAM list:", ipam_list ipam_delete_list = [data_ipam_name] for ipam in ipam_list: domain, project, fq_name = ipam['fq_name'] if fq_name in ipam_delete_list: obj = IPAM(tenant_connections) ipam_id = ipam['uuid'] obj.delete(ipam_id) self.db.delete_ipam(fq_name) ipam_obj = IPAM(tenant_connections) data_ipam_id = ipam_obj.create(data_ipam_name, data_vdns_id) print "DATA IPAM:", data_ipam_id policy_name_pattern = tenant_conf['policies']['name'] allow_rules_network = tenant_conf['policies']['rules'][ 'allow_rules_network'] allow_rules_port = tenant_conf['policies']['rules']['allow_rules_port'] rules = [] for rule_index in xrange(len(allow_rules_network)): r = allow_rules_network[rule_index].split() src_nw = r[0] dst_nw = r[1] r = allow_rules_port[rule_index].split() src_port = r[0] dst_port = r[1] rule = { 'direction': '<>', 'simple_action': 'pass', 'protocol': 'any', 'src_ports': '%s' % src_port, 'dst_ports': '%s' % dst_port, 'source_network': '%s' % src_nw, 'dest_network': '%s' % dst_nw, } print "rule:", rule rules.append(rule) tenant_connections.quantum_h = tenant_connections.get_network_h() tenant_connections.api_server_inspect = tenant_connections.get_api_server_inspect_handles( ) policy_name = re.sub('XXX', str(tenant_index), policy_name_pattern) policy_obj = Policy(tenant_connections) policy_obj.policy_name = policy_name print "policy name:", policy_name policy_id = policy_obj.create(tenant_connections.inputs, policy_name, rules, tenant_connections) for vn_index in xrange(vns_count): vn_name = re.sub('XXX', str(tenant_index), vn_name_pattern) vn_name = re.sub('YYY', str(vn_index), vn_name) data_vn_name = re.sub('CCC', 'data', vn_name) vn_obj = VN(tenant_connections) self.vn_name = data_vn_name cidr = data_cidr_obj.get_next_cidr() print "CIDR:", cidr subnets = [{'cidr': cidr, 'name': self.vn_name + "_subnet"}] print "creating VN:", self.vn_name, subnets, data_ipam_id data_vn_id = vn_obj.create(self.vn_name, subnets=subnets, ipam_id=data_ipam_id) vn_obj.vn_id = data_vn_id vn_obj.add_policy(policy_obj.fixture) for c in xrange(vm_count): vm_name = "vm%d" % vm_index vm_index += 1 vm_obj = virtual_machines(tenant_index, tenant_conf, tenant_connections) vm_obj.create_vm(vm_name, self.vn_name, vn_index, self.mgmt_vn_id, data_vn_id, self.glance_image) #queue.put(1) return tenant_obj
def config_test(self): self.get_connection_handle() tenant_name = "tenant" + "".join([random.choice(string.ascii_uppercase + string.digits) for i in xrange(10)]) project_obj = Project(self.connections) project_obj.create(tenant_name)