diff --git a/auraed/Cargo.toml b/auraed/Cargo.toml index e5565b849..945d49da0 100644 --- a/auraed/Cargo.toml +++ b/auraed/Cargo.toml @@ -48,7 +48,7 @@ libcontainer = { git = "https://github.com/containers/youki", rev = "5b62356e377 ] } log = "0.4.21" netlink-packet-route = "0.13.0" # Used for netlink_packet_route::rtnl::address::nlas definition -nix = { workspace = true, features = ["sched", "mount", "signal"] } +nix = { workspace = true, features = ["sched", "mount", "signal", "net"] } oci-spec = "0.6.4" once_cell = "1" procfs = "0.16.0" diff --git a/auraed/src/vms/vm_service.rs b/auraed/src/vms/vm_service.rs index 0cb517bd5..65e45af77 100644 --- a/auraed/src/vms/vm_service.rs +++ b/auraed/src/vms/vm_service.rs @@ -95,7 +95,7 @@ impl vm_service_server::VmService for VmService { Status::internal(format!("Failed to start VM: {:?}", e)) })?; - Ok(Response::new(VmServiceFreeResponse { vm_id: req.vm_id })) + Ok(Response::new(VmServiceFreeResponse {})) } async fn start( diff --git a/auraed/tests/vms_start_must_start_vm_with_auraed.rs b/auraed/tests/vms_start_must_start_vm_with_auraed.rs index 9b8461e0d..06e041903 100644 --- a/auraed/tests/vms_start_must_start_vm_with_auraed.rs +++ b/auraed/tests/vms_start_must_start_vm_with_auraed.rs @@ -13,8 +13,6 @@ * SPDX-License-Identifier: Apache-2.0 * \* -------------------------------------------------------------------------- */ -use std::thread; - use client::discovery::discovery_service::DiscoveryServiceClient; use client::vms::vm_service::VmServiceClient; use client::{Client, ClientError}; diff --git a/auraescript/src/lib.rs b/auraescript/src/lib.rs index 200545835..6e7dfd3e4 100644 --- a/auraescript/src/lib.rs +++ b/auraescript/src/lib.rs @@ -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") @@ -140,6 +141,7 @@ fn stdlib() -> Vec { ops.extend(discovery::op_decls()); ops.extend(health::op_decls()); ops.extend(observe::op_decls()); + ops.extend(vms::op_decls()); ops } diff --git a/auraescript/src/vms.rs b/auraescript/src/vms.rs new file mode 100644 index 000000000..9a9c4ef27 --- /dev/null +++ b/auraescript/src/vms.rs @@ -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); diff --git a/examples/virtual_machines.ts b/examples/virtual_machines.ts new file mode 100755 index 000000000..f26fc0e48 --- /dev/null +++ b/examples/virtual_machines.ts @@ -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({ + 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({ vmId: "ae-sleeper-vm" }); +console.log('Started VM:', created) + +// Wait 5s for the Vm to be ready +wait(5000); + +let machines = await vmService.list({}); +console.log('Listed VMs:', machines) + +// Stop the VM +await vmService.stop({ vmId: "ae-sleeper-vm" }); + +// Wait 5s for the Vm to stop +wait(5000); + +// Free the VM +await vmService.free({ vmId: "ae-sleeper-vm" }); +