def change_customer(self, customer_name, uri, method, conn=None): try: cexists = (r.table( Collection.Customers).get(customer_name).run(conn)) customer_data = {AgentKey.CustomerName: customer_name} if cexists: update_agent_field(self.agent_id, AgentKey.CustomerName, customer_name, self.username, uri, method) delete_agent_from_all_tags(self.agent_id) rv_q = Queue('move_agent', connection=rq_pool) rv_q.enqueue_call( func=update_all_app_data_for_agent, args=(self.agent_id, customer_data), timeout=3600, ) status = (GenericResults(self.username, uri, method).object_updated( self.agent_id, 'agent', customer_data)) else: status = (GenericResults(self.username, uri, method).invalid_id( self.agent_id, 'agent')) except Exception as e: status = (GenericResults(self.username, uri, method).something_broke( self.agent_id, 'agents', e)) logger.exception(e) return (status)
def reboot(self): oper_type = REBOOT results = self._update_operation(oper_type) if self.success == "true": update_agent_field(self.agent_id, AgentKey.NeedsReboot, 'no', self.username, self.uri, self.method) return (results)
def reboot(self): oper_type = REBOOT results = self._update_operation(oper_type) if self.success == "true": update_agent_field( self.agent_id, AgentKey.NeedsReboot, 'no', self.username, self.uri, self.method ) return(results)
def change_customer(self, customer_name, uri, method, conn=None): try: cexists = ( r .table(Collection.Customers) .get(customer_name) .run(conn) ) customer_data = {AgentKey.CustomerName: customer_name} if cexists: update_agent_field( self.agent_id, AgentKey.CustomerName, customer_name, self.username, uri, method ) delete_agent_from_all_tags(self.agent_id) rv_q = Queue('move_agent', connection=rq_pool) rv_q.enqueue_call( func=update_all_app_data_for_agent, args=(self.agent_id, customer_data), timeout=3600, ) status = ( GenericResults( self.username, uri, method ).object_updated(self.agent_id, 'agent', customer_data) ) else: status = ( GenericResults( self.username, uri, method ).invalid_id(self.agent_id, 'agent') ) except Exception as e: status = ( GenericResults( self.username, uri, method ).something_broke(self.agent_id, 'agents', e) ) logger.exception(e) return(status)
def _changer(self, newname, name_type=AgentKey.DisplayName, uri=None, method=None, conn=None): if newname: agent_updated = ( update_agent_field( self.agent_id, name_type, newname, self.username, uri, method ) ) return(agent_updated)
def _changer(self, newname, name_type=AgentKey.DisplayName, uri=None, method=None, conn=None): if newname: agent_updated = (update_agent_field(self.agent_id, name_type, newname, self.username, uri, method)) return (agent_updated)
def _update_app_status(self, data, oper_type): try: if self.reboot_required == 'true': update_agent_field(self.agent_id, 'needs_reboot', 'yes', self.username) if self.success == 'true' and re.search(r'^install', oper_type): status = INSTALLED install_date = self.date_now elif self.success == 'true' and re.search(r'^uninstall', oper_type): status = AVAILABLE install_date = 0.0 elif self.success == 'false' and re.search(r'^install', oper_type): status = AVAILABLE install_date = 0.0 elif self.success == 'false' and re.search(r'^uninstall', oper_type): status = INSTALLED install_date = 0.0 app_exist = get_app_data(self.app_id, table=self.CurrentAppsCollection) oper_app_exists = (oper_with_appid_exists(self.operation_id, self.agent_id, self.app_id)) if app_exist: if oper_app_exists and self.success == 'true': results = (self.operation.update_app_results( self.operation_id, self.agent_id, self.app_id, OperationCodes.ResultsReceived, errors=self.error)) if self.apps_to_delete: try: self.apps_to_delete = [ loads(x) for x in self.apps_to_delete ] except Exception as e: logger.exception(e) for apps in self.apps_to_delete: delete_app_from_agent(apps[NAME], apps[VERSION], self.agent_id) if self.apps_to_add: try: self.apps_to_add = [ loads(x) for x in self.apps_to_add ] except Exception as e: logger.exception(e) incoming_packages_from_agent( self.username, self.agent_id, self.customer_name, self.agent_data[AgentKey.OsCode], self.agent_data[AgentKey.OsString], self.apps_to_add, delete_afterwards=False) elif oper_app_exists and self.success == 'false': results = (self.operation.update_app_results( self.operation_id, self.agent_id, self.app_id, OperationCodes.ResultsReceivedWithErrors, errors=self.error)) else: results = (GenericResults(self.username, self.uri, self.method).invalid_id( self.operation_id, oper_type)) data_to_update = ({ self.CurrentAppsPerAgentKey.Status: status, self.CurrentAppsPerAgentKey.InstallDate: r.epoch_time(install_date) }) if oper_type == INSTALL_OS_APPS or oper_type == UNINSTALL: update_os_app_per_agent(self.agent_id, self.app_id, data_to_update) elif oper_type == INSTALL_CUSTOM_APPS: update_custom_app_per_agent(self.agent_id, self.app_id, data_to_update) elif oper_type == INSTALL_SUPPORTED_APPS: update_supported_app_per_agent(self.agent_id, self.app_id, data_to_update) elif oper_type == INSTALL_AGENT_UPDATE: update_agent_app_per_agent(self.agent_id, self.app_id, data_to_update) else: results = (GenericResults(self.username, self.uri, self.method).invalid_id( self.operation_id, oper_type)) except Exception as e: results = (GenericResults(self.username, self.uri, self.method).something_broke( self.operation_id, oper_type, e)) logger.exception(results) return (results)
def _update_app_status(self, data, oper_type): try: if self.reboot_required == 'true': update_agent_field( self.agent_id, 'needs_reboot', 'yes', self.username ) if self.success == 'true' and re.search(r'^install', oper_type): status = INSTALLED install_date = self.date_now elif self.success == 'true' and re.search(r'^uninstall', oper_type): status = AVAILABLE install_date = 0.0 elif self.success == 'false' and re.search(r'^install', oper_type): status = AVAILABLE install_date = 0.0 elif self.success == 'false' and re.search(r'^uninstall', oper_type): status = INSTALLED install_date = 0.0 app_exist = get_app_data(self.app_id, table=self.CurrentAppsCollection) oper_app_exists = ( oper_with_appid_exists( self.operation_id, self.agent_id, self.app_id ) ) if app_exist: if oper_app_exists and self.success == 'true': results = ( self.operation.update_app_results( self.operation_id, self.agent_id, self.app_id, OperationCodes.ResultsReceived, errors=self.error ) ) if self.apps_to_delete: try: self.apps_to_delete = [loads(x) for x in self.apps_to_delete] except Exception as e: logger.exception(e) for apps in self.apps_to_delete: delete_app_from_agent( apps[NAME], apps[VERSION], self.agent_id ) if self.apps_to_add: try: self.apps_to_add = [loads(x) for x in self.apps_to_add] except Exception as e: logger.exception(e) incoming_packages_from_agent( self.username, self.agent_id, self.customer_name, self.agent_data[AgentKey.OsCode], self.agent_data[AgentKey.OsString], self.apps_to_add, delete_afterwards=False ) elif oper_app_exists and self.success == 'false': results = ( self.operation.update_app_results( self.operation_id, self.agent_id, self.app_id, OperationCodes.ResultsReceivedWithErrors, errors=self.error ) ) else: results = ( GenericResults( self.username, self.uri, self.method ).invalid_id(self.operation_id, oper_type) ) data_to_update = ( { self.CurrentAppsPerAgentKey.Status: status, self.CurrentAppsPerAgentKey.InstallDate: r.epoch_time(install_date) } ) if oper_type == INSTALL_OS_APPS or oper_type == UNINSTALL: update_os_app_per_agent(self.agent_id, self.app_id, data_to_update) elif oper_type == INSTALL_CUSTOM_APPS: update_custom_app_per_agent(self.agent_id, self.app_id, data_to_update) elif oper_type == INSTALL_SUPPORTED_APPS: update_supported_app_per_agent(self.agent_id, self.app_id, data_to_update) elif oper_type == INSTALL_AGENT_UPDATE: update_agent_app_per_agent(self.agent_id, self.app_id, data_to_update) else: results = ( GenericResults( self.username, self.uri, self.method ).invalid_id(self.operation_id, oper_type) ) except Exception as e: results = ( GenericResults( self.username, self.uri, self.method ).something_broke(self.operation_id, oper_type, e) ) logger.exception(results) return(results)