Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 1 | package openstack |
| 2 | |
| 3 | import ( |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 4 | "fmt" |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 5 | "net/url" |
jrperritt | 93b4a3c | 2016-07-20 20:29:30 -0500 | [diff] [blame] | 6 | "reflect" |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 7 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud" |
| 9 | tokens2 "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens" |
| 10 | tokens3 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" |
| 11 | "github.com/gophercloud/gophercloud/openstack/utils" |
Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 12 | ) |
| 13 | |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 14 | const ( |
| 15 | v20 = "v2.0" |
| 16 | v30 = "v3.0" |
| 17 | ) |
Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 18 | |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 19 | // NewClient prepares an unauthenticated ProviderClient instance. |
| 20 | // Most users will probably prefer using the AuthenticatedClient function instead. |
| 21 | // This is useful if you wish to explicitly control the version of the identity service that's used for authentication explicitly, |
| 22 | // for example. |
| 23 | func NewClient(endpoint string) (*gophercloud.ProviderClient, error) { |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 24 | u, err := url.Parse(endpoint) |
| 25 | if err != nil { |
| 26 | return nil, err |
| 27 | } |
| 28 | hadPath := u.Path != "" |
| 29 | u.Path, u.RawQuery, u.Fragment = "", "", "" |
| 30 | base := u.String() |
| 31 | |
Ash Wilson | a844064 | 2014-10-07 09:55:58 -0400 | [diff] [blame] | 32 | endpoint = gophercloud.NormalizeURL(endpoint) |
| 33 | base = gophercloud.NormalizeURL(base) |
Ash Wilson | e7da01c | 2014-09-09 12:31:06 -0400 | [diff] [blame] | 34 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 35 | if hadPath { |
| 36 | return &gophercloud.ProviderClient{ |
| 37 | IdentityBase: base, |
| 38 | IdentityEndpoint: endpoint, |
| 39 | }, nil |
| 40 | } |
| 41 | |
| 42 | return &gophercloud.ProviderClient{ |
| 43 | IdentityBase: base, |
| 44 | IdentityEndpoint: "", |
| 45 | }, nil |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | // AuthenticatedClient logs in to an OpenStack cloud found at the identity endpoint specified by options, acquires a token, and |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 49 | // returns a Client instance that's ready to operate. |
Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 50 | // It first queries the root identity endpoint to determine which versions of the identity service are supported, then chooses |
| 51 | // the most recent identity service available to proceed. |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 52 | func AuthenticatedClient(options gophercloud.AuthOptions) (*gophercloud.ProviderClient, error) { |
| 53 | client, err := NewClient(options.IdentityEndpoint) |
| 54 | if err != nil { |
| 55 | return nil, err |
| 56 | } |
| 57 | |
| 58 | err = Authenticate(client, options) |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | return client, nil |
| 63 | } |
| 64 | |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 65 | // Authenticate or re-authenticate against the most recent identity service supported at the provided endpoint. |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 66 | func Authenticate(client *gophercloud.ProviderClient, options gophercloud.AuthOptions) error { |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 67 | versions := []*utils.Version{ |
feisky | 66803f0 | 2015-08-28 22:06:34 +0800 | [diff] [blame] | 68 | {ID: v20, Priority: 20, Suffix: "/v2.0/"}, |
| 69 | {ID: v30, Priority: 30, Suffix: "/v3/"}, |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 70 | } |
| 71 | |
Ash Wilson | 2491b4c | 2015-02-12 16:13:39 -0500 | [diff] [blame] | 72 | chosen, endpoint, err := utils.ChooseVersion(client, versions) |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 73 | if err != nil { |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 74 | return err |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | switch chosen.ID { |
| 78 | case v20: |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 79 | return v2auth(client, endpoint, options, gophercloud.EndpointOpts{}) |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 80 | case v30: |
jrperritt | 0bc5578 | 2016-07-27 13:50:14 -0500 | [diff] [blame] | 81 | return v3auth(client, endpoint, &options, gophercloud.EndpointOpts{}) |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 82 | default: |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 83 | // The switch statement must be out of date from the versions list. |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 84 | return fmt.Errorf("Unrecognized identity version: %s", chosen.ID) |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 88 | // AuthenticateV2 explicitly authenticates against the identity v2 endpoint. |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 89 | func AuthenticateV2(client *gophercloud.ProviderClient, options gophercloud.AuthOptions, eo gophercloud.EndpointOpts) error { |
| 90 | return v2auth(client, "", options, eo) |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 93 | func v2auth(client *gophercloud.ProviderClient, endpoint string, options gophercloud.AuthOptions, eo gophercloud.EndpointOpts) error { |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 94 | v2Client, err := NewIdentityV2(client, eo) |
| 95 | if err != nil { |
| 96 | return err |
| 97 | } |
| 98 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 99 | if endpoint != "" { |
| 100 | v2Client.Endpoint = endpoint |
| 101 | } |
| 102 | |
jrperritt | 64d0ef0 | 2016-04-13 13:10:04 -0500 | [diff] [blame] | 103 | v2Opts := tokens2.AuthOptions{ |
| 104 | IdentityEndpoint: options.IdentityEndpoint, |
| 105 | Username: options.Username, |
| 106 | Password: options.Password, |
| 107 | TenantID: options.TenantID, |
| 108 | TenantName: options.TenantName, |
| 109 | AllowReauth: options.AllowReauth, |
| 110 | TokenID: options.TokenID, |
| 111 | } |
| 112 | |
| 113 | result := tokens2.Create(v2Client, v2Opts) |
Ash Wilson | 52fbd18 | 2014-10-03 13:48:06 -0400 | [diff] [blame] | 114 | |
| 115 | token, err := result.ExtractToken() |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | |
Ash Wilson | 52fbd18 | 2014-10-03 13:48:06 -0400 | [diff] [blame] | 120 | catalog, err := result.ExtractServiceCatalog() |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 121 | if err != nil { |
| 122 | return err |
| 123 | } |
| 124 | |
Jon Perritt | f4052c6 | 2015-02-14 09:48:18 -0700 | [diff] [blame] | 125 | if options.AllowReauth { |
Jon Perritt | 6fe7c40 | 2015-02-17 12:24:53 -0700 | [diff] [blame] | 126 | client.ReauthFunc = func() error { |
Masahiro Sano | 1b2bafe | 2015-03-06 23:26:54 +0900 | [diff] [blame] | 127 | client.TokenID = "" |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 128 | return v2auth(client, endpoint, options, eo) |
Jon Perritt | 6fe7c40 | 2015-02-17 12:24:53 -0700 | [diff] [blame] | 129 | } |
Jon Perritt | f4052c6 | 2015-02-14 09:48:18 -0700 | [diff] [blame] | 130 | } |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 131 | client.TokenID = token.ID |
Ash Wilson | 130a6e2 | 2014-10-07 10:48:17 -0400 | [diff] [blame] | 132 | client.EndpointLocator = func(opts gophercloud.EndpointOpts) (string, error) { |
| 133 | return V2EndpointURL(catalog, opts) |
| 134 | } |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 135 | |
| 136 | return nil |
| 137 | } |
| 138 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 139 | // AuthenticateV3 explicitly authenticates against the identity v3 service. |
jrperritt | 0bc5578 | 2016-07-27 13:50:14 -0500 | [diff] [blame] | 140 | func AuthenticateV3(client *gophercloud.ProviderClient, options tokens3.AuthOptionsBuilder, eo gophercloud.EndpointOpts) error { |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 141 | return v3auth(client, "", options, eo) |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 142 | } |
| 143 | |
jrperritt | 0bc5578 | 2016-07-27 13:50:14 -0500 | [diff] [blame] | 144 | func v3auth(client *gophercloud.ProviderClient, endpoint string, opts tokens3.AuthOptionsBuilder, eo gophercloud.EndpointOpts) error { |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 145 | // Override the generated service endpoint with the one returned by the version endpoint. |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 146 | v3Client, err := NewIdentityV3(client, eo) |
| 147 | if err != nil { |
| 148 | return err |
| 149 | } |
| 150 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 151 | if endpoint != "" { |
| 152 | v3Client.Endpoint = endpoint |
| 153 | } |
| 154 | |
jrperritt | 0bc5578 | 2016-07-27 13:50:14 -0500 | [diff] [blame] | 155 | result := tokens3.Create(v3Client, opts) |
Guillaume Giamarchi | b2663b2 | 2015-04-01 01:23:29 +0200 | [diff] [blame] | 156 | |
| 157 | token, err := result.ExtractToken() |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 158 | if err != nil { |
| 159 | return err |
| 160 | } |
Guillaume Giamarchi | b2663b2 | 2015-04-01 01:23:29 +0200 | [diff] [blame] | 161 | |
| 162 | catalog, err := result.ExtractServiceCatalog() |
| 163 | if err != nil { |
| 164 | return err |
| 165 | } |
| 166 | |
Ash Wilson | 63b2a29 | 2014-10-02 09:29:06 -0400 | [diff] [blame] | 167 | client.TokenID = token.ID |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 168 | |
jrperritt | 0bc5578 | 2016-07-27 13:50:14 -0500 | [diff] [blame] | 169 | if opts.CanReauth() { |
Jon Perritt | 6fe7c40 | 2015-02-17 12:24:53 -0700 | [diff] [blame] | 170 | client.ReauthFunc = func() error { |
hzlouchao | f6e2926 | 2015-10-27 12:51:08 +0800 | [diff] [blame] | 171 | client.TokenID = "" |
jrperritt | 0bc5578 | 2016-07-27 13:50:14 -0500 | [diff] [blame] | 172 | return v3auth(client, endpoint, opts, eo) |
Jon Perritt | 6fe7c40 | 2015-02-17 12:24:53 -0700 | [diff] [blame] | 173 | } |
Jon Perritt | f4052c6 | 2015-02-14 09:48:18 -0700 | [diff] [blame] | 174 | } |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 175 | client.EndpointLocator = func(opts gophercloud.EndpointOpts) (string, error) { |
Guillaume Giamarchi | b2663b2 | 2015-04-01 01:23:29 +0200 | [diff] [blame] | 176 | return V3EndpointURL(catalog, opts) |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | return nil |
| 180 | } |
| 181 | |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 182 | // NewIdentityV2 creates a ServiceClient that may be used to interact with the v2 identity service. |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 183 | func NewIdentityV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
jrperritt | 93b4a3c | 2016-07-20 20:29:30 -0500 | [diff] [blame] | 184 | endpoint := client.IdentityBase + "v2.0/" |
| 185 | var err error |
| 186 | if !reflect.DeepEqual(eo, gophercloud.EndpointOpts{}) { |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 187 | eo.ApplyDefaults("identity") |
jrperritt | 93b4a3c | 2016-07-20 20:29:30 -0500 | [diff] [blame] | 188 | endpoint, err = client.EndpointLocator(eo) |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 189 | if err != nil { |
| 190 | return nil, err |
| 191 | } |
jrperritt | 93b4a3c | 2016-07-20 20:29:30 -0500 | [diff] [blame] | 192 | } |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 193 | |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 194 | return &gophercloud.ServiceClient{ |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 195 | ProviderClient: client, |
jrperritt | 93b4a3c | 2016-07-20 20:29:30 -0500 | [diff] [blame] | 196 | Endpoint: endpoint, |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 197 | }, nil |
Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 200 | // NewIdentityV3 creates a ServiceClient that may be used to access the v3 identity service. |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 201 | func NewIdentityV3(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
jrperritt | 93b4a3c | 2016-07-20 20:29:30 -0500 | [diff] [blame] | 202 | endpoint := client.IdentityBase + "v3/" |
| 203 | var err error |
| 204 | if !reflect.DeepEqual(eo, gophercloud.EndpointOpts{}) { |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 205 | eo.ApplyDefaults("identity") |
jrperritt | 93b4a3c | 2016-07-20 20:29:30 -0500 | [diff] [blame] | 206 | endpoint, err = client.EndpointLocator(eo) |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 207 | if err != nil { |
| 208 | return nil, err |
| 209 | } |
jrperritt | 93b4a3c | 2016-07-20 20:29:30 -0500 | [diff] [blame] | 210 | } |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 211 | |
| 212 | return &gophercloud.ServiceClient{ |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 213 | ProviderClient: client, |
jrperritt | 93b4a3c | 2016-07-20 20:29:30 -0500 | [diff] [blame] | 214 | Endpoint: endpoint, |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 215 | }, nil |
feisky | 66803f0 | 2015-08-28 22:06:34 +0800 | [diff] [blame] | 216 | } |
| 217 | |
Jon Perritt | bb5e981 | 2014-10-15 17:53:44 -0500 | [diff] [blame] | 218 | // NewObjectStorageV1 creates a ServiceClient that may be used with the v1 object storage package. |
| 219 | func NewObjectStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
Jon Perritt | 509fbb6 | 2014-09-10 13:29:56 -0500 | [diff] [blame] | 220 | eo.ApplyDefaults("object-store") |
| 221 | url, err := client.EndpointLocator(eo) |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 222 | if err != nil { |
| 223 | return nil, err |
| 224 | } |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 225 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 226 | } |
Ash Wilson | 5e57c1b | 2014-09-17 09:24:46 -0400 | [diff] [blame] | 227 | |
| 228 | // NewComputeV2 creates a ServiceClient that may be used with the v2 compute package. |
| 229 | func NewComputeV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 230 | eo.ApplyDefaults("compute") |
| 231 | url, err := client.EndpointLocator(eo) |
| 232 | if err != nil { |
| 233 | return nil, err |
| 234 | } |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 235 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
Ash Wilson | 5e57c1b | 2014-09-17 09:24:46 -0400 | [diff] [blame] | 236 | } |
Ash Wilson | ebc3d12 | 2014-09-24 13:44:05 -0400 | [diff] [blame] | 237 | |
| 238 | // NewNetworkV2 creates a ServiceClient that may be used with the v2 network package. |
Jamie Hannaford | 7ea2958 | 2014-09-11 15:49:46 +0200 | [diff] [blame] | 239 | func NewNetworkV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 240 | eo.ApplyDefaults("network") |
| 241 | url, err := client.EndpointLocator(eo) |
| 242 | if err != nil { |
| 243 | return nil, err |
| 244 | } |
Ash Wilson | 99541ab | 2014-10-06 17:32:39 -0400 | [diff] [blame] | 245 | return &gophercloud.ServiceClient{ |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 246 | ProviderClient: client, |
| 247 | Endpoint: url, |
| 248 | ResourceBase: url + "v2.0/", |
Ash Wilson | 99541ab | 2014-10-06 17:32:39 -0400 | [diff] [blame] | 249 | }, nil |
Jamie Hannaford | 7ea2958 | 2014-09-11 15:49:46 +0200 | [diff] [blame] | 250 | } |
Jon Perritt | c5ee85e | 2014-09-17 00:53:19 -0500 | [diff] [blame] | 251 | |
| 252 | // NewBlockStorageV1 creates a ServiceClient that may be used to access the v1 block storage service. |
| 253 | func NewBlockStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 254 | eo.ApplyDefaults("volume") |
| 255 | url, err := client.EndpointLocator(eo) |
| 256 | if err != nil { |
| 257 | return nil, err |
| 258 | } |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 259 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
Jon Perritt | c5ee85e | 2014-09-17 00:53:19 -0500 | [diff] [blame] | 260 | } |
Jon Perritt | ebd18ec | 2015-01-16 09:13:31 -0700 | [diff] [blame] | 261 | |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 262 | // NewBlockStorageV2 creates a ServiceClient that may be used to access the v2 block storage service. |
| 263 | func NewBlockStorageV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
Nick Craig-Wood | b64fd20 | 2016-05-13 15:56:18 +0100 | [diff] [blame] | 264 | eo.ApplyDefaults("volumev2") |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 265 | url, err := client.EndpointLocator(eo) |
| 266 | if err != nil { |
| 267 | return nil, err |
| 268 | } |
Nick Craig-Wood | b64fd20 | 2016-05-13 15:56:18 +0100 | [diff] [blame] | 269 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 270 | } |
| 271 | |
ehdou | 10f1f85 | 2016-10-14 20:58:23 +0300 | [diff] [blame] | 272 | // NewSharedFileSystemV2 creates a ServiceClient that may be used to access the v2 shared file system service. |
| 273 | func NewSharedFileSystemV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 274 | eo.ApplyDefaults("sharev2") |
| 275 | url, err := client.EndpointLocator(eo) |
| 276 | if err != nil { |
| 277 | return nil, err |
| 278 | } |
| 279 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
| 280 | } |
| 281 | |
Jon Perritt | ebd18ec | 2015-01-16 09:13:31 -0700 | [diff] [blame] | 282 | // NewCDNV1 creates a ServiceClient that may be used to access the OpenStack v1 |
| 283 | // CDN service. |
| 284 | func NewCDNV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 285 | eo.ApplyDefaults("cdn") |
| 286 | url, err := client.EndpointLocator(eo) |
| 287 | if err != nil { |
| 288 | return nil, err |
| 289 | } |
| 290 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
| 291 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 292 | |
| 293 | // NewOrchestrationV1 creates a ServiceClient that may be used to access the v1 orchestration service. |
| 294 | func NewOrchestrationV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 295 | eo.ApplyDefaults("orchestration") |
| 296 | url, err := client.EndpointLocator(eo) |
| 297 | if err != nil { |
| 298 | return nil, err |
| 299 | } |
| 300 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
| 301 | } |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 302 | |
Jamie Hannaford | 75e8cc4 | 2015-11-16 14:09:25 +0100 | [diff] [blame] | 303 | // NewDBV1 creates a ServiceClient that may be used to access the v1 DB service. |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 304 | func NewDBV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 305 | eo.ApplyDefaults("database") |
| 306 | url, err := client.EndpointLocator(eo) |
| 307 | if err != nil { |
| 308 | return nil, err |
| 309 | } |
| 310 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
| 311 | } |
jrperritt | c5c590a | 2016-11-04 14:41:15 -0500 | [diff] [blame^] | 312 | |
| 313 | // NewImageServiceV2 creates a ServiceClient that may be used to access the v2 image service. |
| 314 | func NewImageServiceV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 315 | eo.ApplyDefaults("image") |
| 316 | url, err := client.EndpointLocator(eo) |
| 317 | if err != nil { |
| 318 | return nil, err |
| 319 | } |
| 320 | return &gophercloud.ServiceClient{ProviderClient: client, |
| 321 | Endpoint: url, |
| 322 | ResourceBase: url + "v2/"}, nil |
| 323 | } |