blob: b6f6b4804fc0fec04b818157345b036ceae80779 [file] [log] [blame]
Ash Wilsonb8401a72014-09-08 17:07:49 -04001package gophercloud
2
3import "errors"
4
5var (
Ash Wilson1cd3e692014-09-09 11:01:47 -04006 // ErrServiceNotFound is returned when no service matches the EndpointOpts.
7 ErrServiceNotFound = errors.New("No suitable service could be found in the service catalog.")
8
Ash Wilsonb8401a72014-09-08 17:07:49 -04009 // ErrEndpointNotFound is returned when no available endpoints match the provided EndpointOpts.
10 ErrEndpointNotFound = errors.New("No suitable endpoint could be found in the service catalog.")
11)
12
Jamie Hannafordb280dea2014-10-24 15:14:06 +020013// Availability indicates whether a specific service endpoint is accessible.
14// Identity v2 lists these as different kinds of URLs ("adminURL",
15// "internalURL", and "publicURL"), while v3 lists them as "Interfaces".
Ash Wilsonefac18b2014-09-10 14:44:42 -040016type Availability string
Ash Wilson0747d7e2014-09-09 14:27:35 -040017
18const (
Ash Wilsonefac18b2014-09-10 14:44:42 -040019 // AvailabilityAdmin makes an endpoint only available to administrators.
20 AvailabilityAdmin Availability = "admin"
Ash Wilson0747d7e2014-09-09 14:27:35 -040021
Ash Wilsonefac18b2014-09-10 14:44:42 -040022 // AvailabilityPublic makes an endpoint available to everyone.
23 AvailabilityPublic Availability = "public"
Ash Wilson0747d7e2014-09-09 14:27:35 -040024
Ash Wilsonefac18b2014-09-10 14:44:42 -040025 // AvailabilityInternal makes an endpoint only available within the cluster.
26 AvailabilityInternal Availability = "internal"
Ash Wilson0747d7e2014-09-09 14:27:35 -040027)
28
Ash Wilsonb8401a72014-09-08 17:07:49 -040029// EndpointOpts contains options for finding an endpoint for an Openstack client.
30type EndpointOpts struct {
Ash Wilsonb8401a72014-09-08 17:07:49 -040031 // Type is the service type for the client (e.g., "compute", "object-store").
Jamie Hannafordb280dea2014-10-24 15:14:06 +020032 // Required.
Ash Wilsonb8401a72014-09-08 17:07:49 -040033 Type string
34
Jamie Hannafordb280dea2014-10-24 15:14:06 +020035 // Name is the service name for the client (e.g., "nova") as it appears in
36 // the service catalog. Services can have the same Type but a different Name,
37 // which is why both Type and Name are sometimes needed. Optional.
Ash Wilsonb8401a72014-09-08 17:07:49 -040038 Name string
39
Jamie Hannafordb280dea2014-10-24 15:14:06 +020040 // Region is the geographic region in which the service resides. Required only
41 // for services that span multiple regions.
Ash Wilsonb8401a72014-09-08 17:07:49 -040042 Region string
43
Jamie Hannafordb280dea2014-10-24 15:14:06 +020044 // Availability is the visibility of the endpoint to be returned. Valid types
45 // are: AvailabilityPublic, AvailabilityInternal, or AvailabilityAdmin.
Ash Wilsonf1bfb902014-09-10 16:35:08 -040046 // Availability is not required, and defaults to AvailabilityPublic.
Ash Wilsonefac18b2014-09-10 14:44:42 -040047 // Not all providers or services offer all Availability options.
48 Availability Availability
Ash Wilsonb8401a72014-09-08 17:07:49 -040049}
50
Jamie Hannafordb280dea2014-10-24 15:14:06 +020051// EndpointLocator is a function that describes how to locate a single endpoint
52// from a service catalog for a specific ProviderClient. It should be set
53// during ProviderClient authentication and used to discover related ServiceClients.
Ash Wilsonb8401a72014-09-08 17:07:49 -040054type EndpointLocator func(EndpointOpts) (string, error)
Jon Perritt509fbb62014-09-10 13:29:56 -050055
Jamie Hannafordb280dea2014-10-24 15:14:06 +020056// ApplyDefaults sets EndpointOpts fields if not already set. Currently,
57// EndpointOpts.Availability defaults to the public endpoint.
Jon Perritt509fbb62014-09-10 13:29:56 -050058func (eo *EndpointOpts) ApplyDefaults(t string) {
59 if eo.Type == "" {
60 eo.Type = t
61 }
62 if eo.Availability == "" {
63 eo.Availability = AvailabilityPublic
64 }
65}