コード例 #1
0
    def __present(self):
        changed = False
        msg = ''

        if not self.current_resource:
            if 'credentials' not in self.data:
                raise OneViewModuleValueError(self.MSG_CREDENTIALS_MANDATORY)

            if self.oneview_client.api_version < 500:
                self.current_resource = self.resource_client.add(
                    self.data['credentials'])
            else:
                options = self.data['credentials'].copy()
                options['family'] = self.data.get('family', None)
                options['hostname'] = self.data.get('hostname', None)
                self.current_resource = self.resource_client.add(options)

            changed = True
            msg = self.MSG_ADDED

        else:
            resource = deepcopy(self.current_resource.data)
            data = self.data.copy()
            merged_data = dict_merge(resource, data)
            temp_list = []
            merged_data_copy = deepcopy(merged_data)
            if merged_data_copy.get('deviceSpecificAttributes') and merged_data_copy.get('deviceSpecificAttributes').get('discoveredPools') and \
                    merged_data_copy.get('deviceSpecificAttributes').get('managedPools'):
                for discoveredPool in merged_data_copy[
                        'deviceSpecificAttributes']['discoveredPools']:
                    for managedPool in merged_data['deviceSpecificAttributes'][
                            'managedPools']:
                        if discoveredPool['name'] == managedPool['name']:
                            temp_list.append(discoveredPool)
                            merged_data['deviceSpecificAttributes'][
                                'discoveredPools'].remove(discoveredPool)
                merged_data['deviceSpecificAttributes'][
                    'managedPools'] = temp_list

            # remove password, it cannot be used in comparison
            if 'credentials' in merged_data and 'password' in merged_data[
                    'credentials']:
                del merged_data['credentials']['password']

            if not compare(self.current_resource.data, merged_data):
                # update the resource
                self.current_resource.update(merged_data)
                # if not changed:
                changed = True
                msg = self.MSG_UPDATED
            else:
                msg = self.MSG_ALREADY_PRESENT

        return dict(
            changed=changed,
            msg=msg,
            ansible_facts=dict(storage_system=self.current_resource.data))
コード例 #2
0
    def __update(self):
        if "newName" in self.data:
            self.data["name"] = self.data.pop("newName")

        self.current_resource = self.current_resource[0]
        merged_rack_mounts = self.__mergeRackMounts()
        merged_data = dict_merge(self.data, self.current_resource)
        if "rackMounts" in merged_rack_mounts:
            merged_data['rackMounts'] = merged_rack_mounts['rackMounts']
        if not compare(self.current_resource, merged_data):
            updated_response = self.resource_client.update(merged_data)
            return True, self.MSG_UPDATED, dict(rack=updated_response)
        else:
            return False, self.MSG_ALREADY_PRESENT, dict(
                rack=self.current_resource)
コード例 #3
0
    def __update(self):
        changed = False
        existing_data = self.current_resource.data.copy()
        updated_data = dict_merge(existing_data, self.data)

        state_change, updated_data = self.__compare_resource_assignments(
            existing_data, updated_data)

        if compare(self.current_resource.data,
                   updated_data) and state_change is False:
            msg = self.MSG_ALREADY_PRESENT
        else:
            self.current_resource.update(updated_data)
            changed = True
            msg = self.MSG_UPDATED

        return changed, msg
コード例 #4
0
    def __update(self):
        if "newName" in self.data:
            self.data["name"] = self.data.pop("newName")

        self.current_resource = self.current_resource[0]
        merged_rack_mounts = self.__mergeRackMounts()
        merged_data = dict_merge(self.data, self.current_resource)
        if "rackMounts" in merged_rack_mounts:
            merged_data['rackMounts'] = merged_rack_mounts['rackMounts']
        if not compare(self.current_resource, merged_data):
            updated_response = self.resource_client.update(merged_data)
            changed = True
            msg = self.MSG_UPDATED
            return dict(changed=changed,
                        msg=msg,
                        ansible_facts=dict(rack=updated_response))
        else:
            changed = False
            msg = self.MSG_ALREADY_PRESENT
            return dict(changed=changed,
                        msg=msg,
                        ansible_facts=dict(rack=self.current_resource))