Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation update and Python version check #27

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: required
dist: bionic
language: python
python:
- "3.7"
- "3.10"

# command to install dependencies
install:
Expand Down Expand Up @@ -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
Expand Down
68 changes: 32 additions & 36 deletions plugins/inventory/powervm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,16 @@
# 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 = '''
name: powervm_inventory
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
Expand All @@ -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.
Expand All @@ -85,24 +55,23 @@ 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.
Currently, no hostname lookup is performed, so only IP addresses
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
Expand Down Expand Up @@ -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.'''
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/hmc_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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 = {}
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/hmc_pwdpolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions plugins/modules/hmc_update_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion plugins/modules/hmc_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions plugins/modules/power_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

EXAMPLES = '''
- name: poweroff managed system
hmc_managed_system:
power_system:
hmc_host: "{{ inventory_hostname }}"
hmc_auth:
username: '{{ ansible_user }}'
Expand All @@ -115,7 +115,7 @@
action: poweroff

- name: poweron managed system
hmc_managed_system:
power_system:
hmc_host: "{{ inventory_hostname }}"
hmc_auth:
username: '{{ ansible_user }}'
Expand All @@ -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 }}'
Expand All @@ -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 }}'
Expand All @@ -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 }}'
Expand Down Expand Up @@ -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):
Expand Down
38 changes: 35 additions & 3 deletions plugins/modules/powervm_lpar_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@
password: '{{ hmc_password }}'
system_name: <system_name>
vm_name: <vm_name>
vm_id: <lpar_id>
proc: 4
proc_unit: 4
mem: 20480
Expand All @@ -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:
Expand All @@ -437,6 +438,19 @@
- vios_name: <viosname>
fc_port: <fc_port_name/loc_code>
wwpn_pair: <wwpn1;wwpn2>
vnic_config:
- vnic_adapter_id: <vnic_adapter_id>
backing_devices:
- location_code: XXXXX.XXX.XXXXXXX-P1-T1
capacity: <capacity>
hosting_partition: <vios_name>
- location_code: P1-T2
- backing_devices:
- location_code: P1-T3
hosting_partition: <vios_name>
- location_code: P1-T4
capacity: <capacity>
- vnic_adapter_id: <vnic_adapter_id>
os_type: aix_linux
state: present

Expand Down Expand Up @@ -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: <system_name>
vm_name: <vm_name>
install_settings:
vm_ip: <IP_address of the lpar>
nim_ip: <IP_address of the NIM Server>
nim_gateway: <Gateway IP_Addres>
nim_subnetmask: <Subnetmask IP_Address>
action: install_os

'''

RETURN = '''
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/powervm_lpar_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down
Loading