![]() ![]() Related ( 'project' ), required = False, display = False ) workflow = models. Related ( 'inventory_source' ), required = False, display = False ) project = models. Related ( 'job_template' ), required = False, display = False ) inventory_source = models. # Plus, one and only one field should be provided. note these fields will only be used during creation. Field ( required = False, display = False ) # Unified jt fields. Field ( unique = True ) description = models. Resource ): """A resource for schedules.""" cli_help = 'Manage schedules within Ansible Tower.' endpoint = '/schedules/' # General fields. endpoint = old_endpoint return result decorator = decorator_with_pk if has_pk else decorator_without_pk for item in CLICK_ATTRS : setattr ( decorator, item, getattr ( func, item, )) decorator. endpoint = new_endpoint result = func ( obj, pk = pk, * args, ** kwargs ) obj. endpoint new_endpoint = helper ( kwargs, obj ) if is_create : obj. endpoint = old_endpoint return result def decorator_with_pk ( obj, pk = None, * args, ** kwargs ): old_endpoint = obj. endpoint = new_endpoint result = func ( obj, * args, ** kwargs ) obj. ![]() ![]() UsageError ( 'You must provide exactly one unified job' ' template field during creation.' ) def decorator_without_pk ( obj, * args, ** kwargs ): old_endpoint = obj. join (], str ( unified_job_template ), 'schedules/' ]) elif is_create : raise exc. UsageError ( 'More than one unified job template fields provided, ' 'please tighten your criteria.' ) if unified_job_template is not None : kwargs = unified_job_template obj. pop ( item ) if unified_job_template is None : unified_job_template = ( item, jt_id ) else : raise exc. get ( item, None ) is not None : jt_id = kwargs. """ unified_job_template = None for item in UNIFIED_JT : if kwargs. """ def helper ( kwargs, obj ): """The helper function preceding actual function that aggregates unified jt fields. Raises: exc.UsageError: Either more than one unified jt fields are provided, or none is provided when is_create flag is set. Returns: A function with necessary click-related attributes whose keyworded arguments are aggregated. has_pk: Boolean flag showing whether this method uses pk as argument. is_create: Boolean flag showing whether this method is create. Args: func: The CURD method to be decorated. import click from tower_cli import models, exceptions as exc from tower_cli.cli import types UNIFIED_JT = CLICK_ATTRS = ( '_click_params_', '_cli_command', '_cli_command_attrs' ) def jt_aggregate ( func, is_create = False, has_pk = False ): """Decorator to aggregate unified_jt-related fields. # See the License for the specific language governing permissions and # limitations under the License. # You may obtain a copy of the License at # 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. # Aaron Tan # Licensed under the Apache License, Version 2.0 (the "License") # you may not use this file except in compliance with the License. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |