Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: adress renaming (#191), also check in usable policy that block is >= 0 #192

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions client/albatross_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ let output_result ((hdr, reply) as wire) =
| `Unikernel_image (compressed, image) ->
let name = hdr.Vmm_commands.name in
write_to_file name compressed image
| `Old_unikernels vms ->
| `Old_unikernels unikernels ->
List.iter (fun (name, cfg) ->
if String.length cfg.Vmm_core.Unikernel.image > 0 then
write_to_file name cfg.compressed cfg.image)
vms
unikernels
| `Block_device_image (compressed, image) ->
let name = hdr.Vmm_commands.name in
write_to_file name compressed image
Expand Down Expand Up @@ -175,7 +175,7 @@ let prepare_update ~happy_eyeballs level host dryrun = function
Lwt.return (Error Communication_failed)
| Error _ -> Lwt.return (Error Communication_failed)

let create_vm force image cpuid memory argv block_devices bridges compression restart_on_fail exit_codes =
let create_unikernel force image cpuid memory argv block_devices bridges compression restart_on_fail exit_codes =
let ( let* ) = Result.bind in
let* () =
if Vmm_core.String_set.(cardinal (of_list (List.map (fun (n, _, _) -> n) bridges))) = List.length bridges then
Expand Down Expand Up @@ -222,15 +222,15 @@ let create_block size compression data =
else
Error (`Msg "data exceeds size")

let policy vms memory cpus block bridgesl =
let policy unikernels memory cpus block bridgesl =
let bridges = Vmm_core.String_set.of_list bridgesl
and cpuids = Vmm_core.IS.of_list cpus
in
if not (Vmm_core.String_set.cardinal bridges = List.length bridgesl) then
Logs.warn (fun m -> m "Bridges is not a set");
if not (Vmm_core.IS.cardinal cpuids = List.length cpus) then
Logs.warn (fun m -> m "CPUids is not a set");
Vmm_core.Policy.{ vms ; cpuids ; memory ; block ; bridges }
Vmm_core.Policy.{ unikernels ; cpuids ; memory ; block ; bridges }

let to_exit_code = function
| Error `Eof -> Error Success
Expand Down Expand Up @@ -668,8 +668,8 @@ let info_policy () path =
let remove_policy () path =
jump (`Policy_cmd `Policy_remove) (Vmm_core.Name.create_of_path path)

let add_policy () vms memory cpus block bridges path d cert key ca key_type tmpdir =
let p = policy vms memory cpus block bridges in
let add_policy () unikernels memory cpus block bridges path d cert key ca key_type tmpdir =
let p = policy unikernels memory cpus block bridges in
match Vmm_core.Policy.usable p with
| Error `Msg msg ->
Logs.err (fun m -> m "%s" msg);
Expand All @@ -689,7 +689,7 @@ let destroy () = jump (`Unikernel_cmd `Unikernel_destroy)

let create () force image cpuid memory argv block network compression restart_on_fail exit_code
name d cert key ca key_type tmpdir =
match create_vm force image cpuid memory argv block network (compress_default compression d) restart_on_fail exit_code with
match create_unikernel force image cpuid memory argv block network (compress_default compression d) restart_on_fail exit_code with
| Ok cmd -> jump (`Unikernel_cmd cmd) name d cert key ca key_type tmpdir
| Error _ as e -> e

Expand Down Expand Up @@ -972,7 +972,7 @@ let cpus =
let doc = "CPUids to allow for this policy (argument may be repeated)." in
Arg.(value & opt_all int [] & info [ "cpu" ] ~doc)

let vms =
let unikernels =
let doc = "Number of unikernels to allow running at the same time." in
Arg.(required & pos 1 (some int) None & info [] ~doc ~docv:"UNIKERNELS")

Expand Down Expand Up @@ -1016,7 +1016,7 @@ let cpu =
let doc = "CPUid to use." in
Arg.(value & opt int 0 & info [ "cpu" ] ~doc)

let vm_mem =
let unikernel_mem =
let doc = "Memory to assign (in MB)." in
Arg.(value & opt int 32 & info [ "mem" ] ~doc)

Expand Down Expand Up @@ -1127,23 +1127,23 @@ let path =
let doc = "Path to unikernels." in
Arg.(required & pos 0 (some path_c) None & info [] ~doc ~docv:"PATH")

let vm_c = Arg.conv (Name.of_string, Name.pp)
let unikernel_c = Arg.conv (Name.of_string, Name.pp)

let opt_vm_name =
let opt_unikernel_name =
let doc = "Name of unikernel." in
Arg.(value & opt vm_c Name.root & info [ "n" ; "name"] ~doc)
Arg.(value & opt unikernel_c Name.root & info [ "n" ; "name"] ~doc)

let vm_name =
let unikernel_name =
let doc = "Name of unikernel." in
Arg.(required & pos 0 (some vm_c) None & info [] ~doc ~docv:"UNIKERNEL-NAME")
Arg.(required & pos 0 (some unikernel_c) None & info [] ~doc ~docv:"UNIKERNEL-NAME")

let block_name =
let doc = "Name of block device." in
Arg.(required & pos 0 (some vm_c) None & info [] ~doc ~docv:"BLOCK-NAME")
Arg.(required & pos 0 (some unikernel_c) None & info [] ~doc ~docv:"BLOCK-NAME")

let opt_block_name =
let doc = "Name of block device." in
Arg.(value & opt vm_c Name.root & info [ "name" ] ~doc)
Arg.(value & opt unikernel_c Name.root & info [ "name" ] ~doc)

let remote_host default_port =
let parse s =
Expand Down Expand Up @@ -1225,7 +1225,7 @@ let destroy_cmd =
`P "Destroy a unikernel."]
in
let term =
Term.(term_result (const destroy $ (Albatross_cli.setup_log (const false)) $ vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const destroy $ (Albatross_cli.setup_log (const false)) $ unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "destroy" ~doc ~man ~exits
in
Cmd.v info term
Expand All @@ -1237,7 +1237,7 @@ let restart_cmd =
`P "Restarts a unikernel."]
in
let term =
Term.(term_result (const restart $ (Albatross_cli.setup_log (const false)) $ vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const restart $ (Albatross_cli.setup_log (const false)) $ unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "restart" ~doc ~man ~exits
in
Cmd.v info term
Expand All @@ -1261,7 +1261,7 @@ let info_cmd =
`P "Shows information about unikernels."]
in
let term =
Term.(term_result (const info_ $ (Albatross_cli.setup_log (const false)) $ opt_vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const info_ $ (Albatross_cli.setup_log (const false)) $ opt_unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "info" ~doc ~man ~exits
in
Cmd.v info term
Expand All @@ -1273,7 +1273,7 @@ let get_cmd =
`P "Downloads a unikernel image from albatross to disk."]
in
let term =
Term.(term_result (const get $ (Albatross_cli.setup_log (const false)) $ compress_level $ vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const get $ (Albatross_cli.setup_log (const false)) $ compress_level $ unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "get" ~doc ~man ~exits
in
Cmd.v info term
Expand All @@ -1297,7 +1297,7 @@ let add_policy_cmd =
`P "Adds a policy."]
in
let term =
Term.(term_result (const add_policy $ (Albatross_cli.setup_log (const false)) $ vms $ mem $ cpus $ opt_block_size $ bridge $ path $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const add_policy $ (Albatross_cli.setup_log (const false)) $ unikernels $ mem $ cpus $ opt_block_size $ bridge $ path $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "add-policy" ~doc ~man ~exits
in
Cmd.v info term
Expand All @@ -1309,7 +1309,7 @@ let create_cmd =
`P "Creates a unikernel."]
in
let term =
Term.(term_result (const create $ (Albatross_cli.setup_log (const false)) $ force $ image $ cpu $ vm_mem $ args $ block $ net $ compress_level $ restart_on_fail $ exit_code $ vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const create $ (Albatross_cli.setup_log (const false)) $ force $ image $ cpu $ unikernel_mem $ args $ block $ net $ compress_level $ restart_on_fail $ exit_code $ unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "create" ~doc ~man ~exits
in
Cmd.v info term
Expand All @@ -1321,7 +1321,7 @@ let console_cmd =
`P "Shows console output of a unikernel."]
in
let term =
Term.(term_result (const console $ (Albatross_cli.setup_log (const false)) $ since $ count $ vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const console $ (Albatross_cli.setup_log (const false)) $ since $ count $ unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "console" ~doc ~man ~exits
in
Cmd.v info term
Expand All @@ -1333,7 +1333,7 @@ let stats_subscribe_cmd =
`P "Shows statistics of unikernel."]
in
let term =
Term.(term_result (const stats_subscribe $ (Albatross_cli.setup_log (const false)) $ opt_vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const stats_subscribe $ (Albatross_cli.setup_log (const false)) $ opt_unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "stats" ~doc ~man ~exits
in
Cmd.v info term
Expand All @@ -1345,7 +1345,7 @@ let stats_remove_cmd =
`P "Removes statistics of unikernel."]
in
let term =
Term.(term_result (const stats_remove $ (Albatross_cli.setup_log (const false)) $ opt_vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const stats_remove $ (Albatross_cli.setup_log (const false)) $ opt_unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "stats-remove" ~doc ~man ~exits
in
Cmd.v info term
Expand All @@ -1357,7 +1357,7 @@ let stats_add_cmd =
`P "Add unikernel to statistics gathering."]
in
let term =
Term.(term_result (const stats_add $ (Albatross_cli.setup_log (const false)) $ vmm_dev $ pid_req0 $ bridge_taps $ opt_vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
Term.(term_result (const stats_add $ (Albatross_cli.setup_log (const false)) $ vmm_dev $ pid_req0 $ bridge_taps $ opt_unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir))
and info = Cmd.info "stats-add" ~doc ~man ~exits
in
Cmd.v info term
Expand Down Expand Up @@ -1429,7 +1429,7 @@ let update_cmd =
`P "Check and update a unikernel from the binary repository."]
in
let term =
Term.(const update $ (Albatross_cli.setup_log (const false)) $ http_host $ dryrun $ compress_level $ vm_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir)
Term.(const update $ (Albatross_cli.setup_log (const false)) $ http_host $ dryrun $ compress_level $ unikernel_name $ dst $ ca_cert $ ca_key $ server_ca $ pub_key_type $ Albatross_cli.tmpdir)
and info = Cmd.info "update" ~doc ~man ~exits
in
Cmd.v info term
Expand Down
38 changes: 19 additions & 19 deletions daemon/albatross_influx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module P = struct

let i64 i = Printf.sprintf "%Lui" i

let encode_ru vm ru =
let encode_ru unikernel ru =
let fields =
[ "utime", tv ru.utime ;
"stime", tv ru.stime ;
Expand All @@ -96,9 +96,9 @@ module P = struct
]
in
let fields = List.map (fun (k, v) -> k ^ "=" ^ v) fields in
Printf.sprintf "resource_usage,vm=%s %s" vm (String.concat "," fields)
Printf.sprintf "resource_usage,vm=%s %s" unikernel (String.concat "," fields)

let encode_kinfo_mem vm mem =
let encode_kinfo_mem unikernel mem =
let now = Unix.gettimeofday () in
let started =
Int64.to_float (fst mem.start) +. (float_of_int (snd mem.start) /. 1_000_000.)
Expand All @@ -117,9 +117,9 @@ module P = struct
]
in
let fields = List.map (fun (k, v) -> k ^ "=" ^ v) fields in
Printf.sprintf "kinfo_mem,vm=%s %s" vm (String.concat "," fields)
Printf.sprintf "kinfo_mem,vm=%s %s" unikernel (String.concat "," fields)

let encode_vmm vm xs =
let encode_vmm unikernel xs =
let escape s =
let cutted = String.split_on_char ',' s in
let cutted = String.concat "\\," cutted in
Expand All @@ -128,13 +128,13 @@ module P = struct
let cutted = String.split_on_char '=' cutted in
String.concat "\\=" cutted
in
Printf.sprintf "vmm,vm=%s %s" vm
Printf.sprintf "vmm,vm=%s %s" unikernel
(String.concat ","
(List.map (fun (k, v) -> (escape k) ^ "=" ^ (i64 v)) xs))

let i32 i = Printf.sprintf "%lui" i

let encode_if vm ifd =
let encode_if unikernel ifd =
let fields =
(* TODO: flags *)
[ "send_queue_length", i32 ifd.send_length ;
Expand All @@ -157,7 +157,7 @@ module P = struct
in
let fields = List.map (fun (k, v) -> k ^ "=" ^ v) fields in
Printf.sprintf "interface,vm=%s,bridge=%s %s"
vm ifd.bridge (String.concat "," fields)
unikernel ifd.bridge (String.concat "," fields)
end

let command = ref 1L
Expand Down Expand Up @@ -233,10 +233,10 @@ let rec read_sock_write_tcp drop c ?fd fam addr =
Lwt.return (Some fd) >>= fun fd ->
read_sock_write_tcp drop c ?fd fam addr

let query_sock vm c =
let header = Vmm_commands.header ~sequence:!command vm in
let query_sock unikernel c =
let header = Vmm_commands.header ~sequence:!command unikernel in
command := Int64.succ !command ;
Logs.debug (fun m -> m "%Lu requesting %a via socket" !command Name.pp vm) ;
Logs.debug (fun m -> m "%Lu requesting %a via socket" !command Name.pp unikernel) ;
Vmm_lwt.write_wire c (header, `Command (`Stats_cmd `Stats_subscribe))

let rec maybe_connect () =
Expand All @@ -251,7 +251,7 @@ let rec maybe_connect () =
Logs.debug (fun m -> m "connected");
Lwt.return c

let client influx vm drop =
let client influx unikernel drop =
match influx with
| None -> Lwt.return (Error (`Msg "influx host not provided"))
| Some (ip, port) ->
Expand All @@ -276,7 +276,7 @@ let client influx vm drop =
let rec loop () =
(* start a socket connection to vmm_stats *)
maybe_connect () >>= fun c ->
query_sock vm c >>= function
query_sock unikernel c >>= function
| Error e ->
let err =
Error (`Msg (Fmt.str "error %s while writing to stat socket" (str_of_e e)))
Expand All @@ -288,22 +288,22 @@ let client influx vm drop =
in
loop ()

let run_client _ influx vm drop tmpdir =
let run_client _ influx unikernel drop tmpdir =
Sys.(set_signal sigpipe Signal_ignore) ;
Albatross_cli.set_tmpdir tmpdir;
Lwt_main.run (client influx vm drop)
Lwt_main.run (client influx unikernel drop)

open Cmdliner

let drop_label =
let doc = "Drop unikernel path" in
Arg.(value & flag & info [ "drop-label" ] ~doc)

let vm_c = Arg.conv (Name.of_string, Name.pp)
let unikernel_c = Arg.conv (Name.of_string, Name.pp)

let opt_vm_name =
let opt_unikernel_name =
let doc = "name of unikernel." in
Arg.(value & opt vm_c Name.root & info [ "n" ; "name"] ~doc)
Arg.(value & opt unikernel_c Name.root & info [ "n" ; "name"] ~doc)

let cmd =
let doc = "Albatross Influx connector" in
Expand All @@ -313,7 +313,7 @@ let cmd =
statistics and pushes them via TCP to influxdb";
] in
let term =
Term.(term_result (const run_client $ (Albatross_cli.setup_log Albatrossd_utils.syslog) $ Albatrossd_utils.influx $ opt_vm_name $ drop_label $ Albatross_cli.tmpdir))
Term.(term_result (const run_client $ (Albatross_cli.setup_log Albatrossd_utils.syslog) $ Albatrossd_utils.influx $ opt_unikernel_name $ drop_label $ Albatross_cli.tmpdir))
and info = Cmd.info "albatross-influx" ~version:Albatross_cli.version ~doc ~man
in
Cmd.v info term
Expand Down
20 changes: 10 additions & 10 deletions daemon/albatrossd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let rec create stat_out cons_out data_out name config =
| Error (`Msg msg) ->
Logs.err (fun m -> m "create (exec) failed %s" msg) ;
Lwt.return (None, fail_cont ())
| Ok (state', stat, data, name, vm) ->
| Ok (state', stat, data, name, unikernel) ->
state := state';
(if Unikernel.restart_handler config then
match Vmm_vmmd.register_restart !state name Lwt.task with
Expand All @@ -42,18 +42,18 @@ let rec create stat_out cons_out data_out name config =
state := state';
if may && should_restart config name r then
create stat_out cons_out stub_data_out
name vm.Unikernel.config
name unikernel.Unikernel.config
else
Lwt.return_unit)));
stat_out "setting up stat" stat >|= fun () ->
(Some vm, data)) >>= fun (started, data) ->
(Some unikernel, data)) >>= fun (started, data) ->
(match started with
| None -> ()
| Some vm ->
| Some unikernel ->
Lwt.async (fun () ->
Vmm_lwt.wait_and_clear vm.Unikernel.pid >>= fun r ->
Vmm_lwt.wait_and_clear unikernel.Unikernel.pid >>= fun r ->
Lwt_mutex.with_lock create_lock (fun () ->
let state', stat' = Vmm_vmmd.handle_shutdown !state name vm r in
let state', stat' = Vmm_vmmd.handle_shutdown !state name unikernel r in
state := state';
stat_out "handle shutdown stat" stat' >|= fun () ->
let state', waiter_opt = Vmm_vmmd.waiter !state name in
Expand Down Expand Up @@ -94,8 +94,8 @@ let handle cons_out stat_out fd addr =
Lwt_mutex.unlock create_lock;
out wire >|= fun () ->
`Close
| `Create (id, vm) ->
create stat_out cons_out out id vm >|= fun () ->
| `Create (id, unikernel) ->
create stat_out cons_out out id unikernel >|= fun () ->
Lwt_mutex.unlock create_lock;
`Close
| `Wait (who, data) ->
Expand All @@ -105,14 +105,14 @@ let handle cons_out stat_out fd addr =
task >>= fun r ->
out (data r) >|= fun () ->
`Close
| `Wait_and_create (who, (id, vm)) ->
| `Wait_and_create (who, (id, unikernel)) ->
let state', task = Vmm_vmmd.register !state who Lwt.task in
state := state';
Lwt_mutex.unlock create_lock;
task >>= fun r ->
Logs.info (fun m -> m "wait returned %a" pp_process_exit r);
Lwt_mutex.with_lock create_lock (fun () ->
create stat_out cons_out out id vm) >|= fun () ->
create stat_out cons_out out id unikernel) >|= fun () ->
`Close
| `Replace_stats (wire, datas) ->
(Option.fold
Expand Down
Loading
Loading