Exemplo n.º 1
0
def add_custom_app_to_agents(username,
                             customer_name,
                             uri,
                             method,
                             file_data,
                             agent_id=None,
                             app_id=None):

    if app_id and not agent_id:
        app_info = (get_app_data(app_id, table=CustomAppsCollection))

        agent_ids = get_all_agent_ids(customer_name,
                                      agent_os=app_info[AgentKey.OsCode])
        if len(agent_ids) > 0:
            for agentid in agent_ids:
                update_file_data(app_id, agentid, file_data)
                agent_info_to_insert = ({
                    CustomAppsPerAgentKey.AgentId:
                    agentid,
                    CustomAppsPerAgentKey.AppId:
                    app_id,
                    CustomAppsPerAgentKey.Status:
                    AVAILABLE,
                    CustomAppsPerAgentKey.CustomerName:
                    customer_name,
                    CustomAppsPerAgentKey.InstallDate:
                    r.epoch_time(0.0)
                })
                apps_to_insert_per_agent(username, uri, method,
                                         agent_info_to_insert)

    if agent_id and not app_id:
        agent_info = get_agent_info(agent_id)
        apps_info = get_apps_data(customer_name,
                                  os_code=agent_info[AgentKey.OsCode])
        if len(apps_info) > 0:
            for app_info in apps_info:
                app_id = app_info.get(CustomAppsKey.AppId)
                file_data = get_file_data(app_id)
                update_file_data(app_id, agent_id, file_data)
                agent_info_to_insert = ({
                    CustomAppsPerAgentKey.AgentId:
                    agent_id,
                    CustomAppsPerAgentKey.AppId:
                    app_id,
                    CustomAppsPerAgentKey.Status:
                    AVAILABLE,
                    CustomAppsPerAgentKey.CustomerName:
                    customer_name,
                    CustomAppsPerAgentKey.InstallDate:
                    r.epoch_time(0.0)
                })
                apps_to_insert_per_agent(username, uri, method,
                                         agent_info_to_insert)
Exemplo n.º 2
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))