Skip to content

Commit 51831d9

Browse files
authored
Merge pull request #2875 from gophercloud/bp-v1-74052e2
[v1] [db/v1/instance]: adding support for availability_zone for a db instance
2 parents 00c2107 + 9cfe594 commit 51831d9

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

openstack/db/v1/instances/requests.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func (opts NetworkOpts) ToMap() (map[string]interface{}, error) {
4747

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

92+
if opts.AvailabilityZone != "" {
93+
instance["availability_zone"] = opts.AvailabilityZone
94+
}
95+
9096
if opts.Name != "" {
9197
instance["name"] = opts.Name
9298
}

openstack/db/v1/instances/testing/fixtures_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ var instanceGet = `
104104
var createReq = `
105105
{
106106
"instance": {
107+
"availability_zone": "us-east1",
107108
"databases": [
108109
{
109110
"character_set": "utf8",

openstack/db/v1/instances/testing/requests_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ func TestCreate(t *testing.T) {
1717
HandleCreate(t)
1818

1919
opts := instances.CreateOpts{
20-
Name: "json_rack_instance",
21-
FlavorRef: "1",
20+
AvailabilityZone: "us-east1",
21+
Name: "json_rack_instance",
22+
FlavorRef: "1",
2223
Databases: db.BatchCreateOpts{
2324
{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
2425
{Name: "nextround"},
@@ -48,8 +49,9 @@ func TestCreateWithFault(t *testing.T) {
4849
HandleCreateWithFault(t)
4950

5051
opts := instances.CreateOpts{
51-
Name: "json_rack_instance",
52-
FlavorRef: "1",
52+
AvailabilityZone: "us-east1",
53+
Name: "json_rack_instance",
54+
FlavorRef: "1",
5355
Databases: db.BatchCreateOpts{
5456
{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
5557
{Name: "nextround"},

0 commit comments

Comments
 (0)