Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 1 | package configurations |
| 2 | |
| 3 | import ( |
Krzysztof Szukiełojć | 3f41d08 | 2017-05-07 14:43:06 +0200 | [diff] [blame^] | 4 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 5 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/db/v1/instances" |
| 6 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 7 | ) |
| 8 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 9 | // List will list all of the available configurations. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 10 | func List(client *gophercloud.ServiceClient) pagination.Pager { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 11 | return pagination.NewPager(client, baseURL(client), func(r pagination.PageResult) pagination.Page { |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 12 | return ConfigPage{pagination.SinglePageBase(r)} |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 13 | }) |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 14 | } |
| 15 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 16 | // CreateOptsBuilder is a top-level interface which renders a JSON map. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 17 | type CreateOptsBuilder interface { |
| 18 | ToConfigCreateMap() (map[string]interface{}, error) |
| 19 | } |
| 20 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 21 | // DatastoreOpts is the primary options struct for creating and modifying |
| 22 | // how configuration resources are associated with datastores. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 23 | type DatastoreOpts struct { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 24 | // The type of datastore. Defaults to "MySQL". |
| 25 | Type string `json:"type,omitempty"` |
| 26 | // The specific version of a datastore. Defaults to "5.6". |
| 27 | Version string `json:"version,omitempty"` |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 28 | } |
| 29 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 30 | // CreateOpts is the struct responsible for configuring new configurations. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 31 | type CreateOpts struct { |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 32 | // The configuration group name |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 33 | Name string `json:"name" required:"true"` |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 34 | // A map of user-defined configuration settings that will define |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 35 | // how each associated datastore works. Each key/value pair is specific to a |
| 36 | // datastore type. |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 37 | Values map[string]interface{} `json:"values" required:"true"` |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 38 | // Associates the configuration group with a particular datastore. |
| 39 | Datastore *DatastoreOpts `json:"datastore,omitempty"` |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 40 | // A human-readable explanation for the group. |
| 41 | Description string `json:"description,omitempty"` |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 44 | // ToConfigCreateMap casts a CreateOpts struct into a JSON map. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 45 | func (opts CreateOpts) ToConfigCreateMap() (map[string]interface{}, error) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 46 | return gophercloud.BuildRequestBody(opts, "configuration") |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 47 | } |
| 48 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 49 | // Create will create a new configuration group. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 50 | func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 51 | b, err := opts.ToConfigCreateMap() |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 52 | if err != nil { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 53 | r.Err = err |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 54 | return |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 55 | } |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 56 | _, r.Err = client.Post(baseURL(client), &b, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}}) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 57 | return |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 60 | // Get will retrieve the details for a specified configuration group. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 61 | func Get(client *gophercloud.ServiceClient, configID string) (r GetResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 62 | _, r.Err = client.Get(resourceURL(client, configID), &r.Body, nil) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 63 | return |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 66 | // UpdateOptsBuilder is the top-level interface for casting update options into |
| 67 | // JSON maps. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 68 | type UpdateOptsBuilder interface { |
| 69 | ToConfigUpdateMap() (map[string]interface{}, error) |
| 70 | } |
| 71 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 72 | // UpdateOpts is the struct responsible for modifying existing configurations. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 73 | type UpdateOpts struct { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 74 | // The configuration group name |
| 75 | Name string `json:"name,omitempty"` |
| 76 | // A map of user-defined configuration settings that will define |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 77 | // how each associated datastore works. Each key/value pair is specific to a |
| 78 | // datastore type. |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 79 | Values map[string]interface{} `json:"values,omitempty"` |
| 80 | // Associates the configuration group with a particular datastore. |
| 81 | Datastore *DatastoreOpts `json:"datastore,omitempty"` |
| 82 | // A human-readable explanation for the group. |
| 83 | Description string `json:"description,omitempty"` |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 86 | // ToConfigUpdateMap will cast an UpdateOpts struct into a JSON map. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 87 | func (opts UpdateOpts) ToConfigUpdateMap() (map[string]interface{}, error) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 88 | return gophercloud.BuildRequestBody(opts, "configuration") |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 91 | // Update will modify an existing configuration group by performing a merge |
| 92 | // between new and existing values. If the key already exists, the new value |
| 93 | // will overwrite. All other keys will remain unaffected. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 94 | func Update(client *gophercloud.ServiceClient, configID string, opts UpdateOptsBuilder) (r UpdateResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 95 | b, err := opts.ToConfigUpdateMap() |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 96 | if err != nil { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 97 | r.Err = err |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 98 | return |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 99 | } |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 100 | _, r.Err = client.Patch(resourceURL(client, configID), &b, nil, nil) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 101 | return |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 104 | // Replace will modify an existing configuration group by overwriting the |
| 105 | // entire parameter group with the new values provided. Any existing keys not |
| 106 | // included in UpdateOptsBuilder will be deleted. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 107 | func Replace(client *gophercloud.ServiceClient, configID string, opts UpdateOptsBuilder) (r ReplaceResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 108 | b, err := opts.ToConfigUpdateMap() |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 109 | if err != nil { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 110 | r.Err = err |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 111 | return |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 112 | } |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 113 | _, r.Err = client.Put(resourceURL(client, configID), &b, nil, nil) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 114 | return |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 115 | } |
| 116 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 117 | // Delete will permanently delete a configuration group. Please note that |
| 118 | // config groups cannot be deleted whilst still attached to running instances - |
| 119 | // you must detach and then delete them. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 120 | func Delete(client *gophercloud.ServiceClient, configID string) (r DeleteResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 121 | _, r.Err = client.Delete(resourceURL(client, configID), nil) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 122 | return |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 125 | // ListInstances will list all the instances associated with a particular |
| 126 | // configuration group. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 127 | func ListInstances(client *gophercloud.ServiceClient, configID string) pagination.Pager { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 128 | return pagination.NewPager(client, instancesURL(client, configID), func(r pagination.PageResult) pagination.Page { |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 129 | return instances.InstancePage{pagination.LinkedPageBase{PageResult: r}} |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 130 | }) |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 131 | } |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 132 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 133 | // ListDatastoreParams will list all the available and supported parameters |
| 134 | // that can be used for a particular datastore ID and a particular version. |
| 135 | // For example, if you are wondering how you can configure a MySQL 5.6 instance, |
| 136 | // you can use this operation (you will need to retrieve the MySQL datastore ID |
| 137 | // by using the datastores API). |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 138 | func ListDatastoreParams(client *gophercloud.ServiceClient, datastoreID, versionID string) pagination.Pager { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 139 | return pagination.NewPager(client, listDSParamsURL(client, datastoreID, versionID), func(r pagination.PageResult) pagination.Page { |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 140 | return ParamPage{pagination.SinglePageBase(r)} |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 141 | }) |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 142 | } |
| 143 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 144 | // GetDatastoreParam will retrieve information about a specific configuration |
| 145 | // parameter. For example, you can use this operation to understand more about |
| 146 | // "innodb_file_per_table" configuration param for MySQL datastores. You will |
| 147 | // need the param's ID first, which can be attained by using the ListDatastoreParams |
| 148 | // operation. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 149 | func GetDatastoreParam(client *gophercloud.ServiceClient, datastoreID, versionID, paramID string) (r ParamResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 150 | _, r.Err = client.Get(getDSParamURL(client, datastoreID, versionID, paramID), &r.Body, nil) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 151 | return |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 154 | // ListGlobalParams is similar to ListDatastoreParams but does not require a |
| 155 | // DatastoreID. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 156 | func ListGlobalParams(client *gophercloud.ServiceClient, versionID string) pagination.Pager { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 157 | return pagination.NewPager(client, listGlobalParamsURL(client, versionID), func(r pagination.PageResult) pagination.Page { |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 158 | return ParamPage{pagination.SinglePageBase(r)} |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 159 | }) |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 160 | } |
| 161 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 162 | // GetGlobalParam is similar to GetDatastoreParam but does not require a |
| 163 | // DatastoreID. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 164 | func GetGlobalParam(client *gophercloud.ServiceClient, versionID, paramID string) (r ParamResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 165 | _, r.Err = client.Get(getGlobalParamURL(client, versionID, paramID), &r.Body, nil) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 166 | return |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 167 | } |