openstack_sd: Supporting application credential for authentication. (#4968)
* openstack_sd: Support application credentials for authentication. Updated gophercloud Signed-off-by: Kevin Bulebush <kmbulebu@gmail.com>pull/5089/head
parent
b8ede99767
commit
718344434c
@ -1 +1,3 @@ |
||||
**/*.swp |
||||
.idea |
||||
.vscode |
||||
|
||||
@ -0,0 +1,98 @@ |
||||
- job: |
||||
name: gophercloud-unittest |
||||
parent: golang-test |
||||
description: | |
||||
Run gophercloud unit test |
||||
run: .zuul/playbooks/gophercloud-unittest/run.yaml |
||||
nodeset: ubuntu-xenial-ut |
||||
|
||||
- job: |
||||
name: gophercloud-acceptance-test |
||||
parent: golang-test |
||||
description: | |
||||
Run gophercloud acceptance test on master branch |
||||
run: .zuul/playbooks/gophercloud-acceptance-test/run.yaml |
||||
|
||||
- job: |
||||
name: gophercloud-acceptance-test-queens |
||||
parent: gophercloud-acceptance-test |
||||
description: | |
||||
Run gophercloud acceptance test on queens branch |
||||
vars: |
||||
global_env: |
||||
OS_BRANCH: stable/queens |
||||
|
||||
- job: |
||||
name: gophercloud-acceptance-test-rocky |
||||
parent: gophercloud-acceptance-test |
||||
description: | |
||||
Run gophercloud acceptance test on rocky branch |
||||
vars: |
||||
global_env: |
||||
OS_BRANCH: stable/rocky |
||||
|
||||
- job: |
||||
name: gophercloud-acceptance-test-pike |
||||
parent: gophercloud-acceptance-test |
||||
description: | |
||||
Run gophercloud acceptance test on pike branch |
||||
vars: |
||||
global_env: |
||||
OS_BRANCH: stable/pike |
||||
|
||||
- job: |
||||
name: gophercloud-acceptance-test-ocata |
||||
parent: gophercloud-acceptance-test |
||||
description: | |
||||
Run gophercloud acceptance test on ocata branch |
||||
vars: |
||||
global_env: |
||||
OS_BRANCH: stable/ocata |
||||
|
||||
- job: |
||||
name: gophercloud-acceptance-test-newton |
||||
parent: gophercloud-acceptance-test |
||||
description: | |
||||
Run gophercloud acceptance test on newton branch |
||||
vars: |
||||
global_env: |
||||
OS_BRANCH: stable/newton |
||||
|
||||
- job: |
||||
name: gophercloud-acceptance-test-mitaka |
||||
parent: gophercloud-acceptance-test |
||||
description: | |
||||
Run gophercloud acceptance test on mitaka branch |
||||
vars: |
||||
global_env: |
||||
OS_BRANCH: stable/mitaka |
||||
nodeset: ubuntu-trusty |
||||
|
||||
- project: |
||||
name: gophercloud/gophercloud |
||||
check: |
||||
jobs: |
||||
- gophercloud-unittest |
||||
- gophercloud-acceptance-test |
||||
recheck-mitaka: |
||||
jobs: |
||||
- gophercloud-acceptance-test-mitaka |
||||
recheck-newton: |
||||
jobs: |
||||
- gophercloud-acceptance-test-newton |
||||
recheck-ocata: |
||||
jobs: |
||||
- gophercloud-acceptance-test-ocata |
||||
recheck-pike: |
||||
jobs: |
||||
- gophercloud-acceptance-test-pike |
||||
recheck-queens: |
||||
jobs: |
||||
- gophercloud-acceptance-test-queens |
||||
recheck-rocky: |
||||
jobs: |
||||
- gophercloud-acceptance-test-rocky |
||||
periodic: |
||||
jobs: |
||||
- gophercloud-unittest |
||||
- gophercloud-acceptance-test |
||||
@ -1,148 +0,0 @@ |
||||
# Tips |
||||
|
||||
## Implementing default logging and re-authentication attempts |
||||
|
||||
You can implement custom logging and/or limit re-auth attempts by creating a custom HTTP client |
||||
like the following and setting it as the provider client's HTTP Client (via the |
||||
`gophercloud.ProviderClient.HTTPClient` field): |
||||
|
||||
```go |
||||
//... |
||||
|
||||
// LogRoundTripper satisfies the http.RoundTripper interface and is used to |
||||
// customize the default Gophercloud RoundTripper to allow for logging. |
||||
type LogRoundTripper struct { |
||||
rt http.RoundTripper |
||||
numReauthAttempts int |
||||
} |
||||
|
||||
// newHTTPClient return a custom HTTP client that allows for logging relevant |
||||
// information before and after the HTTP request. |
||||
func newHTTPClient() http.Client { |
||||
return http.Client{ |
||||
Transport: &LogRoundTripper{ |
||||
rt: http.DefaultTransport, |
||||
}, |
||||
} |
||||
} |
||||
|
||||
// RoundTrip performs a round-trip HTTP request and logs relevant information about it. |
||||
func (lrt *LogRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) { |
||||
glog.Infof("Request URL: %s\n", request.URL) |
||||
|
||||
response, err := lrt.rt.RoundTrip(request) |
||||
if response == nil { |
||||
return nil, err |
||||
} |
||||
|
||||
if response.StatusCode == http.StatusUnauthorized { |
||||
if lrt.numReauthAttempts == 3 { |
||||
return response, fmt.Errorf("Tried to re-authenticate 3 times with no success.") |
||||
} |
||||
lrt.numReauthAttempts++ |
||||
} |
||||
|
||||
glog.Debugf("Response Status: %s\n", response.Status) |
||||
|
||||
return response, nil |
||||
} |
||||
|
||||
endpoint := "https://127.0.0.1/auth" |
||||
pc := openstack.NewClient(endpoint) |
||||
pc.HTTPClient = newHTTPClient() |
||||
|
||||
//... |
||||
``` |
||||
|
||||
|
||||
## Implementing custom objects |
||||
|
||||
OpenStack request/response objects may differ among variable names or types. |
||||
|
||||
### Custom request objects |
||||
|
||||
To pass custom options to a request, implement the desired `<ACTION>OptsBuilder` interface. For |
||||
example, to pass in |
||||
|
||||
```go |
||||
type MyCreateServerOpts struct { |
||||
Name string |
||||
Size int |
||||
} |
||||
``` |
||||
|
||||
to `servers.Create`, simply implement the `servers.CreateOptsBuilder` interface: |
||||
|
||||
```go |
||||
func (o MyCreateServeropts) ToServerCreateMap() (map[string]interface{}, error) { |
||||
return map[string]interface{}{ |
||||
"name": o.Name, |
||||
"size": o.Size, |
||||
}, nil |
||||
} |
||||
``` |
||||
|
||||
create an instance of your custom options object, and pass it to `servers.Create`: |
||||
|
||||
```go |
||||
// ... |
||||
myOpts := MyCreateServerOpts{ |
||||
Name: "s1", |
||||
Size: "100", |
||||
} |
||||
server, err := servers.Create(computeClient, myOpts).Extract() |
||||
// ... |
||||
``` |
||||
|
||||
### Custom response objects |
||||
|
||||
Some OpenStack services have extensions. Extensions that are supported in Gophercloud can be |
||||
combined to create a custom object: |
||||
|
||||
```go |
||||
// ... |
||||
type MyVolume struct { |
||||
volumes.Volume |
||||
tenantattr.VolumeExt |
||||
} |
||||
|
||||
var v struct { |
||||
MyVolume `json:"volume"` |
||||
} |
||||
|
||||
err := volumes.Get(client, volID).ExtractInto(&v) |
||||
// ... |
||||
``` |
||||
|
||||
## Overriding default `UnmarshalJSON` method |
||||
|
||||
For some response objects, a field may be a custom type or may be allowed to take on |
||||
different types. In these cases, overriding the default `UnmarshalJSON` method may be |
||||
necessary. To do this, declare the JSON `struct` field tag as "-" and create an `UnmarshalJSON` |
||||
method on the type: |
||||
|
||||
```go |
||||
// ... |
||||
type MyVolume struct { |
||||
ID string `json: "id"` |
||||
TimeCreated time.Time `json: "-"` |
||||
} |
||||
|
||||
func (r *MyVolume) UnmarshalJSON(b []byte) error { |
||||
type tmp MyVolume |
||||
var s struct { |
||||
tmp |
||||
TimeCreated gophercloud.JSONRFC3339MilliNoZ `json:"created_at"` |
||||
} |
||||
err := json.Unmarshal(b, &s) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
*r = Volume(s.tmp) |
||||
|
||||
r.TimeCreated = time.Time(s.CreatedAt) |
||||
|
||||
return err |
||||
} |
||||
// ... |
||||
``` |
||||
@ -1,32 +0,0 @@ |
||||
# Compute |
||||
|
||||
## Floating IPs |
||||
|
||||
* `github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingip` is now `github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips` |
||||
* `floatingips.Associate` and `floatingips.Disassociate` have been removed. |
||||
* `floatingips.DisassociateOpts` is now required to disassociate a Floating IP. |
||||
|
||||
## Security Groups |
||||
|
||||
* `secgroups.AddServerToGroup` is now `secgroups.AddServer`. |
||||
* `secgroups.RemoveServerFromGroup` is now `secgroups.RemoveServer`. |
||||
|
||||
## Servers |
||||
|
||||
* `servers.Reboot` now requires a `servers.RebootOpts` struct: |
||||
|
||||
```golang |
||||
rebootOpts := &servers.RebootOpts{ |
||||
Type: servers.SoftReboot, |
||||
} |
||||
res := servers.Reboot(client, server.ID, rebootOpts) |
||||
``` |
||||
|
||||
# Identity |
||||
|
||||
## V3 |
||||
|
||||
### Tokens |
||||
|
||||
* `Token.ExpiresAt` is now of type `gophercloud.JSONRFC3339Milli` instead of |
||||
`time.Time` |
||||
@ -1,74 +0,0 @@ |
||||
|
||||
## On Pull Requests |
||||
|
||||
- Before you start a PR there needs to be a Github issue and a discussion about it |
||||
on that issue with a core contributor, even if it's just a 'SGTM'. |
||||
|
||||
- A PR's description must reference the issue it closes with a `For <ISSUE NUMBER>` (e.g. For #293). |
||||
|
||||
- A PR's description must contain link(s) to the line(s) in the OpenStack |
||||
source code (on Github) that prove(s) the PR code to be valid. Links to documentation |
||||
are not good enough. The link(s) should be to a non-`master` branch. For example, |
||||
a pull request implementing the creation of a Neutron v2 subnet might put the |
||||
following link in the description: |
||||
|
||||
https://github.com/openstack/neutron/blob/stable/mitaka/neutron/api/v2/attributes.py#L749 |
||||
|
||||
From that link, a reviewer (or user) can verify the fields in the request/response |
||||
objects in the PR. |
||||
|
||||
- A PR that is in-progress should have `[wip]` in front of the PR's title. When |
||||
ready for review, remove the `[wip]` and ping a core contributor with an `@`. |
||||
|
||||
- Forcing PRs to be small can have the effect of users submitting PRs in a hierarchical chain, with |
||||
one depending on the next. If a PR depends on another one, it should have a [Pending #PRNUM] |
||||
prefix in the PR title. In addition, it will be the PR submitter's responsibility to remove the |
||||
[Pending #PRNUM] tag once the PR has been updated with the merged, dependent PR. That will |
||||
let reviewers know it is ready to review. |
||||
|
||||
- A PR should be small. Even if you intend on implementing an entire |
||||
service, a PR should only be one route of that service |
||||
(e.g. create server or get server, but not both). |
||||
|
||||
- Unless explicitly asked, do not squash commits in the middle of a review; only |
||||
append. It makes it difficult for the reviewer to see what's changed from one |
||||
review to the next. |
||||
|
||||
## On Code |
||||
|
||||
- In re design: follow as closely as is reasonable the code already in the library. |
||||
Most operations (e.g. create, delete) admit the same design. |
||||
|
||||
- Unit tests and acceptance (integration) tests must be written to cover each PR. |
||||
Tests for operations with several options (e.g. list, create) should include all |
||||
the options in the tests. This will allow users to verify an operation on their |
||||
own infrastructure and see an example of usage. |
||||
|
||||
- If in doubt, ask in-line on the PR. |
||||
|
||||
### File Structure |
||||
|
||||
- The following should be used in most cases: |
||||
|
||||
- `requests.go`: contains all the functions that make HTTP requests and the |
||||
types associated with the HTTP request (parameters for URL, body, etc) |
||||
- `results.go`: contains all the response objects and their methods |
||||
- `urls.go`: contains the endpoints to which the requests are made |
||||
|
||||
### Naming |
||||
|
||||
- For methods on a type in `results.go`, the receiver should be named `r` and the |
||||
variable into which it will be unmarshalled `s`. |
||||
|
||||
- Functions in `requests.go`, with the exception of functions that return a |
||||
`pagination.Pager`, should be named returns of the name `r`. |
||||
|
||||
- Functions in `requests.go` that accept request bodies should accept as their |
||||
last parameter an `interface` named `<Action>OptsBuilder` (eg `CreateOptsBuilder`). |
||||
This `interface` should have at the least a method named `To<Resource><Action>Map` |
||||
(eg `ToPortCreateMap`). |
||||
|
||||
- Functions in `requests.go` that accept query strings should accept as their |
||||
last parameter an `interface` named `<Action>OptsBuilder` (eg `ListOptsBuilder`). |
||||
This `interface` should have at the least a method named `To<Resource><Action>Query` |
||||
(eg `ToServerListQuery`). |
||||
@ -1,3 +1,68 @@ |
||||
// Package floatingips provides the ability to manage floating ips through
|
||||
// nova-network
|
||||
/* |
||||
Package floatingips provides the ability to manage floating ips through the |
||||
Nova API. |
||||
|
||||
This API has been deprecated and will be removed from a future release of the |
||||
Nova API service. |
||||
|
||||
For environements that support this extension, this package can be used |
||||
regardless of if either Neutron or nova-network is used as the cloud's network |
||||
service. |
||||
|
||||
Example to List Floating IPs |
||||
|
||||
allPages, err := floatingips.List(computeClient).AllPages() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
allFloatingIPs, err := floatingips.ExtractFloatingIPs(allPages) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
for _, fip := range allFloatingIPs { |
||||
fmt.Printf("%+v\n", fip) |
||||
} |
||||
|
||||
Example to Create a Floating IP |
||||
|
||||
createOpts := floatingips.CreateOpts{ |
||||
Pool: "nova", |
||||
} |
||||
|
||||
fip, err := floatingips.Create(computeClient, createOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Delete a Floating IP |
||||
|
||||
err := floatingips.Delete(computeClient, "floatingip-id").ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Associate a Floating IP With a Server |
||||
|
||||
associateOpts := floatingips.AssociateOpts{ |
||||
FloatingIP: "10.10.10.2", |
||||
} |
||||
|
||||
err := floatingips.AssociateInstance(computeClient, "server-id", associateOpts).ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Disassociate a Floating IP From a Server |
||||
|
||||
disassociateOpts := floatingips.DisassociateOpts{ |
||||
FloatingIP: "10.10.10.2", |
||||
} |
||||
|
||||
err := floatingips.DisassociateInstance(computeClient, "server-id", disassociateOpts).ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
*/ |
||||
package floatingips |
||||
|
||||
@ -1,3 +1,51 @@ |
||||
// Package hypervisors gives information and control of the os-hypervisors
|
||||
// portion of the compute API
|
||||
/* |
||||
Package hypervisors returns details about list of hypervisors, shows details for a hypervisor |
||||
and shows summary statistics for all hypervisors over all compute nodes in the OpenStack cloud. |
||||
|
||||
Example of Show Hypervisor Details |
||||
|
||||
hypervisorID := 42 |
||||
hypervisor, err := hypervisors.Get(computeClient, 42).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
fmt.Printf("%+v\n", hypervisor) |
||||
|
||||
Example of Retrieving Details of All Hypervisors |
||||
|
||||
allPages, err := hypervisors.List(computeClient).AllPages() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
allHypervisors, err := hypervisors.ExtractHypervisors(allPages) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
for _, hypervisor := range allHypervisors { |
||||
fmt.Printf("%+v\n", hypervisor) |
||||
} |
||||
|
||||
Example of Show Hypervisor Statistics |
||||
|
||||
hypervisorsStatistics, err := hypervisors.GetStatistics(computeClient).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
fmt.Printf("%+v\n", hypervisorsStatistics) |
||||
|
||||
Example of Show Hypervisor Uptime |
||||
|
||||
hypervisorID := 42 |
||||
hypervisorUptime, err := hypervisors.GetUptime(computeClient, hypervisorID).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
fmt.Printf("%+v\n", hypervisorUptime) |
||||
|
||||
*/ |
||||
package hypervisors |
||||
|
||||
142
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/doc.go
generated
vendored
142
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/doc.go
generated
vendored
@ -1,7 +1,137 @@ |
||||
// Package flavors provides information and interaction with the flavor API
|
||||
// resource in the OpenStack Compute service.
|
||||
//
|
||||
// A flavor is an available hardware configuration for a server. Each flavor
|
||||
// has a unique combination of disk space, memory capacity and priority for CPU
|
||||
// time.
|
||||
/* |
||||
Package flavors provides information and interaction with the flavor API |
||||
in the OpenStack Compute service. |
||||
|
||||
A flavor is an available hardware configuration for a server. Each flavor |
||||
has a unique combination of disk space, memory capacity and priority for CPU |
||||
time. |
||||
|
||||
Example to List Flavors |
||||
|
||||
listOpts := flavors.ListOpts{ |
||||
AccessType: flavors.PublicAccess, |
||||
} |
||||
|
||||
allPages, err := flavors.ListDetail(computeClient, listOpts).AllPages() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
allFlavors, err := flavors.ExtractFlavors(allPages) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
for _, flavor := range allFlavors { |
||||
fmt.Printf("%+v\n", flavor) |
||||
} |
||||
|
||||
Example to Create a Flavor |
||||
|
||||
createOpts := flavors.CreateOpts{ |
||||
ID: "1", |
||||
Name: "m1.tiny", |
||||
Disk: gophercloud.IntToPointer(1), |
||||
RAM: 512, |
||||
VCPUs: 1, |
||||
RxTxFactor: 1.0, |
||||
} |
||||
|
||||
flavor, err := flavors.Create(computeClient, createOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to List Flavor Access |
||||
|
||||
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" |
||||
|
||||
allPages, err := flavors.ListAccesses(computeClient, flavorID).AllPages() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
allAccesses, err := flavors.ExtractAccesses(allPages) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
for _, access := range allAccesses { |
||||
fmt.Printf("%+v", access) |
||||
} |
||||
|
||||
Example to Grant Access to a Flavor |
||||
|
||||
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" |
||||
|
||||
accessOpts := flavors.AddAccessOpts{ |
||||
Tenant: "15153a0979884b59b0592248ef947921", |
||||
} |
||||
|
||||
accessList, err := flavors.AddAccess(computeClient, flavor.ID, accessOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Remove/Revoke Access to a Flavor |
||||
|
||||
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" |
||||
|
||||
accessOpts := flavors.RemoveAccessOpts{ |
||||
Tenant: "15153a0979884b59b0592248ef947921", |
||||
} |
||||
|
||||
accessList, err := flavors.RemoveAccess(computeClient, flavor.ID, accessOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Create Extra Specs for a Flavor |
||||
|
||||
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" |
||||
|
||||
createOpts := flavors.ExtraSpecsOpts{ |
||||
"hw:cpu_policy": "CPU-POLICY", |
||||
"hw:cpu_thread_policy": "CPU-THREAD-POLICY", |
||||
} |
||||
createdExtraSpecs, err := flavors.CreateExtraSpecs(computeClient, flavorID, createOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
fmt.Printf("%+v", createdExtraSpecs) |
||||
|
||||
Example to Get Extra Specs for a Flavor |
||||
|
||||
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" |
||||
|
||||
extraSpecs, err := flavors.ListExtraSpecs(computeClient, flavorID).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
fmt.Printf("%+v", extraSpecs) |
||||
|
||||
Example to Update Extra Specs for a Flavor |
||||
|
||||
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" |
||||
|
||||
updateOpts := flavors.ExtraSpecsOpts{ |
||||
"hw:cpu_thread_policy": "CPU-THREAD-POLICY-UPDATED", |
||||
} |
||||
updatedExtraSpec, err := flavors.UpdateExtraSpec(computeClient, flavorID, updateOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
fmt.Printf("%+v", updatedExtraSpec) |
||||
|
||||
Example to Delete an Extra Spec for a Flavor |
||||
|
||||
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" |
||||
err := flavors.DeleteExtraSpec(computeClient, flavorID, "hw:cpu_thread_policy").ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
*/ |
||||
package flavors |
||||
|
||||
276
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/requests.go
generated
vendored
276
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/requests.go
generated
vendored
171
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/results.go
generated
vendored
171
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/results.go
generated
vendored
32
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/urls.go
generated
vendored
32
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/urls.go
generated
vendored
@ -1,7 +1,32 @@ |
||||
// Package images provides information and interaction with the image API
|
||||
// resource in the OpenStack Compute service.
|
||||
//
|
||||
// An image is a collection of files used to create or rebuild a server.
|
||||
// Operators provide a number of pre-built OS images by default. You may also
|
||||
// create custom images from cloud servers you have launched.
|
||||
/* |
||||
Package images provides information and interaction with the images through |
||||
the OpenStack Compute service. |
||||
|
||||
This API is deprecated and will be removed from a future version of the Nova |
||||
API service. |
||||
|
||||
An image is a collection of files used to create or rebuild a server. |
||||
Operators provide a number of pre-built OS images by default. You may also |
||||
create custom images from cloud servers you have launched. |
||||
|
||||
Example to List Images |
||||
|
||||
listOpts := images.ListOpts{ |
||||
Limit: 2, |
||||
} |
||||
|
||||
allPages, err := images.ListDetail(computeClient, listOpts).AllPages() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
allImages, err := images.ExtractImages(allPages) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
for _, image := range allImages { |
||||
fmt.Printf("%+v\n", image) |
||||
} |
||||
*/ |
||||
package images |
||||
|
||||
31
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/images/requests.go
generated
vendored
31
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/images/requests.go
generated
vendored
40
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/images/results.go
generated
vendored
40
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/images/results.go
generated
vendored
119
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/doc.go
generated
vendored
119
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/doc.go
generated
vendored
@ -1,6 +1,115 @@ |
||||
// Package servers provides information and interaction with the server API
|
||||
// resource in the OpenStack Compute service.
|
||||
//
|
||||
// A server is a virtual machine instance in the compute system. In order for
|
||||
// one to be provisioned, a valid flavor and image are required.
|
||||
/* |
||||
Package servers provides information and interaction with the server API |
||||
resource in the OpenStack Compute service. |
||||
|
||||
A server is a virtual machine instance in the compute system. In order for |
||||
one to be provisioned, a valid flavor and image are required. |
||||
|
||||
Example to List Servers |
||||
|
||||
listOpts := servers.ListOpts{ |
||||
AllTenants: true, |
||||
} |
||||
|
||||
allPages, err := servers.List(computeClient, listOpts).AllPages() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
allServers, err := servers.ExtractServers(allPages) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
for _, server := range allServers { |
||||
fmt.Printf("%+v\n", server) |
||||
} |
||||
|
||||
Example to Create a Server |
||||
|
||||
createOpts := servers.CreateOpts{ |
||||
Name: "server_name", |
||||
ImageRef: "image-uuid", |
||||
FlavorRef: "flavor-uuid", |
||||
} |
||||
|
||||
server, err := servers.Create(computeClient, createOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Delete a Server |
||||
|
||||
serverID := "d9072956-1560-487c-97f2-18bdf65ec749" |
||||
err := servers.Delete(computeClient, serverID).ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Force Delete a Server |
||||
|
||||
serverID := "d9072956-1560-487c-97f2-18bdf65ec749" |
||||
err := servers.ForceDelete(computeClient, serverID).ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Reboot a Server |
||||
|
||||
rebootOpts := servers.RebootOpts{ |
||||
Type: servers.SoftReboot, |
||||
} |
||||
|
||||
serverID := "d9072956-1560-487c-97f2-18bdf65ec749" |
||||
|
||||
err := servers.Reboot(computeClient, serverID, rebootOpts).ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Rebuild a Server |
||||
|
||||
rebuildOpts := servers.RebuildOpts{ |
||||
Name: "new_name", |
||||
ImageID: "image-uuid", |
||||
} |
||||
|
||||
serverID := "d9072956-1560-487c-97f2-18bdf65ec749" |
||||
|
||||
server, err := servers.Rebuilt(computeClient, serverID, rebuildOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Resize a Server |
||||
|
||||
resizeOpts := servers.ResizeOpts{ |
||||
FlavorRef: "flavor-uuid", |
||||
} |
||||
|
||||
serverID := "d9072956-1560-487c-97f2-18bdf65ec749" |
||||
|
||||
err := servers.Resize(computeClient, serverID, resizeOpts).ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
err = servers.ConfirmResize(computeClient, serverID).ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Snapshot a Server |
||||
|
||||
snapshotOpts := servers.CreateImageOpts{ |
||||
Name: "snapshot_name", |
||||
} |
||||
|
||||
serverID := "d9072956-1560-487c-97f2-18bdf65ec749" |
||||
|
||||
image, err := servers.CreateImage(computeClient, serverID, snapshotOpts).ExtractImageID() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
*/ |
||||
package servers |
||||
|
||||
307
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go
generated
vendored
307
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go
generated
vendored
180
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/results.go
generated
vendored
180
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/results.go
generated
vendored
@ -0,0 +1,14 @@ |
||||
/* |
||||
Package openstack contains resources for the individual OpenStack projects |
||||
supported in Gophercloud. It also includes functions to authenticate to an |
||||
OpenStack cloud and for provisioning various service-level clients. |
||||
|
||||
Example of Creating a Service Client |
||||
|
||||
ao, err := openstack.AuthOptionsFromEnv() |
||||
provider, err := openstack.AuthenticatedClient(ao) |
||||
client, err := openstack.NewNetworkV2(client, gophercloud.EndpointOpts{ |
||||
Region: os.Getenv("OS_REGION_NAME"), |
||||
}) |
||||
*/ |
||||
package openstack |
||||
70
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/doc.go
generated
vendored
70
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/doc.go
generated
vendored
@ -1,7 +1,65 @@ |
||||
// Package tenants provides information and interaction with the
|
||||
// tenants API resource for the OpenStack Identity service.
|
||||
//
|
||||
// See http://developer.openstack.org/api-ref-identity-v2.html#identity-auth-v2
|
||||
// and http://developer.openstack.org/api-ref-identity-v2.html#admin-tenants
|
||||
// for more information.
|
||||
/* |
||||
Package tenants provides information and interaction with the |
||||
tenants API resource for the OpenStack Identity service. |
||||
|
||||
See http://developer.openstack.org/api-ref-identity-v2.html#identity-auth-v2
|
||||
and http://developer.openstack.org/api-ref-identity-v2.html#admin-tenants
|
||||
for more information. |
||||
|
||||
Example to List Tenants |
||||
|
||||
listOpts := tenants.ListOpts{ |
||||
Limit: 2, |
||||
} |
||||
|
||||
allPages, err := tenants.List(identityClient, listOpts).AllPages() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
allTenants, err := tenants.ExtractTenants(allPages) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
for _, tenant := range allTenants { |
||||
fmt.Printf("%+v\n", tenant) |
||||
} |
||||
|
||||
Example to Create a Tenant |
||||
|
||||
createOpts := tenants.CreateOpts{ |
||||
Name: "tenant_name", |
||||
Description: "this is a tenant", |
||||
Enabled: gophercloud.Enabled, |
||||
} |
||||
|
||||
tenant, err := tenants.Create(identityClient, createOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Update a Tenant |
||||
|
||||
tenantID := "e6db6ed6277c461a853458589063b295" |
||||
|
||||
updateOpts := tenants.UpdateOpts{ |
||||
Description: "this is a new description", |
||||
Enabled: gophercloud.Disabled, |
||||
} |
||||
|
||||
tenant, err := tenants.Update(identityClient, tenantID, updateOpts).Extract() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Delete a Tenant |
||||
|
||||
tenantID := "e6db6ed6277c461a853458589063b295" |
||||
|
||||
err := tenants.Delete(identitYClient, tenantID).ExtractErr() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
*/ |
||||
package tenants |
||||
|
||||
87
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/requests.go
generated
vendored
87
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/requests.go
generated
vendored
40
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/results.go
generated
vendored
40
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/results.go
generated
vendored
16
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/urls.go
generated
vendored
16
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/urls.go
generated
vendored
@ -1,5 +1,46 @@ |
||||
// Package tokens provides information and interaction with the token API
|
||||
// resource for the OpenStack Identity service.
|
||||
// For more information, see:
|
||||
// http://developer.openstack.org/api-ref-identity-v2.html#identity-auth-v2
|
||||
/* |
||||
Package tokens provides information and interaction with the token API |
||||
resource for the OpenStack Identity service. |
||||
|
||||
For more information, see: |
||||
http://developer.openstack.org/api-ref-identity-v2.html#identity-auth-v2
|
||||
|
||||
Example to Create an Unscoped Token from a Password |
||||
|
||||
authOpts := gophercloud.AuthOptions{ |
||||
Username: "user", |
||||
Password: "pass" |
||||
} |
||||
|
||||
token, err := tokens.Create(identityClient, authOpts).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Create a Token from a Tenant ID and Password |
||||
|
||||
authOpts := gophercloud.AuthOptions{ |
||||
Username: "user", |
||||
Password: "password", |
||||
TenantID: "fc394f2ab2df4114bde39905f800dc57" |
||||
} |
||||
|
||||
token, err := tokens.Create(identityClient, authOpts).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Create a Token from a Tenant Name and Password |
||||
|
||||
authOpts := gophercloud.AuthOptions{ |
||||
Username: "user", |
||||
Password: "password", |
||||
TenantName: "tenantname" |
||||
} |
||||
|
||||
token, err := tokens.Create(identityClient, authOpts).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
*/ |
||||
package tokens |
||||
|
||||
28
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tokens/requests.go
generated
vendored
28
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tokens/requests.go
generated
vendored
67
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tokens/results.go
generated
vendored
67
vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tokens/results.go
generated
vendored
112
vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/doc.go
generated
vendored
112
vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/doc.go
generated
vendored
@ -1,6 +1,108 @@ |
||||
// Package tokens provides information and interaction with the token API
|
||||
// resource for the OpenStack Identity service.
|
||||
//
|
||||
// For more information, see:
|
||||
// http://developer.openstack.org/api-ref-identity-v3.html#tokens-v3
|
||||
/* |
||||
Package tokens provides information and interaction with the token API |
||||
resource for the OpenStack Identity service. |
||||
|
||||
For more information, see: |
||||
http://developer.openstack.org/api-ref-identity-v3.html#tokens-v3
|
||||
|
||||
Example to Create a Token From a Username and Password |
||||
|
||||
authOptions := tokens.AuthOptions{ |
||||
UserID: "username", |
||||
Password: "password", |
||||
} |
||||
|
||||
token, err := tokens.Create(identityClient, authOptions).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Create a Token From a Username, Password, and Domain |
||||
|
||||
authOptions := tokens.AuthOptions{ |
||||
UserID: "username", |
||||
Password: "password", |
||||
DomainID: "default", |
||||
} |
||||
|
||||
token, err := tokens.Create(identityClient, authOptions).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
authOptions = tokens.AuthOptions{ |
||||
UserID: "username", |
||||
Password: "password", |
||||
DomainName: "default", |
||||
} |
||||
|
||||
token, err = tokens.Create(identityClient, authOptions).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Create a Token From a Token |
||||
|
||||
authOptions := tokens.AuthOptions{ |
||||
TokenID: "token_id", |
||||
} |
||||
|
||||
token, err := tokens.Create(identityClient, authOptions).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Create a Token from a Username and Password with Project ID Scope |
||||
|
||||
scope := tokens.Scope{ |
||||
ProjectID: "0fe36e73809d46aeae6705c39077b1b3", |
||||
} |
||||
|
||||
authOptions := tokens.AuthOptions{ |
||||
Scope: &scope, |
||||
UserID: "username", |
||||
Password: "password", |
||||
} |
||||
|
||||
token, err = tokens.Create(identityClient, authOptions).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Create a Token from a Username and Password with Domain ID Scope |
||||
|
||||
scope := tokens.Scope{ |
||||
DomainID: "default", |
||||
} |
||||
|
||||
authOptions := tokens.AuthOptions{ |
||||
Scope: &scope, |
||||
UserID: "username", |
||||
Password: "password", |
||||
} |
||||
|
||||
token, err = tokens.Create(identityClient, authOptions).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
Example to Create a Token from a Username and Password with Project Name Scope |
||||
|
||||
scope := tokens.Scope{ |
||||
ProjectName: "project_name", |
||||
DomainID: "default", |
||||
} |
||||
|
||||
authOptions := tokens.AuthOptions{ |
||||
Scope: &scope, |
||||
UserID: "username", |
||||
Password: "password", |
||||
} |
||||
|
||||
token, err = tokens.Create(identityClient, authOptions).ExtractToken() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
*/ |
||||
package tokens |
||||
|
||||
132
vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go
generated
vendored
132
vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go
generated
vendored
106
vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go
generated
vendored
106
vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go
generated
vendored
@ -0,0 +1,28 @@ |
||||
package utils |
||||
|
||||
import ( |
||||
"net/url" |
||||
"regexp" |
||||
"strings" |
||||
) |
||||
|
||||
// BaseEndpoint will return a URL without the /vX.Y
|
||||
// portion of the URL.
|
||||
func BaseEndpoint(endpoint string) (string, error) { |
||||
u, err := url.Parse(endpoint) |
||||
if err != nil { |
||||
return "", err |
||||
} |
||||
|
||||
u.RawQuery, u.Fragment = "", "" |
||||
|
||||
path := u.Path |
||||
versionRe := regexp.MustCompile("v[0-9.]+/?") |
||||
|
||||
if version := versionRe.FindString(path); version != "" { |
||||
versionIndex := strings.Index(path, version) |
||||
u.Path = path[:versionIndex] |
||||
} |
||||
|
||||
return u.String(), nil |
||||
} |
||||
Loading…
Reference in new issue