-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from lindig/json-interface
CP-17112 New JSON interface for more control over reaction to next shutdown message
- Loading branch information
Showing
14 changed files
with
270 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
xen-test-vm - minimal VM kernel for testing Xen | ||
|
||
This code builds a minimal kernel (or VM) that can be run on a Xen | ||
hypervisor for exercising tests. The behaviour of the kernel can be | ||
controlled with a JSON record that can be passed to the kernel via the | ||
XenStore. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
opam-version: "1.2" | ||
name: "xen-test-vm" | ||
version: "0.2" | ||
maintainer: "Christian Lindig <[email protected]>" | ||
authors: "Christian Lindig <[email protected]>" | ||
build: [ | ||
[make] | ||
] | ||
install: [ | ||
make "PREFIX=%{prefix}%" "install" | ||
] | ||
remove: [ | ||
make "PREFIX=%{prefix}%" "remove" | ||
] | ||
homepage: "https://github.com/lindig/xen-test-vm" | ||
dev-repo: "https://github.com/lindig/xen-test-vm" | ||
bug-reports: "https://github.com/lindig/xen-test-vm" | ||
|
||
depends: [ | ||
"mirage-xen" | ||
"mirage-console" | ||
"mirage-bootvar-xen" | ||
"mirage" | ||
"yojson" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
(* vim: set et sw=2 ts=2 *) | ||
|
||
module Y = Yojson.Basic | ||
module U = Yojson.Basic.Util | ||
|
||
exception Error of string | ||
let error fmt = Printf.ksprintf (fun msg -> raise (Error msg)) fmt | ||
|
||
(** actions a guest can take *) | ||
type action = | ||
| Suspend | ||
| PowerOff | ||
| Reboot | ||
| Halt | ||
| Crash | ||
| Ignore | ||
|
||
(** how is a control message from the host acknowledged by the guest *) | ||
type ack = | ||
| AckOK (* ack by putting empty string *) | ||
| AckWrite of string (* ack by putting string *) | ||
| AckNone (* don't ack *) | ||
| AckDelete (* delete key /control/shutdown *) | ||
|
||
(** message to a guest *) | ||
type t = | ||
| Now of action | ||
| OnShutdown of ack * action | ||
|
||
let action = function | ||
| "suspend" -> Suspend | ||
| "poweroff" -> PowerOff | ||
| "reboot" -> Reboot | ||
| "halt" -> Halt | ||
| "crash" -> Crash | ||
| "ignore" -> Ignore | ||
| x -> error "unknown action: %s" x | ||
|
||
let do_when ack action = function | ||
| "now" -> Now(action) | ||
| "onshutdown"-> OnShutdown(ack, action) | ||
| x -> error "unknown when: %s" x | ||
|
||
let ack = function | ||
| "ok" -> AckOK | ||
| "none" -> AckNone | ||
| "delete" -> AckDelete | ||
| x -> AckWrite(x) | ||
|
||
let from_string str = | ||
try | ||
let json = Y.from_string str in | ||
let ack' = json |> U.member "ack" |> U.to_string |> ack in | ||
let action' = json |> U.member "action" |> U.to_string |> action in | ||
json | ||
|> U.member "when" | ||
|> U.to_string | ||
|> do_when ack' action' | ||
with | ||
Yojson.Json_error msg -> error "bad json: %s" msg | ||
|
||
|
Oops, something went wrong.