Skip to content

Commit 31a30ff

Browse files
committed
xapi-cli-server: Add rate limit CLI operations
Signed-off-by: Christian Pardillo Laursen <[email protected]>
1 parent fb93ab8 commit 31a30ff

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

ocaml/xapi-cli-server/cli_frontend.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,6 +3869,18 @@ let rec cmdtable_data : (string * cmd_spec) list =
38693869
; flags= []
38703870
}
38713871
)
3872+
; ( "rate-limit-create"
3873+
, {
3874+
reqd= ["client-id"; "burst-size"; "fill-rate"]
3875+
; optn= []
3876+
; help=
3877+
"Add a rate limit to a XAPI client, by specifying fill rate \
3878+
(requests per second) and burst size (maximum number of requests at \
3879+
once)"
3880+
; implementation= No_fd Cli_operations.Rate_limit.create
3881+
; flags= []
3882+
}
3883+
)
38723884
]
38733885

38743886
let cmdtable : (string, cmd_spec) Hashtbl.t = Hashtbl.create 50

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8179,3 +8179,23 @@ module VM_group = struct
81798179
in
81808180
Client.VM_group.destroy ~rpc ~session_id ~self:ref
81818181
end
8182+
8183+
module Rate_limit = struct
8184+
let create printer rpc session_id params =
8185+
let client_id = List.assoc "client-id" params in
8186+
let burst_size = float_of_string (List.assoc "burst-size" params) in
8187+
let fill_rate = float_of_string (List.assoc "fill-rate" params) in
8188+
let ref =
8189+
Client.Rate_limit.create ~rpc ~session_id ~client_id ~burst_size
8190+
~fill_rate
8191+
in
8192+
let uuid = Client.Rate_limit.get_uuid ~rpc ~session_id ~self:ref in
8193+
printer (Cli_printer.PMsg uuid)
8194+
8195+
let destroy _printer rpc session_id params =
8196+
let ref =
8197+
Client.Rate_limit.get_by_uuid ~rpc ~session_id
8198+
~uuid:(List.assoc "uuid" params)
8199+
in
8200+
Client.Rate_limit.destroy ~rpc ~session_id ~self:ref
8201+
end

ocaml/xapi-cli-server/records.ml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5933,3 +5933,38 @@ let pci_record rpc session_id pci =
59335933
()
59345934
]
59355935
}
5936+
5937+
let rate_limit_record rpc session_id rate_limit =
5938+
let _ref = ref rate_limit in
5939+
let empty_record =
5940+
ToGet (fun () -> Client.Rate_limit.get_record ~rpc ~session_id ~self:!_ref)
5941+
in
5942+
let record = ref empty_record in
5943+
let x () = lzy_get record in
5944+
{
5945+
setref=
5946+
(fun r ->
5947+
_ref := r ;
5948+
record := empty_record
5949+
)
5950+
; setrefrec=
5951+
(fun (a, b) ->
5952+
_ref := a ;
5953+
record := Got b
5954+
)
5955+
; record= x
5956+
; getref= (fun () -> !_ref)
5957+
; fields=
5958+
[
5959+
make_field ~name:"uuid" ~get:(fun () -> (x ()).API.rate_limit_uuid) ()
5960+
; make_field ~name:"client_id"
5961+
~get:(fun () -> (x ()).API.rate_limit_client_id)
5962+
()
5963+
; make_field ~name:"burst_size"
5964+
~get:(fun () -> string_of_float (x ()).API.rate_limit_burst_size)
5965+
()
5966+
; make_field ~name:"fill_rate"
5967+
~get:(fun () -> string_of_float (x ()).API.rate_limit_fill_rate)
5968+
()
5969+
]
5970+
}

0 commit comments

Comments
 (0)