Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 010f2b6

Browse files
committed
Merge pull request #515 from jtopjian/jtopjian-multi-ephemeral
[rfr] multi ephemeral support
2 parents b4e5f90 + ecf63dd commit 010f2b6

File tree

3 files changed

+148
-2
lines changed

3 files changed

+148
-2
lines changed

acceptance/openstack/compute/v2/bootfromvolume_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,64 @@ func TestBootFromVolume(t *testing.T) {
5353
defer servers.Delete(client, server.ID)
5454
t.Logf("Deleting server [%s]...", name)
5555
}
56+
57+
func TestMultiEphemeral(t *testing.T) {
58+
client, err := newClient()
59+
th.AssertNoErr(t, err)
60+
61+
if testing.Short() {
62+
t.Skip("Skipping test that requires server creation in short mode.")
63+
}
64+
65+
choices, err := ComputeChoicesFromEnv()
66+
if err != nil {
67+
t.Fatal(err)
68+
}
69+
70+
name := tools.RandomString("Gophercloud-", 8)
71+
t.Logf("Creating server [%s].", name)
72+
73+
bd := []bootfromvolume.BlockDevice{
74+
bootfromvolume.BlockDevice{
75+
BootIndex: 0,
76+
UUID: choices.ImageID,
77+
SourceType: bootfromvolume.Image,
78+
DestinationType: "local",
79+
DeleteOnTermination: true,
80+
},
81+
bootfromvolume.BlockDevice{
82+
BootIndex: -1,
83+
SourceType: bootfromvolume.Blank,
84+
DestinationType: "local",
85+
DeleteOnTermination: true,
86+
GuestFormat: "ext4",
87+
VolumeSize: 1,
88+
},
89+
bootfromvolume.BlockDevice{
90+
BootIndex: -1,
91+
SourceType: bootfromvolume.Blank,
92+
DestinationType: "local",
93+
DeleteOnTermination: true,
94+
GuestFormat: "ext4",
95+
VolumeSize: 1,
96+
},
97+
}
98+
99+
serverCreateOpts := servers.CreateOpts{
100+
Name: name,
101+
FlavorRef: choices.FlavorID,
102+
ImageRef: choices.ImageID,
103+
}
104+
server, err := bootfromvolume.Create(client, bootfromvolume.CreateOptsExt{
105+
serverCreateOpts,
106+
bd,
107+
}).Extract()
108+
th.AssertNoErr(t, err)
109+
if err = waitForStatus(client, server, "ACTIVE"); err != nil {
110+
t.Fatal(err)
111+
}
112+
113+
t.Logf("Created server: %+v\n", server)
114+
defer servers.Delete(client, server.ID)
115+
t.Logf("Deleting server [%s]...", name)
116+
}

openstack/compute/v2/extensions/bootfromvolume/requests.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
Volume SourceType = "volume"
1616
Snapshot SourceType = "snapshot"
1717
Image SourceType = "image"
18+
Blank SourceType = "blank"
1819
)
1920

2021
// BlockDevice is a structure with options for booting a server instance
@@ -32,6 +33,9 @@ type BlockDevice struct {
3233
// and "local".
3334
DestinationType string `json:"destination_type"`
3435

36+
// GuestFormat [optional] specifies the format of the block device.
37+
GuestFormat string `json:"guest_format"`
38+
3539
// SourceType [required] must be one of: "volume", "snapshot", "image".
3640
SourceType SourceType `json:"source_type"`
3741

@@ -82,6 +86,9 @@ func (opts CreateOptsExt) ToServerCreateMap() (map[string]interface{}, error) {
8286
if bd.DestinationType != "" {
8387
blockDevice[i]["destination_type"] = bd.DestinationType
8488
}
89+
if bd.GuestFormat != "" {
90+
blockDevice[i]["guest_format"] = bd.GuestFormat
91+
}
8592

8693
}
8794
serverMap["block_device_mapping_v2"] = blockDevice

openstack/compute/v2/extensions/bootfromvolume/requests_test.go

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func TestCreateOpts(t *testing.T) {
3232
"name": "createdserver",
3333
"imageRef": "asdfasdfasdf",
3434
"flavorRef": "performance1-1",
35-
"flavorName": "",
36-
"imageName": "",
35+
"flavorName": "",
36+
"imageName": "",
3737
"block_device_mapping_v2":[
3838
{
3939
"uuid":"123456",
@@ -51,3 +51,81 @@ func TestCreateOpts(t *testing.T) {
5151
th.AssertNoErr(t, err)
5252
th.CheckJSONEquals(t, expected, actual)
5353
}
54+
55+
func TestCreateMultiEphemeralOpts(t *testing.T) {
56+
base := servers.CreateOpts{
57+
Name: "createdserver",
58+
ImageRef: "asdfasdfasdf",
59+
FlavorRef: "performance1-1",
60+
}
61+
62+
ext := CreateOptsExt{
63+
CreateOptsBuilder: base,
64+
BlockDevice: []BlockDevice{
65+
BlockDevice{
66+
BootIndex: 0,
67+
DeleteOnTermination: true,
68+
DestinationType: "local",
69+
SourceType: Image,
70+
UUID: "123456",
71+
},
72+
BlockDevice{
73+
BootIndex: -1,
74+
DeleteOnTermination: true,
75+
DestinationType: "local",
76+
GuestFormat: "ext4",
77+
SourceType: Blank,
78+
VolumeSize: 1,
79+
},
80+
BlockDevice{
81+
BootIndex: -1,
82+
DeleteOnTermination: true,
83+
DestinationType: "local",
84+
GuestFormat: "ext4",
85+
SourceType: Blank,
86+
VolumeSize: 1,
87+
},
88+
},
89+
}
90+
91+
expected := `
92+
{
93+
"server": {
94+
"name": "createdserver",
95+
"imageRef": "asdfasdfasdf",
96+
"flavorRef": "performance1-1",
97+
"flavorName": "",
98+
"imageName": "",
99+
"block_device_mapping_v2":[
100+
{
101+
"boot_index": "0",
102+
"delete_on_termination": "true",
103+
"destination_type":"local",
104+
"source_type":"image",
105+
"uuid":"123456",
106+
"volume_size": "0"
107+
},
108+
{
109+
"boot_index": "-1",
110+
"delete_on_termination": "true",
111+
"destination_type":"local",
112+
"guest_format":"ext4",
113+
"source_type":"blank",
114+
"volume_size": "1"
115+
},
116+
{
117+
"boot_index": "-1",
118+
"delete_on_termination": "true",
119+
"destination_type":"local",
120+
"guest_format":"ext4",
121+
"source_type":"blank",
122+
"volume_size": "1"
123+
}
124+
]
125+
}
126+
}
127+
`
128+
actual, err := ext.ToServerCreateMap()
129+
th.AssertNoErr(t, err)
130+
th.CheckJSONEquals(t, expected, actual)
131+
}

0 commit comments

Comments
 (0)