def post(self): self.set_header('Content-Type', 'application/json') uri = self.request.uri method = self.request.method name = self.get_argument('name', None) user_name = self.get_current_user() result = api.Customer.delete(name, user_name) if result['pass']: # delete all agents of this customer all_agents = get_all_agent_ids(customer_name=name) for agent_id in all_agents: agent = AgentManager( agent_id, customer_name=name ) # TODO: real uri, real method agent.delete_agent(uri, method) self.write(json.dumps(result, indent=4))
def delete(self): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: agent_ids = self.arguments.get('agent_ids') if not isinstance(agent_ids, list): agent_ids = agent_ids.split() agentids_deleted =[] agentids_not_deleted =[] for agent_id in agent_ids: agent = AgentManager(agent_id, customer_name=customer_name) results = agent.delete_agent(uri, method) if results['http_status'] == 200: delete_oper = ( StoreOperation( username, customer_name, uri, method ) ) delete_oper.uninstall_agent(agent_id) agentids_deleted.append(agent_id) else: agentids_not_deleted.append(agent_id) results['data'] = { 'agentids_deleted': agentids_deleted, 'agentids_not_deleted': agentids_not_deleted } self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('agent_ids', 'delete agentids', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def delete(self, agent_id): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: agent = AgentManager(agent_id, customer_name=customer_name) delete_oper = StoreOperation(username, customer_name, uri, method) delete_oper.uninstall_agent(agent_id) results = agent.delete_agent(uri, method) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(username, uri, method).something_broke( agent_id, 'delete agent', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def delete(self, agent_id): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: agent = AgentManager(agent_id, customer_name=customer_name) delete_oper = StoreOperation(username, customer_name, uri, method) delete_oper.uninstall_agent(agent_id) results = agent.delete_agent(uri, method) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke(agent_id, 'delete agent', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def delete(self): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: agent_ids = self.arguments.get('agent_ids') if not isinstance(agent_ids, list): agent_ids = agent_ids.split() agentids_deleted = [] agentids_not_deleted = [] for agent_id in agent_ids: agent = AgentManager(agent_id, customer_name=customer_name) results = agent.delete_agent(uri, method) if results['http_status'] == 200: delete_oper = (StoreOperation(username, customer_name, uri, method)) delete_oper.uninstall_agent(agent_id) agentids_deleted.append(agent_id) else: agentids_not_deleted.append(agent_id) results['data'] = { 'agentids_deleted': agentids_deleted, 'agentids_not_deleted': agentids_not_deleted } self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(username, uri, method).something_broke( 'agent_ids', 'delete agentids', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))