diff --git a/.travis.yml b/.travis.yml index 265b9e7..74d4425 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: required dist: bionic language: python python: - - "3.7" + - "3.10" # command to install dependencies install: @@ -46,6 +46,7 @@ script: - pyenv global 3.7 - ansible-test sanity --python 3.7 --skip-test shellcheck + - ansible-test sanity --python 3.10 --skip-test shellcheck - cd /home/travis/.ansible/collections/ - python -m pytest - cd $build_path diff --git a/plugins/inventory/powervm_inventory.py b/plugins/inventory/powervm_inventory.py index 89ca0cd..9a906c4 100644 --- a/plugins/inventory/powervm_inventory.py +++ b/plugins/inventory/powervm_inventory.py @@ -2,34 +2,6 @@ # 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) -import xml.etree.ElementTree as ET -import json -import sys -from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable -from ansible.module_utils.six import string_types, viewitems, reraise -from ansible.errors import AnsibleParserError -from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import HmcError -from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_rest_client import parse_error_response -from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_rest_client import HmcRestClient -from ansible.config.manager import ensure_type -from ansible.template import Templar - -from ansible.utils.display import Display -display = Display() - -# Generic setting for log initializing and log rotation -import logging -LOG_FILENAME = "/tmp/ansible_power_hmc.log" -logger = logging.getLogger(__name__) - - -def init_logger(): - logging.basicConfig( - filename=LOG_FILENAME, - format='[%(asctime)s] %(levelname)s: [%(funcName)s] %(message)s', - level=logging.DEBUG) - - __metaclass__ = type DOCUMENTATION = ''' @@ -37,10 +9,9 @@ def init_logger(): author: - Torin Reilly (@torinreilly) - Michael Cohoon (@mtcohoon) - - Ozzie Rodriguez - - Anil Vijayan + - Ozzie Rodriguez (@OzzieRodriguez) + - Anil Vijayan (@AnilVijayan) - Navinakumar Kandakur (@nkandak1) - plugin_type: inventory version_added: "1.1.0" requirements: - Python >= 3 @@ -67,7 +38,6 @@ def init_logger(): description: A dictionary of hosts and their associated usernames and passwords. required: true type: dict - elements: dict filters: description: - A key value pair for filtering by various LPAR/VIOS attributes. @@ -85,7 +55,6 @@ def init_logger(): description: Add hosts to group based on the values of a variable. type: list elements: str - default: [] exclude_ip: description: A list of IP addresses to exclude from the inventory. This will be compared to the RMC IP address specified in the HMC. @@ -93,16 +62,16 @@ def init_logger(): that match the RMC IP address specified in the HMC will be excluded. This is not valid for IBMi LPARs type: list - default: [] + elements: str exclude_lpar: description: A list of partitions (LPAR, VIOS) to exclude by partition name. type: list - default: [] + elements: str exclude_system: description: A list of HMC managed systems whose partitions (LPAR, VIOS) will be excluded from the dynamic inventory. type: list - default: [] + elements: str ansible_display_name: description: By default, partitions names will be used as the name displayed by Ansible in output. If you wish this to display the IP address instead you may @@ -231,6 +200,33 @@ def init_logger(): - Frame2-XXX-WWWWWW ''' +import xml.etree.ElementTree as ET +import json +import sys +from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable +from ansible.module_utils.six import string_types, viewitems, reraise +from ansible.errors import AnsibleParserError +from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import HmcError +from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_rest_client import parse_error_response +from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_rest_client import HmcRestClient +from ansible.config.manager import ensure_type +from ansible.template import Templar + +from ansible.utils.display import Display +display = Display() + +# Generic setting for log initializing and log rotation +import logging +LOG_FILENAME = "/tmp/ansible_power_hmc.log" +logger = logging.getLogger(__name__) + + +def init_logger(): + logging.basicConfig( + filename=LOG_FILENAME, + format='[%(asctime)s] %(levelname)s: [%(funcName)s] %(message)s', + level=logging.DEBUG) + class LparFieldNotFoundError(Exception): '''Raised when a field does not exist in the LPAR data.''' diff --git a/plugins/modules/hmc_command.py b/plugins/modules/hmc_command.py index 9edfa0e..aa21e0c 100644 --- a/plugins/modules/hmc_command.py +++ b/plugins/modules/hmc_command.py @@ -73,6 +73,7 @@ from ansible.module_utils.basic import AnsibleModule from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_cli_client import HmcCliConnection from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import HmcError +import sys def init_logger(): @@ -137,6 +138,10 @@ def run_module(): if module._verbosity >= 5: init_logger() + if sys.version_info < (3, 0): + py_ver = sys.version_info[0] + module.fail_json("Unsupported Python version {0}, supported python version is 3 and above".format(py_ver)) + changed, info, warning = perform_task(module) result = {} diff --git a/plugins/modules/hmc_pwdpolicy.py b/plugins/modules/hmc_pwdpolicy.py index f4af37d..dacbb2f 100644 --- a/plugins/modules/hmc_pwdpolicy.py +++ b/plugins/modules/hmc_pwdpolicy.py @@ -197,6 +197,7 @@ from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import ParameterError from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_cli_client import HmcCliConnection from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_resource import Hmc +import sys def init_logger(): @@ -484,6 +485,10 @@ def run_module(): if module._verbosity >= 5: init_logger() + if sys.version_info < (3, 0): + py_ver = sys.version_info[0] + module.fail_json("Unsupported Python version {0}, supported python version is 3 and above".format(py_ver)) + changed, result = perform_task(module) if isinstance(result, str): diff --git a/plugins/modules/hmc_update_upgrade.py b/plugins/modules/hmc_update_upgrade.py index fdefda6..00236d9 100644 --- a/plugins/modules/hmc_update_upgrade.py +++ b/plugins/modules/hmc_update_upgrade.py @@ -169,8 +169,7 @@ from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import ParameterError from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import Error from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import HmcError - - +import sys import logging LOG_FILENAME = "/tmp/ansible_power_hmc.log" logger = logging.getLogger(__name__) @@ -201,7 +200,7 @@ def command_option_checker(config): unsupportedList = ['mount_location'] if config['location_type'] == 'sftp': - if not(config['sshkey_file'] or config['passwd']): + if not (config['sshkey_file'] or config['passwd']): raise ParameterError("mandatory parameter 'passwd' or 'sshkey_file' is missing") elif config['sshkey_file'] and config['passwd']: raise ParameterError("conflicting parameters 'passwd' and 'sshkey_file'. Provide any one") @@ -578,6 +577,10 @@ def run_module(): if module._verbosity >= 5: init_logger() + if sys.version_info < (3, 0): + py_ver = sys.version_info[0] + module.fail_json("Unsupported Python version {0}, supported python version is 3 and above".format(py_ver)) + changed, build_info, warning = perform_task(module) if isinstance(build_info, str): diff --git a/plugins/modules/hmc_user.py b/plugins/modules/hmc_user.py index c868d87..7a8dea7 100644 --- a/plugins/modules/hmc_user.py +++ b/plugins/modules/hmc_user.py @@ -222,6 +222,8 @@ from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import ParameterError from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import HmcError from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_resource import Hmc +import sys + USER_AUTHORITY_ERR = "HSCL350B The user does not have the appropriate authority" @@ -302,7 +304,7 @@ def validate_sub_params(params): if notTogetherList: for notTogether in notTogetherList: - if(all(params[each] for each in notTogether)): + if (all(params[each] for each in notTogether)): raise ParameterError("%s state will not support parameters: %s together" % (state, ','.join(notTogether))) if mandatoryList: @@ -631,6 +633,10 @@ def run_module(): if module._verbosity >= 5: init_logger() + if sys.version_info < (3, 0): + py_ver = sys.version_info[0] + module.fail_json("Unsupported Python version {0}, supported python version is 3 and above".format(py_ver)) + changed, user_info, warning = perform_task(module) if isinstance(user_info, str): module.fail_json(msg=user_info) diff --git a/plugins/modules/power_system.py b/plugins/modules/power_system.py index 8cbd364..a817f8c 100644 --- a/plugins/modules/power_system.py +++ b/plugins/modules/power_system.py @@ -106,7 +106,7 @@ EXAMPLES = ''' - name: poweroff managed system - hmc_managed_system: + power_system: hmc_host: "{{ inventory_hostname }}" hmc_auth: username: '{{ ansible_user }}' @@ -115,7 +115,7 @@ action: poweroff - name: poweron managed system - hmc_managed_system: + power_system: hmc_host: "{{ inventory_hostname }}" hmc_auth: username: '{{ ansible_user }}' @@ -124,7 +124,7 @@ action: poweron - name: modify managed system name, powerOn lpar start policy and powerOff policy - hmc_managed_system: + power_system: hmc_host: "{{ inventory_hostname }}" hmc_auth: username: '{{ ansible_user }}' @@ -136,7 +136,7 @@ action: modify_syscfg - name: modify managed system memory settings - hmc_managed_system: + power_system: hmc_host: "{{ inventory_hostname }}" hmc_auth: username: '{{ ansible_user }}' @@ -148,7 +148,7 @@ action: modify_hwres - name: fetch the managed system details - hmc_managed_system: + power_system: hmc_host: "{{ inventory_hostname }}" hmc_auth: username: '{{ ansible_user }}' @@ -444,6 +444,10 @@ def run_module(): if module._verbosity >= 5: init_logger() + if sys.version_info < (3, 0): + py_ver = sys.version_info[0] + module.fail_json("Unsupported Python version {0}, supported python version is 3 and above".format(py_ver)) + changed, info, warning = perform_task(module) if isinstance(info, str): diff --git a/plugins/modules/powervm_lpar_instance.py b/plugins/modules/powervm_lpar_instance.py index 98163e7..9a2b524 100644 --- a/plugins/modules/powervm_lpar_instance.py +++ b/plugins/modules/powervm_lpar_instance.py @@ -403,6 +403,7 @@ password: '{{ hmc_password }}' system_name: vm_name: + vm_id: proc: 4 proc_unit: 4 mem: 20480 @@ -419,7 +420,7 @@ state: present - name: Create an AIX/Linux logical partition instance with default proc, mem, virt_network_config, volume_config's volumes_size and - npiv_config + npiv_config, vnic_config powervm_lpar_instance: hmc_host: '{{ inventory_hostname }}' hmc_auth: @@ -437,6 +438,19 @@ - vios_name: fc_port: wwpn_pair: + vnic_config: + - vnic_adapter_id: + backing_devices: + - location_code: XXXXX.XXX.XXXXXXX-P1-T1 + capacity: + hosting_partition: + - location_code: P1-T2 + - backing_devices: + - location_code: P1-T3 + hosting_partition: + - location_code: P1-T4 + capacity: + - vnic_adapter_id: os_type: aix_linux state: present @@ -496,6 +510,20 @@ all_resources: True os_type: aix_linux state: present + +- name: Install aix/Linux OS on LPAR from NIM Server + powervm_lpar_instance: + hmc_host: '{{ inventory_hostname }}' + hmc_auth: "{{ curr_hmc_auth }}" + system_name: + vm_name: + install_settings: + vm_ip: + nim_ip: + nim_gateway: + nim_subnetmask: + action: install_os + ''' RETURN = ''' @@ -734,7 +762,7 @@ def identifyFreeVolume(rest_conn, system_uuid, volume_name=None, volume_size=0, for each in pv_xml_list: # This condition is to avoid picking already picked UDID in case of mutiple volume config - if(pvid_list and each.xpath("UniqueDeviceID")[0].text in pvid_list): + if (pvid_list and each.xpath("UniqueDeviceID")[0].text in pvid_list): continue if volume_size > 0 and int(each.xpath("VolumeCapacity")[0].text) >= volume_size: @@ -1197,7 +1225,7 @@ def remove_partition(module, params): retainViosCfg = False deleteVdisks = False else: - retainViosCfg = not(retainViosCfg) + retainViosCfg = not (retainViosCfg) try: hmc.deletePartition(system_name, vm_name, retainViosCfg, deleteVdisks) except HmcError as del_lpar_error: @@ -1645,6 +1673,10 @@ def run_module(): if module._verbosity >= 5: init_logger() + if sys.version_info < (3, 0): + py_ver = sys.version_info[0] + module.fail_json("Unsupported Python version {0}, supported python version is 3 and above".format(py_ver)) + changed, info, warning = perform_task(module) if isinstance(info, str): diff --git a/plugins/modules/powervm_lpar_migration.py b/plugins/modules/powervm_lpar_migration.py index 5ac3ec6..c1e2db2 100644 --- a/plugins/modules/powervm_lpar_migration.py +++ b/plugins/modules/powervm_lpar_migration.py @@ -170,6 +170,7 @@ from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import HmcError from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import ParameterError from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_rest_client import parse_error_response +import sys def init_logger(): @@ -341,6 +342,10 @@ def run_module(): if module._verbosity >= 5: init_logger() + if sys.version_info < (3, 0): + py_ver = sys.version_info[0] + module.fail_json("Unsupported Python version {0}, supported python version is 3 and above".format(py_ver)) + changed, info, warning = perform_task(module) if isinstance(info, str): diff --git a/plugins/modules/vios.py b/plugins/modules/vios.py index 3e628f3..d2bf04f 100644 --- a/plugins/modules/vios.py +++ b/plugins/modules/vios.py @@ -192,6 +192,7 @@ from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_resource import Hmc from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import HmcError from ansible_collections.ibm.power_hmc.plugins.module_utils.hmc_exceptions import ParameterError +import sys def init_logger(): @@ -449,6 +450,10 @@ def run_module(): if module._verbosity >= 5: init_logger() + if sys.version_info < (3, 0): + py_ver = sys.version_info[0] + module.fail_json("Unsupported Python version {0}, supported python version is 3 and above".format(py_ver)) + changed, info, warning = perform_task(module) if isinstance(info, str):