From 5d2568ed4eeab2eb4087c52b122743b830bed921 Mon Sep 17 00:00:00 2001 From: zaidusmani26 Date: Mon, 25 Sep 2023 14:17:14 -0700 Subject: [PATCH] feat(amt): adds execute support for general settings Co-authored-by: Mike --- pkg/amt/alarmclock/service.go | 6 +- pkg/amt/general/settings.go | 133 +++++++++++++++++++++++----------- 2 files changed, 93 insertions(+), 46 deletions(-) diff --git a/pkg/amt/alarmclock/service.go b/pkg/amt/alarmclock/service.go index e45d3d81..fb28e616 100644 --- a/pkg/amt/alarmclock/service.go +++ b/pkg/amt/alarmclock/service.go @@ -20,6 +20,8 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) +const AMT_AlarmClockService = "AMT_AlarmClockService" + // INPUTS // AlarmClockOccurrence represents a single alarm clock setting @@ -75,7 +77,7 @@ type ( } AddAlarmOutput struct { // A reference to the created instance of IPS_AlarmClockOccurrence. - AlarmClock AlarmClock + AlarmClock AlarmClock // Return code. 0 indicates success ReturnValue int } @@ -94,8 +96,6 @@ func (w *Response) JSON() string { return string(jsonOutput) } -const AMT_AlarmClockService = "AMT_AlarmClockService" - type Service struct { base message.Base client wsman.WSManClient diff --git a/pkg/amt/general/settings.go b/pkg/amt/general/settings.go index 7dc83db3..25b03abf 100644 --- a/pkg/amt/general/settings.go +++ b/pkg/amt/general/settings.go @@ -6,54 +6,59 @@ package general import ( + "encoding/json" "encoding/xml" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) -type Response struct { - XMLName xml.Name `xml:"Envelope"` - Header message.Header `xml:"Header"` - Body Body `xml:"Body"` -} - -type Body struct { - XMLName xml.Name `xml:"Body"` - AMTGeneralSettings GeneralSettings `xml:"AMT_GeneralSettings"` -} - -type GeneralSettings struct { - models.SettingData - XMLName xml.Name `xml:"AMT_GeneralSettings"` - NetworkInterfaceEnabled bool - DigestRealm string - IdleWakeTimeout int - HostName string - DomainName string - PingResponseEnabled bool - WsmanOnlyMode bool - PreferredAddressFamily PreferredAddressFamily - DHCPv6ConfigurationTimeout int - DDNSUpdateEnabled bool - DDNSUpdateByDHCPServerEnabled bool - SharedFQDN bool - HostOSFQDN string - DDNSTTL int - AMTNetworkEnabled AMTNetworkEnabled - RmcpPingResponseEnabled bool - DDNSPeriodicUpdateInterval int - PresenceNotificationInterval int - PrivacyLevel PrivacyLevel - PowerSource PowerSource - ThunderboltDockEnabled ThunderboltDockEnabled - OemID int -} +const AMT_GeneralSettings = "AMT_GeneralSettings" +// OUTPUTS +type ( + Response struct { + *wsman.Message + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + Body Body `xml:"Body"` + } + Body struct { + XMLName xml.Name `xml:"Body"` + AMTGeneralSettings GeneralSettings `xml:"AMT_GeneralSettings"` + EnumerateResponse common.EnumerateResponse + } + GeneralSettings struct { + models.SettingData + XMLName xml.Name `xml:"AMT_GeneralSettings"` + NetworkInterfaceEnabled bool + DigestRealm string + IdleWakeTimeout int + HostName string + DomainName string + PingResponseEnabled bool + WsmanOnlyMode bool + PreferredAddressFamily PreferredAddressFamily + DHCPv6ConfigurationTimeout int + DDNSUpdateEnabled bool + DDNSUpdateByDHCPServerEnabled bool + SharedFQDN bool + HostOSFQDN string + DDNSTTL int + AMTNetworkEnabled AMTNetworkEnabled + RmcpPingResponseEnabled bool + DDNSPeriodicUpdateInterval int + PresenceNotificationInterval int + PrivacyLevel PrivacyLevel + PowerSource PowerSource + ThunderboltDockEnabled ThunderboltDockEnabled + OemID int + } +) type PreferredAddressFamily int -const AMT_GeneralSettings = "AMT_GeneralSettings" - const ( IPv4 PreferredAddressFamily = iota IPv6 @@ -67,6 +72,14 @@ const ( PrivacyLevelExtreme ) +func (w *Response) JSON() string { + jsonOutput, err := json.Marshal(w.Body) + if err != nil { + return "" + } + return string(jsonOutput) +} + type PowerSource int const ( @@ -99,13 +112,47 @@ func (GeneralSettings Settings) Get() string { } // Enumerates the instances of this class -func (GeneralSettings Settings) Enumerate() string { - return GeneralSettings.base.Enumerate() +func (GeneralSettings Settings) Enumerate() (response Response, err error) { + response = Response{ + Message: &wsman.Message{ + XMLInput: GeneralSettings.base.Enumerate(), + }, + } + // send the message to AMT + err = GeneralSettings.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return } // Pulls instances of this class, following an Enumerate operation -func (GeneralSettings Settings) Pull(enumerationContext string) string { - return GeneralSettings.base.Pull(enumerationContext) +func (GeneralSettings Settings) Pull(enumerationContext string) (response Response, err error) { + response = Response{ + Message: &wsman.Message{ + XMLInput: GeneralSettings.base.Pull(enumerationContext), + }, + } + // send the message to AMT + err = GeneralSettings.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return } // Put will change properties of the selected instance