def delete_ag(context, aggregate_id): core.delete_resources(context, models.AggregateMetadata, [{'key': 'aggregate_id', 'comparator': 'eq', 'value': aggregate_id}]) core.delete_resource(context, models.Aggregate, aggregate_id) return
def delete(self, _id): context = t_context.extract_context_from_environ() if not t_context.is_admin_context(context): pecan.abort(400, _('Admin role required to delete pods')) return try: with context.session.begin(): pod = core.get_resource(context, models.Pod, _id) if pod is not None: ag_name = utils.get_ag_name(pod['pod_name']) ag = az_ag.get_ag_by_name(context, ag_name) if ag is not None: az_ag.delete_ag(context, ag['id']) core.delete_resource(context, models.Pod, _id) pecan.response.status = 200 except t_exc.ResourceNotFound: return Response(_('Pod not found'), 404) except Exception as e: LOG.exception( _LE('Failed to delete pod: %(pod_id)s,' '%(exception)s'), { 'pod_id': _id, 'exception': e }) return Response(_('Failed to delete pod'), 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 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 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 firewall_bypass')) return try: with context.session.begin(): core.delete_resource(context, models.FirewallBypass, _id) return_object = m.SuccessMessage(result={}) return return_object.to_dict() except t_exceptions.ResourceNotFound as e1: LOG.exception( 'Failed to delete 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 delete firewall_bypass: '******'id: %(id)s,' '%(exception)s ', { 'id': _id, 'exception': e2 }) return_object = m.FailureMessage() return return_object.to_dict()
def get_or_create_route(t_ctx, q_ctx, project_id, pod, ele, _type, list_ele_method): # use configuration option later route_expire_threshold = 30 _id = ele['id'] with t_ctx.session.begin(): routes = core.query_resource(t_ctx, models.ResourceRouting, [{ 'key': 'top_id', 'comparator': 'eq', 'value': _id }, { 'key': 'pod_id', 'comparator': 'eq', 'value': pod['pod_id'] }], []) if routes: route = routes[0] if route['bottom_id']: return route, ALL_DONE else: route_time = route['updated_at'] or route['created_at'] current_time = datetime.datetime.utcnow() delta = current_time - route_time if delta.seconds > route_expire_threshold: # NOTE(zhiyuan) cannot directly remove the route, we have # a race here that other worker is updating this route, we # need to check if the corresponding element has been # created by other worker eles = list_ele_method(t_ctx, q_ctx, pod, ele, _type) if eles: route['bottom_id'] = eles[0]['id'] core.update_resource(t_ctx, models.ResourceRouting, route['id'], route) return route, RES_DONE try: core.delete_resource(t_ctx, models.ResourceRouting, route['id']) except db_exc.ResourceNotFound: pass try: # NOTE(zhiyuan) try/except block inside a with block will cause # problem, so move them out of the block and manually handle the # session context t_ctx.session.begin() route = core.create_resource( t_ctx, models.ResourceRouting, { 'top_id': _id, 'pod_id': pod['pod_id'], 'project_id': project_id, 'resource_type': _type }) t_ctx.session.commit() return route, NONE_DONE except db_exc.DBDuplicateEntry: t_ctx.session.rollback() return None, NONE_DONE finally: t_ctx.session.close()
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 pods')) return try: with context.session.begin(): pod = core.get_resource(context, models.Pod, _id) if pod is not None: ag_name = utils.get_ag_name(pod['pod_name']) ag = az_ag.get_ag_by_name(context, ag_name) if ag is not None: az_ag.delete_ag(context, ag['id']) core.delete_resource(context, models.Pod, _id) pecan.response.status = 200 return {} except t_exc.ResourceNotFound: return Response(_('Pod not found'), 404) except Exception as e: LOG.exception(_LE('Failed to delete pod: %(pod_id)s,' '%(exception)s'), {'pod_id': _id, 'exception': e}) return Response(_('Failed to delete pod'), 500)
def delete_ag(context, aggregate_id): core.delete_resources(context, models.AggregateMetadata, [{ 'key': 'aggregate_id', 'comparator': 'eq', 'value': aggregate_id }]) core.delete_resource(context, models.Aggregate, aggregate_id) return
def get_or_create_route(t_ctx, q_ctx, project_id, pod, ele, _type, list_ele_method): # use configuration option later route_expire_threshold = 30 _id = ele['id'] with t_ctx.session.begin(): routes = core.query_resource( t_ctx, models.ResourceRouting, [{'key': 'top_id', 'comparator': 'eq', 'value': _id}, {'key': 'pod_id', 'comparator': 'eq', 'value': pod['pod_id']}, {'key': 'resource_type', 'comparator': 'eq', 'value': _type}], []) if routes: route = routes[0] if route['bottom_id']: return route, ALL_DONE else: route_time = route['updated_at'] or route['created_at'] current_time = datetime.datetime.utcnow() delta = current_time - route_time if delta.seconds > route_expire_threshold: # NOTE(zhiyuan) cannot directly remove the route, we have # a race here that other worker is updating this route, we # need to check if the corresponding element has been # created by other worker eles = list_ele_method(t_ctx, q_ctx, pod, ele, _type) if eles: route['bottom_id'] = eles[0]['id'] core.update_resource(t_ctx, models.ResourceRouting, route['id'], route) return route, RES_DONE try: core.delete_resource(t_ctx, models.ResourceRouting, route['id']) except db_exc.ResourceNotFound: pass try: # NOTE(zhiyuan) try/except block inside a with block will cause # problem, so move them out of the block and manually handle the # session context t_ctx.session.begin() route = core.create_resource(t_ctx, models.ResourceRouting, {'top_id': _id, 'pod_id': pod['pod_id'], 'project_id': project_id, 'resource_type': _type}) t_ctx.session.commit() return route, NONE_DONE except db_exc.DBDuplicateEntry: t_ctx.session.rollback() return None, NONE_DONE finally: t_ctx.session.close()
def delete_pre_created_resource_mapping(context, name): with context.session.begin(): entries = core.query_resource( context, models.ResourceRouting, filters=[{'key': 'top_id', 'comparator': 'eq', 'value': name}], sorts=[]) if entries: core.delete_resources( context, models.ResourceRouting, filters=[{'key': 'top_id', 'comparator': 'eq', 'value': entries[0]['bottom_id']}]) core.delete_resource(context, models.ResourceRouting, entries[0]['id'])
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 get_or_create_element(t_ctx, q_ctx, project_id, pod, ele, _type, body, list_ele_method, create_ele_method): # use configuration option later max_tries = 5 for _ in xrange(max_tries): route, status = get_or_create_route( t_ctx, q_ctx, project_id, pod, ele['id'], _type, list_ele_method) if not route: eventlet.sleep(0) continue if status == RES_DONE or status == ALL_DONE: # in these cases, bottom_id must exist break if status == NONE_DONE: try: ele = create_ele_method(t_ctx, q_ctx, pod, body, _type) except Exception: with t_ctx.session.begin(): try: core.delete_resource(t_ctx, models.ResourceRouting, route['id']) except db_exc.ResourceNotFound: # NOTE(zhiyuan) this is a rare case that other worker # considers the route expires and delete it though it # was just created, maybe caused by out-of-sync time pass raise with t_ctx.session.begin(): # NOTE(zhiyuan) it's safe to update route, the bottom network # has been successfully created, so other worker will not # delete this route route['bottom_id'] = ele['id'] core.update_resource(t_ctx, models.ResourceRouting, route['id'], route) break if not route: raise Exception('Fail to create %s routing entry' % _type) if not route['bottom_id']: raise Exception('Fail to bind top and bottom %s' % _type) # NOTE(zhiyuan) Status being ALL_DONE means that the routing entry is # complete when we retrieve the resource, so we return False to indicate # that we can directly use this resource safely. Status being RES_DONE and # NONE_DONE means that the routing entry is not complete when we retrieve # the resource but we manage to fill the entry finally, so we return True # to indicate that we may leave some work to do. if status == ALL_DONE: return False, route['bottom_id'] else: return True, route['bottom_id']
def delete(self, _id): context = t_context.extract_context_from_environ() if not t_context.is_admin_context(context): pecan.abort(400, _('Admin role required to delete bindings')) return try: with context.session.begin(): core.delete_resource(context, models.PodBinding, _id) pecan.response.status = 200 except t_exc.ResourceNotFound: pecan.abort(404, _('Pod binding not found')) return
def delete(self, _id): context = t_context.extract_context_from_environ() if not t_context.is_admin_context(context): pecan.abort(400, _('Admin role required to delete bindings')) return try: with context.session.begin(): core.delete_resource(context, models.PodBinding, _id) pecan.response.status = 200 except t_exc.ResourceNotFound: pecan.abort(404, _('Pod binding not found')) return
def delete(self, _id): context = t_context.extract_context_from_environ() with context.session.begin(): flavors = core.query_resource(context, models.InstanceTypes, [{'key': 'flavorid', 'comparator': 'eq', 'value': _id}], []) if not flavors: pecan.abort(404, 'Flavor not found') return core.delete_resource(context, models.InstanceTypes, flavors[0]['id']) pecan.response.status = 202 return
def get_or_create_element(t_ctx, q_ctx, project_id, pod, ele, _type, body, list_ele_method, create_ele_method): # use configuration option later max_tries = 5 for _ in xrange(max_tries): route, status = get_or_create_route(t_ctx, q_ctx, project_id, pod, ele, _type, list_ele_method) if not route: eventlet.sleep(0) continue if status == RES_DONE or status == ALL_DONE: # in these cases, bottom_id must exist break if status == NONE_DONE: try: new_ele = create_ele_method(t_ctx, q_ctx, pod, body, _type) except Exception: with t_ctx.session.begin(): try: core.delete_resource(t_ctx, models.ResourceRouting, route['id']) except db_exc.ResourceNotFound: # NOTE(zhiyuan) this is a rare case that other worker # considers the route expires and delete it though it # was just created, maybe caused by out-of-sync time pass raise with t_ctx.session.begin(): # NOTE(zhiyuan) it's safe to update route, the bottom network # has been successfully created, so other worker will not # delete this route route['bottom_id'] = new_ele['id'] core.update_resource(t_ctx, models.ResourceRouting, route['id'], route) break if not route: raise Exception('Fail to create %s routing entry' % _type) if not route['bottom_id']: raise Exception('Fail to bind top and bottom %s' % _type) # NOTE(zhiyuan) Status being ALL_DONE means that the routing entry is # complete when we retrieve the resource, so we return False to indicate # that we can directly use this resource safely. Status being RES_DONE and # NONE_DONE means that the routing entry is not complete when we retrieve # the resource but we manage to fill the entry finally, so we return True # to indicate that we may leave some work to do. if status == ALL_DONE: return False, route['bottom_id'] else: return True, route['bottom_id']
def delete(self, _id): context = t_context.extract_context_from_environ() if not policy.enforce(context, policy.ADMIN_API_BINDINGS_DELETE): pecan.abort(401, _('Unauthorized to delete bindings')) return try: with context.session.begin(): core.delete_resource(context, models.PodBinding, _id) pecan.response.status = 200 return {} except t_exc.ResourceNotFound: pecan.abort(404, _('Pod binding not found')) return
def get_or_create_element(t_ctx, q_ctx, project_id, pod, ele, _type, body, list_ele_method, create_ele_method): # use configuration option later max_tries = 5 for _ in xrange(max_tries): route, is_new = get_or_create_route( t_ctx, q_ctx, project_id, pod, ele['id'], _type, list_ele_method) if not route: eventlet.sleep(0) continue if not is_new and not route['bottom_id']: eventlet.sleep(0) continue if not is_new and route['bottom_id']: break if is_new: try: ele = create_ele_method(t_ctx, q_ctx, pod, body, _type) except Exception: with t_ctx.session.begin(): try: core.delete_resource(t_ctx, models.ResourceRouting, route['id']) except db_exc.ResourceNotFound: # NOTE(zhiyuan) this is a rare case that other worker # considers the route expires and delete it though it # was just created, maybe caused by out-of-sync time pass raise with t_ctx.session.begin(): # NOTE(zhiyuan) it's safe to update route, the bottom network # has been successfully created, so other worker will not # delete this route route['bottom_id'] = ele['id'] core.update_resource(t_ctx, models.ResourceRouting, route['id'], route) break if not route: raise Exception('Fail to create %s routing entry' % _type) if not route['bottom_id']: raise Exception('Fail to bind top and bottom %s' % _type) return is_new, route['bottom_id']
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 tricircle_resources')) return try: with context.session.begin(): core.delete_resource(context, models.TricircleResource, _id) pecan.response.status = 200 return {} except t_exceptions.ResourceNotFound: return Response(_('Firewall gateway not found'), 404) except Exception as e: LOG.exception('Failed to delete tricircle_resource: %(tricircle_resource_id)s,' '%(exception)s', {'tricircle_resource_id': _id, 'exception': e}) return Response(_('Failed to delete tricircle_resource'), 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 dynamic_peering_connections')) return try: with context.session.begin(): core.delete_resource(context, models.DynamicPeeringConnection, _id) pecan.response.status = 200 return {} except t_exceptions.ResourceNotFound: return Response(_('Dynamic Peering Connection not found'), 404) except Exception as e: LOG.exception('Failed to delete dynamic_peering_connection: %(dynamic_peering_connection_id)s,' '%(exception)s', {'dynamic_peering_connection_id': _id, 'exception': e}) return Response(_('Failed to delete dynamic_peering_connection'), 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 pods')) return try: with context.session.begin(): core.delete_resource(context, models.Pod, _id) pecan.response.status = 200 return {} except t_exceptions.ResourceNotFound: return Response(_('Pod not found'), 404) except Exception as e: LOG.exception('Failed to delete pod: %(pod_id)s,' '%(exception)s', {'pod_id': _id, 'exception': e}) return Response(_('Failed to delete pod'), 500)
def delete(self, _id): context = t_context.extract_context_from_environ() if not t_context.is_admin_context(context): pecan.abort(400, _('Admin role required to delete pods')) return try: with context.session.begin(): pod = core.get_resource(context, models.Pod, _id) if pod is not None: ag_name = utils.get_ag_name(pod['pod_name']) ag = az_ag.get_ag_by_name(context, ag_name) if ag is not None: az_ag.delete_ag(context, ag['id']) core.delete_resource(context, models.Pod, _id) pecan.response.status = 200 except t_exc.ResourceNotFound: return Response(_('Pod not found'), 404) except Exception as e: LOG.error(_LE('Fail to delete pod: %(exception)s'), {'exception': e}) return Response(_('Fail to delete pod'), 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 pods')) return try: with context.session.begin(): core.delete_resource(context, models.Pod, _id) pecan.response.status = 200 return {} except t_exc.ResourceNotFound: return Response(_('Pod not found'), 404) except Exception as e: LOG.exception( _LE('Failed to delete pod: %(pod_id)s,' '%(exception)s'), { 'pod_id': _id, 'exception': e }) return Response(_('Failed to delete pod'), 500)
def delete_dynamic_peering_connection(context, core_router_id): with context.session.begin(): return core.delete_resource(context, models.DynamicPeeringConnection, core_router_id)
def delete_recycle_resource(context, resource_id): with context.session.begin(): return core.delete_resource(context, models.RecycleResources, resource_id)
def delete_core_router(context, core_router_id): with context.session.begin(): return core.delete_resource(context, models.CoreRouter, core_router_id)
def delete_job(context, job_id): with context.session.begin(): return core.delete_resource(context, models.AsyncJob, job_id)
def delete_cached_endpoints(context, config_id): with context.session.begin(): return core.delete_resource(context, models.CachedEndpoint, config_id)
def delete_site(context, site_id): with context.session.begin(): return core.delete_resource(context, Site, site_id)
def delete_pod(context, pod_id): with context.session.begin(): return core.delete_resource(context, models.Pod, pod_id)
def delete_cached_endpoints(context, config_id): with context.session.begin(): return core.delete_resource(context, models.CachedEndpoint, config_id)
def delete_route_entry(context, route_entry_id): with context.session.begin(): return core.delete_resource(context, models.RouteEntry, route_entry_id)
def delete_pod_service_configuration(context, config_id): with context.session.begin(): return core.delete_resource(context, models.PodServiceConfiguration, config_id)
def delete_recycle_resource(context, resource_id): with context.session.begin(): return core.delete_resource( context, models.RecycleResources, resource_id)
def delete_fabric(context, fabric_id): with context.session.begin(): return core.delete_resource(context, models.Fabric, fabric_id)
def delete_tricircle_resource(context, core_router_id): with context.session.begin(): return core.delete_resource(context, models.TricircleResource, core_router_id)
def delete_resource_routing(context, id): with context.session.begin(): return core.delete_resource(context, models.ResourceRouting, id)
def delete_firewall_gateway(context, core_router_id): with context.session.begin(): return core.delete_resource(context, models.FirewallGateway, core_router_id)
def delete_resource_routing(context, id): with context.session.begin(): return core.delete_resource(context, models.ResourceRouting, id)
def delete_firewall_bypass(context, core_router_id): with context.session.begin(): return core.delete_resource(context, models.FirewallBypass, core_router_id)
def delete_site_service_configuration(context, config_id): with context.session.begin(): return core.delete_resource(context, SiteServiceConfiguration, config_id)
def delete_region(context, region_id): with context.session.begin(): return core.delete_resource(context, models.Region, region_id)
def delete_job(context, job_id): with context.session.begin(): return core.delete_resource(context, models.AsyncJob, job_id)
def delete_dci(context, dci_id): with context.session.begin(): return core.delete_resource(context, models.DCI, dci_id)
def delete_pod(context, pod_id): with context.session.begin(): return core.delete_resource(context, models.Pod, pod_id)