Skip to content

Commit

Permalink
add compatibility to still support ygg_ip for old workloads (#2193)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhamadazmy authored Feb 1, 2024
1 parent dd28b90 commit 52a4a6c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
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)
}

0 comments on commit 52a4a6c

Please sign in to comment.