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,102 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 super-group for the update manager."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import argparse
from googlecloudsdk.calliope import base
from googlecloudsdk.core import config
from googlecloudsdk.core import log
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Components(base.Group):
"""List, install, update, or remove Google Cloud CLI components.
The {command} command group lets you control which tools are installed
in the Google Cloud CLI. It can be used to install, update and remove
components of the Google Cloud CLI, ensuring a lean, up-to-date installation.
{command} regularly checks whether updates are available for the
tools you already have installed, and gives you the opportunity to upgrade to
the latest version.
Certain components have dependencies. {command} will install any dependencies,
and during removal, any dependant components will be uninstalled
automatically.
## EXAMPLES
To see all available components:
$ {command} list
To install a component you don't have:
$ {command} install COMPONENT
To remove a component you no longer need:
$ {command} remove COMPONENT
To update all components you have to their latest version:
$ {command} update
To update all installed components to version 1.2.3:
$ {command} update --version 1.2.3
"""
category = base.SDK_TOOLS_CATEGORY
@staticmethod
def Args(parser):
"""Sets args for gcloud components."""
# An override for the location to install components into.
parser.add_argument('--sdk-root-override', required=False, hidden=True,
help='THIS ARGUMENT NEEDS HELP TEXT.')
# A different URL to look at instead of the default.
parser.add_argument('--snapshot-url-override', required=False, hidden=True,
help='THIS ARGUMENT NEEDS HELP TEXT.')
# This is not a commonly used option. You can use this flag to create a
# Cloud SDK install for an OS other than the one you are running on.
# Running the updater multiple times for different operating systems could
# result in an inconsistent install.
parser.add_argument('--operating-system-override', required=False,
hidden=True,
help='THIS ARGUMENT NEEDS HELP TEXT.')
# This is not a commonly used option. You can use this flag to create a
# Cloud SDK install for a processor architecture other than that of your
# current machine. Running the updater multiple times for different
# architectures could result in an inconsistent install.
parser.add_argument('--architecture-override', required=False, hidden=True,
help='THIS ARGUMENT NEEDS HELP TEXT.')
# pylint:disable=g-missing-docstring
def Filter(self, unused_tool_context, args):
base.DisableUserProjectQuota()
if config.INSTALLATION_CONFIG.IsAlternateReleaseChannel():
log.warning('You are using alternate release channel: [%s]',
config.INSTALLATION_CONFIG.release_channel)
# Always show the URL if using a non standard release channel.
log.warning('Snapshot URL for this release channel is: [%s]',
config.INSTALLATION_CONFIG.snapshot_url)

View File

@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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 components copy-bundled-python` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.components import util
from googlecloudsdk.core.updater import update_manager
@base.Hidden
class CopyBundledPython(base.Command):
"""Make a temporary copy of bundled Python installation.
Also print its location.
If the Python installation used to execute this command is *not* bundled, do
not make a copy. Instead, print the location of the current Python
installation.
"""
@staticmethod
def Args(parser):
parser.display_info.AddFormat('value(python_location)')
def Run(self, args):
manager = util.GetUpdateManager(args)
if manager.IsPythonBundled():
python_location = update_manager.CopyPython()
else:
python_location = sys.executable
# There's no straightforward way to print a string that was returned from
# Run() using the formatting, so we wrap it in a dict.
return {'python_location': python_location}

View File

@@ -0,0 +1,85 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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 command to install/update gcloud components."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.components import util
@base.UniverseCompatible
class Install(base.SilentCommand):
"""Install one or more Google Cloud CLI components.
Ensure that each of the specified components (as well as any dependent
components) is installed on the local workstation. Components are installed
without performing any upgrades to your existing CLI installation. All
components are installed at the current version of your CLI.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
Components that are available for installation can be viewed by
running:
$ {parent_command} list
Installing a given component will also install all components on which
it depends. The command lists all components it is about to install,
and asks for confirmation before proceeding.
``{command}'' installs components from the version of the Google Cloud
CLI you currently have installed. You can see your current version by
running:
$ {top_command} version
If you want to update your Google Cloud CLI installation to the latest
available version, use:
$ {parent_command} update
""",
'EXAMPLES': """\
The following command installs ``COMPONENT-1'', ``COMPONENT-2'',
and all components that they depend on:
$ {command} COMPONENT-1 COMPONENT-2
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'component_ids',
metavar='COMPONENT-IDS',
nargs='+',
help='The IDs of the components to be installed.')
parser.add_argument(
'--compile-python',
required=False,
hidden=True,
default='True',
action='store_true',
help='THIS ARGUMENT NEEDS HELP TEXT.')
def Run(self, args):
"""Runs the list command."""
update_manager = util.GetUpdateManager(args)
update_manager.Install(args.component_ids)

View File

@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 command to list installed/available gcloud components."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.components import util
from googlecloudsdk.core import log
class List(base.ListCommand):
"""List the status of all Google Cloud CLI components.
This command lists all the available components in the Google Cloud CLI. For
each component, the command lists the following information:
* Status on your local workstation: not installed, installed (and
up to date), and update available (installed, but not up to date)
* Name of the component (a description)
* ID of the component (used to refer to the component in other
[{parent_command}] commands)
* Size of the component
## EXAMPLES
To list the status of all Google Cloud CLI components, run:
$ {command}
To show the currently installed version (if any) and the latest available
version of each component, run:
$ {command} --show-versions
"""
@staticmethod
def Args(parser):
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
parser.add_argument(
'--only-local-state',
action='store_true',
help='Only show locally installed components.',
)
parser.add_argument(
'--show-versions', required=False, action='store_true',
help='Show installed and available versions of all components.')
parser.add_argument(
'--show-hidden', required=False, action='store_true',
help='Show installed and available versions of all components.',
hidden=True,
)
parser.add_argument(
'--show-platform',
required=False,
action='store_true',
help='Show operating system and architecture of all components')
def _SetFormat(self, args):
attributes = [
'box',
'title="Components"'
]
columns = [] if args.only_local_state else ['state.name:label=Status']
columns.append('name:label=Name')
if args.show_versions:
columns.extend([
'current_version_string:label=Installed:align=right',
'latest_version_string:label=Latest:align=right',
])
columns.extend([
'id:label=ID',
'size.size(zero="",min=1048576):label=Size:align=right',
])
if args.show_platform:
columns.extend([
'platform.architecture.id:label=ARCHITECTURE',
'platform.operating_system.id:label=OPERATING_SYSTEM'
])
args.GetDisplayInfo().AddFormat('table[{attributes}]({columns})'.format(
attributes=','.join(attributes), columns=','.join(columns)))
def Run(self, args):
"""Runs the list command."""
self._SetFormat(args)
update_manager = util.GetUpdateManager(args)
result = update_manager.List(show_hidden=args.show_hidden,
only_local_state=args.only_local_state)
(to_print, self._current_version, self._latest_version) = result
return to_print
def Epilog(self, resources_were_displayed):
if not resources_were_displayed:
log.status.write('\nNo updates.')
latest_version_string = ('' if self._latest_version is None
else ' [{}]'.format(self._latest_version))
log.status.write("""\
To install or remove components at your current Google Cloud CLI version [{current}], run:
$ gcloud components install COMPONENT_ID
$ gcloud components remove COMPONENT_ID
To update your Google Cloud CLI installation to the latest version{latest}, run:
$ gcloud components update
""".format(current=self._current_version, latest=latest_version_string))

View File

@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 command to perform any necessary post installation steps."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.core.updater import local_state
@base.Hidden
class PostProcess(base.SilentCommand):
"""Performs any necessary post installation steps."""
@staticmethod
def Args(parser):
parser.add_argument(
'--force-recompile',
action='store_true',
required=False,
hidden=True,
default='False',
help='THIS ARGUMENT NEEDS HELP TEXT.')
parser.add_argument(
'--compile-python',
required=False,
hidden=True,
default='True',
action='store_true',
help='THIS ARGUMENT NEEDS HELP TEXT.')
def Run(self, args):
# Re-compile python files.
if args.compile_python:
state = local_state.InstallationState.ForCurrent()
state.CompilePythonFiles(force=args.force_recompile)

View File

@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 command to install/update gcloud components."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.components import util
class Reinstall(base.SilentCommand):
"""Reinstall the Google Cloud CLI with the same components you have now.
If your Google Cloud CLI installation becomes corrupt, this command attempts
to fix it by downloading the latest version of the Google Cloud CLI and
reinstalling it. This will replace your existing installation with a fresh
one. The command is the equivalent of deleting your current installation,
downloading a fresh copy of the gcloud CLI, and installing in the same
location.
## EXAMPLES
To reinstall all components you have installed, run:
$ {command}
"""
@staticmethod
def Args(parser):
pass
def Run(self, args):
"""Runs the list command."""
update_manager = util.GetUpdateManager(args)
update_manager.Reinstall()

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 command to remove gcloud components."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.components import util
@base.UniverseCompatible
class Remove(base.SilentCommand):
"""Remove one or more installed components.
Uninstall all listed components, as well as all components that directly or
indirectly depend on them.
"""
detailed_help = {
'DESCRIPTION': """\
Uninstall all listed components, as well as all components that
directly or indirectly depend on them.
The command lists all components it is about to remove, and asks for
confirmation before proceeding.
""",
'EXAMPLES': """\
To remove ``COMPONENT-1'', ``COMPONENT-2'', and all components that
directly or indirectly depend on ``COMPONENT-1'' or ``COMPONENT-2'',
type the following:
$ {command} COMPONENT-1 COMPONENT-2
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'component_ids',
metavar='COMPONENT_ID',
nargs='+',
help='The IDs of the components to be removed.')
def Run(self, args):
"""Runs the list command."""
update_manager = util.GetUpdateManager(args)
update_manager.Remove(args.component_ids)

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 super-group for the update manager."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import argparse
import os
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.core import config
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.updater import update_manager
from googlecloudsdk.core.util import platforms
class Repositories(base.Group):
"""Manage additional component repositories for Trusted Tester programs."""
detailed_help = {
'DESCRIPTION': """\
List, add, and remove component repositories for Trusted Tester
programs. If you are not participating in a Trusted Tester program,
these commands are not necessary for updating your Google Cloud CLI
installation.
If you are participating in a Trusted Tester program, you will be
instructed on the location of repositories that you should add.
These commands allow you to manage the set of repositories you have
registered.
Once you have a repository registered, the component manager will use
that location to locate new Google Cloud CLI components that are
available, or possibly different versions of existing components that
can be installed.
If you want to revert to a standard version of the Google Cloud CLI at
any time, you may remove all repositories and then run:
$ gcloud components update
to revert to a standard installation.
""",
}

View File

@@ -0,0 +1,94 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 command to list installed/available gcloud components."""
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.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.updater import snapshots
from googlecloudsdk.core.updater import update_manager
class Add(base.SilentCommand):
"""Add a new Trusted Tester component repository.
"""
detailed_help = {
'DESCRIPTION': """\
Add a new Trusted Tester component repository to the list of
repositories used by the component manager. This will allow you to
install and update components found in this repository.
If you are participating in a Trusted Tester program, you will be
instructed on the location of repositories with additional versions of
one or more Google Cloud CLI components.
""",
'EXAMPLES': """\
To add the Trusted Tester component repository
http://repo.location.com run:
$ gcloud components repositories add http://repo.location.com
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'url',
nargs='+',
metavar='URL',
help='One or more URLs for the component repositories you want to add.')
def Run(self, args):
"""Runs the add command."""
# Ensure all the repos are valid.
for repo in args.url:
try:
snapshots.ComponentSnapshot.FromURLs(
repo, command_path='components.repositories.add')
except snapshots.Error:
raise exceptions.InvalidArgumentException(
'url',
'The given repository [{repo}] could not be fetched. Check your '
'network settings and ensure that you have entered a valid '
'repository URL.'.format(repo=repo))
repos = update_manager.UpdateManager.GetAdditionalRepositories()
added = []
existing = []
for url in args.url:
if url in repos:
existing.append(url)
else:
added.append(url)
repos.extend(added)
properties.PersistProperty(
properties.VALUES.component_manager.additional_repositories,
','.join(repos),
scope=properties.Scope.INSTALLATION)
for url in added:
log.status.Print('Added repository: [{repo}]'.format(repo=url))
for url in existing:
log.status.Print(
'Repository already added, skipping: [{repo}]'.format(repo=url))
return added

View File

@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 command to list installed/available gcloud components."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
from googlecloudsdk.core.updater import snapshots
from googlecloudsdk.core.updater import update_manager
def TransformLastUpdate(r):
try:
snapshot = snapshots.ComponentSnapshot.FromURLs(
r, command_path='components.repositories.list')
return snapshot.sdk_definition.LastUpdatedString()
except (AttributeError, TypeError, snapshots.URLFetchError):
return 'Unknown'
_COMPONENTS_REPOSITORIES_TRANSFORMS = {
'last_update': TransformLastUpdate,
}
class List(base.ListCommand):
"""List any Trusted Tester component repositories you have registered.
"""
detailed_help = {
'DESCRIPTION': """
List all Trusted Tester component repositories that are registered
with the component manager. If you have additional repositories, the
component manager will look at them to discover additional components
to install, or different versions of existing components that are
available.
""",
'EXAMPLES': """
To list all Trusted Tester component repositories that are registered
with the component manager, run:
$ {command}
"""
}
@staticmethod
def Args(parser):
"""Adds/removes args for this command."""
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
parser.display_info.AddFormat("""
table(
.:label=REPOSITORY,
last_update():label=LAST_UPDATE
)
""")
parser.display_info.AddTransforms(_COMPONENTS_REPOSITORIES_TRANSFORMS)
def Run(self, args):
"""Runs the list command."""
repos = update_manager.UpdateManager.GetAdditionalRepositories()
return repos if repos else []
def Epilog(self, resources_were_displayed):
if not resources_were_displayed:
log.status.write(
'You have no registered component repositories. To add one, run:\n'
' $ gcloud components repositories add URL\n\n')

View File

@@ -0,0 +1,109 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 command to list installed/available gcloud components."""
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.components import completers
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.console import console_io
from googlecloudsdk.core.updater import update_manager
class Remove(base.SilentCommand):
"""Remove a registered Trusted Test component repository.
"""
detailed_help = {
'DESCRIPTION': """\
Remove a registered Trusted Tester component repository from the list
of repositories used by the component manager. After removing a
repository, you can run:
$ gcloud components update
to revert back to the standard version of any components that were
installed from that repository.
""",
'EXAMPLES': """\
To be prompted for registered Trusted Tester component repositories to
remove run:
$ gcloud components repositories remove
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'url',
nargs='*',
metavar='URL',
completer=completers.RepoCompleter,
help='Zero or more URLs for the component repositories you want to '
'remove. If none are given, you will be prompted to choose which '
'existing repository you want to remove.')
parser.add_argument('--all', action='store_true',
help='Remove all registered repositories.')
def Run(self, args):
"""Runs the remove command."""
repos = update_manager.UpdateManager.GetAdditionalRepositories()
removed_repos = []
# Removing all URLs.
if args.all:
removed_repos.extend(repos)
repos = []
# Specifying URLs to remove explicitly.
elif args.url:
if not repos:
raise update_manager.NoRegisteredRepositoriesError(
'You have no registered repositories.')
for url in args.url:
if url not in repos:
raise exceptions.InvalidArgumentException(
'url',
'URL [{0}] was not a known registered repository.'.format(url))
for url in args.url:
repos.remove(url)
removed_repos.extend(args.url)
# No URL specified, prompt to choose one.
else:
if not repos:
raise update_manager.NoRegisteredRepositoriesError(
'You have no registered repositories.')
result = console_io.PromptChoice(
repos, default=None,
message='Which repository would you like to remove?')
if result is None:
log.status.Print('No repository was removed.')
else:
removed_repos.append(repos.pop(result))
if removed_repos:
properties.PersistProperty(
properties.VALUES.component_manager.additional_repositories,
','.join(repos) if repos else None,
scope=properties.Scope.INSTALLATION)
for removed_repo in removed_repos:
log.status.Print('Removed repository: [{repo}]'.format(repo=removed_repo))
return removed_repos

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 command to restore a backup of a Google Cloud CLI installation."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.components import util
@base.Hidden
@base.Deprecate(
is_removed=False,
warning=(
'Starting with release 473.0.0, the Google Cloud CLI updates in place'
' instead of making a backup copy of the installation directory when'
' running `gcloud components update`, `install`, and `remove` commands'
' (this reduces the time taken by those operations). Consequently, this'
' command has no backup to restore in those cases. Instead, to restore'
' your installation to a previous version, run'
' `gcloud components update --version=<previous_version>`, or install'
' the previous version directly from'
' https://cloud.google.com/sdk/docs/install.'
),
)
@base.UniverseCompatible
class Restore(base.SilentCommand):
"""Restore the Google Cloud CLI installation to its state before a reinstall.
This is an undo operation, which restores the Google Cloud CLI installation on
the local workstation to the state it was in just before the most recent
`{parent_command} reinstall` command. A `restore` command does not undo a
previous `restore` command.
## EXAMPLES
To restore the Google Cloud CLI installation to its state before reinstalling,
run:
$ {command}
"""
@staticmethod
def Args(_):
pass
def Run(self, args):
"""Runs the restore command."""
update_manager = util.GetUpdateManager(args)
update_manager.Restore()

View File

@@ -0,0 +1,119 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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 command to install/update gcloud components."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.components import util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.console import console_io
from googlecloudsdk.core.util.prompt_helper import OptInPrompter
# This command is silent as does not produce any resource output.
# In fact it should not run any display code, as the installation has changed
# and current run state is invalid in relation to new installation.
@base.UniverseCompatible
class Update(base.SilentCommand):
"""Update all of your installed components to the latest version.
Ensure that the latest version of all installed components is installed on the
local workstation.
"""
detailed_help = {
'DESCRIPTION': """
{description}
The command lists all components it is about to update, and asks for
confirmation before proceeding.
By default, this command will update all components to their latest
version. This can be configured by using the `--version` flag to
choose a specific version to update to. This version may also be a
version older than the one that is currently installed, thus allowing
you to downgrade your Google Cloud CLI installation.
You can see your current Google Cloud CLI version by running:
$ {top_command} version
To see the latest version of the Google Cloud CLI, run:
$ {parent_command} list
If you run this command without the `--version` flag and you already
have the latest version installed, no update will be performed.
""",
'EXAMPLES': """
To update all installed components to the latest version:
$ {command}
To update all installed components to a fixed Google Cloud CLI version
1.2.3:
$ {command} --version=1.2.3
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'--version',
help='An optional Google Cloud CLI version to update your components to'
'. By default, components are updated to the latest available version. '
'By selecting an older version you can downgrade your Google Cloud CLI '
'installation.')
parser.add_argument(
'component_ids',
metavar='COMPONENT-IDS',
nargs='*',
hidden=True,
help='THIS ARGUMENT NEEDS HELP TEXT.')
parser.add_argument(
'--compile-python',
required=False,
hidden=True,
default='True',
action='store_true',
help='THIS ARGUMENT NEEDS HELP TEXT.')
def Run(self, args):
"""Runs the list command."""
if properties.VALUES.core.disable_usage_reporting.GetBool() in [None, True]:
OptInPrompter().Prompt()
update_manager = util.GetUpdateManager(args)
if args.component_ids and not args.version:
install = console_io.PromptContinue(
message='You have specified individual components to update. If you '
'are trying to install new components, use:\n $ gcloud '
'components install {components}'.format(
components=' '.join(args.component_ids)),
prompt_string='Do you want to run install instead',
default=False,
throw_if_unattended=False,
cancel_on_no=False)
if install:
update_manager.Install(args.component_ids)
return
log.status.Print('Beginning update. This process may take several minutes.')
update_manager.Update(args.component_ids, version=args.version)