def __parse_data(self): data = deepcopy(self.data) # Allow usage of baselineName instead of baselineUri if data.get('baselineName'): baseline_name = data.pop('baselineName', "") spp = self.resource_client.get_by_name(baseline_name) if spp: data['baselineUri'] = spp.data['uri'] else: raise OneViewModuleException( "Baseline SPP named '{0}' not found in OneView Appliance.". format(baseline_name)) # Allow usage of hotfixNames instead of hotfixUris if data and data.get('hotfixNames'): hotfix_names = data.pop('hotfixNames', []) data['hotfixUris'] = data.get('hotfixUris', []) for hotfix_name in hotfix_names: hotfix = self.resource_client.get_by_name(hotfix_name) if hotfix: data['hotfixUris'].append(hotfix.data['uri']) else: raise OneViewModuleException( "Hotfix named '{0}' not found in OneView Appliance.". format(hotfix_name)) return data
def __create_profile(self): tries = 0 self.__remove_inconsistent_data() while tries < self.CONCURRENCY_FAILOVER_RETRIES: try: tries += 1 server_hardware_uri = self._auto_assign_server_profile() if server_hardware_uri: self.module.log(msg="Power off the Server Hardware before create the Server Profile") self.__set_server_hardware_power_state(server_hardware_uri, 'Off') # Build the data to create a new server profile based on a template if informed server_profile = self.__build_new_profile_data(server_hardware_uri) self.module.log(msg="Request Server Profile creation") return self.resource_client.create(server_profile, **self.params) except OneViewModuleTaskError as task_error: self.module.log("Error code: {0} Message: {1}".format(str(task_error.error_code), str(task_error.msg))) if task_error.error_code in self.ASSIGN_HARDWARE_ERROR_CODES: # if this is because the server is already assigned, someone grabbed it before we assigned, # ignore and try again # This waiting time was chosen empirically and it could differ according to the hardware. time.sleep(10) else: raise task_error raise OneViewModuleException(self.MSG_ERROR_ALLOCATE_SERVER_HARDWARE)
def __update_server_profile(self, profile_with_updates): self.module.log(msg="Updating Server Profile") # These removes are necessary in case SH associated to the SP is being changed if self.data.get('enclosureUri') is None: profile_with_updates.pop('enclosureUri', None) if self.data.get('enclosureBay') is None: profile_with_updates.pop('enclosureBay', None) # Some specific SP operations require the SH to be powered off. This method attempts # the update, and in case of failure mentioning powering off the SH, a Power off on # the SH is attempted, followed by the update operation again and a Power On. try: self.current_resource.update(profile_with_updates) except OneViewModuleException as exception: error_msg = '; '.join(str(e) for e in exception.args) power_on_msg = 'Some server profile attributes cannot be changed while the server hardware is powered on.' if power_on_msg in error_msg: self.module.log("Update failed due to powered on Server Hardware. Powering off before retrying.") time.sleep(10) # sleep timer to avoid timing issues after update operation failed # When reassigning Server Hardwares, both the original and the new SH should be set to OFF self.__set_server_hardware_power_state(self.current_resource.data['serverHardwareUri'], 'Off') self.__set_server_hardware_power_state(profile_with_updates['serverHardwareUri'], 'Off') self.module.log("Retrying update operation after server power off") self.current_resource.update(profile_with_updates) self.module.log("Powering on the server hardware after update") self.__set_server_hardware_power_state(self.current_resource.data['serverHardwareUri'], 'On') else: raise OneViewModuleException(error_msg)
def execute_module(self): if not self.current_resource: return dict(failed=True, msg=self.MSG_RESOURCE_NOT_FOUND) try: self.current_resource.patch(self.data['uri']) except OneViewModuleException as exception: error_msg = '; '.join(str(e) for e in exception.args) raise OneViewModuleException(error_msg) return dict(changed=True, msg=self.MSG_TASK_UPDATED, ansible_facts=dict(tasks=self.current_resource.data))
def execute_module(self): data = deepcopy(self.data) or {} # Checks for the name and data['customBaselineName'] params for a name attribute to the Firmware Driver. if not data.get('customBaselineName') and not self.module.params.get( 'name'): msg = "A 'name' parameter or a 'customBaselineName' field inside the 'data' parameter " msg += "is required for this operation." raise OneViewModuleException(msg) # name parameter takes priority over customBaselineName if data.get( 'customBaselineName') and not self.module.params.get('name'): self.current_resource = self.resource_client.get_by_name( data['customBaselineName']) if self.state == 'present': changed, msg, firmware_driver = self.__present(data) return dict(changed=changed, msg=msg, ansible_facts=firmware_driver) elif self.state == 'absent': return self.resource_absent()