Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions openshift/ansiblegen/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
30 changes: 30 additions & 0 deletions openshift/ansiblegen/examples/openshift_v1_build_config.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 8 additions & 3 deletions openshift/helper/ansible.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down