github.com/gophercloud/gophercloud@v1.11.0/openstack/container/v1/capsules/microversions.go (about)

     1  package capsules
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/gophercloud/gophercloud"
     8  	"github.com/gophercloud/gophercloud/pagination"
     9  )
    10  
    11  // ExtractV132 is a function that accepts a result and extracts a capsule resource.
    12  func (r commonResult) ExtractV132() (*CapsuleV132, error) {
    13  	var s *CapsuleV132
    14  	err := r.ExtractInto(&s)
    15  	return s, err
    16  }
    17  
    18  // Represents a Capsule at microversion v1.32 or greater.
    19  type CapsuleV132 struct {
    20  	// UUID for the capsule
    21  	UUID string `json:"uuid"`
    22  
    23  	// User ID for the capsule
    24  	UserID string `json:"user_id"`
    25  
    26  	// Project ID for the capsule
    27  	ProjectID string `json:"project_id"`
    28  
    29  	// cpu for the capsule
    30  	CPU float64 `json:"cpu"`
    31  
    32  	// Memory for the capsule
    33  	Memory string `json:"memory"`
    34  
    35  	// The name of the capsule
    36  	MetaName string `json:"name"`
    37  
    38  	// Indicates whether capsule is currently operational.
    39  	Status string `json:"status"`
    40  
    41  	// Indicates whether capsule is currently operational.
    42  	StatusReason string `json:"status_reason"`
    43  
    44  	// The created time of the capsule.
    45  	CreatedAt time.Time `json:"-"`
    46  
    47  	// The updated time of the capsule.
    48  	UpdatedAt time.Time `json:"-"`
    49  
    50  	// Links includes HTTP references to the itself, useful for passing along to
    51  	// other APIs that might want a capsule reference.
    52  	Links []interface{} `json:"links"`
    53  
    54  	// The capsule restart policy
    55  	RestartPolicy map[string]string `json:"restart_policy"`
    56  
    57  	// The capsule metadata labels
    58  	MetaLabels map[string]string `json:"labels"`
    59  
    60  	// The capsule IP addresses
    61  	Addresses map[string][]Address `json:"addresses"`
    62  
    63  	// The container object inside capsule
    64  	Containers []Container `json:"containers"`
    65  
    66  	// The capsule host
    67  	Host string `json:"host"`
    68  }
    69  
    70  // ExtractCapsulesV132 accepts a Page struct, specifically a CapsulePage struct,
    71  // and extracts the elements into a slice of CapsuleV132 structs. In other words,
    72  // a generic collection is mapped into a relevant slice.
    73  func ExtractCapsulesV132(r pagination.Page) ([]CapsuleV132, error) {
    74  	var s struct {
    75  		Capsules []CapsuleV132 `json:"capsules"`
    76  	}
    77  	err := (r.(CapsulePage)).ExtractInto(&s)
    78  	return s.Capsules, err
    79  }
    80  
    81  func (r *CapsuleV132) UnmarshalJSON(b []byte) error {
    82  	type tmp CapsuleV132
    83  
    84  	var s struct {
    85  		tmp
    86  		CreatedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"created_at"`
    87  		UpdatedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"updated_at"`
    88  	}
    89  
    90  	err := json.Unmarshal(b, &s)
    91  	if err != nil {
    92  		return err
    93  	}
    94  
    95  	*r = CapsuleV132(s.tmp)
    96  
    97  	r.CreatedAt = time.Time(s.CreatedAt)
    98  	r.UpdatedAt = time.Time(s.UpdatedAt)
    99  
   100  	return nil
   101  }