Skip to content

dellemc_unity_host: Addition of ip to Host #4

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
39 changes: 38 additions & 1 deletion plugins/modules/dellemc_unity_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
choices: [present-in-host , absent-in-host]
type: str

host_ips:
description:
- Host IPs list
type: list
elements: str

state:
description:
- State of the host.
Expand All @@ -97,6 +103,19 @@
description: "ansible-test-host"
state: "present"

- name: Create Host with Ips.
dellemc_unity_host:
unispherehost: "{{unispherehost}}"
username: "{{username}}"
password: "{{password}}"
verifycert: "{{verifycert}}"
host_name: "ansible-test-host"
host_os: "Linux"
host_ips:
- 192.168.0.128
description: "ansible-test-host"
state: "present"

- name: Create Host with Initiators.
dellemc_unity_host:
unispherehost: "{{unispherehost}}"
Expand Down Expand Up @@ -321,6 +340,7 @@ def create_host(self, host_name):
try:
description = self.module.params['description']
host_os = self.module.params['host_os']
host_ips = self.module.params["host_ips"]
host_type = utils.HostTypeEnum.HOST_MANUAL
initiators = self.module.params['initiators']
initiator_state = self.module.params['initiator_state']
Expand Down Expand Up @@ -358,6 +378,13 @@ def create_host(self, host_name):
result, new_host \
= self.add_initiator_to_host(host_details, initiators)

# Add ips, if given
if host_ips and len(host_ips) > 0:
host_details = self.unity.get_host(name=host_name)
for ip in host_ips:
host_details.add_ip_port(ip)
new_host = self.unity.get_host(name=host_details.name)

return True, new_host

except Exception as e:
Expand Down Expand Up @@ -409,7 +436,9 @@ def is_host_modified(self, host_details):
'new_host_name'] != host_details.name) \
or (self.module.params['initiators'] is not None
and self.module.params['initiators']
!= self.get_host_initiators_list(host_details)):
!= self.get_host_initiators_list(host_details)) \
or (self.module.params['host_ips'] is not None
and self.module.params['host_ips'] != host_details.ip_list):
LOG.info("Modification required.")
modified_flag = True

Expand Down Expand Up @@ -594,6 +623,7 @@ def perform_module_operation(self):
new_host_name = self.module.params['new_host_name']
initiator_state = self.module.params['initiator_state']
initiators = self.module.params['initiators']
host_ips = self.module.params['host_ips']
state = self.module.params['state']

if host_name and len(host_name) > 255:
Expand Down Expand Up @@ -696,6 +726,12 @@ def perform_module_operation(self):
= self.add_initiator_to_host(host_details, initiators)
result['host_details'] = host_details._get_properties()

# Add ips, if given
if host_ips and len(host_ips) > 0:
host_details = self.unity.get_host(name=host_name)
for ip in host_ips:
host_details.add_ip_port(ip)

else:
LOG.info('Host modification is not applicable, '
'as none of the attributes has changed.')
Expand Down Expand Up @@ -752,6 +788,7 @@ def get_unity_host_parameters():
initiator_state=dict(required=False, type='str',
choices=['present-in-host',
'absent-in-host']),
host_ips=dict(Required=False, type='list', elements='str'),
state=dict(required=True, type='str',
choices=['present', 'absent'])
)
Expand Down