From a871b70be9f7cf271a95262e8f70bc6bc8e31c04 Mon Sep 17 00:00:00 2001 From: Peter Razumovsky Date: Fri, 20 Mar 2015 09:30:57 +0300 Subject: [PATCH] Fix resources allocation in documentation Allocation of contributed resources generates incorrectly, so this patch fixes res allocation. Now contributed resources are in Contributed Heat Resource Types page and integrated are in OpenStack Resource Types page. Escaping from using env because of all_resources loaded from PluginMapping. Change-Id: I6d7c501f231c546f909c3ed7f19fc8d1fc04e927 Closes-bug: #1433675 --- .../heat_keystone/resources/group.py | 41 +------ .../heat_keystone/resources/project.py | 32 +----- .../heat_keystone/resources/role.py | 17 +-- .../heat_keystone/resources/user.py | 61 +--------- .../rackspace/resources/cloud_server.py | 6 +- doc/source/ext/resources.py | 106 ++++++++++++------ doc/source/template_guide/cfn.rst | 2 +- doc/source/template_guide/contrib.rst | 21 ++-- doc/source/template_guide/openstack.rst | 2 +- 9 files changed, 88 insertions(+), 200 deletions(-) diff --git a/contrib/heat_keystone/heat_keystone/resources/group.py b/contrib/heat_keystone/heat_keystone/resources/group.py index 3f47799ca6..38c3c56c56 100644 --- a/contrib/heat_keystone/heat_keystone/resources/group.py +++ b/contrib/heat_keystone/heat_keystone/resources/group.py @@ -20,46 +20,7 @@ from heat.engine import support class KeystoneGroup(role_assignments.KeystoneRoleAssignment): - ''' - Heat Template Resource for Keystone Group. - - heat_template_version: 2013-05-23 - - description: Sample Keystone Group template - - parameters: - group_name: - type: string - description: Keystone group name - group_description: - type: string - description: Keystone group description - group_domain: - type: string - description: Keystone group domain name - group_role: - type: string - description: role - group_role_domain: - type: string - description: group role domain - group_role_project: - type: string - description: group role project - - resources: - admin_group: - type: OS::Keystone::Group - properties: - name: {get_param: group_name} - domain: {get_param: group_domain} - description: {get_param: group_description} - roles: - - role: {get_param: group_role} - domain: {get_param: group_role_domain} - - role: {get_param: group_role} - project: {get_param: group_role_project} - ''' + """Heat Template Resource for Keystone Group.""" support_status = support.SupportStatus( version='2015.1', diff --git a/contrib/heat_keystone/heat_keystone/resources/project.py b/contrib/heat_keystone/heat_keystone/resources/project.py index 1950804167..84a81df938 100644 --- a/contrib/heat_keystone/heat_keystone/resources/project.py +++ b/contrib/heat_keystone/heat_keystone/resources/project.py @@ -19,37 +19,7 @@ from heat.engine import support class KeystoneProject(resource.Resource): - ''' - Heat Template Resource for Keystone Project. - - heat_template_version: 2013-05-23 - - description: Sample Keystone Project template - - parameters: - project_name: - type: string - description: Keystone project name - project_description: - type: string - description: Keystone project description - project_enabled: - type: boolean - description: Keystone project is enabled or disabled - project_domain: - type: string - description: Keystone project domain name or id - - resources: - admin_project: - type: OS::Keystone::Project - properties: - name: {get_param: project_name} - domain: {get_param: project_domain} - description: {get_param: project_description} - enabled: {get_param: project_enabled} - - ''' + """Heat Template Resource for Keystone Project.""" support_status = support.SupportStatus( version='2015.1', diff --git a/contrib/heat_keystone/heat_keystone/resources/role.py b/contrib/heat_keystone/heat_keystone/resources/role.py index 00347cd460..3005dce56c 100644 --- a/contrib/heat_keystone/heat_keystone/resources/role.py +++ b/contrib/heat_keystone/heat_keystone/resources/role.py @@ -18,22 +18,7 @@ from heat.engine import support class KeystoneRole(resource.Resource): - ''' - Heat Template Resource for Keystone Role. - - heat_template_version: 2013-05-23 - - parameters: - role_name: - type: string - description: Keystone role name - - resources: - sample_role: - type: OS::Keystone::Role - properties: - name: {get_param: role_name} - ''' + """Heat Template Resource for Keystone Role.""" support_status = support.SupportStatus( version='2015.1', diff --git a/contrib/heat_keystone/heat_keystone/resources/user.py b/contrib/heat_keystone/heat_keystone/resources/user.py index 4c34fd8395..dced35325a 100644 --- a/contrib/heat_keystone/heat_keystone/resources/user.py +++ b/contrib/heat_keystone/heat_keystone/resources/user.py @@ -20,66 +20,7 @@ from heat.engine import support class KeystoneUser(role_assignments.KeystoneRoleAssignment): - ''' - Heat Template Resource for Keystone User. - - heat_template_version: 2013-05-23 - - description: Sample Keystone User template - - parameters: - user_name: - type: string - description: Keystone user name - user_description: - type: string - description: Keystone user description - user_enabled: - type: boolean - description: Keystone user is enabled or disabled - user_domain: - type: string - description: Keystone user domain name - user_email: - type: string - description: Keystone user email address - user_password: - type: string - description: Keystone user password - user_default_project: - type: string - description: Keystone user default project id - user_groups: - type: comma_delimited_list - description: Keystone groups, where this user is part of - group_role: - type: string - description: role - group_role_domain: - type: string - description: group role domain - group_role_project: - type: string - description: group role project - - resources: - admin_user: - type: OS::Keystone::User - properties: - name: {get_param: user_name} - domain: {get_param: user_domain} - description: {get_param: user_description} - enabled: {get_param: user_enabled} - email: {get_param: user_email} - password: {get_param: user_password} - default_project: {get_param: user_default_project} - groups: {get_param: user_groups} - roles: - - role: {get_param: group_role} - domain: {get_param: group_role_domain} - - role: {get_param: group_role} - project: {get_param: group_role_project} - ''' + """Heat Template Resource for Keystone User.""" support_status = support.SupportStatus( version='2015.1', diff --git a/contrib/rackspace/rackspace/resources/cloud_server.py b/contrib/rackspace/rackspace/resources/cloud_server.py index 2dd93a0190..f75084655b 100644 --- a/contrib/rackspace/rackspace/resources/cloud_server.py +++ b/contrib/rackspace/rackspace/resources/cloud_server.py @@ -29,7 +29,11 @@ LOG = logging.getLogger(__name__) class CloudServer(server.Server): - """Resource for Rackspace Cloud Servers.""" + """Resource for Rackspace Cloud Servers. + + This resource overloads existent integrated OS::Nova::Server resource and + is used for Rackspace Cloud Servers. + """ # Managed Cloud automation statuses MC_STATUS_IN_PROGRESS = 'In Progress' diff --git a/doc/source/ext/resources.py b/doc/source/ext/resources.py index b322ec6649..77ce8f790c 100644 --- a/doc/source/ext/resources.py +++ b/doc/source/ext/resources.py @@ -17,24 +17,27 @@ import itertools from docutils import core from docutils import nodes import pydoc +import six from sphinx.util import compat from heat.common.i18n import _ from heat.engine import attributes -from heat.engine import environment from heat.engine import plugin_manager from heat.engine import properties -from heat.engine import resources from heat.engine import support _CODE_NAMES = {'2014.1': 'Icehouse', '2014.2': 'Juno', '2015.1': 'Kilo'} -global_env = environment.Environment({}, user_env=False) +all_resources = {} -class resourcepages(nodes.General, nodes.Element): +class integratedrespages(nodes.General, nodes.Element): + pass + + +class contribresourcepages(nodes.General, nodes.Element): pass @@ -45,33 +48,38 @@ class ResourcePages(compat.Directive): final_argument_whitespace = False option_spec = {} + def path(self): + return None + def run(self): prefix = self.arguments and self.arguments.pop() or None content = [] - for resource_type, resource_class in _all_resources(prefix): - self.resource_type = resource_type - self.resource_class = resource_class - section = self._section(content, resource_type, '%s') + for resource_type, resource_classes in _filter_resources(prefix, + self.path()): + for resource_class in resource_classes: + self.resource_type = resource_type + self.resource_class = resource_class + section = self._section(content, resource_type, '%s') - self.props_schemata = properties.schemata( - self.resource_class.properties_schema) - self.attrs_schemata = attributes.schemata( - self.resource_class.attributes_schema) + self.props_schemata = properties.schemata( + self.resource_class.properties_schema) + self.attrs_schemata = attributes.schemata( + self.resource_class.attributes_schema) - self._status_str(resource_class.support_status, section) + self._status_str(resource_class.support_status, section) - cls_doc = pydoc.getdoc(resource_class) - if cls_doc: - # allow for rst in the class comments - cls_nodes = core.publish_doctree(cls_doc).children - section.extend(cls_nodes) + cls_doc = pydoc.getdoc(resource_class) + if cls_doc: + # allow for rst in the class comments + cls_nodes = core.publish_doctree(cls_doc).children + section.extend(cls_nodes) - self.contribute_properties(section) - self.contribute_attributes(section) + self.contribute_properties(section) + self.contribute_attributes(section) - self.contribute_hot_syntax(section) - self.contribute_yaml_syntax(section) - self.contribute_json_syntax(section) + self.contribute_hot_syntax(section) + self.contribute_yaml_syntax(section) + self.contribute_json_syntax(section) return content @@ -323,18 +331,36 @@ Resources: definition.append(def_para) -def _all_resources(prefix=None): - type_names = sorted(global_env.get_types()) - if prefix is not None: - def prefix_match(name): - return name.startswith(prefix) +class IntegrateResourcePages(ResourcePages): - type_names = itertools.ifilter(prefix_match, type_names) + def path(self): + return 'heat.engine.resources' - def resource_type(name): - return name, global_env.get_class(name) - return itertools.imap(resource_type, type_names) +class ContribResourcePages(ResourcePages): + + def path(self): + return 'heat.engine.plugins' + + +def _filter_resources(prefix=None, path=None): + def prefix_match(name): + return prefix is None or name.startswith(prefix) + + def path_match(cls): + return path is None or cls.__module__.startswith(path) + + filtered_resources = {} + for name in sorted(all_resources.keys()): + if prefix_match(name): + for cls in all_resources.get(name): + if path_match(cls): + if filtered_resources.get(name) is not None: + filtered_resources[name].append(cls) + else: + filtered_resources[name] = [cls] + + return sorted(six.iteritems(filtered_resources)) def _load_all_resources(): @@ -342,12 +368,20 @@ def _load_all_resources(): resource_mapping = plugin_manager.PluginMapping('resource') res_plugin_mappings = resource_mapping.load_all(manager) - resources._register_resources(global_env, res_plugin_mappings) - environment.read_global_environment(global_env) + for mapping in res_plugin_mappings: + name, cls = mapping + if all_resources.get(name) is not None: + all_resources[name].append(cls) + else: + all_resources[name] = [cls] def setup(app): _load_all_resources() - app.add_node(resourcepages) + app.add_node(integratedrespages) - app.add_directive('resourcepages', ResourcePages) + app.add_directive('integratedrespages', IntegrateResourcePages) + + app.add_node(contribresourcepages) + + app.add_directive('contribrespages', ContribResourcePages) diff --git a/doc/source/template_guide/cfn.rst b/doc/source/template_guide/cfn.rst index 1ffb5e669f..0065e66059 100644 --- a/doc/source/template_guide/cfn.rst +++ b/doc/source/template_guide/cfn.rst @@ -13,4 +13,4 @@ CloudFormation Compatible Resource Types ---------------------------------------- -.. resourcepages:: AWS:: +.. integratedrespages:: AWS:: diff --git a/doc/source/template_guide/contrib.rst b/doc/source/template_guide/contrib.rst index 947dc3c6bc..e6e55db171 100644 --- a/doc/source/template_guide/contrib.rst +++ b/doc/source/template_guide/contrib.rst @@ -14,6 +14,11 @@ Contributed Heat Resource Types =============================== +.. rubric:: These resources are not enabled by default. + +.. contribrespages:: OS:: + + Rackspace Cloud Resource Types ------------------------------ @@ -31,7 +36,7 @@ properly. More information about them can be found in the `_. -.. resourcepages:: Rackspace:: +.. contribrespages:: Rackspace:: DockerInc Resource @@ -44,16 +49,4 @@ requires the `docker-py `_ package. You can find more information in the `DOCKER_README `_. -.. resourcepages:: DockerInc:: - -Nova Flavor Resource --------------------- - -.. rubric:: This resource is not enabled by default. - -This plugin enables dynamic creation of Nova flavors through Heat. You can -find more information in the `NOVA_FLAVOR_README -`_. - -.. resourcepages:: OS::Nova::Flavor +.. contribrespages:: DockerInc:: diff --git a/doc/source/template_guide/openstack.rst b/doc/source/template_guide/openstack.rst index f342a6e0b2..45db2ccf3f 100644 --- a/doc/source/template_guide/openstack.rst +++ b/doc/source/template_guide/openstack.rst @@ -14,4 +14,4 @@ OpenStack Resource Types ------------------------ -.. resourcepages:: OS:: +.. integratedrespages:: OS::