Esempio n. 1
0
 def invoke(self, client, operation_name, parameters, parsed_args,
            parsed_globals):
     py_operation_name = xform_name(operation_name)
     if client.can_paginate(py_operation_name) and parsed_globals.paginate:
         response = client.get_paginator(py_operation_name).paginate(
             **parameters)
     else:
         response = getattr(client,
                            xform_name(operation_name))(**parameters)
     self._display_response(operation_name, response, parsed_globals)
     return True
Esempio n. 2
0
 def _create_methods(self, service_model):
     op_dict = {}
     for operation_name in service_model.operation_names:
         py_operation_name = xform_name(operation_name)
         op_dict[py_operation_name] = self._create_api_method(
             py_operation_name, operation_name, service_model)
     return op_dict
Esempio n. 3
0
 def filter_operation(self, operation_name, form_factor,
                      operation_form_factors):
     """
     Replace the named operation in this command's command table with a
     filtered one.
     """
     command_table = self._get_command_table()
     cli_name = xform_name(operation_name, '-')
     command_table[cli_name] = FilteredServiceOperation(
         name=cli_name,
         parent_name=self._name,
         form_factor=form_factor,
         operation_form_factors=operation_form_factors)
Esempio n. 4
0
 def get_param_model(self, dotted_name):
     service_name, operation_name, param_name = dotted_name.split('.')
     service_model = self.driver.get_service_model(service_name)
     operation = service_model.operation_model(operation_name)
     input_shape = operation.input_shape
     required_arguments = input_shape.required_members
     is_required = param_name in required_arguments
     member_shape = input_shape.members[param_name]
     type_name = member_shape.type_name
     cli_arg_name = xform_name(param_name, '-')
     if type_name == 'boolean':
         cls = BooleanArgument
     elif type_name == 'list':
         cls = ListArgument
     else:
         cls = CLIArgument
     return cls(cli_arg_name, member_shape, mock.Mock(), is_required)
Esempio n. 5
0
 def build_translation_map(self):
     operation_model = self.help_command.obj
     d = {}
     for cli_name, cli_argument in self.help_command.arg_table.items():
         if cli_argument.argument_model is not None:
             argument_name = cli_argument.argument_model.name
             if argument_name in d:
                 previous_mapping = d[argument_name]
                 # If the argument name is a boolean argument, we want the
                 # the translation to default to the one that does not start
                 # with --no-. So we check if the cli parameter currently
                 # being used starts with no- and if stripping off the no-
                 # results in the new proposed cli argument name. If it
                 # does, we assume we have the postive form of the argument
                 # which is the name we want to use in doc translations.
                 if cli_argument.cli_type_name == 'boolean' and \
                    previous_mapping.startswith('no-') and \
                    cli_name == previous_mapping[3:]:
                     d[argument_name] = cli_name
             else:
                 d[argument_name] = cli_name
     for operation_name in operation_model.service_model.operation_names:
         d[operation_name] = xform_name(operation_name, '-')
     return d
Esempio n. 6
0
 def _create_argument_table(self):
     argument_table = OrderedDict()
     input_shape = self._operation_model.input_shape
     required_arguments = []
     arg_dict = {}
     if input_shape is not None:
         required_arguments = input_shape.required_members
         arg_dict = input_shape.members
     for arg_name, arg_shape in arg_dict.items():
         cli_arg_name = xform_name(arg_name, '-')
         arg_class = self.ARG_TYPES.get(arg_shape.type_name,
                                        self.DEFAULT_ARG_CLASS)
         is_required = arg_name in required_arguments
         arg_object = arg_class(name=cli_arg_name,
                                argument_model=arg_shape,
                                is_required=is_required,
                                operation_model=self._operation_model,
                                serialized_name=arg_name,
                                no_paramfile=arg_shape.is_no_paramfile)
         arg_object.add_to_arg_table(argument_table)
     add_pagination_params(self._operation_model, argument_table)
     add_cli_input_json(self._operation_model, argument_table)
     add_generate_skeleton(self._operation_model, argument_table)
     return argument_table
Esempio n. 7
0
 def _create_command_table(self):
     command_table = OrderedDict()
     service_model = self._get_service_model()
     for operation_name in service_model.operation_names:
         cli_name = xform_name(operation_name, '-')
         operation_model = service_model.operation_model(operation_name)
         command_table[cli_name] = ServiceOperation(
             name=cli_name,
             parent_name=self._name,
             operation_model=operation_model,
             operation_caller=CLIOperationCaller())
     try:
         __import__('cdpcli.extensions.%s.register' % self._name,
                    fromlist=['register']).register(command_table)
     except ImportError as err:
         py3_err = "No module named 'cdpcli.extensions.%s'" % self._name
         py2_err = "No module named %s.register" % self._name
         if py2_err not in str(err) and py3_err not in str(err):
             # Looks like a different error than missing extensions.
             LOG.warn("Failed to import service (%s) extension: %s",
                      self._name, err)
         pass
     self._add_lineage(command_table)
     return command_table
Esempio n. 8
0
 def build_translation_map(self):
     d = {}
     service_model = self.help_command.obj
     for operation_name in service_model.operation_names:
         d[operation_name] = xform_name(operation_name, '-')
     return d
Esempio n. 9
0
 def _create_name_mapping(self, service_model):
     mapping = {}
     for operation_name in service_model.operation_names:
         py_operation_name = xform_name(operation_name)
         mapping[py_operation_name] = operation_name
     return mapping
Esempio n. 10
0
def _get_all_cli_input_tokens(operation_model):
    if operation_model.can_paginate:
        yield xform_name(operation_model.paging_input_token, '-')
        yield xform_name(operation_model.paging_page_size, '-')