def _unregister_app(self, app, args, lo=None, pos=None, delay=False): if lo is None: lo, pos = self._get_ldap_connection(args, allow_machine_connection=True) updates = {} for key in ucr_keys(): if key.startswith('appcenter/apps/%s/' % app.id): updates[key] = None if re.match('ucs/web/overview/entries/[^/]+/%s/' % app.id, key): updates[key] = None if re.match('appreport/%s/' % app.id, key): updates[key] = None if app.docker and not app.plugin_of: try: from univention.appcenter.actions.service import Service except ImportError: # univention-appcenter-docker is not installed pass else: try: init_script = Service.get_init(app) os.unlink(init_script) self._call_script('/usr/sbin/update-rc.d', os.path.basename(init_script), 'remove') except OSError: pass ldap_object = get_app_ldap_object(app, lo, pos) if ldap_object: self.log('Removing localhost from LDAP object') ldap_object.remove_localhost() if not delay: ucr_save(updates) self._reload_apache() return updates
def _register_app(self, app, args, lo=None, pos=None, delay=False): if lo is None: lo, pos = self._get_ldap_connection(args, allow_machine_connection=True) updates = {} self.log('Registering UCR for %s' % app.id) self.log('Marking %s as installed' % app) if app.is_installed(): status = ucr_get(app.ucr_status_key, 'installed') else: status = 'installed' ucr_save({ app.ucr_status_key: status, app.ucr_version_key: app.version, app.ucr_ucs_version_key: app.get_ucs_version() }) self._register_ports(app) updates.update(self._register_docker_variables(app)) updates.update(self._register_app_report_variables(app)) # Register app in LDAP (cn=...,cn=apps,cn=univention) ldap_object = get_app_ldap_object(app, lo, pos, or_create=True) self.log('Adding localhost to LDAP object') ldap_object.add_localhost() updates.update(self._register_overview_variables(app)) if not delay: ucr_save(updates) self._reload_apache() return updates
def _unregister_attributes(self, app, args): attributes, __ = get_extended_attributes(app) if attributes: lo, pos = self._get_ldap_connection(args) ldap_object = get_app_ldap_object(app, lo, pos) if ldap_object.get_siblings(): self.debug('Not removing attributes, App is still installed somewhere') return for attribute in attributes: remove_extended_attribute(attribute, lo, pos)
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 _register_attributes_for_apps(self, apps, args): if not self._shall_register(args, 'attributes'): return lo, pos = self._get_ldap_connection(args) for app in apps: ldap_object = get_app_ldap_object(app, lo, pos) if self._do_register(app, args): domain = get_action('domain') i = domain.to_dict([app])[0]['installations'] if all(LooseVersion(ucr_get('version/version')) >= LooseVersion(x['ucs_version']) for x in i.values() if x['ucs_version']): self._register_attributes(app, args) else: self.debug('Not registering attributes. App is not the latest version in domain.') elif ldap_object.get_siblings(): self.debug('Not removing attributes, App is still installed somewhere') else: self._unregister_attributes(app, args)