Beispiel #1
0
    def Run(self, args):
        """Run 'dns resource-record-sets list'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      A list of records for this zone.
    """
        dns = self.context['dns']
        project = properties.VALUES.core.project.Get(required=True)

        request = dns.resourceRecordSets().list(project=project,
                                                managedZone=args.zone,
                                                name=args.name,
                                                type=args.type)

        try:
            result_list = []
            result = request.execute()
            result_list.extend(result['rrsets'])
            while 'nextPageToken' in result and result[
                    'nextPageToken'] is not None:
                request = dns.resourceRecordSets().list(
                    project=project,
                    managedZone=args.zone,
                    pageToken=result['nextPageToken'])
                result = request.execute()
                result_list.extend(result['rrsets'])
            return result_list
        except errors.HttpError as error:
            raise exceptions.HttpException(util.GetError(error))
        except errors.Error as error:
            raise exceptions.ToolException(error)
Beispiel #2
0
  def Run(self, args):
    """Run 'dns managed-zone delete'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      A dict object representing the changes resource obtained by the delete
      operation if the delete was successful.
    """
    project = properties.VALUES.core.project.Get(required=True)
    really = console_io.PromptContinue(
        'Deleting %s in %s' % (args.zone, project))
    if not really:
      return

    dns = self.context['dns']
    if args.delete_zone_contents:
      self.DeleteZoneContents_(dns, project, args.zone)

    request = dns.managedZones().delete(project=project, managedZone=args.zone)
    try:
      result = request.execute()
      return result
    except errors.HttpError as error:
      raise exceptions.HttpException(util.GetError(error, verbose=True))
    except errors.Error as error:
      raise exceptions.ToolException(error)
Beispiel #3
0
    def Run(self, args):
        """Run 'dns changes get'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      A dict object representing the changes resource obtained by the get
      operation if the get was successful.
    Raises:
      HttpException: A http error response was received while executing api
          request.
      ToolException: An error other than http error occured while executing the
          command.
    """
        dns = self.context['dns']
        project = properties.VALUES.core.project.Get(required=True)
        request = dns.changes().get(project=project,
                                    managedZone=args.zone,
                                    changeId=args.change)
        try:
            result = request.execute()
            return result
        except errors.HttpError as error:
            raise exceptions.HttpException(util.GetError(error))
        except errors.Error as error:
            raise exceptions.ToolException(error)
Beispiel #4
0
  def Run(self, args):
    """Run 'dns managed-zone create'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.
    Returns:
      A dict object representing the changes resource obtained by the create
      operation if the create was successful.
    """
    project = properties.VALUES.core.project.Get(required=True)
    zone = {}
    zone['dnsName'] = args.dns_name
    zone['name'] = args.zone
    zone['description'] = args.description

    really = console_io.PromptContinue('Creating %s in %s' % (zone, project))
    if not really:
      return

    dns = self.context['dns']
    request = dns.managedZones().create(project=project, body=zone)
    try:
      result = request.execute()
      return result
    except errors.HttpError as error:
      raise exceptions.HttpException(util.GetError(error))
    except errors.Error as error:
      raise exceptions.ToolException(error)
Beispiel #5
0
  def Run(self, args):
    """Run 'dns changes list'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      A list object representing the changes resource(s) obtained by the list
      operation if the list was successful.
    Raises:
      HttpException: A http error response was received while executing api
          request.
      ToolException: An error other than http error occured while executing the
          command.
    """
    dns = self.context['dns']
    project = properties.VALUES.core.project.Get(required=True)
    sort_order = args.sort_order
    if sort_order is None:
      sort_order = 'descending'
    max_results = List.DEFAULT_MAX_RESULTS
    if args.max_results is not None:
      max_results = int(args.max_results)

    if max_results > 0:
      page_size = min(max_results, List.DEFAULT_PAGE_SIZE)
    else:
      page_size = List.DEFAULT_PAGE_SIZE

    request = dns.changes().list(project=project,
                                 managedZone=args.zone,
                                 maxResults=page_size,
                                 sortOrder=sort_order)
    try:
      result_list = []
      result = request.execute()
      result_list.extend(result['changes'])
      while ((max_results <= 0 or len(result_list) < max_results) and
             'nextPageToken' in result and
             result['nextPageToken'] is not None):
        if max_results > 0:
          page_size = min(
              max_results - len(result_list), List.DEFAULT_PAGE_SIZE)
        request = dns.changes().list(project=project,
                                     managedZone=args.zone,
                                     maxResults=page_size,
                                     pageToken=result['nextPageToken'],
                                     sortOrder=sort_order)
        result = request.execute()
        result_list.extend(result['changes'])
      return result_list
    except errors.HttpError as error:
      raise exceptions.HttpException(util.GetError(error))
    except errors.Error as error:
      raise exceptions.ToolException(error)
Beispiel #6
0
    def Run(self, args):
        """Run 'dns managed-zone list'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      A list of dict objects representing the zone resource obtained by the
      list operation if the list was successful.
    """
        dns = self.context['dns']
        project = properties.VALUES.core.project.Get(required=True)

        max_results = List.DEFAULT_MAX_RESULTS
        if args.max_results is not None:
            max_results = int(args.max_results)

        if max_results > 0:
            page_size = min(max_results, List.DEFAULT_PAGE_SIZE)
        else:
            page_size = List.DEFAULT_PAGE_SIZE

        request = dns.managedZones().list(project=project,
                                          maxResults=page_size)

        try:
            result_list = []
            result = request.execute()
            result_list.extend(result['managedZones'])
            while ((max_results <= 0 or len(result_list) < max_results)
                   and 'nextPageToken' in result
                   and result['nextPageToken'] is not None):
                if max_results > 0:
                    page_size = min(max_results - len(result_list),
                                    List.DEFAULT_PAGE_SIZE)
                request = dns.managedZones().list(
                    project=project,
                    maxResults=page_size,
                    pageToken=result['nextPageToken'])
                result = request.execute()
                result_list.extend(result['managedZones'])
            return result_list
        except errors.HttpError as error:
            raise exceptions.HttpException(util.GetError(error, verbose=True))
        except errors.Error as error:
            raise exceptions.ToolException(error)
Beispiel #7
0
    def Run(self, args):
        """Run 'dns project get'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      A dict object representing the project resource obtained by the get
      operation if the get was successful.
    """
        dns = self.context['dns']
        project = properties.VALUES.core.project.Get(required=True)
        request = dns.projects().get(project=project)
        try:
            result = request.execute()
            return result
        except errors.HttpError as error:
            raise exceptions.HttpException(util.GetError(error, verbose=True))
        except errors.Error as error:
            raise exceptions.ToolException(error)