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

     1  package clustertemplates
     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 ExtractErr
    20  // method to determine if the call succeeded or failed.
    21  type DeleteResult struct {
    22  	gophercloud.ErrResult
    23  }
    24  
    25  // GetResult is the response of a Get operations.
    26  type GetResult struct {
    27  	commonResult
    28  }
    29  
    30  // UpdateResult is the response of a Update operations.
    31  type UpdateResult struct {
    32  	commonResult
    33  }
    34  
    35  // Extract is a function that accepts a result and extracts a cluster-template resource.
    36  func (r commonResult) Extract() (*ClusterTemplate, error) {
    37  	var s *ClusterTemplate
    38  	err := r.ExtractInto(&s)
    39  	return s, err
    40  }
    41  
    42  // Represents a template for a Cluster Template
    43  type ClusterTemplate struct {
    44  	APIServerPort       int                `json:"apiserver_port"`
    45  	COE                 string             `json:"coe"`
    46  	ClusterDistro       string             `json:"cluster_distro"`
    47  	CreatedAt           time.Time          `json:"created_at"`
    48  	DNSNameServer       string             `json:"dns_nameserver"`
    49  	DockerStorageDriver string             `json:"docker_storage_driver"`
    50  	DockerVolumeSize    int                `json:"docker_volume_size"`
    51  	ExternalNetworkID   string             `json:"external_network_id"`
    52  	FixedNetwork        string             `json:"fixed_network"`
    53  	FixedSubnet         string             `json:"fixed_subnet"`
    54  	FlavorID            string             `json:"flavor_id"`
    55  	FloatingIPEnabled   bool               `json:"floating_ip_enabled"`
    56  	HTTPProxy           string             `json:"http_proxy"`
    57  	HTTPSProxy          string             `json:"https_proxy"`
    58  	ImageID             string             `json:"image_id"`
    59  	InsecureRegistry    string             `json:"insecure_registry"`
    60  	KeyPairID           string             `json:"keypair_id"`
    61  	Labels              map[string]string  `json:"labels"`
    62  	Links               []gophercloud.Link `json:"links"`
    63  	MasterFlavorID      string             `json:"master_flavor_id"`
    64  	MasterLBEnabled     bool               `json:"master_lb_enabled"`
    65  	Name                string             `json:"name"`
    66  	NetworkDriver       string             `json:"network_driver"`
    67  	NoProxy             string             `json:"no_proxy"`
    68  	ProjectID           string             `json:"project_id"`
    69  	Public              bool               `json:"public"`
    70  	RegistryEnabled     bool               `json:"registry_enabled"`
    71  	ServerType          string             `json:"server_type"`
    72  	TLSDisabled         bool               `json:"tls_disabled"`
    73  	UUID                string             `json:"uuid"`
    74  	UpdatedAt           time.Time          `json:"updated_at"`
    75  	UserID              string             `json:"user_id"`
    76  	VolumeDriver        string             `json:"volume_driver"`
    77  	Hidden              bool               `json:"hidden"`
    78  }
    79  
    80  // ClusterTemplatePage is the page returned by a pager when traversing over a
    81  // collection of cluster-templates.
    82  type ClusterTemplatePage struct {
    83  	pagination.LinkedPageBase
    84  }
    85  
    86  // NextPageURL is invoked when a paginated collection of cluster template has reached
    87  // the end of a page and the pager seeks to traverse over a new one. In order
    88  // to do this, it needs to construct the next page's URL.
    89  func (r ClusterTemplatePage) NextPageURL() (string, error) {
    90  	var s struct {
    91  		Next string `json:"next"`
    92  	}
    93  	err := r.ExtractInto(&s)
    94  	if err != nil {
    95  		return "", err
    96  	}
    97  	return s.Next, nil
    98  }
    99  
   100  // IsEmpty checks whether a ClusterTemplatePage struct is empty.
   101  func (r ClusterTemplatePage) IsEmpty() (bool, error) {
   102  	if r.StatusCode == 204 {
   103  		return true, nil
   104  	}
   105  
   106  	is, err := ExtractClusterTemplates(r)
   107  	return len(is) == 0, err
   108  }
   109  
   110  // ExtractClusterTemplates accepts a Page struct, specifically a ClusterTemplatePage struct,
   111  // and extracts the elements into a slice of cluster templates structs. In other words,
   112  // a generic collection is mapped into a relevant slice.
   113  func ExtractClusterTemplates(r pagination.Page) ([]ClusterTemplate, error) {
   114  	var s struct {
   115  		ClusterTemplates []ClusterTemplate `json:"clustertemplates"`
   116  	}
   117  	err := (r.(ClusterTemplatePage)).ExtractInto(&s)
   118  	return s.ClusterTemplates, err
   119  }