github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/compute/v2/availabilityzones/results.go (about)

     1  package availabilityzones
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2"
     8  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
     9  )
    10  
    11  // ServiceState represents the state of a service in an AvailabilityZone.
    12  type ServiceState struct {
    13  	Active    bool      `json:"active"`
    14  	Available bool      `json:"available"`
    15  	UpdatedAt time.Time `json:"-"`
    16  }
    17  
    18  // UnmarshalJSON to override default
    19  func (r *ServiceState) UnmarshalJSON(b []byte) error {
    20  	type tmp ServiceState
    21  	var s struct {
    22  		tmp
    23  		UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
    24  	}
    25  	err := json.Unmarshal(b, &s)
    26  	if err != nil {
    27  		return err
    28  	}
    29  	*r = ServiceState(s.tmp)
    30  
    31  	r.UpdatedAt = time.Time(s.UpdatedAt)
    32  
    33  	return nil
    34  }
    35  
    36  // Services is a map of services contained in an AvailabilityZone.
    37  type Services map[string]ServiceState
    38  
    39  // Hosts is map of hosts/nodes contained in an AvailabilityZone.
    40  // Each host can have multiple services.
    41  type Hosts map[string]Services
    42  
    43  // ZoneState represents the current state of the availability zone.
    44  type ZoneState struct {
    45  	// Returns true if the availability zone is available
    46  	Available bool `json:"available"`
    47  }
    48  
    49  // AvailabilityZone contains all the information associated with an OpenStack
    50  // AvailabilityZone.
    51  type AvailabilityZone struct {
    52  	Hosts Hosts `json:"hosts"`
    53  	// The availability zone name
    54  	ZoneName  string    `json:"zoneName"`
    55  	ZoneState ZoneState `json:"zoneState"`
    56  }
    57  
    58  type AvailabilityZonePage struct {
    59  	pagination.SinglePageBase
    60  }
    61  
    62  // ExtractAvailabilityZones returns a slice of AvailabilityZones contained in a
    63  // single page of results.
    64  func ExtractAvailabilityZones(r pagination.Page) ([]AvailabilityZone, error) {
    65  	var s struct {
    66  		AvailabilityZoneInfo []AvailabilityZone `json:"availabilityZoneInfo"`
    67  	}
    68  	err := (r.(AvailabilityZonePage)).ExtractInto(&s)
    69  	return s.AvailabilityZoneInfo, err
    70  }