Esempio n. 1
0
    def _uninstall_operation(self, operation):

        restart_needed = False
        urn_response = RvUrn.get_operation_urn(operation.type)

        if not operation.uninstall_data_list:
            error = "No applications specified to uninstall."

            rvsof_result = RvSofResult(
                operation.id,
                operation.type,
                '',  # app id
                [],  # apps_to_delete
                [],  # apps_to_add
                'false',  # success
                'false',  # restart
                error,  # error
                [],  # data
                urn_response,
                RequestMethod.PUT)

            self._send_results(rvsof_result)

        else:

            for uninstall_data in operation.uninstall_data_list:

                uninstall_result = \
                    self._operation_handler.uninstall_application(uninstall_data)

                if uninstall_result.restart == 'true':
                    restart_needed = True

                rvsof_result = RvSofResult(
                    operation.id,
                    operation.type,
                    uninstall_data.id,  # app id
                    [],  # apps_to_delete
                    [],  # apps_to_add
                    uninstall_result.success,  # success
                    uninstall_result.restart,  # restart
                    uninstall_result.error,  # error
                    [],  # data
                    urn_response,
                    RequestMethod.PUT)

                self._send_results(rvsof_result)

        logger.info('Done uninstalling applications.')

        self.run_refresh_apps_operation()

        # TODO(urgent): get restart working for uninstalls
        try:
            self._restart_if_needed(operation.restart, restart_needed)
        except AttributeError:
            logger.error("Failed to check if restart was needed due to no"
                         "restart attribute in operation.")
Esempio n. 2
0
    def refresh_apps_operation(self, operation):
        raw = {}

        # TODO: don't hardcode
        if not operation.id.endswith('-agent'):
            raw[OperationKey.OperationId] = operation.id

        raw[OperationKey.Data] = self.refresh_apps()

        operation.raw_result = json.dumps(raw)
        operation.urn_response = RvUrn.get_refresh_apps_urn()
        operation.request_method = RequestMethod.PUT

        self._send_results(operation)
Esempio n. 3
0
    def refresh_apps_operation(self, operation):
        raw = {}

        # TODO: don't hardcode
        if not operation.id.endswith('-agent'):
            raw[OperationKey.OperationId] = operation.id

        raw[OperationKey.Data] = self.refresh_apps()

        operation.raw_result = json.dumps(raw)
        operation.urn_response = RvUrn.get_refresh_apps_urn()
        operation.request_method = RequestMethod.PUT

        self._send_results(operation)
Esempio n. 4
0
    def _install_operation(self, operation):

        # TODO: if operation specifies update directory, change to that
        update_dir = settings.UpdatesDirectory
        failed_to_download = False

        urn_response = RvUrn.get_operation_urn(operation.type)

        try:

            self._download_updates(operation)

        except Exception as e:
            logger.error("Error occured while downloading updates.")
            logger.exception(e)

            failed_to_download = True

        if not operation.install_data_list or failed_to_download:
            error = RvError.UpdatesNotFound

            if failed_to_download:
                error = 'Failed to download packages.'

            rvsof_result = RvSofResult(
                operation.id,
                operation.type,
                '',  # app id
                [],  # apps_to_delete
                [],  # apps_to_add
                'false',  # success
                'false',  # restart
                error,  # error
                CreateApplication.null_application().to_dict(),  # app json
                urn_response,
                RequestMethod.PUT
            )

            self._send_results(rvsof_result)

        else:

            if operation.type == RvOperationValue.InstallAgentUpdate:
                self._agent_update(operation, update_dir)
            # TODO(urgent): remove this, only for testing
            #elif operation.type == RvOperationValue.InstallCustomApps:
            #    self._agent_update(operation, update_dir)
            else:
                self._regular_update(operation, update_dir)
Esempio n. 5
0
    def _install_operation(self, operation):

        # TODO: if operation specifies update directory, change to that
        update_dir = settings.UpdatesDirectory
        failed_to_download = False

        urn_response = RvUrn.get_operation_urn(operation.type)

        try:

            self._download_updates(operation)

        except Exception as e:
            logger.error("Error occured while downloading updates.")
            logger.exception(e)

            failed_to_download = True

        if not operation.install_data_list or failed_to_download:
            error = RvError.UpdatesNotFound

            if failed_to_download:
                error = 'Failed to download packages.'

            rvsof_result = RvSofResult(
                operation.id,
                operation.type,
                '',  # app id
                [],  # apps_to_delete
                [],  # apps_to_add
                'false',  # success
                'false',  # restart
                error,  # error
                CreateApplication.null_application().to_dict(),  # app json
                urn_response,
                RequestMethod.PUT)

            self._send_results(rvsof_result)

        else:

            if operation.type == RvOperationValue.InstallAgentUpdate:
                self._agent_update(operation, update_dir)
            # TODO(urgent): remove this, only for testing
            #elif operation.type == RvOperationValue.InstallCustomApps:
            #    self._agent_update(operation, update_dir)
            else:
                self._regular_update(operation, update_dir)
Esempio n. 6
0
    def _regular_update(self, operation, update_dir):
        urn_response = RvUrn.get_operation_urn(operation.type)
        install_method = self._get_install_method(operation.type)

        restart_needed = False

        for install_data in operation.install_data_list:

            install_result = install_method(install_data, update_dir)

            if install_result.restart == 'true':
                restart_needed = True

            rvsof_result = RvSofResult(
                operation.id,
                operation.type,
                install_data.id,  # app id
                install_result.apps_to_delete,  # apps_to_delete
                install_result.apps_to_add,  # apps_to_add
                install_result.successful,  # success
                install_result.restart,  # restart
                install_result.error,  # error
                install_result.app_json,  # app json
                urn_response,
                RequestMethod.PUT
            )

            # TODO(urgent): always leave commented out, or remove
            #loaded = json.loads(rvsof_result.raw_result)
            #print json.dumps(loaded, indent=4)

            self._send_results(rvsof_result)

        # TODO(urgent): should I call a handlers cleaning method from here?

        if os.path.isdir(self._update_directory):
            shutil.rmtree(self._update_directory)

        logger.info('Done installing updates.')

        self._restart_if_needed(operation.restart, restart_needed)
Esempio n. 7
0
    def _regular_update(self, operation, update_dir):
        urn_response = RvUrn.get_operation_urn(operation.type)
        install_method = self._get_install_method(operation.type)

        restart_needed = False

        for install_data in operation.install_data_list:

            install_result = install_method(install_data, update_dir)

            if install_result.restart == 'true':
                restart_needed = True

            rvsof_result = RvSofResult(
                operation.id,
                operation.type,
                install_data.id,  # app id
                install_result.apps_to_delete,  # apps_to_delete
                install_result.apps_to_add,  # apps_to_add
                install_result.successful,  # success
                install_result.restart,  # restart
                install_result.error,  # error
                install_result.app_json,  # app json
                urn_response,
                RequestMethod.PUT)

            # TODO(urgent): always leave commented out, or remove
            #loaded = json.loads(rvsof_result.raw_result)
            #print json.dumps(loaded, indent=4)

            self._send_results(rvsof_result)

        # TODO(urgent): should I call a handlers cleaning method from here?

        if os.path.isdir(self._update_directory):
            shutil.rmtree(self._update_directory)

        logger.info('Done installing updates.')

        self._restart_if_needed(operation.restart, restart_needed)
Esempio n. 8
0
    def _agent_update(self, operation, update_dir):
        urn_response = RvUrn.get_operation_urn(operation.type)
        install_method = self._get_install_method(operation.type)
        # TODO(urgent): remove this, only for testing
        #install_method = self._operation_handler.install_agent_update

        restart_needed = False

        for install_data in operation.install_data_list:
            install_result = install_method(
                install_data, operation.id, update_dir
            )

            if install_result.restart == 'true':
                restart_needed = True

            rvsof_result = RvSofResult(
                operation.id,
                operation.type,
                install_data.id,  # app id
                install_result.apps_to_delete,  # apps_to_delete
                install_result.apps_to_add,  # apps_to_add
                install_result.successful,  # success
                install_result.restart,  # restart
                install_result.error,  # error
                install_result.app_json,  # app json
                urn_response,
                RequestMethod.PUT
            )

            if rvsof_result.success != '':
                self._send_results(rvsof_result)

        #if os.path.isdir(self._update_directory):
        #    shutil.rmtree(self._update_directory)

        logger.info('Done attempting to update agent.')

        self._restart_if_needed(operation.restart, restart_needed)
Esempio n. 9
0
    def _check_if_updated(self):
        logger.info("Checking if agent updated.")
        update_result = {}

        try:

            if os.path.exists(settings.update_file):
                with open(settings.update_file, 'r') as _file:
                    update_result = json.load(_file)

                app_id = update_result['app_id']
                operation_id = update_result['operation_id']
                success = update_result['success']
                error = update_result.get('error', '')

                rvsof_result = RvSofResult(
                    operation_id,
                    RvOperationValue.InstallAgentUpdate,
                    app_id,  # app id
                    [],  # apps_to_delete
                    [],  # apps_to_add
                    success,  # success
                    'false',  # restart
                    error,  # error
                    "{}",  # app json
                    RvUrn.get_install_agent_update_urn(),
                    RequestMethod.PUT
                )

                logger.info(rvsof_result.__dict__)

                self._send_results(rvsof_result)

                os.remove(settings.update_file)

        except Exception as e:
            logger.error("Failure while sending agent update result.")
            logger.exception(e)
Esempio n. 10
0
    def _check_if_updated(self):
        logger.info("Checking if agent updated.")
        update_result = {}

        try:

            if os.path.exists(settings.update_file):
                with open(settings.update_file, 'r') as _file:
                    update_result = json.load(_file)

                app_id = update_result['app_id']
                operation_id = update_result['operation_id']
                success = update_result['success']
                error = update_result.get('error', '')

                rvsof_result = RvSofResult(
                    operation_id,
                    RvOperationValue.InstallAgentUpdate,
                    app_id,  # app id
                    [],  # apps_to_delete
                    [],  # apps_to_add
                    success,  # success
                    'false',  # restart
                    error,  # error
                    "{}",  # app json
                    RvUrn.get_install_agent_update_urn(),
                    RequestMethod.PUT)

                logger.info(rvsof_result.__dict__)

                self._send_results(rvsof_result)

                os.remove(settings.update_file)

        except Exception as e:
            logger.error("Failure while sending agent update result.")
            logger.exception(e)
Esempio n. 11
0
    def _agent_update(self, operation, update_dir):
        urn_response = RvUrn.get_operation_urn(operation.type)
        install_method = self._get_install_method(operation.type)
        # TODO(urgent): remove this, only for testing
        #install_method = self._operation_handler.install_agent_update

        restart_needed = False

        for install_data in operation.install_data_list:
            install_result = install_method(install_data, operation.id,
                                            update_dir)

            if install_result.restart == 'true':
                restart_needed = True

            rvsof_result = RvSofResult(
                operation.id,
                operation.type,
                install_data.id,  # app id
                install_result.apps_to_delete,  # apps_to_delete
                install_result.apps_to_add,  # apps_to_add
                install_result.successful,  # success
                install_result.restart,  # restart
                install_result.error,  # error
                install_result.app_json,  # app json
                urn_response,
                RequestMethod.PUT)

            if rvsof_result.success != '':
                self._send_results(rvsof_result)

        #if os.path.isdir(self._update_directory):
        #    shutil.rmtree(self._update_directory)

        logger.info('Done attempting to update agent.')

        self._restart_if_needed(operation.restart, restart_needed)
Esempio n. 12
0
    def _uninstall_operation(self, operation):

        restart_needed = False
        urn_response = RvUrn.get_operation_urn(operation.type)

        if not operation.uninstall_data_list:
            error = "No applications specified to uninstall."

            rvsof_result = RvSofResult(
                operation.id,
                operation.type,
                '',  # app id
                [],  # apps_to_delete
                [],  # apps_to_add
                'false',  # success
                'false',  # restart
                error,  # error
                [],  # data
                urn_response,
                RequestMethod.PUT
            )

            self._send_results(rvsof_result)

        else:

            for uninstall_data in operation.uninstall_data_list:

                uninstall_result = \
                    self._operation_handler.uninstall_application(uninstall_data)

                if uninstall_result.restart == 'true':
                    restart_needed = True

                rvsof_result = RvSofResult(
                    operation.id,
                    operation.type,
                    uninstall_data.id,  # app id
                    [],  # apps_to_delete
                    [],  # apps_to_add
                    uninstall_result.success,  # success
                    uninstall_result.restart,  # restart
                    uninstall_result.error,  # error
                    [],  # data
                    urn_response,
                    RequestMethod.PUT
                )

                self._send_results(rvsof_result)

        logger.info('Done uninstalling applications.')

        self.run_refresh_apps_operation()

        # TODO(urgent): get restart working for uninstalls
        try:
            self._restart_if_needed(operation.restart, restart_needed)
        except AttributeError:
            logger.error(
                "Failed to check if restart was needed due to no"
                "restart attribute in operation."
            )