From 430e18d9af1dcab410828901a0972be483257adf Mon Sep 17 00:00:00 2001 From: ieisystem Date: Fri, 27 Sep 2024 17:10:42 +0800 Subject: [PATCH] Add new modules system_lock_mode_info, edit_system_lock_mode --- README.md | 2 +- .../fragments/27-edit_add_lock_mode.yml | 2 + docs/edit_system_lock_mode_module.rst | 327 ++++++++++++++++++ galaxy.yml | 2 +- plugins/modules/edit_system_lock_mode.py | 115 ++++++ plugins/modules/system_lock_mode_info.py | 99 ++++++ 6 files changed, 545 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/27-edit_add_lock_mode.yml create mode 100644 docs/edit_system_lock_mode_module.rst create mode 100644 plugins/modules/edit_system_lock_mode.py create mode 100644 plugins/modules/system_lock_mode_info.py diff --git a/README.md b/README.md index a2ab832..ffa9d3c 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Thes modules require the following to be installed on the control node: * Python 3.7 or later * [Ansible](http://www.ansible.com) 2.10 or later -* [ieisystem support] [inManage](https://github.com/ieisystem/inManage) 1.1.0 or later +* [ieisystem support] [inManage](https://github.com/ieisystem/inManage) 1.2.0 or later ## Included content diff --git a/changelogs/fragments/27-edit_add_lock_mode.yml b/changelogs/fragments/27-edit_add_lock_mode.yml new file mode 100644 index 0000000..973a9c1 --- /dev/null +++ b/changelogs/fragments/27-edit_add_lock_mode.yml @@ -0,0 +1,2 @@ +major_changes: + - "Add new modules system_lock_mode_info, edit_system_lock_mode(https://github.com/ieisystem/kaytus.ksmanage/pull/27)." diff --git a/docs/edit_system_lock_mode_module.rst b/docs/edit_system_lock_mode_module.rst new file mode 100644 index 0000000..f7e7d1f --- /dev/null +++ b/docs/edit_system_lock_mode_module.rst @@ -0,0 +1,327 @@ +.. Document meta + +:orphan: + +.. Anchors + +.. _ansible_collections.kaytus.ksmanage.edit_system_lock_mode_module: + +.. Anchors: short name for ansible.builtin + +.. Anchors: aliases + + + +.. Title + +kaytus.ksmanage.edit_system_lock_mode -- Set system lock mode information ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. Collection note + +.. note:: + This plugin is part of the `kaytus.ksmanage collection `_. + + To install it use: :code:`ansible-galaxy collection install kaytus.ksmanage`. + + To use it in a playbook, specify: :code:`kaytus.ksmanage.edit_system_lock_mode`. + +.. version_added + +.. versionadded:: 2.0.0 of kaytus.ksmanage + +.. contents:: + :local: + :depth: 1 + +.. Deprecated + + +Synopsis +-------- + +.. Description + +- Set system lock mode information on kaytus Server. + + +.. Aliases + + +.. Requirements + +Requirements +------------ +The below requirements are needed on the host that executes this module. + +- Python 3.7+ +- inManage + + +.. Options + +Parameters +---------- + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterChoices/DefaultsComments
+
+ host + +
+ string +
+
+ +
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
+
+
+ lock_status + +
+ string + / required
+
+
    Choices: +
  • close
  • +
  • open
  • +
+
+
System lock mode status.
+
+
+ password + +
+ string +
+
+ +
Specifies the password to use to authenticate the connection to the remote device. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
+
+
+ provider + +
+ dictionary +
+
+ +
A dict object containing connection details.
+
+
+ host + +
+ string +
+
+ +
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
+
+
+ password + +
+ string +
+
+ +
Specifies the password to use to authenticate the connection to the remote device. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
+
+
+ username + +
+ string +
+
+ +
Configures the username to use to authenticate the connection to the remote device. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
+
+
+ username + +
+ string +
+
+ +
Configures the username to use to authenticate the connection to the remote device. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
+
+
+ +.. Notes + +Notes +----- + +.. note:: + - Does not support ``check_mode``. + +.. Seealso + + +.. Examples + +Examples +-------- + +.. code-block:: yaml+jinja + + + - name: System lock mode test + hosts: ksmanage + connection: local + gather_facts: false + vars: + ksmanage: + host: "{{ ansible_ssh_host }}" + username: "{{ username }}" + password: "{{ password }}" + + tasks: + + - name: "Set system lock mode to close" + kaytus.ksmanage.edit_system_lock_mode: + lock_status: "close" + provider: "{{ ksmanage }}" + + - name: "Set system lock mode to open" + kaytus.ksmanage.edit_system_lock_mode: + lock_status: "open" + provider: "{{ ksmanage }}" + + + + +.. Facts + + +.. Return values + +Return Values +------------- +Common return values are documented :ref:`here `, the following are the fields unique to this module: + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + +
KeyReturnedDescription
+
+ changed + +
+ boolean +
+
always +
Check to see if a change was made on the device.
+
+
+
+ message + +
+ string +
+
always +
Messages returned after module execution.
+
+
+
+ state + +
+ string +
+
always +
Status after module execution.
+
+
+

+ +.. Status (Presently only deprecated) + + +.. Authors + +Authors +~~~~~~~ + +- WangBaoshan (@ieisystem) + + + +.. Parsing errors + diff --git a/galaxy.yml b/galaxy.yml index abcf092..4b1fb6f 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -9,7 +9,7 @@ namespace: kaytus name: ksmanage # The version of the collection. Must be compatible with semantic versioning -version: 1.2.2 +version: 2.0.0 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/plugins/modules/edit_system_lock_mode.py b/plugins/modules/edit_system_lock_mode.py new file mode 100644 index 0000000..4ba2cfc --- /dev/null +++ b/plugins/modules/edit_system_lock_mode.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + +# Copyright(C) 2023 IEIT Inc. All Rights Reserved. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) + +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: edit_system_lock_mode +version_added: "2.0.0" +author: + - WangBaoshan (@ieisystem) +short_description: Set system lock mode information +description: + - Set system lock mode information on kaytus Server. +notes: + - Does not support C(check_mode). +options: + lock_status: + description: + - System lock mode status. + choices: ['close', 'open'] + type: str + required: true +extends_documentation_fragment: + - kaytus.ksmanage.ksmanage +''' + +EXAMPLES = ''' +- name: System lock mode test + hosts: ksmanage + connection: local + gather_facts: false + vars: + ksmanage: + host: "{{ ansible_ssh_host }}" + username: "{{ username }}" + password: "{{ password }}" + + tasks: + + - name: "Set system lock mode to close" + kaytus.ksmanage.edit_system_lock_mode: + lock_status: "close" + provider: "{{ ksmanage }}" + + - name: "Set system lock mode to open" + kaytus.ksmanage.edit_system_lock_mode: + lock_status: "open" + provider: "{{ ksmanage }}" +''' + +RETURN = ''' +message: + description: Messages returned after module execution. + returned: always + type: str +state: + description: Status after module execution. + returned: always + type: str +changed: + description: Check to see if a change was made on the device. + returned: always + type: bool +''' + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.kaytus.ksmanage.plugins.module_utils.ksmanage import (ksmanage_argument_spec, get_connection) + + +class Lock(object): + def __init__(self, argument_spec): + self.spec = argument_spec + self.module = None + self.init_module() + self.results = dict() + + def init_module(self): + """Init module object""" + + self.module = AnsibleModule( + argument_spec=self.spec, supports_check_mode=False) + + def run_command(self): + self.module.params['subcommand'] = 'setSystemLockdownMode' + self.results = get_connection(self.module) + if self.results['State'] == 'Success': + self.results['changed'] = True + + def show_result(self): + """Show result""" + self.module.exit_json(**self.results) + + def work(self): + """Worker""" + self.run_command() + self.show_result() + + +def main(): + argument_spec = dict( + lock_status=dict(type='str', required=True, choices=['close', 'open']), + ) + argument_spec.update(ksmanage_argument_spec) + psu_obj = Lock(argument_spec) + psu_obj.work() + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/system_lock_mode_info.py b/plugins/modules/system_lock_mode_info.py new file mode 100644 index 0000000..23d1c9b --- /dev/null +++ b/plugins/modules/system_lock_mode_info.py @@ -0,0 +1,99 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + +# Copyright(C) 2023 IEIT Inc. All Rights Reserved. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) + +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: system_lock_mode_info +version_added: "2.0.0" +author: + - WangBaoshan (@ieisystem) +short_description: Get system lock mode information +description: + - Get system lock mode information on kaytus Server. +notes: + - Supports C(check_mode). +options: {} +extends_documentation_fragment: + - kaytus.ksmanage.ksmanage +''' + +EXAMPLES = ''' +- name: System lock mode test + hosts: ksmanage + connection: local + gather_facts: false + vars: + ksmanage: + host: "{{ ansible_ssh_host }}" + username: "{{ username }}" + password: "{{ password }}" + + tasks: + + - name: "Get system lock mode information" + kaytus.ksmanage.system_lock_mode_info: + provider: "{{ ksmanage }}" +''' + +RETURN = ''' +message: + description: Messages returned after module execution. + returned: always + type: str +state: + description: Status after module execution. + returned: always + type: str +changed: + description: Check to see if a change was made on the device. + returned: always + type: bool +''' + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.kaytus.ksmanage.plugins.module_utils.ksmanage import (ksmanage_argument_spec, get_connection) + + +class Lock(object): + def __init__(self, argument_spec): + self.spec = argument_spec + self.module = None + self.init_module() + self.results = dict() + + def init_module(self): + """Init module object""" + + self.module = AnsibleModule( + argument_spec=self.spec, supports_check_mode=True) + + def run_command(self): + self.module.params['subcommand'] = 'getSystemLockdownMode' + self.results = get_connection(self.module) + + def show_result(self): + """Show result""" + self.module.exit_json(**self.results) + + def work(self): + """Worker""" + self.run_command() + self.show_result() + + +def main(): + argument_spec = dict() + argument_spec.update(ksmanage_argument_spec) + ad_obj = Lock(argument_spec) + ad_obj.work() + + +if __name__ == '__main__': + main()