Skip to content

Commit 8a454d9

Browse files
Ludovic LamarcheLudovic Lamarche
authored andcommitted
update live migrate api with microversion 2.25
1 parent efb556a commit 8a454d9

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package migrate
2+
3+
import "github.com/gophercloud/gophercloud"
4+
5+
// LiveMigrateOpts specifies parameters of live migrate action.
6+
type LiveMigrate225Opts struct {
7+
// The host to which to migrate the server.
8+
// If this parameter is None, the scheduler chooses a host.
9+
Host *string `json:"host"`
10+
11+
// Set to True to migrate local disks by using block migration.
12+
// If the source or destination host uses shared storage and you set
13+
// this value to True, the live migration fails.
14+
BlockMigration string `json:"block_migration"`
15+
16+
// Set to True to enable over commit when the destination host is checked
17+
// for available disk space. Set to False to disable over commit. This setting
18+
// affects only the libvirt virt driver.
19+
DiskOverCommit *bool `json:"disk_over_commit,omitempty"`
20+
}
21+
22+
// ToLiveMigrateMap constructs a request body from LiveMigrateOpts.
23+
func (opts LiveMigrate225Opts) ToLiveMigrateMap() (map[string]interface{}, error) {
24+
return gophercloud.BuildRequestBody(opts, "os-migrateLive")
25+
}

openstack/compute/v2/extensions/migrate/testing/fixtures.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,18 @@ func mockLiveMigrateResponse(t *testing.T, id string) {
3131
w.WriteHeader(http.StatusAccepted)
3232
})
3333
}
34+
35+
func mockLiveMigrate225Response(t *testing.T, id string) {
36+
th.Mux.HandleFunc("/servers/"+id+"/action", func(w http.ResponseWriter, r *http.Request) {
37+
th.TestMethod(t, r, "POST")
38+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
39+
th.TestJSONRequest(t, r, `{
40+
"os-migrateLive": {
41+
"host": "01c0cadef72d47e28a672a76060d492c",
42+
"block_migration": "auto",
43+
"disk_over_commit": true
44+
}
45+
}`)
46+
w.WriteHeader(http.StatusAccepted)
47+
})
48+
}

openstack/compute/v2/extensions/migrate/testing/requests_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,22 @@ func TestLiveMigrate(t *testing.T) {
3939
err := migrate.LiveMigrate(client.ServiceClient(), serverID, migrationOpts).ExtractErr()
4040
th.AssertNoErr(t, err)
4141
}
42+
43+
func TestLiveMigrate225(t *testing.T) {
44+
th.SetupHTTP()
45+
defer th.TeardownHTTP()
46+
47+
mockLiveMigrate225Response(t, serverID)
48+
49+
host := "01c0cadef72d47e28a672a76060d492c"
50+
diskOverCommit := true
51+
52+
migrationOpts := migrate.LiveMigrate225Opts{
53+
Host: &host,
54+
BlockMigration: "auto",
55+
DiskOverCommit: &diskOverCommit,
56+
}
57+
58+
err := migrate.LiveMigrate(client.ServiceClient(), serverID, migrationOpts).ExtractErr()
59+
th.AssertNoErr(t, err)
60+
}

0 commit comments

Comments
 (0)