def get_apps(cls): ret = [] apps = Apps().get_all_apps() blacklist = ucr_get('repository/app_center/blacklist') whitelist = ucr_get('repository/app_center/whitelist') if blacklist: blacklist = re.split('\s*,\s*', blacklist) if whitelist: whitelist = re.split('\s*,\s*', whitelist) for app in apps: if blacklist or whitelist: unlocalised_app = app.get_app_cache_obj().copy( locale='en').find_by_component_id(app.component_id) if cls._blacklist_includes_app( blacklist, unlocalised_app) and not cls._blacklist_includes_app( whitelist, unlocalised_app): continue if app.end_of_life and not app.is_installed(): continue if ucr_is_true('ad/member') and app.ad_member_issue_hide: continue if ucr_get('server/role') not in app.server_role: continue if app._docker_prudence_is_true(): _apps = [ _app for _app in Apps().get_all_apps_with_id(app.id) if _app.docker_migration_works or not _app.docker ] try: app = sorted(_apps)[-1] except IndexError: continue ret.append(app) return ret
def _sanitize(self, value, name, further_args): app = Apps().find(value) if not app.is_installed() and not app.install_permissions_exist(): apps = Apps().get_all_apps_with_id(app.id) apps = [_app for _app in apps if not _app.install_permissions] if apps: app = sorted(apps)[-1] return app
def main(self, args): app = args.app self.original_app = self.old_app = Apps().find(app.id) if app == self.old_app: app = Apps().find_candidate(app) or app if self._app_too_old(self.old_app, app): return args.app = app return self.do_it(args)
def main(self, args): app = args.app self.original_app = self.old_app = Apps().find(app.id) if app == self.old_app: app = Apps().find_candidate(app) or app if not args.only_master_packages: # always allow only_master_packages if self._app_too_old(self.old_app, app): return args.app = app return self.do_it(args)
def get_by_component_id(self, component_id): domain = get_action('domain') if isinstance(component_id, list): requested_apps = [Apps().find_by_component_id(cid) for cid in component_id] return domain.to_dict(requested_apps) else: app = Apps().find_by_component_id(component_id) if app: return domain.to_dict([app])[0] else: raise umcm.UMC_Error(_('Could not find an application for %s') % component_id)
def _update_local_files(self): super(Update, self)._update_local_files() self.debug('Updating app icon files in UMC directory...') # clear existing SVG logo files and re-copy them again for isvg in glob(os.path.join(FRONTEND_ICONS_DIR, 'apps-*.svg')): os.unlink(isvg) for app in Apps().get_all_apps(): for _app in Apps().get_all_apps_with_id(app.id): self._update_svg_file(_app.logo_name, _app.get_cache_file('logo')) self._update_svg_file(_app.logo_detail_page_name, _app.get_cache_file('logodetailpage'))
def main(self, args): apps = args.app real_apps = [] for app in apps: old_app = Apps().find(app.id) if app == old_app: app = Apps().find_candidate(app) or app if not args.only_master_packages: # always allow only_master_packages if self._app_too_old(old_app, app): continue real_apps.append(app) if not real_apps: return args.app = real_apps return self.do_it(args)
def main(self, args): if not args.apps: args.apps = Apps().get_all_locally_installed_apps() self.logfile_logger = get_logfile_logger('update-certificates') for app in args.apps: self.log('updating certificates for {0}'.format(app)) self.update_certificates(app)
def _list(self, pattern): ret = [] for app in self.get_apps(): versions = [] installations = {} if pattern: if not fnmatch(app.id, pattern): continue app = Apps().find(app.id, latest=True) for _app in Apps().get_all_apps_with_id(app.id): ldap_obj = get_app_ldap_object(_app) servers = ldap_obj.installed_on_servers() versions.append(_app.version) installations[_app.version] = servers ret.append((app, versions, installations)) return ret
def main(self, args): something_changed = False for app_cache in self._app_caches(args): # first of all, set up local cache mkdir(app_cache.get_cache_dir()) if self._extract_local_archive(app_cache): something_changed = True for appcenter_cache in self._appcenter_caches(args): # download meta files like index.json mkdir(appcenter_cache.get_cache_dir()) if self._download_supra_files(appcenter_cache): appcenter_cache.clear_cache() something_changed = True for app_cache in self._app_caches(args): # try it one more time (ucs.ini may have changed) mkdir(app_cache.get_cache_dir()) if self._extract_local_archive(app_cache): something_changed = True # download apps based on meta files if self._download_apps(app_cache): app_cache.clear_cache() something_changed = True if something_changed: apps_cache = Apps() for app in apps_cache.get_all_locally_installed_apps(): newest_app = apps_cache.find_candidate(app) or app if app < newest_app: ucr_save({app.ucr_upgrade_key: 'yes'}) self._update_local_files()
def _get_docker(cls, app): if not app.docker: return if app.plugin_of: app = Apps().find(app.plugin_of) return cls._get_docker(app) return Docker(app, cls.logger)
def _upgrade_docker(self, app, args): install = get_action('install')() action_args = install._build_namespace( _namespace=args, app=app, set_vars=self._get_configure_settings(self.old_app, filter_action=False), send_info=False, skip_checks=['must_not_be_installed']) if install.call_with_namespace(action_args): app_cache = Apps() for _app in app_cache.get_all_apps(): if _app.plugin_of == app.id and _app.is_installed(): _app = app_cache.find(_app.id, latest=True) if _app.docker: _old_app = self.old_app self._upgrade_docker(_app, args) self.old_app = _old_app remove = get_action('remove')() action_args = remove._build_namespace( _namespace=args, app=self.old_app, send_info=False, skip_checks=['must_not_be_depended_on']) remove._remove_app(self.old_app, action_args) if remove._unregister_component(self.old_app): update_packages() self._call_join_script( app, args ) # run again in case remove() called an installed unjoin script self.old_app = app
def test_upgrade(self, app): if app.required_app_version_upgrade: required_version = LooseVersion(app.required_app_version_upgrade) installed_app = Apps().find(app.id) installed_version = LooseVersion(installed_app.version) if required_version > installed_version: return {'required_version': app.required_app_version_upgrade}
def main(self, args): apps = args.app real_apps = [] for app in apps: _apps = Apps().get_all_apps_with_id(app.id) if app._docker_prudence_is_true(): _apps = [_app for _app in _apps if not _app.docker] if _apps: app = sorted(_apps)[-1] self.warn( 'Using %s instead of %s because docker is to be ignored' % (app, args.app)) else: raise InstallNonDockerVersionError(args.app) if not app.install_permissions_exist(): _apps = [ _app for _app in _apps if not _app.install_permissions ] if _apps: app = sorted(_apps)[-1] self.warn( 'Using %s instead of %s because of lacking install permissions' % (app, args.app)) else: raise InstallWithoutPermissionError() real_apps.append(app) args.app = real_apps return self.do_it(args)
def get_apps(no_cache=False): if no_cache: AppCache().clear_cache() get = get_action('get') return [ get.to_dict(app) for app in Apps().get_all_apps() if app.is_ucs_component() ]
def _get_installations(self, app, hosts, app_ldap_objects): ret = {} local_ucs_version = ucr_get('version/version') for host in hosts: candidate = self._find_latest_app_version(app) role = host.info.get('serverRole')[0] description = host.info.get('description') remote_ucs_version = host.info.get('operatingSystemVersion') is_local = host.info.get('fqdn') == get_local_fqdn() if remote_ucs_version: remote_ucs_version = re.sub('.*([0-9]+\.[0-9]+).*', '\\1', remote_ucs_version) ip = host.info.get('ip') # list version = None update_available = None for app_obj in app_ldap_objects: app_obj_version = app_obj.info.get('version') app_obj_id = app_obj.info.get('id')[:-len(app_obj_version) - 1] if app_obj_id == app.id: if host.info.get('fqdn') in app_obj.info.get('server', []): version = app_obj_version break if local_ucs_version != remote_ucs_version: # unable to compute directly... better treat as not available update_available = False elif version: remote_app = Apps().find(app.id, app_version=version) if remote_app: prevent_docker = None if not is_local: prevent_docker = True candidate = Apps().find_candidate( remote_app, prevent_docker=prevent_docker) or remote_app update_available = remote_app < candidate ret[host['name']] = { 'ucs_version': remote_ucs_version, 'version': version, 'update_available': update_available, 'candidate_version': candidate.version, 'description': description, 'ip': ip, 'role': role, } return ret
def _sanitize(self, value, name, further_args): app_id = value app_version = None if '=' in value: app_id, app_version = tuple(value.split('=', 1)) app = Apps().find(app_id, app_version=app_version) if not app.is_installed() and not app.install_permissions_exist(): apps = Apps().get_all_apps_with_id(app.id) apps = [_app for _app in apps if not _app.install_permissions] if apps: if app_version: for _app in apps: if _app.version == app_version: app = _app break else: app = sorted(apps)[-1] return app
def _register_installed_apps_in_ucr(self): installed_codes = [] for app in Apps().get_all_apps(): if app.is_installed(): installed_codes.append(app.code) with catch_stdout(self.logger): ucr_save({ 'appcenter/installed': '-'.join(installed_codes), 'repository/app_center/installed': '-'.join(installed_codes), # to be deprecated })
def invoke_docker(self, function, app, force, values, progress): for setting in app.get_settings(): if isinstance(setting, FileSetting) and not isinstance(setting, PasswordFileSetting): if values.get(setting.name): values[setting.name] = values[setting.name].decode('base64') progress.title = _('%s: Running tests') % app.name serious_problems = False if function == 'upgrade': _original_app = app app = Apps().find_candidate(app) if app is None: # Bug #44384: Under mysterious circumstances, app may be None after the .find_candidate() # This may happen in global App Center when the system the user is logged in has different ini files # than the system the App shall be upgraded on. E.g., in mixed appcenter / appcenter-test environments app = _original_app errors, warnings = {'must_have_candidate': False}, {} else: errors, warnings = app.check(function) can_continue = force # "dry_run" if errors: MODULE.process('Cannot %s %s: %r' % (function, app.id, errors)) serious_problems = True can_continue = False if warnings: MODULE.process('Warning trying to %s %s: %r' % (function, app.id, warnings)) result = { 'serious_problems': serious_problems, 'invokation_forbidden_details': errors, 'invokation_warning_details': warnings, 'can_continue': can_continue, 'software_changes_computed': False, } if can_continue: kwargs = {'noninteractive': True, 'skip_checks': ['shall_have_enough_ram', 'shall_only_be_installed_in_ad_env_with_password_service', 'must_not_have_concurrent_operation'], 'set_vars': values} if function == 'install': progress.title = _('Installing %s') % (app.name,) elif function == 'uninstall': progress.title = _('Uninstalling %s') % (app.name,) elif function == 'upgrade': progress.title = _('Upgrading %s') % (app.name,) action = get_action(function) handler = UMCProgressHandler(progress) handler.setLevel(logging.INFO) action.logger.addHandler(handler) try: result['success'] = action.call(app=app, username=self.username, password=self.password, **kwargs) except AppCenterError as exc: raise umcm.UMC_Error(str(exc), result=dict( display_feedback=True, title='%s %s' % (exc.title, exc.info))) finally: action.logger.removeHandler(handler) return result
def test_upgrade(self, apps): current_ram = get_current_ram_available() required_ram = 0 for app in apps: required_ram += app.min_physical_ram installed_app = Apps().find(app.id) # is already installed, just a minor version upgrade # RAM "used" by this installed app should count # as free. best approach: subtract it required_ram -= installed_app.min_physical_ram if current_ram < required_ram: return {'minimum': required_ram, 'current': current_ram}
def _appcenter_caches(self, args): if args.appcenter_server: return [AppCenterCache(server=args.appcenter_server)] else: ret = [] servers = set() for appcenter_cache in Apps().get_appcenter_caches(): server = appcenter_cache.get_server() if server not in servers: servers.add(server) ret.append(appcenter_cache) return ret
def _update_apps(self, args): self.log( 'Updating all installed Apps to use the new App Center server') logfile_logger = get_logfile_logger('dev-use-test-appcenter') for app in Apps().get_all_locally_installed_apps(): self.log('Updating %s' % app) register = get_action('register') # we should only use ['component'] in container_mode() # and None otherwise, because it is more correct. however, # this would require credentials (for potential schema updates etc) register.call(apps=[app], register_task=['component']) if app.docker and not container_mode(): try: from univention.appcenter.docker import Docker except ImportError: # should not happen self.log('univention-appcenter-docker is not installed') continue start = get_action('start') start.call(app=app) docker = Docker(app, self.logger) self.log('Updating container... (checking for appbox)') if docker.execute('which', 'univention-app').returncode == 0: self.log( '... setting the new App Center inside the container') returncode = docker.execute( 'univention-install', '-y', 'univention-appcenter-dev', _logger=logfile_logger).returncode if returncode != 0: self.warn( 'univention-install univention-appcenter-dev failed!' ) if args.revert: returncode = docker.execute( 'univention-app', 'dev-use-test-appcenter', '--revert', _logger=logfile_logger).returncode else: returncode = docker.execute( 'univention-app', 'dev-use-test-appcenter', '--appcenter-host', args.appcenter_host, _logger=logfile_logger).returncode if returncode != 0: self.fatal( 'univention-app dev-use-test-appcenter failed!') else: self.log('... nothing to do here')
def main(self, args): reload_package_manager() apps = args.apps if not apps: self.debug('No apps given. Using all') apps = Apps().get_all_apps() self._register_component_for_apps(apps, args) self._register_files_for_apps(apps, args) self._register_host_for_apps(apps, args) self._register_app_for_apps(apps, args) self._register_database_for_apps(apps, args) self._register_attributes_for_apps(apps, args) self._register_installed_apps_in_ucr()
def get_settings(content, app): fname = '/tmp/app.settings' with open(fname, 'wb') as fd: fd.write(content) populate = get_action('dev-populate-appcenter') populate.call(component_id=app.component_id, ini=app.get_ini_file(), settings='/tmp/app.settings') app = Apps().find(app.id) settings = app.get_settings() return settings
def _candidate_dict(cls, app): ret = {} candidate = Apps().find_candidate(app) if candidate: ret['update_available'] = True ret['candidate_docker'] = candidate.docker ret['candidate_version'] = candidate.version ret['candidate_component_id'] = candidate.component_id ret['candidate_readme_update'] = candidate.readme_update ret['candidate_readme_post_update'] = candidate.readme_post_update else: ret['update_available'] = False # TODO: ucr.is_true(app.ucr_upgrade_key); Bug#39916 return ret
def buy(self, application): app = Apps().find(application) if not app or not app.shop_url: return None ret = {} ret['key_id'] = self.ucr.get('license/uuid') ret['ucs_version'] = self.ucr.get('version/version') ret['app_id'] = app.id ret['app_version'] = app.version # ret['locale'] = locale.getlocale()[0] # done by frontend ret['user_count'] = None # FIXME: get users and computers from license ret['computer_count'] = None return ret
def _get_app_network(self): _logger.debug('Getting network for %s' % self.app) network = ucr_get(self.app.ucr_ip_key) if network and '/' in network: _logger.debug('Found %s' % network) try: network = IPv4Network(u'%s' % (network, ), False) except ValueError as exc: _logger.warn('Error using the network %s: %s' % (network, exc)) return None else: return network docker0_net = IPv4Network( u'%s' % (ucr_get('appcenter/docker/compose/network', '172.16.1.1/16'), ), False) gateway, netmask = docker0_net.exploded.split('/', 1) # '172.16.1.1', '16' used_docker_networks = [] for _app in Apps().get_all_apps( ): # TODO: find container not managed by the App Center? if _app.id == self.app.id: continue ip = ucr_get(_app.ucr_ip_key) try: app_network = IPv4Network(u'%s' % (ip, ), False) except ValueError as exc: continue else: used_docker_networks.append(app_network) prefixlen_diff = 24 - int(netmask) if prefixlen_diff <= 0: _logger.warn( 'Cannot get a subnet big enough' ) # maybe I could... but currently, I only work with 24-netmasks return None for network in docker0_net.subnets( prefixlen_diff ): # 172.16.1.1/24, 172.16.2.1/24, ..., 172.16.255.1/24 _logger.debug('Testing %s' % network) if IPv4Address(u'%s' % (gateway, )) in network: _logger.debug('Refusing due to "main subnet"') continue if any( app_network.overlaps(network) for app_network in used_docker_networks): _logger.debug('Refusing due to range already used') continue return network _logger.warn('Cannot find any viable subnet')
def _sanitize(self, value, name, further_args): app = Apps.find_by_string(value) app_version = app.version if not app.is_installed() and not app.install_permissions_exist(): apps = Apps().get_all_apps_with_id(app.id) apps = [_app for _app in apps if not _app.install_permissions] if apps: for _app in apps: if _app.version == app_version: app = _app break else: app = sorted(apps)[-1] return app
def outside_test_app(request, local_appcenter, outside_test_preinst, outside_test_settings): ini_file, app_id = request.param() with open('/tmp/app.ini', 'w') as fd: fd.write(ini_file) with open('/tmp/app.settings', 'w') as fd: fd.write(outside_test_settings) with open('/tmp/app.preinst', 'w') as fd: fd.write(outside_test_preinst, ) populate = get_action('dev-populate-appcenter') populate.call(new=True, settings='/tmp/app.settings', preinst='/tmp/app.preinst', ini='/tmp/app.ini') return Apps().find(app_id)
def get_requested_apps(): ret = [] try: with open(APPCENTER_FILE) as f: for line in f: app = Apps().find(line.strip()) if app: ret.append(app) else: pass #utils.fail('Error finding %s' % (line,)) except EnvironmentError: pass #utils.fail('Error reading %s: %s' % (APPCENTER_FILE, exc)) return ret