def add_supported_app_to_agents(username, customer_name, uri, method, agent_id=None): if agent_id: agent_info = get_agent_info(agent_id) apps_info = ( get_apps_data( customer_name, table=SupportedAppsCollection, os_code=agent_info[AgentKey.OsCode] ) ) if len(apps_info) > 0: for app_info in apps_info: app_id = app_info.get(SupportedAppsKey.AppId) file_data = get_file_data(app_id) update_file_data( app_id, agent_id, file_data ) agent_info_to_insert = ( { SupportedAppsPerAgentKey.AgentId: agent_id, SupportedAppsPerAgentKey.AppId: app_id, SupportedAppsPerAgentKey.Status: AVAILABLE, SupportedAppsPerAgentKey.CustomerName: customer_name, SupportedAppsPerAgentKey.InstallDate: r.epoch_time(0.0) } ) apps_to_insert_per_agent( username, uri, method, agent_info_to_insert, table=SupportedAppsPerAgentCollection )
def add_supported_app_to_agents(username, customer_name, uri, method, agent_id=None): if agent_id: agent_info = get_agent_info(agent_id) apps_info = (get_apps_data(customer_name, table=SupportedAppsCollection, os_code=agent_info[AgentKey.OsCode])) if len(apps_info) > 0: for app_info in apps_info: app_id = app_info.get(SupportedAppsKey.AppId) file_data = get_file_data(app_id) update_file_data(app_id, agent_id, file_data) agent_info_to_insert = ({ SupportedAppsPerAgentKey.AgentId: agent_id, SupportedAppsPerAgentKey.AppId: app_id, SupportedAppsPerAgentKey.Status: AVAILABLE, SupportedAppsPerAgentKey.CustomerName: customer_name, SupportedAppsPerAgentKey.InstallDate: r.epoch_time(0.0) }) apps_to_insert_per_agent(username, uri, method, agent_info_to_insert, table=SupportedAppsPerAgentCollection)
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)
def update_agents_with_supported(self, apps, agents=None): try: conn = db_connect() if agents: for agent in agents: ( r .table(self.CurrentAppsPerAgentCollection) .get_all( agent[self.CurrentAppsPerAgentKey.AgentId], index=self.CurrentAppsPerAgentIndexes.AgentId ) .delete() .run(conn) ) for app in apps: if not agents: agents = get_agents_info(agent_os=app[AgentKey.OsCode]) file_data = app.get(self.CurrentAppsKey.FileData) if agents: for agent in agents: if agent[AgentKey.OsCode] == app[AgentKey.OsCode]: agent[self.CurrentAppsPerAgentKey.AppId] = app[self.CurrentAppsPerAgentKey.AppId] update_file_data( agent[self.CurrentAppsPerAgentKey.AppId], agent[self.CurrentAppsPerAgentKey.AgentId], file_data ) app_per_agent_props = self._set_app_per_agent_properties(**agent) agent_has_app = self.check_if_agent_has_app(agent) if not agent_has_app: self.insert_app( app_per_agent_props ) elif agent_has_app: app_per_agent_props[self.CurrentAppsPerAgentKey.Status] = INSTALLED self.insert_app(app_per_agent_props) conn.close() except Exception as e: logger.exception(e)
def update_agents_with_supported(self, apps, agents=None): try: conn = db_connect() if agents: for agent in agents: (r.table(self.CurrentAppsPerAgentCollection).get_all( agent[self.CurrentAppsPerAgentKey.AgentId], index=self.CurrentAppsPerAgentIndexes.AgentId).delete( ).run(conn)) for app in apps: if not agents: agents = get_agents_info(agent_os=app[AgentKey.OsCode]) file_data = app.get(self.CurrentAppsKey.FileData) if agents: for agent in agents: if agent[AgentKey.OsCode] == app[AgentKey.OsCode]: agent[self.CurrentAppsPerAgentKey.AppId] = app[ self.CurrentAppsPerAgentKey.AppId] update_file_data( agent[self.CurrentAppsPerAgentKey.AppId], agent[self.CurrentAppsPerAgentKey.AgentId], file_data) app_per_agent_props = self._set_app_per_agent_properties( **agent) agent_has_app = self.check_if_agent_has_app(agent) if not agent_has_app: self.insert_app(app_per_agent_props) elif agent_has_app: app_per_agent_props[self.CurrentAppsPerAgentKey .Status] = INSTALLED self.insert_app(app_per_agent_props) conn.close() except Exception as e: logger.exception(e)