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,29 @@
# -*- 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.
"""virtualenv command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.core import properties
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.GA)
class VirtualEnv(base.Group):
"""Manage Cloud SDK virtual env setup."""

View File

@@ -0,0 +1,113 @@
# -*- 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 to create virtualenv environment."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.config.virtualenv import util
from googlecloudsdk.core import config
from googlecloudsdk.core import execution_utils
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.util import files
@base.Hidden
@base.DefaultUniverseOnly
class Create(base.Command):
"""Create a virtualenv environment.
Create a virtual env context for gcloud to run in. Installs several
python modules into the virtual environment. The virtual env environment
can be inspected via the `{parent_command} describe` command. Note this
command does not enable the virtualenv environment, you must run
`{parent_command} enable` to do so.
"""
@staticmethod
def Args(parser):
"""Adds args for this command."""
parser.add_argument(
'--python-to-use',
help='Absolute path to python to use to create virtual env.')
def Run(self, args):
if util.IsPy2() and not args.IsSpecified('python_to_use'):
log.error('Virtual env support requires Python 3.')
raise exceptions.ExitCodeNoError(exit_code=3)
if util.IsWindows():
log.error('Virtual env support not enabled on Windows.')
raise exceptions.ExitCodeNoError(exit_code=4)
if args.IsSpecified('python_to_use'):
python = args.python_to_use
else:
try:
python = execution_utils.GetPythonExecutable()
except ValueError:
log.error('Failed to resolve python to use for virtual env.')
raise exceptions.ExitCodeNoError(exit_code=5)
ve_dir = config.Paths().virtualenv_dir
if util.VirtualEnvExists(ve_dir):
log.error('Virtual env setup {} already exists.'.format(ve_dir))
raise exceptions.ExitCodeNoError(exit_code=5)
succeeded_making_venv = False
try:
log.status.Print('Creating virtualenv...')
# python -m venv is preferred as it aligns the python used with
# the current in used Python.
ec = execution_utils.Exec([python, '-m', 'venv', ve_dir],
no_exit=True,
err_func=log.file_only_logger.debug,
out_func=log.file_only_logger.debug)
if ec != 0:
# Many linux vendors havea a history of having a broken python-venv
# package that will not work correctly, debian for example. If -m venv
# failed above we will attempt to use the virtualenv tool if it is
# installed and exists in $PATH.
ec = execution_utils.Exec(['virtualenv', '-q', '-p', python, ve_dir],
no_exit=True)
if ec != 0:
log.error('Virtual env setup failed.')
raise exceptions.ExitCodeNoError(exit_code=ec)
log.status.Print('Installing modules...')
install_modules = [
'{}/bin/pip3'.format(ve_dir), 'install', '--log',
'{}/install_module.log'.format(ve_dir),
'--disable-pip-version-check'
]
install_modules.extend(util.MODULES)
ec = execution_utils.Exec(install_modules, no_exit=True)
if ec == 0:
# prevent the cleanup that occurs in finally block
succeeded_making_venv = True
else:
log.error('Virtual env setup failed.')
if properties.IsInternalUserCheck():
log.error(
'You might need further authentication. See more at '
'go/gcloud-internal-auth.'
)
raise exceptions.ExitCodeNoError(exit_code=ec)
finally:
# If something went wrong we clean up any partial created ve_dir
if not succeeded_making_venv:
if util.VirtualEnvExists(ve_dir):
files.RmTree(ve_dir)

View File

@@ -0,0 +1,43 @@
# -*- 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 to delete virtualenv environment."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.config.virtualenv import util
from googlecloudsdk.core import config
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
from googlecloudsdk.core.util import files
class Delete(base.Command):
"""Delete a virtualenv environment."""
def Run(self, args):
ve_dir = config.Paths().virtualenv_dir
if not util.VirtualEnvExists(ve_dir):
log.status.Print('Virtual env does not exist at {}.'.format(ve_dir))
raise exceptions.ExitCodeNoError(exit_code=1)
console_io.PromptContinue(
message='Delete virtual env setup at {}'.format(ve_dir),
cancel_on_no=True)
files.RmTree(ve_dir)

View File

@@ -0,0 +1,82 @@
# -*- 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 to describe virtualenv environment."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.config.virtualenv import util
from googlecloudsdk.core import config
from googlecloudsdk.core import execution_utils
from googlecloudsdk.core import log
class VirtualEnvInfo(object):
def __init__(self, python_version, modules, enabled):
self.python_version = python_version
self.modules = modules
self.enabled = enabled
class Module(object):
def __init__(self, module_name, module_version):
self.module_name = module_name
self.module_version = module_version
@base.Hidden
class Describe(base.Command):
"""Describe a virtualenv environment."""
def Run(self, args):
ve_dir = config.Paths().virtualenv_dir
if not util.VirtualEnvExists(ve_dir):
log.error('Virtual env does not exist at {}.'.format(ve_dir))
raise exceptions.ExitCodeNoError(exit_code=1)
# The Python version being used.
python_version = 'NOT AVAILABLE'
def _ver(output):
self._version_output = output
ec = execution_utils.Exec(['{}/bin/python3'.format(ve_dir), '--version'],
no_exit=True, out_func=_ver)
if ec == 0:
version_parts = self._version_output.split(' ')
if len(version_parts) == 2:
python_version = version_parts[1]
# The modules installed in the environment.
modules = []
def _mod_output(output):
self._modules_stdout = output
execution_utils.Exec(['{}/bin/pip3'.format(ve_dir), 'freeze'],
no_exit=True, out_func=_mod_output)
for l in self._modules_stdout.split('\n'):
if '==' in l:
mn, mv = l.split('==')
modules.append(Module(mn, mv))
# The enable|disable state of the virtual env environment.
ve_enabled = False
if util.EnableFileExists(ve_dir):
ve_enabled = True
return VirtualEnvInfo(python_version, modules, ve_enabled)

View File

@@ -0,0 +1,42 @@
# -*- 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 to disable virtualenv environment."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.config.virtualenv import util
from googlecloudsdk.core import config
from googlecloudsdk.core import log
@base.Hidden
class Disable(base.Command):
"""Disable a virtualenv environment."""
def Run(self, args):
ve_dir = config.Paths().virtualenv_dir
if util.VirtualEnvExists(ve_dir):
if util.EnableFileExists(ve_dir):
util.RmEnableFile(ve_dir)
log.status.Print('Virtual env disabled.')
else:
log.error('Virtual env does not exist at {}.'.format(ve_dir))
raise exceptions.ExitCodeNoError(exit_code=1)

View File

@@ -0,0 +1,44 @@
# -*- 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 to enable virtualenv environment."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.config.virtualenv import util
from googlecloudsdk.core import config
from googlecloudsdk.core import log
@base.Hidden
class Enable(base.Command):
"""Enable a virtualenv environment."""
def Run(self, args):
ve_dir = config.Paths().virtualenv_dir
if util.VirtualEnvExists(ve_dir):
if not util.EnableFileExists(ve_dir):
util.CreateEnableFile(ve_dir)
log.status.Print('Virtual env enabled.')
else:
log.error('Virtual env does not exist at {}.'.format(ve_dir))
raise exceptions.ExitCodeNoError(exit_code=1)

View File

@@ -0,0 +1,51 @@
# -*- 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 to update virtualenv environment."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.config.virtualenv import util
from googlecloudsdk.core import config
from googlecloudsdk.core import execution_utils
from googlecloudsdk.core import log
@base.Hidden
class Update(base.Command):
"""Update modules installed in a virtualenv environment."""
def Run(self, args):
ve_dir = config.Paths().virtualenv_dir
if not util.VirtualEnvExists(ve_dir):
log.error('Virtual env does not exist at {}.'.format(ve_dir))
raise exceptions.ExitCodeNoError(exit_code=1)
log.status.Print('Updating modules...')
update_modules = [
'{}/bin/pip3'.format(ve_dir), 'install', '--log',
'{}/update_module.log'.format(ve_dir), '-q',
'--disable-pip-version-check'
]
update_modules.extend(util.MODULES)
ec = execution_utils.Exec(update_modules, no_exit=True)
if ec != 0:
log.error('Failed to update modules.')
raise exceptions.ExitCodeNoError(exit_code=1)
log.status.Print('Modules updated.')