Ergonomics (#41)

The info subcommands for {unikernel,block,policy} never error

Before, running the commands block, info or policy when no block
devices, unikernels or policies respectively were set up the command
would report an error and give the user a dangerous-looking WARNING
saying the command failed:

    $ albatross-client-local block
    albatross-client-local: [WARNING] host [vm: ]: command failed block: not found

Now instead the commands will report success with a message stating
there are no objects.

Co-authored-by: Hannes Mehnert <hannes@mehnert.org>
This commit is contained in:
Reynir Björnsson 2020-11-14 22:27:55 +01:00 committed by GitHub
parent 1986ca2a1d
commit f954955dd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 22 deletions

View file

@ -141,12 +141,17 @@ type success = [
let pp_block ppf (id, size, active) =
Fmt.pf ppf "block %a size %d MB active %B" Name.pp id size active
let my_fmt_list empty pp_elt ppf xs =
match xs with
| [] -> Fmt.string ppf empty
| _ -> Fmt.(list ~sep:(unit "@.") pp_elt ppf xs)
let pp_success ppf = function
| `Empty -> Fmt.string ppf "success"
| `String data -> Fmt.pf ppf "success: %s" data
| `Policies ps -> Fmt.(list ~sep:(unit "@.") (pair ~sep:(unit ": ") Name.pp Policy.pp)) ppf ps
| `Unikernels vms -> Fmt.(list ~sep:(unit "@.") (pair ~sep:(unit ": ") Name.pp Unikernel.pp_config)) ppf vms
| `Block_devices blocks -> Fmt.(list ~sep:(unit "@.") pp_block) ppf blocks
| `Policies ps -> my_fmt_list "no policies" Fmt.(pair ~sep:(unit ": ") Name.pp Policy.pp) ppf ps
| `Unikernels vms -> my_fmt_list "no unikernels" Fmt.(pair ~sep:(unit ": ") Name.pp Unikernel.pp_config) ppf vms
| `Block_devices blocks -> my_fmt_list "no block devices" pp_block ppf blocks
type res = [
| `Command of t

View file

@ -212,11 +212,6 @@ let handle_policy_cmd t id = function
(fun prefix policy policies-> (prefix, policy) :: policies)
[]
in
match policies with
| [] ->
Logs.debug (fun m -> m "policies: couldn't find %a" Name.pp id) ;
Error (`Msg "policy: not found")
| _ ->
Ok (t, `End (`Success (`Policies policies)))
let handle_unikernel_cmd t id = function
@ -229,13 +224,7 @@ let handle_unikernel_cmd t id = function
(id, cfg) :: vms)
[]
in
begin match vms with
| [] ->
Logs.debug (fun m -> m "info: couldn't find %a" Name.pp id) ;
Error (`Msg "info: no unikernel found")
| _ ->
Ok (t, `End (`Success (`Unikernels vms)))
end
| `Unikernel_get ->
Logs.debug (fun m -> m "get %a" Name.pp id) ;
begin match Vmm_trie.find id t.resources.Vmm_resources.unikernels with
@ -304,11 +293,6 @@ let handle_block_cmd t id = function
(fun prefix (size, active) blocks -> (prefix, size, active) :: blocks)
[]
in
match blocks with
| [] ->
Logs.debug (fun m -> m "block: couldn't find %a" Name.pp id) ;
Error (`Msg "block: not found")
| _ ->
Ok (t, `End (`Success (`Block_devices blocks)))
let handle_command t (header, payload) =