Skip to content

Commit

Permalink
Merge pull request #2875 from gophercloud/bp-v1-74052e2
Browse files Browse the repository at this point in the history
[v1] [db/v1/instance]: adding support for availability_zone for a db instance
  • Loading branch information
EmilienM committed Jan 19, 2024
2 parents 00c2107 + 9cfe594 commit 51831d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions openstack/db/v1/instances/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (opts NetworkOpts) ToMap() (map[string]interface{}, error) {

// CreateOpts is the struct responsible for configuring a new database instance.
type CreateOpts struct {
// The availability zone of the instance.
AvailabilityZone string `json:"availability_zone,omitempty"`
// Either the integer UUID (in string form) of the flavor, or its URI
// reference as specified in the response from the List() call. Required.
FlavorRef string
Expand Down Expand Up @@ -87,6 +89,10 @@ func (opts CreateOpts) ToInstanceCreateMap() (map[string]interface{}, error) {
"flavorRef": opts.FlavorRef,
}

if opts.AvailabilityZone != "" {
instance["availability_zone"] = opts.AvailabilityZone
}

if opts.Name != "" {
instance["name"] = opts.Name
}
Expand Down
1 change: 1 addition & 0 deletions openstack/db/v1/instances/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ var instanceGet = `
var createReq = `
{
"instance": {
"availability_zone": "us-east1",
"databases": [
{
"character_set": "utf8",
Expand Down
10 changes: 6 additions & 4 deletions openstack/db/v1/instances/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ func TestCreate(t *testing.T) {
HandleCreate(t)

opts := instances.CreateOpts{
Name: "json_rack_instance",
FlavorRef: "1",
AvailabilityZone: "us-east1",
Name: "json_rack_instance",
FlavorRef: "1",
Databases: db.BatchCreateOpts{
{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
{Name: "nextround"},
Expand Down Expand Up @@ -48,8 +49,9 @@ func TestCreateWithFault(t *testing.T) {
HandleCreateWithFault(t)

opts := instances.CreateOpts{
Name: "json_rack_instance",
FlavorRef: "1",
AvailabilityZone: "us-east1",
Name: "json_rack_instance",
FlavorRef: "1",
Databases: db.BatchCreateOpts{
{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
{Name: "nextround"},
Expand Down

0 comments on commit 51831d9

Please sign in to comment.