def __delete_port_tenant_iaas(self, job_input): # Get JOB Input Parameters iaas_region_id = job_input['data']['IaaS_region_id'] iaas_tenant_id = job_input['data']['IaaS_tenant_id'] tenant_lan_list = job_input['data']['tenant_lan_list'] dc_id = job_input['data']['dc_id'] job_cleaning_mode = job_input['data'].get('job_cleaning_mode', '0') # Get Endpoint(OpenStack:IaaS) os_endpoint_iaas = self.get_os_endpoint_iaas(iaas_region_id, '', iaas_tenant_id, dc_id) # Create Instance(OpenStack Client) os_ports_instance = ports.OscQuantumPorts(self.job_config) target_network_list = [] for tenant_lan in tenant_lan_list: try: # Delete Port(OpenStack:VIM) os_ports_instance.delete_port(os_endpoint_iaas, tenant_lan['IaaS_port_id']) except: if job_cleaning_mode == '1': self.output_log_fatal(__name__, traceback.format_exc()) else: raise target_network_list.append(tenant_lan['network_id']) return target_network_list
def __msa_port_create_wim_csr1000v_for_tunnel(self, job_input, dc_segment, router_name): # Get JOB Input Parameters pod_id = job_input['pod_id'] dc_id = job_input['dc_id'] msa_network_info = job_input['msa_network_info'] nal_tenant_id = job_input['nal_tenant_id'] wan_network_id = job_input['wan_network_id'] # Get DC Segment Info dc_segment_ip_address = dc_segment[router_name + '_ip_address'] dc_segment_netmask = dc_segment['netmask'] # Get Endpoint(OpenStack:VIM) os_endpoint_vim = self.get_os_endpoint_vim(pod_id, '', nal_tenant_id, dc_id) # Create Instance(OpenStack Client) osc_ports = ports.OscQuantumPorts(self.job_config) # Create Port(OpenStack:VIM)(MSA) port_res_msa = osc_ports.create_port(os_endpoint_vim, msa_network_info['network_id'], '', True, msa_network_info['subnet_id']) msa_port_id = port_res_msa['port']['id'] msa_ip_address = port_res_msa['port']['fixed_ips'][0]['ip_address'] msa_port_info = port_res_msa # Get Network Info(IDC) idc_network_info = self.get_os_network_info( pod_id, nal_tenant_id, self.job_config.NW_NAME_IDC, '', dc_id) # Create Port(OpenStack:VIM)(WAN) port_res_wan = osc_ports.create_port(os_endpoint_vim, wan_network_id, '', True, idc_network_info['subnet_id'], dc_segment_ip_address) # Set JOB Output Parameters job_output = { 'msa_netmask': msa_network_info['netmask'], 'msa_port_id': msa_port_id, 'msa_ip_address': msa_ip_address, 'msa_port_info': msa_port_info, 'wan_port_id': port_res_wan['port']['id'], 'wan_port_info': port_res_wan, 'wan_info': { self.utils.IP_VER_V4: { 'ip': dc_segment_ip_address, 'netmask': dc_segment_netmask, }, } } return job_output
def __delete_port_wan(self, job_input): # Get JOB Input Parameters wan_lan_list = job_input['wan_lan_list'] dc_id = job_input['dc_id'] pod_id = job_input['pod_id'] nal_tenant_id = job_input['nal_tenant_id'] operation_id = job_input['operation_id'] logical_delete_apl_port_list \ = job_input['logical_delete_apl_port_list'] job_cleaning_mode = job_input.get('job_cleaning_mode', '0') # Get Endpoint(OpenStack:VIM) os_endpoint_vim = self.get_os_endpoint_vim(pod_id, '', nal_tenant_id, dc_id) # Create Instance(OpenStack Client) os_ports_instance = ports.OscQuantumPorts(self.job_config) for wan_lan in wan_lan_list: wan_port_id = wan_lan['port_id'] if len(wan_port_id) > 0: try: # Delete Port(OpenStack:VIM) os_ports_instance.delete_port(os_endpoint_vim, wan_port_id) except: if job_cleaning_mode == '1': self.output_log_fatal(__name__, traceback.format_exc()) else: raise logical_delete_apl_port_list.append({ 'search': { 'delete_flg': 0, 'tenant_id': nal_tenant_id, 'apl_type': 1, 'port_id': wan_port_id, }, 'params': { 'update_id': operation_id, 'delete_flg': 1, } }) return logical_delete_apl_port_list
def __create_os_port_vim(self, pod_id, tenant_id, network_id, subnet_id, port_name='', fixed_ips_ip_address=''): # Get Endpoint(OpenStack:VIM) os_endpoint = self.get_os_endpoint_vim(pod_id, '', tenant_id) # Create Port(OpenStack Client) osc_ports = ports.OscQuantumPorts(self.job_config) port_res = osc_ports.create_port(os_endpoint, network_id, port_name, True, subnet_id, fixed_ips_ip_address) return port_res
def __delete_os_port_vim(self, pod_id, tenant_id, port_id, job_cleaning_mode=0): # Get Endpoint(OpenStack:VIM) os_endpoint = self.get_os_endpoint_vim(pod_id, '', tenant_id) osc_ports = ports.OscQuantumPorts(self.job_config) try: # Delete Port(OpenStack Client) osc_ports.delete_port(os_endpoint, port_id) except: if job_cleaning_mode == '1': self.output_log_fatal(__name__, traceback.format_exc()) else: raise
def __add_os_port_fixed_ip_vim(self, pod_id, tenant_id, port_id, subnet_id, ip_address): # Get Endpoint(OpenStack:VIM) os_endpoint = self.get_os_endpoint_vim(pod_id, '', tenant_id) # Create Port(OpenStack Client) os_ports_instance = ports.OscQuantumPorts(self.job_config) # Get Port(OpenStack:VIM) os_port_res = os_ports_instance.get_port(os_endpoint, port_id) fixed_ip_append = {'subnet_id': subnet_id} if len(ip_address) > 0: fixed_ip_append['ip_address'] = ip_address fixed_ips_update = os_port_res['port']['fixed_ips'] fixed_ips_update.append(fixed_ip_append) # Update Port(OpenStack:VIM) os_port_upd = os_ports_instance.update_port(os_endpoint, port_id, None, None, fixed_ips_update) return os_port_upd['port']
def get_free_ip_max(self, job_input, subnet_id=''): free_ip = {} free_ip1 = {} free_ip2 = {} free_ip3 = {} # Get JOB Input Parameters iaas_region_id = job_input['IaaS_region_id'] iaas_tenant_id = job_input['IaaS_tenant_id'] iaas_network_id = job_input['IaaS_network_id'] nal_tenant_id = job_input['nal_tenant_id'] dc_id = job_input.get('dc_id', 'system') vim_iaas_with_flg = self.get_vim_iaas_with_flg(job_input) # Create Instance(OpenStack Client) os_subnets = subnets.OscQuantumSubnets(self.job_config) os_ports = ports.OscQuantumPorts(self.job_config) if vim_iaas_with_flg == 0: iaas_token_tenant = iaas_tenant_id else: iaas_token_tenant = nal_tenant_id # Get Endpoint(OpenStack:IaaS) os_endpoint_iaas = self.get_os_endpoint_iaas(iaas_region_id, '', iaas_token_tenant, dc_id) # List Subnets(OpenStack) os_subnet_list = os_subnets.list_subnets(os_endpoint_iaas) # List Ports(OpenStack) os_port_list = os_ports.list_ports(os_endpoint_iaas) port_list = [] for port_array in os_port_list['ports']: if port_array['network_id'] == iaas_network_id: port_list.append(port_array) for subnet_array in os_subnet_list['subnets']: if str(subnet_array['ip_version']) != self.utils.IP_VER_V4: continue if subnet_id != '' and subnet_id != subnet_array['id']: continue if subnet_array['network_id'] == iaas_network_id: cidr = subnet_array['cidr'] netmask = cidr.split('/') network_range = self.utils.get_network_range_from_cidr(cidr) network_bin = network_range['network'] broadcast_bin = network_range['broadcast'] ip_tmp = broadcast_bin - 1 end = network_bin + 1 while ip_tmp > end: ip_inuse = False for port in port_list: for fixed_ip in port['fixed_ips']: if self.utils.get_ipaddress_version(fixed_ip[ 'ip_address']) != self.utils.IP_VER_V4: continue fixed_ip_address = fixed_ip['ip_address'] fixed_ip_address = struct.unpack( '!i', socket.inet_aton(fixed_ip_address))[0] if fixed_ip_address == ip_tmp: ip_inuse = True break if ip_inuse == True: break if ip_inuse == False: free_ip_tmp = {} free_ip_tmp['ip'] \ = socket.inet_ntoa(struct.pack(r'!i', (ip_tmp))) free_ip_tmp['cidr'] = cidr free_ip_tmp['netmask'] = netmask[1] free_ip_tmp['subnet_ip'] = netmask[0] free_ip_tmp['id'] = subnet_array['id'] if free_ip_tmp['ip'] \ == subnet_array['gateway_ip']: if self.job_config.USE_GATEWAY_ADDR_VLAN_IP \ == True and len(free_ip3) == 0: free_ip3 = free_ip_tmp else: ip_indhcp = False for dhcp in subnet_array['allocation_pools']: dhcp_start_bin = struct.unpack( '!i', socket.inet_aton(dhcp['start']))[0] dhcp_end_bin = struct.unpack( '!i', socket.inet_aton(dhcp['end']))[0] if ip_tmp >= dhcp_start_bin \ and ip_tmp <= dhcp_end_bin: ip_indhcp = True break if ip_indhcp == True: if len(free_ip2) == 0: free_ip2 = free_ip_tmp else: free_ip1 = free_ip_tmp break ip_tmp = ip_tmp - 1 if len(free_ip1) > 0: break if len(free_ip1) > 0: free_ip = free_ip1 elif len(free_ip2) > 0: free_ip = free_ip2 elif len(free_ip3) > 0: free_ip = free_ip3 if len(free_ip) == 0: raise SystemError('free_ip not found') return free_ip
def __assign_msa_network(self, tenant_name, pod_id, nal_tenant_id, operation_id, job_input): IaaS_tenant_id = job_input['IaaS_tenant_id'] vim_iaas_with_flg = self.get_vim_iaas_with_flg(job_input) # Get Endpoint(DB Client) db_endpoint_msa_vlan = self.get_db_endpoint( self.job_config.REST_URI_MSA_VLAN) # Get Endpoint(OpenStack:VIM) os_endpoint_vim = self.get_os_endpoint_vim(pod_id, '', nal_tenant_id) # Create Instance(OpenStack Client) osc_networks = networks.OscQuantumNetworks(self.job_config) os_subnets_instance = subnets.OscQuantumSubnets(self.job_config) os_ports_instance = ports.OscQuantumPorts(self.job_config) # Create Instance(DB Client) db_list = list.ListClient(self.job_config) db_update = update.UpdateClient(self.job_config) # List NAL_MSA_VLAN_MNG(DB Client) params = {} params['delete_flg'] = 0 params['status'] = 0 db_list.set_context(db_endpoint_msa_vlan, params) db_list.execute() msa_vlan_list = db_list.get_return_param() msa_network_info = {} if len(msa_vlan_list) != 0: rec = msa_vlan_list[0] # Update NAL_MSA_VLAN_MNG(DB Client) keys = [rec['ID']] params = {} params['update_id'] = operation_id params['pod_id'] = pod_id params['tenant_name'] = tenant_name params['status'] = 1 params['tenant_id'] = nal_tenant_id db_update.set_context(db_endpoint_msa_vlan, keys, params) db_update.execute() cidr = rec['network_address'] + '/' + rec['netmask'] if vim_iaas_with_flg == 0: # Create Network(OpenStack:VIM) network_name = 'MSA_for_' + nal_tenant_id physical_network_name = None else: # Create Network(OpenStack:VIM) network_name = 'MSA_for_' + IaaS_tenant_id physical_network_name = self.get_os_physical_network_name() os_cre_network_vim = osc_networks.create_network( os_endpoint_vim, network_name, True, False, rec['vlan_id'], physical_network_name) network_info = os_cre_network_vim['network'] network_id = network_info['id'] # Get Network Data(id) ret = self.utils.get_network_range_from_cidr(cidr) gatewy_ip = \ socket.inet_ntoa(struct.pack('!L', ret['network'] + 1)) os_cre_subnet_vim = os_subnets_instance.create_subnet( os_endpoint_vim, network_id, cidr, '', nal_tenant_id, '4', gatewy_ip) subnet_info = os_cre_subnet_vim['subnet'] subnet_id = subnet_info['id'] # Create Port(OpenStack:VIM) os_cre_port_vim = os_ports_instance.create_port( os_endpoint_vim, network_id) # Get Port Info port_info = os_cre_port_vim['port'] port_id = port_info['id'] ip_address = port_info['fixed_ips'][0]['ip_address'] # MSA setup self.__setup_msa_network_vlan(pod_id, rec['vlan_id'], ip_address, rec['netmask']) # Update NAL_MSA_VLAN_MNG(DB Client) keys = [rec['ID']] params = {} params['update_id'] = operation_id params['msa_ip_address'] = ip_address params['network_id'] = network_id params['subnet_id'] = subnet_id params['port_id'] = port_id params['network_info'] = json.dumps(network_info) params['subnet_info'] = json.dumps(subnet_info) params['port_info'] = json.dumps(port_info) db_update.set_context(db_endpoint_msa_vlan, keys, params) db_update.execute() # List NAL_MSA_VLAN_MNG(DB Client) params = {} params['delete_flg'] = 0 params['pod_id'] = pod_id params['tenant_name'] = tenant_name db_list.set_context(db_endpoint_msa_vlan, params) db_list.execute() msa_network_info = db_list.get_return_param() else: raise SystemError('vlan for MSA not Found.') return msa_network_info
def test_quantum(self): endpoint = self.ENDPOINT_URL tenant_id = self.ADMIN_TENANT_ID admin_user_name = 'admin' admin_password = '******' nw_name = 'nw_ksp' subnet_name = 'subnet_ksp' port_name = 'port_ksp' cidr_ipv4 = '10.0.0.0/24' cidr_ipv6 = '2001:db8::/48' fixed_ips_ip_address_ipv4 = '10.0.0.1' fixed_ips_ip_address_ipv6 = '2001:DB8::10' port_id_list = [] job_config = config.JobConfig() token = tokens.OscTokens(job_config).create_token( admin_user_name, admin_password, endpoint) print('create_token') print(token) endpoint_array = tokens.OscTokens(job_config).get_endpoints( endpoint, token, admin_user_name, admin_password, tenant_id) print('get_endpoints') print(json.dumps(endpoint_array)) endpoint_array['region_id'] = self.REGION_ID # Create Network nw_name_new = nw_name \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = networks.OscQuantumNetworks(job_config)\ .create_network(endpoint_array, nw_name_new, True, False, None, None ) print('create_network') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Get Network nw_id_new = res['network']['id'] res = networks.OscQuantumNetworks(job_config)\ .get_network(endpoint_array, nw_id_new) print('get_network') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # List Networks res = networks.OscQuantumNetworks(job_config)\ .list_networks(endpoint_array) print('list_networks') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Create Subnet subnet_name_new = subnet_name \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = subnets.OscQuantumSubnets(job_config)\ .create_subnet( endpoint_array, nw_id_new, cidr_ipv4, subnet_name_new, tenant_id, '4', fixed_ips_ip_address_ipv4) print('create_subnet') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Get Subnet subnet_id_new_ipv4 = res['subnet']['id'] res = subnets.OscQuantumSubnets(job_config)\ .get_subnet(endpoint_array, subnet_id_new_ipv4) print('get_subnet') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Create Subnet subnet_name_new = subnet_name \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = subnets.OscQuantumSubnets(job_config)\ .create_subnet( endpoint_array, nw_id_new, cidr_ipv6, subnet_name_new, '', '6') print('create_subnet') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) subnet_id_new_ipv6 = res['subnet']['id'] # List Subnets res = subnets.OscQuantumSubnets(job_config)\ .list_subnets(endpoint_array) print('list_subnets') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Create Port port_name_new = port_name + '-1-' \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = ports.OscQuantumPorts(job_config)\ .create_port(endpoint_array, nw_id_new, port_name_new, True ) print('create_port') print(json.dumps(res)) port_id_list.append(res['port']['id']) # Assertion self.assertGreaterEqual(len(res), 1) # Get Port res = ports.OscQuantumPorts(job_config)\ .get_port(endpoint_array, port_id_list[0]) print('get_port') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Create Port port_name_new = port_name + '-2-' \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = ports.OscQuantumPorts(job_config)\ .create_port(endpoint_array, nw_id_new, port_name_new, True, subnet_id_new_ipv4 ) print('create_port') print(json.dumps(res)) port_id_list.append(res['port']['id']) # Create Port port_name_new = port_name + '-3-' \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = ports.OscQuantumPorts(job_config)\ .create_port(endpoint_array, nw_id_new, port_name_new, True, subnet_id_new_ipv6 ) print('create_port') print(json.dumps(res)) port_id_list.append(res['port']['id']) # Create Port port_name_new = port_name + '-4-' \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = ports.OscQuantumPorts(job_config)\ .create_port(endpoint_array, nw_id_new, port_name_new, True, '', '10.0.0.10' ) print('create_port') print(json.dumps(res)) port_id_list.append(res['port']['id']) # Assertion self.assertGreaterEqual(len(res), 1) # List Ports res = ports.OscQuantumPorts(job_config).list_ports(endpoint_array) print('list_ports') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) for port_id in port_id_list: # Detach Port res = ports.OscQuantumPorts(job_config)\ .detach_port_device(endpoint_array, port_id) print('detach_port_device') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Delete Port res = ports.OscQuantumPorts(job_config)\ .delete_port(endpoint_array, port_id) print('delete_port') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Create Port(Dual Stack) fixed_ips = [{ 'subnet_id': subnet_id_new_ipv4, 'ip_address': fixed_ips_ip_address_ipv4, }, { 'subnet_id': subnet_id_new_ipv6, 'ip_address': fixed_ips_ip_address_ipv6, }] port_name_new = port_name \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = ports.OscQuantumPorts(job_config)\ .create_port_dual_stack( endpoint_array, nw_id_new, port_name_new, True, fixed_ips) print('create_port_dual_stack') print(json.dumps(res)) port_id_new = res['port']['id'] # Get Port res = ports.OscQuantumPorts(job_config)\ .get_port(endpoint_array, port_id_new) print('get_port(create_port_dual_stack)') print(json.dumps(res)) # Update Port fixed_ips = [ { 'subnet_id': subnet_id_new_ipv4, 'ip_address': fixed_ips_ip_address_ipv4, }, { 'subnet_id': subnet_id_new_ipv6, 'ip_address': fixed_ips_ip_address_ipv6, }, ] res = ports.OscQuantumPorts(job_config)\ .update_port(endpoint_array, port_id_new, port_name_new + 'upd', False, fixed_ips) print('update_port') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Get Port res = ports.OscQuantumPorts(job_config)\ .get_port(endpoint_array, port_id_new) print('get_port(update_port)') print(json.dumps(res)) # Delete Port res = ports.OscQuantumPorts(job_config)\ .delete_port(endpoint_array, port_id_new) print('delete_port') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # List Ports res = ports.OscQuantumPorts(job_config).list_ports(endpoint_array) print('list_ports') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Delete Subnet res = subnets.OscQuantumSubnets(job_config)\ .delete_subnet(endpoint_array, subnet_id_new_ipv4) print('delete_subnet') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) res = subnets.OscQuantumSubnets(job_config)\ .delete_subnet(endpoint_array, subnet_id_new_ipv6) print('delete_subnet') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Delete Network res = networks.OscQuantumNetworks(job_config)\ .delete_network(endpoint_array, nw_id_new) print('delete_network') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0)
def __add_port_tenant_ipv6(self, job_input, network_id, vlan_id): output = {} # Get JOB Input Parameters operation_id = job_input['operation_id'] iaas_region_id = job_input['IaaS_region_id'] iaas_tenant_id = job_input['IaaS_tenant_id'] iaas_network_id = job_input['IaaS_network_id'] iaas_subnet_id = job_input['IaaS_subnet_id'] iaas_subnet_id_v6 = job_input['IaaS_subnet_id_v6'] pod_id = job_input['pod_id'] nal_tenant_id = job_input['nal_tenant_id'] vrrp_address = job_input['vrrp_address'] ce1_address = job_input['ce1_address'] ce2_address = job_input['ce2_address'] vim_iaas_with_flg = self.get_vim_iaas_with_flg(job_input) # Get Endpoint(OpenStack:VIM) os_endpoint_vim = self.get_os_endpoint_vim(pod_id, '', nal_tenant_id) if vim_iaas_with_flg == 0: iaas_token_tenant = iaas_tenant_id else: iaas_token_tenant = nal_tenant_id # Get Endpoint(OpenStack:IaaS) os_endpoint_iaas = self.get_os_endpoint_iaas(iaas_region_id, '', iaas_token_tenant) # Get Endpoint(DB Client) db_endpoint_port = self.get_db_endpoint(self.job_config.REST_URI_PORT) # Create Instance(OpenStack Client) os_subnets_instance = subnets.OscQuantumSubnets(self.job_config) os_ports_instance = ports.OscQuantumPorts(self.job_config) # Create Instance(DB Client) db_list_instance = list.ListClient(self.job_config) db_update_instance = update.UpdateClient(self.job_config) # Get Subnet(OpenStack:IaaS) iaas_subnet_res = os_subnets_instance.get_subnet( os_endpoint_iaas, iaas_subnet_id_v6) iaas_cidr_wk = self.utils.get_cidr_compressed( iaas_subnet_res['subnet']['cidr']) iaas_cidr = iaas_cidr_wk['cidr'] subnet_ip_v6 = iaas_cidr_wk['ip'] netmask_v6 = iaas_cidr_wk['netmask'] # List NAL_PORT_MNG(DB) params = {} params['IaaS_tenant_id'] = iaas_tenant_id params['IaaS_network_id'] = iaas_network_id params['IaaS_subnet_id'] = iaas_subnet_id params['delete_flg'] = 0 db_list_instance.set_context(db_endpoint_port, params) db_list_instance.execute() port_list_v4 = db_list_instance.get_return_param() for port_res in port_list_v4: if port_res['ip_address'] == vrrp_address: port_vrrp = port_res if port_res['ip_address'] == ce1_address: port_ce1 = port_res if port_res['ip_address'] == ce2_address: port_ce2 = port_res # Add IPv6 Tenant LAN(CE1,CE2) for router_name, port_ce in { self.job_config.VM_ROUTER_NODE_NAME1: port_ce1, self.job_config.VM_ROUTER_NODE_NAME2: port_ce2, }.items(): port_id_vim = port_ce['port_id'] port_id_iaas = port_ce['IaaS_port_id'] if vim_iaas_with_flg == 0: # Get Port(OpenStack:IaaS) iaas_port_res = os_ports_instance.get_port( os_endpoint_iaas, port_id_iaas) fixed_ips_iaas = iaas_port_res['port']['fixed_ips'] fixed_ips_iaas.append({'subnet_id': iaas_subnet_id_v6}) # Update Port(OpenStack:IaaS) os_upd_port_iaas = os_ports_instance.update_port( os_endpoint_iaas, port_id_iaas, None, None, fixed_ips_iaas) fixed_ips_iaas = os_upd_port_iaas['port']['fixed_ips'] for fixed_ip in fixed_ips_iaas: if fixed_ip['subnet_id'] == iaas_subnet_id_v6: ip_address_v6 = self.utils.get_ipaddress_compressed( fixed_ip['ip_address']) break # List Subnets(OpenStack:VIM) subnet_list = os_subnets_instance.list_subnets(os_endpoint_vim) subnet_exists_flg = False subnet_id = '' for rec in subnet_list['subnets']: vim_cidr = self.utils.get_cidr_compressed(rec['cidr']) if rec['network_id'] == network_id \ and vim_cidr['cidr'] == iaas_cidr: subnet_exists_flg = True subnet_id = rec['id'] break if subnet_exists_flg == False: # Create Subnet(OpenStack:VIM) os_subnet_cre_vim = os_subnets_instance.create_subnet( os_endpoint_vim, network_id, iaas_cidr, '', nal_tenant_id, self.utils.IP_VER_V6) subnet_id = os_subnet_cre_vim['subnet']['id'] # Get Port(OpenStack:VIM) os_port_res_vim = os_ports_instance.get_port( os_endpoint_vim, port_id_vim) fixed_ips_vim = os_port_res_vim['port']['fixed_ips'] fixed_ips_vim.append({ 'subnet_id': subnet_id, 'ip_address': ip_address_v6 }) # Update Port(OpenStack:VIM) os_port_upd_vim = os_ports_instance.update_port( os_endpoint_vim, port_id_vim, None, None, fixed_ips_vim) else: # Get Port(OpenStack:VIM) vim_port_res = os_ports_instance.get_port( os_endpoint_vim, port_id_vim) fixed_ips_vim = vim_port_res['port']['fixed_ips'] fixed_ips_vim.append({'subnet_id': iaas_subnet_id_v6}) # Update Port(OpenStack:IaaS) os_port_upd_vim = os_ports_instance.update_port( os_endpoint_vim, port_id_vim, None, None, fixed_ips_vim) fixed_ips_vim = os_port_upd_vim['port']['fixed_ips'] for fixed_ip in fixed_ips_vim: if fixed_ip['subnet_id'] == iaas_subnet_id_v6: ip_address_v6 = self.utils.get_ipaddress_compressed( fixed_ip['ip_address']) break # Update NAL_PORT_MNG(DB Client) keys = [port_ce['ID']] params = {} params['update_id'] = operation_id params['IaaS_subnet_id_v6'] = iaas_subnet_id_v6 params['ip_address_v6'] = ip_address_v6 params['netmask_v6'] = netmask_v6 params['port_info'] = json.dumps(os_port_upd_vim['port']) db_update_instance.set_context(db_endpoint_port, keys, params) db_update_instance.execute() # Set Output Parameters output[router_name] = {} output[router_name]['network_id'] = port_ce['network_id'] output[router_name]['port_id'] = port_id_vim output[router_name]['ip_address'] = ip_address_v6 output[router_name]['netmask'] = netmask_v6 output[router_name]['rec_id'] = port_ce['ID'] output[router_name]['subnet_ip_address'] = subnet_ip_v6 output[router_name]['IaaS_subnet_id'] = iaas_subnet_id_v6 output[router_name]['vlan_id'] = vlan_id output[router_name]['nic'] = port_ce['nic'] if vim_iaas_with_flg == 0: vrrp_address = 'fe80::f' + format(int(vlan_id), 'x') else: if int(vlan_id) <= 65535: vrrp_address = 'fe80::' + format(int(vlan_id), 'x') else: end_address = format(int(vlan_id), 'x')[-4:] second_address = format(int(vlan_id), 'x')[:-4] vrrp_address = 'fe80::' + second_address + ':' + end_address # Set Output Parameters(vrrp) output['vrrp'] = {} output['vrrp']['network_id'] = port_vrrp['network_id'] output['vrrp']['port_id'] = port_vrrp['port_id'] output['vrrp']['ip_address'] = self.utils.get_ipaddress_compressed( vrrp_address) output['vrrp']['netmask'] = '' output['vrrp']['rec_id'] = port_vrrp['ID'] output['vrrp']['subnet_ip_address'] = '' output['vrrp']['IaaS_subnet_id'] = '' output['vrrp']['vlan_id'] = vlan_id return output
def __create_port_tenant_iaas(self, job_input, network_id, vlan_id, mac_address=''): # Get JOB Input Parameters operation_id = job_input['operation_id'] iaas_region_id = job_input['IaaS_region_id'] iaas_tenant_id = job_input['IaaS_tenant_id'] iaas_network_id = job_input['IaaS_network_id'] iaas_subnet_id = job_input['IaaS_subnet_id'] # network_name = job_input['network_name'] tenant_name = job_input['tenant_name'] pod_id = job_input['pod_id'] nal_tenant_id = job_input['nal_tenant_id'] apl_type = job_input['apl_type'] # Get Endpoint(OpenStack:VIM) os_endpoint_vim = self.get_os_endpoint_vim(pod_id, '', nal_tenant_id) # Get Endpoint(DB Client) db_endpoint_port = self.get_db_endpoint(self.job_config.REST_URI_PORT) # Create Instance(OpenStack Client) os_ports_instance = ports.OscQuantumPorts(self.job_config) # Create Instance(DB Client) db_create_instance = create.CreateClient(self.job_config) db_list_instance = list.ListClient(self.job_config) iaas_port_create_count = 0 while iaas_port_create_count <= \ self.job_config.OS_PORT_CREATE_RETRY_COUNT: # Get Free IpAddress(IaaS) free_ip_iaas = self.get_free_ip_max(job_input, iaas_subnet_id) # Create Port(OpenStack:IaaS) try: os_cre_port_iaas = os_ports_instance.create_port( os_endpoint_vim, iaas_network_id, self.IAAS_PORT_NAME, True, free_ip_iaas['id'], free_ip_iaas['ip'], mac_address) except Exception as e: if str(e) == self.job_config.OS_ERR_MSG_PORT_DUPLICATED: if iaas_port_create_count \ == self.job_config.OS_PORT_CREATE_RETRY_COUNT: raise SystemError( 'Exceeded Limit Count: OpenStack Port Create(IaaS).' ) time.sleep(self.job_config.OS_PORT_CREATE_WAIT_TIME) iaas_port_create_count += 1 continue raise break iaas_port_id = os_cre_port_iaas['port']['id'] # Get Port Info port_info = os_cre_port_iaas['port'] port_id = port_info['id'] ip_address = port_info['fixed_ips'][0]['ip_address'] # Create NAL_PORT_MNG(DB) params = {} params['create_id'] = operation_id params['update_id'] = operation_id params['delete_flg'] = 0 params['port_id'] = port_id params['tenant_name'] = tenant_name params['pod_id'] = pod_id params['tenant_id'] = nal_tenant_id params['network_id'] = network_id params['network_type'] = self.job_config.NW_TYPE_IN params['network_type_detail'] = self.job_config.NW_TYPE_TENANT params['apl_type'] = apl_type params['node_id'] = '' params['IaaS_region_id'] = iaas_region_id params['IaaS_tenant_id'] = iaas_tenant_id params['IaaS_network_id'] = iaas_network_id params['IaaS_subnet_id'] = iaas_subnet_id params['IaaS_port_id'] = iaas_port_id params['nic'] = '' params['ip_address'] = ip_address params['netmask'] = free_ip_iaas['netmask'] params['port_info'] = json.dumps(port_info) params['msa_info'] = json.dumps({}) db_create_instance.set_context(db_endpoint_port, params) db_create_instance.execute() # List NAL_PORT_MNG(DB) params = {} params['port_id'] = port_id params['delete_flg'] = 0 db_list_instance.set_context(db_endpoint_port, params) db_list_instance.execute() port_list = db_list_instance.get_return_param() # Set Output Parameters output = {} output['network_id'] = port_list[0]['network_id'] output['port_id'] = port_list[0]['port_id'] output['ip_address'] = port_list[0]['ip_address'] output['netmask'] = port_list[0]['netmask'] output['rec_id'] = port_list[0]['ID'] output['subnet_ip_address'] = free_ip_iaas['subnet_ip'] output['IaaS_subnet_id'] = free_ip_iaas['id'] output['vlan_id'] = vlan_id return output
def test_nova(self): import random mac_address = [] for i in range(6): mac_address.append('%02x' % random.choice(range(1, 256))) print(':'.join(mac_address)) endpoint = self.ENDPOINT_URL tenant_id = self.ADMIN_TENANT_ID admin_user_name = 'admin' admin_password = '******' sv_name = 'sv_ksp' nw_name = 'nw_ksp' subnet_name = 'subnet_ksp' port_name = 'port_ksp' cidr = '0.0.0.0/27' imageRef = self.IMAGE_ID flavorRef = '1' network_list = [ { 'uuid': '', 'port': '', } ] job_config = config.JobConfig() token = tokens.OscTokens(job_config).create_token( admin_user_name, admin_password, endpoint) print('create_token') print(token) endpoint_array = tokens.OscTokens(job_config).get_endpoints( endpoint, token, admin_user_name, admin_password, tenant_id) print('get_endpoints') print(json.dumps(endpoint_array)) endpoint_array['region_id'] = self.REGION_ID # Create Network nw_name_new = nw_name \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = networks.OscQuantumNetworks(job_config)\ .create_network(endpoint_array, nw_name_new) print('create_network') print(json.dumps(res)) # Create Subnet nw_id_new = res['network']['id'] subnet_name_new = subnet_name \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = subnets.OscQuantumSubnets(job_config)\ .create_subnet(endpoint_array, nw_id_new, cidr, subnet_name_new) print('create_subnet') print(json.dumps(res)) # Create Port subnet_id_new = res['subnet']['id'] port_name_new = port_name \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') res = ports.OscQuantumPorts(job_config)\ .create_port(endpoint_array, nw_id_new, port_name_new) port_id_new = res['port']['id'] print('create_port') print(json.dumps(res)) # List Server res = servers.OscServers(job_config)\ .list_servers(endpoint_array) print('list_servers') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # List Flavors res = flavors.OscNovaFlavors(job_config)\ .list_flavors(endpoint_array) print('list_flavors') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Create Server sv_name_new = sv_name \ + datetime.datetime.today().strftime('%Y%m%d%H%M%S') network_list[0]['uuid'] = nw_id_new network_list[0]['port'] = port_id_new res = servers.OscServers(job_config).create_server( endpoint_array, sv_name_new, imageRef, flavorRef, network_list) print('create_server') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) time.sleep(self.WAIT_TIME_CREATE_SERVER) # Get Server server_id_new = res['server']['id'] res = servers.OscServers(job_config)\ .get_server(endpoint_array, server_id_new) print('get_server') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Action Server(Resume) actionkey = servers.OscServers(job_config).SERVER_ACTION_RESUME res = servers.OscServers(job_config)\ .action_server(endpoint_array, server_id_new, actionkey) print('action_server(resume)') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Action Server(Reset Network) actionkey = servers.OscServers(job_config).SERVER_ACTION_RESETNETWORK res = servers.OscServers(job_config)\ .action_server(endpoint_array, server_id_new, actionkey) print('action_server(reset network)') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Action Server(Suspend) actionkey = servers.OscServers(job_config).SERVER_ACTION_SUSPEND res = servers.OscServers(job_config)\ .action_server(endpoint_array, server_id_new, actionkey) print('action_server(suspend)') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Action Server(Reboot) actionkey = servers.OscServers(job_config).SERVER_ACTION_REBOOT boottype = servers.OscServers(job_config).SERVER_REBOOT_TYPE_SOFT res = servers.OscServers(job_config).action_server( endpoint_array, server_id_new, actionkey, boottype) print('action_server(reboot)') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Action Server(Resize) actionkey = servers.OscServers(job_config).SERVER_ACTION_RESIZE res = servers.OscServers(job_config)\ .action_server(endpoint_array, server_id_new, None, '2') print('action_server(resize)') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Action Server(Confirm Resize) actionkey = servers.OscServers(job_config).SERVER_ACTION_CONFIRMRESIZE res = servers.OscServers(job_config)\ .action_server(endpoint_array, server_id_new, actionkey) print('action_server(confirm resize)') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Action Server(OS Start) actionkey = servers.OscServers(job_config).SERVER_ACTION_OS_START res = servers.OscServers(job_config)\ .action_server(endpoint_array, server_id_new, actionkey) print('action_server(os start)') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Action Server(OS Stop) actionkey = servers.OscServers(job_config).SERVER_ACTION_OS_STOP res = servers.OscServers(job_config)\ .action_server(endpoint_array, server_id_new, actionkey) print('action_server(os stop)') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Action Server(Get Console) actionkey = servers.OscServers(job_config).SERVER_ACTION_GETCONSOLE res = servers.OscServers(job_config).action_server( endpoint_array, server_id_new, actionkey, None, None, 'xvpvnc') print('action_server(get console)') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Action Server(Status Pause) actionkey = servers.OscServers(job_config).SERVER_STATUS_PAUSE res = servers.OscServers(job_config)\ .action_server(endpoint_array, server_id_new, actionkey) print('action_server(status pause)') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # Attach Interface res = servers.OscServers(job_config)\ .attach_interface(endpoint_array, server_id_new, port_id_new) print('attach_interface') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # List Interfaces res = servers.OscServers(job_config)\ .list_interfaces(endpoint_array, server_id_new) print('list_interfaces') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # List Flavors res = flavors.OscNovaFlavors(job_config).list_flavors(endpoint_array) print('list_flavors') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Detach Interface res = servers.OscServers(job_config)\ .detach_interface(endpoint_array, server_id_new, port_id_new) print('detach_interface') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0) # List Server res = servers.OscServers(job_config)\ .list_servers(endpoint_array) print('list_servers') print(json.dumps(res)) # Assertion self.assertGreaterEqual(len(res), 1) # Delete Port res = ports.OscQuantumPorts(job_config)\ .delete_port(endpoint_array, port_id_new) print('delete_port') print(json.dumps(res)) # Delete Subnet res = subnets.OscQuantumSubnets(job_config)\ .delete_subnet(endpoint_array, subnet_id_new) print('delete_subnet') print(json.dumps(res)) # Delete Network res = networks.OscQuantumNetworks(job_config)\ .delete_network(endpoint_array, nw_id_new) print('delete_network') print(json.dumps(res)) # Delete Server res = servers.OscServers(job_config)\ .delete_server(endpoint_array, server_id_new) print('delete_server') print(json.dumps(res)) # Assertion self.assertEqual(len(res), 0)
def msa_port_delete_wim(self, job_input): function_name = inspect.currentframe().f_code.co_name # Output Log(Job Input) self.output_log_job_params(self.LOG_TYPE_INPUT, __name__, function_name, job_input) # Get JOB Input Parameters operation_id = job_input['operation_id'] dc_id = job_input['dc_id'] pod_id = job_input['pod_id'] nal_tenant_id = job_input['nal_tenant_id'] msa_port_id1 = job_input['apl_info'][ self.job_config.VM_ROUTER_NODE_NAME1]['msa_port_id'] msa_port_id2 = job_input['apl_info'][ self.job_config.VM_ROUTER_NODE_NAME2]['msa_port_id'] job_cleaning_mode = job_input.get('job_cleaning_mode', '0') logical_delete_apl_port_list \ = job_input['logical_delete_apl_port_list'] # Get Endpoint(OpenStack:VIM) os_endpoint_vim = self.get_os_endpoint_vim(pod_id, '', nal_tenant_id, dc_id) # Create Instance(OpenStack Client) osc_ports = ports.OscQuantumPorts(self.job_config) # Delete Port(OpenStack Client)(MSA) try: osc_ports.delete_port(os_endpoint_vim, msa_port_id1) except: if job_cleaning_mode == '1': self.output_log_fatal(__name__, traceback.format_exc()) else: raise try: osc_ports.delete_port(os_endpoint_vim, msa_port_id2) except: if job_cleaning_mode == '1': self.output_log_fatal(__name__, traceback.format_exc()) else: raise # Set Delete Info logical_delete_apl_port_list.append({ 'search': { 'delete_flg': 0, 'tenant_id': nal_tenant_id, 'apl_type': self.job_config.APL_TYPE_VR, 'port_id': msa_port_id1, }, 'params': { 'update_id': operation_id, 'delete_flg': 1, }, }) logical_delete_apl_port_list.append({ 'search': { 'delete_flg': 0, 'tenant_id': nal_tenant_id, 'apl_type': self.job_config.APL_TYPE_VR, 'port_id': msa_port_id2, }, 'params': { 'update_id': operation_id, 'delete_flg': 1, }, }) # Output Log(Job Output) job_output = { 'logical_delete_apl_port_list': logical_delete_apl_port_list } self.output_log_job_params(self.LOG_TYPE_OUTPUT, __name__, function_name, job_output) return job_output
def __wan_port_add_ipv6_wim(self, job_input, router_name): # Get JOB Input Parameters pod_id = job_input['pod_id'] dc_id = job_input['dc_id'] nal_tenant_id = job_input['nal_tenant_id'] node_id = job_input['apl_info'][router_name]['node_id'] wan_lan_list = job_input['wan_lan_list'] # Get Allocation Info(WAN) wan_allocation_info = job_input['wan_allocation_info'][router_name] # Get port_id(WAN) for wan_lan in wan_lan_list: if wan_lan['node_id'] == node_id: wan_network_id = wan_lan['network_id'] wan_port_id = wan_lan['port_id'] break # Get Endpoint(OpenStack:VIM) os_endpoint_vim = self.get_os_endpoint_vim(pod_id, '', nal_tenant_id, dc_id) # Create Instance(OpenStack Client) osc_subnets = subnets.OscQuantumSubnets(self.job_config) osc_ports = ports.OscQuantumPorts(self.job_config) wan_ip = wan_allocation_info['wan'][self.utils.IP_VER_V6]['ip'] wan_ip_subnet = wan_allocation_info['wan'][ self.utils.IP_VER_V6]['subnet_ip'] wan_netmask = wan_allocation_info['wan'][ self.utils.IP_VER_V6]['netmask'] wan_cidr = wan_ip_subnet + '/' + str(wan_netmask) wan_subnet_id = '' subnet_exists_flg = False # List Subnets(OpenStack:VIM) subnet_list = osc_subnets.list_subnets(os_endpoint_vim) for rec in subnet_list['subnets']: vim_cidr = self.utils.get_cidr_compressed(rec['cidr']) if rec['network_id'] == wan_network_id \ and vim_cidr['cidr'] == wan_cidr: subnet_exists_flg = True wan_subnet_id = rec['id'] break if subnet_exists_flg == False: # Create Subnet(OpenStack:VIM)(WAN) subnet_res_wan = osc_subnets.create_subnet(os_endpoint_vim, wan_network_id, wan_cidr, '', nal_tenant_id, self.utils.IP_VER_V6) wan_subnet_id = subnet_res_wan['subnet']['id'] # Get Port(OpenStack:VIM) os_port_res = osc_ports.get_port(os_endpoint_vim, wan_port_id) fixed_ips_update = os_port_res['port']['fixed_ips'] fixed_ips_update.append({ 'subnet_id': wan_subnet_id, 'ip_address': wan_ip }) # Update Port(OpenStack:VIM) os_port_upd = osc_ports.update_port(os_endpoint_vim, wan_port_id, None, None, fixed_ips_update) # Set JOB Output Parameters job_output = { 'port_info': os_port_upd, } return job_output
def __msa_port_create_wim_csr1000v(self, job_input, router_name): # Get JOB Input Parameters pod_id = job_input['pod_id'] dc_id = job_input['dc_id'] msa_network_info = job_input['msa_network_info'] nal_tenant_id = job_input['nal_tenant_id'] wan_network_id = job_input['wan_network_id'] # Get Allocation Info(WAN) wan_allocation_info = job_input['wan_allocation_info'][router_name] # Get Endpoint(OpenStack:VIM) os_endpoint_vim = self.get_os_endpoint_vim(pod_id, '', nal_tenant_id, dc_id) # Create Instance(OpenStack Client) osc_subnets = subnets.OscQuantumSubnets(self.job_config) osc_ports = ports.OscQuantumPorts(self.job_config) # Create Port(OpenStack:VIM)(MSA) port_res_msa = osc_ports.create_port(os_endpoint_vim, msa_network_info['network_id'], '', True, msa_network_info['subnet_id']) msa_port_id = port_res_msa['port']['id'] msa_ip_address = port_res_msa['port']['fixed_ips'][0]['ip_address'] msa_port_info = port_res_msa fixed_ips = [] for ip_ver in [self.utils.IP_VER_V4]: wan_cidr = wan_allocation_info['wan'][ip_ver]['subnet_ip'] \ + '/' + str(wan_allocation_info['wan'][ip_ver]['netmask']) wan_subnet_id = '' subnet_exists_flg = False # List Subnets(OpenStack:VIM) subnet_list = osc_subnets.list_subnets(os_endpoint_vim) for rec in subnet_list['subnets']: vim_cidr = self.utils.get_cidr_compressed(rec['cidr']) if rec['network_id'] == wan_network_id \ and vim_cidr['cidr'] == wan_cidr: subnet_exists_flg = True wan_subnet_id = rec['id'] break if subnet_exists_flg == False: # Create Subnet(OpenStack:VIM)(WAN) subnet_res_wan = osc_subnets.create_subnet( os_endpoint_vim, wan_network_id, wan_cidr, '', nal_tenant_id, ip_ver) wan_subnet_id = subnet_res_wan['subnet']['id'] fixed_ips.append({ 'subnet_id': wan_subnet_id, 'ip_address': wan_allocation_info['wan'][ip_ver]['ip'], }) # Create Port(OpenStack:VIM)(WAN) port_res_wan = osc_ports.create_port_dual_stack( os_endpoint_vim, wan_network_id, '', True, fixed_ips) # Set JOB Output Parameters job_output = { 'msa_netmask': msa_network_info['netmask'], 'msa_port_id': msa_port_id, 'msa_ip_address': msa_ip_address, 'msa_port_info': msa_port_info, 'wan_port_id': port_res_wan['port']['id'], 'wan_port_info': port_res_wan, 'wan_info': { self.utils.IP_VER_V4: { 'ip': wan_allocation_info['wan'][self.utils.IP_VER_V4]['ip'], 'netmask': wan_allocation_info['wan'][self.utils.IP_VER_V4] ['netmask'], }, } } return job_output