Skip to content

Commit 555dba8

Browse files
committed
CP-10203: XenAPI: api call for RDP on/off request
Signed-off-by: Hui Zhang <[email protected]>
1 parent 0bbd4f5 commit 555dba8

File tree

8 files changed

+100
-0
lines changed

8 files changed

+100
-0
lines changed

ocaml/idl/api_errors.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ let vm_old_pv_drivers = "VM_OLD_PV_DRIVERS"
174174
let vm_lacks_feature_shutdown = "VM_LACKS_FEATURE_SHUTDOWN"
175175
let vm_lacks_feature_suspend = "VM_LACKS_FEATURE_SUSPEND"
176176
let vm_lacks_feature_vcpu_hotplug = "VM_LACKS_FEATURE_VCPU_HOTPLUG"
177+
let vm_lacks_feature_ts = "VM_LACKS_FEATURE_TS"
177178
let vm_cannot_delete_default_template = "VM_CANNOT_DELETE_DEFAULT_TEMPLATE"
178179
let vm_memory_size_too_low = "VM_MEMORY_SIZE_TOO_LOW"
179180
let vm_memory_target_wait_timeout = "VM_MEMORY_TARGET_WAIT_TIMEOUT"

ocaml/idl/datamodel.ml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ let _ =
623623
~doc:"You attempted an operation which needs the VM hotplug-vcpu feature on a VM which lacks it." ();
624624
error Api_errors.vm_lacks_feature_suspend [ "vm" ]
625625
~doc:"You attempted an operation which needs the VM cooperative suspend feature on a VM which lacks it." ();
626+
error Api_errors.vm_lacks_feature_ts [ "vm" ]
627+
~doc:"You attempted to ask a VM to enable or disable Remote Desktop Protocol but the VM lacks this control feature." ();
626628
error Api_errors.vm_is_template ["vm"]
627629
~doc:"The operation attempted is not valid for a template VM" ();
628630
error Api_errors.other_operation_in_progress ["class"; "object"]
@@ -2090,6 +2092,30 @@ let vm_pool_migrate_complete = call
20902092
~allowed_roles:_R_VM_POWER_ADMIN
20912093
()
20922094

2095+
let vm_beg_rdp_on = call
2096+
~name:"beg_rdp_on"
2097+
~lifecycle:[
2098+
Published, rel_augusta, "Ask the VM to enable Remote Desktop Protocol. Error if the VM is halted or does not advertise this control feature. The VM may or may not cooperate."
2099+
]
2100+
~in_oss_since:None
2101+
~doc:"Ask the VM to enable Remote Desktop Protocol. Error if the VM is halted or does not advertise this control feature. The VM may or may not cooperate."
2102+
~params:[Ref _vm, "vm", "The VM to ask to enable Remote Desktop Protocol"]
2103+
~errs:[Api_errors.vm_bad_power_state; Api_errors.vm_lacks_feature_ts]
2104+
~allowed_roles:_R_VM_OP
2105+
()
2106+
2107+
let vm_beg_rdp_off = call
2108+
~name:"beg_rdp_off"
2109+
~lifecycle:[
2110+
Published, rel_augusta, "Ask the VM to disable Remote Desktop Protocol. Error if the VM is halted or does not advertise this control feature. The VM may or may not cooperate."
2111+
]
2112+
~in_oss_since:None
2113+
~doc:"Ask the VM to disable Remote Desktop Protocol. Error if the VM is halted or does not advertise this control feature. The VM may or may not cooperate."
2114+
~params:[Ref _vm, "vm", "The VM to ask to disable Remote Desktop Protocol"]
2115+
~errs:[Api_errors.vm_bad_power_state; Api_errors.vm_lacks_feature_ts]
2116+
~allowed_roles:_R_VM_OP
2117+
()
2118+
20932119
let host_migrate_receive = call
20942120
~in_oss_since:None
20952121
~in_product_since:rel_tampa
@@ -6742,6 +6768,7 @@ let vm_operations =
67426768
vm_migrate_send;
67436769
vm_get_boot_record; vm_send_sysrq; vm_send_trigger;
67446770
vm_query_services;vm_shutdown;
6771+
vm_beg_rdp_on;vm_beg_rdp_off;
67456772
]
67466773
@ [ "changing_memory_live", "Changing the memory settings";
67476774
"awaiting_memory_live", "Waiting for the memory settings to change";
@@ -6825,6 +6852,8 @@ let vm =
68256852
vm_import_convert;
68266853
vm_set_appliance;
68276854
vm_query_services;
6855+
vm_beg_rdp_on;
6856+
vm_beg_rdp_off;
68286857
]
68296858
~contents:
68306859
([ uid _vm;

ocaml/xapi/cli_frontend.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,24 @@ there are two or more empty CD devices, please use the command 'vbd-insert' and
13351335
flags=[Vm_selectors];
13361336
};
13371337

1338+
"vm-beg-rdp-on",
1339+
{
1340+
reqd=[];
1341+
optn=[];
1342+
help="Ask the VM to enable Remote Desktop Protocol. This relies on support from the guest agent in the VM. The guest may or may not cooperate.";
1343+
implementation=No_fd Cli_operations.vm_beg_rdp_on;
1344+
flags=[Vm_selectors];
1345+
};
1346+
1347+
"vm-beg-rdp-off",
1348+
{
1349+
reqd=[];
1350+
optn=[];
1351+
help="Ask the VM to disable Remote Desktop Protocol. This relies on support from the guest agent in the VM. The guest may or may not cooperate.";
1352+
implementation=No_fd Cli_operations.vm_beg_rdp_off;
1353+
flags=[Vm_selectors];
1354+
};
1355+
13381356
"snapshot-export-to-template",
13391357
{
13401358
reqd=["filename"; "snapshot-uuid"];

ocaml/xapi/cli_operations.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,12 @@ let vm_memory_target_wait printer rpc session_id params =
19631963
let vm=vm.getref () in
19641964
Client.VM.wait_memory_target_live rpc session_id vm) params [])
19651965

1966+
let vm_beg_rdp_on printer rpc session_id params =
1967+
ignore(do_vm_op printer rpc session_id (fun vm -> Client.VM.beg_rdp_on rpc session_id (vm.getref ())) params [])
1968+
1969+
let vm_beg_rdp_off printer rpc session_id params =
1970+
ignore(do_vm_op printer rpc session_id (fun vm -> Client.VM.beg_rdp_off rpc session_id (vm.getref ())) params [])
1971+
19661972
let data_source_to_kvs ds =
19671973
["name_label",ds.API.data_source_name_label;
19681974
"name_description",ds.API.data_source_name_description;

ocaml/xapi/message_forwarding.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,20 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
13061306
update_vbd_operations ~__context ~vm;
13071307
update_vif_operations ~__context ~vm
13081308

1309+
let beg_rdp_on ~__context ~vm =
1310+
info "VM.beg_rdp_on: VM = '%s'" (vm_uuid ~__context vm);
1311+
let local_fn = Local.VM.beg_rdp_on ~vm in
1312+
with_vm_operation ~__context ~self:vm ~doc:"VM.beg_rdp_on" ~op:`beg_rdp_on
1313+
(fun () ->
1314+
forward_vm_op ~local_fn ~__context ~vm (fun session_id rpc -> Client.VM.beg_rdp_on rpc session_id vm))
1315+
1316+
let beg_rdp_off ~__context ~vm =
1317+
info "VM.beg_rdp_off: VM = '%s'" (vm_uuid ~__context vm);
1318+
let local_fn = Local.VM.beg_rdp_off ~vm in
1319+
with_vm_operation ~__context ~self:vm ~doc:"VM.beg_rdp_off" ~op:`beg_rdp_off
1320+
(fun () ->
1321+
forward_vm_op ~local_fn ~__context ~vm (fun session_id rpc -> Client.VM.beg_rdp_off rpc session_id vm))
1322+
13091323
let set_xenstore_data ~__context ~self ~value =
13101324
info "VM.set_xenstore_data: VM = '%s'" (vm_uuid ~__context self);
13111325
Db.VM.set_xenstore_data ~__context ~self ~value;

ocaml/xapi/xapi_vm.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,33 @@ let set_memory_dynamic_range ~__context ~self ~min ~max =
700700
if power_state = `Running
701701
then Xapi_xenops.set_memory_dynamic_range ~__context ~self min max
702702

703+
(* xenstore paths *)
704+
let control_path ~xs ~domid x =
705+
xs.Xenstore.Xs.getdomainpath domid ^ "/control/" ^ x
706+
707+
let is_feature_ts_on ~xs ~domid ~vm =
708+
try
709+
xs.Xenstore.Xs.read (control_path ~xs ~domid "feature-ts") = "1"
710+
with e ->
711+
debug "Exception while reading feature-ts of VM %s (domain %i): %s"
712+
(Ref.string_of vm) domid (Printexc.to_string e);
713+
false
714+
715+
let beg_rdp ~__context ~vm ~enabled =
716+
let domid = Int64.to_int (Db.VM.get_domid ~__context ~self:vm) in
717+
Xenstore.with_xs (fun xs ->
718+
if is_feature_ts_on ~xs ~domid ~vm
719+
then
720+
let control_ts = if enabled then "1" else "0" in
721+
xs.Xenstore.Xs.write (control_path ~xs ~domid "ts") control_ts
722+
else raise (Api_errors.Server_error (Api_errors.vm_lacks_feature_ts, [ Ref.string_of vm ])))
723+
724+
let beg_rdp_on ~__context ~vm =
725+
beg_rdp ~__context ~vm ~enabled:true
726+
727+
let beg_rdp_off ~__context ~vm =
728+
beg_rdp ~__context ~vm ~enabled:false
729+
703730
let send_sysrq ~__context ~vm ~key =
704731
raise (Api_errors.Server_error (Api_errors.not_implemented, [ "send_sysrq" ]))
705732

ocaml/xapi/xapi_vm.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,6 @@ val import_convert : __context:Context.t -> _type:string -> username:string -> p
244244
(** [query_services __context self] returns a Map of service type -> name label provided
245245
by the specific VM. *)
246246
val query_services : __context:Context.t -> self:API.ref_VM -> (string * string) list
247+
248+
val beg_rdp_on : __context:Context.t -> vm:API.ref_VM -> unit
249+
val beg_rdp_off: __context:Context.t -> vm:API.ref_VM -> unit

ocaml/xapi/xapi_vm_lifecycle.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ let allowed_power_states ~__context ~vmr ~(op:API.vm_operations) =
8080
| `get_boot_record
8181
| `shutdown
8282
| `hard_shutdown
83+
| `beg_rdp_on
84+
| `beg_rdp_off
8385
-> [`Paused; `Suspended; `Running]
8486
| `assert_operation_valid
8587
| `metadata_export

0 commit comments

Comments
 (0)