def execute(self, *keys, **options): fqdn = keys[0] if options['state'] == u'enabled': to_status = ENABLED from_status = HIDDEN else: to_status = HIDDEN from_status = ENABLED roles = self.api.Command.server_role_find( server_server=fqdn, status=from_status, include_master=True, )['result'] from_roles = [r[u'role_servrole'] for r in roles] if not from_roles: # no server role is in source status raise errors.EmptyModlist if to_status == ENABLED: enable_services(fqdn) else: self._check_hide_server(fqdn) hide_services(fqdn) # update system roles result = self.api.Command.dns_update_system_records() if not result.get('value'): self.add_message(messages.AutomaticDNSRecordsUpdateFailed()) return { 'value': fqdn, 'result': True, }
def post_callback(self, ldap, dn, entry_attrs, *keys, **options): assert isinstance(dn, DN) self.obj.get_enabled_roles(entry_attrs) if 'ipalocation_location' in options: ipalocation = entry_attrs.get('ipalocation') if ipalocation: ipalocation = ipalocation[0]['idnsname'] else: ipalocation = u'' try: self.api.Command.dnsserver_mod( keys[0], setattr=[ u'idnsSubstitutionVariable;ipalocation={loc}'.format( loc=ipalocation) ]) except errors.EmptyModlist: pass except errors.NotFound: # server is not DNS server pass if 'ipalocation_location' or 'ipaserviceweight' in options: self.add_message( messages.ServiceRestartRequired( service=services.service('named', api).systemd_name, server=keys[0], )) result = self.api.Command.dns_update_system_records() if not result.get('value'): self.add_message(messages.AutomaticDNSRecordsUpdateFailed()) self.obj.convert_location(entry_attrs, **options) ipalocation = entry_attrs.get('ipalocation_location', [None])[0] if ipalocation: servers_in_loc = self.api.Command.server_find( in_location=ipalocation, no_members=False)['result'] dns_server_in_loc = False for server in servers_in_loc: if 'DNS server' in server.get('enabled_role_servrole', ()): dns_server_in_loc = True break if not dns_server_in_loc: self.add_message( messages.LocationWithoutDNSServer(location=ipalocation)) return dn
def pre_callback(self, ldap, dn, *keys, **options): assert isinstance(dn, DN) if not options.get('force'): servers = self.api.Command.server_find( in_location=keys[-1])['result'] location_member = servers[0]['cn'][0] if servers else None if location_member: raise DependentEntry(label=_('IPA Server'), key=keys[-1], dependent=location_member) system_records = IPASystemRecords(self.api) _success, failed = system_records.remove_location_records(keys[-1]) if failed: self.add_message(messages.AutomaticDNSRecordsUpdateFailed()) return dn