def install_update(self, install_data, update_dir=None): """ Install OS X updates. Returns: Installation result """ # Use to get the apps to be removed on the server side old_install_list = self.get_installed_applications() success = 'false' error = RvError.UpdatesNotFound restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory #update_data = self._macsqlite.get_update_data( # install_data.name #) if install_data.downloaded: success, error = self.pkg_installer.install(install_data) if success != 'true': logger.debug( "Failed to install update {0}. success:{1}, error:{2}". format(install_data.name, success, error)) # Let the OS take care of downloading and installing. success, error = \ self.pkg_installer.complete_softwareupdate(install_data) else: logger.debug( ("Downloaded = False for: {0} calling " "complete_softwareupdate.").format(install_data.name)) success, error = \ self.pkg_installer.complete_softwareupdate(install_data) if success == 'true': #restart = update_data.get(UpdateDataColumn.NeedsRestart, 'false') restart = self._get_reboot_required(install_data.name) new_install_list = self.get_installed_applications() app_encoding = self._get_app_encoding(install_data.name, new_install_list) apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list) return InstallResult(success, error, restart, app_encoding, apps_to_delete, apps_to_add)
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = '' restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] success, error, restart = self._yum_update(install_data.name) if success == 'true': new_install_list = self.get_installed_applications() app = self._get_installed_app(install_data.name, new_install_list) app_encoding = app.to_dict() apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list ) return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') success = 'false' error = '' restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] old_install_list = self.get_installed_applications() success, error, restart = self._yum_update(install_data.name) if success == 'true': new_install_list = self.get_installed_applications() app = self._get_installed_app(install_data.name, new_install_list) app_encoding = app.to_dict() apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list ) return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def _get_installed_app(self, name): installed_packages = self._get_installed_packages() pkg_dict = installed_packages.get(name, {}) if not pkg_dict: return CreateApplication.null_application() return self._create_app_from_dict(pkg_dict)
def _get_installed_app(self, name): installed_packages = self._get_installed_packages() pkg_dict = installed_packages.get(name, {}) if not pkg_dict: return CreateApplication.null_application() return self._create_app_from_dict(pkg_dict)
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)
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)
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = '' restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory if install_data.downloaded: packages_dir = os.path.join(update_dir, install_data.id) success, error, restart = self._yum_local_update( install_data.name, packages_dir, install_data.proc_niceness ) if success == 'true': new_install_list = self.get_installed_applications() app = self._get_installed_app( install_data.name, new_install_list ) app_encoding = app.to_dict() apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list ) else: logger.debug("Downloaded = False for: {0}" .format(install_data.name)) error = "Failed to download packages." return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = RvError.UpdatesNotFound restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory packages_dir = os.path.join(update_dir, install_data.id) moving_error = self._move_pkgs_to_apt_dir(packages_dir) if not moving_error: success, error, restart = self._apt_install( install_data.name, install_data.proc_niceness ) if success == 'true': app = self._get_installed_app(install_data.name) app_encoding = app.to_dict() apps_to_add, apps_to_delete = \ self._get_apps_to_add_and_delete(old_install_list) else: error = moving_error # TODO(urgent): should I apt-get clean here or in rv_plugin? return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = '' restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory if install_data.downloaded: packages_dir = os.path.join(update_dir, install_data.id) success, error, restart = self._yum_local_update( install_data.name, packages_dir, install_data.proc_niceness) if success == 'true': new_install_list = self.get_installed_applications() app = self._get_installed_app(install_data.name, new_install_list) app_encoding = app.to_dict() apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list) else: logger.debug("Downloaded = False for: {0}".format( install_data.name)) error = "Failed to download packages." return InstallResult(success, error, restart, app_encoding, apps_to_delete, apps_to_add)
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = RvError.UpdatesNotFound restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory packages_dir = os.path.join(update_dir, install_data.id) moving_error = self._move_pkgs_to_apt_dir(packages_dir) if not moving_error: success, error, restart = self._apt_install( install_data.name, install_data.proc_niceness) if success == 'true': app = self._get_installed_app(install_data.name) app_encoding = app.to_dict() apps_to_add, apps_to_delete = \ self._get_apps_to_add_and_delete(old_install_list) else: error = moving_error # TODO(urgent): should I apt-get clean here or in rv_plugin? return InstallResult(success, error, restart, app_encoding, apps_to_delete, apps_to_add)
def install_update(self, install_data, update_dir=None): """ Install OS X updates. Returns: Installation result """ # Use to get the apps to be removed on the server side old_install_list = self.get_installed_applications() success = 'false' error = RvError.UpdatesNotFound restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory #update_data = self._macsqlite.get_update_data( # install_data.name #) if install_data.downloaded: success, error = self.pkg_installer.install(install_data) if success != 'true': logger.debug( "Failed to install update {0}. success:{1}, error:{2}" .format(install_data.name, success, error) ) # Let the OS take care of downloading and installing. success, error = \ self.pkg_installer.complete_softwareupdate(install_data) else: logger.debug(("Downloaded = False for: {0} calling " "complete_softwareupdate.") .format(install_data.name)) success, error = \ self.pkg_installer.complete_softwareupdate(install_data) if success == 'true': #restart = update_data.get(UpdateDataColumn.NeedsRestart, 'false') restart = self._get_reboot_required(install_data.name) new_install_list = self.get_installed_applications() app_encoding = self._get_app_encoding( install_data.name, new_install_list ) apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list ) return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def _get_installed_app(self, name, installed_apps): for app in installed_apps: if app.name == name: return app return CreateApplication.null_application()
def _get_installed_app(self, name, install_list): for app in install_list: if app.name == name: return app return CreateApplication.null_application()
def oracle_jre_install(): JRE7_root_path = '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/' JRE7_command = os.path.join(JRE7_root_path, 'Contents/Home/bin/java') application = CreateApplication.null_application() try: if os.path.exists(JRE7_command): # For some sane reason, '-version' spits output to the # stderr... output = subprocess.check_output([JRE7_command, '-version'], stderr=subprocess.STDOUT) # Output example: # java version "1.7.0_21" # Java(TM) SE Runtime Environment (build 1.7.0_21-b12) # Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode) if '64-Bit' in output.splitlines()[2]: bit_type = '64' else: bit_type = '32' app_name = 'Java ' + bit_type app_vendor_name = 'Oracle' raw_ver = 'NA' try: raw_ver = output.splitlines()[0].split('"')[1] version = raw_ver.replace('_', '.') + '0' app_version = version.partition('.')[2] except Exception as e: logger.error("Unknown Java version format: %s" % raw_ver) app_version = '' try: s = os.stat(JRE7_command) #app.install_date = datetime.fromtimestamp( # s.st_ctime).strftime('%m/%d/%Y') app_install_date = s.st_ctime except Exception as e: logger.error("Could not verify install date.") logger.exception(e) app_install_date = None application = CreateApplication.create( app_name, app_version, '', # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size '', # vendor_id, app_vendor_name, # vendor_name app_install_date, # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) except Exception as e: logger.error("Could not verify Oracle Java install.") logger.exception(e) return application
def oracle_jre_install(): JRE7_root_path = '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/' JRE7_command = os.path.join(JRE7_root_path, 'Contents/Home/bin/java') application = CreateApplication.null_application() try: if os.path.exists(JRE7_command): # For some sane reason, '-version' spits output to the # stderr... output = subprocess.check_output([JRE7_command, '-version'], stderr=subprocess.STDOUT) # Output example: # java version "1.7.0_21" # Java(TM) SE Runtime Environment (build 1.7.0_21-b12) # Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode) if '64-Bit' in output.splitlines()[2]: bit_type = '64' else: bit_type = '32' app_name = 'Java ' + bit_type app_vendor_name = 'Oracle' raw_ver = 'NA' try: raw_ver = output.splitlines()[0].split('"')[1] version = raw_ver.replace('_', '.') + '0' app_version = version.partition('.')[2] except Exception as e: logger.error("Unknown Java version format: %s" % raw_ver) app_version = '' try: s = os.stat(JRE7_command) #app.install_date = datetime.fromtimestamp( # s.st_ctime).strftime('%m/%d/%Y') app_install_date = s.st_ctime except Exception as e: logger.error("Could not verify install date.") logger.exception(e) app_install_date = None application = CreateApplication.create( app_name, app_version, '', # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size '', # vendor_id, app_vendor_name, # vendor_name app_install_date, # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) except Exception as e: logger.error("Could not verify Oracle Java install.") logger.exception(e) return application