Skip to content

Commit 1edd1a2

Browse files
committed
Allow selection of image format during VDI pool migration
This patch add a new parameter to `VDI.pool-migrate`. This new parameter allows to provide a string that is the destination format. This string is used to check whether the destination SR supports the expected format. If the check fails or cannot be performed due to missing information on the destination SR, an error is returned. Signed-off-by: Guillaume <[email protected]>
1 parent 3c3a85d commit 1edd1a2

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

ocaml/idl/datamodel.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5364,6 +5364,10 @@ module VDI = struct
53645364
[
53655365
(Ref _vdi, "vdi", "The VDI to migrate")
53665366
; (Ref _sr, "sr", "The destination SR")
5367+
; ( String
5368+
, "dest_img_format"
5369+
, "The image format to use on destination SR"
5370+
)
53675371
; (Map (String, String), "options", "Other parameters")
53685372
]
53695373
~result:(Ref _vdi, "The new reference of the migrated VDI.")

ocaml/xapi-cli-server/cli_frontend.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,10 +2412,10 @@ let rec cmdtable_data : (string * cmd_spec) list =
24122412
; ( "vdi-pool-migrate"
24132413
, {
24142414
reqd= ["uuid"; "sr-uuid"]
2415-
; optn= []
2415+
; optn= ["dest-img-format"]
24162416
; help=
2417-
"Migrate a VDI to a specified SR, while the VDI is attached to a \
2418-
running guest."
2417+
"Migrate a VDI to a specified SR, while it is attached to a running \
2418+
guest. You can specify the image format for the destination."
24192419
; implementation= No_fd Cli_operations.vdi_pool_migrate
24202420
; flags= []
24212421
}

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,8 +2060,12 @@ let vdi_pool_migrate printer rpc session_id params =
20602060
Client.VDI.get_by_uuid ~rpc ~session_id ~uuid:(List.assoc "uuid" params)
20612061
and sr =
20622062
Client.SR.get_by_uuid ~rpc ~session_id ~uuid:(List.assoc "sr-uuid" params)
2063+
and dest_img_format =
2064+
List.assoc_opt "dest-img-format" params |> Option.value ~default:""
20632065
and options = [] (* no options implemented yet *) in
2064-
let newvdi = Client.VDI.pool_migrate ~rpc ~session_id ~vdi ~sr ~options in
2066+
let newvdi =
2067+
Client.VDI.pool_migrate ~rpc ~session_id ~vdi ~sr ~dest_img_format ~options
2068+
in
20652069
let newuuid = Client.VDI.get_uuid ~rpc ~session_id ~self:newvdi in
20662070
printer (Cli_printer.PList [newuuid])
20672071

ocaml/xapi/message_forwarding.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5455,7 +5455,8 @@ functor
54555455
~prefer_slaves:true op
54565456
)
54575457

5458-
let pool_migrate ~__context ~vdi ~sr ~options =
5458+
let pool_migrate ~__context ~vdi ~sr ~dest_img_format ~options =
5459+
debug "GTNDEBUG: pool_migrate from message forwarder...." ;
54595460
let vbds =
54605461
let expr =
54615462
Xapi_database.Db_filter_types.(
@@ -5475,7 +5476,9 @@ functor
54755476
("__internal__vm", Ref.string_of vm)
54765477
:: List.remove_assoc "__internal__vm" options
54775478
in
5478-
let local_fn = Local.VDI.pool_migrate ~vdi ~sr ~options in
5479+
let local_fn =
5480+
Local.VDI.pool_migrate ~vdi ~sr ~dest_img_format ~options
5481+
in
54795482
let force =
54805483
try bool_of_string (List.assoc "force" options) with _ -> false
54815484
in
@@ -5510,11 +5513,12 @@ functor
55105513
in
55115514
let op session_id rpc =
55125515
let sync_op () =
5513-
Client.VDI.pool_migrate ~rpc ~session_id ~vdi ~sr ~options
5516+
Client.VDI.pool_migrate ~rpc ~session_id ~vdi ~sr
5517+
~dest_img_format ~options
55145518
in
55155519
let async_op () =
55165520
Client.InternalAsync.VDI.pool_migrate ~rpc ~session_id ~vdi ~sr
5517-
~options
5521+
~dest_img_format ~options
55185522
in
55195523
Helpers.try_internal_async ~__context API.ref_VDI_of_rpc async_op
55205524
sync_op

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ let migrate_send ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options ~vgpu_map
20302030
~vgpu_map ~options
20312031
)
20322032

2033-
let vdi_pool_migrate ~__context ~vdi ~sr ~options =
2033+
let vdi_pool_migrate ~__context ~vdi ~sr ~dest_img_format ~options =
20342034
if Db.VDI.get_type ~__context ~self:vdi = `cbt_metadata then (
20352035
error "VDI.pool_migrate: the specified VDI has type cbt_metadata (at %s)"
20362036
__LOC__ ;
@@ -2116,13 +2116,15 @@ let vdi_pool_migrate ~__context ~vdi ~sr ~options =
21162116
XenAPI.Host.migrate_receive ~rpc ~session_id ~host:dest_host ~network
21172117
~options
21182118
in
2119-
assert_can_migrate ~__context ~vm ~dest ~live:true ~vdi_map ~vif_map:[]
2120-
~vgpu_map:[] ~options:[] ;
2119+
assert_can_migrate ~__context ~vm ~dest ~live:true ~vdi_map
2120+
~vdi_format_map:[(vdi, dest_img_format)]
2121+
~vif_map:[] ~vgpu_map:[] ~options:[] ;
21212122
assert_can_migrate_sender ~__context ~vm ~dest ~live:true ~vdi_map
21222123
~vif_map:[] ~vgpu_map:[] ~options:[] ;
21232124
ignore
21242125
(migrate_send ~__context ~vm ~dest ~live:true ~vdi_map
2125-
~vdi_format_map:[] ~vif_map:[] ~vgpu_map:[] ~options
2126+
~vdi_format_map:[(vdi, dest_img_format)]
2127+
~vif_map:[] ~vgpu_map:[] ~options
21262128
)
21272129
) ;
21282130
Db.VBD.get_VDI ~__context ~self:vbd

0 commit comments

Comments
 (0)