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 9977fe2
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 4 deletions.
2 changes: 1 addition & 1 deletion auraed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion auraed/src/vms/vm_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions auraed/tests/vms_start_must_start_vm_with_auraed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
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 9977fe2

Please sign in to comment.