From 53b56825cd625b401caf6c62d634d7ed4b155a8c Mon Sep 17 00:00:00 2001 From: Mariusz Mazur Date: Tue, 26 Mar 2019 22:22:50 +0100 Subject: [PATCH] kubevirt: cleanup module docs (#54119) --- lib/ansible/module_utils/kubevirt.py | 14 +++--- .../modules/cloud/kubevirt/kubevirt_preset.py | 6 +-- .../modules/cloud/kubevirt/kubevirt_rs.py | 6 +-- .../cloud/kubevirt/kubevirt_template.py | 30 ++++++++----- .../modules/cloud/kubevirt/kubevirt_vm.py | 6 +-- .../doc_fragments/kubevirt_common_options.py | 44 +++++++------------ 6 files changed, 50 insertions(+), 56 deletions(-) diff --git a/lib/ansible/module_utils/kubevirt.py b/lib/ansible/module_utils/kubevirt.py index 46a468b9f8..acf2fdb228 100644 --- a/lib/ansible/module_utils/kubevirt.py +++ b/lib/ansible/module_utils/kubevirt.py @@ -24,20 +24,20 @@ API_GROUP = 'kubevirt.io' VM_COMMON_ARG_SPEC = { - 'name': {}, + 'name': {'required': True}, + 'namespace': {'required': True}, + 'state': { + 'default': 'present', + 'choices': ['present', 'absent'], + }, 'force': { 'type': 'bool', 'default': False, }, 'resource_definition': { - 'type': list_dict_str, + 'type': 'dict', 'aliases': ['definition', 'inline'] }, - 'src': { - 'type': 'path', - }, - 'namespace': {}, - 'api_version': {'type': 'str', 'default': '%s/%s' % (API_GROUP, MAX_SUPPORTED_API_VERSION), 'aliases': ['api', 'version']}, 'merge_type': {'type': 'list', 'choices': ['json', 'merge', 'strategic-merge']}, 'wait': {'type': 'bool', 'default': True}, 'wait_timeout': {'type': 'int', 'default': 120}, diff --git a/lib/ansible/modules/cloud/kubevirt/kubevirt_preset.py b/lib/ansible/modules/cloud/kubevirt/kubevirt_preset.py index 3fe3543a22..303ee05c1d 100644 --- a/lib/ansible/modules/cloud/kubevirt/kubevirt_preset.py +++ b/lib/ansible/modules/cloud/kubevirt/kubevirt_preset.py @@ -51,7 +51,6 @@ options: extends_documentation_fragment: - k8s_auth_options - - k8s_resource_options - kubevirt_vm_options - kubevirt_common_options @@ -93,7 +92,7 @@ import copy import traceback -from ansible.module_utils.k8s.common import AUTH_ARG_SPEC, COMMON_ARG_SPEC +from ansible.module_utils.k8s.common import AUTH_ARG_SPEC from ansible.module_utils.kubevirt import ( virtdict, @@ -113,8 +112,7 @@ class KubeVirtVMPreset(KubeVirtRawModule): @property def argspec(self): """ argspec property builder """ - argument_spec = copy.deepcopy(COMMON_ARG_SPEC) - argument_spec.update(copy.deepcopy(AUTH_ARG_SPEC)) + argument_spec = copy.deepcopy(AUTH_ARG_SPEC) argument_spec.update(VM_COMMON_ARG_SPEC) argument_spec.update(VMP_ARG_SPEC) return argument_spec diff --git a/lib/ansible/modules/cloud/kubevirt/kubevirt_rs.py b/lib/ansible/modules/cloud/kubevirt/kubevirt_rs.py index 1a0a567bd5..085d3ef535 100644 --- a/lib/ansible/modules/cloud/kubevirt/kubevirt_rs.py +++ b/lib/ansible/modules/cloud/kubevirt/kubevirt_rs.py @@ -57,7 +57,6 @@ options: extends_documentation_fragment: - k8s_auth_options - - k8s_resource_options - kubevirt_vm_options - kubevirt_common_options @@ -112,7 +111,7 @@ import copy import traceback -from ansible.module_utils.k8s.common import AUTH_ARG_SPEC, COMMON_ARG_SPEC +from ansible.module_utils.k8s.common import AUTH_ARG_SPEC try: from openshift.dynamic.client import ResourceInstance @@ -139,8 +138,7 @@ class KubeVirtVMIRS(KubeVirtRawModule): @property def argspec(self): """ argspec property builder """ - argument_spec = copy.deepcopy(COMMON_ARG_SPEC) - argument_spec.update(copy.deepcopy(AUTH_ARG_SPEC)) + argument_spec = copy.deepcopy(AUTH_ARG_SPEC) argument_spec.update(copy.deepcopy(VM_COMMON_ARG_SPEC)) argument_spec.update(copy.deepcopy(VMIR_ARG_SPEC)) return argument_spec diff --git a/lib/ansible/modules/cloud/kubevirt/kubevirt_template.py b/lib/ansible/modules/cloud/kubevirt/kubevirt_template.py index a2a5590b6c..acff602fba 100644 --- a/lib/ansible/modules/cloud/kubevirt/kubevirt_template.py +++ b/lib/ansible/modules/cloud/kubevirt/kubevirt_template.py @@ -26,6 +26,16 @@ version_added: "2.8" author: KubeVirt Team (@kubevirt) options: + name: + description: + - Name of the Template object. + required: true + type: str + namespace: + description: + - Namespace where the Template object exists. + required: true + type: str objects: description: - List of any valid API objects, such as a I(DeploymentConfig), I(Service), etc. The object @@ -129,9 +139,7 @@ options: extends_documentation_fragment: - k8s_auth_options - - k8s_resource_options - k8s_state_options - - k8s_name_options requirements: - python >= 2.7 @@ -197,7 +205,7 @@ kubevirt_template: import copy import traceback -from ansible.module_utils.k8s.common import AUTH_ARG_SPEC, COMMON_ARG_SPEC +from ansible.module_utils.k8s.common import AUTH_ARG_SPEC from ansible.module_utils.kubevirt import ( virtdict, @@ -207,12 +215,15 @@ from ansible.module_utils.kubevirt import ( TEMPLATE_ARG_SPEC = { + 'name': {'required': True}, + 'namespace': {'required': True}, 'state': { - 'type': 'str', - 'choices': [ - 'present', 'absent' - ], - 'default': 'present' + 'default': 'present', + 'choices': ['present', 'absent'], + }, + 'force': { + 'type': 'bool', + 'default': False, }, 'merge_type': { 'type': 'list', @@ -271,8 +282,7 @@ class KubeVirtVMTemplate(KubeVirtRawModule): @property def argspec(self): """ argspec property builder """ - argument_spec = copy.deepcopy(COMMON_ARG_SPEC) - argument_spec.update(copy.deepcopy(AUTH_ARG_SPEC)) + argument_spec = copy.deepcopy(AUTH_ARG_SPEC) argument_spec.update(TEMPLATE_ARG_SPEC) return argument_spec diff --git a/lib/ansible/modules/cloud/kubevirt/kubevirt_vm.py b/lib/ansible/modules/cloud/kubevirt/kubevirt_vm.py index fa092a7824..730aa0ed74 100644 --- a/lib/ansible/modules/cloud/kubevirt/kubevirt_vm.py +++ b/lib/ansible/modules/cloud/kubevirt/kubevirt_vm.py @@ -65,7 +65,6 @@ options: extends_documentation_fragment: - k8s_auth_options - - k8s_resource_options - kubevirt_vm_options - kubevirt_common_options @@ -210,7 +209,7 @@ kubevirt_vm: import copy import traceback -from ansible.module_utils.k8s.common import AUTH_ARG_SPEC, COMMON_ARG_SPEC +from ansible.module_utils.k8s.common import AUTH_ARG_SPEC try: from openshift.dynamic.client import ResourceInstance @@ -243,8 +242,7 @@ class KubeVirtVM(KubeVirtRawModule): @property def argspec(self): """ argspec property builder """ - argument_spec = copy.deepcopy(COMMON_ARG_SPEC) - argument_spec.update(copy.deepcopy(AUTH_ARG_SPEC)) + argument_spec = copy.deepcopy(AUTH_ARG_SPEC) argument_spec.update(VM_COMMON_ARG_SPEC) argument_spec.update(VM_ARG_SPEC) return argument_spec diff --git a/lib/ansible/plugins/doc_fragments/kubevirt_common_options.py b/lib/ansible/plugins/doc_fragments/kubevirt_common_options.py index c25816eb51..6092a6d5eb 100644 --- a/lib/ansible/plugins/doc_fragments/kubevirt_common_options.py +++ b/lib/ansible/plugins/doc_fragments/kubevirt_common_options.py @@ -5,21 +5,23 @@ class ModuleDocFragment(object): - - # Standard oVirt documentation fragment DOCUMENTATION = r''' options: + resource_definition: + description: + - "A partial YAML definition of the object being created/updated. Here you can define Kubernetes + resource parameters not covered by this module's parameters." + - "NOTE: I(resource_definition) has lower priority than module parameters. If you try to define e.g. + I(metadata.namespace) here, that value will be ignored and I(namespace) used instead." + aliases: + - definition + - inline + type: dict wait: description: - "I(True) if the module should wait for the resource to get into desired state." type: bool default: yes - kind: - description: - - Use to specify an object model. Use to create, delete, or discover an object without providing a full - resource definition. Use in conjunction with I(api_version), I(name), and I(namespace) to identify a - specific object. If I(resource definition) is provided, the I(kind) from the I(resource_definition) - will override this option. force: description: - If set to C(no), and I(state) is C(present), an existing object will be replaced. @@ -30,14 +32,6 @@ options: - The amount of time in seconds the module should wait for the resource to get into desired state. type: int default: 120 - api_version: - description: - - "Specify the API version to be used." - type: str - default: kubevirt.io/v1alpha3 - aliases: - - api - - version memory: description: - The amount of memory to be requested by virtual machine. @@ -54,16 +48,12 @@ options: type: str merge_type: description: - - Whether to override the default patch merge approach with a specific type. By default, the strategic - merge will typically be used. - - For example, Custom Resource Definitions typically aren't updatable by the usual strategic merge. You may - want to use C(merge) if you see "strategic merge patch format is not supported" - - See U(https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment) - - Requires openshift >= 0.6.2 - - If more than one merge_type is given, the merge_types will be tried in order - - If openshift >= 0.6.2, this defaults to C(['strategic-merge', 'merge']), which is ideal for using the same parameters - on resource kinds that combine Custom Resources and built-in resources. For openshift < 0.6.2, the default - is simply C(strategic-merge). + - Whether to override the default patch merge approach with a specific type. + - If more than one merge type is given, the merge types will be tried in order. + - "Defaults to C(['strategic-merge', 'merge']), which is ideal for using the same parameters + on resource kinds that combine Custom Resources and built-in resources, as + Custom Resource Definitions typically aren't updatable by the usual strategic merge." + - "See U(https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment)" type: list choices: [ json, merge, strategic-merge ] cpu_shares: @@ -122,5 +112,5 @@ requirements: notes: - "In order to use this module you have to install Openshift Python SDK. To ensure it's installed with correct version you can create the following task: - I(pip: name=openshift version=0.8.2)" + I(pip: name=openshift>=0.8.2)" '''