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,27 @@
# -*- 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.
"""gcloud dns operations command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Policies(base.Group):
"""Manage your Cloud DNS policies."""
pass

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.
"""Command group for managing Dns policy configurations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Config(base.Group):
"""Manage Dns policy configurations."""

View File

@@ -0,0 +1,38 @@
release_tracks: [ALPHA]
command_type: CONFIG_EXPORT
help_text:
brief: Export the configuration for a Dns policy.
description: |
*{command}* exports the configuration for a Dns policy.
Policy configurations can be exported in
Kubernetes Resource Model (krm) or Terraform HCL formats. The
default format is `krm`.
Specifying `--all` allows you to export the configurations for all
policies within the project.
Specifying `--path` allows you to export the configuration(s) to
a local directory.
examples: |
To export the configuration for a policy, run:
$ {command} my-policy
To export the configuration for a policy to a file, run:
$ {command} my-policy --path=/path/to/dir/
To export the configuration for a policy in Terraform
HCL format, run:
$ {command} my-policy --resource-format=terraform
To export the configurations for all policies within a
project, run:
$ {command} --all
arguments:
resource:
help_text: Policy to export the configuration for.
spec: !REF googlecloudsdk.command_lib.dns.resources:policy

View File

@@ -0,0 +1,278 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""gcloud dns policy create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dns import util
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.dns import flags
from googlecloudsdk.command_lib.dns import resource_args
from googlecloudsdk.command_lib.dns import util as command_util
from googlecloudsdk.core import log
def _AddArgsCommon(parser):
flags.GetPolicyDescriptionArg(required=True).AddToParser(parser)
flags.GetPolicyNetworksArg(required=True).AddToParser(parser)
flags.GetPolicyInboundForwardingArg().AddToParser(parser)
flags.GetPolicyAltNameServersArg().AddToParser(parser)
flags.GetPolicyLoggingArg().AddToParser(parser)
flags.GetPolicyPrivateAltNameServersArg().AddToParser(parser)
flags.GetEnableDns64AllQueriesArg().AddToParser(parser)
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA)
class CreateGA(base.UpdateCommand):
r"""Creates a new Cloud DNS policy.
This command creates a new Cloud DNS policy.
## EXAMPLES
To create a new policy with minimal arguments, run:
$ {command} mypolicy \
--description='My new policy test policy 5' \
--networks=''
To create a new policy with all optional arguments, run:
$ {command} mypolicy \
--description='My new policy test policy 5' \
--networks=network1,network2 \
--alternative-name-servers=192.168.1.1,192.168.1.2 \
--enable-inbound-forwarding \
--enable-logging \
--enable-dns64-all-queries
"""
@staticmethod
def Args(parser):
resource_args.AddPolicyResourceArg(
parser, verb='to create', api_version='v1')
_AddArgsCommon(parser)
parser.display_info.AddFormat('json')
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('enable_dns64_all_queries'):
policy.dns64Config = messages.PolicyDns64Config(
scope=messages.PolicyDns64ConfigScope(
allQueries=args.enable_dns64_all_queries
)
)
else:
policy.dns64Config = messages.PolicyDns64Config(
scope=messages.PolicyDns64ConfigScope(allQueries=False)
)
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
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(CreateGA):
r"""Creates a new Cloud DNS policy.
This command creates a new Cloud DNS policy.
## EXAMPLES
To create a new policy with minimal arguments, run:
$ {command} mypolicy \
--description='My new policy test policy 5' \
--networks=''
To create a new policy with all optional arguments, run:
$ {command} mypolicy \
--description='My new policy test policy 5' \
--networks=network1,network2 \
--alternative-name-servers=192.168.1.1,192.168.1.2 \
--private-alternative-name-servers=100.64.0.1 \
--enable-inbound-forwarding \
--enable-logging \
--enable-dns64-all-queries
"""
@staticmethod
def Args(parser):
resource_args.AddPolicyResourceArg(
parser, verb='to create', api_version='v1beta2')
_AddArgsCommon(parser)
parser.display_info.AddFormat('json')
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.BetaParseAltNameServers(
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('enable_dns64_all_queries'):
policy.dns64Config = messages.PolicyDns64Config(
scope=messages.PolicyDns64ConfigScope(
allQueries=args.enable_dns64_all_queries
)
)
else:
policy.dns64Config = messages.PolicyDns64Config(
scope=messages.PolicyDns64ConfigScope(allQueries=False)
)
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
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(CreateBeta):
r"""Creates a new Cloud DNS policy.
This command creates a new Cloud DNS policy.
## EXAMPLES
To create a new policy with minimal arguments, run:
$ {command} mypolicy \
--description='My new policy test policy 5' \
--networks=''
To create a new policy with all optional arguments, run:
$ {command} mypolicy \
--description='My new policy test policy 5' \
--networks=network1,network2 \
--alternative-name-servers=192.168.1.1,192.168.1.2 \
--private-alternative-name-servers=100.64.0.1 \
--enable-inbound-forwarding \
--enable-logging \
--enable-dns64-all-queries
"""
@staticmethod
def Args(parser):
resource_args.AddPolicyResourceArg(
parser, verb='to create', api_version='v1alpha2')
_AddArgsCommon(parser)
parser.display_info.AddFormat('json')

View File

@@ -0,0 +1,30 @@
- &GA
release_tracks: [GA]
help_text:
brief: Deletes a Cloud DNS policy.
description: |
Deletes a Cloud DNS policy.
## EXAMPLES
To delete a policy, run:
$ {command} mypolicy
request:
collection: dns.policies
method: delete
api_version: v1
arguments:
resource:
help_text: The name of the policy you want to delete.
is_positional: true
spec: !REF googlecloudsdk.command_lib.dns.resources:policy
- <<: *GA
release_tracks: [BETA, ALPHA]
request:
collection: dns.policies
method: delete
api_version: v1beta2

View File

@@ -0,0 +1,23 @@
- help_text:
brief: Describes a Cloud DNS policy.
description: |
Describes details of a Cloud DNS policy.
## EXAMPLES
To describe a policy, run:
$ {command} mypolicy
request:
collection: dns.policies
method: get
api_version: v1
arguments:
resource:
help_text: The name of the policy you want to describe.
is_positional: true
spec: !REF googlecloudsdk.command_lib.dns.resources:policy
output:
format: json

View File

@@ -0,0 +1,61 @@
- &GA
release_tracks: [GA]
help_text:
brief: View the list of all your Cloud DNS policies.
description: |
Displays the list of all Cloud DNS policies in a given project.
## EXAMPLES
To see the list of all policies, run:
$ {command}
To see the list of first 10 policies, run:
$ {command} --limit=10
request:
collection: dns.policies
method: list
api_version: v1
response:
id_field: name
arguments:
resource:
help_text: The project you want to list policies for.
spec: !REF googlecloudsdk.command_lib.dns.resources:project
output:
format: |
table(name,
description,
enableInboundForwarding:label=FORWARDING,
enableLogging:label=LOGGING,
alternativeNameServerConfig.targetNameServers.extract(
ipv4Address).map().join(", ").list():label=ALTERNATE_NAME_SERVERS,
networks.firstof(networkUrl).map().scope().join(", "):label=NETWORKS,
dns64Config.scope.allQueries:label=DNS64_ALL_QUERIES
)
- <<: *GA
release_tracks: [ALPHA, BETA]
request:
collection: dns.policies
method: list
api_version: v1beta2
output:
format: |
table(name,
description,
enableInboundForwarding:label=FORWARDING,
enableLogging:label=LOGGING,
alternativeNameServerConfig.targetNameServers.extract(
ipv4Address).map().join(", ").list():label=ALTERNATE_NAME_SERVERS,
networks.firstof(networkUrl).map().scope().join(", "):label=NETWORKS,
dns64Config.scope.allQueries:label=DNS64_ALL_QUERIES
)

View File

@@ -0,0 +1,237 @@
# -*- 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.
"""gcloud dns policy update command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dns import util
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dns import flags
from googlecloudsdk.command_lib.dns import resource_args
from googlecloudsdk.command_lib.dns import util as command_util
from googlecloudsdk.core import log
def _AddArgsCommon(parser):
flags.GetPolicyDescriptionArg().AddToParser(parser)
flags.GetPolicyNetworksArg().AddToParser(parser)
flags.GetPolicyInboundForwardingArg().AddToParser(parser)
flags.GetPolicyAltNameServersArg().AddToParser(parser)
flags.GetPolicyLoggingArg().AddToParser(parser)
flags.GetPolicyPrivateAltNameServersArg().AddToParser(parser)
flags.GetEnableDns64AllQueriesArg(update=True).AddToParser(parser)
def _ArgsNeededForUpdateCommon():
return (
'networks',
'description',
'enable_inbound_forwarding',
'enable_logging',
'alternative_name_servers',
'enable_dns64_all_queries',
)
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA)
class UpdateGA(base.UpdateCommand):
"""Update an existing Cloud DNS policy.
Update an existing Cloud DNS policy.
## EXAMPLES
To change the description of a policy, run:
$ {command} mypolicy --description="Hello, world!"
"""
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)
@staticmethod
def Args(parser):
resource_args.AddPolicyResourceArg(
parser, verb='to update', api_version='v1')
_AddArgsCommon(parser)
parser.display_info.AddFormat('json')
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)
args_needed_for_update = _ArgsNeededForUpdateCommon()
if not any(args.IsSpecified(arg) for arg in args_needed_for_update):
log.status.Print('Nothing to update.')
return to_update
if args.IsSpecified('networks'):
if args.networks == ['']:
args.networks = []
to_update.networks = command_util.ParsePolicyNetworks(
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('enable_dns64_all_queries'):
to_update.dns64Config = messages.PolicyDns64Config(
scope=messages.PolicyDns64ConfigScope(
allQueries=args.enable_dns64_all_queries
)
)
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
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class UpdateBeta(UpdateGA):
"""Update an existing Cloud DNS policy.
Update an existing Cloud DNS policy.
## EXAMPLES
To change the description of a policy, run:
$ {command} mypolicy --description="Hello, world!"
"""
@staticmethod
def Args(parser):
resource_args.AddPolicyResourceArg(
parser, verb='to update', api_version='v1beta2')
_AddArgsCommon(parser)
parser.display_info.AddFormat('json')
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)
args_needed_for_update = _ArgsNeededForUpdateCommon()
if not any(args.IsSpecified(arg) for arg in args_needed_for_update):
log.status.Print('Nothing to update.')
return to_update
if args.IsSpecified('networks'):
if args.networks == ['']:
args.networks = []
to_update.networks = command_util.ParsePolicyNetworks(
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('enable_dns64_all_queries'):
to_update.dns64Config = messages.PolicyDns64Config(
scope=messages.PolicyDns64ConfigScope(
allQueries=args.enable_dns64_all_queries
)
)
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
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(UpdateBeta):
"""Update an existing Cloud DNS policy.
Update an existing Cloud DNS policy.
## EXAMPLES
To change the description of a policy, run:
$ {command} mypolicy --description="Hello, world!"
"""
@staticmethod
def Args(parser):
resource_args.AddPolicyResourceArg(
parser, verb='to update', api_version='v1alpha2')
_AddArgsCommon(parser)
parser.display_info.AddFormat('json')