Example #1
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')
    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 #3
0
  def Run(self, args):
    api_version = util.GetApiFromTrack(self.ReleaseTrack())
    client = util.GetApiClient(api_version)
    messages = apis.GetMessagesModule('dns', api_version)

    # Get Response Policy
    response_policy_ref = args.CONCEPTS.response_policies.Parse()
    to_update = self._FetchResponsePolicy(response_policy_ref, api_version)

    if not (args.IsSpecified('networks') or args.IsSpecified('description')):
      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 args.IsSpecified('description'):
      to_update.description = args.description

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

    updated_response_policy = client.responsePolicies.Update(update_req)

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

    return updated_response_policy
Example #4
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 #6
0
 def _FetchPolicy(self, policy_ref, api_version):
     """Get policy to be Updated."""
     client = util.GetApiClient(api_version)
     m = apis.GetMessagesModule('dns', api_version)
     get_request = m.DnsPoliciesGetRequest(policy=policy_ref.Name(),
                                           project=policy_ref.project)
     return client.policies.Get(get_request)
    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 _FetchResponsePolicy(self, response_policy_ref, api_version):
   """Get response policy to be Updated."""
   client = util.GetApiClient(api_version)
   message_module = apis.GetMessagesModule('dns', api_version)
   get_request = message_module.DnsResponsePoliciesGetRequest(
       responsePolicy=response_policy_ref.Name(),
       project=response_policy_ref.project)
   return client.responsePolicies.Get(get_request)
    def Run(self, args):
        dns = util.GetApiClient('v1')
        project_ref = resources.REGISTRY.Parse(args.dns_project,
                                               collection='dns.projects')

        return dns.projects.Get(
            dns.MESSAGES_MODULE.DnsProjectsGetRequest(
                project=project_ref.project))
Example #10
0
    def Run(self, args):
        dns = util.GetApiClient('v1alpha2')
        messages = apis.GetMessagesModule('dns', 'v1alpha2')

        result = dns.activePeeringZones.Deactivate(
            messages.DnsActivePeeringZonesDeactivateRequest(
                peeringZoneId=int(args.zone_id),
                project=properties.VALUES.core.project.GetOrFail()))
        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 #12
0
  def Run(self, args):
    dns_client = util.GetApiClient('v1')

    project_id = properties.VALUES.core.project.GetOrFail()

    return list_pager.YieldFromList(
        dns_client.managedZones,
        dns_client.MESSAGES_MODULE.DnsManagedZonesListRequest(
            project=project_id),
        field='managedZones')
Example #13
0
def _FetchResponsePolicyRule(response_policy, response_policy_rule,
                             api_version):
    """Get response policy rule to be Updated."""
    client = util.GetApiClient(api_version)
    m = apis.GetMessagesModule('dns', api_version)
    get_request = m.DnsResponsePolicyRulesGetRequest(
        responsePolicy=response_policy,
        project=properties.VALUES.core.project.Get(),
        responsePolicyRule=response_policy_rule)
    return client.responsePolicyRules.Get(get_request)
Example #14
0
    def Run(self, args):
        api_version = util.GetApiFromTrack(self.ReleaseTrack())
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Response Policy Rule
        response_policy_rule_ref = args.CONCEPTS.response_policy_rule.Parse()
        response_policy_rule_name = response_policy_rule_ref.Name()

        response_policy_rule = messages.ResponsePolicyRule(
            ruleName=response_policy_rule_name)

        response_policy = messages.ResponsePolicy(
            responsePolicyName=args.response_policy)

        to_update = _FetchResponsePolicyRule(response_policy.responsePolicyName, \
                                                  response_policy_rule.ruleName,\
                                                  api_version)

        if not args.IsSpecified('local_data') and not args.IsSpecified(
                'behavior'):
            log.status.Print('Nothing to update.')
            return to_update

        if args.IsSpecified('local_data'):
            to_update.behavior = None
            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)
            to_update.localData = messages.ResponsePolicyRuleLocalData(
                localDatas=rrsets)

        if args.IsSpecified('behavior'):
            to_update.localData = None
            to_update.behavior = command_util\
                .ParseResponsePolicyRulesBehavior(args, api_version)

        update_req = messages.DnsResponsePolicyRulesUpdateRequest(
            responsePolicy=response_policy.responsePolicyName,
            responsePolicyRule=response_policy_rule.ruleName,
            responsePolicyRuleResource=to_update,
            project=properties.VALUES.core.project.Get())

        updated_response_policy_rule = client.responsePolicyRules.Update(
            update_req)

        log.UpdatedResource(updated_response_policy_rule.responsePolicyRule,
                            kind='ResponsePolicyRule')

        return updated_response_policy_rule
Example #15
0
    def Run(self, args):
        api_version = util.GetApiFromTrack(self.ReleaseTrack())
        dns_client = util.GetApiClient(api_version)

        project_id = properties.VALUES.core.project.GetOrFail()

        return list_pager.YieldFromList(
            dns_client.managedZones,
            dns_client.MESSAGES_MODULE.DnsManagedZonesListRequest(
                project=project_id),
            field='managedZones')
Example #16
0
    def Run(self, args):
        api_version = util.GetApiFromTrack(self.ReleaseTrack())
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Policy
        policy_ref = args.CONCEPTS.policy.Parse()
        policy_name = policy_ref.Name()

        policy = messages.Policy(name=policy_name,
                                 enableLogging=False,
                                 enableInboundForwarding=False)

        if args.IsSpecified('networks'):
            if args.networks == ['']:
                args.networks = []
            policy.networks = command_util.ParsePolicyNetworks(
                args.networks, policy_ref.project, api_version)
        else:
            raise exceptions.RequiredArgumentException('--networks', ("""
           A list of networks must be
           provided.'
         NOTE: You can provide an empty value ("") for policies that
          have NO network binding.
          """))

        if args.IsSpecified('alternative_name_servers') or args.IsSpecified(
                'private_alternative_name_servers'):
            if args.alternative_name_servers == ['']:
                args.alternative_name_servers = []
            if args.private_alternative_name_servers == ['']:
                args.private_alternative_name_servers = []
            policy.alternativeNameServerConfig = command_util.ParseAltNameServers(
                version=api_version,
                server_list=args.alternative_name_servers,
                private_server_list=args.private_alternative_name_servers)

        if args.IsSpecified('enable_inbound_forwarding'):
            policy.enableInboundForwarding = args.enable_inbound_forwarding

        if args.IsSpecified('enable_logging'):
            policy.enableLogging = args.enable_logging

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

        create_request = messages.DnsPoliciesCreateRequest(
            policy=policy, project=policy_ref.project)

        result = client.policies.Create(create_request)

        log.CreatedResource(policy_ref, kind='Policy')

        return result
  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 #18
0
    def Run(self, args):
        api_version = util.GetApiFromTrack(self.ReleaseTrack())
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Policy
        policy_ref = args.CONCEPTS.policy.Parse()
        to_update = self._FetchPolicy(policy_ref, api_version)

        if not (args.IsSpecified('networks') or args.IsSpecified('description')
                or args.IsSpecified('enable_inbound_forwarding')
                or args.IsSpecified('enable_logging')
                or args.IsSpecified('alternative_name_servers')):
            log.status.Print('Nothing to update.')
            return to_update

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

        if args.IsSpecified('alternative_name_servers') or args.IsSpecified(
                'private_alternative_name_servers'):
            if args.alternative_name_servers == ['']:
                args.alternative_name_servers = []
            if args.private_alternative_name_servers == ['']:
                args.private_alternative_name_servers = []
            to_update.alternativeNameServerConfig = command_util.ParseAltNameServers(
                version=api_version,
                server_list=args.alternative_name_servers,
                private_server_list=args.private_alternative_name_servers)

        if args.IsSpecified('enable_inbound_forwarding'):
            to_update.enableInboundForwarding = args.enable_inbound_forwarding

        if args.IsSpecified('enable_logging'):
            to_update.enableLogging = args.enable_logging

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

        update_req = messages.DnsPoliciesUpdateRequest(
            policy=to_update.name,
            policyResource=to_update,
            project=policy_ref.project)

        updated_policy = client.policies.Update(update_req).policy

        log.UpdatedResource(updated_policy.name, kind='Policy')

        return updated_policy
  def Run(self, args):
    api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
    client = util.GetApiClient(api_version)
    messages = apis.GetMessagesModule('dns', api_version)

    request = messages.DnsResponsePoliciesListRequest(
        project=properties.VALUES.core.project.GetOrFail())

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

    return list_pager.YieldFromList(
        client.responsePolicies, request, field='responsePolicies')
    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 #21
0
  def Run(self, args):
    api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
    dns_client = util.GetApiClient(api_version)

    project_id = properties.VALUES.core.project.GetOrFail()

    request = dns_client.MESSAGES_MODULE.DnsManagedZonesListRequest(
        project=project_id)
    # For a request with location, use v2 api.
    if api_version == 'v2':
      request.location = args.location

    return list_pager.YieldFromList(
        dns_client.managedZones, request, field='managedZones')
Example #22
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 #23
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 #24
0
    def Run(self, args):
        dns = util.GetApiClient('v1')
        messages = apis.GetMessagesModule('dns', 'v1')

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

        result = dns.managedZones.Delete(
            messages.DnsManagedZonesDeleteRequest(
                managedZone=zone_ref.managedZone, project=zone_ref.project))
        log.DeletedResource(zone_ref)
        return result
  def Run(self, args):
    api_version = util.GetApiFromTrack(self.ReleaseTrack())
    dns_client = util.GetApiClient(api_version)
    messages = apis.GetMessagesModule('dns', api_version)
    zone_ref = args.CONCEPTS.zone.Parse()
    resource_name = 'projects/{0}/managedZones/{1}'.format(
        zone_ref.project, zone_ref.managedZone)

    req = messages.DnsProjectsManagedZonesGetIamPolicyRequest(
        resource=resource_name,
        googleIamV1GetIamPolicyRequest=messages.GoogleIamV1GetIamPolicyRequest(
            options=messages.GoogleIamV1GetPolicyOptions(
                requestedPolicyVersion=iam_util
                .MAX_LIBRARY_IAM_SUPPORTED_VERSION)))

    return dns_client.projects_managedZones.GetIamPolicy(req)
Example #26
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
Example #27
0
    def Run(self, args):
        api_version = util.GetApiFromTrack(self.ReleaseTrack())
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Response Policy Rule
        response_policy_rule_ref = args.CONCEPTS.response_policy_rule.Parse()
        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
        response_policy = messages.ResponsePolicy(
            responsePolicyName=args.response_policy)

        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=response_policy.responsePolicyName,
            project=response_policy_rule_ref.project,
            responsePolicyRule=response_policy_rule)

        result = client.responsePolicyRules.Create(create_request)

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

        return result
    def Run(self, args):
        api_version = util.GetApiFromTrack(self.ReleaseTrack())
        dns_client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)
        zone_ref = args.CONCEPTS.zone.Parse()
        resource_name = 'projects/{0}/managedZones/{1}'.format(
            zone_ref.project, zone_ref.managedZone)
        policy, update_mask = iam_util.ParsePolicyFileWithUpdateMask(
            args.policy_file, messages.GoogleIamV1Policy)

        req = messages.DnsProjectsManagedZonesSetIamPolicyRequest(
            resource=resource_name,
            googleIamV1SetIamPolicyRequest=messages.
            GoogleIamV1SetIamPolicyRequest(policy=policy,
                                           updateMask=update_mask))

        return dns_client.projects_managedZones.SetIamPolicy(req)
Example #29
0
    def Run(self, args):
        dns = util.GetApiClient('v1alpha2')
        messages = apis.GetMessagesModule('dns', 'v1alpha2')

        project_id = args.project if args.project is not None \
            else properties.VALUES.core.project.GetOrFail()
        network_url = args.target_network

        ids_response = dns.activePeeringZones.List(
            messages.DnsActivePeeringZonesListRequest(
                project=project_id, targetNetwork=network_url))

        zone_list = []
        for zone_id in ids_response.peeringZones:
            zone_list.append(
                dns.activePeeringZones.GetPeeringZoneInfo(
                    messages.DnsActivePeeringZonesGetPeeringZoneInfoRequest(
                        project=project_id, peeringZoneId=zone_id.id)))
        return zone_list
  def Run(self, args):
    api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
    dns = util.GetApiClient(api_version)
    registry = util.GetRegistry(api_version)

    zone_ref = registry.Parse(
        args.dns_zone,
        util.GetParamsForRegistry(api_version, args),
        collection='dns.managedZones')
    request = dns.MESSAGES_MODULE.DnsManagedZonesDeleteRequest(
        managedZone=zone_ref.managedZone, project=zone_ref.project)

    if api_version == 'v2':
      # For a request with location, use v2 api.
      request.location = args.location

    result = dns.managedZones.Delete(request)
    log.DeletedResource(zone_ref)
    return result