| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: ibm_svc_auth |
| 14 |
short_description: This module generates an authentication token for a user on IBM Storage Virtualize family system |
| 15 |
description: |
| 16 |
- Ansible interface to generate the authentication token. |
| 17 |
The token is used to make REST API calls to the storage system. |
| 18 |
version_added: "1.5.0" |
| 19 |
options: |
| 20 |
clustername: |
| 21 |
description: |
| 22 |
- The hostname or management IP of the Storage Virtualize system. |
| 23 |
type: str |
| 24 |
required: true |
| 25 |
domain: |
| 26 |
description: |
| 27 |
- Domain for the Storage Virtualize system. |
| 28 |
- Valid when hostname is used for the parameter I(clustername). |
| 29 |
type: str |
| 30 |
username: |
| 31 |
description: |
| 32 |
- REST API username for the Storage Virtualize system. |
| 33 |
- This parameter is required in this module to generate the token. |
| 34 |
type: str |
| 35 |
password: |
| 36 |
description: |
| 37 |
- REST API password for the Storage Virtualize system. |
| 38 |
- This parameter is required in this module to generate the token. |
| 39 |
type: str |
| 40 |
token: |
| 41 |
description: |
| 42 |
- The authentication token to verify a user on the Storage Virtualize system. |
| 43 |
- This field is not required for ibm_svc_auth module. |
| 44 |
type: str |
| 45 |
validate_certs: |
| 46 |
description: |
| 47 |
- Validates certification. |
| 48 |
default: false |
| 49 |
type: bool |
| 50 |
log_path: |
| 51 |
description: |
| 52 |
- Path of debug log file. |
| 53 |
type: str |
| 54 |
author: |
| 55 |
- Shilpi Jain(@Shilpi-J) |
| 56 |
notes: |
| 57 |
- This module supports C(check_mode). |
| 58 |
''' |
| 59 |
|
| 60 |
EXAMPLES = ''' |
| 61 |
- name: Obtain an authentication token |
| 62 |
register: result |
| 63 |
ibm.storage_virtualize.ibm_svc_auth: |
| 64 |
clustername: "{{ clustername }}" |
| 65 |
domain: "{{ domain }}" |
| 66 |
username: "{{ username }}" |
| 67 |
password: "{{ password }}" |
| 68 |
- name: Create a volume |
| 69 |
ibm.storage_virtualize.ibm_svc_manage_volume: |
| 70 |
clustername: "{{ clustername }}" |
| 71 |
domain: "{{ domain }}" |
| 72 |
username: "{{ username }}" |
| 73 |
password: "{{ password }}" |
| 74 |
token: "{{ result.token }}" |
| 75 |
name: volume0 |
| 76 |
state: present |
| 77 |
pool: Pool0 |
| 78 |
size: "4294967296" |
| 79 |
unit: b |
| 80 |
''' |
| 81 |
|
| 82 |
RETURN = ''' |
| 83 |
token: |
| 84 |
description: Authentication token for a user. |
| 85 |
returned: success |
| 86 |
type: str |
| 87 |
version_added: 1.5.0 |
| 88 |
''' |
| 89 |
|
| 90 |
from ansible.module_utils.basic import AnsibleModule |
| 91 |
from ansible_collections.ibm.storage_virtualize.plugins.module_utils.ibm_svc_utils import IBMSVCRestApi, svc_argument_spec, get_logger |
| 92 |
from ansible.module_utils._text import to_native |
| 93 |
|
| 94 |
|
| 95 |
class IBMSVCauth(object): |
| 96 |
def __init__(self): |
| 97 |
argument_spec = svc_argument_spec() |
| 98 |
|
| 99 |
self.module = AnsibleModule(argument_spec=argument_spec, |
| 100 |
supports_check_mode=True) |
| 101 |
|
| 102 |
|
| 103 |
log_path = self.module.params['log_path'] |
| 104 |
log = get_logger(self.__class__.__name__, log_path) |
| 105 |
self.log = log.info |
| 106 |
|
| 107 |
self.restapi = IBMSVCRestApi( |
| 108 |
module=self.module, |
| 109 |
clustername=self.module.params['clustername'], |
| 110 |
domain=self.module.params['domain'], |
| 111 |
username=self.module.params['username'], |
| 112 |
password=self.module.params['password'], |
| 113 |
validate_certs=self.module.params['validate_certs'], |
| 114 |
log_path=log_path, |
| 115 |
token=None |
| 116 |
) |
| 117 |
|
| 118 |
|
| 119 |
def main(): |
| 120 |
v = IBMSVCauth() |
| 121 |
try: |
| 122 |
if v.restapi.token is not None: |
| 123 |
msg = "Authentication token generated" |
| 124 |
v.module.exit_json(msg=msg, token=v.restapi.token) |
| 125 |
else: |
| 126 |
msg = "Authentication token is not generated" |
| 127 |
v.module.fail_json(msg=msg, token=v.restapi.token) |
| 128 |
except Exception as e: |
| 129 |
v.module.fail_json(msg="Module failed. Error [%s]." % to_native(e)) |
| 130 |
|
| 131 |
|
| 132 |
if __name__ == '__main__': |
| 133 |
main() |