def put(self): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: agent_ids = self.arguments.get('agent_ids') new_customer = self.arguments.get('customer_name') if not isinstance(agent_ids, list): agent_ids = agent_ids.split() agentids_moved = [] agentids_not_moved = [] for agent_id in agent_ids: agent = AgentManager(agent_id, customer_name=customer_name) results = agent.change_customer(new_customer, uri, method) if results['http_status'] == 200: agentids_moved.append(agent_id) else: agentids_not_moved.append(agent_id) results['data'] = { 'agentids_moved': agentids_moved, 'agentids_not_moved': agentids_not_moved } 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_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: agent = AgentManager(agent_id, customer_name=customer_name) delete_oper = StorePatchingOperation(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 get(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: agent = AgentManager(agent_id, customer_name=customer_name) results = agent.get_data(uri=uri, method=method) 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, 'get agent_info', 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_user_property(username, UserKeys.CurrentCustomer) ) 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 = ( StorePatchingOperation( 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_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: agent = AgentManager(agent_id, customer_name=customer_name) delete_oper = StorePatchingOperation(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 put(self, agent_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: displayname = self.arguments.get('display_name', None) hostname = self.arguments.get('hostname', None) prod_level = self.arguments.get('production_level', None) new_customer = self.arguments.get('customer_name', None) agent = AgentManager(agent_id, customer_name=customer_name) if (displayname and not hostname and not prod_level and not new_customer): results = agent.displayname_changer(displayname, uri, method) elif (hostname and not prod_level and not displayname and not new_customer): results = agent.hostname_changer(hostname, uri, method) elif (prod_level and not hostname and not displayname and not new_customer): results = agent.production_state_changer(prod_level, uri, method) elif prod_level and hostname and displayname and not new_customer: agent_data = { 'host_name': hostname, 'production_level': prod_level, 'display_name': displayname } results = agent.update_fields(agent_data, uri, method) elif (new_customer and not prod_level and not hostname and not displayname): results = agent.change_customer(new_customer, uri, method) else: results = ( GenericResults( username, uri, method ).incorrect_arguments() ) 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, 'modify 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 get(self, agent_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: agent = AgentManager(agent_id, customer_name=customer_name) results = agent.get_data(uri=uri, method=method) 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, 'get agent_info', 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 put(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: displayname = self.arguments.get('display_name', None) hostname = self.arguments.get('hostname', None) prod_level = self.arguments.get('production_level', None) new_customer = self.arguments.get('customer_name', None) agent = AgentManager(agent_id, customer_name=customer_name) if (displayname and not hostname and not prod_level and not new_customer): results = agent.displayname_changer(displayname, uri, method) elif (hostname and not prod_level and not displayname and not new_customer): results = agent.hostname_changer(hostname, uri, method) elif (prod_level and not hostname and not displayname and not new_customer): results = agent.production_state_changer( prod_level, uri, method) elif prod_level and hostname and displayname and not new_customer: agent_data = { 'host_name': hostname, 'production_level': prod_level, 'display_name': displayname } results = agent.update_fields(agent_data, uri, method) elif (new_customer and not prod_level and not hostname and not displayname): results = agent.change_customer(new_customer, uri, method) else: results = (GenericResults(username, uri, method).incorrect_arguments()) 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, 'modify 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 get(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) name = self.get_argument('query', None) uri = self.request.uri method = self.request.method if name: tag = TagSearcher(username, customer_name, uri, method) results = tag.search_by_name(name) else: tag = AgentManager(agent_id, customer_name, username) results = tag.get_tags(uri, method) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))