File tree Expand file tree Collapse file tree
openstack/compute/v2/servers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
288292type 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
You can’t perform that action at this time.
0 commit comments