summaryrefslogtreecommitdiff
path: root/main.go
blob: f9aec8a7f1ee067f82a50fa88346e8ebf8a2b8cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0

package main

import (
	"embed"
	"fmt"
	"os"
	"path/filepath"
	"time"

	"go.wit.com/dev/alexflint/arg"
	"go.wit.com/log"
)

var Version string

//go:embed resources/*
var resources embed.FS

func main() {
	if os.Getenv("VIRTIGO_HOME") == "" {
		homeDir, _ := os.UserHomeDir()
		fullpath := filepath.Join(homeDir, ".config/virtigo")
		os.Setenv("VIRTIGO_HOME", fullpath)
	}
	pp := arg.MustParse(&argv)

	if !argv.Uptime {
		pp.WriteHelp(os.Stdout)
		os.Exit(0)
	}

	if argv.Daemon {
		log.DaemonMode(true)
	}

	cfgfile()

	// initialize the grid as unstable
	me.unstable = time.Now()

	// how often to poll the hypervisors
	me.delay = 5 * time.Second

	/*
		log.Info("command line hypervisors:", argv.Hosts)
		for _, name := range argv.Hosts {
			h := findHypervisor(name)
			if h != nil {
				log.Info("command line hypervisor", name, "already in config file")
				continue
			}
			h = addHypervisor(name)
			h.pb.Active = true
		}
	*/

	// start the watchdog polling for each hypervisor
	for _, h := range me.hypers {
		log.Info("starting polling on", h.pb.Hostname)
		go h.NewWatchdog()
	}

	// sit here
	startHTTP()
}

func makeDroplet(start string) {
	d := findDroplet(start)
	if d == nil {
		log.Info("droplet is unknown:", start)
		os.Exit(0)
	}
	log.Info("start droplet here:", d.pb.Hostname)
	domcfg := makeStandardXml(d)

	fmt.Printf("Virt type %s\n", domcfg.Type)
	fmt.Printf("Virt name %s\n", domcfg.Name)
	fmt.Printf("Virt UUID %s\n", domcfg.UUID)
	fmt.Printf("Virt Memory %d %s\n", domcfg.Memory.Value, domcfg.Memory.Unit)

	// test add some ethernet devices
	macs := getMacs(domcfg)
	fmt.Printf("Virt mac addr:%s\n", macs)

	// clearEthernet(domcfg)

	addEthernet(domcfg, "04:44:33:11:22:11", "worldbr")
	addEthernet(domcfg, "04:44:33:33:44:55", "greenbr")

	// add a check here to make these unique
	// setRandomMacs(domcfg)

	// print out the final mac addresses
	macs = getMacs(domcfg)
	fmt.Printf("Virt mac addr:%s\n", macs)

	qcow := "/home/nfs/" + d.pb.Hostname + ".qcow2"
	setSimpleDisk(domcfg, qcow)

	writeoutXml(domcfg, "blahcarr")
	os.Exit(0)
}