Finish DB docs for Rackspace
diff --git a/rackspace/db/v1/backups/doc.go b/rackspace/db/v1/backups/doc.go
index b000aa0..664eead 100644
--- a/rackspace/db/v1/backups/doc.go
+++ b/rackspace/db/v1/backups/doc.go
@@ -1 +1,6 @@
+// Package backups provides information and interaction with the backup API
+// resource in the Rackspace Database service.
+//
+// A backup is a copy of a database instance that can be used to restore it to
+// some defined point in history.
package backups
diff --git a/rackspace/db/v1/backups/requests.go b/rackspace/db/v1/backups/requests.go
index 9bcc25a..9170d78 100644
--- a/rackspace/db/v1/backups/requests.go
+++ b/rackspace/db/v1/backups/requests.go
@@ -7,18 +7,25 @@
"github.com/rackspace/gophercloud/pagination"
)
+// CreateOptsBuilder is the top-level interface for creating JSON maps.
type CreateOptsBuilder interface {
ToBackupCreateMap() (map[string]interface{}, error)
}
+// CreateOpts is responsible for configuring newly provisioned backups.
type CreateOpts struct {
+ // [REQUIRED] The name of the backup. The only restriction is the name must
+ // be less than 64 characters long.
Name string
+ // [REQUIRED] The ID of the instance being backed up.
InstanceID string
+ // [OPTIONAL] A human-readable explanation of the backup.
Description string
}
+// ToBackupCreateMap will create a JSON map for the Create operation.
func (opts CreateOpts) ToBackupCreateMap() (map[string]interface{}, error) {
if opts.Name == "" {
return nil, errors.New("Name is a required field")
@@ -39,6 +46,17 @@
return map[string]interface{}{"backup": backup}, nil
}
+// Create asynchronously creates a new backup for a specified database instance.
+// During the backup process, write access on MyISAM databases will be
+// temporarily disabled; innoDB databases will be unaffected. During this time,
+// you will not be able to add or delete databases or users; nor delete, stop
+// or reboot the instance itself. Only one backup is permitted at once.
+//
+// Backups are not deleted when database instances are deleted; you must
+// manually delete any backups created using Delete(). Backups are saved to your
+// Cloud Files account in a new container called z_CLOUDDB_BACKUPS. It is
+// strongly recommended you do not alter this container or its contents; usual
+// storage costs apply.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
var res CreateResult
@@ -57,14 +75,18 @@
return res
}
+// ListOptsBuilder is the top-level interface for creating query strings.
type ListOptsBuilder interface {
ToBackupListQuery() (string, error)
}
+// ListOpts allows you to refine a list search by certain parameters.
type ListOpts struct {
+ // The type of datastore by which to filter.
Datastore string `q:"datastore"`
}
+// ToBackupListQuery converts a ListOpts struct into a query string.
func (opts ListOpts) ToBackupListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
if err != nil {
@@ -73,6 +95,7 @@
return q.String(), nil
}
+// List will list all the saved backups for all database instances.
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := baseURL(client)
@@ -91,6 +114,7 @@
return pagination.NewPager(client, url, pageFn)
}
+// Get will retrieve details for a particular backup based on its unique ID.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
@@ -102,6 +126,7 @@
return res
}
+// Delete will permanently delete a backup.
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
var res DeleteResult
diff --git a/rackspace/db/v1/backups/results.go b/rackspace/db/v1/backups/results.go
index 402fc86..b6a5f17 100644
--- a/rackspace/db/v1/backups/results.go
+++ b/rackspace/db/v1/backups/results.go
@@ -7,6 +7,19 @@
"github.com/rackspace/gophercloud/rackspace/db/v1/datastores"
)
+// Status represents the various states a Backup can be in.
+type Status string
+
+// Enum types for the status.
+const (
+ StatusNew Status = "NEW"
+ StatusBuilding Status = "BUILDING"
+ StatusCompleted Status = "COMPLETED"
+ StatusFailed Status = "FAILED"
+ StatusDeleteFailed Status = "DELETE_FAILED"
+)
+
+// Backup represents a Backup API resource.
type Backup struct {
Description string
ID string
@@ -15,24 +28,32 @@
Name string
ParentID string `json:"parent_id" mapstructure:"parent_id"`
Size float64
- Status string
+ Status Status
Created string
Updated string
Datastore datastores.DatastorePartial
}
+// CreateResult represents the result of a create operation.
type CreateResult struct {
commonResult
}
+// GetResult represents the result of a get operation.
type GetResult struct {
commonResult
}
+// DeleteResult represents the result of a delete operation.
+type DeleteResult struct {
+ gophercloud.ErrResult
+}
+
type commonResult struct {
gophercloud.Result
}
+// Extract will retrieve a Backup struct from an operation's result.
func (r commonResult) Extract() (*Backup, error) {
if r.Err != nil {
return nil, r.Err
@@ -46,10 +67,7 @@
return &response.Backup, err
}
-type DeleteResult struct {
- gophercloud.ErrResult
-}
-
+// BackupPage represents a page of backups.
type BackupPage struct {
pagination.SinglePageBase
}
@@ -63,6 +81,7 @@
return len(is) == 0, nil
}
+// ExtractBackups will retrieve a slice of Backup structs from a paginated collection.
func ExtractBackups(page pagination.Page) ([]Backup, error) {
casted := page.(BackupPage).Body
diff --git a/rackspace/db/v1/configurations/doc.go b/rackspace/db/v1/configurations/doc.go
index 48c51d6..45b9cfb 100644
--- a/rackspace/db/v1/configurations/doc.go
+++ b/rackspace/db/v1/configurations/doc.go
@@ -1 +1,11 @@
+// Package configurations provides information and interaction with the
+// configuration API resource in the Rackspace Database service.
+//
+// A configuration group is a collection of key/value pairs which define how a
+// particular database operates. These key/value pairs are specific to each
+// datastore type and serve like settings. Some directives are capable of being
+// applied dynamically, while other directives require a server restart to take
+// effect. The configuration group can be applied to an instance at creation or
+// applied to an existing instance to modify the behavior of the running
+// datastore on the instance.
package configurations
diff --git a/rackspace/db/v1/configurations/requests.go b/rackspace/db/v1/configurations/requests.go
index 726176a..088b7ca 100644
--- a/rackspace/db/v1/configurations/requests.go
+++ b/rackspace/db/v1/configurations/requests.go
@@ -8,6 +8,7 @@
"github.com/rackspace/gophercloud/pagination"
)
+// List will list all of the available configurations.
func List(client *gophercloud.ServiceClient) pagination.Pager {
pageFn := func(r pagination.PageResult) pagination.Page {
return ConfigPage{pagination.SinglePageBase(r)}
@@ -16,15 +17,22 @@
return pagination.NewPager(client, baseURL(client), pageFn)
}
+// CreateOptsBuilder is a top-level interface which renders a JSON map.
type CreateOptsBuilder interface {
ToConfigCreateMap() (map[string]interface{}, error)
}
+// DatastoreOpts is the primary options struct for creating and modifying
+// how configuration resources are associated with datastores.
type DatastoreOpts struct {
- Type string
+ // [OPTIONAL] The type of datastore. Defaults to "MySQL".
+ Type string
+
+ // [OPTIONAL] The specific version of a datastore. Defaults to "5.6".
Version string
}
+// ToMap renders a JSON map for a datastore setting.
func (opts DatastoreOpts) ToMap() (map[string]string, error) {
datastore := map[string]string{}
@@ -39,13 +47,24 @@
return datastore, nil
}
+// CreateOpts is the struct responsible for configuring new configurations.
type CreateOpts struct {
- Datastore *DatastoreOpts
+ // [REQUIRED] The configuration group name
+ Name string
+
+ // [REQUIRED] A map of user-defined configuration settings that will define
+ // how each associated datastore works. Each key/value pair is specific to a
+ // datastore type.
+ Values map[string]interface{}
+
+ // [OPTIONAL] Associates the configuration group with a particular datastore.
+ Datastore *DatastoreOpts
+
+ // [OPTIONAL] A human-readable explanation for the group.
Description string
- Name string
- Values map[string]interface{}
}
+// ToConfigCreateMap casts a CreateOpts struct into a JSON map.
func (opts CreateOpts) ToConfigCreateMap() (map[string]interface{}, error) {
if opts.Name == "" {
return nil, errors.New("Name is a required field")
@@ -74,6 +93,7 @@
return map[string]interface{}{"configuration": config}, nil
}
+// Create will create a new configuration group.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
var res CreateResult
@@ -92,6 +112,7 @@
return res
}
+// Get will retrieve the details for a specified configuration group.
func Get(client *gophercloud.ServiceClient, configID string) GetResult {
var res GetResult
@@ -103,17 +124,30 @@
return res
}
+// UpdateOptsBuilder is the top-level interface for casting update options into
+// JSON maps.
type UpdateOptsBuilder interface {
ToConfigUpdateMap() (map[string]interface{}, error)
}
+// UpdateOpts is the struct responsible for modifying existing configurations.
type UpdateOpts struct {
- Datastore *DatastoreOpts
+ // [OPTIONAL] The configuration group name
+ Name string
+
+ // [OPTIONAL] A map of user-defined configuration settings that will define
+ // how each associated datastore works. Each key/value pair is specific to a
+ // datastore type.
+ Values map[string]interface{}
+
+ // [OPTIONAL] Associates the configuration group with a particular datastore.
+ Datastore *DatastoreOpts
+
+ // [OPTIONAL] A human-readable explanation for the group.
Description string
- Name string
- Values map[string]interface{}
}
+// ToConfigUpdateMap will cast an UpdateOpts struct into a JSON map.
func (opts UpdateOpts) ToConfigUpdateMap() (map[string]interface{}, error) {
config := map[string]interface{}{}
@@ -140,6 +174,9 @@
return map[string]interface{}{"configuration": config}, nil
}
+// Update will modify an existing configuration group by performing a merge
+// between new and existing values. If the key already exists, the new value
+// will overwrite. All other keys will remain unaffected.
func Update(client *gophercloud.ServiceClient, configID string, opts UpdateOptsBuilder) UpdateResult {
var res UpdateResult
@@ -158,6 +195,9 @@
return res
}
+// Replace will modify an existing configuration group by overwriting the
+// entire parameter group with the new values provided. Any existing keys not
+// included in UpdateOptsBuilder will be deleted.
func Replace(client *gophercloud.ServiceClient, configID string, opts UpdateOptsBuilder) ReplaceResult {
var res ReplaceResult
@@ -176,6 +216,7 @@
return res
}
+// Delete will permanently delete a configuration group.
func Delete(client *gophercloud.ServiceClient, configID string) DeleteResult {
var res DeleteResult
@@ -186,6 +227,8 @@
return res
}
+// ListInstances will list all the instances associated with a particular
+// configuration group.
func ListInstances(client *gophercloud.ServiceClient, configID string) pagination.Pager {
pageFn := func(r pagination.PageResult) pagination.Page {
return instances.InstancePage{pagination.LinkedPageBase{PageResult: r}}
@@ -193,6 +236,11 @@
return pagination.NewPager(client, instancesURL(client, configID), pageFn)
}
+// ListDatastoreParams will list all the available and supported parameters
+// that can be used for a particular datastore ID and a particular version.
+// For example, if you are wondering how you can configure a MySQL 5.6 instance,
+// you can use this operation (you will need to retrieve the MySQL datastore ID
+// by using the datastores API).
func ListDatastoreParams(client *gophercloud.ServiceClient, datastoreID, versionID string) pagination.Pager {
pageFn := func(r pagination.PageResult) pagination.Page {
return ParamPage{pagination.SinglePageBase(r)}
@@ -200,6 +248,11 @@
return pagination.NewPager(client, listDSParamsURL(client, datastoreID, versionID), pageFn)
}
+// GetDatastoreParam will retrieve information about a specific configuration
+// parameter. For example, you can use this operation to understand more about
+// "innodb_file_per_table" configuration param for MySQL datastores. You will
+// need the param's ID first, which can be attained by using the ListDatastoreParams
+// operation.
func GetDatastoreParam(client *gophercloud.ServiceClient, datastoreID, versionID, paramID string) ParamResult {
var res ParamResult
@@ -211,6 +264,8 @@
return res
}
+// ListGlobalParams is similar to ListDatastoreParams but does not require a
+// DatastoreID.
func ListGlobalParams(client *gophercloud.ServiceClient, versionID string) pagination.Pager {
pageFn := func(r pagination.PageResult) pagination.Page {
return ParamPage{pagination.SinglePageBase(r)}
@@ -218,6 +273,8 @@
return pagination.NewPager(client, listGlobalParamsURL(client, versionID), pageFn)
}
+// GetGlobalParam is similar to GetDatastoreParam but does not require a
+// DatastoreID.
func GetGlobalParam(client *gophercloud.ServiceClient, versionID, paramID string) ParamResult {
var res ParamResult
diff --git a/rackspace/db/v1/configurations/results.go b/rackspace/db/v1/configurations/results.go
index 5c960b8..98ce25f 100644
--- a/rackspace/db/v1/configurations/results.go
+++ b/rackspace/db/v1/configurations/results.go
@@ -6,6 +6,7 @@
"github.com/rackspace/gophercloud/pagination"
)
+// Config represents a configuration group API resource.
type Config struct {
Created string
Updated string
@@ -18,10 +19,12 @@
Values map[string]interface{}
}
+// ConfigPage contains a page of Config resources in a paginated collection.
type ConfigPage struct {
pagination.SinglePageBase
}
+// IsEmpty indicates whether a ConfigPage is empty.
func (r ConfigPage) IsEmpty() (bool, error) {
is, err := ExtractConfigs(r)
if err != nil {
@@ -30,6 +33,7 @@
return len(is) == 0, nil
}
+// ExtractConfigs will retrieve a slice of Config structs from a page.
func ExtractConfigs(page pagination.Page) ([]Config, error) {
casted := page.(ConfigPage).Body
@@ -45,6 +49,7 @@
gophercloud.Result
}
+// Extract will retrieve a Config resource from an operation result.
func (r commonResult) Extract() (*Config, error) {
if r.Err != nil {
return nil, r.Err
@@ -58,26 +63,32 @@
return &response.Config, err
}
+// GetResult represents the result of a Get operation.
type GetResult struct {
commonResult
}
+// CreateResult represents the result of a Create operation.
type CreateResult struct {
commonResult
}
+// UpdateResult represents the result of an Update operation.
type UpdateResult struct {
gophercloud.ErrResult
}
+// ReplaceResult represents the result of a Replace operation.
type ReplaceResult struct {
gophercloud.ErrResult
}
+// DeleteResult represents the result of a Delete operation.
type DeleteResult struct {
gophercloud.ErrResult
}
+// Param represents a configuration parameter API resource.
type Param struct {
Max int
Min int
@@ -86,10 +97,12 @@
Type string
}
+// ParamPage contains a page of Param resources in a paginated collection.
type ParamPage struct {
pagination.SinglePageBase
}
+// IsEmpty indicates whether a ParamPage is empty.
func (r ParamPage) IsEmpty() (bool, error) {
is, err := ExtractParams(r)
if err != nil {
@@ -98,6 +111,7 @@
return len(is) == 0, nil
}
+// ExtractParams will retrieve a slice of Param structs from a page.
func ExtractParams(page pagination.Page) ([]Param, error) {
casted := page.(ParamPage).Body
@@ -109,10 +123,13 @@
return resp.Params, err
}
+// ParamResult represents the result of an operation which retrieves details
+// about a particular configuration param.
type ParamResult struct {
gophercloud.Result
}
+// Extract will retrieve a param from an operation result.
func (r ParamResult) Extract() (*Param, error) {
if r.Err != nil {
return nil, r.Err
diff --git a/rackspace/db/v1/databases/doc.go b/rackspace/db/v1/databases/doc.go
index 18cbec7..1a178b6 100644
--- a/rackspace/db/v1/databases/doc.go
+++ b/rackspace/db/v1/databases/doc.go
@@ -1 +1,3 @@
+// Package databases provides information and interaction with the database API
+// resource in the Rackspace Database service.
package databases
diff --git a/rackspace/db/v1/datastores/doc.go b/rackspace/db/v1/datastores/doc.go
index f36997a..ae14026 100644
--- a/rackspace/db/v1/datastores/doc.go
+++ b/rackspace/db/v1/datastores/doc.go
@@ -1 +1,3 @@
+// Package datastores provides information and interaction with the datastore
+// API resource in the Rackspace Database service.
package datastores
diff --git a/rackspace/db/v1/datastores/requests.go b/rackspace/db/v1/datastores/requests.go
index 767bdc3..9e147ab 100644
--- a/rackspace/db/v1/datastores/requests.go
+++ b/rackspace/db/v1/datastores/requests.go
@@ -5,6 +5,7 @@
"github.com/rackspace/gophercloud/pagination"
)
+// List will list all available datastore types that instances can use.
func List(client *gophercloud.ServiceClient) pagination.Pager {
pageFn := func(r pagination.PageResult) pagination.Page {
return DatastorePage{pagination.SinglePageBase(r)}
@@ -12,6 +13,7 @@
return pagination.NewPager(client, baseURL(client), pageFn)
}
+// Get will retrieve the details of a specified datastore type.
func Get(client *gophercloud.ServiceClient, datastoreID string) GetResult {
var res GetResult
@@ -23,6 +25,8 @@
return res
}
+// ListVersions will list all of the available versions for a specified
+// datastore type.
func ListVersions(client *gophercloud.ServiceClient, datastoreID string) pagination.Pager {
pageFn := func(r pagination.PageResult) pagination.Page {
return VersionPage{pagination.SinglePageBase(r)}
@@ -30,6 +34,7 @@
return pagination.NewPager(client, versionsURL(client, datastoreID), pageFn)
}
+// GetVersion will retrieve the details of a specified datastore version.
func GetVersion(client *gophercloud.ServiceClient, datastoreID, versionID string) GetVersionResult {
var res GetVersionResult
diff --git a/rackspace/db/v1/datastores/results.go b/rackspace/db/v1/datastores/results.go
index 31fd838..a86a3cc 100644
--- a/rackspace/db/v1/datastores/results.go
+++ b/rackspace/db/v1/datastores/results.go
@@ -6,12 +6,14 @@
"github.com/rackspace/gophercloud/pagination"
)
+// Version represents a version API resource. Multiple versions belong to a Datastore.
type Version struct {
ID string
Links []gophercloud.Link
Name string
}
+// Datastore represents a Datastore API resource.
type Datastore struct {
DefaultVersion string `json:"default_version" mapstructure:"default_version"`
ID string
@@ -20,24 +22,31 @@
Versions []Version
}
+// DatastorePartial is a meta structure which is used in various API responses.
+// It is a lightweight and truncated version of a full Datastore resource,
+// offering details of the Version, Type and VersionID only.
type DatastorePartial struct {
Version string
Type string
VersionID string `json:"version_id" mapstructure:"version_id"`
}
+// GetResult represents the result of a Get operation.
type GetResult struct {
gophercloud.Result
}
+// GetVersionResult represents the result of getting a version.
type GetVersionResult struct {
gophercloud.Result
}
+// DatastorePage represents a page of datastore resources.
type DatastorePage struct {
pagination.SinglePageBase
}
+// IsEmpty indicates whether a Datastore collection is empty.
func (r DatastorePage) IsEmpty() (bool, error) {
is, err := ExtractDatastores(r)
if err != nil {
@@ -46,6 +55,8 @@
return len(is) == 0, nil
}
+// ExtractDatastores retrieves a slice of datastore structs from a paginated
+// collection.
func ExtractDatastores(page pagination.Page) ([]Datastore, error) {
casted := page.(DatastorePage).Body
@@ -57,6 +68,7 @@
return resp.Datastores, err
}
+// Extract retrieves a single Datastore struct from an operation result.
func (r GetResult) Extract() (*Datastore, error) {
if r.Err != nil {
return nil, r.Err
@@ -70,10 +82,12 @@
return &response.Datastore, err
}
+// DatastorePage represents a page of version resources.
type VersionPage struct {
pagination.SinglePageBase
}
+// IsEmpty indicates whether a collection of version resources is empty.
func (r VersionPage) IsEmpty() (bool, error) {
is, err := ExtractVersions(r)
if err != nil {
@@ -82,6 +96,7 @@
return len(is) == 0, nil
}
+// ExtractVersions retrieves a slice of versions from a paginated collection.
func ExtractVersions(page pagination.Page) ([]Version, error) {
casted := page.(VersionPage).Body
@@ -93,6 +108,7 @@
return resp.Versions, err
}
+// Extract retrieves a single Version struct from an operation result.
func (r GetVersionResult) Extract() (*Version, error) {
if r.Err != nil {
return nil, r.Err
diff --git a/rackspace/db/v1/flavors/delegate.go b/rackspace/db/v1/flavors/delegate.go
index 0d50f55..689b81e 100644
--- a/rackspace/db/v1/flavors/delegate.go
+++ b/rackspace/db/v1/flavors/delegate.go
@@ -6,10 +6,12 @@
"github.com/rackspace/gophercloud/pagination"
)
+// List will list all available flavors.
func List(client *gophercloud.ServiceClient) pagination.Pager {
return os.List(client)
}
+// Get retrieves the details for a particular flavor.
func Get(client *gophercloud.ServiceClient, flavorID string) os.GetResult {
return os.Get(client, flavorID)
}
diff --git a/rackspace/db/v1/flavors/doc.go b/rackspace/db/v1/flavors/doc.go
new file mode 100644
index 0000000..922a4e6
--- /dev/null
+++ b/rackspace/db/v1/flavors/doc.go
@@ -0,0 +1,3 @@
+// Package flavors provides information and interaction with the flavor API
+// resource in the Rackspace Database service.
+package flavors
diff --git a/rackspace/db/v1/instances/doc.go b/rackspace/db/v1/instances/doc.go
index 98a1bb3..0c8ad63 100644
--- a/rackspace/db/v1/instances/doc.go
+++ b/rackspace/db/v1/instances/doc.go
@@ -1 +1,3 @@
+// Package instances provides information and interaction with the instance API
+// resource in the Rackspace Database service.
package instances
diff --git a/rackspace/db/v1/instances/requests.go b/rackspace/db/v1/instances/requests.go
index cfebd5d..7a1a4f8 100644
--- a/rackspace/db/v1/instances/requests.go
+++ b/rackspace/db/v1/instances/requests.go
@@ -6,6 +6,10 @@
"github.com/rackspace/gophercloud/rackspace/db/v1/backups"
)
+// GetDefaultConfig lists the default configuration settings from the template
+// that was applied to the specified instance. In a sense, this is the vanilla
+// configuration setting applied to an instance. Further configuration can be
+// applied by associating an instance with a configuration group.
func GetDefaultConfig(client *gophercloud.ServiceClient, id string) ConfigResult {
var res ConfigResult
@@ -17,6 +21,9 @@
return res
}
+// AssociateWithConfigGroup associates a specified instance to a specified
+// configuration group. If any of the parameters within a configuration group
+// require a restart, then the instance will transition into a restart.
func AssociateWithConfigGroup(client *gophercloud.ServiceClient, instanceID, configGroupID string) UpdateResult {
reqBody := map[string]string{
"configuration": configGroupID,
@@ -32,6 +39,7 @@
return res
}
+// ListBackups will list all the backups for a specified database instance.
func ListBackups(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
pageFn := func(r pagination.PageResult) pagination.Page {
return backups.BackupPage{pagination.SinglePageBase(r)}
@@ -39,6 +47,9 @@
return pagination.NewPager(client, backupsURL(client, instanceID), pageFn)
}
+// DetachReplica will detach a specified replica instance from its source
+// instance, effectively allowing it to operate independently. Detaching a
+// replica will restart the MySQL service on the instance.
func DetachReplica(client *gophercloud.ServiceClient, replicaID string) DetachResult {
var res DetachResult
diff --git a/rackspace/db/v1/instances/results.go b/rackspace/db/v1/instances/results.go
index 2ce302b..7a44f1b 100644
--- a/rackspace/db/v1/instances/results.go
+++ b/rackspace/db/v1/instances/results.go
@@ -45,10 +45,13 @@
// Information about the attached volume of the instance.
Volume os.Volume
+ // IP indicates the various IP addresses which allow access.
IP []string
+ // Indicates whether this instance is a replica of another source instance.
ReplicaOf *Instance `mapstructure:"replica_of" json:"replica_of"`
+ // Indicates whether this instance is the source of other replica instances.
Replicas []Instance
}
@@ -70,6 +73,7 @@
os.CreateResult
}
+// Extract will retrieve an instance from a create result.
func (r CreateResult) Extract() (*Instance, error) {
return commonExtract(r.Err, r.Body)
}
@@ -84,10 +88,13 @@
return commonExtract(r.Err, r.Body)
}
+// ConfigResult represents the result of getting default configuration for an
+// instance.
type ConfigResult struct {
gophercloud.Result
}
+// DetachResult represents the result of detaching a replica from its source.
type DetachResult struct {
gophercloud.ErrResult
}
@@ -114,6 +121,7 @@
gophercloud.ErrResult
}
+// ExtractInstances retrieves a slice of instances from a paginated collection.
func ExtractInstances(page pagination.Page) ([]Instance, error) {
casted := page.(os.InstancePage).Body
diff --git a/rackspace/db/v1/users/delegate.go b/rackspace/db/v1/users/delegate.go
index 0e724f5..0bb4c8c 100644
--- a/rackspace/db/v1/users/delegate.go
+++ b/rackspace/db/v1/users/delegate.go
@@ -6,14 +6,17 @@
"github.com/rackspace/gophercloud/pagination"
)
+// Create will create a new database user for the specified database instance.
func Create(client *gophercloud.ServiceClient, instanceID string, opts os.CreateOptsBuilder) os.CreateResult {
return os.Create(client, instanceID, opts)
}
+// List will list all available users for a specified database instance.
func List(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
return os.List(client, instanceID)
}
+// Delete will permanently remove a user from a specified database instance.
func Delete(client *gophercloud.ServiceClient, instanceID, userName string) os.DeleteResult {
return os.Delete(client, instanceID, userName)
}
diff --git a/rackspace/db/v1/users/doc.go b/rackspace/db/v1/users/doc.go
new file mode 100644
index 0000000..84f2eb3
--- /dev/null
+++ b/rackspace/db/v1/users/doc.go
@@ -0,0 +1,3 @@
+// Package users provides information and interaction with the user API
+// resource in the Rackspace Database service.
+package users
diff --git a/rackspace/db/v1/users/requests.go b/rackspace/db/v1/users/requests.go
index f526cf9..7c30079 100644
--- a/rackspace/db/v1/users/requests.go
+++ b/rackspace/db/v1/users/requests.go
@@ -7,6 +7,17 @@
"github.com/rackspace/gophercloud/pagination"
)
+/*
+ChangePassword changes the password for one or more users. For example, to
+change the respective passwords for two users:
+
+ opts := os.BatchCreateOpts{
+ os.CreateOpts{Name: "db_user_1", Password: "new_password_1"},
+ os.CreateOpts{Name: "db_user_2", Password: "new_password_2"},
+ }
+
+ ChangePassword(client, "instance_id", opts)
+*/
func ChangePassword(client *gophercloud.ServiceClient, instanceID string, opts os.BatchCreateOpts) UpdatePasswordsResult {
var res UpdatePasswordsResult
@@ -24,6 +35,8 @@
return res
}
+// Update will modify the attributes of a specified user. Attributes that can
+// be updated are: user name, password, and host.
func Update(client *gophercloud.ServiceClient, instanceID, userName string, opts os.CreateOpts) UpdateResult {
var res UpdateResult
@@ -42,6 +55,7 @@
return res
}
+// Get will retrieve the details for a particular user.
func Get(client *gophercloud.ServiceClient, instanceID, userName string) GetResult {
var res GetResult
@@ -53,6 +67,7 @@
return res
}
+// ListAccess will list all of the databases a user has access to.
func ListAccess(client *gophercloud.ServiceClient, instanceID, userName string) pagination.Pager {
pageFn := func(r pagination.PageResult) pagination.Page {
return AccessPage{pagination.LinkedPageBase{PageResult: r}}
@@ -61,6 +76,18 @@
return pagination.NewPager(client, dbsURL(client, instanceID, userName), pageFn)
}
+/*
+GrantAccess for the specified user to one or more databases on a specified
+instance. For example, to add a user to multiple databases:
+
+ opts := db.BatchCreateOpts{
+ db.CreateOpts{Name: "database_1"},
+ db.CreateOpts{Name: "database_3"},
+ db.CreateOpts{Name: "database_19"},
+ }
+
+ GrantAccess(client, "instance_id", "user_name", opts)
+*/
func GrantAccess(client *gophercloud.ServiceClient, instanceID, userName string, opts db.BatchCreateOpts) GrantAccessResult {
var res GrantAccessResult
@@ -78,6 +105,19 @@
return res
}
+/*
+RevokeAccess will revoke access for the specified user to one or more databases
+on a specified instance. For example, to remove a user's access to multiple
+databases:
+
+ opts := db.BatchCreateOpts{
+ db.CreateOpts{Name: "database_1"},
+ db.CreateOpts{Name: "database_3"},
+ db.CreateOpts{Name: "database_19"},
+ }
+
+ RevokeAccess(client, "instance_id", "user_name", opts)
+*/
func RevokeAccess(client *gophercloud.ServiceClient, instanceID, userName, dbName string) RevokeAccessResult {
var res RevokeAccessResult
diff --git a/rackspace/db/v1/users/results.go b/rackspace/db/v1/users/results.go
index 3537e68..3d4acb4 100644
--- a/rackspace/db/v1/users/results.go
+++ b/rackspace/db/v1/users/results.go
@@ -15,24 +15,31 @@
// The user password
Password string
+ // Specifies the host from which a user is allowed to connect to the database.
+ // Possible values are a string containing an IPv4 address or "%" to allow
+ // connecting from any host.
Host string
// The databases associated with this user
Databases []db.Database
}
+// UpdatePasswordsResult represents the result of changing a user password.
type UpdatePasswordsResult struct {
gophercloud.ErrResult
}
+// UpdateResult represents the result of updating a user.
type UpdateResult struct {
gophercloud.ErrResult
}
+// GetResult represents the result of getting a user.
type GetResult struct {
gophercloud.Result
}
+// Extract will retrieve a User struct from a getresult.
func (r GetResult) Extract() (*User, error) {
if r.Err != nil {
return nil, r.Err
@@ -88,10 +95,12 @@
return response.DBs, err
}
+// GrantAccessResult represents the result of granting access to a user.
type GrantAccessResult struct {
gophercloud.ErrResult
}
+// RevokeAccessResult represents the result of revoking access to a user.
type RevokeAccessResult struct {
gophercloud.ErrResult
}