def Run(self, args): client = registrations.RegistrationsClient() args.registration = util.NormalizeResourceName(args.registration) registration_ref = args.CONCEPTS.registration.Parse() if args.disable_dnssec and args.dns_settings_from_file: raise exceptions.Error( 'argument --disable-dnssec: At most one of ' '--dns-settings-from-file | --disable-dnssec may be specified.') registration = client.Get(registration_ref) util.AssertRegistrationOperational(registration) dns_settings, updated = dns_util.ParseDNSSettings( args.name_servers, args.cloud_dns_zone, args.use_google_domains_dns, args.dns_settings_from_file, registration_ref.registrationsId, enable_dnssec=not args.disable_dnssec, dns_settings=registration.dnsSettings) if dns_settings is None: dns_settings, updated = dns_util.PromptForNameServers( registration_ref.registrationsId, enable_dnssec=not args.disable_dnssec, dns_settings=registration.dnsSettings) if dns_settings is None: return None if registration.dnsSettings.glueRecords and not updated.glue_records: # It's ok to leave Glue records while changing name servers. log.status.Print('Glue records will not be cleared. If you want to clear ' 'them, use --dns-settings-from-file flag.') ds_records_present = dns_util.DnssecEnabled(registration.dnsSettings) name_servers_changed = updated.dns_provider and not dns_util.NameServersEquivalent( registration.dnsSettings, dns_settings) if ds_records_present and name_servers_changed: log.warning('Name servers should not be changed if Ds ' 'records are present. Disable DNSSEC first and wait ' '24 hours before you change name servers. Otherwise ' 'your domain may stop serving.') if not args.unsafe_dns_update: dns_util.PromptForUnsafeDnsUpdate() response = client.ConfigureDNS( registration_ref, dns_settings, updated, validate_only=args.validate_only) if args.validate_only: log.status.Print('The command will not have any effect because ' 'validate-only flag is present.') else: response = util.WaitForOperation(response, args.async_) log.UpdatedResource(registration_ref.Name(), 'registration', args.async_) return response
def testDifferentNameServersNotEquivalent(self): messages = registrations.GetMessagesModule(API_VERSION) prev_dns_settings = messages.DnsSettings(customDns=messages.CustomDns( nameServers=['ns1.com', 'ns2.com'])) new_dns_settings = messages.DnsSettings(customDns=messages.CustomDns( nameServers=['new.ns1.com', 'new.ns2.com'])) self.assertFalse( dns_util.NameServersEquivalent(prev_dns_settings, new_dns_settings))
def testCustomNameServersDifferentOrderEquivalent(self): messages = registrations.GetMessagesModule(API_VERSION) prev_dns_settings = messages.DnsSettings(customDns=messages.CustomDns( nameServers=['ns1.com', 'ns2.com'], dsRecords=[messages.DsRecord(digest='hash')])) new_dns_settings = messages.DnsSettings(customDns=messages.CustomDns( nameServers=['ns2.com', 'ns1.com'])) self.assertTrue( dns_util.NameServersEquivalent(prev_dns_settings, new_dns_settings))
def testDifferentDnsProvidersNotEquivalent(self): messages = registrations.GetMessagesModule(API_VERSION) prev_dns_settings = messages.DnsSettings( googleDomainsDns=messages.GoogleDomainsDns( nameServers=['ns1.com', 'ns2.com'], dsState=messages.GoogleDomainsDns.DsStateValueValuesEnum. DS_RECORDS_PUBLISHED)) new_dns_settings = messages.DnsSettings(customDns=messages.CustomDns( nameServers=['ns1.com', 'ns2.com'])) self.assertFalse( dns_util.NameServersEquivalent(prev_dns_settings, new_dns_settings))
def testGoogleDomainsNameServersEquivalent(self): messages = registrations.GetMessagesModule(API_VERSION) prev_dns_settings = messages.DnsSettings( googleDomainsDns=messages.GoogleDomainsDns( nameServers=['ns1.com', 'ns2.com'], dsState=messages.GoogleDomainsDns.DsStateValueValuesEnum. DS_RECORDS_PUBLISHED)) new_dns_settings = messages.DnsSettings( googleDomainsDns=messages.GoogleDomainsDns( dsState=messages.GoogleDomainsDns.DsStateValueValuesEnum. DS_RECORDS_UNPUBLISHED)) self.assertTrue( dns_util.NameServersEquivalent(prev_dns_settings, new_dns_settings))