Permalink
Browse files

CA-61740: Update allowed_operations when converting a template into a…

… VM.

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information...
1 parent d3754ae commit a3bd9eb3d44617e1da4ac7eb740d88455bda36f5 @johnelse committed Aug 6, 2012
@@ -61,6 +61,7 @@ let vm_operation_table =
`unpause, "unpause";
`update_allowed_operations, "update_allowed_operations";
`make_into_template, "make_into_template";
+ `convert_from_template, "convert_from_template";
`send_sysrq, "send_sysrq";
`send_trigger, "send_trigger";
`changing_memory_live, "changing_memory_live";
View
@@ -122,6 +122,7 @@ let vlan_tag_invalid = "VLAN_TAG_INVALID"
let vm_bad_power_state = "VM_BAD_POWER_STATE"
let vm_is_template = "VM_IS_TEMPLATE"
let vm_is_snapshot = "VM_IS_SNAPSHOT"
+let vm_is_not_template = "VM_IS_NOT_TEMPLATE"
let other_operation_in_progress = "OTHER_OPERATION_IN_PROGRESS"
let vbd_not_removable_media = "VBD_NOT_REMOVABLE_MEDIA"
let vbd_not_unpluggable = "VBD_NOT_UNPLUGGABLE"
View
@@ -531,6 +531,8 @@ let _ =
~doc:"You attempted an operation on a VM which requires a more recent version of the PV drivers. Please upgrade your PV drivers." ();
error Api_errors.vm_is_template ["vm"]
~doc:"The operation attempted is not valid for a template VM" ();
+ error Api_errors.vm_is_not_template ["vm"]
+ ~doc:"The operation attempted is only valid for a template VM" ();
error Api_errors.other_operation_in_progress ["class"; "object"]
~doc:"Another operation involving the object is currently in progress" ();
error Api_errors.vbd_not_removable_media ["vbd"]
@@ -6541,6 +6543,7 @@ let vm_operations =
"data_source_op", "Add, remove, query or list data sources";
"update_allowed_operations", "";
"make_into_template", "Turning this VM into a template";
+ "convert_from_template", "Turning this template into a VM";
"import", "importing a VM from a network stream";
"export", "exporting a VM to a network stream";
"metadata_export", "exporting VM metadata to a network stream";
@@ -1019,14 +1019,12 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
Xapi_vm_lifecycle.update_allowed_operations ~__context ~self
let set_is_a_template ~__context ~self ~value =
- if value
- then with_vm_operation ~__context ~self ~doc:"VM.set_is_a_template" ~op:`make_into_template
- (fun () ->
- Local.VM.set_is_a_template ~__context ~self ~value:true)
- else Local.VM.set_is_a_template ~__context ~self ~value
- (*
- else raise (Api_errors.Server_error(Api_errors.operation_not_allowed, [ "Must use VM.provision" ]))
- *)
+ let op =
+ if value then `make_into_template
+ else `convert_from_template
+ in
+ with_vm_operation ~__context ~self ~doc:"VM.set_is_a_template" ~op
+ (fun () -> Local.VM.set_is_a_template ~__context ~self ~value)
let maximise_memory ~__context ~self ~total ~approximate =
info "VM.maximise_memory: VM = '%s'; total = '%Ld'; approximate = '%b'" (vm_uuid ~__context self) total approximate;
@@ -35,6 +35,7 @@ let allowed_power_states ~__context ~vmr ~(op:API.vm_operations) =
| `changing_static_range
| `changing_VCPUs
| `make_into_template
+ | `convert_from_template
| `provision
| `start
| `start_on
@@ -162,7 +163,7 @@ let check_template ~vmr ~op ~ref_str =
] in
if false
|| List.mem op allowed_operations
- || (op = `destroy && not default_template)
+ || (List.mem op [`destroy; `convert_from_template] && not default_template)
then None
else Some (Api_errors.vm_is_template, [ref_str; Record_util.vm_operation_to_string op])
@@ -251,6 +252,12 @@ let check_operation_error ~__context ~vmr ~vmgmr ~ref ~clone_suspended_vm_enable
then check_snapshot ~vmr ~op ~ref_str
else None) in
+ (* if the VM is not a template, it cannot be converted from a template. *)
+ let current_error = check current_error (fun () ->
+ if op = `convert_from_template && (not is_template)
+ then Some (Api_errors.vm_is_not_template, [ref_str])
+ else None) in
+
(* if the VM is neither a template nor a snapshot, do not allow provision and revert. *)
let current_error = check current_error (fun () ->
if op = `provision && (not is_template)
@@ -376,7 +383,7 @@ let update_allowed_operations ~__context ~self =
`start; `start_on; `pause; `unpause; `clean_shutdown; `clean_reboot;
`hard_shutdown; `hard_reboot; `suspend; `resume; `resume_on; `export; `destroy;
`provision; `changing_VCPUs_live; `pool_migrate; `migrate_send; `make_into_template; `changing_static_range;
- `changing_shadow_memory; `changing_dynamic_range]
+ `changing_shadow_memory; `changing_dynamic_range; `convert_from_template]
in
(* FIXME: need to be able to deal with rolling-upgrade for orlando as well *)
let allowed =

0 comments on commit a3bd9eb

Please sign in to comment.