def setup_idrac_syslog(idrac, module): """ Setup iDRAC remote syslog settings idrac -- iDRAC handle module -- Ansible module """ msg = {} msg['changed'] = False msg['failed'] = False msg['msg'] = {} err = False try: if module.params["state"] == "present": idrac.config_mgr._sysconfig.iDRAC.SysLog.SysLogEnable_SysLog = \ TypeHelper.convert_to_enum('Enabled', SysLogEnable_SysLogTypes) idrac.config_mgr._sysconfig.iDRAC.SysLog.Port_SysLog = \ module.params['syslog_port'] if module.params['syslog_servers']: servers = [ server for server in module.params['syslog_servers'] if server.strip() ] if servers: servers.extend(["", "", ""]) idrac.config_mgr._sysconfig.iDRAC.SysLog.Server1_SysLog = servers[ 0] idrac.config_mgr._sysconfig.iDRAC.SysLog.Server2_SysLog = servers[ 1] idrac.config_mgr._sysconfig.iDRAC.SysLog.Server3_SysLog = servers[ 2] else: idrac.config_mgr._sysconfig.iDRAC.SysLog.SysLogEnable_SysLog = \ TypeHelper.convert_to_enum('Disabled', SysLogEnable_SysLogTypes) msg['changed'] = idrac.config_mgr._sysconfig.is_changed() if module.check_mode: # since it is running in check mode, reject the changes idrac.config_mgr._sysconfig.reject() else: msg['msg'] = idrac.config_mgr.apply_changes() if "Status" in msg['msg'] and msg['msg']["Status"] != "Success": msg['failed'] = True msg['changed'] = False except Exception as e: err = True msg['msg'] = "Error: %s" % str(e) msg['failed'] = True return msg, err
def setup_idrac_webserver(idrac, module): """ Setup iDRAC Webserver services Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ msg = {} msg['changed'] = False msg['failed'] = False msg['msg'] = {} error = False try: tls_protocol = TypeHelper.convert_to_enum(module.params['tls_protocol'], TLSProtocol_WebServerTypes) ssl_bits = TypeHelper.convert_to_enum(module.params['ssl_bits'], SSLEncryptionBitLength_WebServerTypes) if module.params['state'] == 'present': idrac.config_mgr._sysconfig.iDRAC.WebServer.\ Enable_WebServer = Enable_WebServerTypes.Enabled idrac.config_mgr._sysconfig.iDRAC.WebServer.\ Timeout_WebServer = module.params['timeout'] idrac.config_mgr._sysconfig.iDRAC.WebServer.\ HttpPort_WebServer = module.params['http_port'] idrac.config_mgr._sysconfig.iDRAC.WebServer.\ HttpsPort_WebServer = module.params['https_port'] idrac.config_mgr._sysconfig.iDRAC.WebServer.\ TLSProtocol_WebServer = tls_protocol idrac.config_mgr._sysconfig.iDRAC.WebServer.\ SSLEncryptionBitLength_WebServer = ssl_bits else: idrac.config_mgr._sysconfig.iDRAC.WebServer.\ Enable_WebServer = Enable_WebServerTypes.Disabled msg['changed'] = idrac.config_mgr._sysconfig.is_changed() if module.check_mode: # Since it is running in check mode, reject the changes idrac.config_mgr._sysconfig.reject() else: msg['msg'] = idrac.config_mgr.apply_changes(reboot=False) if "Status" in msg['msg'] and msg['msg']['Status'] != "Success": msg['failed'] = True msg['changed'] = False except Exception as err: error = True msg['msg'] = "Error: %s" % str(err) msg['failed'] = True return msg, error
def setup_idrac_snmp(idrac, module): """ Setup iDRAC SNMP Configuration parameters Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ msg = {} msg['changed'] = False msg['failed'] = False msg['msg'] = {} err = False try: idrac.config_mgr.SNMPConfiguration.AgentEnable_SNMP = \ TypeHelper.convert_to_enum(module.params['snmp_enable'], AgentEnable_SNMPTypes) idrac.config_mgr.SNMPConfiguration.AgentCommunity_SNMP = \ module.params['snmp_community'].lower() idrac.config_mgr.SNMPConfiguration.AlertPort_SNMP = \ module.params['snmp_trap_port'] idrac.config_mgr.SNMPConfiguration.DiscoveryPort_SNMP = \ module.params['snmp_port'] idrac.config_mgr.SNMPConfiguration.SNMPProtocol_SNMP = \ TypeHelper.convert_to_enum(module.params['snmp_protocol'], SNMPProtocol_SNMPTypes) idrac.config_mgr.SNMPConfiguration.TrapFormat_SNMP = \ TypeHelper.convert_to_enum(module.params['snmp_trap_format'], TrapFormat_SNMPTypes) msg['changed'] = idrac.config_mgr._sysconfig.is_changed() if module.check_mode: # since it is running in check mode, reject the changes idrac.config_mgr._sysconfig.reject() else: msg['msg'] = idrac.config_mgr.apply_changes() if "Status" in msg['msg'] and msg['msg']['Status'] != "Success": msg['failed'] = True msg['changed'] = False except Exception as e: err = True msg['msg'] = "Error: %s" % str(e) msg['failed'] = True return msg, err
def _setup_ipv4(idrac, module): """ Setup IPv4 parameters Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ idrac.config_mgr._sysconfig.iDRAC.IPv4.Enable_IPv4 = \ TypeHelper.convert_to_enum(module.params['ipv4_enable'], Enable_IPv4Types) idrac.config_mgr._sysconfig.iDRAC.IPv4.DHCPEnable_IPv4 = \ TypeHelper.convert_to_enum(module.params['ipv4_dhcp_enable'], DHCPEnable_IPv4Types)
def setup_boot_settings(idrac, module): """ Configure Boot Order parameters on PowerEdge Servers Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ msg = {} msg['changed'] = False msg['failed'] = False msg['msg'] = {} error = False try: curr_boot_mode = idrac.config_mgr._sysconfig.BIOS.BootMode # Boot Mode - reboot imminent _setup_boot_mode(idrac, module) # Boot Seq retry if module.params['boot_seq_retry']: idrac.config_mgr._sysconfig.BIOS.BootSeqRetry = \ TypeHelper.convert_to_enum(module.params['boot_seq_retry'], BootSeqRetryTypes) # Setup HDD Sequence _setup_hdd_seq(idrac, module) # Setup BIOS Boot Settings if curr_boot_mode == BootModeTypes.Bios: _setup_bios_boot_settings(idrac, module) # Setup Uefi Boot Settings if curr_boot_mode == BootModeTypes.Uefi: _setup_uefi_boot_settings(idrac, module) # Setup iDRAC Boot configuration parameters _setup_idrac_boot_settings(idrac, module) msg['changed'] = idrac.config_mgr._sysconfig.is_changed() if module.check_mode: # since it is running in check mode, reject the changes idrac.config_mgr._sysconfig.reject() else: msg['msg'] = idrac.config_mgr.apply_changes() if "Status" in msg['msg'] and msg['msg']['Status'] != "Success": msg['failed'] = True msg['changed'] = False except Exception as err: error = True msg['msg'] = "Error: %s" % str(err) msg['exception'] = traceback.format_exc() msg['failed'] = True return msg, error
def _setup_ipv4_static(idrac, module): """ Setup IPv4 Static parameters Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ if module.params['ipv4_dhcp_enable'] == 'Disabled': if module.params['ipv4_static']: idrac.config_mgr._sysconfig.iDRAC.IPv4Static.Address_IPv4Static = \ module.params['ipv4_static'] if module.params['ipv4_static_gw']: idrac.config_mgr._sysconfig.iDRAC.IPv4Static.Gateway_IPv4Static = \ module.params['ipv4_static_gw'] if module.params['ipv4_static_mask']: idrac.config_mgr._sysconfig.iDRAC.IPv4Static.Netmask_IPv4Static = \ module.params['ipv4_static_mask'] idrac.config_mgr._sysconfig.iDRAC.IPv4Static.DNSFromDHCP_IPv4Static = \ TypeHelper.convert_to_enum(module.params['ipv4_dns_from_dhcp'], DNSFromDHCP_IPv4StaticTypes) if module.params['ipv4_dns_from_dhcp'] != 'Enabled': if module.params['ipv4_preferred_dns']: idrac.config_mgr._sysconfig.iDRAC.IPv4Static.DNS1_IPv4Static = \ module.params['ipv4_prefered_dns'] if module.params['ipv4_alternate_dns']: idrac.config_mgr._sysconfig.iDRAC.IPv4Static.DNS2_IPv4Static = \ module.params['ipv4_alternate_dns']
def _setup_idrac_boot_settings(idrac, module): # First boot device first_boot_device = module.params['first_boot_device'] if first_boot_device: idrac.config_mgr._sysconfig.iDRAC.ServerBoot.FirstBootDevice_ServerBoot = \ TypeHelper.convert_to_enum(first_boot_device, FirstBootDevice_ServerBootTypes) # Boot Once boot_once = TypeHelper.convert_to_enum(module.params['boot_once'], BootOnce_ServerBootTypes) if first_boot_device and first_boot_device in [ 'BIOS', 'F10', 'F11', 'UEFIDevicePath' ]: boot_once = TypeHelper.convert_to_enum('Enabled', BootOnce_ServerBootTypes) idrac.config_mgr._sysconfig.iDRAC.ServerBoot.BootOnce_ServerBoot = boot_once
def _setup_boot_mode(idrac, module): """ Setup boot mode - reboot is imminent if you change the boot mode Keyword arguments: idrac -- idrac, module module -- Ansible module """ if module.params['boot_mode']: idrac.config_mgr._sysconfig.BIOS.BootMode = TypeHelper.convert_to_enum( module.params['boot_mode'], BootModeTypes)
def export_server_config_profile(idrac, module): """ Export Server Configuration Profile to a network share Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ msg = {} msg['changed'] = False msg['failed'] = False err = False try: scp_file_name_format = "%ip_%Y%m%d_%H%M%S_" + \ module.params['scp_components'] + "_SCP.xml" myshare = FileOnShare(remote=module.params['share_name'], isFolder=True) myshare.addcreds( UserCredentials(module.params['share_user'], module.params['share_pwd'])) scp_file_name = myshare.new_file(scp_file_name_format) scp_components = TypeHelper.convert_to_enum( module.params['scp_components'], SCPTargetEnum) export_format = ExportFormatEnum.XML if module.params['export_format'] == 'JSON': export_format = ExportFormatEnum.JSON export_method = ExportMethodEnum.Default if module.params['export_method'] == 'Clone': export_method = ExportMethodEnum.Clone msg['msg'] = idrac.config_mgr.scp_export( scp_share_path=scp_file_name, components=scp_components, format_file=export_format, method=export_method, job_wait=module.params['job_wait']) if 'Status' in msg['msg'] and msg['msg']['Status'] != "Success": msg['failed'] = True except Exception as e: err = True msg['msg'] = "Error: %s" % str(e) msg['failed'] = True return msg, err
def _setup_nic_static(idrac, module): """ Setup iDRAC NIC Static attributes Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ idrac.config_mgr._sysconfig.iDRAC.NICStatic.DNSDomainFromDHCP_NICStatic = \ TypeHelper.convert_to_enum(module.params['dns_domain_from_dhcp'], DNSDomainFromDHCP_NICStaticTypes) if module.params['dns_domain_name']: idrac.config_mgr._sysconfig.iDRAC.NICStatic.DNSDomainName_NICStatic = \ module.params['dns_domain_name']
def setup_idrac_lc_attr(idrac, module): """ Setup iDRAC Lifecycle attributes Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ msg = {} msg['changed'] = False msg['failed'] = False msg['msg'] = {} err = False try: idrac.config_mgr._sysconfig.LifecycleController.LCAttributes.\ CollectSystemInventoryOnRestart_LCAttributes = \ TypeHelper.convert_to_enum(module.params['csior'], CollectSystemInventoryOnRestart_LCAttributesTypes) msg['changed'] = idrac.config_mgr._sysconfig.is_changed() if module.check_mode: # Since it is running in check mode, reject the changes idrac.config_mgr._sysconfig.reject() else: msg['msg'] = idrac.config_mgr.apply_changes( reboot=module.params['reboot']) if "Status" in msg['msg'] and msg['msg']['Status'] != "Success": msg['failed'] = True msg['changed'] = False except Exception as e: err = True msg['msg'] = "Error: %s" % str(e) msg['failed'] = True return msg, err
def _create_virtual_drive(idrac, module): """ Create a virtual drive Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ msg = {} span_length = module.params.get('span_length') span_depth = module.params.get('span_depth') pd_slots = module.params.get('pd_slots') raid_level = TypeHelper.convert_to_enum(module.params['raid_level'], RAIDTypesTypes) read_policy = TypeHelper.convert_to_enum(module.params['read_policy'], RAIDdefaultReadPolicyTypes) write_policy = TypeHelper.convert_to_enum(module.params['write_policy'], RAIDdefaultWritePolicyTypes) disk_policy = TypeHelper.convert_to_enum(module.params['disk_policy'], DiskCachePolicyTypes) # Physical Disk filter pd_filter = '((disk.parent.parent is Controller and disk.parent.parent.FQDD._value == "{0}")'.format( module.params['controller_fqdd']) pd_filter += ' or (disk.parent is Controller and disk.parent.FQDD._value == "{0}"))'.format( module.params['controller_fqdd']) pd_filter += ' and disk.MediaType == "{0}"'.format( module.params['media_type']) pd_filter += ' and disk.BusProtocol == "{0}"'.format( module.params['bus_protocol']) # Either one of Span Length and Physical Disks Slots must be defined if not (span_length or pd_slots): module.fail_json( msg="Either span_length or pd_slots must be defined for VD creation" ) elif pd_slots: slots = "" for i in pd_slots: slots += "\"" + str(i) + "\"," slots_list = "[" + slots[0:-1] + "]" pd_filter += " and disk.Slot._value in " + slots_list span_length = len(pd_slots) # check span_length if span_length < MIN_SPAN_LENGTH[TypeHelper.resolve(raid_level)]: module.fail_json(msg="Invalid span length for RAID Level: " + TypeHelper.resolve(raid_level)) # Span depth must be at least 1 which is used for RAID 0, 1, 5 and 6 span_depth = 1 if (span_depth < 1) else span_depth # Span depth must be at least 2 for RAID levels 10, 50 and 60 if raid_level in [ RAIDTypesTypes.RAID_10, RAIDTypesTypes.RAID_50, RAIDTypesTypes.RAID_60 ]: span_depth = 2 if (span_depth < 2) else span_depth msg = idrac.config_mgr.RaidHelper.new_virtual_disk( Name=module.params['vd_name'], Size=module.params['vd_size'], RAIDaction=RAIDactionTypes.Create, RAIDTypes=raid_level, RAIDdefaultReadPolicy=read_policy, RAIDdefaultWritePolicy=write_policy, DiskCachePolicy=disk_policy, SpanLength=span_length, SpanDepth=span_depth, StripeSize=module.params['stripe_size'], NumberDedicatedHotSpare=module.params['dedicated_hot_spare'], NumberGlobalHotSpare=module.params['global_hot_spare'], PhysicalDiskFilter=pd_filter) return msg
def __setattr__(self, name, value): # Do not allow access to internal variables if name in ['_orig_value', '_state']: raise AttributeError('Invalid attribute ' + name) # Freeze mode: No sets allowed if '_freeze' in self.__dict__ and self._freeze: raise ValueError('object in freeze mode') # allow updates to other fields except _value # should we allow updates to '_type', '_alias', '_fname'? if name not in ['_value']: self.__dict__[name] = value return # Create-only attribute : No updates allowed if not self._modifyAllowed and \ self._state in [TypeState.Committed, TypeState.Changing]: raise ValueError('updates not allowed to this object') # CompositeField : sets not allowed in composite fields if self._composite: raise AttributeError('composite objects cannot be modified') # value is None, object was committed; ==> no change if value is None and \ self._state in [TypeState.Committed, TypeState.Precommit, TypeState.Changing]: return # Validate value and convert it if needed valid = False msg = None if value is None or TypeHelper.belongs_to(self._type, value): valid = True elif type(self) == type(value): value = value._value valid = True elif isinstance(value, str): # expected value is int if self._type == int: value = int(value) valid = True # expected value is bool elif self._type == bool: value = bool(value) valid = True # expected value is enumeration elif TypeHelper.is_enum(self._type): newvalue = TypeHelper.convert_to_enum(value, self._type) if newvalue is not None: value = newvalue valid = True else: msg = str(value) + " is not " + str(self._type) else: msg = str(value) + " cannot be converted to " + str(self._type) else: msg = "No type conversion found for '" + str(value) + "'. "\ "Expected " + str(self._type.__name__) + ". Got " +\ type(value).__name__ if valid and not self.my_accept_value(value): msg = type(self).__name__ + " returned failure for " + str(value) valid = False # if invalid, raise ValueError exception if not valid: raise ValueError(msg) # same value - no change if name in self.__dict__ and self._value == value: return # List fields, simply append the new entry! if self._list and name in self.__dict__ and self.__dict__[name]: value = self.__dict__[name] + "," + value # modify the value self.__dict__[name] = value if self._state in [ TypeState.UnInitialized, TypeState.Precommit, TypeState.Initializing ]: self.__dict__['_state'] = TypeState.Initializing elif self._state in [TypeState.Committed, TypeState.Changing]: if self._orig_value == self._value: self.__dict__['_state'] = TypeState.Committed else: self.__dict__['_state'] = TypeState.Changing else: print("Should not come here") if self.is_changed() and self._parent: self._parent.child_state_changed(self, self._state)
def _setup_bios_attributes(idrac, module): bios_attributes = module.params.get('bios_attributes') if bios_attributes: # Uefi PxeDev1 Network Settings curr_pxe_dev = idrac.config_mgr._sysconfig.BIOS.PxeDev1EnDis pxe_dev = bios_attributes.get('PxeDev1EnDis') if pxe_dev: idrac.config_mgr._sysconfig.BIOS.PxeDev1EnDis = \ TypeHelper.convert_to_enum(pxe_dev, PxeDev1EnDisTypes) # only if PxeDev1EnDis is set to 'Enabled' else the atributes # will be read-only in the SCP if curr_pxe_dev == PxeDev1EnDisTypes.Enabled: pxe_dev_if = bios_attributes.get('PxeDev1Interface') if pxe_dev_if: if not isinstance(pxe_dev_if, string_types): module.fail_json( msg= "\'PxeDev1Interface\' must be of type String or Unicode: {0}" .format(str(pxe_dev_if))) idrac.config_mgr._sysconfig.BIOS.PxeDev1Interface = pxe_dev_if pxe_dev_protocol = bios_attributes.get('PxeDev1Protocol') if pxe_dev_protocol: idrac.config_mgr._sysconfig.BIOS.PxeDev1Protocol = \ TypeHelper.convert_to_enum(pxe_dev_protocol, PxeDev1ProtocolTypes) pxe_dev_vlan = bios_attributes.get('PxeDev1VlanEnDis') if pxe_dev_vlan: idrac.config_mgr._sysconfig.BIOS.PxeDev1VlanEnDis = \ TypeHelper.convert_to_enum(pxe_dev_vlan, PxeDev1VlanEnDisTypes) pxe_dev_vlan_id = bios_attributes.get('PxeDev1VlanId') if pxe_dev_vlan_id: idrac.config_mgr._sysconfig.BIOS.PxeDev1VlanId = pxe_dev_vlan_id pxe_dev_vlan_pri = bios_attributes.get('PxeDev1VlanPriority') if pxe_dev_vlan_pri: idrac.config_mgr._sysconfig.BIOS.PxeDev1VlanPriority = pxe_dev_vlan_pri # Uefi PxeDev2 Network Settings curr_pxe_dev = idrac.config_mgr._sysconfig.BIOS.PxeDev2EnDis pxe_dev = bios_attributes.get('PxeDev2EnDis') if pxe_dev: idrac.config_mgr._sysconfig.BIOS.PxeDev2EnDis = \ TypeHelper.convert_to_enum(pxe_dev, PxeDev2EnDisTypes) # only if PxeDev2EnDis is 'Enabled' else the attributes will be # read-only in SCP if curr_pxe_dev == PxeDev2EnDisTypes.Enabled: pxe_dev_if = bios_attributes.get('PxeDev2Interface') if pxe_dev_if: if not isinstance(pxe_dev_if, string_types): module.fail_json( msg= "\'PxeDev2Interface\' must be of type String or Unicode: {0}" .format(str(pxe_dev_if))) idrac.config_mgr._sysconfig.BIOS.PxeDev2Interface = pxe_dev_if pxe_dev_protocol = bios_attributes.get('PxeDev2Protocol') if pxe_dev_protocol: idrac.config_mgr._sysconfig.BIOS.PxeDev2Protocol = \ TypeHelper.convert_to_enum(pxe_dev_protocol, PxeDev2ProtocolTypes) pxe_dev_vlan = bios_attributes.get('PxeDev2VlanEnDis') if pxe_dev_vlan: idrac.config_mgr._sysconfig.BIOS.PxeDev2VlanEnDis = \ TypeHelper.convert_to_enum(pxe_dev_vlan, PxeDev2VlanEnDisTypes) pxe_dev_vlan_id = bios_attributes.get('PxeDev2VlanId') if pxe_dev_vlan_id: idrac.config_mgr._sysconfig.BIOS.PxeDev2VlanId = pxe_dev_vlan_id pxe_dev_vlan_pri = bios_attributes.get('PxeDev2VlanPriority') if pxe_dev_vlan_pri: idrac.config_mgr._sysconfig.BIOS.PxeDev2VlanPriority = pxe_dev_vlan_pri # Uefi PxeDev3 Network Settings curr_pxe_dev = idrac.config_mgr._sysconfig.BIOS.PxeDev3EnDis pxe_dev = bios_attributes.get('PxeDev3EnDis') if pxe_dev: idrac.config_mgr._sysconfig.BIOS.PxeDev3EnDis = \ TypeHelper.convert_to_enum(pxe_dev, PxeDev3EnDisTypes) # only if PxeDev3EnDis is 'Enabled' else the attributes will be # read-only in SCP if curr_pxe_dev == PxeDev3EnDisTypes.Enabled: pxe_dev_if = bios_attributes.get('PxeDev3Interface') if pxe_dev_if: if not isinstance(pxe_dev_if, string_types): module.fail_json( msg= "\'PxeDev3Interface\' must be of type String or Unicode: {0}" .format(str(pxe_dev_if))) idrac.config_mgr._sysconfig.BIOS.PxeDev3Interface = pxe_dev_if pxe_dev_protocol = bios_attributes.get('PxeDev3Protocol') if pxe_dev_protocol: idrac.config_mgr._sysconfig.BIOS.PxeDev3Protocol = \ TypeHelper.convert_to_enum(pxe_dev_protocol, PxeDev3ProtocolTypes) pxe_dev_vlan = bios_attributes.get('PxeDev3VlanEnDis') if pxe_dev_vlan: idrac.config_mgr._sysconfig.BIOS.PxeDev3VlanEnDis = \ TypeHelper.convert_to_enum(pxe_dev_vlan, PxeDev3VlanEnDisTypes) pxe_dev_vlan_id = bios_attributes.get('PxeDev3VlanId') if pxe_dev_vlan_id: idrac.config_mgr._sysconfig.BIOS.PxeDev3VlanId = pxe_dev_vlan_id pxe_dev_vlan_pri = bios_attributes.get('PxeDev3VlanPriority') if pxe_dev_vlan_pri: idrac.config_mgr._sysconfig.BIOS.PxeDev3VlanPriority = pxe_dev_vlan_pri # Uefi PxeDev4 Network Settings curr_pxe_dev = idrac.config_mgr._sysconfig.BIOS.PxeDev4EnDis pxe_dev = bios_attributes.get('PxeDev4EnDis') if pxe_dev: idrac.config_mgr._sysconfig.BIOS.PxeDev4EnDis = \ TypeHelper.convert_to_enum(pxe_dev, PxeDev4EnDisTypes) # only if PxeDev4EnDis is 'Enabled' else the attributes will be # read-only in SCP if curr_pxe_dev == PxeDev4EnDisTypes.Enabled: pxe_dev_if = bios_attributes.get('PxeDev4Interface') if pxe_dev_if: if not isinstance(pxe_dev_if, string_types): module.fail_json( msg= "\'PxeDev4Interface\' must be of type String or Unicode: {0}" .format(str(pxe_dev_if))) idrac.config_mgr._sysconfig.BIOS.PxeDev4Interface = pxe_dev_if pxe_dev_protocol = bios_attributes.get('PxeDev4Protocol') if pxe_dev_protocol: idrac.config_mgr._sysconfig.BIOS.PxeDev4Protocol = \ TypeHelper.convert_to_enum(pxe_dev_protocol, PxeDev4ProtocolTypes) pxe_dev_vlan = bios_attributes.get('PxeDev4VlanEnDis') if pxe_dev_vlan: idrac.config_mgr._sysconfig.BIOS.PxeDev4VlanEnDis = \ TypeHelper.convert_to_enum(pxe_dev_vlan, PxeDev4VlanEnDisTypes) pxe_dev_vlan_id = bios_attributes.get('PxeDev4VlanId') if pxe_dev_vlan_id: idrac.config_mgr._sysconfig.BIOS.PxeDev4VlanId = pxe_dev_vlan_id pxe_dev_vlan_pri = bios_attributes.get('PxeDev4VlanPriority') if pxe_dev_vlan_pri: idrac.config_mgr._sysconfig.BIOS.PxeDev4VlanPriority = pxe_dev_vlan_pri
def _setup_nic(idrac, module): """ Setup iDRAC NIC attributes Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ idrac.config_mgr._sysconfig.iDRAC.NIC.Enable_NIC = \ TypeHelper.convert_to_enum(module.params['nic_enable'], Enable_NICTypes) idrac.config_mgr._sysconfig.iDRAC.NIC.Selection_NIC = \ TypeHelper.convert_to_enum(module.params['nic_selection'], Selection_NICTypes) # NIC Selection mode and failover mode should not be same if module.params['nic_selection'] == module.params['nic_failover']: module.fail_json( msg="NIC Selection mode and Failover mode cannot be same") elif module.params['nic_selection'] != 'Dedicated': idrac.config_mgr._sysconfig.iDRAC.NIC.FailoverNIC = \ TypeHelper.convert_to_enum(module.params['nic_failover'], Failover_NICTypes) # if NIC Selection is not 'Dedicated', then Auto-Negotiation is always ON if module.params['nic_selection'] != 'Dedicated': idrac.config_mgr._sysconfig.IDRAC.NIC.Autoneg_NIC = Autoneg_NICTypes.Enabled else: idrac.config_mgr._sysconfig.iDRAC.NIC.Autoneg_NIC = \ TypeHelper.convert_to_enum(module.params['nic_autoneg'], Autoneg_NICTypes) # NIC Speed and Duplex mode can only be set when Auto-Negotiation is not ON if module.params['nic_autoneg'] != 'Enabled': if module.params['nic_selection'] != 'Dedicated': idrac.config_mgr._sysconfig.iDRAC.NIC.Speed_NIC = Speed_NICTypes.T_100 else: idrac.config_mgr._sysconfig.iDRAC.NIC.Speed_NIC = \ TypeHelper.convert_to_enum(module.params['nic_speed'], Speed_NICTypes) idrac.config_mgr._sysconfig.iDRAC.NIC.Duplex_NIC = \ TypeHelper.convert_to_enum(module.params['nic_duplex'], Duplex_NICTypes) idrac.config_mgr._sysconfig.iDRAC.NIC.MTU_NIC = module.params['nic_mtu'] # DNS Registration idrac.config_mgr._sysconfig.iDRAC.NIC.DNSRegister_NIC = \ TypeHelper.convert_to_enum(module.params['dns_register'], DNSRegister_NICTypes) if module.params['dns_idrac_name']: idrac.config_mgr._sysconfig.iDRAC.NIC.DNSRacName = module.params[ 'dns_idrac_name'] # Enable Auto-Config if module.params['nic_auto_config'] != 'Disabled': if module.params['ipv4_enable'] != 'Enabled' or \ module.params['ipv4_dhcp_enable'] != 'Enabled': module.fail_json( msg="IPv4 and DHCPv4 must be enabled for Auto-Config") idrac.config_mgr._sysconfig.iDRAC.NIC.AutoConfig_NIC = \ TypeHelper.convert_to_enum(module.params['nic_auto_config'], AutoConfig_NICTypes) # VLAN idrac.config_mgr._sysconfig.iDRAC.NIC.VLanEnable_NIC = \ TypeHelper.convert_to_enum(module.params['vlan_enable'], VLanEnable_NICTypes) idrac.config_mgr._sysconfig.iDRAC.NIC.VLanID_NIC = module.params['vlan_id'] idrac.config_mgr._sysconfig.iDRAC.NIC.VLanPriority_NIC = module.params[ 'vlan_priority']
def virtual_drive(idrac, module): """ Create or delete a virtual drive Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ msg = {} msg['changed'] = False msg['failed'] = False msg['msg'] = {} err = False try: raid_level = TypeHelper.convert_to_enum(module.params['raid_level'], RAIDTypesTypes) read_policy = TypeHelper.convert_to_enum(module.params['read_policy'], RAIDdefaultReadPolicyTypes) write_policy = TypeHelper.convert_to_enum( module.params['write_policy'], RAIDdefaultWritePolicyTypes) disk_policy = TypeHelper.convert_to_enum(module.params['disk_policy'], DiskCachePolicyTypes) pd_filter = "(disk.parent.parent is Controller and disk.parent.parent.FQDD._value == \"" + module.params['controller_fqdd'] + "\")" + \ " and disk.MediaType == \"" + module.params['media_type'] + "\"" + \ " and disk.BusProtocol == \"" + module.params['bus_protocol'] + "\"" if module.params['pd_slots']: pd_slots = "" for i in module.params['pd_slots']: pd_slots = "\"" + i + "\", " pd_slots_list = "[" + pd_slots[0:-1] + "]" pd_filter += " and disk.Slot in " + pd_slots_list # Check whether VD exists exists = _virtual_drive_exists(idrac, module) if module.params['state'] == 'present': if module.check_mode or exists: msg['changed'] = not exists else: msg['msg'] = idrac.config_mgr.RaidHelper.new_virtual_disk( Name=module.params['vd_name'], Size=module.params['vd_size'], RAIDTypes=raid_level, RAIDdefaultReadPolicy=read_policy, RAIDdefaultWritePolicy=write_policy, DiskCachePolicy=disk_policy, SpanLength=module.params['span_length'], SpanDepth=module.params['span_depth'], StripeSize=module.params['stripe_size'], NumberDedicatedHotSpare=module. params['dedicated_hot_spare'], NumberGlobalHotSpare=module.params['global_hot_spare'], PhysicalDiskFilter=pd_filter) else: if module.check_mode or not exists: msg['changed'] = exists else: msg['msg'] = idrac.config_mgr.RAIDHelper.delete_virtual_disk( Name=module.params['vd_name']) if "Status" in msg['msg']: if msg['msg']['Status'] == "Success": msg['changed'] = True else: msg['failed'] = True except Exception as e: err = True msg['msg'] = "Error: %s" % str(e) msg['exception'] = traceback.format_exc() msg['failed'] = True return msg, err
def RepoBuilder(arglist): parser = ArgumentParser(description='Local Repository Builder') parser.add_argument( '-C', '--catalog', action="store", dest="catalog", nargs='?', default='Catalog', type=str, help="Name of the Catalog file that contains the info about needed DUPs" ) parser.add_argument('-f', '--folder', action="store", dest="folder", type=str, help="folder from where repository is built") parser.add_argument('-c', '--components', action="store", dest="component", nargs='+', help="components for which the DUPs are requested.") parser.add_argument('-s', '--site', action="store", dest="site", type=str, nargs='?', default='downloads.dell.com', help="models for which the DUPs are requested.") parser.add_argument('-p', '--protocol', action="store", dest="protocol", nargs='?', default='HTTP', choices=['HTTP', 'FTP', 'NoOp', 'HashCheck'], help="models for which the DUPs are requested.") parser.add_argument('-v', '--verbose', action="store_true", help="verbose mode") parser.add_argument('-D', '--download-dups', action="store_true", dest="dld_dups", help="download DUPs") parser.add_argument('-l', '--download-catalog', action="store_true", dest="dld_catalog", help="download catalog") parser.add_argument('-b', '--build-catalog', action="store_true", dest="build_catalog", help="build catalog") parser.add_argument('-i', '--download-index', action="store_true", dest="dld_index", help="build index") options = parser.parse_args(arglist) if not options.component: options.component = [] if options.folder is None: print("Folder must be provided") return -1 if options.verbose is None: options.verbose = False if options.verbose: logging.basicConfig(level=logging.DEBUG) if not options.dld_dups and not options.build_catalog and \ not options.dld_catalog: options.dld_catalog = True options.build_catalog = True options.dld_dups = True options.protocol = TypeHelper.convert_to_enum(options.protocol, DownloadProtocolEnum) updshare = LocalFile(local=options.folder, isFolder=True) if not updshare.IsValid: print("Folder is not writable!") return -2 if options.protocol != DownloadProtocolEnum.HashCheck: print("Configuring Update Share...") UpdateManager.configure(updshare, site=options.site, protocol=options.protocol) if options.dld_catalog: if options.protocol != DownloadProtocolEnum.HashCheck: print("Updating Catalog from downloads.dell.com...") UpdateManager.update_catalog() if options.build_catalog: if options.protocol != DownloadProtocolEnum.HashCheck: print("Building Repository Catalog ....") UpdateHelper.build_repo(options.catalog, True, *options.component) if options.dld_index: if options.protocol != DownloadProtocolEnum.HashCheck: print("Updating index from downloads.dell.com...") UpdateManager.update_index() if options.dld_dups: if options.protocol != DownloadProtocolEnum.HashCheck: print("Downloading DUPs ...") UpdateManager.update_cache(options.catalog)
def setup_idrac_snmp_alert(idrac, module): """ Setup iDRAC SNMP Alert Destinations idrac -- iDRAC handle module -- Ansible module """ msg = {} msg['changed'] = False msg['failed'] = False msg['msg'] = {} error = False try: if not module.params['snmp_alert_dest']: module.fail_json(msg="At least one SNMP alert destination must be provided") for alert_dest in module.params['snmp_alert_dest']: if not isinstance(alert_dest, dict): # reject any changes that are already done idrac.config_mgr._sysconfig.reject() module.fail_json(msg="Invalid SNMP Alert, should be of type \ dict: " + str(alert_dest)) dest_address = alert_dest.get('dest_address') state = alert_dest.get('state') if state and state.lower() == 'enabled': state = TypeHelper.convert_to_enum('Enabled', State_SNMPAlertTypes) else: state = TypeHelper.convert_to_enum('Disabled', State_SNMPAlertTypes) snmpv3_user_name = alert_dest.get('snmpv3_user_name') if dest_address: # check if the destination already exists alert = idrac.config_mgr._sysconfig.iDRAC.SNMPAlert.find_first( Destination_SNMPAlert=dest_address) if module.params['state'] == 'present': if not alert: idrac.config_mgr._sysconfig.iDRAC.SNMPAlert.new( Destination_SNMPAlert=dest_address, State_SNMPAlert=state, SNMPv3Username_SNMPAlert=snmpv3_user_name) else: if state: alert.State_SNMPAlert = state if snmpv3_user_name: alert.SNMPv3Username_SNMPAlert = snmpv3_user_name else: if alert: idrac.config_mgr._sysconfig.iDRAC.SNMPAlert.remove( Destination_SNMPAlert=dest_address) else: # Reject all changes idrac.config_mgr._sysconfig.reject() module.fail_json(msg="Alert Dest: " + dest_address + " does not exist") else: # Reject all changes idrac.config_mgr._sysconfig.reject() module.fail_json(msg="No \"dest_address\" key found:" + str(alert_dest)) msg['changed'] = idrac.config_mgr._sysconfig.is_changed() if module.check_mode: # since it is running in check mode, reject all changes idrac.config_mgr._sysconfig.reject() else: msg['msg'] = idrac.config_mgr.apply_changes() if 'Status' in msg['msg']: if msg['msg']['Status'] == 'Success': msg['changed'] = True else: msg['failed'] = True msg['changed'] = False except Exception as err: error = True msg['msg'] = "Error: %s" % str(err) msg['exception'] = traceback.format_exc() msg['failed'] = True return msg, error