From ca1525310f8853d534590346f5d9688ddeedfd0e Mon Sep 17 00:00:00 2001 From: Fabrice Peraud Date: Wed, 25 Aug 2021 11:50:29 +0200 Subject: [PATCH] dellemc_unity_host: Addition of ip to Host --- plugins/modules/dellemc_unity_host.py | 39 ++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/plugins/modules/dellemc_unity_host.py b/plugins/modules/dellemc_unity_host.py index 741025d..0675b46 100644 --- a/plugins/modules/dellemc_unity_host.py +++ b/plugins/modules/dellemc_unity_host.py @@ -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. @@ -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}}" @@ -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'] @@ -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: @@ -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 @@ -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: @@ -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.') @@ -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']) )