Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 9793d94

Browse files
author
Jamie Hannaford
committed
Adding documentation
1 parent 4a17028 commit 9793d94

File tree

13 files changed

+108
-48
lines changed

13 files changed

+108
-48
lines changed

openstack/db/v1/databases/doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
// Package flavors provides information and interaction with the database API
2+
// resource in the OpenStack Database service.
3+
//
4+
// A database, when referred to here, refers to the database engine running on
5+
// an instance.
16
package databases

openstack/db/v1/databases/requests.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,36 @@ import (
77
"github.com/rackspace/gophercloud/pagination"
88
)
99

10+
// CreateOptsBuilder builds create options
1011
type CreateOptsBuilder interface {
1112
ToDBCreateMap() (map[string]interface{}, error)
1213
}
1314

1415
// DatabaseOpts is the struct responsible for configuring a database; often in
1516
// the context of an instance.
1617
type CreateOpts struct {
17-
// Specifies the name of the database. Optional.
18+
// [REQUIRED] Specifies the name of the database. Valid names can be composed
19+
// of the following characters: letters (either case); numbers; these
20+
// characters '@', '?', '#', ' ' but NEVER beginning a name string; '_' is
21+
// permitted anywhere. Prohibited characters that are forbidden include:
22+
// single quotes, double quotes, back quotes, semicolons, commas, backslashes,
23+
// and forward slashes.
1824
Name string
1925

20-
// Set of symbols and encodings. Optional; the default character set is utf8.
26+
// [OPTIONAL] Set of symbols and encodings. The default character set is
27+
// "utf8". See http://dev.mysql.com/doc/refman/5.1/en/charset-mysql.html for
28+
// supported character sets.
2129
CharSet string
2230

23-
// Set of rules for comparing characters in a character set. Optional; the
24-
// default value for collate is utf8_general_ci.
31+
// [OPTIONAL] Set of rules for comparing characters in a character set. The
32+
// default value for collate is "utf8_general_ci". See
33+
// http://dev.mysql.com/doc/refman/5.1/en/charset-mysql.html for supported
34+
// collations.
2535
Collate string
2636
}
2737

38+
// ToMap is a helper function to convert individual DB create opt structures
39+
// into sub-maps.
2840
func (opts CreateOpts) ToMap() (map[string]string, error) {
2941
if opts.Name == "" {
3042
return nil, fmt.Errorf("Name is a required field")
@@ -44,8 +56,10 @@ func (opts CreateOpts) ToMap() (map[string]string, error) {
4456
return db, nil
4557
}
4658

59+
// BatchCreateOpts allows for multiple databases to created and modified.
4760
type BatchCreateOpts []CreateOpts
4861

62+
// ToDBCreateMap renders a JSON map for creating DBs.
4963
func (opts BatchCreateOpts) ToDBCreateMap() (map[string]interface{}, error) {
5064
var dbs []map[string]string
5165
for _, db := range opts {
@@ -58,6 +72,8 @@ func (opts BatchCreateOpts) ToDBCreateMap() (map[string]interface{}, error) {
5872
return map[string]interface{}{"databases": dbs}, nil
5973
}
6074

75+
// Create will create a new database within the specified instance. If the
76+
// specified instance does not exist, a 404 error will be returned.
6177
func Create(client *gophercloud.ServiceClient, instanceID string, opts CreateOptsBuilder) CreateResult {
6278
var res CreateResult
6379

@@ -76,6 +92,9 @@ func Create(client *gophercloud.ServiceClient, instanceID string, opts CreateOpt
7692
return res
7793
}
7894

95+
// List will list all of the databases for a specified instance. Note: this
96+
// operation will only return user-defined databases; it will exclude system
97+
// databases like "mysql", "information_schema", "lost+found" etc.
7998
func List(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
8099
createPageFn := func(r pagination.PageResult) pagination.Page {
81100
return DBPage{pagination.LinkedPageBase{PageResult: r}}
@@ -84,6 +103,8 @@ func List(client *gophercloud.ServiceClient, instanceID string) pagination.Pager
84103
return pagination.NewPager(client, baseURL(client, instanceID), createPageFn)
85104
}
86105

106+
// Delete will permanently delete the database within a specified instance.
107+
// All contained data inside the database will also be permanently deleted.
87108
func Delete(client *gophercloud.ServiceClient, instanceID, dbName string) DeleteResult {
88109
var res DeleteResult
89110

openstack/db/v1/databases/results.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"github.com/rackspace/gophercloud/pagination"
77
)
88

9+
// Database represents a Database API resource.
910
type Database struct {
10-
// Specifies the name of the MySQL DB.
11+
// Specifies the name of the MySQL database.
1112
Name string
1213

1314
// Set of symbols and encodings. The default character set is utf8.
@@ -18,10 +19,16 @@ type Database struct {
1819
Collate string
1920
}
2021

22+
// CreateResult represents the result of a Create operation.
2123
type CreateResult struct {
2224
gophercloud.Result
2325
}
2426

27+
// DeleteResult represents the result of a Delete operation.
28+
type DeleteResult struct {
29+
gophercloud.ErrResult
30+
}
31+
2532
// DBPage represents a single page of a paginated DB collection.
2633
type DBPage struct {
2734
pagination.LinkedPageBase
@@ -63,7 +70,3 @@ func ExtractDBs(page pagination.Page) ([]Database, error) {
6370
err := mapstructure.Decode(casted, &response)
6471
return response.Databases, err
6572
}
66-
67-
type DeleteResult struct {
68-
gophercloud.ErrResult
69-
}

openstack/db/v1/flavors/doc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Package flavors provides information and interaction with the flavor API
2-
// resource in the OpenStack Compute service.
2+
// resource in the OpenStack Database service.
33
//
4-
// A flavor is an available hardware configuration for a server. Each flavor
5-
// has a unique combination of disk space, memory capacity and priority for CPU
6-
// time.
4+
// A flavor is an available hardware configuration for a database instance.
5+
// Each flavor has a unique combination of disk space, memory capacity and
6+
// priority for CPU time.
77
package flavors

openstack/db/v1/flavors/fixtures.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const flavor = `
2626
`
2727

2828
var (
29-
flavorID = "{flavorID}"
29+
flavorID = 1
3030
_baseURL = "/flavors"
3131
resURL = "/flavors/" + flavorID
3232
)

openstack/db/v1/flavors/requests.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"github.com/rackspace/gophercloud/pagination"
66
)
77

8+
// List will list all available hardware flavors that an instance can use. The
9+
// operation is identical to the one supported by the Nova API, but without the
10+
// "disk" property.
811
func List(client *gophercloud.ServiceClient) pagination.Pager {
912
createPage := func(r pagination.PageResult) pagination.Page {
1013
return FlavorPage{pagination.LinkedPageBase{PageResult: r}}
@@ -13,7 +16,8 @@ func List(client *gophercloud.ServiceClient) pagination.Pager {
1316
return pagination.NewPager(client, listURL(client), createPage)
1417
}
1518

16-
func Get(client *gophercloud.ServiceClient, id string) GetResult {
19+
// Get will retrieve information for a specified hardware flavor.
20+
func Get(client *gophercloud.ServiceClient, id int) GetResult {
1721
var gr GetResult
1822

1923
_, gr.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{

openstack/db/v1/flavors/results.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package flavors
22

33
import (
4-
"errors"
5-
64
"github.com/mitchellh/mapstructure"
75
"github.com/rackspace/gophercloud"
86
"github.com/rackspace/gophercloud/pagination"
97
)
108

11-
// ErrCannotInterpret is returned by an Extract call if the response body doesn't have the expected structure.
12-
var ErrCannotInterpet = errors.New("Unable to interpret a response body.")
13-
149
// GetResult temporarily holds the response from a Get call.
1510
type GetResult struct {
1611
gophercloud.Result
@@ -32,15 +27,16 @@ func (gr GetResult) Extract() (*Flavor, error) {
3227

3328
// Flavor records represent (virtual) hardware configurations for server resources in a region.
3429
type Flavor struct {
35-
// The Id field contains the flavor's unique identifier.
36-
// For example, this identifier will be useful when specifying which hardware configuration to use for a new server instance.
30+
// The flavor's unique identifier.
3731
ID int `mapstructure:"id"`
3832

33+
// The RAM capacity for the flavor.
3934
RAM int `mapstructure:"ram"`
4035

4136
// The Name field provides a human-readable moniker for the flavor.
4237
Name string `mapstructure:"name"`
4338

39+
// Links to access the flavor.
4440
Links []gophercloud.Link
4541
}
4642

openstack/db/v1/instances/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
// Package instances provides information and interaction with the instance API
2+
// resource in the OpenStack Database service.
3+
//
4+
// A database instance is an isolated database environment with compute and
5+
// storage resources in a single tenant environment on a shared physical host
6+
// machine.
17
package instances

openstack/db/v1/instances/requests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type CreateOpts struct {
3535
Users users.BatchCreateOpts
3636
}
3737

38+
// ToInstanceCreateMap will render a JSON map.
3839
func (opts CreateOpts) ToInstanceCreateMap() (map[string]interface{}, error) {
3940
if opts.Size > 300 || opts.Size < 1 {
4041
return nil, fmt.Errorf("Size (GB) must be between 1-300")

openstack/db/v1/instances/results.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,11 @@ package instances
33
import (
44
"github.com/mitchellh/mapstructure"
55
"github.com/rackspace/gophercloud"
6+
"github.com/rackspace/gophercloud/openstack/db/v1/flavors"
67
"github.com/rackspace/gophercloud/openstack/db/v1/users"
78
"github.com/rackspace/gophercloud/pagination"
89
)
910

10-
// Flavor represents information about a hardware flavor for a database instance.
11-
type Flavor struct {
12-
// The unique identifier for a flavor.
13-
ID string
14-
15-
// Various links which allow a user to reference the flavor.
16-
Links []gophercloud.Link
17-
}
18-
1911
// Volume represents information about an attached volume for a database instance.
2012
type Volume struct {
2113
// The size in GB of the volume
@@ -33,7 +25,7 @@ type Instance struct {
3325
Updated string //time.Time
3426

3527
// Indicates the hardware flavor the instance uses.
36-
Flavor Flavor
28+
Flavor flavors.Flavor
3729

3830
// A DNS-resolvable hostname associated with the database instance (rather
3931
// than an IPv4 address). Since the hostname always resolves to the correct

0 commit comments

Comments
 (0)