github.com/gophercloud/gophercloud@v1.11.0/openstack/containerinfra/v1/clusters/results.go (about)

     1  package clusters
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/gophercloud/gophercloud"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  )
     9  
    10  type commonResult struct {
    11  	gophercloud.Result
    12  }
    13  
    14  // CreateResult is the response of a Create operations.
    15  type CreateResult struct {
    16  	commonResult
    17  }
    18  
    19  // DeleteResult is the result from a Delete operation. Call its Extract or ExtractErr
    20  // method to determine if the call succeeded or failed.
    21  type DeleteResult struct {
    22  	gophercloud.ErrResult
    23  }
    24  
    25  // GetResult represents the result of a get operation.
    26  type GetResult struct {
    27  	commonResult
    28  }
    29  
    30  // Extract is a function that accepts a result and extracts a cluster resource.
    31  func (r commonResult) Extract() (*Cluster, error) {
    32  	var s *Cluster
    33  	err := r.ExtractInto(&s)
    34  	return s, err
    35  }
    36  
    37  // UpdateResult is the response of a Update operations.
    38  type UpdateResult struct {
    39  	commonResult
    40  }
    41  
    42  // UpgradeResult is the response of a Upgrade operations.
    43  type UpgradeResult struct {
    44  	commonResult
    45  }
    46  
    47  // ResizeResult is the response of a Resize operations.
    48  type ResizeResult struct {
    49  	commonResult
    50  }
    51  
    52  func (r CreateResult) Extract() (string, error) {
    53  	var s struct {
    54  		UUID string
    55  	}
    56  	err := r.ExtractInto(&s)
    57  	return s.UUID, err
    58  }
    59  
    60  func (r UpdateResult) Extract() (string, error) {
    61  	var s struct {
    62  		UUID string
    63  	}
    64  	err := r.ExtractInto(&s)
    65  	return s.UUID, err
    66  }
    67  
    68  func (r UpgradeResult) Extract() (string, error) {
    69  	var s struct {
    70  		UUID string
    71  	}
    72  	err := r.ExtractInto(&s)
    73  	return s.UUID, err
    74  }
    75  
    76  func (r ResizeResult) Extract() (string, error) {
    77  	var s struct {
    78  		UUID string
    79  	}
    80  	err := r.ExtractInto(&s)
    81  	return s.UUID, err
    82  }
    83  
    84  type Cluster struct {
    85  	APIAddress         string                 `json:"api_address"`
    86  	COEVersion         string                 `json:"coe_version"`
    87  	ClusterTemplateID  string                 `json:"cluster_template_id"`
    88  	ContainerVersion   string                 `json:"container_version"`
    89  	CreateTimeout      int                    `json:"create_timeout"`
    90  	CreatedAt          time.Time              `json:"created_at"`
    91  	DiscoveryURL       string                 `json:"discovery_url"`
    92  	DockerVolumeSize   int                    `json:"docker_volume_size"`
    93  	Faults             map[string]string      `json:"faults"`
    94  	FlavorID           string                 `json:"flavor_id"`
    95  	KeyPair            string                 `json:"keypair"`
    96  	Labels             map[string]string      `json:"labels"`
    97  	LabelsAdded        map[string]string      `json:"labels_added"`
    98  	LabelsOverridden   map[string]string      `json:"labels_overridden"`
    99  	LabelsSkipped      map[string]string      `json:"labels_skipped"`
   100  	Links              []gophercloud.Link     `json:"links"`
   101  	MasterFlavorID     string                 `json:"master_flavor_id"`
   102  	MasterAddresses    []string               `json:"master_addresses"`
   103  	MasterCount        int                    `json:"master_count"`
   104  	Name               string                 `json:"name"`
   105  	NodeAddresses      []string               `json:"node_addresses"`
   106  	NodeCount          int                    `json:"node_count"`
   107  	ProjectID          string                 `json:"project_id"`
   108  	StackID            string                 `json:"stack_id"`
   109  	Status             string                 `json:"status"`
   110  	StatusReason       string                 `json:"status_reason"`
   111  	UUID               string                 `json:"uuid"`
   112  	UpdatedAt          time.Time              `json:"updated_at"`
   113  	UserID             string                 `json:"user_id"`
   114  	FloatingIPEnabled  bool                   `json:"floating_ip_enabled"`
   115  	FixedNetwork       string                 `json:"fixed_network"`
   116  	FixedSubnet        string                 `json:"fixed_subnet"`
   117  	HealthStatus       string                 `json:"health_status"`
   118  	HealthStatusReason map[string]interface{} `json:"health_status_reason"`
   119  }
   120  
   121  type ClusterPage struct {
   122  	pagination.LinkedPageBase
   123  }
   124  
   125  func (r ClusterPage) NextPageURL() (string, error) {
   126  	var s struct {
   127  		Next string `json:"next"`
   128  	}
   129  	err := r.ExtractInto(&s)
   130  	if err != nil {
   131  		return "", err
   132  	}
   133  	return s.Next, nil
   134  }
   135  
   136  // IsEmpty checks whether a ClusterPage struct is empty.
   137  func (r ClusterPage) IsEmpty() (bool, error) {
   138  	if r.StatusCode == 204 {
   139  		return true, nil
   140  	}
   141  
   142  	is, err := ExtractClusters(r)
   143  	return len(is) == 0, err
   144  }
   145  
   146  func ExtractClusters(r pagination.Page) ([]Cluster, error) {
   147  	var s struct {
   148  		Clusters []Cluster `json:"clusters"`
   149  	}
   150  	err := (r.(ClusterPage)).ExtractInto(&s)
   151  	return s.Clusters, err
   152  }