update credentials section in ilo files. Add sync_data script .
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -28,8 +28,8 @@ if not os.path.exists(cred_path):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(cred_path)
|
||||
try:
|
||||
LOGIN_ACCOUNT = config.get("ilo", "username", fallback="root")
|
||||
LOGIN_PASSWORD = config.get("ilo", "password")
|
||||
LOGIN_ACCOUNT = config.get("ilo_credentials", "username", fallback="root")
|
||||
LOGIN_PASSWORD = config.get("ilo_credentials", "password")
|
||||
except (configparser.NoSectionError, configparser.NoOptionError) as e:
|
||||
print(f"Error reading credentials file: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python3
|
||||
import argparse
|
||||
import configparser
|
||||
import os
|
||||
import sys
|
||||
import urllib3
|
||||
import redfish
|
||||
|
||||
# Suppress SSL warnings for self-signed iLO certificates
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
parser = argparse.ArgumentParser(description="Get the power status of an HPE server via iLO Redfish")
|
||||
parser.add_argument("hostname", help="iLO hostname or IP address")
|
||||
parser.add_argument("-c", "--credentials", default="/etc/ilo_credentials",
|
||||
help="Path to credentials file (default: /etc/ilo_credentials)")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Read credentials from file (chmod 600 recommended: sudo chmod 600 /etc/ilo_credentials)
|
||||
# File format:
|
||||
# [ilo]
|
||||
# username = root
|
||||
# password = yourpassword
|
||||
cred_path = args.credentials
|
||||
if not os.path.exists(cred_path):
|
||||
print(f"Error: credentials file not found: {cred_path}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(cred_path)
|
||||
try:
|
||||
LOGIN_ACCOUNT = config.get("ilo_credentials", "username", fallback="root")
|
||||
LOGIN_PASSWORD = config.get("ilo_credentials", "password")
|
||||
except (configparser.NoSectionError, configparser.NoOptionError) as e:
|
||||
print(f"Error reading credentials file: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
BASE_URL = f"https://{args.hostname}"
|
||||
|
||||
REDFISHOBJ = redfish.RedfishClient(
|
||||
base_url=BASE_URL,
|
||||
username=LOGIN_ACCOUNT,
|
||||
password=LOGIN_PASSWORD,
|
||||
)
|
||||
REDFISHOBJ.login(auth="session")
|
||||
|
||||
sys_response = REDFISHOBJ.get("/redfish/v1/Systems/1/")
|
||||
power_state = sys_response.dict.get("PowerState", "Unknown")
|
||||
|
||||
print(f"Power State: {power_state}")
|
||||
|
||||
REDFISHOBJ.logout()
|
||||
@@ -0,0 +1,81 @@
|
||||
#Requires -Version 5.1
|
||||
|
||||
$FfsExe = 'C:\Program Files\FreeFileSync\FreeFileSync.exe'
|
||||
$ScriptDir = $PSScriptRoot
|
||||
$LogDir = Join-Path $ScriptDir 'logs'
|
||||
$ReportDir = Join-Path $ScriptDir 'reports'
|
||||
|
||||
$SyncJobs = @(
|
||||
'D:\jobs\shuttlebay_SyncSettings.ffs_batch'
|
||||
'D:\jobs\main_bridge_SyncSettings.ffs_batch'
|
||||
'D:\jobs\engineering_SyncSettings.ffs_batch'
|
||||
)
|
||||
|
||||
# ── Setup ──────────────────────────────────────────────────────────────────────
|
||||
foreach ($dir in $LogDir, $ReportDir) {
|
||||
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir | Out-Null }
|
||||
}
|
||||
|
||||
$RunTs = Get-Date -Format 'yyyyMMdd_HHmmss'
|
||||
$LogFile = Join-Path $LogDir "sync_history_$RunTs.log"
|
||||
|
||||
function Write-Log {
|
||||
param([string]$Message)
|
||||
$line = "[$(Get-Date -Format 'ddd MM/dd/yyyy HH:mm:ss.ff')] $Message"
|
||||
Write-Host $line
|
||||
Add-Content -Path $LogFile -Value $line
|
||||
}
|
||||
|
||||
Write-Log 'Sync run started'
|
||||
Write-Host "Log file: $LogFile"
|
||||
|
||||
# ── Run sync jobs ──────────────────────────────────────────────────────────────
|
||||
foreach ($job in $SyncJobs) {
|
||||
$jobName = Split-Path $job -Leaf
|
||||
Write-Host ''
|
||||
Write-Log "Running synchronization: $jobName"
|
||||
|
||||
$tmpOut = [IO.Path]::GetTempFileName()
|
||||
$proc = Start-Process -FilePath $FfsExe -ArgumentList $job `
|
||||
-RedirectStandardOutput $tmpOut -NoNewWindow -PassThru -Wait
|
||||
$rc = $proc.ExitCode
|
||||
$output = Get-Content -Path $tmpOut -Raw
|
||||
Remove-Item $tmpOut -Force
|
||||
if ($output) { Add-Content -Path $LogFile -Value $output }
|
||||
|
||||
switch ($rc) {
|
||||
0 { Write-Log 'Synchronization completed successfully.' }
|
||||
1 { Write-Log 'Synchronization completed with warnings.' }
|
||||
default {
|
||||
Write-Log "Synchronization failed or was aborted. Exit code: $rc"
|
||||
exit $rc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ''
|
||||
Write-Log 'All synchronization jobs completed.'
|
||||
|
||||
# ── Copy HTML reports ──────────────────────────────────────────────────────────
|
||||
$logPaths = Select-String -Path $LogFile -Pattern '"logFile"\s*:\s*"([^"]+)"' |
|
||||
ForEach-Object { $_.Matches[0].Groups[1].Value -replace '\\\\', '\' } |
|
||||
Sort-Object -Unique
|
||||
|
||||
$copied = 0
|
||||
foreach ($path in $logPaths) {
|
||||
if ([IO.Path]::GetExtension($path) -ieq '.html') {
|
||||
if (Test-Path $path) {
|
||||
Copy-Item -Path $path -Destination $ReportDir -Force
|
||||
Write-Log "Copied report: $(Split-Path $path -Leaf)"
|
||||
$copied++
|
||||
} else {
|
||||
Write-Log "Report not found: $path"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Log "Total reports copied: $copied"
|
||||
|
||||
# ── Shutdown ───────────────────────────────────────────────────────────────────
|
||||
Write-Log 'Shutting down server now.'
|
||||
Stop-Computer -Force
|
||||
Reference in New Issue
Block a user