...
This commit is contained in:
Binary file not shown.
@@ -1,26 +1,25 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.mycelium
|
||||
import freeflowuniverse.herolib.clients.mycelium
|
||||
|
||||
mycelium.delete()!
|
||||
|
||||
mut r:=mycelium.inspect()!
|
||||
println("My pub key: ${r.public_key}")
|
||||
mut r := mycelium.inspect()!
|
||||
println('My pub key: ${r.public_key}')
|
||||
|
||||
mut client := mycelium.get()!
|
||||
println(client)
|
||||
|
||||
// Send a message to a node by public key
|
||||
// Parameters: public_key, payload, topic, wait_for_reply
|
||||
msg := client.send_msg(
|
||||
r.public_key, // destination public key
|
||||
'Hello World', // message payload
|
||||
'greetings', // optional topic
|
||||
false // wait for reply
|
||||
)!
|
||||
msg := client.send_msg(r.public_key, // destination public key
|
||||
'Hello World', // message payload
|
||||
'greetings', // optional topic
|
||||
false // wait for reply
|
||||
)!
|
||||
|
||||
println('Sent message ID: ${msg.id}')
|
||||
println("send succeeded")
|
||||
println('send succeeded')
|
||||
|
||||
// Receive messages
|
||||
// Parameters: wait_for_message, peek_only, topic_filter
|
||||
@@ -40,4 +39,4 @@ println('Message payload: ${received.payload}')
|
||||
// status := client.get_msg_status(msg.id)!
|
||||
// println('Message status: ${status.state}')
|
||||
// println('Created at: ${status.created}')
|
||||
// println('Expires at: ${status.deadline}')
|
||||
// println('Expires at: ${status.deadline}')
|
||||
|
||||
@@ -4,13 +4,11 @@ import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal
|
||||
import time
|
||||
|
||||
|
||||
mut gs := gittools.new()!
|
||||
mydocs_path:=gs.get_path(
|
||||
pull:true,
|
||||
reset:false,
|
||||
url:'https://git.ourworld.tf/tfgrid/info_docs_depin/src/branch/main/docs'
|
||||
mydocs_path := gs.get_path(
|
||||
pull: true
|
||||
reset: false
|
||||
url: 'https://git.ourworld.tf/tfgrid/info_docs_depin/src/branch/main/docs'
|
||||
)!
|
||||
|
||||
println(mydocs_path)
|
||||
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.net.mycelium as mycelium_installer
|
||||
import freeflowuniverse.herolib.clients.mycelium
|
||||
import freeflowuniverse.herolib.clients.mycelium
|
||||
|
||||
mut installer:=mycelium_installer.get()!
|
||||
mut installer := mycelium_installer.get()!
|
||||
installer.start()!
|
||||
|
||||
mut r:=mycelium.inspect()!
|
||||
mut r := mycelium.inspect()!
|
||||
println(r)
|
||||
|
||||
|
||||
|
||||
mut client := mycelium.get()!
|
||||
|
||||
// Send a message to a node by public key
|
||||
// Parameters: public_key, payload, topic, wait_for_reply
|
||||
msg := client.send_msg(
|
||||
'abc123...', // destination public key
|
||||
'Hello World', // message payload
|
||||
'greetings', // optional topic
|
||||
true // wait for reply
|
||||
)!
|
||||
msg := client.send_msg('abc123...', // destination public key
|
||||
'Hello World', // message payload
|
||||
'greetings', // optional topic
|
||||
true // wait for reply
|
||||
)!
|
||||
println('Sent message ID: ${msg.id}')
|
||||
|
||||
// Receive messages
|
||||
@@ -30,15 +27,14 @@ println('Received message from: ${received.src_pk}')
|
||||
println('Message payload: ${received.payload}')
|
||||
|
||||
// Reply to a message
|
||||
client.reply_msg(
|
||||
received.id, // original message ID
|
||||
received.src_pk, // sender's public key
|
||||
'Got your message!', // reply payload
|
||||
'greetings' // topic
|
||||
)!
|
||||
client.reply_msg(received.id, // original message ID
|
||||
received.src_pk, // sender's public key
|
||||
'Got your message!', // reply payload
|
||||
'greetings' // topic
|
||||
)!
|
||||
|
||||
// Check message status
|
||||
status := client.get_msg_status(msg.id)!
|
||||
println('Message status: ${status.state}')
|
||||
println('Created at: ${status.created}')
|
||||
println('Expires at: ${status.deadline}')
|
||||
println('Expires at: ${status.deadline}')
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.zinit as zinit_installer
|
||||
|
||||
mut installer:=zinit_installer.get()!
|
||||
mut installer := zinit_installer.get()!
|
||||
installer.start()!
|
||||
|
||||
@@ -2,24 +2,23 @@
|
||||
|
||||
import freeflowuniverse.herolib.osal.tun
|
||||
|
||||
|
||||
// Check if TUN is available
|
||||
if available := tun.available() {
|
||||
if available {
|
||||
println('TUN is available on this system')
|
||||
|
||||
// Get a free TUN interface name
|
||||
if interface_name := tun.free() {
|
||||
println('Found free TUN interface: ${interface_name}')
|
||||
|
||||
// Example: Now you could use this interface name
|
||||
// to set up your tunnel
|
||||
} else {
|
||||
println('Error finding free interface: ${err}')
|
||||
}
|
||||
} else {
|
||||
println('TUN is not available on this system')
|
||||
}
|
||||
if available {
|
||||
println('TUN is available on this system')
|
||||
|
||||
// Get a free TUN interface name
|
||||
if interface_name := tun.free() {
|
||||
println('Found free TUN interface: ${interface_name}')
|
||||
|
||||
// Example: Now you could use this interface name
|
||||
// to set up your tunnel
|
||||
} else {
|
||||
println('Error finding free interface: ${err}')
|
||||
}
|
||||
} else {
|
||||
println('TUN is not available on this system')
|
||||
}
|
||||
} else {
|
||||
println('Error checking TUN availability: ${err}')
|
||||
println('Error checking TUN availability: ${err}')
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import freeflowuniverse.herolib.core.base
|
||||
import time
|
||||
import os
|
||||
|
||||
//herocompile means we do it for the host system
|
||||
// herocompile means we do it for the host system
|
||||
mut pm := herocontainers.new(herocompile: false, install: false)!
|
||||
|
||||
//pm.builder_base(reset:true)!
|
||||
// pm.builder_base(reset:true)!
|
||||
|
||||
mut builder := pm.builder_get('base')!
|
||||
builder.shell()!
|
||||
@@ -22,7 +22,7 @@ println(builder)
|
||||
// bash & python can be executed directly in build container
|
||||
|
||||
// any of the herocommands can be executed like this
|
||||
//mybuildcontainer.run(cmd: 'installers -n heroweb', runtime: .herocmd)!
|
||||
// mybuildcontainer.run(cmd: 'installers -n heroweb', runtime: .herocmd)!
|
||||
|
||||
// //following will execute heroscript in the buildcontainer
|
||||
// mybuildcontainer.run(
|
||||
|
||||
@@ -5,16 +5,15 @@ import freeflowuniverse.herolib.web.docusaurus
|
||||
|
||||
// Create a new docusaurus factory
|
||||
mut docs := docusaurus.new(
|
||||
// build_path: '/tmp/docusaurus_build'
|
||||
build_path: '/tmp/docusaurus_build'
|
||||
)!
|
||||
|
||||
// Create a new docusaurus site
|
||||
mut site := docs.dev(
|
||||
url:'https://git.ourworld.tf/despiegk/docs_kristof'
|
||||
url: 'https://git.ourworld.tf/despiegk/docs_kristof'
|
||||
)!
|
||||
|
||||
|
||||
//FOR FUTURE TO ADD CONTENT FROM DOCTREE
|
||||
// FOR FUTURE TO ADD CONTENT FROM DOCTREE
|
||||
|
||||
// Create a doctree for content
|
||||
// mut tree := doctree.new(name: 'content')!
|
||||
@@ -34,10 +33,10 @@ mut site := docs.dev(
|
||||
// )!
|
||||
|
||||
// Build the docusaurus site
|
||||
//site.build()!
|
||||
// site.build()!
|
||||
|
||||
// Generate the static site
|
||||
//site.generate()!
|
||||
// site.generate()!
|
||||
|
||||
// Optionally open the site in a browser
|
||||
// site.open()!
|
||||
|
||||
@@ -7,8 +7,8 @@ import freeflowuniverse.herolib.core.httpconnection
|
||||
// Represents a destination for a message, can be either IP or public key
|
||||
pub struct MessageDestination {
|
||||
pub:
|
||||
ip string @[omitempty] // IP in the subnet of the receiver node
|
||||
pk string @[omitempty] // hex encoded public key of the receiver node
|
||||
ip string @[omitempty] // IP in the subnet of the receiver node
|
||||
pk string @[omitempty] // hex encoded public key of the receiver node
|
||||
}
|
||||
|
||||
// Body of a message to be sent
|
||||
@@ -29,12 +29,12 @@ pub:
|
||||
pub struct InboundMessage {
|
||||
pub:
|
||||
id string
|
||||
src_ip string @[json: 'srcIp'] // Sender overlay IP address
|
||||
src_pk string @[json: 'srcPk'] // Sender public key, hex encoded
|
||||
dst_ip string @[json: 'dstIp'] // Receiver overlay IP address
|
||||
dst_pk string @[json: 'dstPk'] // Receiver public key, hex encoded
|
||||
topic string // Optional message topic
|
||||
payload string // Message payload, base64 encoded
|
||||
src_ip string @[json: 'srcIp'] // Sender overlay IP address
|
||||
src_pk string @[json: 'srcPk'] // Sender public key, hex encoded
|
||||
dst_ip string @[json: 'dstIp'] // Receiver overlay IP address
|
||||
dst_pk string @[json: 'dstPk'] // Receiver public key, hex encoded
|
||||
topic string // Optional message topic
|
||||
payload string // Message payload, base64 encoded
|
||||
}
|
||||
|
||||
// Information about an outbound message
|
||||
@@ -44,7 +44,7 @@ pub:
|
||||
state string // pending, received, read, aborted or sending object
|
||||
created i64 // Unix timestamp of creation
|
||||
deadline i64 // Unix timestamp of expiry
|
||||
msg_len int @[json: 'msgLen'] // Length in bytes
|
||||
msg_len int @[json: 'msgLen'] // Length in bytes
|
||||
}
|
||||
|
||||
// General information about a node
|
||||
@@ -63,12 +63,13 @@ pub:
|
||||
pub fn (mut self Mycelium) connection() !&httpconnection.HTTPConnection {
|
||||
mut c := self.conn or {
|
||||
mut c2 := httpconnection.new(
|
||||
name: 'mycelium'
|
||||
url: self.server_url
|
||||
name: 'mycelium'
|
||||
url: self.server_url
|
||||
retry: 3
|
||||
)!
|
||||
c2
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -76,23 +77,23 @@ pub fn (mut self Mycelium) connection() !&httpconnection.HTTPConnection {
|
||||
pub fn (mut self Mycelium) send_msg(pk string, payload string, topic string, wait bool) !InboundMessage {
|
||||
mut conn := self.connection()!
|
||||
mut body := PushMessageBody{
|
||||
dst: MessageDestination{
|
||||
dst: MessageDestination{
|
||||
pk: pk
|
||||
ip: ''
|
||||
}
|
||||
payload: base64.encode_str(payload)
|
||||
topic: base64.encode_str(topic)
|
||||
topic: base64.encode_str(topic)
|
||||
}
|
||||
mut prefix := '/api/v1/messages'
|
||||
if wait {
|
||||
prefix += '?reply_timeout=120'
|
||||
prefix += '?reply_timeout=120'
|
||||
}
|
||||
return conn.post_json_generic[InboundMessage](
|
||||
method: .post
|
||||
prefix: prefix
|
||||
data: json.encode(body)
|
||||
method: .post
|
||||
prefix: prefix
|
||||
data: json.encode(body)
|
||||
dataformat: .json
|
||||
)!
|
||||
)!
|
||||
}
|
||||
|
||||
// Receive a message from the queue
|
||||
@@ -109,8 +110,8 @@ pub fn (mut self Mycelium) receive_msg(wait bool, peek bool, topic string) !Inbo
|
||||
prefix += 'topic=${base64.encode_str(topic)}'
|
||||
}
|
||||
return conn.get_json_generic[InboundMessage](
|
||||
method: .get
|
||||
prefix: prefix
|
||||
method: .get
|
||||
prefix: prefix
|
||||
dataformat: .json
|
||||
)!
|
||||
}
|
||||
@@ -129,8 +130,8 @@ pub fn (mut self Mycelium) receive_msg_opt(wait bool, peek bool, topic string) ?
|
||||
prefix += 'topic=${base64.encode_str(topic)}'
|
||||
}
|
||||
res := conn.get_json_generic[InboundMessage](
|
||||
method: .get
|
||||
prefix: prefix
|
||||
method: .get
|
||||
prefix: prefix
|
||||
dataformat: .json
|
||||
) or {
|
||||
if err.msg().contains('204') {
|
||||
@@ -145,8 +146,8 @@ pub fn (mut self Mycelium) receive_msg_opt(wait bool, peek bool, topic string) ?
|
||||
pub fn (mut self Mycelium) get_msg_status(id string) !MessageStatusResponse {
|
||||
mut conn := self.connection()!
|
||||
return conn.get_json_generic[MessageStatusResponse](
|
||||
method: .get
|
||||
prefix: '/api/v1/messages/status/${id}'
|
||||
method: .get
|
||||
prefix: '/api/v1/messages/status/${id}'
|
||||
dataformat: .json
|
||||
)!
|
||||
}
|
||||
@@ -155,28 +156,29 @@ pub fn (mut self Mycelium) get_msg_status(id string) !MessageStatusResponse {
|
||||
pub fn (mut self Mycelium) reply_msg(id string, pk string, payload string, topic string) ! {
|
||||
mut conn := self.connection()!
|
||||
mut body := PushMessageBody{
|
||||
dst: MessageDestination{
|
||||
dst: MessageDestination{
|
||||
pk: pk
|
||||
ip: ''
|
||||
}
|
||||
payload: base64.encode_str(payload)
|
||||
topic: base64.encode_str(topic)
|
||||
topic: base64.encode_str(topic)
|
||||
}
|
||||
_ := conn.post_json_generic[MessageDestination](
|
||||
method: .post
|
||||
prefix: '/api/v1/messages/reply/${id}'
|
||||
data: json.encode(body)
|
||||
method: .post
|
||||
prefix: '/api/v1/messages/reply/${id}'
|
||||
data: json.encode(body)
|
||||
dataformat: .json
|
||||
)!
|
||||
}
|
||||
|
||||
// curl -v -H 'Content-Type: application/json' -d '{"dst": {"pk": "be4bf135d60b7e43a46be1ad68f955cdc1209a3c55dc30d00c4463b1dace4377"}, "payload": "xuV+"}' http://localhost:8989/api/v1/messages\
|
||||
|
||||
// Get node info
|
||||
pub fn (mut self Mycelium) get_info() !Info {
|
||||
mut conn := self.connection()!
|
||||
return conn.get_json_generic[Info](
|
||||
method: .get
|
||||
prefix: '/api/v1/admin'
|
||||
method: .get
|
||||
prefix: '/api/v1/admin'
|
||||
dataformat: .json
|
||||
)!
|
||||
}
|
||||
@@ -185,8 +187,8 @@ pub fn (mut self Mycelium) get_info() !Info {
|
||||
pub fn (mut self Mycelium) get_pubkey_from_ip(ip string) !PublicKeyResponse {
|
||||
mut conn := self.connection()!
|
||||
return conn.get_json_generic[PublicKeyResponse](
|
||||
method: .get
|
||||
prefix: '/api/v1/pubkey/${ip}'
|
||||
method: .get
|
||||
prefix: '/api/v1/pubkey/${ip}'
|
||||
dataformat: .json
|
||||
)!
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import os
|
||||
import time
|
||||
import json
|
||||
|
||||
|
||||
pub fn check() bool {
|
||||
// if core.is_osx()! {
|
||||
// mut scr := screen.new(reset: false) or {return False}
|
||||
@@ -38,7 +37,6 @@ pub fn check() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
pub struct MyceliumInspectResult {
|
||||
pub:
|
||||
public_key string @[json: publicKey]
|
||||
|
||||
@@ -5,120 +5,109 @@ import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
|
||||
__global (
|
||||
mycelium_global map[string]&Mycelium
|
||||
mycelium_default string
|
||||
mycelium_global map[string]&Mycelium
|
||||
mycelium_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet{
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get (args_ ArgsGet) ArgsGet {
|
||||
mut args:=args_
|
||||
if args.name == ""{
|
||||
args.name = "default"
|
||||
}
|
||||
return args
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&Mycelium {
|
||||
mut context:=base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := Mycelium{}
|
||||
if !(args.name in mycelium_global) {
|
||||
if ! exists(args)!{
|
||||
set(obj)!
|
||||
}else{
|
||||
heroscript := context.hero_config_get("mycelium",args.name)!
|
||||
mut obj_:=heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return mycelium_global[args.name] or {
|
||||
println(mycelium_global)
|
||||
//bug if we get here because should be in globals
|
||||
panic("could not get config for mycelium with name, is bug:${args.name}")
|
||||
}
|
||||
pub fn get(args_ ArgsGet) !&Mycelium {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := Mycelium{}
|
||||
if args.name !in mycelium_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('mycelium', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return mycelium_global[args.name] or {
|
||||
println(mycelium_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for mycelium with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
//register the config for the future
|
||||
pub fn set(o Mycelium)! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set("mycelium", o.name, heroscript)!
|
||||
// register the config for the future
|
||||
pub fn set(o Mycelium) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('mycelium', o.name, heroscript)!
|
||||
}
|
||||
|
||||
//does the config exists?
|
||||
pub fn exists(args_ ArgsGet)! bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists("mycelium", args.name)
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('mycelium', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet)! {
|
||||
mut args := args_get(args_)
|
||||
mut context:=base.context()!
|
||||
context.hero_config_delete("mycelium",args.name)!
|
||||
if args.name in mycelium_global {
|
||||
//del mycelium_global[args.name]
|
||||
}
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('mycelium', args.name)!
|
||||
if args.name in mycelium_global {
|
||||
// del mycelium_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
//only sets in mem, does not set as config
|
||||
fn set_in_mem(o Mycelium)! {
|
||||
mut o2:=obj_init(o)!
|
||||
mycelium_global[o.name] = &o2
|
||||
mycelium_default = o.name
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o Mycelium) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
mycelium_global[o.name] = &o2
|
||||
mycelium_default = o.name
|
||||
}
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string //if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
|
||||
mut args:=args_
|
||||
|
||||
|
||||
mut plbook := args.plbook or {
|
||||
playbook.new(text: args.heroscript)!
|
||||
}
|
||||
|
||||
mut install_actions := plbook.find(filter: 'mycelium.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript:=install_action.heroscript()
|
||||
mut obj2:=heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
mut args := args_
|
||||
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||
|
||||
mut install_actions := plbook.find(filter: 'mycelium.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//switch instance to be used for mycelium
|
||||
// switch instance to be used for mycelium
|
||||
pub fn switch(name string) {
|
||||
mycelium_default = name
|
||||
mycelium_default = name
|
||||
}
|
||||
|
||||
|
||||
//helpers
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs{
|
||||
instance string = 'default'
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -12,26 +12,23 @@ const default = true
|
||||
pub struct Mycelium {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
server_url string = "http://localhost:8989"
|
||||
conn ?&httpconnection.HTTPConnection @[skip; str: skip]
|
||||
server_url string = 'http://localhost:8989'
|
||||
conn ?&httpconnection.HTTPConnection @[skip; str: skip]
|
||||
}
|
||||
|
||||
|
||||
//your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ Mycelium)!Mycelium{
|
||||
mut mycfg:=mycfg_
|
||||
return mycfg
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ Mycelium) !Mycelium {
|
||||
mut mycfg := mycfg_
|
||||
return mycfg
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj Mycelium) !string {
|
||||
return encoderhero.encode[Mycelium ](obj)!
|
||||
return encoderhero.encode[Mycelium](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !Mycelium {
|
||||
mut obj := encoderhero.decode[Mycelium](heroscript)!
|
||||
return obj
|
||||
mut obj := encoderhero.decode[Mycelium](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ pub fn (mut h HTTPConnection) get(req_ Request) !string {
|
||||
req.debug = true
|
||||
req.method = .get
|
||||
result := h.send(req)!
|
||||
println(result)
|
||||
println(result)
|
||||
return result.data
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ fn decode_struct[T](_ T, data string) !T {
|
||||
should_skip = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if ! should_skip {
|
||||
}
|
||||
if !should_skip {
|
||||
$if field.is_struct {
|
||||
$if field.typ !is time.Time {
|
||||
if !field.name[0].is_capital() {
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn encode[T](val T) !string {
|
||||
$if T is $struct {
|
||||
e.encode_struct[T](val)!
|
||||
} $else $if T is $array {
|
||||
//TODO: need to make comma separated list only works if int,u8,u16,i8... or string if string put all elements in \''...\'',...
|
||||
// TODO: need to make comma separated list only works if int,u8,u16,i8... or string if string put all elements in \''...\'',...
|
||||
e.add_child_list[T](val, 'TODO')
|
||||
} $else {
|
||||
return error('can only add elements for struct or array of structs. \n${val}')
|
||||
@@ -138,8 +138,8 @@ pub fn (mut e Encoder) encode_struct[T](t T) ! {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ! should_skip {
|
||||
|
||||
if !should_skip {
|
||||
val := t.$(field.name)
|
||||
// time is encoded in the above params encoding step so skip and dont treat as recursive struct
|
||||
$if val is time.Time || val is ourtime.OurTime {
|
||||
|
||||
@@ -5,23 +5,21 @@ import time
|
||||
import v.reflection
|
||||
|
||||
struct MyStruct {
|
||||
id int
|
||||
id int
|
||||
name string
|
||||
//skip attributes would be best way how to do the encoding but can't get it to work
|
||||
// skip attributes would be best way how to do the encoding but can't get it to work
|
||||
other ?&Remark @[skip; str: skip]
|
||||
}
|
||||
|
||||
//is the one we should skip
|
||||
// is the one we should skip
|
||||
struct Remark {
|
||||
id int
|
||||
id int
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn test_encode() ! {
|
||||
mut o := MyStruct{
|
||||
id: 1
|
||||
name: 'test'
|
||||
id: 1
|
||||
name: 'test'
|
||||
other: &Remark{
|
||||
id: 123
|
||||
}
|
||||
@@ -29,17 +27,16 @@ fn test_encode() ! {
|
||||
|
||||
script := encode[MyStruct](o)!
|
||||
|
||||
assert script.trim_space() == "!!define.my_struct id:1 name:test"
|
||||
assert script.trim_space() == '!!define.my_struct id:1 name:test'
|
||||
|
||||
println(script)
|
||||
|
||||
o2:=decode[MyStruct](script)!
|
||||
o2 := decode[MyStruct](script)!
|
||||
|
||||
assert o2== MyStruct{
|
||||
id: 1
|
||||
assert o2 == MyStruct{
|
||||
id: 1
|
||||
name: 'test'
|
||||
}
|
||||
|
||||
println(o2)
|
||||
|
||||
}
|
||||
|
||||
@@ -17,10 +17,9 @@ pub fn (params Params) decode_struct[T](_ T) !T {
|
||||
$if field.is_enum {
|
||||
t.$(field.name) = params.get_int(field.name) or { 0 }
|
||||
} $else {
|
||||
//super annoying didn't find other way, then to ignore options
|
||||
$if field.is_option{
|
||||
|
||||
}$else{
|
||||
// super annoying didn't find other way, then to ignore options
|
||||
$if field.is_option {
|
||||
} $else {
|
||||
if field.name[0].is_capital() {
|
||||
// embed := params.decode_struct(t.$(field.name))!
|
||||
t.$(field.name) = params.decode_struct(t.$(field.name))!
|
||||
|
||||
@@ -103,12 +103,11 @@ fn test_decode() {
|
||||
decoded_child := test_child_params.decode[TestChild]()!
|
||||
assert decoded_child == test_child
|
||||
|
||||
//IMPORTANT OPTIONALS ARE NOT SUPPORTED AND WILL NOT BE ENCODED FOR NOW (unless we find ways how to deal with attributes to not encode skipped elements)
|
||||
// IMPORTANT OPTIONALS ARE NOT SUPPORTED AND WILL NOT BE ENCODED FOR NOW (unless we find ways how to deal with attributes to not encode skipped elements)
|
||||
|
||||
// test recursive decode struct with child
|
||||
decoded := test_params.decode[TestStruct]()!
|
||||
assert decoded == test_struct
|
||||
|
||||
}
|
||||
|
||||
fn test_encode() {
|
||||
|
||||
@@ -159,8 +159,8 @@ fn repo_match_check(repo GitRepo, args ReposGetArgs) !bool {
|
||||
// Raises:
|
||||
// - Error: If multiple repositories are found with similar names or if cloning fails.
|
||||
pub fn (mut gitstructure GitStructure) get_path(args_ ReposGetArgs) !string {
|
||||
mut args:=args_
|
||||
if args.pull{
|
||||
mut args := args_
|
||||
if args.pull {
|
||||
args.status_clean = true
|
||||
}
|
||||
mut r := gitstructure.get_repo(args_)!
|
||||
|
||||
@@ -6,148 +6,139 @@ import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.zinit as zinit_installer
|
||||
import freeflowuniverse.herolib.clients.mycelium
|
||||
import freeflowuniverse.herolib.clients.mycelium
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
|
||||
import freeflowuniverse.herolib.installers.lang.rust
|
||||
|
||||
import os
|
||||
|
||||
fn startupcmd () ![]zinit.ZProcessNewArgs{
|
||||
mut installer := get()!
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
fn startupcmd() ![]zinit.ZProcessNewArgs {
|
||||
mut installer := get()!
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
|
||||
mut peers_str := installer.peers.join(' ')
|
||||
mut tun_name := 'tun${installer.tun_nr}'
|
||||
mut peers_str := installer.peers.join(' ')
|
||||
mut tun_name := 'tun${installer.tun_nr}'
|
||||
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'mycelium'
|
||||
cmd: 'mycelium --key-file ${osal.hero_path()!}/cfg/priv_key.bin --peers ${peers_str} --tun-name ${tun_name}'
|
||||
env: {
|
||||
'HOME': '/root'
|
||||
}
|
||||
}
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'mycelium'
|
||||
cmd: 'mycelium --key-file ${osal.hero_path()!}/cfg/priv_key.bin --peers ${peers_str} --tun-name ${tun_name}'
|
||||
env: {
|
||||
'HOME': '/root'
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
return res
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
mycelium.inspect() or {return false}
|
||||
return true
|
||||
mycelium.inspect() or { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
fn start_pre()!{
|
||||
|
||||
fn start_pre() ! {
|
||||
}
|
||||
|
||||
fn start_post()!{
|
||||
|
||||
fn start_post() ! {
|
||||
}
|
||||
|
||||
fn stop_pre()!{
|
||||
|
||||
fn stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post()!{
|
||||
|
||||
fn stop_post() ! {
|
||||
}
|
||||
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
cmd:='${osal.profile_path_source_and()!} mycelium -V'
|
||||
// println(cmd)
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
println(res)
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse mycelium version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) == texttools.version(r[0].all_after_last("mycelium")) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
cmd := '${osal.profile_path_source_and()!} mycelium -V'
|
||||
// println(cmd)
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
println(res)
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse mycelium version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) == texttools.version(r[0].all_after_last('mycelium')) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//get the Upload List of the files
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
// 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
|
||||
// uploads to S3 server if configured
|
||||
fn upload() ! {
|
||||
// installers.upload(
|
||||
// cmdname: 'mycelium'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/mycelium'
|
||||
// )!
|
||||
|
||||
// installers.upload(
|
||||
// cmdname: 'mycelium'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/mycelium'
|
||||
// )!
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install mycelium')
|
||||
console.print_header('install mycelium')
|
||||
|
||||
mut z_installer:=zinit_installer.get()!
|
||||
z_installer.start()!
|
||||
mut z_installer := zinit_installer.get()!
|
||||
z_installer.start()!
|
||||
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-aarch64-unknown-linux-musl.tar.gz'
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-x86_64-unknown-linux-musl.tar.gz'
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-aarch64-apple-darwin.tar.gz'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-x86_64-apple-darwin.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-aarch64-unknown-linux-musl.tar.gz'
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-x86_64-unknown-linux-musl.tar.gz'
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-aarch64-apple-darwin.tar.gz'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-x86_64-apple-darwin.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
|
||||
pathlib.get_dir(
|
||||
path: '${osal.hero_path()!}/cfg'
|
||||
create: true
|
||||
)!
|
||||
pathlib.get_dir(
|
||||
path: '${osal.hero_path()!}/cfg'
|
||||
create: true
|
||||
)!
|
||||
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 5000
|
||||
expand_dir: '/tmp/mycelium'
|
||||
)!
|
||||
mut binpath := dest.file_get('mycelium')!
|
||||
osal.cmd_add(
|
||||
cmdname: 'mycelium'
|
||||
source: binpath.path
|
||||
)!
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 5000
|
||||
expand_dir: '/tmp/mycelium'
|
||||
)!
|
||||
mut binpath := dest.file_get('mycelium')!
|
||||
osal.cmd_add(
|
||||
cmdname: 'mycelium'
|
||||
source: binpath.path
|
||||
)!
|
||||
}
|
||||
|
||||
fn build() ! {
|
||||
url := 'https://github.com/threefoldtech/mycelium'
|
||||
myplatform:=core.platform()!
|
||||
if myplatform != .ubuntu {
|
||||
return error('only support ubuntu for now')
|
||||
}
|
||||
rust.install()!
|
||||
url := 'https://github.com/threefoldtech/mycelium'
|
||||
myplatform := core.platform()!
|
||||
if myplatform != .ubuntu {
|
||||
return error('only support ubuntu for now')
|
||||
}
|
||||
rust.install()!
|
||||
|
||||
console.print_header('build mycelium')
|
||||
console.print_header('build mycelium')
|
||||
|
||||
mut gs := gittools.new()!
|
||||
gitpath:=gs.get_path(
|
||||
pull:true,
|
||||
reset:false,
|
||||
url:url
|
||||
)!
|
||||
mut gs := gittools.new()!
|
||||
gitpath := gs.get_path(
|
||||
pull: true
|
||||
reset: false
|
||||
url: url
|
||||
)!
|
||||
|
||||
panic("implement")
|
||||
panic('implement')
|
||||
|
||||
|
||||
cmd := '
|
||||
cmd := '
|
||||
cd ${gitpath}
|
||||
source ~/.cargo/env
|
||||
cargo install --path . --locked
|
||||
@@ -155,27 +146,22 @@ fn build() ! {
|
||||
cp target/release/mycelium ~/.cargo/bin/mycelium
|
||||
mycelium --version
|
||||
'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
// //now copy to the default bin path
|
||||
// mut binpath := dest.file_get('...')!
|
||||
// adds it to path
|
||||
// osal.cmd_add(
|
||||
// cmdname: 'griddriver2'
|
||||
// source: binpath.path
|
||||
// )!
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
// //now copy to the default bin path
|
||||
// mut binpath := dest.file_get('...')!
|
||||
// adds it to path
|
||||
// osal.cmd_add(
|
||||
// cmdname: 'griddriver2'
|
||||
// source: binpath.path
|
||||
// )!
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
osal.process_kill_recursive(name: 'mycelium')!
|
||||
osal.cmd_delete('mycelium')!
|
||||
|
||||
|
||||
osal.process_kill_recursive(name:'mycelium')!
|
||||
osal.cmd_delete('mycelium')!
|
||||
|
||||
osal.rm("
|
||||
osal.rm('
|
||||
mycelium
|
||||
")!
|
||||
|
||||
')!
|
||||
}
|
||||
|
||||
|
||||
@@ -4,288 +4,277 @@ import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
mycelium_global map[string]&MyceliumInstaller
|
||||
mycelium_default string
|
||||
mycelium_global map[string]&MyceliumInstaller
|
||||
mycelium_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet{
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get (args_ ArgsGet) ArgsGet {
|
||||
mut args:=args_
|
||||
if args.name == ""{
|
||||
args.name = "default"
|
||||
}
|
||||
return args
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&MyceliumInstaller {
|
||||
mut context:=base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := MyceliumInstaller{}
|
||||
if !(args.name in mycelium_global) {
|
||||
if ! exists(args)!{
|
||||
set(obj)!
|
||||
}else{
|
||||
heroscript := context.hero_config_get("mycelium",args.name)!
|
||||
mut obj_:=heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return mycelium_global[args.name] or {
|
||||
println(mycelium_global)
|
||||
//bug if we get here because should be in globals
|
||||
panic("could not get config for mycelium with name, is bug:${args.name}")
|
||||
}
|
||||
pub fn get(args_ ArgsGet) !&MyceliumInstaller {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := MyceliumInstaller{}
|
||||
if args.name !in mycelium_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('mycelium', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return mycelium_global[args.name] or {
|
||||
println(mycelium_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for mycelium with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
//register the config for the future
|
||||
pub fn set(o MyceliumInstaller)! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set("mycelium", o.name, heroscript)!
|
||||
// register the config for the future
|
||||
pub fn set(o MyceliumInstaller) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('mycelium', o.name, heroscript)!
|
||||
}
|
||||
|
||||
//does the config exists?
|
||||
pub fn exists(args_ ArgsGet)! bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists("mycelium", args.name)
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('mycelium', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet)! {
|
||||
mut args := args_get(args_)
|
||||
mut context:=base.context()!
|
||||
context.hero_config_delete("mycelium",args.name)!
|
||||
if args.name in mycelium_global {
|
||||
//del mycelium_global[args.name]
|
||||
}
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('mycelium', args.name)!
|
||||
if args.name in mycelium_global {
|
||||
// del mycelium_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
//only sets in mem, does not set as config
|
||||
fn set_in_mem(o MyceliumInstaller)! {
|
||||
mut o2:=obj_init(o)!
|
||||
mycelium_global[o.name] = &o2
|
||||
mycelium_default = o.name
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o MyceliumInstaller) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
mycelium_global[o.name] = &o2
|
||||
mycelium_default = o.name
|
||||
}
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string //if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
|
||||
mut args:=args_
|
||||
mut args := args_
|
||||
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||
|
||||
mut plbook := args.plbook or {
|
||||
playbook.new(text: args.heroscript)!
|
||||
}
|
||||
|
||||
mut install_actions := plbook.find(filter: 'mycelium.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript:=install_action.heroscript()
|
||||
mut obj2:=heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'mycelium.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
|
||||
mut other_actions := plbook.find(filter: 'mycelium.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ["destroy","install","build"]{
|
||||
mut p := other_action.params
|
||||
reset:=p.get_default_false("reset")
|
||||
if other_action.name == "destroy" || reset{
|
||||
console.print_debug("install action mycelium.destroy")
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == "install"{
|
||||
console.print_debug("install action mycelium.install")
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ["start","stop","restart"]{
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut mycelium_obj:=get(name:name)!
|
||||
console.print_debug("action object:\n${mycelium_obj}")
|
||||
if other_action.name == "start"{
|
||||
console.print_debug("install action mycelium.${other_action.name}")
|
||||
mycelium_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == "stop"{
|
||||
console.print_debug("install action mycelium.${other_action.name}")
|
||||
mycelium_obj.stop()!
|
||||
}
|
||||
if other_action.name == "restart"{
|
||||
console.print_debug("install action mycelium.${other_action.name}")
|
||||
mycelium_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'mycelium.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
reset := p.get_default_false('reset')
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action mycelium.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action mycelium.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut mycelium_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${mycelium_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action mycelium.${other_action.name}')
|
||||
mycelium_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action mycelium.${other_action.name}')
|
||||
mycelium_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action mycelium.${other_action.name}')
|
||||
mycelium_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# 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()!
|
||||
}
|
||||
}
|
||||
// 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()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//load from disk and make sure is properly intialized
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self MyceliumInstaller) reload() ! {
|
||||
switch(self.name)
|
||||
self=obj_init(self)!
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()!{
|
||||
return
|
||||
}
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('mycelium start')
|
||||
console.print_header('mycelium start')
|
||||
|
||||
if ! installed()!{
|
||||
install()!
|
||||
}
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting mycelium with ${zprocess.startuptype}...')
|
||||
console.print_debug('starting mycelium with ${zprocess.startuptype}...')
|
||||
|
||||
sm.new(zprocess)!
|
||||
sm.new(zprocess)!
|
||||
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('mycelium did not install properly.')
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('mycelium did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) running() !bool {
|
||||
switch(self.name)
|
||||
switch(self.name)
|
||||
|
||||
//walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
r:=sm.running(zprocess.name)!
|
||||
if r==false{
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
if r == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs{
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
|
||||
|
||||
//switch instance to be used for mycelium
|
||||
// switch instance to be used for mycelium
|
||||
pub fn switch(name string) {
|
||||
mycelium_default = name
|
||||
mycelium_default = name
|
||||
}
|
||||
|
||||
|
||||
//helpers
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs{
|
||||
instance string = 'default'
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module mycelium
|
||||
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import freeflowuniverse.herolib.osal.tun
|
||||
import os
|
||||
@@ -7,66 +8,63 @@ pub const version = '0.5.7'
|
||||
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
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
pub struct MyceliumInstaller {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
peers []string = [
|
||||
"tcp://188.40.132.242:9651",
|
||||
"quic://[2a01:4f8:212:fa6::2]:9651",
|
||||
"tcp://185.69.166.7:9651",
|
||||
"quic://[2a02:1802:5e:0:ec4:7aff:fe51:e36b]:9651",
|
||||
"tcp://65.21.231.58:9651",
|
||||
"quic://[2a01:4f9:5a:1042::2]:9651",
|
||||
"tcp://[2604:a00:50:17b:9e6b:ff:fe1f:e054]:9651",
|
||||
"quic://5.78.122.16:9651",
|
||||
"tcp://[2a01:4ff:2f0:3621::1]:9651",
|
||||
"quic://142.93.217.194:9651",
|
||||
]
|
||||
tun_nr int
|
||||
name string = 'default'
|
||||
peers []string = [
|
||||
'tcp://188.40.132.242:9651',
|
||||
'quic://[2a01:4f8:212:fa6::2]:9651',
|
||||
'tcp://185.69.166.7:9651',
|
||||
'quic://[2a02:1802:5e:0:ec4:7aff:fe51:e36b]:9651',
|
||||
'tcp://65.21.231.58:9651',
|
||||
'quic://[2a01:4f9:5a:1042::2]:9651',
|
||||
'tcp://[2604:a00:50:17b:9e6b:ff:fe1f:e054]:9651',
|
||||
'quic://5.78.122.16:9651',
|
||||
'tcp://[2a01:4ff:2f0:3621::1]:9651',
|
||||
'quic://142.93.217.194:9651',
|
||||
]
|
||||
tun_nr int
|
||||
}
|
||||
|
||||
|
||||
|
||||
//your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ MyceliumInstaller)!MyceliumInstaller{
|
||||
mut mycfg:=mycfg_
|
||||
return mycfg
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ MyceliumInstaller) !MyceliumInstaller {
|
||||
mut mycfg := mycfg_
|
||||
return mycfg
|
||||
}
|
||||
|
||||
//called before start if done
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
mut installer := get()!
|
||||
if installer.tun_nr == 0 {
|
||||
// Check if TUN is available first
|
||||
if available := tun.available() {
|
||||
if !available {
|
||||
return error('TUN is not available on this system')
|
||||
}
|
||||
// Get free TUN interface name
|
||||
if interface_name := tun.free() {
|
||||
// Parse the interface number from the name (e.g. "tun0" -> 0)
|
||||
nr := interface_name.trim_string_left('tun').int()
|
||||
installer.tun_nr = nr
|
||||
} else {
|
||||
return error('Failed to get free TUN interface: ${err}')
|
||||
}
|
||||
} else {
|
||||
return error('Failed to check TUN availability: ${err}')
|
||||
}
|
||||
set(installer)!
|
||||
}
|
||||
mut installer := get()!
|
||||
if installer.tun_nr == 0 {
|
||||
// Check if TUN is available first
|
||||
if available := tun.available() {
|
||||
if !available {
|
||||
return error('TUN is not available on this system')
|
||||
}
|
||||
// Get free TUN interface name
|
||||
if interface_name := tun.free() {
|
||||
// Parse the interface number from the name (e.g. "tun0" -> 0)
|
||||
nr := interface_name.trim_string_left('tun').int()
|
||||
installer.tun_nr = nr
|
||||
} else {
|
||||
return error('Failed to get free TUN interface: ${err}')
|
||||
}
|
||||
} else {
|
||||
return error('Failed to check TUN availability: ${err}')
|
||||
}
|
||||
set(installer)!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj MyceliumInstaller) !string {
|
||||
return encoderhero.encode[MyceliumInstaller ](obj)!
|
||||
return encoderhero.encode[MyceliumInstaller](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !MyceliumInstaller {
|
||||
mut obj := encoderhero.decode[MyceliumInstaller](heroscript)!
|
||||
return obj
|
||||
mut obj := encoderhero.decode[MyceliumInstaller](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
module mycelium
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ fn ulist_get() !ulist.UList {
|
||||
fn upload() ! {
|
||||
}
|
||||
|
||||
fn startupcmd () ![]zinit.ZProcessNewArgs{
|
||||
fn startupcmd() ![]zinit.ZProcessNewArgs {
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'zinit'
|
||||
|
||||
@@ -4,218 +4,207 @@ import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
zinit_global map[string]&Zinit
|
||||
zinit_default string
|
||||
zinit_global map[string]&Zinit
|
||||
zinit_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet{
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&Zinit {
|
||||
return &Zinit{}
|
||||
pub fn get(args_ ArgsGet) !&Zinit {
|
||||
return &Zinit{}
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string //if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
|
||||
mut args:=args_
|
||||
mut args := args_
|
||||
|
||||
mut plbook := args.plbook or {
|
||||
playbook.new(text: args.heroscript)!
|
||||
}
|
||||
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||
|
||||
mut other_actions := plbook.find(filter: 'zinit.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ["destroy","install","build"]{
|
||||
mut p := other_action.params
|
||||
reset:=p.get_default_false("reset")
|
||||
if other_action.name == "destroy" || reset{
|
||||
console.print_debug("install action zinit.destroy")
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == "install"{
|
||||
console.print_debug("install action zinit.install")
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ["start","stop","restart"]{
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut zinit_obj:=get(name:name)!
|
||||
console.print_debug("action object:\n${zinit_obj}")
|
||||
if other_action.name == "start"{
|
||||
console.print_debug("install action zinit.${other_action.name}")
|
||||
zinit_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == "stop"{
|
||||
console.print_debug("install action zinit.${other_action.name}")
|
||||
zinit_obj.stop()!
|
||||
}
|
||||
if other_action.name == "restart"{
|
||||
console.print_debug("install action zinit.${other_action.name}")
|
||||
zinit_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'zinit.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
reset := p.get_default_false('reset')
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action zinit.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action zinit.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut zinit_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${zinit_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action zinit.${other_action.name}')
|
||||
zinit_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action zinit.${other_action.name}')
|
||||
zinit_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action zinit.${other_action.name}')
|
||||
zinit_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# 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()!
|
||||
}
|
||||
}
|
||||
// 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()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut self Zinit) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()!{
|
||||
return
|
||||
}
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('zinit start')
|
||||
console.print_header('zinit start')
|
||||
|
||||
if ! installed()!{
|
||||
install()!
|
||||
}
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting zinit with ${zprocess.startuptype}...')
|
||||
console.print_debug('starting zinit with ${zprocess.startuptype}...')
|
||||
|
||||
sm.new(zprocess)!
|
||||
sm.new(zprocess)!
|
||||
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('zinit did not install properly.')
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('zinit did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) running() !bool {
|
||||
switch(self.name)
|
||||
switch(self.name)
|
||||
|
||||
//walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
r:=sm.running(zprocess.name)!
|
||||
if r==false{
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
if r == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs{
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
|
||||
|
||||
//switch instance to be used for zinit
|
||||
// switch instance to be used for zinit
|
||||
pub fn switch(name string) {
|
||||
zinit_default = name
|
||||
zinit_default = name
|
||||
}
|
||||
|
||||
|
||||
//helpers
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs{
|
||||
instance string = 'default'
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -5,74 +5,69 @@ import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
|
||||
|
||||
import os
|
||||
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
res := os.execute('${osal.profile_path_source_and()!} podman -v')
|
||||
if res.exit_code != 0 {
|
||||
println(res)
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse podman version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) <= texttools.version(r[0].all_after("version")) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
res := os.execute('${osal.profile_path_source_and()!} podman -v')
|
||||
if res.exit_code != 0 {
|
||||
println(res)
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse podman version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) <= texttools.version(r[0].all_after('version')) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//get the Upload List of the files
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
fn upload() ! {
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install podman')
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! || core.is_linux_intel()!{
|
||||
osal.package_install("podman,buildah,crun,mmdebstrap")!
|
||||
return
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-arm64.pkg'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-amd64.pkg'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
console.print_header('install podman')
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! || core.is_linux_intel()! {
|
||||
osal.package_install('podman,buildah,crun,mmdebstrap')!
|
||||
return
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-arm64.pkg'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-amd64.pkg'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 9000
|
||||
expand_dir: '/tmp/podman'
|
||||
)!
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 9000
|
||||
expand_dir: '/tmp/podman'
|
||||
)!
|
||||
|
||||
//dest.moveup_single_subdir()!
|
||||
// dest.moveup_single_subdir()!
|
||||
|
||||
panic("implement")
|
||||
panic('implement')
|
||||
}
|
||||
|
||||
|
||||
fn destroy() ! {
|
||||
// mut systemdfactory := systemd.new()!
|
||||
// systemdfactory.destroy("zinit")!
|
||||
|
||||
// mut systemdfactory := systemd.new()!
|
||||
// systemdfactory.destroy("zinit")!
|
||||
// osal.process_kill_recursive(name:'zinit')!
|
||||
// osal.cmd_delete('zinit')!
|
||||
|
||||
// osal.process_kill_recursive(name:'zinit')!
|
||||
// osal.cmd_delete('zinit')!
|
||||
|
||||
osal.package_remove('
|
||||
osal.package_remove('
|
||||
podman
|
||||
conmon
|
||||
buildah
|
||||
@@ -80,10 +75,10 @@ fn destroy() ! {
|
||||
runc
|
||||
')!
|
||||
|
||||
// //will remove all paths where go/bin is found
|
||||
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
||||
// //will remove all paths where go/bin is found
|
||||
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
||||
|
||||
osal.rm("
|
||||
osal.rm('
|
||||
podman
|
||||
conmon
|
||||
buildah
|
||||
@@ -94,8 +89,5 @@ fn destroy() ! {
|
||||
/var/lib/buildah
|
||||
/tmp/podman
|
||||
/tmp/conmon
|
||||
")!
|
||||
|
||||
|
||||
')!
|
||||
}
|
||||
|
||||
|
||||
@@ -4,121 +4,109 @@ import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
podman_global map[string]&PodmanInstaller
|
||||
podman_default string
|
||||
podman_global map[string]&PodmanInstaller
|
||||
podman_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet{
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&PodmanInstaller {
|
||||
return &PodmanInstaller{}
|
||||
pub fn get(args_ ArgsGet) !&PodmanInstaller {
|
||||
return &PodmanInstaller{}
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string //if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
|
||||
mut args:=args_
|
||||
mut args := args_
|
||||
|
||||
mut plbook := args.plbook or {
|
||||
playbook.new(text: args.heroscript)!
|
||||
}
|
||||
|
||||
|
||||
mut other_actions := plbook.find(filter: 'podman.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ["destroy","install","build"]{
|
||||
mut p := other_action.params
|
||||
reset:=p.get_default_false("reset")
|
||||
if other_action.name == "destroy" || reset{
|
||||
console.print_debug("install action podman.destroy")
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == "install"{
|
||||
console.print_debug("install action podman.install")
|
||||
install()!
|
||||
}
|
||||
}
|
||||
}
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||
|
||||
mut other_actions := plbook.find(filter: 'podman.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
reset := p.get_default_false('reset')
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action podman.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action podman.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# 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()!
|
||||
}
|
||||
}
|
||||
// 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 struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self PodmanInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut self PodmanInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
destroy()!
|
||||
switch(self.name)
|
||||
destroy()!
|
||||
}
|
||||
|
||||
|
||||
|
||||
//switch instance to be used for podman
|
||||
// switch instance to be used for podman
|
||||
pub fn switch(name string) {
|
||||
podman_default = name
|
||||
podman_default = name
|
||||
}
|
||||
|
||||
|
||||
//helpers
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs{
|
||||
instance string = 'default'
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module podman
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import os
|
||||
@@ -7,34 +8,31 @@ pub const version = '4.9.3'
|
||||
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
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
pub struct PodmanInstaller {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
|
||||
|
||||
//your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ PodmanInstaller)!PodmanInstaller{
|
||||
mut mycfg:=mycfg_
|
||||
return mycfg
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ PodmanInstaller) !PodmanInstaller {
|
||||
mut mycfg := mycfg_
|
||||
return mycfg
|
||||
}
|
||||
|
||||
//called before start if done
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
//mut installer := get()!
|
||||
// mut installer := get()!
|
||||
}
|
||||
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj PodmanInstaller) !string {
|
||||
return encoderhero.encode[PodmanInstaller ](obj)!
|
||||
return encoderhero.encode[PodmanInstaller](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !PodmanInstaller {
|
||||
mut obj := encoderhero.decode[PodmanInstaller](heroscript)!
|
||||
return obj
|
||||
mut obj := encoderhero.decode[PodmanInstaller](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -124,8 +124,8 @@ pub fn profile_path_source() !string {
|
||||
// or empty if it doesn't exist
|
||||
pub fn profile_path_source_and() !string {
|
||||
p := profile_path_source() or { return '' }
|
||||
if p.len==0{
|
||||
return ""
|
||||
if p.len == 0 {
|
||||
return ''
|
||||
}
|
||||
return '${p} && '
|
||||
}
|
||||
@@ -300,7 +300,7 @@ pub fn profile_paths_preferred() ![]string {
|
||||
|
||||
for file in toadd {
|
||||
if os.exists(file) {
|
||||
//println('${file} exists')
|
||||
// println('${file} exists')
|
||||
profile_files2 << file
|
||||
}
|
||||
}
|
||||
@@ -309,7 +309,7 @@ pub fn profile_paths_preferred() ![]string {
|
||||
|
||||
pub fn profile_path() !string {
|
||||
mut preferred := profile_paths_preferred()!
|
||||
if preferred.len==0{
|
||||
if preferred.len == 0 {
|
||||
return error("can't find profile_path, found none")
|
||||
}
|
||||
return preferred[0]
|
||||
|
||||
@@ -53,9 +53,9 @@ pub fn package_install(name_ string) ! {
|
||||
platform_ := core.platform()!
|
||||
cpu := core.cputype()!
|
||||
|
||||
mut sudo_pre:=""
|
||||
mut sudo_pre := ''
|
||||
if core.sudo_required()! {
|
||||
sudo_pre="sudo "
|
||||
sudo_pre = 'sudo '
|
||||
}
|
||||
if platform_ == .osx {
|
||||
if cpu == .arm {
|
||||
@@ -68,10 +68,11 @@ pub fn package_install(name_ string) ! {
|
||||
}
|
||||
}
|
||||
} else if platform_ == .ubuntu {
|
||||
exec(cmd: 'export DEBIAN_FRONTEND=noninteractive && ${sudo_pre}apt install -y ${name} -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --allow-downgrades --allow-remove-essential --allow-change-held-packages')
|
||||
or { return error('could not install package on Ubuntu: ${name}\nerror:\n${err}')}
|
||||
exec(
|
||||
cmd: 'export DEBIAN_FRONTEND=noninteractive && ${sudo_pre}apt install -y ${name} -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --allow-downgrades --allow-remove-essential --allow-change-held-packages'
|
||||
) or { return error('could not install package on Ubuntu: ${name}\nerror:\n${err}') }
|
||||
} else if platform_ == .alpine {
|
||||
exec(cmd: "${sudo_pre}apk add ${name}") or {
|
||||
exec(cmd: '${sudo_pre}apk add ${name}') or {
|
||||
return error('could not install package on Alpine: ${name}\nerror:\n${err}')
|
||||
}
|
||||
} else if platform_ == .arch {
|
||||
|
||||
@@ -55,7 +55,6 @@ pub fn free() !string {
|
||||
if mynum > max_num {
|
||||
max_num = mynum
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// Next available number
|
||||
|
||||
@@ -16,32 +16,7 @@ pub fn (mut self Builder) install_zinit() ! {
|
||||
touch /etc/environment
|
||||
mkdir -p /etc/zinit/
|
||||
'
|
||||
|
||||
// # Define the command to check if zinit is running
|
||||
// CHECK_CMD="pgrep -x zinit"
|
||||
// START_CMD="/sbin/zinit init --container"
|
||||
|
||||
// # Check if zinit is already running
|
||||
// if ! \$CHECK_CMD > /dev/null; then
|
||||
// echo "Zinit is not running. Starting it in a screen session..."
|
||||
|
||||
// # Check if the screen session already exists
|
||||
// if screen -list | grep -q zinitscreen; then
|
||||
// #echo "Screen session zinitscreen already exists. Attaching..."
|
||||
// #screen -r zinitscreen
|
||||
// else
|
||||
// echo "Creating new screen session and starting zinit..."
|
||||
// screen -dmS zinitscreen bash -c "/sbin/zinit init --container"
|
||||
// fi
|
||||
// else
|
||||
// echo "Zinit is already running."
|
||||
// fi
|
||||
|
||||
// zinit list
|
||||
|
||||
// '
|
||||
)!
|
||||
|
||||
self.set_entrypoint('/sbin/zinit init --container')!
|
||||
|
||||
}
|
||||
|
||||
@@ -14,16 +14,14 @@ pub mut:
|
||||
pub fn (mut e CEngine) builder_base(args GetArgs) !Builder {
|
||||
name := 'base'
|
||||
if !args.reset && e.builder_exists(name)! {
|
||||
|
||||
return e.builder_get(name)!
|
||||
}
|
||||
console.print_header('buildah base build')
|
||||
|
||||
|
||||
mut builder := e.builder_new(name: name, from: 'scratch', delete: true)!
|
||||
mount_path := builder.mount_to_path()!
|
||||
if mount_path.len<4{
|
||||
return error("mount_path needs to be +4 chars")
|
||||
if mount_path.len < 4 {
|
||||
return error('mount_path needs to be +4 chars')
|
||||
}
|
||||
osal.exec(
|
||||
cmd: '
|
||||
|
||||
@@ -17,9 +17,9 @@ fn (mut e CEngine) builders_load() ! {
|
||||
@[params]
|
||||
pub struct BuilderNewArgs {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
from string = 'docker.io/ubuntu:latest'
|
||||
delete bool = true
|
||||
name string = 'default'
|
||||
from string = 'docker.io/ubuntu:latest'
|
||||
delete bool = true
|
||||
}
|
||||
|
||||
pub fn (mut e CEngine) builder_new(args_ BuilderNewArgs) !Builder {
|
||||
@@ -65,14 +65,14 @@ pub fn (mut e CEngine) builder_get(name string) !Builder {
|
||||
}
|
||||
|
||||
pub fn (mut e CEngine) builders_delete_all() ! {
|
||||
console.print_debug("remove all")
|
||||
console.print_debug('remove all')
|
||||
osal.execute_stdout('buildah rm -a')!
|
||||
e.builders_load()!
|
||||
}
|
||||
|
||||
pub fn (mut e CEngine) builder_delete(name string) ! {
|
||||
if e.builder_exists(name)! {
|
||||
console.print_debug("remove ${name}")
|
||||
console.print_debug('remove ${name}')
|
||||
osal.execute_stdout('buildah rm ${name}')!
|
||||
e.builders_load()!
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ pub mut:
|
||||
command string
|
||||
}
|
||||
|
||||
|
||||
// create/start container (first need to get a herocontainerscontainer before we can start)
|
||||
pub fn (mut container Container) start() ! {
|
||||
exec(cmd: 'podman start ${container.id}')!
|
||||
|
||||
@@ -2,12 +2,12 @@ module herocontainers
|
||||
|
||||
import time
|
||||
import freeflowuniverse.herolib.osal { exec }
|
||||
import freeflowuniverse.herolib.data.ipaddress { IPAddress }
|
||||
import freeflowuniverse.herolib.data.ipaddress
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.virt.utils
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
//info see https://docs.podman.io/en/latest/markdown/podman-run.1.html
|
||||
// info see https://docs.podman.io/en/latest/markdown/podman-run.1.html
|
||||
|
||||
@[params]
|
||||
pub struct ContainerCreateArgs {
|
||||
@@ -19,46 +19,44 @@ pub struct ContainerCreateArgs {
|
||||
privileged bool
|
||||
remove_when_done bool = true // remove the container when it shuts down
|
||||
// Resource limits
|
||||
memory string // Memory limit (e.g. "100m", "2g")
|
||||
memory_reservation string // Memory soft limit
|
||||
memory_swap string // Memory + swap limit
|
||||
cpus f64 // Number of CPUs (e.g. 1.5)
|
||||
cpu_shares int // CPU shares (relative weight)
|
||||
cpu_period int // CPU CFS period in microseconds (default: 100000)
|
||||
cpu_quota int // CPU CFS quota in microseconds (e.g. 50000 for 0.5 CPU)
|
||||
cpuset_cpus string // CPUs in which to allow execution (e.g. "0-3", "1,3")
|
||||
memory string // Memory limit (e.g. "100m", "2g")
|
||||
memory_reservation string // Memory soft limit
|
||||
memory_swap string // Memory + swap limit
|
||||
cpus f64 // Number of CPUs (e.g. 1.5)
|
||||
cpu_shares int // CPU shares (relative weight)
|
||||
cpu_period int // CPU CFS period in microseconds (default: 100000)
|
||||
cpu_quota int // CPU CFS quota in microseconds (e.g. 50000 for 0.5 CPU)
|
||||
cpuset_cpus string // CPUs in which to allow execution (e.g. "0-3", "1,3")
|
||||
// Network configuration
|
||||
network string // Network mode (bridge, host, none, container:id)
|
||||
network_aliases []string // Add network-scoped aliases
|
||||
exposed_ports []string // Ports to expose without publishing (e.g. "80/tcp", "53/udp")
|
||||
network string // Network mode (bridge, host, none, container:id)
|
||||
network_aliases []string // Add network-scoped aliases
|
||||
exposed_ports []string // Ports to expose without publishing (e.g. "80/tcp", "53/udp")
|
||||
// DNS configuration
|
||||
dns_servers []string // Set custom DNS servers
|
||||
dns_options []string // Set custom DNS options
|
||||
dns_search []string // Set custom DNS search domains
|
||||
dns_servers []string // Set custom DNS servers
|
||||
dns_options []string // Set custom DNS options
|
||||
dns_search []string // Set custom DNS search domains
|
||||
// Device configuration
|
||||
devices []string // Host devices to add (e.g. "/dev/sdc:/dev/xvdc:rwm")
|
||||
device_cgroup_rules []string // Add rules to cgroup allowed devices list
|
||||
devices []string // Host devices to add (e.g. "/dev/sdc:/dev/xvdc:rwm")
|
||||
device_cgroup_rules []string // Add rules to cgroup allowed devices list
|
||||
// Runtime configuration
|
||||
detach bool = true // Run container in background
|
||||
attach []string // Attach to STDIN, STDOUT, and/or STDERR
|
||||
interactive bool // Keep STDIN open even if not attached (-i)
|
||||
detach bool = true // Run container in background
|
||||
attach []string // Attach to STDIN, STDOUT, and/or STDERR
|
||||
interactive bool // Keep STDIN open even if not attached (-i)
|
||||
// Storage configuration
|
||||
rootfs string // Use directory as container's root filesystem
|
||||
mounts []string // Mount filesystem (type=bind,src=,dst=,etc)
|
||||
volumes []string // Bind mount a volume (alternative to mounted_volumes)
|
||||
published_ports []string // Publish container ports to host (alternative to forwarded_ports)
|
||||
rootfs string // Use directory as container's root filesystem
|
||||
mounts []string // Mount filesystem (type=bind,src=,dst=,etc)
|
||||
volumes []string // Bind mount a volume (alternative to mounted_volumes)
|
||||
published_ports []string // Publish container ports to host (alternative to forwarded_ports)
|
||||
pub mut:
|
||||
image_repo string
|
||||
image_tag string
|
||||
command string = '/bin/bash'
|
||||
}
|
||||
|
||||
|
||||
|
||||
// create a new container from an image
|
||||
pub fn (mut e CEngine) container_create(args_ ContainerCreateArgs) !&Container {
|
||||
mut args:=args_
|
||||
|
||||
mut args := args_
|
||||
|
||||
mut cmd := 'podman run --systemd=false'
|
||||
|
||||
// Handle detach/attach options
|
||||
|
||||
@@ -258,7 +258,6 @@ fn (mut site DocSite) template_install() ! {
|
||||
|
||||
cfg := site.config
|
||||
|
||||
|
||||
profile_include := osal.profile_path_source()!
|
||||
|
||||
develop := $tmpl('templates/develop.sh')
|
||||
|
||||
Reference in New Issue
Block a user