Debian Codegraph @

ansible_collections/cisco/ucs/plugins/modules/ucs_wwn_pool.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'certified'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: ucs_wwn_pool
16 short_description: Configures WWNN or WWPN pools on Cisco UCS Manager
17 description:
18 - Configures WWNNs or WWPN pools on Cisco UCS Manager.
19 extends_documentation_fragment: cisco.ucs.ucs
20 options:
21 state:
22 description:
23 - If C(present), will verify WWNNs/WWPNs are present and will create if needed.
24 - If C(absent), will verify WWNNs/WWPNs are absent and will delete if needed.
25 choices: [present, absent]
26 default: present
27 type: str
28 name:
29 description:
30 - The name of the World Wide Node Name (WWNN) or World Wide Port Name (WWPN) pool.
31 - This name can be between 1 and 32 alphanumeric characters.
32 - "You cannot use spaces or any special characters other than - (hyphen), \"_\" (underscore), : (colon), and . (period)."
33 - You cannot change this name after the WWNN or WWPN pool is created.
34 required: yes
35 type: str
36 purpose:
37 description:
38 - Specify whether this is a node (WWNN) or port (WWPN) pool.
39 - Optional if state is absent.
40 choices: [node, port]
41 type: str
42 description:
43 description:
44 - A description of the WWNN or WWPN pool.
45 - Enter up to 256 characters.
46 - "You can use any characters or spaces except the following:"
47 - "` (accent mark), \ (backslash), ^ (carat), \" (double quote), = (equal sign), > (greater than), < (less than), or ' (single quote)."
48 aliases: [ descr ]
49 type: str
50 order:
51 description:
52 - The Assignment Order field.
53 - "This can be one of the following:"
54 - "default - Cisco UCS Manager selects a random identity from the pool."
55 - "sequential - Cisco UCS Manager selects the lowest available identity from the pool."
56 choices: [default, sequential]
57 default: default
58 type: str
59 first_addr:
60 description:
61 - The first initiator in the World Wide Name (WWN) block.
62 - This is the From field in the UCS Manager Add WWN Blocks menu.
63 type: str
64 last_addr:
65 description:
66 - The last initiator in the World Wide Name (WWN) block.
67 - This is the To field in the UCS Manager Add WWN Blocks menu.
68 - For WWxN pools, the pool size must be a multiple of ports-per-node + 1.
69 - For example, if there are 7 ports per node, the pool size must be a multiple of 8.
70 - If there are 63 ports per node, the pool size must be a multiple of 64.
71 type: str
72 org_dn:
73 description:
74 - Org dn (distinguished name)
75 default: org-root
76 type: str
77 requirements:
78 - ucsmsdk
79 author:
80 - David Soper (@dsoper2)
81 - John McDonough (@movinalot)
82 - CiscoUcs (@CiscoUcs)
83 '''
84
85 EXAMPLES = r'''
86 - name: Configure WWNN/WWPN pools
87 cisco.ucs.ucs_wwn_pool:
88 hostname: 172.16.143.150
89 username: admin
90 password: password
91 name: WWNN-Pool
92 purpose: node
93 first_addr: 20:00:00:25:B5:48:00:00
94 last_addr: 20:00:00:25:B5:48:00:0F
95 - cisco.ucs.ucs_wwn_pool:
96 hostname: 172.16.143.150
97 username: admin
98 password: password
99 name: WWPN-Pool-A
100 purpose: port
101 order: sequential
102 first_addr: 20:00:00:25:B5:48:0A:00
103 last_addr: 20:00:00:25:B5:48:0A:0F
104
105 - name: Remove WWNN/WWPN pools
106 cisco.ucs.ucs_wwn_pool:
107 hostname: 172.16.143.150
108 username: admin
109 password: password
110 name: WWNN-Pool
111 state: absent
112 - cisco.ucs.ucs_wwn_pool:
113 hostname: 172.16.143.150
114 username: admin
115 password: password
116 name: WWPN-Pool-A
117 state: absent
118 '''
119
120 RETURN = r'''
121 #
122 '''
123
124 from ansible.module_utils.basic import AnsibleModule
125 from ansible_collections.cisco.ucs.plugins.module_utils.ucs import UCSModule, ucs_argument_spec
126
127
128 def main():
129 argument_spec = ucs_argument_spec.copy()
130 argument_spec.update(
131 org_dn=dict(type='str', default='org-root'),
132 name=dict(type='str', required=True),
133 purpose=dict(type='str', choices=['node', 'port']),
134 description=dict(type='str', aliases=['descr']),
135 order=dict(type='str', default='default', choices=['default', 'sequential']),
136 first_addr=dict(type='str'),
137 last_addr=dict(type='str'),
138 state=dict(type='str', default='present', choices=['present', 'absent']),
139 )
140
141 module = AnsibleModule(
142 argument_spec,
143 supports_check_mode=True,
144 )
145 ucs = UCSModule(module)
146
147 err = False
148
149 from ucsmsdk.mometa.fcpool.FcpoolInitiators import FcpoolInitiators
150 from ucsmsdk.mometa.fcpool.FcpoolBlock import FcpoolBlock
151
152 changed = False
153 try:
154 # single resource specified, create list from the current params
155 wwn_list = [module.params]
156 for wwn in wwn_list:
157 mo_exists = False
158 props_match = False
159 # set default params. Done here to set values for lists which can't be done in the argument_spec
160 if not wwn.get('descr'):
161 wwn['descr'] = ''
162 if not wwn.get('order'):
163 wwn['order'] = 'default'
164 # dn is <org_dn>/wwn-pool-<name> for WWNN or WWPN
165 dn = module.params['org_dn'] + '/wwn-pool-' + wwn['name']
166
167 mo = ucs.login_handle.query_dn(dn)
168 if mo:
169 mo_exists = True
170
171 if module.params['state'] == 'absent':
172 if mo_exists:
173 if not module.check_mode:
174 ucs.login_handle.remove_mo(mo)
175 ucs.login_handle.commit()
176 changed = True
177 else:
178 # append purpose param with suffix used by UCSM
179 purpose_param = wwn['purpose'] + '-wwn-assignment'
180 if mo_exists:
181 # check top-level mo props
182 kwargs = dict(assignment_order=wwn['order'])
183 kwargs['descr'] = wwn['descr']
184 kwargs['purpose'] = purpose_param
185 if (mo.check_prop_match(**kwargs)):
186 # top-level props match, check next level mo/props
187 if 'last_addr' in wwn and 'first_addr' in wwn:
188 block_dn = dn + '/block-' + wwn['first_addr'].upper() + '-' + wwn['last_addr'].upper()
189 mo_1 = ucs.login_handle.query_dn(block_dn)
190 if mo_1:
191 props_match = True
192 else:
193 props_match = True
194
195 if not props_match:
196 if not module.check_mode:
197 # create if mo does not already exist
198 mo = FcpoolInitiators(
199 parent_mo_or_dn=module.params['org_dn'],
200 name=wwn['name'],
201 descr=wwn['descr'],
202 assignment_order=wwn['order'],
203 purpose=purpose_param,
204 )
205 if 'last_addr' in wwn and 'first_addr' in wwn:
206 mo_1 = FcpoolBlock(
207 parent_mo_or_dn=mo,
208 to=wwn['last_addr'],
209 r_from=wwn['first_addr'],
210 )
211
212 ucs.login_handle.add_mo(mo, True)
213 ucs.login_handle.commit()
214 changed = True
215
216 except Exception as e:
217 err = True
218 ucs.result['msg'] = "setup error: %s " % str(e)
219
220 ucs.result['changed'] = changed
221 if err:
222 module.fail_json(**ucs.result)
223 module.exit_json(**ucs.result)
224
225
226 if __name__ == '__main__':
227 main()