def put(self, _id, **kw): context = t_context.extract_context_from_environ() firewall_bypass = request.context['request_data']['firewall_bypass'] try: with context.session.begin(): core.get_resource_object(context, models.FirewallBypass, _id) firewall_bypass_updated = core.update_resource( context, models.FirewallBypass, _id, firewall_bypass) return_object = m.SuccessMessage( result={'firewall_bypass': firewall_bypass_updated}) return return_object.to_dict() except t_exceptions.ResourceNotFound as e1: LOG.exception( 'Failed to update firewall_bypass : '******'id%(id)s ,' '%(exception)s ', { 'id': _id, 'exception': e1 }) return m.FirewallBypassNotFound(id=_id).to_dict() except Exception as e2: LOG.exception( 'Failed to update firewall_bypass: '******'id: %(id)s,' '%(exception)s ', { 'id': _id, 'exception': e2 }) return_object = m.FailureMessage() return return_object.to_dict()
def put(self, _id, **kw): context = t_context.extract_context_from_environ() dci = request.context['request_data']['dci'] try: with context.session.begin(): core.get_resource_object(context, models.DCI, _id) connection_updated = core.update_resource( context, models.DCI, _id, dci) return_object = m.SuccessMessage( result={'dci': connection_updated}) return return_object.to_dict() except t_exceptions.ResourceNotFound as e: LOG.exception( 'Failed to update dci: ' 'dci_id %(dci_id)s ,' '%(exception)s ', { 'dci_id': _id, 'exception': e }) return m.DCINotFound(dci_id=_id).to_dict() except Exception as e: LOG.exception('Failed to update dci: ' '%(exception)s ', {'exception': e}) return_object = m.FailureMessage() return return_object.to_dict()
def delete(self, _id): context = t_context.extract_context_from_environ() if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE): pecan.abort(401, _('Unauthorized to delete regions')) return try: with context.session.begin(): print "MaXiao 111 delete region has dcs " region_object = core.get_resource_object(context, models.Region, _id) print "MaXiao delete region has dcs :"+str(region_result) if len(region_object.dcs)>0: raise t_exceptions.InUse("Specified region has dc(s)") core.delete_resource(context, models.Region, _id) pecan.response.status = 200 return {} except t_exceptions.InUse: return Response(_('Specified region has dcs'), 400) except t_exceptions.ResourceNotFound: return Response(_('Region not found'), 404) except Exception as e: LOG.exception('Failed to delete region: %(region_id)s,' '%(exception)s', {'region_id': _id, 'exception': e}) return Response(_('Failed to delete region'), 500)
def delete(self, _id): context = t_context.extract_context_from_environ() if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE): pecan.abort(401, _('Unauthorized to delete dcs')) return try: with context.session.begin(): region_object = core.get_resource_object(context, models.DC, _id) if len(region_object.fabrics) >0: raise t_exceptions.InUse("Specified dc has fabric(s)") if len(region_object.core_routers) >0: raise t_exceptions.InUse("Specified dc has core_router(s)") core.delete_resource(context, models.DC, _id) pecan.response.status = 200 return {} except t_exceptions.InUse: return Response(_('Specified region has dcs/core_routers'), 400) except t_exceptions.ResourceNotFound: return Response(_('DC not found'), 404) except Exception as e: LOG.exception('Failed to delete dc: %(dc_id)s,' '%(exception)s', {'dc_id': _id, 'exception': e}) return Response(_('Failed to delete dc'), 500)
def add_router_interface(self): context = t_context.extract_context_from_environ() body = {"core_router_interface": request.context['request_data']} attr_info = body_validation.RESOURCE_ATTRIBUTE_MAP.get(self.resource) body_validation.BodyValidationHook.check_request_body( body, True, "core_router_interface", attr_info) fabric = request.context['request_data']['fabric'] _uuid = uuidutils.generate_uuid() try: with context.session.begin(): core_router_object = core.get_resource_object( context, models.CoreRouter, self.core_router_id) new_core_router_interface = core.create_resource( context, models.CoreRouterInterface, { 'interface_id': _uuid, 'project_id': core_router_object.project_id, 'core_router_id': self.core_router_id, 'fabric': fabric, }) except t_exceptions.ResourceNotFound as e: LOG.exception( 'Failed to add core_router_interface : ' 'core_router_id %(core_router_id)s ,' '%(exception)s ', { 'core_router_id': self.core_router_id, 'exception': e }) return m.CoreRouterNotFound( core_router_id=self.core_router_id).to_dict() except db_exc.DBDuplicateEntry as e1: LOG.exception( 'Failed to create core_router_interface :' 'core_router_id: %(core_router_id)s,' 'fabric: %(fabric)s,' '%(exception)s ', { 'core_router_id': self.core_router_id, 'fabric': fabric, 'exception': e1 }) return_object = m.CoreRouterInterfaceForFabricExists(fabric=fabric) return return_object.to_dict() except Exception as e2: LOG.exception( 'Failed to create core_router_interface :' 'core_router_id: %(core_router_id)s,' 'fabric: %(fabric)s,' '%(exception)s ', { 'core_router_id': self.core_router_id, 'fabric': fabric, 'exception': e2 }) return_object = m.FailureMessage() return return_object.to_dict() return_object = m.SuccessMessage( result={'core_router_interface': new_core_router_interface}) return return_object.to_dict()
def delete(self, _id): context = t_context.extract_context_from_environ() if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE): pecan.abort(401, _('Unauthorized to delete core_router')) return try: with context.session.begin(): core_router_object = core.get_resource_object( context, models.CoreRouter, _id) if len(core_router_object.interfaces) > 0: raise t_exceptions.CoreRouterInUseInterfacesException( core_router_id=_id, count=len(core_router_object.interfaces)) if len(core_router_object.firewall_bypasss) > 0: raise t_exceptions.CoreRouterInUseFirewallBypasssException( core_router_id=_id, count=len(core_router_object.firewall_bypasss)) core.delete_resource(context, models.CoreRouter, _id) return_object = m.SuccessMessage(result={}) return return_object.to_dict() except t_exceptions.ResourceNotFound as e: LOG.exception( 'Failed to delete core_router : ' 'core_router_id %(core_router_id)s ,' '%(exception)s ', { 'core_router_id': _id, 'exception': e }) return m.CoreRouterNotFound(core_router_id=_id).to_dict() except t_exceptions.CoreRouterInUse as e: LOG.exception( 'Failed to delete core_router: ' '%(core_router_id)s,' '%(exception)s', { 'core_router_id': _id, 'exception': e }) return_object = m.CoreRouterInUse(str(e)) return return_object.to_dict() except Exception as e: LOG.exception( 'Failed to delete core_router: ' '%(core_router_id)s,' '%(exception)s', { 'core_router_id': _id, 'exception': e }) return_object = m.FailureMessage() return return_object.to_dict()
def put(self, _id, **kw): context = t_context.extract_context_from_environ() route_entry = request.context['request_data']['route_entry'] try: with context.session.begin(): core.get_resource_object(context, models.RouteEntry, _id) if 'destination_cidr_list' in route_entry: self._update_route_entry_destination_cidrs( context, _id, route_entry) route_entry_updated = core.update_resource( context, models.RouteEntry, _id, route_entry) return_object = m.SuccessMessage( result={'route_entry': route_entry_updated}) return return_object.to_dict() except t_exceptions.ResourceNotFound as e1: LOG.exception( 'Failed to update route_entry : ' 'id%(id)s ,' '%(exception)s ', { 'id': _id, 'exception': e1 }) return m.RouteEntryNotFound(id=_id).to_dict() except Exception as e2: LOG.exception( 'Failed to update route_entry: ' 'id: %(id)s,' '%(exception)s ', { 'id': _id, 'exception': e2 }) return_object = m.FailureMessage() return return_object.to_dict()
def post(self, **kw): context = t_context.extract_context_from_environ() if not policy.enforce(context, policy.ADMIN_API_PODS_CREATE): pecan.abort(401, _('Unauthorized to create firewall_bypass')) return firewall_bypass = request.context['request_data']['firewall_bypass'] fabric = firewall_bypass.get('fabric', '').strip() core_router_id = firewall_bypass.get('core_router_id', '').strip() router_id = firewall_bypass.get('router_id', '').strip() project_id = firewall_bypass.get('project_id', '').strip() admin_state_up = firewall_bypass.get('admin_state_up', True) status = firewall_bypass.get('status', "DOWN") description = firewall_bypass.get('description', '').strip() _uuid = uuidutils.generate_uuid() try: with context.session.begin(): core_router_object = core.get_resource_object( context, models.CoreRouter, core_router_id) new_firewall_bypass = core.create_resource( context, models.FirewallBypass, { 'id': _uuid, 'fabric': fabric, 'core_router_id': core_router_id, 'router_id': router_id, 'project_id': project_id, 'admin_state_up': admin_state_up, 'status': status, 'description': description }) return_object = m.SuccessMessage( result={'firewall_bypass': new_firewall_bypass}) return return_object.to_dict() except t_exceptions.ResourceNotFound as e: LOG.exception( 'Failed to add firewall_bypass: '******'core_router_id %(core_router_id)s not exists,' '%(exception)s ', { 'core_router_id': core_router_id, 'exception': e }) return m.CoreRouterNotFound( core_router_id=core_router_id).to_dict() except db_exc.DBDuplicateEntry as e1: LOG.exception( 'Record firewall_bypass already exists for ' 'router_id %(router_id)s: ' 'core_router_id %(core_router_id)s: ' '%(exception)s', { 'router_id': router_id, 'core_router_id': core_router_id, 'exception': e1 }) return_object = m.FirewallBypassExists( router_id=router_id, core_router_id=core_router_id) return return_object.to_dict() except Exception as e2: LOG.info( 'Failed to create firewall_bypass: '******'router_id: %(router_id)s,' 'core_router_id %(core_router_id)s: ' '%(exception)s ', { 'router_id': router_id, 'core_router_id': core_router_id, 'exception': e2 }) return_object = m.FailureMessage() return return_object.to_dict()