Skip to content

Commit

Permalink
feat: add vms to auraescript
Browse files Browse the repository at this point in the history
  • Loading branch information
mccormickt committed Aug 7, 2024
1 parent cef25c2 commit 7bda5a3
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
2 changes: 2 additions & 0 deletions auraescript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ mod cri;
mod discovery;
mod health;
mod observe;
mod vms;

fn get_error_class_name(e: &AnyError) -> &'static str {
deno_runtime::errors::get_error_class_name(e).unwrap_or("Error")
Expand Down Expand Up @@ -140,6 +141,7 @@ fn stdlib() -> Vec<deno_core::OpDecl> {
ops.extend(discovery::op_decls());
ops.extend(health::op_decls());
ops.extend(observe::op_decls());
ops.extend(vms::op_decls());
ops
}

Expand Down
33 changes: 33 additions & 0 deletions auraescript/src/vms.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* -------------------------------------------------------------------------- *\
* Apache 2.0 License Copyright © 2022-2023 The Aurae Authors *
* *
* +--------------------------------------------+ *
* | █████╗ ██╗ ██╗██████╗ █████╗ ███████╗ | *
* | ██╔══██╗██║ ██║██╔══██╗██╔══██╗██╔════╝ | *
* | ███████║██║ ██║██████╔╝███████║█████╗ | *
* | ██╔══██║██║ ██║██╔══██╗██╔══██║██╔══╝ | *
* | ██║ ██║╚██████╔╝██║ ██║██║ ██║███████╗ | *
* | ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ | *
* +--------------------------------------------+ *
* *
* Distributed Systems Runtime *
* *
* -------------------------------------------------------------------------- *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
\* -------------------------------------------------------------------------- */

#![allow(non_snake_case)]

macros::ops_generator!("../api/v0/vms/vms.proto", vms, VmService);
76 changes: 76 additions & 0 deletions examples/virtual_machines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env auraescript
/* -------------------------------------------------------------------------- *\
* Apache 2.0 License Copyright © 2022-2023 The Aurae Authors *
* *
* +--------------------------------------------+ *
* | █████╗ ██╗ ██╗██████╗ █████╗ ███████╗ | *
* | ██╔══██╗██║ ██║██╔══██╗██╔══██╗██╔════╝ | *
* | ███████║██║ ██║██████╔╝███████║█████╗ | *
* | ██╔══██║██║ ██║██╔══██╗██╔══██║██╔══╝ | *
* | ██║ ██║╚██████╔╝██║ ██║██║ ██║███████╗ | *
* | ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ | *
* +--------------------------------------------+ *
* *
* Distributed Systems Runtime *
* * * -------------------------------------------------------------------------- * * *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
\* -------------------------------------------------------------------------- */
import * as aurae from "../auraescript/gen/aurae.ts";
import * as cells from "../auraescript/gen/cells.ts";
import * as vms from "../auraescript/gen/vms.ts";

function wait(ms) {
var start = new Date().getTime();
var end = start;
while (end < start + ms) {
end = new Date().getTime();
}
}

const client = await aurae.createClient();
const vmService = new vms.VmServiceClient(client);

let vm = await vmService.create(<vms.VmServiceCreateRequest>{
machine: vms.VirtualMachine.fromPartial({
id: "ae-sleeper-vm",
vcpuCount: 2,
memSizeMb: 1024,
kernelImgPath: "/var/lib/aurae/vm/kernel/vmlinux.bin",
kernelArgs: ["console=hvc0", "root=/dev/vda1", "rw"],
rootDrive: vms.RootDrive.fromPartial({
imagePath: "/var/lib/aurae/vm/image/disk.raw"
}),
})
});
console.log('Created VM:', vm)

// Start and list the VMs
let created = await vmService.start(<vms.VmServiceStartRequest>{ vmId: "ae-sleeper-vm" });
console.log('Started VM:', created)

// Wait 5s for the Vm to be ready
wait(5000);

let machines = await vmService.list(<vms.VmServiceListRequest>{});
console.log('Listed VMs:', machines)

// Stop the VM
await vmService.stop(<vms.VmServiceStopRequest>{ vmId: "ae-sleeper-vm" });

// Wait 5s for the Vm to stop
wait(5000);

// Free the VM
await vmService.free(<vms.VmServiceFreeRequest>{ vmId: "ae-sleeper-vm" });

0 comments on commit 7bda5a3

Please sign in to comment.