예제 #1
0
def GetExistingSnapshot(resource_ref, unused_args, patch_request):
  """Fetch existing redis instance to update and add it to Patch request."""
  api_version = resource_ref.GetCollectionInfo().api_version
  client = filestore_client.FilestoreClient(api_version)
  orig_snapshot = client.GetSnapshot(resource_ref)
  patch_request.snapshot = orig_snapshot
  return patch_request
 def Run(self, args):
     """Create a Filestore instance in the current project."""
     instance_ref = args.CONCEPTS.instance.Parse()
     client = filestore_client.FilestoreClient(self._API_VERSION)
     tier = instances_flags.GetTierArg(
         client.messages, self._API_VERSION).GetEnumForChoice(args.tier)
     labels = labels_util.ParseCreateArgs(
         args, client.messages.Instance.LabelsValue)
     try:
         nfs_export_options = client.MakeNFSExportOptionsMsg(
             messages=client.messages,
             nfs_export_options=args.file_share.get('nfs-export-options',
                                                    []))
     except KeyError as err:
         raise exceptions.InvalidArgumentException('--file-share',
                                                   six.text_type(err))
     instance = client.ParseFilestoreConfig(
         tier=tier,
         description=args.description,
         file_share=args.file_share,
         network=args.network,
         labels=labels,
         zone=instance_ref.locationsId,
         nfs_export_options=nfs_export_options,
         kms_key_name=instances_flags.GetAndValidateKmsKeyName(args))
     result = client.CreateInstance(instance_ref, args.async_, instance)
     if args.async_:
         command = properties.VALUES.metrics.command_name.Get().split('.')
         if command:
             command[-1] = 'list'
         log.status.Print(
             'Check the status of the new instance by listing all instances:\n  '
             '$ {} '.format(' '.join(command)))
     return result
예제 #3
0
    def Run(self, args):
        """Run command line arguments.

    Args:
      args: cmd line arguments.

    Raises:
       InvalidArgumentException: for invalid jason formatted --file-args.
       KeyError: for key errors in Jason values.
    Returns:
       client: client instance.
    """

        instance_ref = args.CONCEPTS.instance.Parse()
        client = filestore_client.FilestoreClient(self._API_VERSION)
        labels_diff = labels_util.Diff.FromUpdateArgs(args)
        orig_instance = client.GetInstance(instance_ref)
        try:
            if args.file_share:
                client.MakeNFSExportOptionsMsg(
                    messages=client.messages,
                    nfs_export_options=args.file_share.get(
                        'nfs-export-options', []))
        except KeyError as err:
            raise exceptions.InvalidArgumentException('--file-share',
                                                      six.text_type(err))
        if labels_diff.MayHaveUpdates():
            labels = labels_diff.Apply(client.messages.Instance.LabelsValue,
                                       orig_instance.labels).GetOrNone()
        else:
            labels = None
        try:
            instance = client.ParseUpdatedInstanceConfig(
                orig_instance,
                description=args.description,
                labels=labels,
                file_share=args.file_share)
        except filestore_client.Error as e:
            raise exceptions.InvalidArgumentException('--file-share',
                                                      six.text_type(e))

        updated_fields = []
        if args.IsSpecified('description'):
            updated_fields.append('description')
        if (args.IsSpecified('update_labels')
                or args.IsSpecified('remove_labels')
                or args.IsSpecified('clear_labels')):
            updated_fields.append('labels')
        if args.IsSpecified('file_share'):
            updated_fields.append('fileShares')
        update_mask = ','.join(updated_fields)

        result = client.UpdateInstance(instance_ref, instance, update_mask,
                                       args.async_)
        if args.async_:
            log.status.Print(
                'To check the status of the operation, run `gcloud {} filestore '
                'operations describe {}`'.format(self._API_VERSION,
                                                 result.name))
        return result
예제 #4
0
 def Run(self, args):
     """Create a Cloud Filestore instance in the current project."""
     instance_ref = args.CONCEPTS.instance.Parse()
     messages = filestore_util.GetMessages()
     tier = instances_flags.GetTierArg(messages).GetEnumForChoice(args.tier)
     labels = labels_util.ParseCreateArgs(args,
                                          messages.Instance.LabelsValue)
     instance = filestore_util.ParseFilestoreConfig(
         tier=tier,
         description=args.description,
         file_share=args.file_share,
         network=args.network,
         labels=labels)
     client = filestore_client.FilestoreClient()
     try:
         client.ValidateFileshares(instance)
     except filestore_client.InvalidCapacityError as e:
         raise exceptions.InvalidArgumentException('--file-share',
                                                   six.text_type(e))
     result = client.CreateInstance(instance_ref, args. async, instance)
     if args. async:
         log.status.Print(
             '\nCheck the status of the new instance by listing all instances:\n  '
             '$ gcloud alpha filestore instances list')
     return result
예제 #5
0
 def Run(self, args):
   """Create a Cloud Filestore instance in the current project."""
   instance_ref = args.CONCEPTS.instance.Parse()
   client = filestore_client.FilestoreClient(self._API_VERSION)
   tier = instances_flags.GetTierArg(
       client.messages).GetEnumForChoice(args.tier)
   labels = labels_util.ParseCreateArgs(args,
                                        client.messages.Instance.LabelsValue)
   instance = client.ParseFilestoreConfig(
       tier=tier, description=args.description,
       file_share=args.file_share, network=args.network,
       labels=labels, zone=instance_ref.locationsId)
   try:
     client.ValidateFileShares(instance)
   except filestore_client.InvalidCapacityError as e:
     raise exceptions.InvalidArgumentException('--file-share',
                                               six.text_type(e))
   result = client.CreateInstance(instance_ref, args.async, instance)
   if args.async:
     command = properties.VALUES.metrics.command_name.Get().split('.')
     if command:
       command[-1] = 'list'
     log.status.Print(
         'Check the status of the new instance by listing all instances:\n  '
         '$ {} '.format(' '.join(command)))
   return result
예제 #6
0
def FormatSnapshotUpdateResponse(response, args):
    """Python hook to generate the snapshot update response."""
    del response
    # Return snapshot describe output.
    resource_ref = GetResourceRef(args)
    api_version = resource_ref.GetCollectionInfo().api_version
    client = filestore_client.FilestoreClient(api_version)
    return encoding.MessageToDict(client.GetSnapshot(resource_ref))
예제 #7
0
def FormatSnapshotUpdateResponse(response, args):
  """Python hook to generate the backup update response."""
  del response
  # Return backup describe output.
  resource_ref = GetResourceRef(args)
  api_version = util.GetApiVersionFromArgs(args)
  client = filestore_client.FilestoreClient(api_version)
  return encoding.MessageToDict(client.GetInstanceSnapshot(resource_ref))
예제 #8
0
파일: list.py 프로젝트: Akiho-Yasuda/wip
 def Run(self, args):
     location_ref = args.CONCEPTS.zone.Parse().RelativeName()
     if args.zone is None and args.location is not None:
         location_list = location_ref.split('/')
         location_list[-1] = args.location
         location_ref = '/'.join(location_list)
     client = filestore_client.FilestoreClient(version=self._API_VERSION)
     return list(client.ListOperations(location_ref, limit=args.limit))
예제 #9
0
def GetExistingBackup(unused_resource_ref, args, patch_request):
    """Fetch existing Filestore instance to update and add it to Patch request."""
    resource_ref = GetResourceRef(args)
    api_version = util.GetApiVersionFromArgs(args)
    client = filestore_client.FilestoreClient(api_version)
    orig_backup = client.GetBackup(resource_ref)
    patch_request.backup = orig_backup
    return patch_request
예제 #10
0
def GetExistingSnapshot(ref, args, patch_request):
  """Fetch existing Filestore instance to update and add it to Patch request."""
  del ref
  resource_ref = GetResourceRef(args)
  api_version = util.GetApiVersionFromArgs(args)
  client = filestore_client.FilestoreClient(api_version)
  orig_snapshot = client.GetInstanceSnapshot(resource_ref)
  patch_request.snapshot = orig_snapshot
  return patch_request
예제 #11
0
    def Run(self, args):
        # Ensure that project is set before parsing location resource.
        properties.VALUES.core.project.GetOrFail()

        location_ref = args.CONCEPTS.zone.Parse().RelativeName()
        if args.zone is None and args.location is not None:
            location_list = location_ref.split('/')
            location_list[-1] = args.location
            location_ref = '/'.join(location_list)
        client = filestore_client.FilestoreClient(version=self._API_VERSION)
        return list(client.ListOperations(location_ref, limit=args.limit))
예제 #12
0
  def Run(self, args):
    """Make API calls to List Cloud Filestore operations.

    Args:
      args: gcloud command-line arguments.

    Returns:
      Generator that yields the Cloud Filestore operations.
    """
    location_ref = args.CONCEPTS.location.Parse()
    return filestore_client.FilestoreClient().ListOperations(
        location_ref, limit=args.limit)
예제 #13
0
    def Run(self, args):
        """Make API calls to List Cloud Filestore locations.

    Args:
      args: gcloud command-line arguments.

    Returns:
      Generator that yields the Cloud Filestore locations.
    """
        project_ref = resources.REGISTRY.Parse(
            properties.VALUES.core.project.GetOrFail(),
            collection='file.projects')
        client = filestore_client.FilestoreClient(version=self._API_VERSION)
        return list(client.ListLocations(project_ref, limit=args.limit))
예제 #14
0
 def Run(self, args):
     """Delete a Cloud Filestore instance."""
     instance_ref = args.CONCEPTS.instance.Parse()
     delete_warning = (
         'You are about to delete Cloud Filestore instance {}. '
         'Are you sure?'.format(instance_ref.RelativeName()))
     if not console_io.PromptContinue(message=delete_warning):
         return None
     client = filestore_client.FilestoreClient(version=self._API_VERSION)
     result = client.DeleteInstance(instance_ref, args. async)
     if args. async:
         log.status.Print(
             '\nCheck the status of the deletion by listing all instances:\n  '
             '$ gcloud alpha filestore instances list')
     return result
예제 #15
0
 def Run(self, args):
   """Run the list command."""
   # Ensure that project is set before parsing location resource.
   properties.VALUES.core.project.GetOrFail()
   location_ref = args.CONCEPTS.zone.Parse().RelativeName()
   # Fetch the location value from fallback options when args.zone is absent.
   # The fallback options will check args.region first, then args.location if
   # args.region also absent.
   if args.zone is None:
     location_list = location_ref.split('/')
     if args.region is not None:
       location_list[-1] = args.region
     elif args.location is not None:
       location_list[-1] = args.location
     location_ref = '/'.join(location_list)
   client = filestore_client.FilestoreClient(version=self._API_VERSION)
   return list(client.ListInstances(location_ref, limit=args.limit))
예제 #16
0
    def Run(self, args):
        """Update a Cloud Filestore instance in the current project."""
        instance_ref = args.CONCEPTS.instance.Parse()
        client = filestore_client.FilestoreClient(self._API_VERSION)
        labels_diff = labels_util.Diff.FromUpdateArgs(args)
        orig_instance = client.GetInstance(instance_ref)
        if labels_diff.MayHaveUpdates():
            labels = labels_diff.Apply(client.messages.Instance.LabelsValue,
                                       orig_instance.labels).GetOrNone()
        else:
            labels = None

        try:
            instance = client.ParseUpdatedInstanceConfig(
                orig_instance,
                description=args.description,
                labels=labels,
                file_share=args.file_share)
        except filestore_client.Error as e:
            raise exceptions.InvalidArgumentException('--file-share',
                                                      six.text_type(e))

        updated_fields = []
        if args.IsSpecified('description'):
            updated_fields.append('description')
        if (args.IsSpecified('update_labels')
                or args.IsSpecified('remove_labels')
                or args.IsSpecified('clear_labels')):
            updated_fields.append('labels')
        if args.IsSpecified('file_share'):
            updated_fields.append('fileShares')
        update_mask = ','.join(updated_fields)

        result = client.UpdateInstance(instance_ref, instance, update_mask,
                                       args.async_)
        if args.async_:
            if self._API_VERSION == 'V1':
                log.status.Print(
                    'To check the status of the operation, run `gcloud filestore '
                    'operations describe {}`'.format(result.name))
            else:
                log.status.Print(
                    'To check the status of the operation, run `gcloud beta filestore '
                    'operations describe {}`'.format(result.name))
        return result
예제 #17
0
파일: delete.py 프로젝트: iofh/QA-System
 def Run(self, args):
   """Delete a Cloud Filestore instance."""
   instance_ref = args.CONCEPTS.instance.Parse()
   delete_warning = ('You are about to delete Cloud Filestore instance {}.\n'
                     'Are you sure?'.format(instance_ref.RelativeName()))
   if not console_io.PromptContinue(message=delete_warning):
     return None
   client = filestore_client.FilestoreClient(version=self._API_VERSION)
   result = client.DeleteInstance(
       instance_ref, args.async_)
   if args.async_:
     command = properties.VALUES.metrics.command_name.Get().split('.')
     if command:
       command[-1] = 'list'
     log.status.Print(
         'Check the status of the deletion by listing all instances:\n  '
         '$ {} '.format(' '.join(command)))
   return result
예제 #18
0
 def Run(self, args):
   """Run the list command."""
   location_ref = args.CONCEPTS.location.Parse()
   client = filestore_client.FilestoreClient(version=self._API_VERSION)
   return list(client.ListInstances(location_ref, limit=args.limit))
예제 #19
0
 def Run(self, args):
   """Run the describe command."""
   instance_ref = args.CONCEPTS.instance.Parse()
   client = filestore_client.FilestoreClient(version=self._API_VERSION)
   return client.GetInstance(instance_ref)
예제 #20
0
 def Run(self, args):
   project_ref = resources.REGISTRY.Parse(
       properties.VALUES.core.project.GetOrFail(),
       collection='file.projects')
   client = filestore_client.FilestoreClient(version=self._API_VERSION)
   return list(client.ListLocations(project_ref, limit=args.limit))
예제 #21
0
 def Run(self, args):
   """Run the list command."""
   location_ref = args.CONCEPTS.location.Parse()
   return filestore_client.FilestoreClient().ListInstances(location_ref,
                                                           limit=args.limit)
예제 #22
0
 def Run(self, args):
     """Run the describe command."""
     operation_ref = args.CONCEPTS.operation.Parse()
     client = filestore_client.FilestoreClient(version=self._API_VERSION)
     return client.GetOperation(operation_ref)
예제 #23
0
 def Run(self, args):
     """Run the describe command."""
     instance_ref = args.CONCEPTS.instance.Parse()
     return filestore_client.FilestoreClient().GetInstance(instance_ref)
예제 #24
0
 def Run(self, args):
   """Run the describe command."""
   location_ref = args.CONCEPTS.location.Parse()
   return filestore_client.FilestoreClient().GetLocation(location_ref)
예제 #25
0
 def Run(self, args):
   location_ref = args.CONCEPTS.location.Parse()
   client = filestore_client.FilestoreClient(version=self._API_VERSION)
   return list(client.ListOperations(location_ref, limit=args.limit))
예제 #26
0
 def Run(self, args):
     """Run the describe command."""
     location_ref = args.CONCEPTS.zone.Parse().RelativeName()
     client = filestore_client.FilestoreClient(version=self._API_VERSION)
     return client.GetLocation(location_ref)