This commit is contained in:
2024-12-25 10:11:52 +01:00
parent 38aaba018e
commit 37d2501067
145 changed files with 12629 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
!!hero_code.generate_installer
name:'cloudhypervisor'
classname:'CloudHypervisor'
singleton:1
templates:0
default:1
title:''
supported_platforms:''
reset:0
startupmanager:0
hasconfig:0
build:1

View File

@@ -0,0 +1,109 @@
module cloudhypervisor
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
// import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.installers.ulist
// import freeflowuniverse.herolib.installers.lang.rust
import os
fn installed() !bool {
res := os.execute('${osal.profile_path_source_and()} cloud-hypervisor --version')
if res.exit_code == 0 {
r := res.output.split_into_lines().filter(it.contains('cloud-hypervisor'))
if r.len != 1 {
return error("couldn't parse cloud-hypervisor version, expected 'cloud hypervisor version' on 1 row.\n${res.output}")
}
v := texttools.version(r[0].all_after('ypervisor v'))
// console.print_debug("version: ${v} ${texttools.version(version)}")
if v != texttools.version(version) {
return false
}
} else {
return false
}
return true
}
fn install() ! {
console.print_header('install cloudhypervisor')
// mut installer := get()!
mut url := ''
if osal.is_linux_arm() {
url = 'https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v${version0}/cloud-hypervisor-static-aarch64'
} else if osal.is_linux_intel() {
url = 'https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v${version0}/cloud-hypervisor-static'
} else {
return error('unsuported platform for cloudhypervisor')
}
osal.package_install('
qemu-kvm
bridge-utils
ovmf
swtpm
')!
console.print_header('download ${url}')
dest := osal.download(
url: url
minsize_kb: 1000
dest: '/tmp/cloud-hypervisor'
)!
console.print_debug('download cloudhypervisor done')
osal.cmd_add(
cmdname: 'cloud-hypervisor'
source: '${dest.path}'
)!
}
fn build() ! {
}
// get the Upload List of the files
fn ulist_get() !ulist.UList {
// mut installer := get()!
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{}
}
// uploads to S3 server if configured
fn upload() ! {
// mut installer := get()!
// installers.upload(
// cmdname: 'cloudhypervisor'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/cloudhypervisor'
// )!
}
fn destroy() ! {
osal.process_kill_recursive(name: 'cloud-hypervisor')!
osal.package_remove('
cloudhypervisor
cloud-hypervisor
')!
// will remove all paths where go/bin is found
osal.profile_path_add_remove(paths2delete: 'go/bin')!
cmd := '
set +e
find / -name "*.img" -type f -exec rm -f {} \\;
rm -rf /tmp/cloud-hypervisor*
rm -f /tmp/cloud-hypervisor.sock
rm -f /var/log/cloud-hypervisor.log
umount /mnt/virtiofs
ip link delete tap0 2>/dev/null
ip link delete tap1 2>/dev/null
'
osal.execute_silent(cmd)!
osal.rm('
cloud-hypervisor
/var/lib/cloud-hypervisor/
')!
}

View File

@@ -0,0 +1,79 @@
module cloudhypervisor
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import freeflowuniverse.herolib.ui.console
import time
__global (
cloudhypervisor_global map[string]&CloudHypervisor
cloudhypervisor_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&CloudHypervisor {
return &CloudHypervisor{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
@[params]
pub struct InstallArgs {
pub mut:
reset bool
}
pub fn (mut self CloudHypervisor) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn (mut self CloudHypervisor) build() ! {
switch(self.name)
build()!
}
pub fn (mut self CloudHypervisor) destroy() ! {
switch(self.name)
destroy()!
}
// switch instance to be used for cloudhypervisor
pub fn switch(name string) {
cloudhypervisor_default = name
}

View File

@@ -0,0 +1,26 @@
module cloudhypervisor
import freeflowuniverse.herolib.data.paramsparser
import os
pub const version0 = '41.0'
pub const version = '${version0}.0'
const singleton = true
const default = true
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
pub struct CloudHypervisor {
pub mut:
name string = 'default'
}
fn obj_init(obj_ CloudHypervisor) !CloudHypervisor {
// never call get here, only thing we can do here is work on object itself
mut obj := obj_
return obj
}
// called before start if done
fn configure() ! {
// mut installer := get()!
}

View File

@@ -0,0 +1,34 @@
# cloudhypervisor
To get started
```vlang
import freeflowuniverse.herolib.installers.something. cloudhypervisor
mut installer:= cloudhypervisor.get()!
installer.start()!
```
## example heroscript
```hero
!!cloudhypervisor.install
homedir: '/home/user/cloudhypervisor'
username: 'admin'
password: 'secretpassword'
title: 'Some Title'
host: 'localhost'
port: 8888
```