Skip to content

Commit 62a7ff0

Browse files
committed
Add config_drive to server struct
Adds config_drive to the regular server struct used for responses. (currently only part of createOpts) which leads to situation that one can create a server with a config_drive. But one can not verify / see that information in any kind of response. This fixes #3534.
1 parent 709c322 commit 62a7ff0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

openstack/compute/v2/servers/results.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net/url"
99
"path"
10+
"strconv"
1011
"time"
1112

1213
"github.com/gophercloud/gophercloud/v2"
@@ -283,6 +284,9 @@ type Server struct {
283284
// Locked indicates the lock status of the server
284285
// This requires microversion 2.9 or later
285286
Locked *bool `json:"locked"`
287+
288+
// ConfigDrive enables metadata injection through a configuration drive.
289+
ConfigDrive bool `json:"-"`
286290
}
287291

288292
type AttachedVolume struct {
@@ -343,6 +347,7 @@ func (r *Server) UnmarshalJSON(b []byte) error {
343347
Image any `json:"image"`
344348
LaunchedAt gophercloud.JSONRFC3339MilliNoZ `json:"OS-SRV-USG:launched_at"`
345349
TerminatedAt gophercloud.JSONRFC3339MilliNoZ `json:"OS-SRV-USG:terminated_at"`
350+
ConfigDrive any `json:"config_drive"`
346351
}
347352
err := json.Unmarshal(b, &s)
348353
if err != nil {
@@ -364,6 +369,24 @@ func (r *Server) UnmarshalJSON(b []byte) error {
364369
r.LaunchedAt = time.Time(s.LaunchedAt)
365370
r.TerminatedAt = time.Time(s.TerminatedAt)
366371

372+
switch t := s.ConfigDrive.(type) {
373+
case nil:
374+
r.ConfigDrive = false
375+
case bool:
376+
r.ConfigDrive = t
377+
case string:
378+
if t == "" {
379+
r.ConfigDrive = false
380+
} else {
381+
r.ConfigDrive, err = strconv.ParseBool(t)
382+
if err != nil {
383+
return fmt.Errorf("failed to parse ConfigDrive %q: %v", t, err)
384+
}
385+
}
386+
default:
387+
return fmt.Errorf("unknown type for ConfigDrive: %T (value: %v)", t, t)
388+
}
389+
367390
return err
368391
}
369392

0 commit comments

Comments
 (0)