Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add compatibility to still support ygg_ip for old workloads #2193

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/gridtypes/zos/zmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,27 @@ type ZMachineResult struct {
PlanetaryIP string `json:"planetary_ip"`
ConsoleURL string `json:"console_url"`
}

func (r *ZMachineResult) UnmarshalJSON(data []byte) error {
var deprecated struct {
ID string `json:"id"`
IP string `json:"ip"`
YggIP string `json:"ygg_ip"`
PlanetaryIP string `json:"planetary_ip"`
ConsoleURL string `json:"console_url"`
}

if err := json.Unmarshal(data, &deprecated); err != nil {
return err
}

r.ID = deprecated.ID
r.IP = deprecated.IP
r.PlanetaryIP = deprecated.PlanetaryIP
if deprecated.YggIP != "" {
r.PlanetaryIP = deprecated.YggIP
}
r.ConsoleURL = deprecated.ConsoleURL

return nil
}
22 changes: 22 additions & 0 deletions pkg/gridtypes/zos/zmachine_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zos

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -94,3 +95,24 @@ func TestZMachineSRU(t *testing.T) {
})
}
}

func TestResultDeprecated(t *testing.T) {
raw := ` {
"id": "192-74881-testing2",
"ip": "10.20.2.2",
"ygg_ip": "32b:8310:9b03:5529:ff0f:37cd:de80:b322",
"console_url": "10.20.2.0:20002"
}`

var result ZMachineResult

err := json.Unmarshal([]byte(raw), &result)
require.NoError(t, err)

require.EqualValues(t, ZMachineResult{
ID: "192-74881-testing2",
IP: "10.20.2.2",
PlanetaryIP: "32b:8310:9b03:5529:ff0f:37cd:de80:b322",
ConsoleURL: "10.20.2.0:20002",
}, result)
}
Loading