def delete_erroneous(not_delete=[]): deleted_instances = [] for erroneous_instance in Instance.get_erroneous(): if erroneous_instance.id not in not_delete: logger.info('Deleting erroneous %s.' % erroneous_instance) erroneous_instance.delete() deleted_instances.append(erroneous_instance.id) # Very conservative approach: # we remove it even if it might still be usable. remove_container.s(erroneous_instance.docker_id).delay() return deleted_instances
def delete_erroneous(not_delete=[]): deleted_instances = [] for erroneous_instance in Instance.get_erroneous(): if erroneous_instance.id not in not_delete: logger.info('Deleting erroneous %s.' % erroneous_instance) erroneous_instance.delete() deleted_instances.append(erroneous_instance.id) # Very conservative approach: # we remove it even if it might still be usable. remove_container.s(erroneous_instance.docker_id).delay() return deleted_instances
def list_instances(): """ Lists instances. --- tags: - instance parameters: - name: show in: query type: string description: Show different types of instances default: running enum: [all, starting, deallocated, allocated, running, finished, error] responses: 200: description: Packet Tracer instances schema: properties: instances: type: array items: $ref: '#/definitions/assign_instance_post_Instance' """ show_param = request.args.get("show") if show_param is None or show_param == "running": # default option return get_json_instances(Instance.get_running()) else: states = ("all", "starting", "deallocated", "allocated", "running", "finished", "error") if show_param not in states: state_enum = "[" for s in states: state_enum += "%s, " % s state_enum = state_enum[:-2] + "]" return BadRequest( "The 'show' parameter must contain one of the following values: %s." % state_enum) if show_param == "all": return get_json_instances(Instance.get_all()) # .limit(10) elif show_param == "starting": return get_json_instances(Instance.get_starting()) elif show_param == "deallocated": return get_json_instances(Instance.get_deallocated()) elif show_param == "allocated": return get_json_instances(Instance.get_allocated()) elif show_param == "error": return get_json_instances(Instance.get_erroneous()) else: # show_param is "finished": return get_json_instances(Instance.get_finished())
def list_instances(): """ Lists instances. --- tags: - instance parameters: - name: show in: query type: string description: Show different types of instances default: running enum: [all, starting, deallocated, allocated, running, finished, error] responses: 200: description: Packet Tracer instances schema: properties: instances: type: array items: $ref: '#/definitions/assign_instance_post_Instance' """ show_param = request.args.get("show") if show_param is None or show_param == "running": # default option return get_json_instances(Instance.get_running()) else: states = ("all", "starting", "deallocated", "allocated", "running", "finished", "error") if show_param not in states: state_enum = "[" for s in states: state_enum += "%s, " % s state_enum = state_enum[:-2] + "]" return BadRequest("The 'show' parameter must contain one of the following values: %s." % state_enum) if show_param == "all": return get_json_instances(Instance.get_all()) # .limit(10) elif show_param == "starting": return get_json_instances(Instance.get_starting()) elif show_param == "deallocated": return get_json_instances(Instance.get_deallocated()) elif show_param == "allocated": return get_json_instances(Instance.get_allocated()) elif show_param == "error": return get_json_instances(Instance.get_erroneous()) else: # show_param is "finished": return get_json_instances(Instance.get_finished())