Example #1
0
  def Run(self, args):
    api_version = 'v1beta2'
    messages = apis.GetMessagesModule('dns', api_version)

    dns_client = util.GetApiClient(api_version)

    zone_ref = util.GetRegistry(api_version).Parse(
        args.zone,
        params={
            'project': properties.VALUES.core.project.GetOrFail,
        },
        collection='dns.managedZones')

    rrsets_ref = util.GetRegistry(api_version).Parse(
        args.type,
        params={
            'project': properties.VALUES.core.project.GetOrFail,
            'managedZone': args.zone,
            'name': args.name
        },
        collection='dns.resourceRecordSets')

    result = dns_client.resourceRecordSets.Delete(
        messages.DnsResourceRecordSetsDeleteRequest(
            project=zone_ref.project,
            managedZone=zone_ref.Name(),
            name=util.AppendTrailingDot(args.name),
            type=args.type))
    log.DeletedResource(rrsets_ref)

    return result
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)

        messages = apis.GetMessagesModule('dns', api_version)

        dns_client = util.GetApiClient(api_version)

        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params=util.GetParamsForRegistry(api_version, args),
            collection='dns.managedZones')
        param = util.GetParamsForRegistry(api_version,
                                          args,
                                          parent='managedZones')
        param['name'] = args.name
        rrsets_ref = util.GetRegistry(api_version).Parse(
            args.type, params=param, collection='dns.resourceRecordSets')

        request = messages.DnsResourceRecordSetsDeleteRequest(
            project=zone_ref.project,
            managedZone=zone_ref.Name(),
            name=util.AppendTrailingDot(args.name),
            type=args.type)

        if api_version == 'v2' and self._BetaOrAlpha():
            request.location = args.location

        result = dns_client.resourceRecordSets.Delete(request)
        log.DeletedResource(rrsets_ref)

        return result
Example #3
0
    def Run(self, args):
        api_version = 'v1'
        # If in the future there are differences between API version, do NOT use
        # this patter of checking ReleaseTrack. Break this into multiple classes.
        if self.ReleaseTrack() == base.ReleaseTrack.BETA:
            api_version = 'v1beta2'

        dns_client = apis.GetClientInstance('dns', api_version)

        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
            },
            collection='dns.managedZones')

        return list_pager.YieldFromList(
            dns_client.resourceRecordSets,
            dns_client.MESSAGES_MODULE.DnsResourceRecordSetsListRequest(
                project=zone_ref.project,
                managedZone=zone_ref.Name(),
                name=util.AppendTrailingDot(args.name),
                type=args.type),
            limit=args.limit,
            field='rrsets')
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)

        messages = apis.GetMessagesModule('dns', api_version)

        dns_client = util.GetApiClient(api_version)

        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params=util.GetParamsForRegistry(api_version, args),
            collection='dns.managedZones')
        request = messages.DnsResourceRecordSetsCreateRequest(
            project=zone_ref.project,
            managedZone=zone_ref.Name(),
            resourceRecordSet=rrsets_util.CreateRecordSetFromArgs(
                args,
                api_version,
                allow_extended_records=(
                    self.ReleaseTrack() == base.ReleaseTrack.ALPHA)))

        if api_version == 'v2':
            request.location = args.location

        result = dns_client.resourceRecordSets.Create(request)

        return result
Example #5
0
    def Run(self, args):
        dns_client = apis.GetClientInstance('dns', 'v1beta2')

        zone_refs = [
            util.GetRegistry('v1beta2').Parse(
                zone,
                params={
                    'project': properties.VALUES.core.project.GetOrFail,
                },
                collection='dns.managedZones') for zone in args.zones
        ]
        requests = [
            dns_client.MESSAGES_MODULE.DnsManagedZoneOperationsListRequest(
                managedZone=zone_ref.Name(), project=zone_ref.project)
            for zone_ref in zone_refs
        ]
        responses = [
            list_pager.YieldFromList(dns_client.managedZoneOperations,
                                     request,
                                     limit=args.limit,
                                     field='operations')
            for request in requests
        ]

        return itertools.chain.from_iterable(responses)
Example #6
0
    def Run(self, args):
        zones_client = managed_zones.Client.FromApiVersion('v1beta2')
        messages = zones_client.messages

        forwarding_config = None
        if args.forwarding_targets:
            forwarding_config = command_util.ParseManagedZoneForwardingConfig(
                args.forwarding_targets, messages)

        visibility_config = None
        if args.networks:
            networks = args.networks if args.networks != [''] else []
            network_urls = [
                util.GetRegistry('v1beta2').Parse(
                    n,
                    params={
                        'project': properties.VALUES.core.project.GetOrFail
                    },
                    collection='compute.networks').SelfLink() for n in networks
            ]
            network_configs = [
                messages.ManagedZonePrivateVisibilityConfigNetwork(
                    networkUrl=nurl) for nurl in network_urls
            ]
            visibility_config = messages.ManagedZonePrivateVisibilityConfig(
                networks=network_configs)

        return _Update(zones_client,
                       args,
                       private_visibility_config=visibility_config,
                       forwarding_config=forwarding_config)
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Response Policy Rule
        registry = util.GetRegistry(api_version)
        response_policy_rule_ref = registry.Parse(
            args.response_policy_rule,
            util.GetParamsForRegistry(api_version,
                                      args,
                                      parent='responsePolicies'),
            collection='dns.responsePolicyRules')
        response_policy_rule_name = response_policy_rule_ref.Name()

        delete_request = messages.DnsResponsePolicyRulesDeleteRequest(
            responsePolicy=args.response_policy,
            project=response_policy_rule_ref.project,
            responsePolicyRule=response_policy_rule_name)

        if api_version == 'v2' and self._BetaOrAlpha():
            delete_request.location = args.location

        result = client.responsePolicyRules.Delete(delete_request)

        log.DeletedResource(response_policy_rule_ref,
                            kind='ResponsePolicyRule')

        return result
Example #8
0
  def Run(self, args):
    dns = apis.GetClientInstance('dns', 'v2beta1')
    messages = apis.GetMessagesModule('dns', 'v2beta1')

    zone_ref = util.GetRegistry('v2beta1').Parse(
        args.dns_zone,
        params={
            'project': properties.VALUES.core.project.GetOrFail,
        },
        collection='dns.managedZones')

    dnssec_config = None
    if args.dnssec_state is not None:
      dnssec_config = command_util.ParseDnssecConfigArgs(args, messages)
    else:
      bad_args = ['denial_of_existence', 'ksk_algorithm', 'zsk_algorithm',
                  'ksk_key_length', 'zsk_key_length']
      for bad_arg in bad_args:
        if getattr(args, bad_arg, None) is not None:
          raise exceptions.InvalidArgumentException(
              bad_arg,
              'DNSSEC must be enabled in order to use other DNSSEC arguments. '
              'Please set --dnssec-state to "on" or "transfer".')

    zone = messages.ManagedZone(name=zone_ref.managedZone,
                                dnsName=util.AppendTrailingDot(args.dns_name),
                                description=args.description,
                                dnssecConfig=dnssec_config)

    result = dns.managedZones.Create(
        messages.DnsManagedZonesCreateRequest(managedZone=zone,
                                              project=zone_ref.project))
    log.CreatedResource(zone_ref)
    return result
Example #9
0
def GetCloudDnsNameServers(cloud_dns_zone, domain):
    """Fetches list of name servers from provided Cloud DNS Managed Zone."""
    # Get the managed-zone.
    dns_api_version = 'v1'
    dns = apis.GetClientInstance('dns', dns_api_version)
    zone_ref = dns_api_util.GetRegistry(dns_api_version).Parse(
        cloud_dns_zone,
        params={
            'project': properties.VALUES.core.project.GetOrFail,
        },
        collection='dns.managedZones')

    try:
        zone = dns.managedZones.Get(
            dns.MESSAGES_MODULE.DnsManagedZonesGetRequest(
                project=zone_ref.project, managedZone=zone_ref.managedZone))
    except apitools_exceptions.HttpError as error:
        raise calliope_exceptions.HttpException(error)
    domain_with_dot = domain + '.'
    if zone.dnsName != domain_with_dot:
        raise exceptions.Error(
            'The dnsName [{}] of specified Cloud DNS zone [{}] does not match the '
            'registration domain [{}]'.format(zone.dnsName, cloud_dns_zone,
                                              domain_with_dot))
    return zone.nameServers
Example #10
0
    def Run(self, args):
        api_version = 'v1'
        # If in the future there are differences between API version, do NOT use
        # this patter of checking ReleaseTrack. Break this into multiple classes.
        if self.ReleaseTrack() == base.ReleaseTrack.BETA:
            api_version = 'v1beta2'

        if os.path.isfile(args.transaction_file):
            raise transaction_util.TransactionFileAlreadyExists(
                'Transaction already exists at [{0}]'.format(
                    args.transaction_file))

        dns = apis.GetClientInstance('dns', api_version)

        # Get the managed-zone.
        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
            },
            collection='dns.managedZones')

        try:
            zone = dns.managedZones.Get(
                dns.MESSAGES_MODULE.DnsManagedZonesGetRequest(
                    project=zone_ref.project,
                    managedZone=zone_ref.managedZone))
        except apitools_exceptions.HttpError as error:
            raise calliope_exceptions.HttpException(error)

        # Initialize an empty change
        change = dns.MESSAGES_MODULE.Change()

        # Get the SOA record, there will be one and only one.
        # Add addition and deletion for SOA incrementing to change.
        records = [
            record for record in list_pager.YieldFromList(
                dns.resourceRecordSets,
                dns.MESSAGES_MODULE.DnsResourceRecordSetsListRequest(
                    project=zone_ref.project,
                    managedZone=zone_ref.Name(),
                    name=zone.dnsName,
                    type='SOA'),
                field='rrsets')
        ]
        change.deletions.append(records[0])
        change.additions.append(
            import_util.NextSOARecordSet(records[0], api_version=api_version))

        # Write change to transaction file
        try:
            with files.FileWriter(args.transaction_file) as transaction_file:
                transaction_util.WriteToYamlFile(transaction_file, change)
        except Exception as exp:
            msg = 'Unable to write transaction [{0}] because [{1}]'
            msg = msg.format(args.transaction_file, exp)
            raise transaction_util.UnableToAccessTransactionFile(msg)

        log.status.Print('Transaction started [{0}].'.format(
            args.transaction_file))
 def GetNetworkSelfLink(network):
     return util.GetRegistry('v1').Parse(
         network,
         collection='compute.networks',
         params={
             'project': properties.VALUES.core.project.GetOrFail
         }).SelfLink()
Example #12
0
  def Run(self, args):
    dns = apis.GetClientInstance('dns', 'v1beta2')
    messages = apis.GetMessagesModule('dns', 'v1beta2')

    zone_ref = util.GetRegistry('v1beta2').Parse(
        args.dns_zone,
        params={
            'project': properties.VALUES.core.project.GetOrFail,
        },
        collection='dns.managedZones')

    dnssec_config = command_util.ParseDnssecConfigArgs(args, messages)
    zone_args = {'name': args.dns_zone}
    if dnssec_config is not None:
      zone_args['dnssecConfig'] = dnssec_config
    if args.description is not None:
      zone_args['description'] = args.description
    zone = messages.ManagedZone(**zone_args)

    def Get():
      return dns.managedZones.Get(
          dns.MESSAGES_MODULE.DnsManagedZonesGetRequest(
              project=zone_ref.project,
              managedZone=zone_ref.managedZone)).labels
    labels_update = labels_util.ProcessUpdateArgsLazy(
        args, messages.ManagedZone.LabelsValue, Get)
    zone.labels = labels_update.GetOrNone()

    result = dns.managedZones.Patch(
        messages.DnsManagedZonesPatchRequest(managedZoneResource=zone,
                                             project=zone_ref.project,
                                             managedZone=args.dns_zone))
    return result
Example #13
0
 def GetNetworkSelfLink(network_url):
   return dns_util.GetRegistry(version).Parse(
       network_url,
       collection="compute.networks",
       params={
           "project": "fake-project"
       }).SelfLink()
Example #14
0
    def Run(self, args):
        dns = apis.GetClientInstance('dns', 'v1beta2')
        messages = apis.GetMessagesModule('dns', 'v1beta2')

        zone_ref = util.GetRegistry('v1beta2').Parse(
            args.dns_zone,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
            },
            collection='dns.managedZones')

        dnssec_config = _MakeDnssecConfig(args, messages)

        labels = labels_util.ParseCreateArgs(args,
                                             messages.ManagedZone.LabelsValue)

        zone = messages.ManagedZone(name=zone_ref.managedZone,
                                    dnsName=util.AppendTrailingDot(
                                        args.dns_name),
                                    description=args.description,
                                    dnssecConfig=dnssec_config,
                                    labels=labels)

        result = dns.managedZones.Create(
            messages.DnsManagedZonesCreateRequest(managedZone=zone,
                                                  project=zone_ref.project))
        log.CreatedResource(zone_ref)
        return [result]
Example #15
0
  def Run(self, args):
    api_version = 'v1'
    # If in the future there are differences between API version, do NOT use
    # this patter of checking ReleaseTrack. Break this into multiple classes.
    if self.ReleaseTrack() == base.ReleaseTrack.BETA:
      api_version = 'v1beta2'
    elif self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
      api_version = 'v1alpha2'

    dns_client = util.GetApiClient(api_version)

    zone_ref = util.GetRegistry(api_version).Parse(
        args.zone,
        params={
            'project': properties.VALUES.core.project.GetOrFail,
        },
        collection='dns.managedZones')

    return list_pager.YieldFromList(
        dns_client.changes,
        dns_client.MESSAGES_MODULE.DnsChangesListRequest(
            project=zone_ref.project,
            managedZone=zone_ref.Name(),
            sortOrder=args.sort_order),
        limit=args.limit, field='changes')
Example #16
0
    def UpdateLabels(self, zone_ref, labels):
        """Update labels using Managed Zones Update request."""
        zone = self.Get(zone_ref)
        zone.labels = labels

        operation = self._service.Update(
            self.messages.DnsManagedZonesUpdateRequest(
                managedZoneResource=zone,
                project=zone_ref.project,
                managedZone=zone_ref.Name()))

        operation_param = {
            'project': zone_ref.project,
            'managedZone': zone_ref.Name(),
        }

        if self.location:
            operation_param['location'] = self.location
        operation_ref = util.GetRegistry(self.version).Parse(
            operation.id,
            params=operation_param,
            collection='dns.managedZoneOperations')

        return operations.WaitFor(
            self.version, operation_ref,
            'Updating managed zone [{}]'.format(zone_ref.Name()))
Example #17
0
    def Run(self, args):
        dns = apis.GetClientInstance('dns', 'v1beta2')
        project_ref = util.GetRegistry('v1beta2').Parse(
            args.dns_project, collection='dns.projects')

        return dns.projects.Get(
            dns.MESSAGES_MODULE.DnsProjectsGetRequest(
                project=project_ref.project))
Example #18
0
    def Run(self, args):
        api_version = 'v1'
        # If in the future there are differences between API version, do NOT use
        # this patter of checking ReleaseTrack. Break this into multiple classes.
        if self.ReleaseTrack() == base.ReleaseTrack.BETA:
            api_version = 'v1beta2'
        elif self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
            api_version = 'v1alpha2'

        with transaction_util.TransactionFile(
                args.transaction_file) as trans_file:
            change = transaction_util.ChangeFromYamlFile(
                trans_file, api_version=api_version)

        if import_util.IsOnlySOAIncrement(change, api_version=api_version):
            log.status.Print('Nothing to do, empty transaction [{0}]'.format(
                args.transaction_file))
            os.remove(args.transaction_file)
            return None

        dns = apis.GetClientInstance('dns', api_version)
        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
            },
            collection='dns.managedZones')

        # Send the change to the service.
        result = dns.changes.Create(
            dns.MESSAGES_MODULE.DnsChangesCreateRequest(
                change=change,
                managedZone=zone_ref.Name(),
                project=zone_ref.project))
        change_ref = util.GetRegistry(api_version).Create(
            collection='dns.changes',
            project=zone_ref.project,
            managedZone=zone_ref.Name(),
            changeId=result.id)
        msg = 'Executed transaction [{0}] for managed-zone [{1}].'.format(
            args.transaction_file, zone_ref.Name())
        log.status.Print(msg)
        log.CreatedResource(change_ref)
        os.remove(args.transaction_file)
        return result
    def Run(self, args):
        api_version = util.GetApiFromTrack(self.ReleaseTrack())
        dns = util.GetApiClient(api_version)
        project_ref = util.GetRegistry(api_version).Parse(
            args.dns_project, collection='dns.projects')

        return dns.projects.Get(
            dns.MESSAGES_MODULE.DnsProjectsGetRequest(
                project=project_ref.project))
Example #20
0
def _Describe(operations_client, args):
    operation_ref = util.GetRegistry(operations_client.version).Parse(
        args.operation_id,
        params={
            'project': properties.VALUES.core.project.GetOrFail,
            'managedZone': args.zone
        },
        collection='dns.managedZoneOperations')

    return operations_client.Get(operation_ref)
Example #21
0
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
        location = args.location if api_version == 'v2' else None
        zones_client = managed_zones.Client.FromApiVersion(
            api_version, location)
        registry = util.GetRegistry(api_version)

        zone_ref = registry.Parse(args.zone,
                                  util.GetParamsForRegistry(api_version, args),
                                  collection='dns.managedZones')
        return zones_client.Get(zone_ref)
Example #22
0
def ParseNetworks(value, project, version):
    """Build a list of PolicyNetworks from command line args."""
    if not value:
        return []
    registry = api_util.GetRegistry(version)
    networks = [
        registry.Parse(network_name,
                       collection='compute.networks',
                       params={'project': project}) for network_name in value
    ]
    return PolicyNetworkProcessor(networks, version)
  def Run(self, args):
    api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
    client = util.GetApiClient(api_version)
    messages = apis.GetMessagesModule('dns', api_version)

    # Get Response Policy Rule
    registry = util.GetRegistry(api_version)
    response_policy_rule_ref = registry.Parse(
        args.response_policy_rule,
        util.GetParamsForRegistry(api_version, args, parent='responsePolicies'),
        collection='dns.responsePolicyRules')
    response_policy_rule_name = response_policy_rule_ref.Name()

    response_policy_rule = messages.ResponsePolicyRule(
        ruleName=response_policy_rule_name)

    response_policy_rule.dnsName = args.dns_name

    if args.IsSpecified('behavior') and args.IsSpecified('local_data'):
      raise exceptions.ConflictingArgumentsException(
          'Only one of arguments [--behavior, --local-data] is allowed.')

    if args.IsSpecified('behavior'):
      response_policy_rule.behavior = command_util.ParseResponsePolicyRulesBehavior(
          args, api_version)
    elif args.IsSpecified('local_data'):
      rrsets = []
      for rrset in args.local_data:
        resource_record_set = messages.ResourceRecordSet(
            name=rrset.get('name'),
            type=rrset.get('type'),
            ttl=rrset.get('ttl'),
            rrdatas=rrset.get('rrdatas').split('|'))
        rrsets.append(resource_record_set)

      local_data = messages.ResponsePolicyRuleLocalData(
          localDatas=rrsets)
      response_policy_rule.localData = local_data

    create_request = messages.DnsResponsePolicyRulesCreateRequest(
        responsePolicy=args.response_policy,
        project=response_policy_rule_ref.project,
        responsePolicyRule=response_policy_rule)

    if api_version == 'v2' and self._BetaOrAlpha():
      create_request.location = args.location

    result = client.responsePolicyRules.Create(create_request)

    log.CreatedResource(response_policy_rule_ref, kind='ResponsePolicyRule')

    return result
Example #24
0
  def Run(self, args):
    dns = apis.GetClientInstance('dns', 'v1beta2')
    zone_ref = util.GetRegistry('v1beta2').Parse(
        args.dns_zone,
        params={
            'project': properties.VALUES.core.project.GetOrFail,
        },
        collection='dns.managedZones')

    return dns.managedZones.Get(
        dns.MESSAGES_MODULE.DnsManagedZonesGetRequest(
            project=zone_ref.project,
            managedZone=zone_ref.managedZone))
    def Run(self, args):
        api_version = 'v1'
        # If in the future there are differences between API version, do NOT use
        # this patter of checking ReleaseTrack. Break this into multiple classes.
        if self.ReleaseTrack() == base.ReleaseTrack.BETA:
            api_version = 'v1beta2'
        elif self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
            api_version = 'v1alpha2'

        with trans_util.TransactionFile(args.transaction_file) as trans_file:
            change = trans_util.ChangeFromYamlFile(trans_file,
                                                   api_version=api_version)

        dns = util.GetApiClient(api_version)

        record_to_remove = rrsets_util.CreateRecordSetFromArgs(
            args,
            api_version=api_version,
            allow_extended_records=(
                self.ReleaseTrack() == base.ReleaseTrack.ALPHA))

        # Ensure the record to be removed exists
        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
            },
            collection='dns.managedZones')
        existing_records = [
            record for record in list_pager.YieldFromList(
                dns.resourceRecordSets,
                dns.MESSAGES_MODULE.DnsResourceRecordSetsListRequest(
                    project=zone_ref.project,
                    managedZone=zone_ref.Name(),
                    name=util.AppendTrailingDot(args.name),
                    type=args.type),
                field='rrsets')
        ]
        if not existing_records or existing_records[0] != record_to_remove:
            raise trans_util.RecordDoesNotExist(
                'Record to be removed does not exist')

        change.deletions.append(record_to_remove)

        with trans_util.TransactionFile(args.transaction_file,
                                        'w') as trans_file:
            trans_util.WriteToYamlFile(trans_file, change)

        log.status.Print(
            'Record removal appended to transaction at [{0}].'.format(
                args.transaction_file))
Example #26
0
    def Run(self, args):
        api_version = 'v1'
        # If in the future there are differences between API version, do NOT use
        # this patter of checking ReleaseTrack. Break this into multiple classes.
        if self.ReleaseTrack() == base.ReleaseTrack.BETA:
            api_version = 'v1beta2'
        if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
            api_version = 'v1alpha2'

        dns = util.GetApiClient(api_version)

        # Get the managed-zone.
        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
            },
            collection='dns.managedZones')
        try:
            zone = dns.managedZones.Get(
                dns.MESSAGES_MODULE.DnsManagedZonesGetRequest(
                    project=zone_ref.project,
                    managedZone=zone_ref.managedZone))
        except apitools_exceptions.HttpError as error:
            raise calliope_exceptions.HttpException(error)

        # Get all the record-sets.
        record_sets = []
        for record_set in list_pager.YieldFromList(
                dns.resourceRecordSets,
                dns.MESSAGES_MODULE.DnsResourceRecordSetsListRequest(
                    project=zone_ref.project, managedZone=zone_ref.Name()),
                field='rrsets'):
            record_sets.append(record_set)

        # Export the record-sets.
        try:
            with files.FileWriter(args.records_file) as export_file:
                if args.zone_file_format:
                    export_util.WriteToZoneFile(export_file, record_sets,
                                                zone.dnsName)
                else:
                    export_util.WriteToYamlFile(export_file, record_sets)
        except Exception as exp:
            msg = 'Unable to export record-sets to file [{0}]: {1}'.format(
                args.records_file, exp)
            raise export_util.UnableToExportRecordsToFile(msg)

        log.status.Print('Exported record-sets to [{0}].'.format(
            args.records_file))
Example #27
0
    def Run(self, args):
        dns = apis.GetClientInstance('dns', 'v1beta2')

        zone_ref = util.GetRegistry('v1beta2').Parse(
            args.dns_zone,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
            },
            collection='dns.managedZones')

        result = dns.managedZones.Delete(
            dns.MESSAGES_MODULE.DnsManagedZonesDeleteRequest(
                managedZone=zone_ref.managedZone, project=zone_ref.project))
        log.DeletedResource(zone_ref)
        return result
Example #28
0
    def Run(self, args):
        dns_client = apis.GetClientInstance('dns', 'v2beta1')

        zone_ref = util.GetRegistry('v2beta1').Parse(
            args.zone,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
            },
            collection='dns.managedZones')

        return list_pager.YieldFromList(
            dns_client.dnsKeys,
            dns_client.MESSAGES_MODULE.DnsDnsKeysListRequest(
                project=zone_ref.project, managedZone=zone_ref.Name()),
            field='dnsKeys')
Example #29
0
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Response Policy
        registry = util.GetRegistry(api_version)
        response_policy_ref = registry.Parse(args.response_policies,
                                             util.GetParamsForRegistry(
                                                 api_version, args),
                                             collection='dns.responsePolicies')
        to_update = self._FetchResponsePolicy(response_policy_ref, api_version)

        if not (args.IsSpecified('networks') or args.IsSpecified('description')
                or (self._BetaOrAlpha() and args.IsSpecified('gkeclusters'))):
            log.status.Print('Nothing to update.')
            return to_update

        if args.IsSpecified('networks'):
            if args.networks == ['']:
                args.networks = []
            to_update.networks = command_util.ParseResponsePolicyNetworks(
                args.networks, response_policy_ref.project, api_version)

        if self._BetaOrAlpha() and args.IsSpecified('gkeclusters'):
            gkeclusters = args.gkeclusters
            to_update.gkeClusters = [
                messages.ResponsePolicyGKECluster(gkeClusterName=name)
                for name in gkeclusters
            ]

        if args.IsSpecified('description'):
            to_update.description = args.description

        update_req = messages.DnsResponsePoliciesUpdateRequest(
            responsePolicy=response_policy_ref.Name(),
            responsePolicyResource=to_update,
            project=response_policy_ref.project)

        if api_version == 'v2':
            update_req.location = args.location

        updated_response_policy = client.responsePolicies.Update(update_req)

        log.UpdatedResource(updated_response_policy.responsePolicy,
                            kind='ResponsePolicy')

        return updated_response_policy
Example #30
0
    def Run(self, args):
        api_version = util.GetApiFromTrack(self.ReleaseTrack())
        dns = util.GetApiClient(api_version)

        zone_ref = util.GetRegistry(api_version).Parse(
            args.dns_zone,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
            },
            collection='dns.managedZones')

        result = dns.managedZones.Delete(
            dns.MESSAGES_MODULE.DnsManagedZonesDeleteRequest(
                managedZone=zone_ref.managedZone, project=zone_ref.project))
        log.DeletedResource(zone_ref)
        return result