def clr_ext_gw(obj, context, port): ip_address = port['fixed_ips'][0]['ip_address'] subnetv2_db = fortinet_db.query_record( context, models_v2.Subnet, id=port['fixed_ips'][0]['subnet_id']) netmask = netaddr.IPNetwork(subnetv2_db.cidr).netmask ip = "%s %s" % (ip_address, netmask) delete_interface_ip(obj, context, name=obj._fortigate['ext_interface'], vdom=const.EXT_VDOM, ip=ip) delete_fwpolicy(obj, context, vdom=const.EXT_VDOM, poolname=ip_address) delete_fwippool(obj, context, vdom=const.EXT_VDOM, name=ip_address) router_db = fortinet_db.query_record(context, l3_db.Router, id=port['device_id']) tenant_id = router_db.get('tenant_id', None) if tenant_id: delete_vlink(obj, context, tenant_id=tenant_id) if not [ getattr(record, 'gw_port_id', None) for record in fortinet_db.query_records(context, l3_db.Router, tenant_id=tenant_id) if getattr(record, 'gw_port_id', None)] and \ not fortinet_db.query_count(context, models_v2.Network, tenant_id=tenant_id): delete_vdom(obj, context, tenant_id=tenant_id)
def delete_network_postcommit(self, mech_context): """Delete network which translates to remove vlan interface and related vdom from the fortigate. """ LOG.debug(_("delete_network_postcommit: called")) network = mech_context.current context = mech_context._plugin_context tenant_id = network["tenant_id"] if not fortinet_db.query_count(context, models_v2.Network, tenant_id=tenant_id): try: namespace = fortinet_db.query_record(context, fortinet_db.Fortinet_ML2_Namespace, tenant_id=tenant_id) if not namespace: return if not [ getattr(record, "gw_port_id", None) for record in fortinet_db.query_records(context, l3_db.Router, tenant_id=namespace.tenant_id) if getattr(record, "gw_port_id", None) ]: utils.delete_vlink(self, context, tenant_id=tenant_id) utils.delete_vdom(self, context, vdom=namespace.vdom) LOG.info( _("delete network postcommit: tenant= %(tenant_id)s" " vdom= %(vdom)s"), {"tenant_id": tenant_id, "vdom": namespace.vdom}, ) except Exception as e: resources.Exinfo(e) raise ml2_exc.MechanismDriverError(method=sys._getframe().f_code.co_name)
def delete_network_postcommit(self, mech_context): """Delete network which translates to remove vlan interface and related vdom from the fortigate. """ LOG.debug(_("delete_network_postcommit: called")) network = mech_context.current context = mech_context._plugin_context tenant_id = network['tenant_id'] if not fortinet_db.query_count( context, models_v2.Network, tenant_id=tenant_id): try: namespace = fortinet_db.query_record( context, fortinet_db.Fortinet_ML2_Namespace, tenant_id=tenant_id) if not namespace: return if not [ getattr(record, 'gw_port_id', None) for record in fortinet_db.query_records( context, l3_db.Router, tenant_id=namespace.tenant_id) if getattr(record, 'gw_port_id', None) ]: utils.delete_vlink(self, context, tenant_id=tenant_id) utils.delete_vdom(self, context, vdom=namespace.vdom) LOG.info( _("delete network postcommit: tenant= %(tenant_id)s" " vdom= %(vdom)s"), { 'tenant_id': tenant_id, 'vdom': namespace.vdom }) except Exception as e: resources.Exinfo(e) raise ml2_exc.MechanismDriverError( method=sys._getframe().f_code.co_name)
def clr_ext_gw(obj, context, port): ip_address = port['fixed_ips'][0]['ip_address'] subnetv2_db = fortinet_db.query_record(context, models_v2.Subnet, id=port['fixed_ips'][0]['subnet_id']) netmask = netaddr.IPNetwork(subnetv2_db.cidr).netmask ip = "%s %s" % (ip_address, netmask) delete_interface_ip(obj, context, name=obj._fortigate['ext_interface'], vdom=const.EXT_VDOM, ip=ip) delete_fwpolicy(obj, context, vdom=const.EXT_VDOM, poolname=ip_address) delete_fwippool(obj, context, vdom=const.EXT_VDOM, name=ip_address) router_db = fortinet_db.query_record(context, l3_db.Router, id=port['device_id']) tenant_id = router_db.get('tenant_id', None) if tenant_id: delete_vlink(obj, context, tenant_id=tenant_id) if not [ getattr(record, 'gw_port_id', None) for record in fortinet_db.query_records(context, l3_db.Router, tenant_id=tenant_id) if getattr(record, 'gw_port_id', None)] and \ not fortinet_db.query_count(context, models_v2.Network, tenant_id=tenant_id): delete_vdom(obj, context, tenant_id=tenant_id)