You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CA-41553: Fix logic bugs in vm_install_real and do some code cleanup
There were two logic bugs in vm_install_real
* When user create a VM based on a snapshot (which is also considered as a template from XenServer point of view), and neither sr-name-lable or sr-uuid is specified (neither is wanted any way), the code will fail if the pool doesn't have default SR set (which is not necessary as well). This is the problem spot in CA-41553.
* When both sr-uuid and sr-name-lable are specified in command line at the same time
- If there is some contradiction, say the SR with sr-uuid doesn't have the name as specified in sr-name-label, XenServer will only take sr-name-label into consideration and ignore sr-uuid without a warning
- If sr-name-label corresponding to several SRs in the system, instead of using the sr-uuid information to restrict the candidate to one, XenServer will simply fail and complain "Multiple SRs with that name-label found".
Signed-off-by: Zheng Li <[email protected]>
ifClient.VM.get_is_a_snapshot rpc session_id template then
1971
+
if (List.mem_assoc "sr-name-label" params
1972
+
||List.mem_assoc "sr-uuid" params) then
1973
+
failwith "Do not use the sr-name-label or sr-uuid argument when installing from a snapshot. By default, it will install each new disk on the same SR as the corresponding snapshot disks."
1974
+
elseSomeRef.null
1975
+
elseNonein
1976
+
1968
1977
(* Rewrite the provisioning XML to refer to the sr-name-label, sr-uuid or the pool default_SR *)
1969
-
let sr_name_label =
1970
-
ifList.mem_assoc "sr-name-label" params
1971
-
thenmatchClient.SR.get_by_name_label rpc session_id (List.assoc "sr-name-label" params) with
1972
-
| [ sr ] -> Some (Client.SR.get_uuid rpc session_id sr)
1978
+
1979
+
let sr_ref =match sr_ref with
1980
+
|Some_ -> sr_ref
1981
+
|None ->
1982
+
ifList.mem_assoc "sr-uuid" params then
1983
+
let uuid =List.assoc "sr-uuid" params in
1984
+
Some (Client.SR.get_by_uuid rpc session_id uuid)
1985
+
elseNonein
1986
+
1987
+
let sr_ref =
1988
+
ifList.mem_assoc "sr-name-label" params then
1989
+
let name =List.assoc "sr-name-label" params in
1990
+
matchClient.SR.get_by_name_label rpc session_id name with
1973
1991
|[] -> failwith "No SR with that name-label found"
1974
-
|_ -> failwith "Multiple SRs with that name-label found"
1975
-
elseNonein
1976
-
let sr_uuid =
1977
-
ifList.mem_assoc "sr-uuid" params
1978
-
then (let uuid =List.assoc "sr-uuid" params in
1979
-
ignore (Client.SR.get_by_uuid rpc session_id uuid); (* throws an exception if not found *)
1980
-
Some uuid)
1981
-
elseNonein
1982
-
let pool_default = get_default_sr_uuid rpc session_id in
1983
-
1984
-
let sr_uuid =match sr_name_label, sr_uuid, pool_default with
1985
-
|Somex, _, _ -> x
1986
-
|_, Somex, _ -> x
1987
-
|_, _, Somex -> x
1988
-
|None, None, None ->
1989
-
let vbds =Client.VM.get_VBDs rpc session_id template in
1990
-
let disks =List.filter (funvbd -> not (Client.VBD.get_type rpc session_id vbd =`CD&&Client.VBD.get_empty rpc session_id vbd)) vbds in
1991
-
let has_provisioned_disks =
1992
+
|sr_list -> match sr_ref with
1993
+
|Somesr ->
1994
+
ifList.mem sr sr_list then sr_ref
1995
+
else failwith "SR specified via sr-uuid doesn't have the name specified via sr-name-label"
1996
+
|None ->
1997
+
ifList.length sr_list >1then
1998
+
failwith "Multiple SRs with that name-label found"
1999
+
elseSome (List.hd sr_list)
2000
+
else sr_ref in
2001
+
2002
+
let sr_ref =match sr_ref with
2003
+
|Some_ -> sr_ref
2004
+
|None ->
2005
+
let all_empty_cd_driver =
2006
+
let vbds =Client.VM.get_VBDs rpc session_id template in
2007
+
letis_empty_cd_drivevbd=
2008
+
Client.VBD.get_type rpc session_id vbd =`CD
2009
+
&&Client.VBD.get_empty rpc session_id vbd in
2010
+
List.for_all is_empty_cd_drive vbds in
2011
+
let no_provision_disk =
1992
2012
let other_config =Client.VM.get_other_config rpc session_id template in
failwith "Do not use the sr-name-label or sr-uuid argument when installing from a snapshot. By default, it will install each new disk on the same SR as the corresponding snapshot disks.";
0 commit comments