1# -*- coding: utf-8 -*- # 2# Copyright 2019 Google LLC. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15"""Shared resource flags for OS Config commands.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import unicode_literals 20 21from googlecloudsdk.calliope.concepts import concepts 22from googlecloudsdk.command_lib.util.concepts import concept_parsers 23from googlecloudsdk.command_lib.util.concepts import presentation_specs 24 25 26def PatchJobAttributeConfig(): 27 return concepts.ResourceParameterAttributeConfig( 28 name='patch_job', help_text='An OS patch job.') 29 30 31def GetPatchJobResourceSpec(): 32 return concepts.ResourceSpec( 33 'osconfig.projects.patchJobs', 34 resource_name='patch_job', 35 projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG, 36 patchJobsId=PatchJobAttributeConfig()) 37 38 39def CreatePatchJobResourceArg(verb, plural=False): 40 """Creates a resource argument for a OS Config patch job. 41 42 Args: 43 verb: str, The verb to describe the resource, such as 'to describe'. 44 plural: bool, If True, use a resource argument that returns a list. 45 46 Returns: 47 PresentationSpec for the resource argument. 48 """ 49 noun = 'Patch job' + ('s' if plural else '') 50 return presentation_specs.ResourcePresentationSpec( 51 'patch_job', 52 GetPatchJobResourceSpec(), 53 '{} {}'.format(noun, verb), 54 required=True, 55 plural=plural, 56 prefixes=False) 57 58 59def AddPatchJobResourceArg(parser, verb, plural=False): 60 """Creates a resource argument for a OS Config patch job. 61 62 Args: 63 parser: The parser for the command. 64 verb: str, The verb to describe the resource, such as 'to describe'. 65 plural: bool, If True, use a resource argument that returns a list. 66 """ 67 concept_parsers.ConceptParser([CreatePatchJobResourceArg( 68 verb, plural)]).AddToParser(parser) 69 70 71def PatchDeploymentAttributeConfig(): 72 return concepts.ResourceParameterAttributeConfig( 73 name='patch_deployment', help_text='An OS patch deployment.') 74 75 76def GetPatchDeploymentResourceSpec(): 77 return concepts.ResourceSpec( 78 'osconfig.projects.patchDeployments', 79 resource_name='patch_deployment', 80 projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG, 81 patchDeploymentsId=PatchDeploymentAttributeConfig()) 82 83 84def CreatePatchDeploymentResourceArg(verb, plural=False): 85 """Creates a resource argument for a OS Config patch deployment. 86 87 Args: 88 verb: str, The verb to describe the resource, such as 'to describe'. 89 plural: bool, If True, use a resource argument that returns a list. 90 91 Returns: 92 PresentationSpec for the resource argument. 93 """ 94 noun = 'Patch deployment' + ('s' if plural else '') 95 return presentation_specs.ResourcePresentationSpec( 96 'patch_deployment', 97 GetPatchDeploymentResourceSpec(), 98 '{} {}'.format(noun, verb), 99 required=True, 100 plural=plural, 101 prefixes=False) 102 103 104def AddPatchDeploymentResourceArg(parser, verb, plural=False): 105 """Creates a resource argument for a OS Config patch deployment. 106 107 Args: 108 parser: The parser for the command. 109 verb: str, The verb to describe the resource, such as 'to describe'. 110 plural: bool, If True, use a resource argument that returns a list. 111 """ 112 concept_parsers.ConceptParser( 113 [CreatePatchDeploymentResourceArg(verb, plural)]).AddToParser(parser) 114