dell / iDRAC-Redfish-Scripting

Python and PowerShell scripting for Dell EMC PowerEdge iDRAC REST API with DMTF Redfish
GNU General Public License v2.0
598 stars 276 forks source link

Setting Timezone via Powershell not working #248

Closed oliverwolfat closed 1 year ago

oliverwolfat commented 1 year ago

Module: Set-IdracLcSystemAttributesREDFISH Property: Time.1.Timezone

Used Variables $general_settings is loaded from a JSON file, the mentioned Values should represent what would be the value. $general_settings.iDRAC_Timezone="Europe/Vienna" $general_settings.iDRAC_NTP=[10.28.20.254] $server.iDRAC_DefaultPW=calvin $server.iDRAC_DhcpIP="10.28.20.10"

Code Example

  # Set NTP Settings
   $iDRAC_settings_Names="Time.1.Timezone"
   $iDRAC_settings_Values="$($general_settings.iDRAC_Timezone)"
   # Only add NTP Servers if configured
   if($general_settings.iDRAC_NTP.Length -gt 0){
      $iDRAC_settings_Names=$iDRAC_settings_Names + ",NTPConfigGroup.1.NTPEnable"
      $iDRAC_settings_Values=$iDRAC_settings_Values + ",Enabled"
      for($i=0;$i -lt $general_settings.iDRAC_NTP.Length;$i++){
         # Only 3 NTP servers possible in iDRAC9
         if($i -lt 3) {
            $iDRAC_settings_Names=$iDRAC_settings_Names + ",NTPConfigGroup.1.NTP$($i+1)"
            $iDRAC_settings_Values=$iDRAC_settings_Values + ",$($general_settings.iDRAC_NTP[$i])"
         }
      }
   } Else {
      # Otherwise use at.pool.ntp.org
      $iDRAC_settings_Names=$iDRAC_settings_Names + ",NTPConfigGroup.1.NTPEnable"
      $iDRAC_settings_Values=$iDRAC_settings_Values + ",Enabled"
      for($i=0;$i -lt 3;$i++){
         $iDRAC_settings_Names=$iDRAC_settings_Names + ",NTPConfigGroup.1.NTP$($i+1)"
         $iDRAC_settings_Values=$iDRAC_settings_Values + ",$($i).at.pool.ntp.org"
      }
   }

   Set-IdracLcSystemAttributesREDFISH -idrac_ip $server.iDRAC_DhcpIP -idrac_username root -idrac_password $server.iDRAC_DefaultPW -attribute_group idrac -attribute_names $iDRAC_settings_Names -attribute_values $iDRAC_settings_Values

Expected Behavior Time.1.Timezone set to Europe/Vienna

Resulting Behavior Time.1.Timezone set to CST6CDT

texroemer commented 1 year ago

Hi @oliverwolfat

I ran the cmdlet to set TimeZone to Europe/Vienna, no issues. I also took your code (didn't have JSON file so i set the variables in script) and created a ps script, also no issues with setting TimeZone to Europe/Vienna.

Did you run the cmdlet outside of your code to confirm it works or does it also fail? If also fails can you let me know which iDRAC version you're using (i tested with 6.10.00).

Running the cmdlet and ps script;

PS C:\> Set-IdracLcSystemAttributesREDFISH -idrac_ip 192.168.0.120 -idrac_username root -idrac_password calvin -attribute_group idrac -attribute_names "Time.1.Timezone,NTPConfigGroup.1.NTPEnable" -attribute_values "Europe/Vienna,Enabled"

- INFO, cmdlet will set idrac attribute(s):

Name                           Value
----                           -----
NTPConfigGroup.1.NTPEnable     Enabled
Time.1.Timezone                Europe/Vienna

- PASS, statuscode 200 returned to successfully set "IDRAC" attribute(s)

- INFO, getting current idrac attribute value(s) that were just changed

- Attribute Name: Time.1.Timezone, Current Value: Europe/Vienna
- Attribute Name: NTPConfigGroup.1.NTPEnable, Current Value: Enabled

PS C:\> .\a.ps1

- INFO, cmdlet will set idrac attribute(s):

Name                           Value                                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                                             
NTPConfigGroup.1.NTPEnable     Enabled                                                                                                                                                                                                                           
NTPConfigGroup.1.NTP3          2.at.pool.ntp.org                                                                                                                                                                                                                 
NTPConfigGroup.1.NTP2          1.at.pool.ntp.org                                                                                                                                                                                                                 
NTPConfigGroup.1.NTP1          0.at.pool.ntp.org                                                                                                                                                                                                                 
Time.1.Timezone                Europe/Vienna                                                                                                                                                                                                                     

- PASS, statuscode 200 returned to successfully set "IDRAC" attribute(s)

- INFO, getting current idrac attribute value(s) that were just changed

- Attribute Name: Time.1.Timezone, Current Value: Europe/Vienna
- Attribute Name: NTPConfigGroup.1.NTPEnable, Current Value: Enabled
- Attribute Name: NTPConfigGroup.1.NTP1, Current Value: 0.at.pool.ntp.org
- Attribute Name: NTPConfigGroup.1.NTP2, Current Value: 1.at.pool.ntp.org
- Attribute Name: NTPConfigGroup.1.NTP3, Current Value: 2.at.pool.ntp.org

PS C:\> cat .\a.ps1
#$general_settings is loaded from a JSON file, the mentioned Values should represent what would be the value.
$iDRAC_Timezone="Europe/Vienna"
$iDRAC_NTP="10.28.20.254"
$iDRAC_DefaultPW="calvin"
$iDRAC_DhcpIP="192.168.0.120"

# Set NTP Settings
   $iDRAC_settings_Names="Time.1.Timezone"
   $iDRAC_settings_Values="$($iDRAC_Timezone)"
   # Only add NTP Servers if configured
   if($general_settings.iDRAC_NTP.Length -gt 0){
      $iDRAC_settings_Names=$iDRAC_settings_Names + ",NTPConfigGroup.1.NTPEnable"
      $iDRAC_settings_Values=$iDRAC_settings_Values + ",Enabled"
      for($i=0;$i -lt $iDRAC_NTP.Length;$i++){
         # Only 3 NTP servers possible in iDRAC9
         if($i -lt 3) {
            $iDRAC_settings_Names=$iDRAC_settings_Names + ",NTPConfigGroup.1.NTP$($i+1)"
            $iDRAC_settings_Values=$iDRAC_settings_Values + ",$($iDRAC_NTP[$i])"
         }
      }
   } Else {
      # Otherwise use at.pool.ntp.org
      $iDRAC_settings_Names=$iDRAC_settings_Names + ",NTPConfigGroup.1.NTPEnable"
      $iDRAC_settings_Values=$iDRAC_settings_Values + ",Enabled"
      for($i=0;$i -lt 3;$i++){
         $iDRAC_settings_Names=$iDRAC_settings_Names + ",NTPConfigGroup.1.NTP$($i+1)"
         $iDRAC_settings_Values=$iDRAC_settings_Values + ",$($i).at.pool.ntp.org"
      }
   }

   Set-IdracLcSystemAttributesREDFISH -idrac_ip $iDRAC_DhcpIP -idrac_username root -idrac_password $iDRAC_DefaultPW -attribute_group idrac -attribute_names $iDRAC_settings_Names -attribute_values $iDRAC_settings_Values

Thanks Tex

oliverwolfat commented 1 year ago

Hi @texroemer

Did you run the cmdlet outside of your code to confirm it works or does it also fail? If also fails can you let me know which iDRAC version you're using (i tested with 6.10.00). I tested it also outside the script and it failed as well. Regarding the iDRAC-Version, i have this issue since 5.00.20.00

I have another server to prepare on Thursday 9th of March, i will report back with my findings regarding iDRAC Version and behavior.

Thanks for the fast response. Oliver

texroemer commented 1 year ago

Thanks for the iDRAC version, i just rollback my server to iDRAC 5.00.20 from 6.10.00, still no issues with setting time zone.

Please let me know if you're still facing issues when setting up the other server.

Thanks Tex

oliverwolfat commented 1 year ago

Hi @texroemer

I finally figured out the Problem. There was some legacy code hidden in the initialization for my script.

In this legacy code i created empty files multiple_idrac_lc_system_attributes, and multiple_bios_attributes This broke everything in my code afterwards, totally my fault. Additionally it seems that the last module update on the dev machine hasn't been done properly. I reinstalled the modules using the script provided for PowerShell.

Tested with iDRAC Firmware 6.10.30.00

I did however found another issue which i will report seperatley.

KR Oliver