Example #1
0
    def put(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')
            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))
Example #2
0
    def get(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)
            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))
Example #3
0
    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))
Example #4
0
    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))
Example #5
0
    def get(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)
            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))
Example #6
0
    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))
Example #7
0
    def put(self, agent_id):
        username = self.get_current_user()
        customer_name = get_current_customer_name(username)
        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))
Example #8
0
    def put(self, agent_id):
        username = self.get_current_user()
        customer_name = get_current_customer_name(username)
        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))
Example #9
0
    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))
Example #10
0
    def get(self, agent_id):
        username = self.get_current_user()
        customer_name = get_current_customer_name(username)
        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))