def generic_update_command(self, name, getter_name='get', getter_type=None, setter_name='create_or_update', setter_type=None, setter_arg_name='parameters', child_collection_prop_name=None, child_collection_key='name', child_arg_name='item_name', custom_func_name=None, custom_func_type=None, **kwargs): from azure.cli.core.commands.arm import _cli_generic_update_command self._check_stale() merged_kwargs = self._flatten_kwargs(kwargs, get_command_type_kwarg()) merged_kwargs_custom = self._flatten_kwargs(kwargs, get_command_type_kwarg(custom_command=True)) # don't inherit deprecation info from command group merged_kwargs['deprecate_info'] = kwargs.get('deprecate_info', None) getter_op = self._resolve_operation(merged_kwargs, getter_name, getter_type) setter_op = self._resolve_operation(merged_kwargs, setter_name, setter_type) custom_func_op = self._resolve_operation(merged_kwargs_custom, custom_func_name, custom_func_type, custom_command=True) if custom_func_name else None _cli_generic_update_command( self.command_loader, '{} {}'.format(self.group_name, name), getter_op=getter_op, setter_op=setter_op, setter_arg_name=setter_arg_name, custom_function_op=custom_func_op, child_collection_prop_name=child_collection_prop_name, child_collection_key=child_collection_key, child_arg_name=child_arg_name, **merged_kwargs)
def generic_update_command(self, name, getter_name='get', getter_type=None, setter_name='create_or_update', setter_type=None, setter_arg_name='parameters', child_collection_prop_name=None, child_collection_key='name', child_arg_name='item_name', custom_func_name=None, custom_func_type=None, **kwargs): from azure.cli.core.commands.arm import _cli_generic_update_command self._check_stale() merged_kwargs = self._flatten_kwargs(kwargs, get_command_type_kwarg()) merged_kwargs_custom = self._flatten_kwargs(kwargs, get_command_type_kwarg(custom_command=True)) # don't inherit deprecation info from command group merged_kwargs['deprecate_info'] = kwargs.get('deprecate_info', None) getter_op = self._resolve_operation(merged_kwargs, getter_name, getter_type) setter_op = self._resolve_operation(merged_kwargs, setter_name, setter_type) custom_func_op = self._resolve_operation(merged_kwargs_custom, custom_func_name, custom_func_type, custom_command=True) if custom_func_name else None _cli_generic_update_command( self.command_loader, '{} {}'.format(self.group_name, name), getter_op=getter_op, setter_op=setter_op, setter_arg_name=setter_arg_name, custom_function_op=custom_func_op, child_collection_prop_name=child_collection_prop_name, child_collection_key=child_collection_key, child_arg_name=child_arg_name, **merged_kwargs)
def _resolve_operation(self, kwargs, name, command_type=None, custom_command=False): source_kwarg = get_command_type_kwarg(custom_command) operations_tmpl = None if command_type: # Top priority: specified command_type for the parameter operations_tmpl = command_type.settings.get( 'operations_tmpl', None) if not operations_tmpl: # Second source: general operations_tmpl set for the command kwargs operations_tmpl = kwargs.get('operations_tmpl', None) if not operations_tmpl: # Final source: retrieve the operations_tmpl from the relevant 'command_type' or 'custom_command_type' command_type = kwargs.get(source_kwarg, None) operations_tmpl = command_type.settings.get( 'operations_tmpl', None) if not operations_tmpl: raise ValueError( "command authoring error: unable to resolve 'operations_tmpl'") return operations_tmpl.format(name)
def _show_command(self, name, getter_name='get', getter_type=None, custom_command=False, **kwargs): from azure.cli.core.commands.arm import _cli_show_command self._check_stale() merged_kwargs = self._flatten_kwargs( kwargs, get_command_type_kwarg(custom_command)) # don't inherit deprecation info from command group merged_kwargs['deprecate_info'] = kwargs.get('deprecate_info', None) if getter_type: merged_kwargs = _merge_kwargs(getter_type.settings, merged_kwargs, CLI_COMMAND_KWARGS) getter_op = self._resolve_operation(merged_kwargs, getter_name, getter_type, custom_command=custom_command) _cli_show_command(self.command_loader, '{} {}'.format(self.group_name, name), getter_op=getter_op, custom_command=custom_command, **merged_kwargs)
def _get_operations_tmpl(cmd, custom_command=False): operations_tmpl = cmd.command_kwargs.get('operations_tmpl') or \ cmd.command_kwargs.get(get_command_type_kwarg(custom_command)).settings['operations_tmpl'] if not operations_tmpl: raise CLIError( "command authoring error: cmd '{}' does not have an operations_tmpl." .format(cmd.name)) return operations_tmpl
def _show_command(self, name, getter_name='get', getter_type=None, custom_command=False, **kwargs): from azure.cli.core.commands.arm import _cli_show_command self._check_stale() merged_kwargs = self._flatten_kwargs(kwargs, get_command_type_kwarg(custom_command)) # don't inherit deprecation info from command group merged_kwargs['deprecate_info'] = kwargs.get('deprecate_info', None) if getter_type: merged_kwargs = _merge_kwargs(getter_type.settings, merged_kwargs, CLI_COMMAND_KWARGS) getter_op = self._resolve_operation(merged_kwargs, getter_name, getter_type, custom_command=custom_command) _cli_show_command(self.command_loader, '{} {}'.format(self.group_name, name), getter_op=getter_op, custom_command=custom_command, **merged_kwargs)
def _command(self, name, method_name, custom_command=False, **kwargs): self._check_stale() merged_kwargs = self._flatten_kwargs(kwargs, get_command_type_kwarg(custom_command)) # don't inherit deprecation info from command group merged_kwargs['deprecate_info'] = kwargs.get('deprecate_info', None) operations_tmpl = merged_kwargs['operations_tmpl'] command_name = '{} {}'.format(self.group_name, name) if self.group_name else name self.command_loader._cli_command(command_name, # pylint: disable=protected-access operation=operations_tmpl.format(method_name), **merged_kwargs) return command_name
def _resolve_operation(self, kwargs, name, command_type=None, custom_command=False): source_kwarg = get_command_type_kwarg(custom_command) operations_tmpl = None if command_type: # Top priority: specified command_type for the parameter operations_tmpl = command_type.settings.get('operations_tmpl', None) if not operations_tmpl: # Second source: general operations_tmpl set for the command kwargs operations_tmpl = kwargs.get('operations_tmpl', None) if not operations_tmpl: # Final source: retrieve the operations_tmpl from the relevant 'command_type' or 'custom_command_type' command_type = kwargs.get(source_kwarg, None) operations_tmpl = command_type.settings.get('operations_tmpl', None) if not operations_tmpl: raise ValueError("command authoring error: unable to resolve 'operations_tmpl'") return operations_tmpl.format(name)
def _get_client_factory(_, custom_command=False, **kwargs): command_type = kwargs.get(get_command_type_kwarg(custom_command), None) factory = kwargs.get('client_factory', None) if not factory and command_type: factory = command_type.settings.get('client_factory', None) return factory
def _get_client_factory(_, custom_command=False, **kwargs): command_type = kwargs.get(get_command_type_kwarg(custom_command), None) factory = kwargs.get('client_factory', None) if not factory and command_type: factory = command_type.settings.get('client_factory', None) return factory
def _get_operations_tmpl(cmd, custom_command=False): operations_tmpl = cmd.command_kwargs.get('operations_tmpl') or \ cmd.command_kwargs.get(get_command_type_kwarg(custom_command)).settings['operations_tmpl'] if not operations_tmpl: raise CLIError("command authoring error: cmd '{}' does not have an operations_tmpl.".format(cmd.name)) return operations_tmpl