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