Skip to content

Commit 30be265

Browse files
authored
Merge pull request #78 from danitso/fix/watchdog-deserialization-issue
fix: watchdog deserialization issue
2 parents d4f59f1 + 8d711a7 commit 30be265

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## v0.4.4
22

3+
BUG FIXES:
34

5+
* resource/virtual_environment_vm: Fix watchdog deserialization issue
46

57
## v0.4.3
68

proxmox/virtual_environment_vm_types.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ type CustomVirtualIODevices []CustomVirtualIODevice
201201
// CustomWatchdogDevice handles QEMU watchdog device parameters.
202202
type CustomWatchdogDevice struct {
203203
Action *string `json:"action,omitempty" url:"action,omitempty"`
204-
Model string `json:"model" url:"model"`
204+
Model *string `json:"model" url:"model"`
205205
}
206206

207207
// VirtualEnvironmentVMCloneRequestBody contains the data for an virtual machine clone request.
@@ -1615,3 +1615,37 @@ func (r *CustomVGADevice) UnmarshalJSON(b []byte) error {
16151615

16161616
return nil
16171617
}
1618+
1619+
// UnmarshalJSON converts a CustomWatchdogDevice string to an object.
1620+
func (r *CustomWatchdogDevice) UnmarshalJSON(b []byte) error {
1621+
var s string
1622+
1623+
err := json.Unmarshal(b, &s)
1624+
1625+
if err != nil {
1626+
return err
1627+
}
1628+
1629+
if s == "" {
1630+
return nil
1631+
}
1632+
1633+
pairs := strings.Split(s, ",")
1634+
1635+
for _, p := range pairs {
1636+
v := strings.Split(strings.TrimSpace(p), "=")
1637+
1638+
if len(v) == 1 {
1639+
r.Model = &v[0]
1640+
} else if len(v) == 2 {
1641+
switch v[0] {
1642+
case "action":
1643+
r.Action = &v[1]
1644+
case "model":
1645+
r.Model = &v[1]
1646+
}
1647+
}
1648+
}
1649+
1650+
return nil
1651+
}

0 commit comments

Comments
 (0)