Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5e433bd
trove: Add API to grant user access to database
nautiam Nov 3, 2023
861b71a
trove: Add API to revoke user access to database
nautiam Nov 3, 2023
c6c73ae
trove: Add database backup feature
nautiam Nov 5, 2023
68ceec1
Add more field to Database instance CreateOpts
nautiam Nov 6, 2023
ec77742
Add more instance API
nautiam Nov 7, 2023
32f6c6b
trove: Add instance log features
nautiam Nov 10, 2023
39765c9
Add field tags for database
nautiam Nov 22, 2023
80b6139
Merge branch 'gophercloud:master' into master
nautiam Dec 27, 2023
25d781b
Merge branch 'master' into dev
nautiam Dec 27, 2023
255982c
cinder: Add snapshot extension
nautiam Dec 27, 2023
c49bee7
trove: fix DetachConfigurationGroup API
nautiam Dec 28, 2023
ef9ffce
trove: Add Access object for Replicate and Restore API
nautiam Jan 4, 2024
3980564
trove: Add replicas and replica_of to Instance result
nautiam Jan 29, 2024
b207220
trove: Allow input password for root user
nautiam Jan 30, 2024
8832b26
trove: Extend Size of instance to 2T
nautiam Jan 30, 2024
20a37b2
trove: Update unit test for EnableRoot
nautiam Feb 2, 2024
1ea103f
trove: Add operating_status field
nautiam Mar 21, 2024
ecf8439
trove: Add ServerId field
nautiam Mar 29, 2024
eb70857
trove: Add TenantId field
nautiam Apr 5, 2024
5da1bb3
trove: Add NetworkOpts fields
nautiam Apr 9, 2024
abde09a
blockstorage: Add TenantID for backup
nautiam Jun 25, 2024
8676d7f
trove: Add availability_zone for Replicate and Restore
nautiam Sep 25, 2024
bf1164c
trove: Add omitempty for Param configuration
nautiam Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions openstack/blockstorage/extensions/backups/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type Backup struct {
// AvailabilityZone is the Availability Zone of the backup.
// This requires microversion 3.51 or later.
AvailabilityZone *string `json:"availability_zone"`

// Tenant is the ID of the project that owns the backup.
TenantID string `json:"project_id"`
}

// CreateResult contains the response body and error from a Create request.
Expand Down
26 changes: 26 additions & 0 deletions openstack/blockstorage/extensions/snapshotextensions/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Package snapshotextensions provides the ability to extend a snapshot
result with tenant/project information. Example:

type SnapshotWithExt struct {
snapshots.Snapshot
snapshotextensions.SnapshotExtension
}

var allSnapshot []SnapshotWithExt

allPages, err := snapshots.List(client, nil).AllPages()
if err != nil {
panic("Unable to retrieve snapshots: %s", err)
}

err = snapshots.ExtractVolumesInto(allPages, &allSnapshots)
if err != nil {
panic("Unable to extract snapshots: %s", err)
}

for _, snapshot := range allSnapshots {
fmt.Println(snapshot.ProjectId)
}
*/
package snapshotextensions
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package snapshotextensions

// SnapshotExtension is an extension to the base Snapshot object
type SnapshotExtension struct {
// A percentage value for the build progress.
Progress string `json:"os-extended-snapshot-attributes:progress"`
// The UUID of the owning project.
ProjectId string `json:"os-extended-snapshot-attributes:project_id"`
}
24 changes: 15 additions & 9 deletions openstack/blockstorage/v3/snapshots/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ func (r SnapshotPage) NextPageURL() (string, error) {
return gophercloud.ExtractNextURL(s.Links)
}

// ExtractSnapshotsInto similar to ExtractInto but operates on a `list` of snapshots
func ExtractSnapshotsInto(r pagination.Page, v interface{}) error {
return r.(SnapshotPage).Result.ExtractIntoSlicePtr(v, "snapshots")
}

// ExtractSnapshots extracts and returns Snapshots. It is used while iterating over a snapshots.List call.
func ExtractSnapshots(r pagination.Page) ([]Snapshot, error) {
var s struct {
Snapshots []Snapshot `json:"snapshots"`
}
err := (r.(SnapshotPage)).ExtractInto(&s)
return s.Snapshots, err
var s []Snapshot
err := ExtractSnapshotsInto(r, &s)
return s, err
}

// UpdateMetadataResult contains the response body and error from an UpdateMetadata request.
Expand All @@ -135,11 +138,14 @@ type commonResult struct {

// Extract will get the Snapshot object out of the commonResult object.
func (r commonResult) Extract() (*Snapshot, error) {
var s struct {
Snapshot *Snapshot `json:"snapshot"`
}
var s Snapshot
err := r.ExtractInto(&s)
return s.Snapshot, err
return &s, err
}

// ExtractInto converts our response data into a snapshot struct
func (r commonResult) ExtractInto(s interface{}) error {
return r.Result.ExtractIntoStructPtr(s, "snapshot")
}

// ResetStatusResult contains the response error from a ResetStatus request.
Expand Down
9 changes: 6 additions & 3 deletions openstack/blockstorage/v3/snapshots/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func MockListResponse(t *testing.T) {
"description": "Daily Backup",
"status": "available",
"size": 30,
"created_at": "2017-05-30T03:35:03.000000"
"created_at": "2017-05-30T03:35:03.000000",
"os-extended-snapshot-attributes:project_id": "89afd400-b646-4bbc-b12b-c0a4d63e5bd3"
},
{
"id": "96c3bda7-c82a-4f50-be73-ca7621794835",
Expand All @@ -41,7 +42,8 @@ func MockListResponse(t *testing.T) {
"description": "Weekly Backup",
"status": "available",
"size": 25,
"created_at": "2017-05-30T03:35:03.000000"
"created_at": "2017-05-30T03:35:03.000000",
"os-extended-snapshot-attributes:project_id": "89afd400-b646-4bbc-b12b-c0a4d63e5bd3"
}
],
"snapshots_links": [
Expand Down Expand Up @@ -76,7 +78,8 @@ func MockGetResponse(t *testing.T) {
"volume_id": "521752a6-acf6-4b2d-bc7a-119f9148cd8c",
"status": "available",
"size": 30,
"created_at": "2017-05-30T03:35:03.000000"
"created_at": "2017-05-30T03:35:03.000000",
"os-extended-snapshot-attributes:project_id": "89afd400-b646-4bbc-b12b-c0a4d63e5bd3"
}
}
`)
Expand Down
43 changes: 43 additions & 0 deletions openstack/blockstorage/v3/snapshots/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,35 @@ import (
"testing"
"time"

"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/snapshotextensions"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)

func TestListAllWithExtensions(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

MockListResponse(t)

type SnapshotWithExt struct {
snapshots.Snapshot
snapshotextensions.SnapshotExtension
}

allPages, err := snapshots.List(client.ServiceClient(), &snapshots.ListOpts{}).AllPages()
th.AssertNoErr(t, err)

var actual []SnapshotWithExt
err = snapshots.ExtractSnapshotsInto(allPages, &actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, 2, len(actual))
th.AssertEquals(t, "89afd400-b646-4bbc-b12b-c0a4d63e5bd3", actual[0].ProjectId)
th.AssertEquals(t, "89afd400-b646-4bbc-b12b-c0a4d63e5bd3", actual[1].ProjectId)
}

func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
Expand Down Expand Up @@ -70,6 +93,26 @@ func TestGet(t *testing.T) {
th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
}

func TestGetWithExtensions(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

MockGetResponse(t)

var s struct {
snapshots.Snapshot
snapshotextensions.SnapshotExtension
}
err := snapshots.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractInto(&s)
th.AssertNoErr(t, err)
th.AssertEquals(t, "89afd400-b646-4bbc-b12b-c0a4d63e5bd3", s.ProjectId)

err = snapshots.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractInto(s)
if err == nil {
t.Errorf("Expected error when providing non-pointer struct")
}
}

func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
Expand Down
3 changes: 3 additions & 0 deletions openstack/db/v1/backups/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package backups provides information and interaction with the backup API
// resource in the OpenStack Database service.
package backups
116 changes: 116 additions & 0 deletions openstack/db/v1/backups/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package backups

import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)

// CreateOptsBuilder is the top-level interface for creating JSON maps.
type CreateOptsBuilder interface {
ToBackupCreateMap() (map[string]interface{}, error)
}

// CreateOpts is the struct responsible for configuring a new user; often in the
// context of an instance.
type CreateOpts struct {
// Specifies a name for the user. Valid names can be composed
// of the following characters: letters (either case); numbers; these
// characters '@', '?', '#', ' ' but NEVER beginning a name string; '_' is
// permitted anywhere. Prohibited characters that are forbidden include:
// single quotes, double quotes, back quotes, semicolons, commas, backslashes,
// and forward slashes. Spaces at the front or end of a user name are also
// not permitted.
Name string `json:"name" required:"true"`
// Specifies the ID of the instance to create backup for.
Instance string `json:"instance" required:"true"`
// Specifies the ID of the parent backup to perform an incremental backup from.
// Optional
ParentId string `json:"parentId,omitempty"`
// Create an incremental backup based on the last full backup or not.
// The value must be 0 or 1. Optional.
Incremental int `json:"incremental,omitempty"`
// Specifies a description for the backup. Optional.
Description string `json:"description,omitempty"`
// Specifies the swift container name. When creating backups, the swift
// container is created automatically if does not exist.
// The backup data is stored as object in the Swift container. Optional.
SwiftContainer string `json:"swiftContainer,omitempty"`
}

// ToBackupCreateMap will generate a JSON map.
func (opts CreateOpts) ToBackupCreateMap() (map[string]interface{}, error) {
if len(opts.Name) > 64 {
err := gophercloud.ErrInvalidInput{}
err.Argument = "backups.CreateOpts.Name"
err.Value = opts.Name
err.Info = "Must be less than 64 chars long"
return nil, err
}
if opts.Instance == "" {
return nil, gophercloud.ErrMissingInput{Argument: "backups.CreateOpts.Instance"}
}
if opts.Incremental > 1 || opts.Incremental < 0 {
err := gophercloud.ErrInvalidInput{}
err.Argument = "backups.CreateOpts.Incremental"
err.Value = opts.Incremental
err.Info = "Incremental parameter must be 1 or 0"
return nil, err
}
backup := map[string]interface{}{
"name": opts.Name,
"instance": opts.Instance,
}
backup["incremental"] = opts.Incremental
if opts.ParentId != "" {
backup["parent_id"] = opts.ParentId
}
if opts.Description != "" {
backup["description"] = opts.Description
}
if opts.SwiftContainer != "" {
backup["swift_container"] = opts.SwiftContainer
}
return map[string]interface{}{"backup": backup}, nil
}

// Create asynchronously provisions a new backup for the specified database
// instance based on the configuration defined in CreateOpts.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToBackupCreateMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Post(baseURL(client), &b, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{202}})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

// List will list all database backups information for a project.
func List(client *gophercloud.ServiceClient) pagination.Pager {
return pagination.NewPager(client, baseURL(client), func(r pagination.PageResult) pagination.Page {
return BackupPage{pagination.LinkedPageBase{PageResult: r}}
})
}

// Get will show detailes of a backup for a project.
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
resp, err := client.Get(resourceURL(client, id), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

// Delete will permanently delete a database backup.
// All the child backups are deleted automatically when a parent backup is deleted.
func Delete(client *gophercloud.ServiceClient, backupId string) (r DeleteResult) {
resp, err := client.Delete(resourceURL(client, backupId), nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

// ListOfInstance will get all the backups of an instance
func ListOfInstance(client *gophercloud.ServiceClient, instanceId string) pagination.Pager {
return pagination.NewPager(client, listURL(client, instanceId), func(r pagination.PageResult) pagination.Page {
return BackupPage{pagination.LinkedPageBase{PageResult: r}}
})
}
Loading