def workflow_kick_and_wait(self, call, url, body): http_status = -1 rj = None (http_status, rj) = call(url, body) if not isinstance(rj, dict): return (http_status, None) exeid = rj.get('executionid') if not isinstance(exeid, six.string_types): LOG.error(_LE('Invalid executin id %s'), exeid) try: wait_time = self.workflow_first_wait eventlet.sleep(wait_time) for __ in range(self.workflow_retry_count): (http_status, rw) = self.workflowinstance(exeid) if not isinstance(rw, dict): LOG.error( _LE('NWA workflow: failed %(http_status)s %(body)s'), {'http_status': http_status, 'body': rw} ) return (http_status, None) if rw.get('status') != 'RUNNING': LOG.debug('%s', rw) return (http_status, rw) eventlet.sleep(wait_time) wait_time = self.workflow_wait_sleep LOG.warning(_LW('NWA workflow: retry over. retry count is %s.'), self.workflow_retry_count) except Exception as e: LOG.error(_LE('NWA workflow: %s'), e) return (http_status, None)
def load_json_from_file(name, json_file, json_str, default_value): if json_file: json_file_abspath = cfg.CONF.find_file(json_file) if not json_file_abspath: LOG.error(_LE('Failed to load %(name)s_file' '"%(json_file)s": file not found'), {'name': name, 'json_file': json_file}) raise cfg.Error(_('NECNWA option parse error')) try: with open(json_file_abspath) as f: return jsonutils.loads(f.read()) except Exception as e: LOG.error(_LE('Failed to load %(name)s_file ' '"%(json_file)s": %(reason)s'), {'reason': e, 'name': name, 'json_file': json_file}) raise cfg.Error(_('NECNWA option parse error')) elif json_str: try: return jsonutils.loads(json_str) except Exception as e: LOG.error(_LE('NECNWA option error during loading %(name)s ' '(%(data)s): %(reason)s'), {'reason': e, 'name': name, 'data': json_str}) raise cfg.Error(_('NECNWA option parse error')) else: LOG.warning(_LW('%(name)s is not configured. ' 'Make sure to set [NWA] %(name)s_file ' 'in NWA plugin configuration file. ' 'Using %(default)s as default value.'), {'name': name, 'default': default_value}) return default_value
def update_port_state_with_notifier(self, rpc_context, **kwargs): port_id = kwargs.get('port_id') network_id = kwargs.get('network_id') network_type = kwargs.get('network_type') segmentation_id = kwargs.get('segmentation_id') physical_network = kwargs.get('physical_network') # 1 update segment session = db_api.get_session() with session.begin(subtransactions=True): try: query = (session.query(models_ml2.NetworkSegment). filter_by(network_id=network_id)) query = query.filter_by(physical_network=physical_network) query = query.filter_by(is_dynamic=True) record = query.one() record.segmentation_id = segmentation_id except sa_exc.NoResultFound: pass # 2 change port state plugin = manager.NeutronManager.get_plugin() plugin.update_port_status( rpc_context, port_id, constants.PORT_STATUS_ACTIVE ) # 3 serch db from port_id session = db_api.get_session() port = None with session.begin(subtransactions=True): try: port_db = (session.query(models_v2.Port). enable_eagerloads(False). filter(models_v2.Port.id.startswith(port_id)). one()) port = plugin._make_port_dict(port_db) except sa_exc.NoResultFound: LOG.error(_LE("Can't find port with port_id %s"), port_id) except sa_exc.MultipleResultsFound: LOG.error(_LE("Multiple ports have port_id starting with %s"), port_id) # 4 send notifier if port is not None: LOG.debug("notifier port_update %(net_type)s, %(seg_id)s, " "%(physnet)s", {'net_type': network_type, 'seg_id': segmentation_id, 'physnet': physical_network}) plugin.notifier.port_update( rpc_context, port, network_type, segmentation_id, physical_network ) return {}
def update_port_state_with_notifier(self, rpc_context, **kwargs): port_id = kwargs.get('port_id') network_id = kwargs.get('network_id') network_type = kwargs.get('network_type') segmentation_id = kwargs.get('segmentation_id') physical_network = kwargs.get('physical_network') # 1 update segment session = db_api.get_session() with session.begin(subtransactions=True): try: query = (session.query(models_ml2.NetworkSegment).filter_by( network_id=network_id)) query = query.filter_by(physical_network=physical_network) query = query.filter_by(is_dynamic=True) record = query.one() record.segmentation_id = segmentation_id except sa_exc.NoResultFound: pass # 2 change port state plugin = manager.NeutronManager.get_plugin() plugin.update_port_status(rpc_context, port_id, constants.PORT_STATUS_ACTIVE) # 3 serch db from port_id session = db_api.get_session() port = None with session.begin(subtransactions=True): try: port_db = (session.query( models_v2.Port).enable_eagerloads(False).filter( models_v2.Port.id.startswith(port_id)).one()) port = plugin._make_port_dict(port_db) except sa_exc.NoResultFound: LOG.error(_LE("Can't find port with port_id %s"), port_id) except sa_exc.MultipleResultsFound: LOG.error(_LE("Multiple ports have port_id starting with %s"), port_id) # 4 send notifier if port is not None: LOG.debug( "notifier port_update %(net_type)s, %(seg_id)s, " "%(physnet)s", { 'net_type': network_type, 'seg_id': segmentation_id, 'physnet': physical_network }) plugin.notifier.port_update(rpc_context, port, network_type, segmentation_id, physical_network) return {}
def _add_router_interface_by_port(self, plugin, context, router_id, interface_info): try: session = context.session port = plugin._core_plugin._get_port(context, interface_info['port_id']) network = plugin._core_plugin.get_network(context, port['network_id']) binding = nwa_db.ensure_port_binding(session, port['id']) port_context = driver_context.PortContext(plugin._core_plugin, context, port, network, binding, None) nwa_info = nwa_l2_utils.portcontext_to_nwa_info( port_context, self.resource_groups) rt_tid = nwa_l3_db.get_tenant_id_by_router( session, router_id ) nwa_rt_tid = nwa_com_utils.get_nwa_tenant_id(rt_tid) nwa_info['tenant_id'] = rt_tid nwa_info['nwa_tenant_id'] = nwa_rt_tid proxy = self._get_nwa_proxy(plugin, rt_tid) proxy.create_tenant_fw( port_context.network._plugin_context, rt_tid, nwa_rt_tid, nwa_info ) except Exception as e: LOG.exception(_LE("create tenant firewall %s"), e)
def _create_vlan(self, context, **kwargs): nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') nwa_data = kwargs.get('nwa_data') network_id = nwa_info['network']['id'] nw_vlan_key = data_utils.get_vlan_key(network_id) if nw_vlan_key in nwa_data: LOG.warning(_LW("aleady in vlan_key %s"), nw_vlan_key) return nwa_data rcode, body = self.client.l2.create_vlan( nwa_tenant_id, nwa_info['subnet']['netaddr'], nwa_info['subnet']['mask'], nwa_info['network']['vlan_type'], openstack_network_id=network_id) if rcode == 200 and body['status'] == 'SUCCEED': # create vlan succeed. LOG.debug("CreateVlan succeed.") data_utils.set_network_data(nwa_data, network_id, nwa_info, body['resultdata']['LogicalNWName']) data_utils.set_vlan_data(nwa_data, network_id, body['resultdata']['VlanID']) else: # create vlan failed. LOG.error(_LE("CreateVlan Failed.")) raise nwa_exc.AgentProxyException(value=nwa_data) return nwa_data
def _create_tenant_nw(self, context, **kwargs): nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') # get resource group name for NWA TenantNW. resource_group_name = nwa_info['resource_group_name_nw'] nwa_data = kwargs.get('nwa_data') if KEY_CREATE_TENANT_NW not in nwa_data: LOG.debug("nwa_tenant_id=%(nwa_tenant_id)s, " "resource_group_name_nw=%(resource_group_name)s", {'nwa_tenant_id': nwa_tenant_id, 'resource_group_name': resource_group_name}) rcode, body = self.client.l2.create_tenant_nw( nwa_tenant_id, resource_group_name ) if rcode == 200 and body['status'] == 'SUCCEED': LOG.debug("CreateTenantNW succeed.") nwa_data[KEY_CREATE_TENANT_NW] = True return nwa_data else: LOG.error(_LE("CreateTenantNW Failed.")) raise nwa_exc.AgentProxyException(value=nwa_data)
def _create_vlan(self, context, **kwargs): nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') nwa_data = kwargs.get('nwa_data') network_id = nwa_info['network']['id'] nw_vlan_key = data_utils.get_vlan_key(network_id) if nw_vlan_key in nwa_data: LOG.warning(_LW("aleady in vlan_key %s"), nw_vlan_key) return nwa_data rcode, body = self.client.l2.create_vlan( nwa_tenant_id, nwa_info['subnet']['netaddr'], nwa_info['subnet']['mask'], nwa_info['network']['vlan_type'], openstack_network_id=network_id ) if rcode == 200 and body['status'] == 'SUCCEED': # create vlan succeed. LOG.debug("CreateVlan succeed.") data_utils.set_network_data(nwa_data, network_id, nwa_info, body['resultdata']['LogicalNWName']) data_utils.set_vlan_data(nwa_data, network_id, body['resultdata']['VlanID']) else: # create vlan failed. LOG.error(_LE("CreateVlan Failed.")) raise nwa_exc.AgentProxyException(value=nwa_data) return nwa_data
def _create_tenant_nw(self, context, **kwargs): nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') # get resource group name for NWA TenantNW. resource_group_name = nwa_info['resource_group_name_nw'] nwa_data = kwargs.get('nwa_data') if KEY_CREATE_TENANT_NW not in nwa_data: LOG.debug( "nwa_tenant_id=%(nwa_tenant_id)s, " "resource_group_name_nw=%(resource_group_name)s", { 'nwa_tenant_id': nwa_tenant_id, 'resource_group_name': resource_group_name }) rcode, body = self.client.l2.create_tenant_nw( nwa_tenant_id, resource_group_name) if rcode == 200 and body['status'] == 'SUCCEED': LOG.debug("CreateTenantNW succeed.") nwa_data[KEY_CREATE_TENANT_NW] = True return nwa_data else: LOG.error(_LE("CreateTenantNW Failed.")) raise nwa_exc.AgentProxyException(value=nwa_data)
def delete_tenant_fw(self, context, **kwargs): """Delete Tenant FireWall. @param context: contains user information. @param kwargs: tenant_id, nwa_tenant_id, nwa_info @return: dict of status and msg. """ tenant_id = kwargs.get('tenant_id') nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') network_id = nwa_info['network']['id'] device_id = nwa_info['device']['id'] nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( context, tenant_id, nwa_tenant_id ) # check tfw interface tfwif = "^DEV_" + device_id + '_.*_TenantFWName$' count = sum(not re.match(tfwif, k) is None for k in nwa_data.keys()) if 1 < count: ret_val = self._update_tenant_fw( context, nwa_data=nwa_data, connect='disconnect', **kwargs ) if not ret_val: LOG.error(_LE("UpdateTenantFW disconnect FAILED")) tfw_sgif = re.compile("^DEV_.*_" + network_id + '_TYPE$') sgif_count = len([k for k in nwa_data if tfw_sgif.match(k)]) if sgif_count: raise nwa_exc.AgentProxyException(value=nwa_data) nwa_data = ret_val elif count == 1: # raise AgentProxyException if fail nwa_data = self._delete_tenant_fw( context, nwa_data=nwa_data, **kwargs) else: LOG.error(_LE("count miss match")) raise nwa_exc.AgentProxyException(value=nwa_data) return self.proxy_l2._terminate_l2_network(context, nwa_data, **kwargs)
def load_json_from_file(name, json_file, json_str, default_value): if json_file: json_file_abspath = cfg.CONF.find_file(json_file) if not json_file_abspath: LOG.error( _LE('Failed to load %(name)s_file' '"%(json_file)s": file not found'), { 'name': name, 'json_file': json_file }) raise cfg.Error(_('NECNWA option parse error')) try: with open(json_file_abspath) as f: return jsonutils.loads(f.read()) except Exception as e: LOG.error( _LE('Failed to load %(name)s_file ' '"%(json_file)s": %(reason)s'), { 'reason': e, 'name': name, 'json_file': json_file }) raise cfg.Error(_('NECNWA option parse error')) elif json_str: try: return jsonutils.loads(json_str) except Exception as e: LOG.error( _LE('NECNWA option error during loading %(name)s ' '(%(data)s): %(reason)s'), { 'reason': e, 'name': name, 'data': json_str }) raise cfg.Error(_('NECNWA option parse error')) else: LOG.warning( _LW('%(name)s is not configured. ' 'Make sure to set [NWA] %(name)s_file ' 'in NWA plugin configuration file. ' 'Using %(default)s as default value.'), { 'name': name, 'default': default_value }) return default_value
def delete_tenant_fw(self, context, **kwargs): """Delete Tenant FireWall. @param context: contains user information. @param kwargs: tenant_id, nwa_tenant_id, nwa_info @return: dict of status and msg. """ tenant_id = kwargs.get('tenant_id') nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') network_id = nwa_info['network']['id'] device_id = nwa_info['device']['id'] nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( context, tenant_id, nwa_tenant_id) # check tfw interface tfwif = "^DEV_" + device_id + '_.*_TenantFWName$' count = sum(not re.match(tfwif, k) is None for k in nwa_data.keys()) if 1 < count: ret_val = self._update_tenant_fw(context, nwa_data=nwa_data, connect='disconnect', **kwargs) if not ret_val: LOG.error(_LE("UpdateTenantFW disconnect FAILED")) tfw_sgif = re.compile("^DEV_.*_" + network_id + '_TYPE$') sgif_count = len([k for k in nwa_data if tfw_sgif.match(k)]) if sgif_count: raise nwa_exc.AgentProxyException(value=nwa_data) nwa_data = ret_val elif count == 1: # raise AgentProxyException if fail nwa_data = self._delete_tenant_fw(context, nwa_data=nwa_data, **kwargs) else: LOG.error(_LE("count miss match")) raise nwa_exc.AgentProxyException(value=nwa_data) return self.proxy_l2._terminate_l2_network(context, nwa_data, **kwargs)
def server_start(): while True: try: LOG.debug('RPCServer thread %d start %s', (self.greenpool.running(), server)) server.start() LOG.debug('RPCServer thread end %s', server) break except Exception as e: LOG.exception(_LE('RPCServer thread start failed: %s'), e)
def delete_general_dev(self, context, **kwargs): """Delete GeneralDev. @param context: contains user information. @param kwargs: @return: dict of status and msg. """ tenant_id = kwargs.get('tenant_id') nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') network_id = nwa_info['network']['id'] resource_group_name = nwa_info['resource_group_name'] nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( context, tenant_id, nwa_tenant_id) # rpc return empty. if not nwa_data: LOG.error( _LE('nwa_tenant_binding not found.' ' tenant_id=%(tenant_id)s,' ' nwa_tenant_id=%(nwa_tenant_id)s'), { 'tenant_id': tenant_id, 'nwa_tenant_id': nwa_tenant_id }) return {'result': 'FAILED'} if not resource_group_name: resource_group_name = get_resource_group_name( nwa_info, nwa_data, nwa_const.NWA_DEVICE_GDV) if not resource_group_name: LOG.debug( 'skip delete_general_dev.' ' No nwa device is associated with' ' the port %s', nwa_info.get('port')) return {'result': 'FAILED'} nwa_info['resource_group_name'] = resource_group_name gd_count = check_segment_gd(network_id, resource_group_name, nwa_data) if 1 < gd_count: nwa_data = self._delete_general_dev_data(nwa_data=nwa_data, **kwargs) raise nwa_exc.AgentProxyException(value=nwa_data) # delete general dev # raise AgentProxyException if fail nwa_data = self._delete_general_dev(context, nwa_data=nwa_data, **kwargs) # delete general dev end return self._terminate_l2_network(context, nwa_data, **kwargs)
def _report_state(self): try: queues = self.server_manager.get_rpc_server_topics() self.agent_state['configurations']['tenant_queues'] = queues self.state_rpc.report_state(self.context, self.agent_state) self.agent_state.pop('start_flag', None) servers = self.server_manager.get_rpc_server_tenant_ids() self.nwa_l2_rpc.update_tenant_rpc_servers(self.context, servers) except Exception as e: LOG.exception(_LE("Failed reporting state! %s"), e)
def delete_general_dev(self, context, **kwargs): """Delete GeneralDev. @param context: contains user information. @param kwargs: @return: dict of status and msg. """ tenant_id = kwargs.get('tenant_id') nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') network_id = nwa_info['network']['id'] resource_group_name = nwa_info['resource_group_name'] nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( context, tenant_id, nwa_tenant_id ) # rpc return empty. if not nwa_data: LOG.error(_LE('nwa_tenant_binding not found.' ' tenant_id=%(tenant_id)s,' ' nwa_tenant_id=%(nwa_tenant_id)s'), {'tenant_id': tenant_id, 'nwa_tenant_id': nwa_tenant_id}) return {'result': 'FAILED'} if not resource_group_name: resource_group_name = get_resource_group_name( nwa_info, nwa_data, nwa_const.NWA_DEVICE_GDV) if not resource_group_name: LOG.debug('skip delete_general_dev.' ' No nwa device is associated with' ' the port %s', nwa_info.get('port')) return {'result': 'FAILED'} nwa_info['resource_group_name'] = resource_group_name gd_count = check_segment_gd(network_id, resource_group_name, nwa_data) if 1 < gd_count: nwa_data = self._delete_general_dev_data( nwa_data=nwa_data, **kwargs) self._delete_general_dev_segment(context, nwa_data, nwa_info) raise nwa_exc.AgentProxyException(value=nwa_data) # delete general dev # raise AgentProxyException if fail nwa_data = self._delete_general_dev(context, nwa_data=nwa_data, **kwargs) # delete general dev end return self._terminate_l2_network(context, nwa_data, **kwargs)
def _delete_tenant_nw(self, context, **kwargs): nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_data = kwargs.get('nwa_data') rcode, body = self.client.l2.delete_tenant_nw(nwa_tenant_id, ) if rcode == 200 and body['status'] == 'SUCCEED': LOG.debug("DeleteTenantNW SUCCEED.") nwa_data.pop(KEY_CREATE_TENANT_NW) else: LOG.error(_LE("DeleteTenantNW %s."), body['status']) raise nwa_exc.AgentProxyException(value=nwa_data) return nwa_data
def _report_state(self): try: queues = self.server_manager.get_rpc_server_topics() self.agent_state['configurations']['tenant_queues'] = len(queues) self.state_rpc.report_state(self.context, self.agent_state) self.agent_state.pop('start_flag', None) servers = self.server_manager.get_rpc_server_tenant_ids() self.nwa_l2_rpc.update_tenant_rpc_servers( self.context, servers ) except Exception as e: LOG.exception(_LE("Failed reporting state! %s"), e)
def update_floatingip(self, context, fpid, floatingip): port_id_specified = 'port_id' in floatingip['floatingip'] if not port_id_specified: LOG.error(_LE("port_id key is not found in %s"), floatingip) raise exc.PortNotFound(port_id=None) port_id = floatingip['floatingip'].get('port_id') try: if port_id_specified and not port_id: floating = context.session.query(l3_db.FloatingIP).filter_by( id=fpid).one() self._delete_nat(context, floating) except sa.orm.exc.NoResultFound: raise exc.PortNotFound(port_id=port_id) ret = super(NECNWAL3Plugin, self).update_floatingip( context, fpid, floatingip) try: if port_id_specified and port_id: floating = context.session.query(l3_db.FloatingIP).filter_by( id=fpid).one() tenant_id = nwa_l3_db.get_tenant_id_by_router( context.session, floating['router_id'] ) nwa_tenant_id = nwa_com_utils.get_nwa_tenant_id(tenant_id) fl_data = { 'floating_ip_address': floating['floating_ip_address'], 'fixed_ip_address': floating['fixed_ip_address'], 'id': fpid, 'device_id': floating['router_id'], 'floating_network_id': floating['floating_network_id'], 'tenant_id': floating['tenant_id'], 'floating_port_id': floating['floating_port_id'] } LOG.info(_LI('setting_nat fl_data is %s'), fl_data) proxy = self._get_nwa_proxy(self, tenant_id) proxy.setting_nat( context, tenant_id=tenant_id, nwa_tenant_id=nwa_tenant_id, floating=fl_data ) except sa.orm.exc.NoResultFound: raise exc.PortNotFound(port_id=port_id) return ret
def _delete_tenant_nw(self, context, **kwargs): nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_data = kwargs.get('nwa_data') rcode, body = self.client.l2.delete_tenant_nw( nwa_tenant_id, ) if rcode == 200 and body['status'] == 'SUCCEED': LOG.debug("DeleteTenantNW SUCCEED.") nwa_data.pop(KEY_CREATE_TENANT_NW) else: LOG.error(_LE("DeleteTenantNW %s."), body['status']) raise nwa_exc.AgentProxyException(value=nwa_data) return nwa_data
def _update_tenant_fw_disconnect(self, context, **kwargs): """Update Tenant FW @param context: contains user information. @param kwargs: @return: nwa_data @raise AgentProxyException """ nwa_data = kwargs.get('nwa_data') device_id = kwargs['nwa_info']['device']['id'] network_id = kwargs['nwa_info']['network']['id'] device_name = data_utils.get_tfw_device_name(nwa_data, device_id) if self.tenant_fw_disconnect_hook: self.tenant_fw_disconnect_hook(context, device_name, **kwargs) rcode, body = self.client.l3.update_tenant_fw( kwargs['nwa_tenant_id'], device_name, kwargs['nwa_info']['port']['ip'], data_utils.get_vlan_logical_name(nwa_data, network_id), kwargs['nwa_info']['network']['vlan_type'], connect='disconnect') if rcode != 200 or body['status'] != 'SUCCEED': LOG.error(_LE("UpdateTenantFW(disconnect) FAILED.")) info = { 'status': 'FAILED', 'msg': 'UpdateTenantFW(disconnect) FAILED.' } raise nwa_exc.AgentProxyException(value=info) LOG.debug("UpdateTenantFW(disconnect) SUCCEED.") resource_group_name_nw = kwargs['nwa_info']['resource_group_name_nw'] data_utils.strip_interface_data(nwa_data, device_id, network_id, resource_group_name_nw) data_utils.strip_tfw_data_if_exist(nwa_data, device_id, network_id, resource_group_name_nw) if not l2.check_segment_tfw(network_id, resource_group_name_nw, nwa_data): data_utils.strip_vp_net_data(nwa_data, network_id, resource_group_name_nw, nwa_const.NWA_DEVICE_TFW) return nwa_data
def update_nat(self, tenant_id, vlan_logical_name, vlan_type, local_ip, global_ip, dev_name, data=None, router_id=None): try: http_status, rj = self.delete_nat(tenant_id, vlan_logical_name, vlan_type, local_ip, global_ip, dev_name, data=data) except Exception as e: LOG.exception(_LE('%s'), e) http_status = -1 rj = None self.setting_nat(tenant_id, vlan_logical_name, vlan_type, local_ip, global_ip, dev_name, data=data, router_id=router_id) return http_status, rj
def _log_workflow_error(self, data): errno = workflow.NwaWorkflow.get_errno_from_resultdata(data) if not self._post_data: return '' post_url, post_body = self._post_data if isinstance(post_body, dict): post_body = jsonutils.dumps(post_body, indent=4, sort_keys=True) name = (workflow.NwaWorkflow.name(post_url) or post_url) reason = workflow.NwaWorkflow.strerror(errno) LOG.error(_LE("NWA workflow: %(name)s reason(%(errno)s)=%(reason)s " "request=%(request)s, response=%(response)s"), {'name': name, 'errno': errno, 'reason': reason, 'request': post_body, 'response': jsonutils.dumps(data, indent=4, sort_keys=True) })
def _update_tenant_fw_disconnect(self, context, **kwargs): """Update Tenant FW @param context: contains user information. @param kwargs: @return: nwa_data @raise AgentProxyException """ nwa_data = kwargs.get('nwa_data') device_id = kwargs['nwa_info']['device']['id'] network_id = kwargs['nwa_info']['network']['id'] device_name = data_utils.get_tfw_device_name(nwa_data, device_id) if self.tenant_fw_disconnect_hook: self.tenant_fw_disconnect_hook(context, device_name, **kwargs) rcode, body = self.client.l3.update_tenant_fw( kwargs['nwa_tenant_id'], device_name, kwargs['nwa_info']['port']['ip'], data_utils.get_vlan_logical_name(nwa_data, network_id), kwargs['nwa_info']['network']['vlan_type'], connect='disconnect' ) if rcode != 200 or body['status'] != 'SUCCEED': LOG.error(_LE("UpdateTenantFW(disconnect) FAILED.")) info = {'status': 'FAILED', 'msg': 'UpdateTenantFW(disconnect) FAILED.'} raise nwa_exc.AgentProxyException(value=info) LOG.debug("UpdateTenantFW(disconnect) SUCCEED.") resource_group_name_nw = kwargs['nwa_info']['resource_group_name_nw'] data_utils.strip_interface_data(nwa_data, device_id, network_id, resource_group_name_nw) data_utils.strip_tfw_data_if_exist(nwa_data, device_id, network_id, resource_group_name_nw) if not l2.check_segment_tfw(network_id, resource_group_name_nw, nwa_data): data_utils.strip_vp_net_data(nwa_data, network_id, resource_group_name_nw, nwa_const.NWA_DEVICE_TFW) return nwa_data
def wrapper(*args, **kwargs): first_arg = args[0] cls = (first_arg if isinstance(first_arg, type) else first_arg.__class__) data = {'class_name': _get_full_class_name(cls), 'method_name': method.__name__} try: ret = method(*args, **kwargs) data['ret'] = ret LOG.debug('%(class_name)s method %(method_name)s ' 'call returned %(ret)s', data) return ret except Exception as e: with excutils.save_and_reraise_exception(): data['exctype'] = e.__class__.__name__ data['reason'] = e LOG.error(_LE('%(class_name)s method %(method_name)s ' 'call raised %(exctype)s: %(reason)s'), data)
def call_workflow(self, tenant_id, post, name, body): url = workflow.NwaWorkflow.path(name) try: wkf = nwa_sem.Semaphore.get_tenant_semaphore(tenant_id) if wkf.sem.locked(): LOG.info(_LI('NWA sem %s(count)s: %(name)s %(url)s %(body)s'), {'count': wkf.sem.balance, 'name': post.__name__, 'url': url, 'body': body}) with wkf.sem: n = copy.copy(self) n.workflow_polling_log_post_data(url, body) http_status, rj = n.workflow_kick_and_wait(post, url, body) return http_status, rj except Exception as e: LOG.exception(_LE('%s'), e) return -1, None
def _delete_tenant_fw(self, context, **kwargs): """Delete Tenant FW @param context: contains user information. @param kwargs: nwa_tenant_id, nwa_tenant_id, nwa_info, nwa_data @return: resutl(succeed = True, other = False), data(nwa_data or None) """ nwa_data = kwargs.get('nwa_data') nwa_info = kwargs['nwa_info'] network_id = nwa_info['network']['id'] device_id = nwa_info['device']['id'] device_name = data_utils.get_tfw_device_name(nwa_data, device_id) if self.tenant_fw_delete_hook: self.tenant_fw_delete_hook(context, device_name, **kwargs) rcode, body = self.client.l3.delete_tenant_fw( kwargs['nwa_tenant_id'], device_name, 'TFW' ) if rcode != 200 or body['status'] != 'SUCCEED': msg = _LE("DeleteTenantFW %s."), body['status'] LOG.error(msg) raise nwa_exc.AgentProxyException(value=nwa_data) LOG.debug("DeleteTenantFW SUCCEED.") resource_group_name_nw = nwa_info['resource_group_name_nw'] # delete recode data_utils.strip_device_data(nwa_data, device_id) data_utils.strip_interface_data(nwa_data, device_id, network_id, resource_group_name_nw) data_utils.strip_tfw_data_if_exist(nwa_data, device_id, network_id, resource_group_name_nw) if not l2.check_segment_tfw(network_id, resource_group_name_nw, nwa_data): data_utils.strip_vp_net_data(nwa_data, network_id, resource_group_name_nw, nwa_const.NWA_DEVICE_TFW) return nwa_data
def _delete_tenant_fw(self, context, **kwargs): """Delete Tenant FW @param context: contains user information. @param kwargs: nwa_tenant_id, nwa_tenant_id, nwa_info, nwa_data @return: resutl(succeed = True, other = False), data(nwa_data or None) """ nwa_data = kwargs.get('nwa_data') nwa_info = kwargs['nwa_info'] network_id = nwa_info['network']['id'] device_id = nwa_info['device']['id'] device_name = data_utils.get_tfw_device_name(nwa_data, device_id) if self.tenant_fw_delete_hook: self.tenant_fw_delete_hook(context, device_name, **kwargs) rcode, body = self.client.l3.delete_tenant_fw(kwargs['nwa_tenant_id'], device_name, 'TFW') if rcode != 200 or body['status'] != 'SUCCEED': msg = _LE("DeleteTenantFW %s."), body['status'] LOG.error(msg) raise nwa_exc.AgentProxyException(value=nwa_data) LOG.debug("DeleteTenantFW SUCCEED.") resource_group_name_nw = nwa_info['resource_group_name_nw'] # delete recode data_utils.strip_device_data(nwa_data, device_id) data_utils.strip_interface_data(nwa_data, device_id, network_id, resource_group_name_nw) data_utils.strip_tfw_data_if_exist(nwa_data, device_id, network_id, resource_group_name_nw) if not l2.check_segment_tfw(network_id, resource_group_name_nw, nwa_data): data_utils.strip_vp_net_data(nwa_data, network_id, resource_group_name_nw, nwa_const.NWA_DEVICE_TFW) return nwa_data
def wrapper(*args, **kwargs): first_arg = args[0] cls = (first_arg if isinstance(first_arg, type) else first_arg.__class__) data = { 'class_name': _get_full_class_name(cls), 'method_name': method.__name__ } try: ret = method(*args, **kwargs) data['ret'] = ret LOG.debug( '%(class_name)s method %(method_name)s ' 'call returned %(ret)s', data) return ret except Exception as e: with excutils.save_and_reraise_exception(): data['exctype'] = e.__class__.__name__ data['reason'] = e LOG.error( _LE('%(class_name)s method %(method_name)s ' 'call raised %(exctype)s: %(reason)s'), data)
def _create_general_dev(self, context, **kwargs): nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') nwa_data = kwargs.get('nwa_data') network_id = nwa_info['network']['id'] resource_group_name = nwa_info['resource_group_name'] port_type = None rcode, body = self.client.l2.create_general_dev( nwa_tenant_id, resource_group_name, data_utils.get_vlan_logical_name(nwa_data, network_id), port_type=port_type ) if rcode == 200 and body['status'] == 'SUCCEED': LOG.debug("CreateGeneralDev SUCCEED") vlan_key = data_utils.get_vlan_key(network_id) if vlan_key not in nwa_data: LOG.error(_LE("not create vlan.")) raise nwa_exc.AgentProxyException(value=nwa_data) vlan_id = data_utils.get_vlan_id(network_id, nwa_data, body['resultdata']) data_utils.set_vp_net_data(nwa_data, network_id, resource_group_name, nwa_const.NWA_DEVICE_GDV, vlan_id) self._append_device_for_gdv(nwa_info, nwa_data) else: LOG.debug("CreateGeneralDev %s", body['status']) raise nwa_exc.AgentProxyException(value=nwa_data) return nwa_data
def _create_general_dev(self, context, **kwargs): nwa_tenant_id = kwargs.get('nwa_tenant_id') nwa_info = kwargs.get('nwa_info') nwa_data = kwargs.get('nwa_data') network_id = nwa_info['network']['id'] resource_group_name = nwa_info['resource_group_name'] port_type = None rcode, body = self.client.l2.create_general_dev( nwa_tenant_id, resource_group_name, data_utils.get_vlan_logical_name(nwa_data, network_id), port_type=port_type) if rcode == 200 and body['status'] == 'SUCCEED': LOG.debug("CreateGeneralDev SUCCEED") vlan_key = data_utils.get_vlan_key(network_id) if vlan_key not in nwa_data: LOG.error(_LE("not create vlan.")) raise nwa_exc.AgentProxyException(value=nwa_data) vlan_id = data_utils.get_vlan_id(network_id, nwa_data, body['resultdata']) data_utils.set_vp_net_data(nwa_data, network_id, resource_group_name, nwa_const.NWA_DEVICE_GDV, vlan_id) self._append_device_for_gdv(nwa_info, nwa_data) else: LOG.debug("CreateGeneralDev %s", body['status']) raise nwa_exc.AgentProxyException(value=nwa_data) return nwa_data
def get_port_from_device(self, context, device): LOG.error(_LE('This method should not be called. ' 'get_ports_from_devices is used.'))