Skip to content

Commit

Permalink
vmware.vmware_rest: Generate action_groups (#78)
Browse files Browse the repository at this point in the history
* vmware.vmware_rest: Generate action_groups

* Use requires_ansible from manifest

* Add requires_ansible to manifest

* Refactor to implement a unit test

* Add unit test

* Fix generate_runtime_yml

* Log generating meta/runtime.yml
  • Loading branch information
mariolenz authored Jan 11, 2024
1 parent 15a0742 commit e775adc
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Giving `module_openapi` as an input to Ansible.content builder scaffolding tool
- *collection:path*: Destination folder where the user wants the output of the scaffolding tool to be stored.
- *collection:namespace*: Ansible collection org name.
- *collection:name*: Ansible collection name.
- *collection:requires_ansible*: The Ansible (core) version the collection requires (only used to generate `vmware.vmware_rest`).
- *plugin:rm_swagger_json*: Swagger JSON/JSON file where OEMs API with all of its REST operations are defined.
- *plugin:content*: The content that the builder generates (values: cloud/security default: security).
- *plugin:api_object_path*: API for which resource module needs to be generated by the tool. When *plugin:content* is set to *cloud* this parameter should be set to the path of the schema files.
Expand Down Expand Up @@ -218,6 +219,7 @@ collection:
path: /collections/ansible_collections/vmware/vmware_rest
namespace: vmware
name: vmware_rest
requires_ansible: 2.14.0
plugins:
- type: module_openapi
name: "vmware_rest"
Expand Down
3 changes: 3 additions & 0 deletions changelogs/fragments/75-vmware_rest-action_groups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- "Add requires_ansible to manifest (https://github.com/ansible-community/ansible.content_builder/pull/76)."
- "Generate action_groups for the vmware.vmware_rest collection (https://github.com/ansible-community/ansible.content_builder/issues/75)."
11 changes: 11 additions & 0 deletions plugins/action/generate_cloud_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
)
# import for amazon.cloud doc generation
from ansible_collections.ansible.content_builder.plugins.plugin_utils.cloud_utils.generator import generate_documentation
# import for vmware.vware_rest runtime.yml generation
from ansible_collections.ansible.content_builder.plugins.plugin_utils.cloud_utils.generator import generate_runtime_yml


# vmware specific
Expand Down Expand Up @@ -1325,6 +1327,15 @@ def generate_vmware_rest(args: Iterable, role_path: str):
role_path=role_path
)
module_list.append(module.name)

print("Generating meta/runtime.yml")
runtime_yml = generate_runtime_yml(args.get("requires_ansible"), "vmware_rest", module_list)
meta_dir = pathlib.Path(args.get("target_dir") + "/meta")
meta_dir.mkdir(parents=True, exist_ok=True)
runtime_file = meta_dir / "runtime.yml"
with open(runtime_file, "w") as file:
yaml.safe_dump(runtime_yml, file, sort_keys=False)

return


Expand Down
14 changes: 13 additions & 1 deletion plugins/plugin_utils/cloud_utils/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ def preprocess(self) -> Iterable:
return sanitized_options


def generate_runtime_yml(requires_ansible, collection, module_list):
yaml_dict = {
"requires_ansible": (">=%s") % requires_ansible,
"action_groups": {collection: []},
}

for m in module_list:
yaml_dict["action_groups"][collection].append(m)

return yaml_dict


def generate_documentation(
module: object, added_ins: Dict, next_version: str, target_dir: str
) -> Iterable:
Expand Down Expand Up @@ -399,4 +411,4 @@ def generate_docs(self, type_name: str):
# TODO: include version
response = self.client.describe_type(Type="RESOURCE", TypeName=type_name)

return response.get("Schema")
return response.get("Schema")
1 change: 1 addition & 0 deletions roles/module_openapi_cloud/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
schema_dir: "{{ plugin['api_object_path'] }}"
modules: "{{ plugin['resource'] }}"
next_version: "{{ plugin['module_version'] }}"
requires_ansible: "{{ collection['requires_ansible'] }}"
changed_when: false
when: ( plugin['action'] == 'generate_modules' ) or ( plugin['action'] == 'generate_all' )

Expand Down
17 changes: 16 additions & 1 deletion roles/run/files/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,22 @@
"path",
"namespace",
"name"
]
],
"if": {
"properties": {
"name": {
"const": "vmware_rest"
}
}
},
"then": {
"properties": {
"requires_ansible": {
"type": "string"
}
},
"required": ["requires_ansible"]
}
},
"license_file": {
"type": "string"
Expand Down
5 changes: 5 additions & 0 deletions tests/cloud/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ def test_generate_documentation():
Path("tests/cloud/fixtures"),
)
assert documentation == expected_content


def test_generate_runtime_yml():
runtime_yml = g.generate_runtime_yml("1.2.3", "test", ["foo", "bar"])
assert runtime_yml == {"requires_ansible": ">=1.2.3", "action_groups": {"test": ["foo", "bar"]}}

0 comments on commit e775adc

Please sign in to comment.