github.com/gophercloud/gophercloud@v1.11.0/openstack/containerinfra/v1/clustertemplates/requests.go (about) 1 package clustertemplates 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // CreateOptsBuilder Builder. 9 type CreateOptsBuilder interface { 10 ToClusterCreateMap() (map[string]interface{}, error) 11 } 12 13 // CreateOpts params 14 type CreateOpts struct { 15 APIServerPort *int `json:"apiserver_port,omitempty"` 16 COE string `json:"coe" required:"true"` 17 DNSNameServer string `json:"dns_nameserver,omitempty"` 18 DockerStorageDriver string `json:"docker_storage_driver,omitempty"` 19 DockerVolumeSize *int `json:"docker_volume_size,omitempty"` 20 ExternalNetworkID string `json:"external_network_id,omitempty"` 21 FixedNetwork string `json:"fixed_network,omitempty"` 22 FixedSubnet string `json:"fixed_subnet,omitempty"` 23 FlavorID string `json:"flavor_id,omitempty"` 24 FloatingIPEnabled *bool `json:"floating_ip_enabled,omitempty"` 25 HTTPProxy string `json:"http_proxy,omitempty"` 26 HTTPSProxy string `json:"https_proxy,omitempty"` 27 ImageID string `json:"image_id" required:"true"` 28 InsecureRegistry string `json:"insecure_registry,omitempty"` 29 KeyPairID string `json:"keypair_id,omitempty"` 30 Labels map[string]string `json:"labels,omitempty"` 31 MasterFlavorID string `json:"master_flavor_id,omitempty"` 32 MasterLBEnabled *bool `json:"master_lb_enabled,omitempty"` 33 Name string `json:"name,omitempty"` 34 NetworkDriver string `json:"network_driver,omitempty"` 35 NoProxy string `json:"no_proxy,omitempty"` 36 Public *bool `json:"public,omitempty"` 37 RegistryEnabled *bool `json:"registry_enabled,omitempty"` 38 ServerType string `json:"server_type,omitempty"` 39 TLSDisabled *bool `json:"tls_disabled,omitempty"` 40 VolumeDriver string `json:"volume_driver,omitempty"` 41 Hidden *bool `json:"hidden,omitempty"` 42 } 43 44 // ToClusterCreateMap constructs a request body from CreateOpts. 45 func (opts CreateOpts) ToClusterCreateMap() (map[string]interface{}, error) { 46 return gophercloud.BuildRequestBody(opts, "") 47 } 48 49 // Create requests the creation of a new cluster. 50 func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 51 b, err := opts.ToClusterCreateMap() 52 if err != nil { 53 r.Err = err 54 return 55 } 56 resp, err := client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ 57 OkCodes: []int{201}, 58 }) 59 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 60 return 61 } 62 63 // Delete deletes the specified cluster ID. 64 func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { 65 resp, err := client.Delete(deleteURL(client, id), nil) 66 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 67 return 68 } 69 70 // ListOptsBuilder allows extensions to add additional parameters to the 71 // List request. 72 type ListOptsBuilder interface { 73 ToClusterTemplateListQuery() (string, error) 74 } 75 76 // ListOpts allows the sorting of paginated collections through 77 // the API. SortKey allows you to sort by a particular cluster templates attribute. 78 // SortDir sets the direction, and is either `asc' or `desc'. 79 // Marker and Limit are used for pagination. 80 type ListOpts struct { 81 Marker string `q:"marker"` 82 Limit int `q:"limit"` 83 SortKey string `q:"sort_key"` 84 SortDir string `q:"sort_dir"` 85 } 86 87 // ToClusterTemplateListQuery formats a ListOpts into a query string. 88 func (opts ListOpts) ToClusterTemplateListQuery() (string, error) { 89 q, err := gophercloud.BuildQueryString(opts) 90 return q.String(), err 91 } 92 93 // List returns a Pager which allows you to iterate over a collection of 94 // cluster-templates. It accepts a ListOptsBuilder, which allows you to sort 95 // the returned collection for greater efficiency. 96 func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 97 url := listURL(client) 98 if opts != nil { 99 query, err := opts.ToClusterTemplateListQuery() 100 if err != nil { 101 return pagination.Pager{Err: err} 102 } 103 url += query 104 } 105 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 106 return ClusterTemplatePage{pagination.LinkedPageBase{PageResult: r}} 107 }) 108 } 109 110 // Get retrieves a specific cluster-template based on its unique ID. 111 func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { 112 resp, err := client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}}) 113 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 114 return 115 } 116 117 type UpdateOp string 118 119 const ( 120 AddOp UpdateOp = "add" 121 RemoveOp UpdateOp = "remove" 122 ReplaceOp UpdateOp = "replace" 123 ) 124 125 type UpdateOpts struct { 126 Op UpdateOp `json:"op" required:"true"` 127 Path string `json:"path" required:"true"` 128 Value interface{} `json:"value,omitempty"` 129 } 130 131 // UpdateOptsBuilder allows extensions to add additional parameters to the 132 // Update request. 133 type UpdateOptsBuilder interface { 134 ToClusterTemplateUpdateMap() (map[string]interface{}, error) 135 } 136 137 // ToClusterUpdateMap assembles a request body based on the contents of 138 // UpdateOpts. 139 func (opts UpdateOpts) ToClusterTemplateUpdateMap() (map[string]interface{}, error) { 140 b, err := gophercloud.BuildRequestBody(opts, "") 141 if err != nil { 142 return nil, err 143 } 144 145 return b, nil 146 } 147 148 // Update implements cluster updated request. 149 func Update(client *gophercloud.ServiceClient, id string, opts []UpdateOptsBuilder) (r UpdateResult) { 150 var o []map[string]interface{} 151 for _, opt := range opts { 152 b, err := opt.ToClusterTemplateUpdateMap() 153 if err != nil { 154 r.Err = err 155 return r 156 } 157 o = append(o, b) 158 } 159 resp, err := client.Patch(updateURL(client, id), o, &r.Body, &gophercloud.RequestOpts{ 160 OkCodes: []int{200, 202}, 161 }) 162 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 163 return 164 }