feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The sub-group for the Filestore Instances."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Instances(base.Group):
"""Create and manage Filestore instances."""

View File

@@ -0,0 +1,353 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Creates a Filestore instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.filestore import filestore_client
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.filestore.instances import flags as instances_flags
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
import six
def _CommonArgs(parser, api_version=filestore_client.V1_API_VERSION):
instances_flags.AddInstanceCreateArgs(parser, api_version)
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a Filestore instance."""
_API_VERSION = filestore_client.V1_API_VERSION
detailed_help = {
'DESCRIPTION': 'Create a Filestore instance.',
'EXAMPLES': """\
To create a Basic HDD instance named `my-instance` in zone `us-central1-c` with a 1TB volume named `my_vol` on the default network, run:
$ {command} my-instance --zone=us-central1-c --tier=BASIC_HDD --file-share=name=my_vol,capacity=1TB --network=name=default
To create an Enterprise instance named `my-ent-instance` in region `us-central1` with a 2TB volume named `my_vol` on network `my-network`, run:
$ {command} my-ent-instance --zone=us-central1 --tier=ENTERPRISE --file-share=name=my_vol,capacity=2TB --network=name=my-network
To create an instance with specific NFS export options, you can use a JSON configuration file with `--flags-file`. For example, create a file named `config.json` with the following content:
{
"--file-share":
{
"capacity": "1024",
"name": "my_vol",
"nfs-export-options": [
{
"access-mode": "READ_WRITE",
"ip-ranges": [
"10.0.0.0/8"
],
"squash-mode": "NO_ROOT_SQUASH"
},
{
"access-mode": "READ_ONLY",
"ip-ranges": [
"192.168.0.0/24"
],
"squash-mode": "ROOT_SQUASH",
"anon_uid": 1003,
"anon_gid": 1003
}
]
}
}
To create a Basic SSD instance named `my-nfs-instance` using the above configuration file, run:
$ {command} my-nfs-instance --zone=us-central1-c --tier=BASIC_SSD --network=name=default --flags-file=config.json
""",
}
@staticmethod
def Args(parser):
_CommonArgs(parser, Create._API_VERSION)
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).GetEnumForChoice(
args.tier
)
protocol = None
if args.protocol is not None:
protocol = instances_flags.GetProtocolArg(
client.messages
).GetEnumForChoice(args.protocol)
ldap = args.ldap or None
labels = labels_util.ParseCreateArgs(args,
client.messages.Instance.LabelsValue)
tags = instances_flags.GetTagsFromArgs(args,
client.messages.Instance.TagsValue)
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,
protocol=protocol,
description=args.description,
file_share=args.file_share,
network=args.network,
performance=args.performance,
labels=labels,
tags=tags,
zone=instance_ref.locationsId,
nfs_export_options=nfs_export_options,
kms_key_name=instances_flags.GetAndValidateKmsKeyName(args),
ldap=ldap,
source_instance=args.source_instance,
deletion_protection_enabled=args.deletion_protection,
deletion_protection_reason=args.deletion_protection_reason)
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
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(Create):
"""Create a Filestore instance."""
_API_VERSION = filestore_client.BETA_API_VERSION
detailed_help = {
'DESCRIPTION': 'Create a Filestore instance.',
'EXAMPLES': """\
To create a Basic HDD instance named `my-instance` in zone `us-central1-c` with a 1TB volume named `my_vol` on the default network, run:
$ {command} my-instance --zone=us-central1-c --tier=BASIC_HDD --file-share=name=my_vol,capacity=1TB --network=name=default
To create an Enterprise instance named `my-ent-instance` in region `us-central1` with a 2TB volume named `my_vol` on network `my-network`, run:
$ {command} my-ent-instance --zone=us-central1 --tier=ENTERPRISE --file-share=name=my_vol,capacity=2TB --network=name=my-network
To create an instance with specific NFS export options, you can use a JSON configuration file with `--flags-file`. For example, create a file named `config.json` with the following content:
{
"--file-share":
{
"capacity": "1024",
"name": "my_vol",
"nfs-export-options": [
{
"access-mode": "READ_WRITE",
"ip-ranges": [
"10.0.0.0/8"
],
"squash-mode": "NO_ROOT_SQUASH"
},
{
"access-mode": "READ_ONLY",
"ip-ranges": [
"192.168.0.0/24"
],
"squash-mode": "ROOT_SQUASH",
"anon_uid": 1003,
"anon_gid": 1003
}
]
}
}
To create a Basic SSD instance named `my-nfs-instance` using the above configuration file, run:
$ {command} my-nfs-instance --zone=us-central1-c --tier=BASIC_SSD --network=name=default --flags-file=config.json
""",
}
@staticmethod
def Args(parser):
_CommonArgs(parser, CreateBeta._API_VERSION)
def Run(self, args):
"""Creates a Filestore instance in the current project.
Note: This is a copied code from Run() of base.ReleaseTrack.GA.
Args:
args: A list of fields.
Returns:
A filestore instance.
"""
instance_ref = args.CONCEPTS.instance.Parse()
client = filestore_client.FilestoreClient(self._API_VERSION)
tier = instances_flags.GetTierArg(client.messages).GetEnumForChoice(
args.tier
)
protocol = None
if args.protocol is not None:
protocol = instances_flags.GetProtocolArg(
client.messages
).GetEnumForChoice(args.protocol)
backend_type = None
if args.backend_type is not None:
backend_type = instances_flags.GetBackendTypeArg(
client.messages
).GetEnumForChoice(args.backend_type)
managed_ad = args.managed_ad or None
ldap = args.ldap or None
source_instance = args.source_instance or None
labels = labels_util.ParseCreateArgs(
args, client.messages.Instance.LabelsValue)
tags = instances_flags.GetTagsFromArgs(args,
client.messages.Instance.TagsValue)
try:
nfs_export_options = client.MakeNFSExportOptionsMsgBeta(
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,
protocol=protocol,
description=args.description,
file_share=args.file_share,
network=args.network,
performance=args.performance,
labels=labels,
tags=tags,
zone=instance_ref.locationsId,
nfs_export_options=nfs_export_options,
kms_key_name=instances_flags.GetAndValidateKmsKeyName(args),
managed_ad=managed_ad,
ldap=ldap,
source_instance=source_instance,
deletion_protection_enabled=args.deletion_protection,
deletion_protection_reason=args.deletion_protection_reason,
backend_type=backend_type,
)
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
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(Create):
"""Create a Filestore instance."""
_API_VERSION = filestore_client.ALPHA_API_VERSION
detailed_help = {
'DESCRIPTION':
'Create a Filestore instance.',
'EXAMPLES':
"""\
The following command creates a Filestore instance named NAME with a single volume.
$ {command} NAME \
--description=DESCRIPTION --tier=TIER \
--file-share=name=VOLUME_NAME,capacity=CAPACITY \
--network=name=NETWORK_NAME,reserved-ip-range=RESERVED_IP_RANGE,connect-mode=CONNECT_MODE \
--zone=ZONE \
--flags-file=FLAGS_FILE
Example json configuration file:
{
"--file-share":
{
"capacity": "61440",
"name": "my_vol",
"nfs-export-options": [
{
"access-mode": "READ_WRITE",
"ip-ranges": [
"10.0.0.0/8",
],
"squash-mode": "NO_ROOT_SQUASH",
},
{
"access-mode": "READ_ONLY",
"ip-ranges": [
"192.168.0.0/24"
],
"squash-mode": "ROOT_SQUASH"
"anon_uid": 1003,
"anon_gid": 1003
}
],
}
}
"""
}
@staticmethod
def Args(parser):
_CommonArgs(parser, CreateAlpha._API_VERSION)
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).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)
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

View File

@@ -0,0 +1,145 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Deletes a Filestore instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.filestore import filestore_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.filestore import flags
from googlecloudsdk.command_lib.filestore.instances import flags as instances_flags
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.console import console_io
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Delete a Filestore instance."""
_API_VERSION = filestore_client.V1_API_VERSION
@staticmethod
def Args(parser):
concept_parsers.ConceptParser([flags.GetInstancePresentationSpec(
'The instance to delete.')]).AddToParser(parser)
instances_flags.AddLocationArg(parser)
instances_flags.AddRegionArg(parser)
instances_flags.AddAsyncFlag(parser)
instances_flags.AddForceArg(parser)
def Run(self, args):
"""Deletes a Filestore instance."""
instance_ref = args.CONCEPTS.instance.Parse()
delete_warning = ('You are about to delete 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_, args.force)
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
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class DeleteBeta(Delete):
"""Delete a Filestore instance."""
_API_VERSION = filestore_client.BETA_API_VERSION
def Run(self, args):
"""Deletes a Filestore instance."""
instance_ref = args.CONCEPTS.instance.Parse()
delete_warning = ('You are about to delete 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_, args.force)
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
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class DeleteAlpha(base.DeleteCommand):
"""Delete a Filestore instance."""
_API_VERSION = filestore_client.ALPHA_API_VERSION
@staticmethod
def Args(parser):
concept_parsers.ConceptParser([
flags.GetInstancePresentationSpec('The instance to delete.')
]).AddToParser(parser)
instances_flags.AddLocationArg(parser)
instances_flags.AddRegionArg(parser)
instances_flags.AddAsyncFlag(parser)
def Run(self, args):
"""Delete a Filestore instance."""
instance_ref = args.CONCEPTS.instance.Parse()
delete_warning = ('You are about to delete 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.DeleteInstanceAlpha(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
help_ = {
'DESCRIPTION':
'Delete a Filestore instance.',
'EXAMPLES':
"""\
To delete a Filestore instance named NAME in us-central1-c:
$ {command} NAME --zone=us-central1-c
"""
}
Delete.detailed_help = help_
DeleteAlpha.detailed_help = help_

View File

@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to show metadata for a Filestore instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.filestore import filestore_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.filestore import flags
from googlecloudsdk.command_lib.filestore.instances import flags as instances_flags
from googlecloudsdk.command_lib.util.concepts import concept_parsers
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Show metadata for a Filestore instance."""
_API_VERSION = filestore_client.V1_API_VERSION
@staticmethod
def Args(parser):
concept_parsers.ConceptParser([flags.GetInstancePresentationSpec(
'The instance to describe.')]).AddToParser(parser)
instances_flags.AddLocationArg(parser)
instances_flags.AddRegionArg(parser)
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)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class DescribeBeta(Describe):
"""Show metadata for a Filestore instance."""
_API_VERSION = filestore_client.BETA_API_VERSION
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class DescribeAlpha(Describe):
"""Show metadata for a Filestore instance."""
_API_VERSION = filestore_client.ALPHA_API_VERSION
Describe.detailed_help = {
'DESCRIPTION':
'Show metadata for a Filestore instance.',
'EXAMPLES':
"""\
The following command shows the metadata for the Filestore instance named NAME
in us-central1-c.
$ {command} NAME --location=us-central1-c
"""
}

View File

@@ -0,0 +1,154 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for listing Filestore instances."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.filestore import filestore_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.filestore import flags
from googlecloudsdk.command_lib.filestore.instances import flags as instances_flags
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List Filestore instances."""
_API_VERSION = filestore_client.V1_API_VERSION
@staticmethod
def Args(parser):
concept_parsers.ConceptParser([flags.GetListingLocationPresentationSpec(
'The location in which to list instances.')]).AddToParser(parser)
instances_flags.AddLocationArg(parser)
instances_flags.AddRegionArg(parser)
parser.display_info.AddFormat(
instances_flags.INSTANCES_LIST_FORMAT_V1_ALPAH
)
def UriFunc(resource):
registry = filestore_client.GetFilestoreRegistry()
ref = registry.Parse(
resource.name, collection=filestore_client.INSTANCES_COLLECTION)
return ref.SelfLink()
parser.display_info.AddUriFunc(UriFunc)
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()
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.ListInstances(location_ref, limit=args.limit))
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class ListBeta(List):
"""List Filestore instances."""
_API_VERSION = filestore_client.BETA_API_VERSION
@staticmethod
def Args(parser):
concept_parsers.ConceptParser([
flags.GetListingLocationPresentationSpec(
'The location in which to list instances.')
]).AddToParser(parser)
instances_flags.AddLocationArg(parser)
instances_flags.AddRegionArg(parser)
parser.display_info.AddFormat(
instances_flags.INSTANCES_LIST_FORMAT_BETA
)
def UriFunc(resource):
registry = filestore_client.GetFilestoreRegistry(
filestore_client.BETA_API_VERSION)
ref = registry.Parse(
resource.name, collection=filestore_client.INSTANCES_COLLECTION)
return ref.SelfLink()
parser.display_info.AddUriFunc(UriFunc)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class ListAlpha(List):
"""List Filestore instances."""
_API_VERSION = filestore_client.ALPHA_API_VERSION
@staticmethod
def Args(parser):
concept_parsers.ConceptParser([flags.GetListingLocationPresentationSpec(
'The location in which to list instances.')]).AddToParser(parser)
instances_flags.AddLocationArg(parser)
instances_flags.AddRegionArg(parser)
parser.display_info.AddFormat(
instances_flags.INSTANCES_LIST_FORMAT_V1_ALPAH
)
def UriFunc(resource):
registry = resources.REGISTRY.Clone()
registry.RegisterApiByName(
filestore_client.API_NAME,
api_version=filestore_client.ALPHA_API_VERSION)
ref = registry.Parse(
resource.name, collection=filestore_client.INSTANCES_COLLECTION)
return ref.SelfLink()
parser.display_info.AddUriFunc(UriFunc)
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))
List.detailed_help = {
'DESCRIPTION':
'',
'EXAMPLES':
"""\
The following command lists a maximum of five Filestore instances sorted
alphabetically by name in descending order:
$ {command} --limit=5 --sort-by=~name
"""
}

View File

@@ -0,0 +1,44 @@
- release_tracks: [BETA, GA]
help_text:
brief: Pause a Filestore replica instance.
description: |
Pause a Filestore replica instance. This command can be called only on a standby instance.
After calling the command, the NFS file system of the standby instance becomes writeable. Any
data changed on the standby instance while it is paused will be lost when the replica is
resumed or promoted.
examples: |
To pause a replica instance with the name ``my-replica-instance'' located in ``us-central1-c'',
run:
$ {command} my-replica-instance --zone=us-central1
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.filestore.resources:instance
help_text: |
Arguments and flags that specify the Filestore instance to pause.
command_level_fallthroughs:
zone:
- arg_name: location
release_tracks: [BETA, GA]
params:
- arg_name: location
release_tracks: [BETA, GA]
help_text: |
Location of the Filestore instance to pause.
request:
BETA:
api_version: v1beta1
GA:
api_version: v1
collection: file.projects.locations.instances
method: pauseReplica
async:
collection: file.projects.locations.operations
input:
confirmation_prompt: |
Warning: You are about to pause a standby replica instance, this action makes the standby
instance's NFS filesystem writeable.

View File

@@ -0,0 +1,64 @@
- release_tracks: [BETA, GA]
help_text:
brief: Promote a Filestore standby replication instance.
description: |
Promote a Filestore standby replication instance to a regular instance. This command can be
called directly on the standby instance or on the active instance with the standby peer
instance parameter.
When used on the standby instance promotes the standby instance to a regular instance even if
the active instance is unavailable.
When used on the active instance detaches the standby instance from the active instance even
if the standby instance is unavailable.
This command can fail for the following reasons:
* The target instance does not exist.
* The instance is not a standby replication member.
* The instance is an active instance and the peer instance parameter is missing or invalid.
examples: |
To promote a standby instance with the name ``my-replica-instance'' located in
``us-central1'', run:
$ {command} my-replica-instance --zone=us-central1
To promote a standby instance with the name ``my-replica-instance'' located in
``us-central1'', attached to the active peer instance ``my-active-instance'' located in
``us-west1'', run:
$ {command} my-active-instance --zone=us-west1 \
--peer-instance=projects/my-project/locations/us-central1/instances/my-replica-instance
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.filestore.resources:instance
help_text: |
Arguments and flags that specify the Filestore instance to promote.
command_level_fallthroughs:
zone:
- arg_name: location
release_tracks: [BETA, GA]
params:
- arg_name: location
release_tracks: [BETA, GA]
help_text: |
Location of the Filestore instance to promote.
- arg_name: peer-instance
release_tracks: [BETA, GA]
api_field: promoteReplicaRequest.peerInstance
help_text: |
The name of the standby peer instance to promote.
request:
BETA:
api_version: v1beta1
GA:
api_version: v1
collection: file.projects.locations.instances
method: promoteReplica
async:
collection: file.projects.locations.operations
input:
confirmation_prompt: |
Warning: You are about to promote a replication standby instance, this action will
permanently remove replication settings and convert the standby into a regular instance.

View File

@@ -0,0 +1,140 @@
- release_tracks: [GA, BETA, ALPHA]
help_text:
ALPHA:
brief: |
Restore a Filestore instance from a snapshot or backup.
description: |
Restore an existing Filestore instance from an existing snapshot
or backup.
examples: |
The following command restores an instance named 'my-instance' with a
fileshare named 'vol1' in the zone europe-west3-a from a backup named
'my-backup' in the region europe-west3.
$ {command} my-instance \
--zone=europe-west3-a \
--file-share=vol1 \
--source-backup=my-backup \
--source-backup-region=europe-west3
BETA:
brief: |
Restore a Filestore instance from a backup.
description: |
Restore an existing Filestore instance from an existing backup.
examples: |
The following command restores an instance named 'my-instance' with a
fileshare named 'vol1' in the zone europe-west3-a from a backup named
'my-backup' in the region europe-west3.
$ {command} my-instance \
--zone=europe-west3-a \
--file-share=vol1 \
--source-backup=my-backup \
--source-backup-region=europe-west3
GA:
brief: |
Restore a Filestore instance from a backup.
description: |
Restore an existing Filestore instance from an existing backup.
examples: |
The following command restores an instance named 'my-instance' with a
fileshare named 'vol1' in the zone europe-west3-a from a backup named
'my-backup' in the region europe-west3.
$ {command} my-instance \
--zone=europe-west3-a \
--file-share=vol1 \
--source-backup=my-backup \
--source-backup-region=europe-west3
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.filestore.resources:instance
help_text: |
Arguments and flags that specify the Filestore instance to restore.
command_level_fallthroughs:
zone:
- arg_name: location
release_tracks: [BETA]
params:
- arg_name: file-share
required: true
api_field: restoreInstanceRequest.fileShare
ALPHA:
help_text:
File share to restore from the snapshot or backup.
BETA:
help_text:
File share to restore from the backup.
GA:
help_text:
File share to restore from the backup.
- arg_name: source-backup
release_tracks: [GA, BETA]
required: true
help_text: |
Name of the Filestore backup to restore from.
- arg_name: source-backup-region
release_tracks: [GA, BETA]
required: true
help_text: |
Region of the Filestore backup to restore from.
- arg_name: location
release_tracks: [BETA]
help_text: |
Location of the Filestore instance to restore this backup to.
- group:
release_tracks: [ALPHA]
required: true
ALPHA:
mutex: true
params:
- group:
help_text: |
The name and region of the Filestore snapshot to restore from.
params:
- arg_name: source-snapshot
required: true
help_text: |
Name of the Filestore snapshot to restore from.
- arg_name: source-snapshot-region
required: false
help_text: |
Region of the Filestore snapshot to restore from. If unspecified, it
is assumed that the Filestore snapshot is local.
- group:
help_text: |
The name and region of the Filestore backup to restore from.
params:
- arg_name: source-backup
required: true
help_text: |
Name of the Filestore backup to restore from.
- arg_name: source-backup-region
required: true
help_text: |
Region of the Filestore backup to restore from.
request:
ALPHA:
api_version: v1p1alpha1
modify_request_hooks:
- googlecloudsdk.command_lib.filestore.backups.util:AddBackupNameToRequest
- googlecloudsdk.command_lib.filestore.snapshots.util:AddSnapshotNameToRequest
BETA:
api_version: v1beta1
modify_request_hooks:
- googlecloudsdk.command_lib.filestore.backups.util:AddBackupNameToRequest
GA:
api_version: v1
modify_request_hooks:
- googlecloudsdk.command_lib.filestore.backups.util:AddBackupNameToRequest
collection: file.projects.locations.instances
method: restore
async:
collection: file.projects.locations.operations
input:
confirmation_prompt: |
You are about to override existing data in [{__name__}].

View File

@@ -0,0 +1,45 @@
- release_tracks: [BETA, GA]
help_text:
brief: Resume a Filestore replica instance.
description: |
Resume a Filestore replica instance. This command can be called only on a paused standby
instance.
Any data written to the standby instance while being paused will be lost when the replica is
resumed. The NFS file system of the standby instance becomes inaccessible and replication is
resumed.
examples: |
To resume a replica instance with the name ``my-replica-instance'' located in ``us-central1-c''
, run:
$ {command} my-replica-instance --zone=us-central1-c
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.filestore.resources:instance
help_text: |
Arguments and flags that specify the Filestore instance to resume.
command_level_fallthroughs:
zone:
- arg_name: location
release_tracks: [BETA, GA]
params:
- arg_name: location
release_tracks: [BETA, GA]
help_text: |
Location of the Filestore instance to resume.
request:
BETA:
api_version: v1beta1
GA:
api_version: v1
collection: file.projects.locations.instances
method: resumeReplica
async:
collection: file.projects.locations.operations
input:
confirmation_prompt: |
Warning: You are about to resume a standby replica instance, any data written to the
standby instance while paused will be lost.

View File

@@ -0,0 +1,42 @@
- release_tracks: [BETA, GA]
help_text:
brief: Revert a Filestore instance.
description: |
Revert a Filestore instance to the target snapshot.
This command can fail for the following reasons:
* The target snapshot does not exist.
* The active account does not have permission to revert the instance.
* The service tier of the instance does not support the operation.
examples: |
To revert an instance with the name ``my-instance'' that's located in
``us-central1'' to the target snapshot named ``my-snapshot'' , run:
$ {command} my-instance --target-snapshot=my-snapshot --location=us-central1
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.filestore.resources:instance_with_generic_location
help_text: |
Arguments and flags that specify the Filestore instance to revert.
params:
- arg_name: target-snapshot
required: true
api_field: revertInstanceRequest.targetSnapshotId
help_text: |
Name of the Filestore snapshot to revert to.
request:
BETA:
api_version: v1beta1
GA:
api_version: v1
collection: file.projects.locations.instances
method: revert
async:
collection: file.projects.locations.operations
input:
confirmation_prompt: |
You are about to override existing data in [{__name__}].

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The sub-group for the Filestore snapshots."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class Snapshots(base.Group):
"""Create and manage Filestore snapshots."""

View File

@@ -0,0 +1,71 @@
- release_tracks: [BETA, GA]
help_text:
brief: Create a Filestore snapshot.
description: |
Create a Filestore snapshot of an instance.
This command can fail for the following reasons:
* A snapshot with the same name already exists.
* The active account does not have permission to create snapshots.
* Maximum number of snapshots for the instance has been reached.
* The service tier of the instance does not support snapshots.
examples: |
To create a snapshot with the name ``my-snapshot'' for an instance named
``my-instance'' that's located in ``us-central1'', run:
$ {command} my-snapshot --instance=my-instance --instance-region=us-central1
arguments:
params:
- arg_name: snapshot
is_positional: true
required: true
help_text: |
Name of the Filestore snapshot to be created.
- arg_name: instance
required: true
help_text: |
Name of the Filestore instance that you want to create a snapshot of.
- group:
mutex: true
required: true
params:
- arg_name: instance-region
help_text: |
Region of the Filestore instance.
- arg_name: instance-location
help_text: |
Location of the Filestore instance.
- api_field: snapshot.description
arg_name: description
required: false
help_text: |
Description of the snapshot. Limit: 2048 characters.
- api_field: snapshot.labels.additionalProperties
arg_name: labels
metavar: KEY=VALUE
required: false
help_text: |
List of label KEY=VALUE pairs to add.
type:
arg_dict:
flatten: true
spec:
- api_field: key
- api_field: value
async:
collection: file.projects.locations.operations
request:
BETA:
api_version: v1beta1
GA:
api_version: v1
display_resource_type: snapshot
collection: file.projects.locations.instances.snapshots
# Disable validating that a snapshot resource arg is specified (as we are using the
# file.projects.locations.instances.snapshots collection). This collection is populated manually.
disable_resource_check: true
modify_request_hooks:
- googlecloudsdk.command_lib.filestore.instances.snapshots.util:FormatSnapshotCreateRequest

View File

@@ -0,0 +1,61 @@
- release_tracks: [BETA, GA]
help_text:
brief: |
Delete a Filestore snapshot.
description: |
Delete a Filestore snapshot.
This command can fail for the following reasons:
* The snapshot or instance specified does not exist.
* The active account does not have permission to delete the given
snapshot.
examples: |
To delete a snapshot named ``my-snapshot'' for the instance ``my-instance''
from ``us-central1'', run:
$ {command} my-snapshot --instance=my-instance --instance-region=us-central1
arguments:
params:
- arg_name: snapshot
required: true
is_positional: true
help_text: |
Name of the Filestore snapshot to be deleted.
- arg_name: instance
required: true
help_text: |
Name of the Filestore instance the snapshot belongs to.
- group:
mutex: true
required: true
params:
- arg_name: instance-region
help_text: |
Region of the Filestore instance.
- arg_name: instance-location
help_text: |
Location of the Filestore instance.
async:
collection: file.projects.locations.operations
request_issued_message: |-
Delete request issued
input:
confirmation_prompt: |
You are about to delete Filestore snapshot. Are you sure?
request:
BETA:
api_version: v1beta1
GA:
api_version: v1
display_resource_type: snapshot
collection: file.projects.locations.instances.snapshots
# Disable validating that a snapshot resource arg is specified (as we are using the
# file.projects.locations.instances.snapshots collection). This collection is populated manually.
disable_resource_check: true
modify_request_hooks:
- googlecloudsdk.command_lib.filestore.instances.snapshots.util:FormatSnapshotAccessRequest

View File

@@ -0,0 +1,50 @@
- release_tracks: [BETA, GA]
help_text:
brief: Display information about a Filestore snapshot.
description: |
Displays information about a Filestore snapshot given a valid snapshot
name, as well as instance name and instance region.
This command can fail for the following reasons:
* The snapshot or instance specified does not exist.
* The active account does not have permission to access the given
snapshot.
examples: |
To display all information associated with a snapshot of the name
``my-snapshot'' for the instance ``my-instance'' from ``us-central1'', run:
$ {command} my-snapshot --instance=my-instance --instance-region=us-central1
arguments:
params:
- arg_name: snapshot
required: true
is_positional: true
help_text: |
Name of the Filestore snapshot to display information about.
- arg_name: instance
required: true
help_text: |
Name of the Filestore instance the snapshot belongs to.
- group:
mutex: true
required: true
params:
- arg_name: instance-region
help_text: |
Region of the Filestore instance.
- arg_name: instance-location
help_text: |
Location of the Filestore instance.
request:
BETA:
api_version: v1beta1
GA:
api_version: v1
collection: file.projects.locations.instances.snapshots
# Disable validating that a snapshot resource arg is specified (as we are using the
# file.projects.locations.instances.snapshots collection). This collection is populated manually.
disable_resource_check: true
modify_request_hooks:
- googlecloudsdk.command_lib.filestore.instances.snapshots.util:FormatSnapshotAccessRequest

View File

@@ -0,0 +1,58 @@
- release_tracks: [BETA, GA]
help_text:
brief: |
List Filestore snapshots.
description: |
List all Filestore snapshots for the specified instance.
To limit the number of snapshots to list, use the `--limit` flag.
This command can fail for the following reasons:
* Specified instance does not exist.
* The active account does not have permission to list snapshots for the
given instance.
* The service tier of the instance does not support snapshots.
examples: |
To list up to five snapshots for the instance ``my-instance'' from
``us-central1'', run:
$ {command} --instance=my-instance --instance-region=us-central1 --limit=5
arguments:
params:
- arg_name: instance
required: true
help_text: |
Name of the Filestore instance the snapshot belongs to.
- group:
mutex: true
required: true
params:
- arg_name: instance-region
help_text: |
Region of the Filestore instance.
- arg_name: instance-location
help_text: |
Location of the Filestore instance.
request:
BETA:
api_version: v1beta1
GA:
api_version: v1
collection: file.projects.locations.instances.snapshots
# Disable validating that a snapshot resource arg is specified (as we are using the
# file.projects.locations.instances.snapshots collection). This collection is populated manually.
disable_resource_check: true
modify_request_hooks:
- googlecloudsdk.command_lib.filestore.instances.snapshots.util:FormatSnapshotsListRequest
response:
id_field: name
output:
format: |
table(
name.basename():label=NAME:sort=1,
state
)

View File

@@ -0,0 +1,63 @@
- release_tracks: [BETA, GA]
help_text:
brief: |
Update the description or labels of a Filestore snapshot.
description: |
Update the metadata of a Filestore snapshot.
This command can fail for the following reasons:
* The snapshot or instance specified does not exist.
* The active account does not have permission to update the given
snapshot.
examples: |
To update the description of a snapshot named ``my-snapshot'' for the
instance ``my-instance'' from ``us-central1'', run:
$ {command} my-snapshot --instance=my-instance --instance-region=us-central1 --description="A new description."
arguments:
params:
- arg_name: snapshot
is_positional: true
required: true
help_text: |
Name of the Filestore snapshot to be updated.
- arg_name: instance
required: true
help_text: |
Name of the Filestore instance the snapshot belongs to.
- group:
mutex: true
required: true
params:
- arg_name: instance-region
help_text: |
Region of the Filestore instance.
- arg_name: instance-location
help_text: |
Location of the Filestore instance.
- arg_name: description
api_field: snapshot.description
help_text: |
Description of the snapshot.
additional_arguments_hook: googlecloudsdk.command_lib.filestore.update_util:UpdateLabelsFlags
response:
modify_response_hooks:
- googlecloudsdk.command_lib.filestore.instances.snapshots.util:FormatSnapshotUpdateResponse
async:
collection: file.projects.locations.operations
request:
BETA:
api_version: v1beta1
GA:
api_version: v1
display_resource_type: snapshot
collection: file.projects.locations.instances.snapshots
modify_request_hooks:
- googlecloudsdk.command_lib.filestore.instances.snapshots.util:FormatSnapshotAccessRequest
- googlecloudsdk.command_lib.filestore.instances.snapshots.util:GetExistingSnapshot
- googlecloudsdk.command_lib.filestore.instances.snapshots.util:AddDescription
- googlecloudsdk.command_lib.filestore.instances.snapshots.util:UpdateLabels

View File

@@ -0,0 +1,475 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Update a Filestore instance."""
import textwrap
from googlecloudsdk.api_lib.filestore import filestore_client
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.filestore.instances import dp_util
from googlecloudsdk.command_lib.filestore.instances import flags as instances_flags
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
def _CommonArgs(parser, api_version=filestore_client.V1_API_VERSION):
instances_flags.AddInstanceUpdateArgs(parser, api_version)
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.CreateCommand):
"""Update a Filestore instance."""
_API_VERSION = filestore_client.V1_API_VERSION
detailed_help = {
'DESCRIPTION':
'Update a Filestore instance.',
'EXAMPLES':
textwrap.dedent("""\
The following command updates the Filestore instance NAME to change the
description to "A new description."
$ {command} NAME --description="A new description."
The following command updates a Filestore instance named NAME to add the label
"key1=value1" and remove any metadata with the label "key2".
$ {command} NAME --update-labels=key1=value1 --remove-labels=key2
$ {command} NAME --zone=ZONE --flags-file=FILE_PATH
Example json configuration file:
{
"--file-share":
{
"capacity": "102400",
"name": "my_vol",
"nfs-export-options": [
{
"access-mode": "READ_WRITE",
"ip-ranges": [
"10.0.0.0/29",
"10.2.0.0/29"
],
"squash-mode": "ROOT_SQUASH",
"anon_uid": 1003,
"anon_gid": 1003
}
]
}
}
The following command updates a Filestore instance named NAME to change the
capacity to CAPACITY.
$ {command} NAME --project=PROJECT_ID --zone=ZONE\
--file-share=name=VOLUME_NAME,capacity=CAPACITY
The following command updates a Filestore instance named NAME to configure the
max-iops-per-tb to MAX-IOPS-PER-TB.
$ {command} NAME --project=PROJECT_ID --zone=ZONE\
--performance=max-iops-per-tb=MAX-IOPS-PER-TB
"""),
}
@staticmethod
def Args(parser):
_CommonArgs(parser, Update._API_VERSION)
def Run(self, args):
"""Runs command line arguments.
Args:
args: Command line arguments.
Returns:
The client instance.
Raises:
InvalidArgumentException: For invalid JSON formatted --file-args.
"""
instance_ref = args.CONCEPTS.instance.Parse()
client = filestore_client.FilestoreClient(self._API_VERSION)
labels_diff = labels_util.Diff.FromUpdateArgs(args)
dp_util.ValidateDeletionProtectionUpdateArgs(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', str(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,
performance=args.performance,
ldap=args.ldap,
disconnect_ldap=args.disconnect_ldap,
clear_nfs_export_options=args.clear_nfs_export_options,
deletion_protection_enabled=args.deletion_protection,
deletion_protection_reason=args.deletion_protection_reason,
)
except filestore_client.InvalidDisconnectLdapError as e:
raise exceptions.InvalidArgumentException(
'--disconnect-ldap', str(e)
)
except filestore_client.InvalidDisconnectManagedADError as e:
raise exceptions.InvalidArgumentException(
'--disconnect-managed-ad', str(e)
)
except filestore_client.Error as e:
raise exceptions.InvalidArgumentException(
'--file-share', str(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')
if args.IsSpecified('performance'):
updated_fields.append('performanceConfig')
updated_fields += dp_util.GetDeletionProtectionUpdateMask(args)
if args.IsSpecified('ldap') or args.IsSpecified('disconnect_ldap'):
updated_fields.append('directoryServices')
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(result.name)
)
return result
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(Update):
"""Update a Filestore instance."""
_API_VERSION = filestore_client.ALPHA_API_VERSION
detailed_help = {
'DESCRIPTION':
'Update a Filestore instance.',
'EXAMPLES':
textwrap.dedent("""\
The following command updates the Filestore instance NAME to change the
description to "A new description."
$ {command} NAME --description="A new description."
The following command updates a Filestore instance named NAME to add the label
"key1=value1" and remove any metadata with the label "key2".
$ {command} NAME --update-labels=key1=value1 --remove-labels=key2
$ {command} NAME --zone=ZONE --flags-file=FILE_PATH
Example json configuration file:
{
"--file-share":
{
"capacity": "102400",
"name": "my_vol",
"nfs-export-options": [
{
"access-mode": "READ_WRITE",
"ip-ranges": [
"10.0.0.0/29",
"10.2.0.0/29"
],
"squash-mode": "ROOT_SQUASH",
"anon_uid": 1003,
"anon_gid": 1003
}
]
}
}
The following command updates a Filestore instance named NAME to change the
capacity to CAPACITY.
$ {command} NAME --project=PROJECT_ID --zone=ZONE\
--file-share=name=VOLUME_NAME,capacity=CAPACITY
"""),
}
@staticmethod
def Args(parser):
_CommonArgs(parser, UpdateAlpha._API_VERSION)
def Run(self, args):
"""Runs command line arguments.
Args:
args: Command line arguments.
Returns:
The client instance.
Raises:
InvalidArgumentException: For invalid JSON formatted --file-args.
"""
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', str(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,
clear_nfs_export_options=args.clear_nfs_export_options,
)
except filestore_client.Error as e:
raise exceptions.InvalidArgumentException(
'--file-share', str(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 alpha filestore '
'operations describe {}`'.format(result.name)
)
return result
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class UpdateBeta(Update):
"""Update a Filestore instance."""
_API_VERSION = filestore_client.BETA_API_VERSION
detailed_help = {
'DESCRIPTION':
'Update a Filestore instance.',
'EXAMPLES':
textwrap.dedent("""\
The following command updates the Filestore instance NAME to change the
description to "A new description."
$ {command} NAME --description="A new description."
The following command updates a Filestore instance named NAME to add the label
"key1=value1" and remove any metadata with the label "key2".
$ {command} NAME --update-labels=key1=value1 --remove-labels=key2
$ {command} NAME --zone=ZONE --flags-file=FILE_PATH
Example json configuration file:
{
"--file-share":
{
"capacity": "102400",
"name": "my_vol",
"nfs-export-options": [
{
"access-mode": "READ_WRITE",
"ip-ranges": [
"10.0.0.0/29",
"10.2.0.0/29"
],
"squash-mode": "ROOT_SQUASH",
"anon_uid": 1003,
"anon_gid": 1003
}
]
}
}
The following command updates a Filestore instance named NAME to change the
capacity to CAPACITY.
$ {command} NAME --project=PROJECT_ID --zone=ZONE\
--file-share=name=VOLUME_NAME,capacity=CAPACITY
The following command updates a Filestore instance named NAME to configure the
max-iops-per-tb to MAX-IOPS-PER-TB.
$ {command} NAME --project=PROJECT_ID --zone=ZONE\
--performance=max-iops-per-tb=MAX-IOPS-PER-TB
"""),
}
@staticmethod
def Args(parser):
_CommonArgs(parser, UpdateBeta._API_VERSION)
def Run(self, args):
"""Runs a command line string arguments.
Args:
args: cmd line string arguments.
Returns:
client: A FilestoreClient instance.
Raises:
InvalidArgumentException: for invalid JSON formatted --file-args.
KeyError: for key errors in JSON values.
"""
instance_ref = args.CONCEPTS.instance.Parse()
client = filestore_client.FilestoreClient(self._API_VERSION)
labels_diff = labels_util.Diff.FromUpdateArgs(args)
dp_util.ValidateDeletionProtectionUpdateArgs(args)
orig_instance = client.GetInstance(instance_ref)
try:
if args.file_share:
client.MakeNFSExportOptionsMsgBeta(
messages=client.messages,
nfs_export_options=args.file_share.get('nfs-export-options', []),
)
except KeyError as e:
raise exceptions.InvalidArgumentException(
'--file-share', str(e)
)
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,
performance=args.performance,
managed_ad=args.managed_ad,
disconnect_managed_ad=args.disconnect_managed_ad,
ldap=args.ldap,
disconnect_ldap=args.disconnect_ldap,
clear_nfs_export_options=args.clear_nfs_export_options,
deletion_protection_enabled=args.deletion_protection,
deletion_protection_reason=args.deletion_protection_reason,
)
except filestore_client.InvalidDisconnectLdapError as e:
raise exceptions.InvalidArgumentException(
'--disconnect-ldap', str(e)
)
except filestore_client.InvalidDisconnectManagedADError as e:
raise exceptions.InvalidArgumentException(
'--disconnect-managed-ad', str(e)
)
except filestore_client.Error as e:
raise exceptions.InvalidArgumentException(
'--file-share', str(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')
if args.IsSpecified('performance'):
updated_fields.append('performanceConfig')
if args.IsSpecified('managed_ad') or args.IsSpecified(
'disconnect_managed_ad'
) or args.IsSpecified('ldap') or args.IsSpecified('disconnect_ldap'):
updated_fields.append('directoryServices')
updated_fields += dp_util.GetDeletionProtectionUpdateMask(args)
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 beta filestore '
'operations describe {}`'.format(result.name)
)
return result