...
This commit is contained in:
35
examples/virt/herorun/basic_example.vsh
Normal file
35
examples/virt/herorun/basic_example.vsh
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.virt.herorun
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
// Create container factory
|
||||
mut factory := herorun.new(reset: false)!
|
||||
|
||||
// Create a new Alpine container
|
||||
mut container := factory.new(name: 'test-alpine', image: .alpine_3_20)!
|
||||
|
||||
// Start the container
|
||||
container.start()!
|
||||
|
||||
// Execute commands in the container
|
||||
result := container.exec(cmd: 'ls -la /', stdout: true)!
|
||||
console.print_debug('Container ls result: ${result}')
|
||||
|
||||
// Test file operations
|
||||
container.exec(cmd: 'echo "Hello from container" > /tmp/test.txt', stdout: false)!
|
||||
content := container.exec(cmd: 'cat /tmp/test.txt', stdout: false)!
|
||||
console.print_debug('File content: ${content}')
|
||||
|
||||
// Get container status and resource usage
|
||||
status := container.status()!
|
||||
cpu := container.cpu_usage()!
|
||||
mem := container.mem_usage()!
|
||||
|
||||
console.print_debug('Container status: ${status}')
|
||||
console.print_debug('CPU usage: ${cpu}%')
|
||||
console.print_debug('Memory usage: ${mem} MB')
|
||||
|
||||
// Clean up
|
||||
container.stop()!
|
||||
container.delete()!
|
||||
36
examples/virt/herorun/builder_integration.vsh
Normal file
36
examples/virt/herorun/builder_integration.vsh
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.virt.herorun
|
||||
import freeflowuniverse.herolib.builder
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
// Create container
|
||||
mut factory := herorun.new()!
|
||||
mut container := factory.new(name: 'builder-test', image: .ubuntu_24_04)!
|
||||
container.start()!
|
||||
|
||||
// Get builder node for the container
|
||||
mut node := container.node()!
|
||||
|
||||
// Use builder methods to interact with container
|
||||
node.file_write('/tmp/script.sh', '
|
||||
#!/bin/bash
|
||||
echo "Running from builder node"
|
||||
whoami
|
||||
pwd
|
||||
ls -la /
|
||||
')!
|
||||
|
||||
result := node.exec(cmd: 'chmod +x /tmp/script.sh && /tmp/script.sh', stdout: true)!
|
||||
console.print_debug('Builder execution result: ${result}')
|
||||
|
||||
// Test file operations through builder
|
||||
exists := node.file_exists('/tmp/script.sh')
|
||||
console.print_debug('Script exists: ${exists}')
|
||||
|
||||
content := node.file_read('/tmp/script.sh')!
|
||||
console.print_debug('Script content: ${content}')
|
||||
|
||||
// Clean up
|
||||
container.stop()!
|
||||
container.delete()!
|
||||
4
examples/virt/herorun/herorun2.vsh
Normal file
4
examples/virt/herorun/herorun2.vsh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.virt.herorun
|
||||
|
||||
Reference in New Issue
Block a user