- Easy to use
- Easy to develop
Easy to use
- Don't mimick API spec. Ansible spec should be a simplified version of API spec.
- Goal is to expose minimum attributes to create, update or delete the entity
- Keep backward & forward compatibility in mind when creating ansible spec
- Look at the example of ansible spec for VM. Only 13 attributes are exposed from API to cater to 80-90% of use cases.
Easy to develop
-
Use
scripts/codegen
to automatically generate code for the module development$python scripts/codegen subnets
-
scripts/codegen
provides 3 things out of the boxa. Client SDK.
b. Ansible module plugin with
run_module()
implementation.c. Bootstrap code for creating and deleting entity.
-
Takes 3 steps to develop the module
Example:
def get_module_spec(): mutually_exclusive = [("name", "uuid")] overlay_ipam_spec = dict(...) external_subnet_spec = dict(...) overlay_subnet_spec = dict(...) module_args = dict( name=dict(type="str", required=False), subnet_uuid=dict(type="str", required=False), vlan_subnet=dict(type="dict", options=vlan_subnet_spec), external_subnet=dict(type="dict", options=external_subnet_spec), overlay_subnet=dict(type="dict", options=overlay_subnet_spec), ) return module_args
- Define
ansible_param
as key and_build_spec_*
method as value inself.build_spec_methods
map.
Example:
self.build_spec_methods = { "name": self._build_spec_name, "vlan_subnet": self._build_spec_vlan_subnet, "external_subnet": self._build_spec_external_subnet, "overlay_subnet": self._build_spec_overlay_subnet, }
- Implement
_get_default_spec(self)
and_build_spec_*(self, payload, config)
methods
Example:
def _get_default_spec(self): return deepcopy( { "api_version": "3.1.0", "metadata": {"kind": "subnet"}, "spec": { "name": "", "resources": {"ip_config": {}, "subnet_type": None}, }, } ) def _build_spec_name(self, payload, value): payload["spec"]["name"] = value return payload, None
- Define
- Create a github issue with following details
-
Title should contain one of the follwoing
- [Feat] Develop ansible module for <api_name>
- [Imprv] Modify ansible module to support <new_functionality>
- [Bug] Fix <summary of issue> bug in <ansible_module_name>
-
Labels should contain one of the following
- feature
- enhancement
- bug
- test
-
Project should be selected
-
Assignees - assign yourself
-
Task list for list of tasks that needs to be developed as part of the fix
- unit tests
- integration tests
- sanity tests
- documentation
- Create one of the following git branch from
main
branch. Useissue#<id>
from 1).
feat/<module_name>_issue#<id>
imprv/issue#<id>
bug/issue#<id>
-
Develop
sanity
,unit
andintegrtaion
tests. -
Create a pull request
-
Ensure 85% code coverage on the pull request. Pull request with less than 85% coverage will be rejected.
-
Link the pull request in
issue#<id>
-
After the pull request is merged, close the
issue#<id>