403Webshell
Server IP : 35.236.43.222  /  Your IP : 216.73.216.143
Web Server : Apache
System : Linux order-form-vm-001 5.10.0-37-cloud-amd64 #1 SMP Debian 5.10.247-1 (2025-12-11) x86_64
User : deploy ( 1002)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/lib/google-cloud-sdk/lib/surface/compute/project_zonal_metadata/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/google-cloud-sdk/lib/surface/compute/project_zonal_metadata/remove.py
# -*- coding: utf-8 -*- #
# Copyright 2023 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 setting metadata on project zonal metadata."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import instance_settings_metadata_utils as metadata_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.project_zonal_metadata import flags
from googlecloudsdk.core import log
from googlecloudsdk.core import properties


@base.ReleaseTracks(
    base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class RemoveMetadata(base.UpdateCommand):
  # pylint:disable=line-too-long
  """Remove project zonal metadata.

  *{command}* is used to remove project zonal metadata from all VMs within the
  specified zone. For information about metadata, see
  [](https://cloud.google.com/compute/docs/metadata).

  Only the metadata keys that you provide in the command get removed. All other
  existing metadata entries remain the same.

  After you remove a specific project zonal metadata entry, if that metadata key
  has any project-wide value configured, then the VMs in the zone automatically
  inherit that project-wide value.
  """
  # pylint:enable=line-too-long

  detailed_help = {'EXAMPLES': """\
        To remove the project zonal metadata with key=value in the zone ``us-central1-a''
        for the project ``my-gcp-project'', run:

        $ {command} --keys=key --zone=us-central1-a --project=my-gcp-project

        For more information and examples about how to remove project zonal
        metadata, see [](https://cloud.google.com/compute/docs/metadata/setting-custom-metadata#remove-custom-project-zonal-metadata)
      """}

  @staticmethod
  def Args(parser):
    flags.ProjectZonalMetadataRemoveMetadataFlags(parser)

  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client
    service = client.apitools_client.instanceSettings
    get_request = client.messages.ComputeInstanceSettingsGetRequest(
        project=properties.VALUES.core.project.GetOrFail(), zone=args.zone
    )
    existing_instance_settings = client.MakeRequests(
        [(service, 'Get', get_request)]
    )[0]
    fingerprint = existing_instance_settings.fingerprint
    existing_metadata = metadata_utils.ConstructMetadataDict(
        existing_instance_settings.metadata
    )
    keys_not_in_existing_metadata = set(args.keys) - set(
        existing_metadata.keys()
    )
    if keys_not_in_existing_metadata:
      log.status.Print(
          'Provide only valid keys. Keys that do not exist in current project'
          ' zonal metadata in zone [{0}] are {1}.'.format(
              existing_instance_settings.zone, keys_not_in_existing_metadata
          )
      )
      return existing_instance_settings.metadata
    request = client.messages.ComputeInstanceSettingsPatchRequest(
        instanceSettings=client.messages.InstanceSettings(
            fingerprint=fingerprint,
            metadata=client.messages.InstanceSettingsMetadata(),
        ),
        project=properties.VALUES.core.project.GetOrFail(),
        updateMask=metadata_utils.ConstructUpdateMask(
            existing_metadata.keys() if args.all else set(args.keys)
        ),
        zone=args.zone,
    )
    return client.MakeRequests(
        [(service, 'Patch', request)],
        no_followup=True,
    )[0]

Youez - 2016 - github.com/yon3zu
LinuXploit