diff --git a/openshift/ansiblegen/docstrings.py b/openshift/ansiblegen/docstrings.py index f7b2c90e..c217e452 100644 --- a/openshift/ansiblegen/docstrings.py +++ b/openshift/ansiblegen/docstrings.py @@ -22,7 +22,7 @@ from .. import __k8s_client_version__ from ..client import models as openshift_models from ..helper.exceptions import KubernetesException -from ..helper.ansible import KubernetesAnsibleModuleHelper, OpenShiftAnsibleModuleHelper +from ..helper.ansible import KubernetesAnsibleModuleHelper, OpenShiftAnsibleModuleHelper, PYTHON_KEYWORD_MAPPING logger = logging.getLogger(__name__) @@ -129,8 +129,9 @@ def add_option(pname, pdict, descr=None): if pdict.get('type') and pdict.get('type') != 'str': doc_string['options'][pname]['type'] = pdict['type'] - for param_name in sorted([x for x, _ in self.helper.argspec.items()]): - param_dict = self.helper.argspec[param_name] + for raw_param_name in sorted([x for x, _ in self.helper.argspec.items()]): + param_name = PYTHON_KEYWORD_MAPPING.get(raw_param_name, raw_param_name) + param_dict = self.helper.argspec[raw_param_name] if param_name.endswith('params'): descr = [self.__params_descr(param_name)] add_option(param_name, param_dict, descr=descr) @@ -200,10 +201,11 @@ def __get_attributes(self, obj, doc_key=None): """ model_class = type(obj) model_name = self.helper.get_base_model_name_snake(model_class.__name__) - for attribute in dir(model_class): - if isinstance(getattr(model_class, attribute), property): - kind = obj.swagger_types[attribute] - docs = inspect.getdoc(getattr(type(obj), attribute)) + for raw_attribute in dir(model_class): + attribute = PYTHON_KEYWORD_MAPPING.get(raw_attribute, raw_attribute) + if isinstance(getattr(model_class, raw_attribute), property): + kind = obj.swagger_types[raw_attribute] + docs = inspect.getdoc(getattr(type(obj), raw_attribute)) string_list = self.__doc_clean_up(docs.split('\n')) if kind in ('str', 'int', 'bool'): doc_key[attribute] = CommentedMap() diff --git a/openshift/ansiblegen/examples/openshift_v1_build_config.yml b/openshift/ansiblegen/examples/openshift_v1_build_config.yml new file mode 100644 index 00000000..b285c4e5 --- /dev/null +++ b/openshift/ansiblegen/examples/openshift_v1_build_config.yml @@ -0,0 +1,30 @@ +# v1_build_config.yml +# +--- +tasks: + +- create: + name: test + namespace: namespace + verify_ssl: False + labels: + app: test + output_to_kind: ImageStreamTag + output_to_name: test:latest + source_git_uri: "https://test.example.com/test.git" + source_secret_name: git + source_type: Git + strategy_source_strategy_from_kind: ImageStreamTag + strategy_source_strategy_from_name: nodejs:6 + strategy_source_strategy_from_namespace: openshift + strategy_type: Source + triggers: + - github: + secret: 8kdCwBdWpup5OydYqXCj + type: GitHub + - generic: + secret: wuve0D41bIFHPU_DzT5- + type: Generic + - type: ConfigChange + - image_change: {} + type: ImageChange diff --git a/openshift/helper/ansible.py b/openshift/helper/ansible.py index 4a1d2ec2..a7756fd7 100644 --- a/openshift/helper/ansible.py +++ b/openshift/helper/ansible.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import base64 import copy import json +import base64 import logging +from keyword import kwlist import string_utils @@ -14,6 +15,8 @@ # Attributes in argspec not needed by Ansible ARG_ATTRIBUTES_BLACKLIST = ('description', 'auth_option', 'property_path') +PYTHON_KEYWORD_MAPPING = dict(zip(map('_{}'.format, kwlist), kwlist)) +PYTHON_KEYWORD_MAPPING.update(dict([reversed(item) for item in PYTHON_KEYWORD_MAPPING.items()])) logger = logging.getLogger(__name__) @@ -343,7 +346,8 @@ def __set_obj_attribute(self, obj, property_path, param_value, param_name): json.dumps(param_value))) while len(property_path) > 0: - prop_name = property_path.pop(0) + raw_prop_name = property_path.pop(0) + prop_name = PYTHON_KEYWORD_MAPPING.get(raw_prop_name, raw_prop_name) prop_kind = obj.swagger_types[prop_name] if prop_kind in PRIMITIVES: try: @@ -613,7 +617,8 @@ def add_meta(prop_name, prop_prefix, prop_alt_prefix): prop_paths.append(prop_name) args[prop_prefix + prop_name]['property_path'] = prop_paths - for prop, prop_attributes in properties.items(): + for raw_prop, prop_attributes in properties.items(): + prop = PYTHON_KEYWORD_MAPPING.get(raw_prop, raw_prop) logger.debug("Prop: {0} attributes: {1}".format(prop, str(prop_attributes))) if prop in ('api_version', 'status', 'kind', 'items') and not prefix: # Don't expose these properties