def __present(self, resource): changed = False msg = '' if not resource: resource = self.oneview_client.users.create(self.data) msg = self.MSG_CREATED changed = True else: merged_data = resource.copy() merged_data.update(self.data) # remove password, it cannot be used in comparison if 'password' in merged_data: del merged_data['password'] if ResourceComparator.compare(resource, merged_data): msg = self.MSG_ALREADY_PRESENT else: resource = self.resource_client.update(merged_data) changed = True msg = self.MSG_UPDATED return dict(changed=changed, msg=msg, ansible_facts=dict(user=resource))
def __present(self, resource): changed = False msg = '' if not resource: if 'credentials' not in self.data: raise HPOneViewValueError(self.MSG_CREDENTIALS_MANDATORY) resource = self.oneview_client.storage_systems.add(self.data['credentials']) changed = True msg = self.MSG_ADDED merged_data = resource.copy() merged_data.update(self.data) if 'credentials' in merged_data and 'password' in merged_data['credentials']: # remove password, it cannot be used in comparison del merged_data['credentials']['password'] if not ResourceComparator.compare(resource, merged_data): # update the resource resource = self.oneview_client.storage_systems.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=resource))
def __present(self, resource, data): self.__replace_names_by_uris(data) changed = False if "newName" in data: data["name"] = data.pop("newName") if not resource: resource = self.oneview_client.os_deployment_servers.add(data) changed = True msg = self.MSG_CREATED else: appliance_uri = data.pop('applianceUri', '') if appliance_uri: data['primaryActiveAppliance'] = appliance_uri merged_data = resource.copy() merged_data.update(data) if not ResourceComparator.compare(resource, merged_data): resource = self.oneview_client.os_deployment_servers.update( merged_data) changed = True msg = self.MSG_UPDATED else: msg = self.MSG_ALREADY_PRESENT return dict(changed=changed, msg=msg, ansible_facts=dict(os_deployment_server=resource))
def __present(self, resource, data): self.__replace_names_by_uris(data) changed = False if "newName" in data: data["name"] = data.pop("newName") if not resource: resource = self.oneview_client.os_deployment_servers.add(data) changed = True msg = self.MSG_CREATED else: appliance_uri = data.pop('applianceUri', '') if appliance_uri: data['primaryActiveAppliance'] = appliance_uri merged_data = resource.copy() merged_data.update(data) if not ResourceComparator.compare(resource, merged_data): resource = self.oneview_client.os_deployment_servers.update(merged_data) changed = True msg = self.MSG_UPDATED else: msg = self.MSG_ALREADY_PRESENT return dict(changed=changed, msg=msg, ansible_facts=dict(os_deployment_server=resource))
def __present(self, data, resource): changed = False msg = self.MSG_ALREADY_PRESENT if not resource: if self.oneview_client.api_version >= 500: raise HPOneViewResourceNotFound(self.MSG_RESOURCE_NOT_FOUND) else: resource = self.oneview_client.storage_pools.add(data) changed = True msg = self.MSG_CREATED else: merged_data = resource.copy() merged_data.update(self.data) if ResourceComparator.compare(resource, merged_data): msg = self.MSG_ALREADY_PRESENT else: resource = self.resource_client.update(merged_data) changed = True msg = self.MSG_UPDATED return dict(changed=changed, msg=msg, ansible_facts=dict(storage_pool=resource))
def __update_settings(self, resource, data): self.__validate_settings(data) ethernet_settings_merged = self.__merge_network_settings('ethernetSettings', resource, data) fcoe_settings_merged = self.__merge_network_settings('fcoeSettings', resource, data) if ResourceComparator.compare(resource['ethernetSettings'], ethernet_settings_merged) and \ ResourceComparator.compare(resource['fcoeSettings'], fcoe_settings_merged): return False, self.MSG_NO_CHANGES_PROVIDED, dict(logical_interconnect=resource) else: settings = { 'ethernetSettings': ethernet_settings_merged, 'fcoeSettings': fcoe_settings_merged } li = self.oneview_client.logical_interconnects.update_settings(resource['uri'], settings) return True, self.MSG_SETTINGS_UPDATED, dict(logical_interconnect=li)
def __present(self, data, resource): server_template_name = data.pop('serverProfileTemplateName', '') server_hardware_name = data.pop('serverHardwareName', '') server_template = None changed = False created = False ServerProfileReplaceNamesByUris().replace(self.oneview_client, data) if server_hardware_name: selected_server_hardware = self.__get_server_hardware_by_name(server_hardware_name) if not selected_server_hardware: raise HPOneViewValueError(self.MSG_HARDWARE_NOT_FOUND.format(server_hardware_name)) data['serverHardwareUri'] = selected_server_hardware['uri'] if server_template_name: server_template = self.oneview_client.server_profile_templates.get_by_name(server_template_name) if not server_template: raise HPOneViewValueError(self.MSG_TEMPLATE_NOT_FOUND.format(server_template_name)) data['serverProfileTemplateUri'] = server_template['uri'] elif data.get('serverProfileTemplateUri'): server_template = self.oneview_client.server_profile_templates.get(data['serverProfileTemplateUri']) if not resource: resource = self.__create_profile(data, server_template) changed = True created = True msg = self.MSG_CREATED else: # This allows unassigning a profile if a SH key is specifically passed in as None if not self.auto_assign_server_hardware: server_hardware_uri_exists = False if 'serverHardwareUri' in self.module.params['data'].keys() or 'serverHardwareName' in self.module.params['data'].keys(): server_hardware_uri_exists = True if data.get('serverHardwareUri') is None and server_hardware_uri_exists: data['serverHardwareUri'] = None # Auto assigns a Server Hardware to Server Profile if auto_assign_server_hardware is True and no SH uris exist if not resource.get('serverHardwareUri') and not data.get('serverHardwareUri') and self.auto_assign_server_hardware: data['serverHardwareUri'] = self._auto_assign_server_profile(data, server_template) merged_data = ServerProfileMerger().merge_data(resource, data) self.__validations_for_os_custom_attributes(data, merged_data, resource) if not ResourceComparator.compare(resource, merged_data): resource = self.__update_server_profile(merged_data, resource) changed = True msg = self.MSG_UPDATED else: msg = self.MSG_ALREADY_PRESENT return created, changed, msg, resource
def __reserved_vlan_range_updated(self): resource = self.get_by_name(self.data['name']) if not resource: raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND) resource_vlan_range = resource.get('reservedVlanRange') merged_data = resource_vlan_range.copy() merged_data.update(self.data['reservedVlanRangeParameters']) if ResourceComparator.compare(resource_vlan_range, merged_data): return dict(changed=False, msg=self.MSG_ALREADY_PRESENT, ansible_facts=dict(fabric=resource)) else: return self.__update_vlan_range(self.data, resource)
def __update_ethernet_settings(self, resource, data): self.__validate_options('ethernetSettings', data) ethernet_settings_merged = resource['ethernetSettings'].copy() ethernet_settings_merged.update(data['ethernetSettings']) if ResourceComparator.compare(resource['ethernetSettings'], ethernet_settings_merged): return False, self.MSG_NO_CHANGES_PROVIDED, dict() else: li = self.oneview_client.logical_interconnects.update_ethernet_settings(resource['uri'], ethernet_settings_merged) return True, self.MSG_ETH_SETTINGS_UPDATED, dict(logical_interconnect=li)
def __update_port_monitor(self, uri, data): self.__validate_options('portMonitor', data) monitor_config = self.__get_port_monitor_configuration(uri) monitor_config_merged = self.__merge_options(data['portMonitor'], monitor_config) if ResourceComparator.compare(monitor_config_merged, monitor_config): return False, self.MSG_NO_CHANGES_PROVIDED, None else: monitor_config_updated = self.oneview_client.logical_interconnects.update_port_monitor( uri, monitor_config_merged) result = dict(port_monitor=monitor_config_updated) return True, self.MSG_PORT_MONITOR_UPDATED, result
def __update_qos_configuration(self, uri, data): self.__validate_options('qosConfiguration', data) qos_config = self.__get_qos_aggregated_configuration(uri) qos_config_merged = self.__merge_options(data['qosConfiguration'], qos_config) if ResourceComparator.compare(qos_config_merged, qos_config): return False, self.MSG_NO_CHANGES_PROVIDED, dict() else: qos_config_updated = self.oneview_client.logical_interconnects.update_qos_aggregated_configuration( uri, qos_config_merged) return True, self.MSG_QOS_UPDATED, dict(qos_configuration=qos_config_updated)
def __update(self, new_data, existent_resource): if "newName" in new_data: new_data["name"] = new_data["newName"] del new_data["newName"] merged_data = existent_resource.copy() merged_data.update(new_data) if not ResourceComparator.compare(existent_resource, merged_data): existent_resource = self.oneview_client.logical_enclosures.update(merged_data) return True, self.MSG_UPDATED, dict(logical_enclosure=existent_resource) else: return False, self.MSG_ALREADY_PRESENT, dict(logical_enclosure=existent_resource)
def __update_snmp_configuration(self, uri, data): self.__validate_options('snmpConfiguration', data) snmp_config = self.__get_snmp_configuration(uri) snmp_config_merged = self.__merge_options(data['snmpConfiguration'], snmp_config) if ResourceComparator.compare(snmp_config_merged, snmp_config): return False, self.MSG_NO_CHANGES_PROVIDED, None else: snmp_config_updated = self.oneview_client.logical_interconnects.update_snmp_configuration( uri, snmp_config_merged) return True, self.MSG_SNMP_UPDATED, dict(snmp_configuration=snmp_config_updated)
def __update(self, data, resource): merged_data = resource.copy() merged_data.update(data) if ResourceComparator.compare(resource, merged_data): changed = False msg = self.MSG_NO_CHANGES_PROVIDED else: changed = True resource = self.oneview_client.managed_sans.update(resource['uri'], data) msg = self.MSG_UPDATED return dict(changed=changed, msg=msg, ansible_facts=dict(managed_san=resource))
def __update_connection_template(self, ethernet_network, bandwidth): if 'connectionTemplateUri' not in ethernet_network: return False, None connection_template = self.oneview_client.connection_templates.get(ethernet_network['connectionTemplateUri']) merged_data = connection_template.copy() merged_data.update({'bandwidth': bandwidth}) if not ResourceComparator.compare(connection_template, merged_data): connection_template = self.oneview_client.connection_templates.update(merged_data) return True, connection_template else: return False, None
def __update(self, data, resource): if resource is None: resource = self.__get_by_name(data['newName']) data["name"] = data.pop("newName") merged_data = resource.copy() merged_data.update(data) if not ResourceComparator.compare(resource, merged_data): resource = self.i3s_client.artifact_bundles.update(merged_data) changed = True msg = self.MSG_UPDATED else: changed = False msg = self.MSG_ALREADY_PRESENT return changed, msg, dict(artifact_bundle=resource)
def __present(self, data, resource): server_template_name = data.pop('server_template', '') server_hardware_name = data.pop('server_hardware', '') server_template = None changed = False created = False ServerProfileReplaceNamesByUris().replace(self.oneview_client, data) if server_hardware_name: selected_server_hardware = self.__get_server_hardware_by_name( server_hardware_name) if not selected_server_hardware: raise HPOneViewValueError( self.MSG_HARDWARE_NOT_FOUND.format(server_hardware_name)) data['serverHardwareUri'] = selected_server_hardware['uri'] if server_template_name: server_template = self.oneview_client.server_profile_templates.get_by_name( server_template_name) if not server_template: raise HPOneViewValueError( self.MSG_TEMPLATE_NOT_FOUND.format(server_template_name)) data['serverProfileTemplateUri'] = server_template['uri'] elif data.get('serverProfileTemplateUri'): server_template = self.oneview_client.server_profile_templates.get( data['serverProfileTemplateUri']) if not resource: resource = self.__create_profile(data, server_template) changed = True created = True msg = self.MSG_CREATED else: merged_data = ServerProfileMerger().merge_data(resource, data) self.__validations_for_os_custom_attributes( data, merged_data, resource) if not ResourceComparator.compare(resource, merged_data): resource = self.__update_server_profile(merged_data) changed = True msg = self.MSG_UPDATED else: msg = self.MSG_ALREADY_PRESENT return created, changed, msg, resource
def __update(self, new_data, existent_resource): if "newName" in new_data: new_data["name"] = new_data["newName"] del new_data["newName"] merged_data = existent_resource.copy() merged_data.update(new_data) if not ResourceComparator.compare(existent_resource, merged_data): existent_resource = self.oneview_client.logical_enclosures.update( merged_data) return True, self.MSG_UPDATED, dict( logical_enclosure=existent_resource) else: return False, self.MSG_ALREADY_PRESENT, dict( logical_enclosure=existent_resource)
def __update(self, data, template): resource = template.copy() merged_data = ServerProfileMerger().merge_data(resource, data) equal = ResourceComparator.compare(merged_data, resource) if equal: msg = self.MSG_ALREADY_PRESENT else: resource = self.resource_client.update(resource=merged_data, id_or_uri=merged_data["uri"]) msg = self.MSG_UPDATED changed = not equal return changed, msg, resource
def __update_connection_template(self, ethernet_network, bandwidth): if 'connectionTemplateUri' not in ethernet_network: return False, None connection_template = self.oneview_client.connection_templates.get( ethernet_network['connectionTemplateUri']) merged_data = connection_template.copy() merged_data.update({'bandwidth': bandwidth}) if not ResourceComparator.compare(connection_template, merged_data): connection_template = self.oneview_client.connection_templates.update( merged_data) return True, connection_template else: return False, None
def __present(self, resource): if not resource: provider_uri = self.data.get('providerUri', self.__get_provider_uri_by_display_name(self.data)) return True, self.MSG_CREATED, self.resource_client.add(self.data, provider_uri) else: merged_data = resource.copy() merged_data.update(self.data) # Remove 'connectionInfo' from comparison, since it is not possible to validate it. resource.pop('connectionInfo', None) merged_data.pop('connectionInfo', None) if ResourceComparator.compare(resource, merged_data): return False, self.MSG_ALREADY_PRESENT, resource else: updated_san_manager = self.resource_client.update(resource=merged_data, id_or_uri=resource['uri']) return True, self.MSG_UPDATED, updated_san_manager
def _present(self, data, resource): if not resource: return self.resource_present(resource, fact_name='storage_volume_template') else: changed = False merged_data = _update_dict_with_depth(deepcopy(resource), data) if ResourceComparator.compare(resource, merged_data): msg = self.MSG_ALREADY_PRESENT else: resource = self.resource_client.update(merged_data) changed = True msg = self.MSG_UPDATED return dict(msg=msg, changed=changed, ansible_facts={'storage_volume_template': resource})
def __present(self, resource): if not resource: provider_uri = self.data.get('providerUri', self.__get_provider_uri_by_display_name(self.data)) return True, self.MSG_CREATED, self.resource_client.add(self.data, provider_uri) else: merged_data = resource.copy() merged_data.update(self.data) if ResourceComparator.compare(resource, merged_data): return False, self.MSG_ALREADY_PRESENT, resource else: # If connectionInfo is not provided, its removed because the password is required for update. if 'connectionInfo' not in self.data: merged_data.pop('connectionInfo') updated_san_manager = self.resource_client.update(resource=merged_data, id_or_uri=resource['uri']) return True, self.MSG_UPDATED, updated_san_manager
def __present(self, data, resource): changed = False msg = '' if not resource: raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND) else: if 'newName' in data: data['name'] = data.pop('newName') merged_data = resource.copy() merged_data.update(data) if not ResourceComparator.compare(resource, merged_data): resource = self.resource_client.update(merged_data) changed = True msg = self.MSG_UPDATED else: msg = self.MSG_ALREADY_PRESENT return changed, msg, dict(connection_template=resource)
def __present(self, data, resource): server_template_name = data.pop('server_template', '') server_hardware_name = data.pop('server_hardware', '') server_template = None changed = False created = False ServerProfileReplaceNamesByUris().replace(self.oneview_client, data) if server_hardware_name: selected_server_hardware = self.__get_server_hardware_by_name(server_hardware_name) if not selected_server_hardware: raise HPOneViewValueError(self.MSG_HARDWARE_NOT_FOUND.format(server_hardware_name)) data['serverHardwareUri'] = selected_server_hardware['uri'] if server_template_name: server_template = self.oneview_client.server_profile_templates.get_by_name(server_template_name) if not server_template: raise HPOneViewValueError(self.MSG_TEMPLATE_NOT_FOUND.format(server_template_name)) data['serverProfileTemplateUri'] = server_template['uri'] elif data.get('serverProfileTemplateUri'): server_template = self.oneview_client.server_profile_templates.get(data['serverProfileTemplateUri']) if not resource: resource = self.__create_profile(data, server_template) changed = True created = True msg = self.MSG_CREATED else: merged_data = ServerProfileMerger().merge_data(resource, data) if not ResourceComparator.compare(resource, merged_data): resource = self.__update_server_profile(merged_data) changed = True msg = self.MSG_UPDATED else: msg = self.MSG_ALREADY_PRESENT return created, changed, msg, resource
def __present(self, resource): changed = False msg = '' if not resource: if 'credentials' not in self.data: raise HPOneViewValueError(self.MSG_CREDENTIALS_MANDATORY) if self.oneview_client.api_version < 500: resource = self.oneview_client.storage_systems.add(self.data['credentials']) else: options = self.data['credentials'].copy() options['family'] = self.data.get('family', None) options['hostname'] = self.data.get('hostname', None) resource = self.oneview_client.storage_systems.add(options) changed = True msg = self.MSG_ADDED merged_data = resource.copy() merged_data.update(self.data) # 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 ResourceComparator.compare(resource, merged_data): # update the resource resource = self.oneview_client.storage_systems.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=resource))
def __present(self, data, resource): changed = False msg = '' if "newName" in data: data["name"] = data.pop("newName") self.__replace_name_by_uris(data) self.__check_present_consistency(data) file_path = data.pop('localImageFilePath', None) if not resource: if data.get('osVolumeURI'): resource = self.i3s_client.golden_images.create(data) msg = self.MSG_CREATED changed = True elif file_path: resource = self.i3s_client.golden_images.upload(file_path, data) msg = self.MSG_UPLOADED changed = True else: raise HPOneViewValueError(self.MSG_MISSING_MANDATORY_ATTRIBUTES) else: merged_data = resource.copy() merged_data.update(data) if not ResourceComparator.compare(resource, merged_data): resource = self.i3s_client.golden_images.update(merged_data) changed = True msg = self.MSG_UPDATED else: msg = self.MSG_ALREADY_PRESENT return changed, msg, dict(golden_image=resource)