Ejemplo n.º 1
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
Ejemplo n.º 2
0
def _Update(zones_client,
            args,
            private_visibility_config=None,
            forwarding_config=None,
            peering_config=None):
    """Helper function to perform the update."""
    zone_ref = args.CONCEPTS.zone.Parse()

    dnssec_config = command_util.ParseDnssecConfigArgs(args,
                                                       zones_client.messages)
    labels_update = labels_util.ProcessUpdateArgsLazy(
        args, zones_client.messages.ManagedZone.LabelsValue,
        lambda: zones_client.Get(zone_ref).labels)

    kwargs = {}
    if private_visibility_config:
        kwargs['private_visibility_config'] = private_visibility_config
    if forwarding_config:
        kwargs['forwarding_config'] = forwarding_config
    if peering_config:
        kwargs['peering_config'] = peering_config
    return zones_client.Patch(zone_ref,
                              dnssec_config=dnssec_config,
                              description=args.description,
                              labels=labels_update.GetOrNone(),
                              **kwargs)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def _Update(zones_client, args):
    zone_ref = args.CONCEPTS.zone.Parse()

    dnssec_config = command_util.ParseDnssecConfigArgs(args,
                                                       zones_client.messages)
    labels_update = labels_util.ProcessUpdateArgsLazy(
        args, zones_client.messages.ManagedZone.LabelsValue,
        lambda: zones_client.Get(zone_ref).labels)

    return zones_client.Patch(zone_ref,
                              dnssec_config=dnssec_config,
                              description=args.description,
                              labels=labels_update.GetOrNone())
Ejemplo n.º 5
0
def _MakeDnssecConfig(args, messages):
  """Parse user-specified args into a DnssecConfig message."""
  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".')
  return dnssec_config
  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)

    result = dns.managedZones.Patch(
        messages.DnsManagedZonesPatchRequest(managedZoneResource=zone,
                                             project=zone_ref.project,
                                             managedZone=args.dns_zone))
    return result
def _Update(zones_client,
            args,
            private_visibility_config=None,
            forwarding_config=None,
            peering_config=None,
            reverse_lookup_config=None,
            cloud_logging_config=None,
            api_version='v1',
            cleared_fields=None):
    """Helper function to perform the update.

  Args:
    zones_client: the managed zones API client.
    args: the args provided by the user on the command line.
    private_visibility_config: zone visibility config.
    forwarding_config: zone forwarding config.
    peering_config: zone peering config.
    reverse_lookup_config: zone reverse lookup config.
    cloud_logging_config: Stackdriver logging config.
    api_version: the API version of this request.
    cleared_fields: the fields that should be included in the request JSON as
      their default value (fields that are their default value will be omitted
      otherwise).

  Returns:
    The update labels and PATCH call response.
  """
    registry = util.GetRegistry(api_version)

    zone_ref = registry.Parse(args.zone,
                              util.GetParamsForRegistry(api_version, args),
                              collection='dns.managedZones')

    dnssec_config = command_util.ParseDnssecConfigArgs(args,
                                                       zones_client.messages,
                                                       api_version)
    labels_update = labels_util.ProcessUpdateArgsLazy(
        args, zones_client.messages.ManagedZone.LabelsValue,
        lambda: zones_client.Get(zone_ref).labels)

    update_results = []

    if labels_update.GetOrNone():
        update_results.append(
            zones_client.UpdateLabels(zone_ref, labels_update.GetOrNone()))

    kwargs = {}
    if private_visibility_config:
        kwargs['private_visibility_config'] = private_visibility_config
    if forwarding_config:
        kwargs['forwarding_config'] = forwarding_config
    if peering_config:
        kwargs['peering_config'] = peering_config
    if reverse_lookup_config:
        kwargs['reverse_lookup_config'] = reverse_lookup_config
    if cloud_logging_config:
        kwargs['cloud_logging_config'] = cloud_logging_config

    if dnssec_config or args.description or kwargs:
        update_results.append(
            zones_client.Patch(zone_ref,
                               args.async_,
                               dnssec_config=dnssec_config,
                               description=args.description,
                               labels=None,
                               cleared_fields=cleared_fields,
                               **kwargs))

    return update_results