Skip to content

Commit

Permalink
Add sanity checks when setting VM fields
Browse files Browse the repository at this point in the history
When setting VM.order, VM.start_delay or VM.shutdown_delay, ensure the
values the fields are being set to are non-negative.

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information
johnelse committed Mar 23, 2011
1 parent 1a72279 commit 6a053b6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
36 changes: 33 additions & 3 deletions ocaml/idl/datamodel.ml
Expand Up @@ -1994,6 +1994,33 @@ let vm_set_protection_policy = call
~allowed_roles:_R_POOL_OP
()

let vm_set_start_delay = call
~name:"set_start_delay"
~in_product_since:rel_boston
~doc:"Set this VM's start delay in seconds"
~params:[Ref _vm, "self", "The VM";
Int, "value", "This VM's start delay in seconds"]
~allowed_roles:_R_POOL_OP
()

let vm_set_shutdown_delay = call
~name:"set_shutdown_delay"
~in_product_since:rel_boston
~doc:"Set this VM's shutdown delay in seconds"
~params:[Ref _vm, "self", "The VM";
Int, "value", "This VM's shutdown delay in seconds"]
~allowed_roles:_R_POOL_OP
()

let vm_set_order = call
~name:"set_order"
~in_product_since:rel_boston
~doc:"Set this VM's boot order"
~params:[Ref _vm, "self", "The VM";
Int, "value", "This VM's boot order"]
~allowed_roles:_R_POOL_OP
()

(* ------------------------------------------------------------------------------------------------------------
Host Management
------------------------------------------------------------------------------------------------------------ *)
Expand Down Expand Up @@ -5961,6 +5988,9 @@ let vm =
vm_retrieve_wlb_recommendations;
vm_copy_bios_strings;
vm_set_protection_policy;
vm_set_start_delay;
vm_set_shutdown_delay;
vm_set_order;
]
~contents:
([ uid _vm;
Expand Down Expand Up @@ -6029,9 +6059,9 @@ let vm =
field ~writer_roles:_R_VM_POWER_ADMIN ~qualifier:StaticRO ~in_product_since:rel_cowley ~default_value:(Some (VRef (Ref.string_of Ref.null))) ~ty:(Ref _vmpp) "protection_policy" "Ref pointing to a protection policy for this VM";
field ~writer_roles:_R_POOL_OP ~qualifier:StaticRO ~in_product_since:rel_cowley ~default_value:(Some (VBool false)) ~ty:Bool "is_snapshot_from_vmpp" "true if this snapshot was created by the protection policy";
field ~writer_roles:_R_POOL_OP ~qualifier:RW ~ty:(Ref _vm_appliance) ~default_value:(Some (VRef (Ref.string_of Ref.null))) "appliance" "the appliance to which this VM belongs";
field ~writer_roles:_R_POOL_OP ~qualifier:RW ~in_product_since:rel_boston ~default_value:(Some (VInt 0L)) ~ty:Int "start_delay" "The delay to wait before proceeding to the next order in the startup sequence (seconds)";
field ~writer_roles:_R_POOL_OP ~qualifier:RW ~in_product_since:rel_boston ~default_value:(Some (VInt 0L)) ~ty:Int "shutdown_delay" "The delay to wait before proceeding to the next order in the shutdown sequence (seconds)";
field ~writer_roles:_R_POOL_OP ~qualifier:RW ~in_product_since:rel_boston ~default_value:(Some (VInt 0L)) ~ty:Int "order" "The point in the startup or shutdown sequence at which this VM will be started";
field ~writer_roles:_R_POOL_OP ~qualifier:StaticRO ~in_product_since:rel_boston ~default_value:(Some (VInt 0L)) ~ty:Int "start_delay" "The delay to wait before proceeding to the next order in the startup sequence (seconds)";
field ~writer_roles:_R_POOL_OP ~qualifier:StaticRO ~in_product_since:rel_boston ~default_value:(Some (VInt 0L)) ~ty:Int "shutdown_delay" "The delay to wait before proceeding to the next order in the shutdown sequence (seconds)";
field ~writer_roles:_R_POOL_OP ~qualifier:StaticRO ~in_product_since:rel_boston ~default_value:(Some (VInt 0L)) ~ty:Int "order" "The point in the startup or shutdown sequence at which this VM will be started";
field ~qualifier:DynamicRO ~lifecycle:[Published, rel_boston, ""] ~ty:(Set (Ref _vgpu)) "VGPUs" "Virtual GPUs";
field ~qualifier:DynamicRO ~lifecycle:[Published, rel_boston, ""] ~ty:(Set (Ref _pci)) "attached_PCIs" "Currently passed-through PCI devices";
field ~qualifier:StaticRO ~in_product_since:rel_boston ~default_value:(Some (VInt 0L)) ~ty:Int "version" "The number of times this VM has been recovered";
Expand Down
12 changes: 12 additions & 0 deletions ocaml/xapi/message_forwarding.ml
Expand Up @@ -1777,6 +1777,18 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
info "VM.set_protection_policy: self = '%s'; " (vm_uuid ~__context self);
Local.VM.set_protection_policy ~__context ~self ~value

let set_start_delay ~__context ~self ~value =
info "VM.set_start_delay: self = '%s';" (vm_uuid ~__context self);
Local.VM.set_start_delay ~__context ~self ~value

let set_shutdown_delay ~__context ~self ~value =
info "VM.set_shutdown_delay: self = '%s';" (vm_uuid ~__context self);
Local.VM.set_shutdown_delay ~__context ~self ~value

let set_order ~__context ~self ~value =
info "VM.set_order: self = '%s';" (vm_uuid ~__context self);
Local.VM.set_order ~__context ~self ~value

end

module VM_metrics = struct
Expand Down
18 changes: 18 additions & 0 deletions ocaml/xapi/xapi_vm.ml
Expand Up @@ -1259,3 +1259,21 @@ let set_protection_policy ~__context ~self ~value =
(if (value <> Ref.null) then Xapi_vmpp.assert_licensed ~__context);
Db.VM.set_protection_policy ~__context ~self ~value
)

let set_start_delay ~__context ~self ~value =
if value < 0L then invalid_value
"start_delay must be non-negative"
(Int64.to_string value);
Db.VM.set_start_delay ~__context ~self ~value

let set_shutdown_delay ~__context ~self ~value =
if value < 0L then invalid_value
"shutdown_delay must be non-negative"
(Int64.to_string value);
Db.VM.set_shutdown_delay ~__context ~self ~value

let set_order ~__context ~self ~value =
if value < 0L then invalid_value
"order must be non-negative"
(Int64.to_string value);
Db.VM.set_order ~__context ~self ~value
4 changes: 4 additions & 0 deletions ocaml/xapi/xapi_vm.mli
Expand Up @@ -267,3 +267,7 @@ val copy_bios_strings :
* had already been set. *)

val set_protection_policy : __context:Context.t -> self:API.ref_VM -> value:API.ref_VMPP -> unit

val set_start_delay : __context:Context.t -> self:API.ref_VM -> value:int64 -> unit
val set_shutdown_delay : __context:Context.t -> self:API.ref_VM -> value:int64 -> unit
val set_order : __context:Context.t -> self:API.ref_VM -> value:int64 -> unit

0 comments on commit 6a053b6

Please sign in to comment.