Ejemplo n.º 1
0
    def execute_module(self):
        if self.data.get('connectionInfo'):
            for connection_hash in self.data.get('connectionInfo'):
                if connection_hash.get('name') == 'Host':
                    resource_name = connection_hash.get('value')
        elif self.data.get('name'):
            resource_name = self.data.get('name')
        else:
            msg = 'A "name" or "connectionInfo" must be provided inside the "data" field for this operation. '
            msg += 'If a "connectionInfo" is provided, the "Host" name is considered as the "name" for the resource.'
            raise OneViewModuleValueError(msg.format())

        resource = self.resource_client.get_by_name(resource_name)

        if self.state == 'present':
            changed, msg, san_manager = self._present(resource)
            return dict(changed=changed,
                        msg=msg,
                        ansible_facts=dict(san_manager=san_manager))

        elif self.state == 'absent':
            return self.resource_absent(resource, method='remove')

        elif self.state == 'connection_information_set':
            changed, msg, san_manager = self._connection_information_set(
                resource)
            return dict(changed=changed,
                        msg=msg,
                        ansible_facts=dict(san_manager=san_manager))
    def _get_provider_uri_by_display_name(self, data):
        display_name = data.get('providerDisplayName')
        provider_uri = self.resource_client.get_provider_uri(display_name)

        if not provider_uri:
            raise OneViewModuleValueError(self.MSG_SAN_MANAGER_PROVIDER_DISPLAY_NAME_NOT_FOUND.format(display_name))

        return provider_uri
 def _connection_information_set(self, resource):
     if not resource:
         return self._present(resource)
     else:
         merged_data = resource.copy()
         merged_data.update(self.data)
         merged_data.pop('refreshState', None)
         if not self.data.get('connectionInfo', None):
             raise OneViewModuleValueError('A connectionInfo field is required for this operation.')
         updated_san_manager = self.resource_client.update(resource=merged_data, id_or_uri=resource['uri'])
         return True, self.MSG_UPDATED, updated_san_manager