-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (43 loc) · 1006 Bytes
/
main.go
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
package main
import (
"log"
"os"
"strings"
inize "github.com/ExaServe/inizer/libinizer"
)
const LOGFILE = "/var/log/inizer.log"
const LOCKFILE = "/var/lib/.inizer.VM"
func ActUponAction() {
action, err := inize.GetVendorData()
if err != nil {
log.Fatal(err)
}
switch {
case strings.Contains(action, "SetAnchor"):
inize.AssignAnchorIP()
fallthrough
case strings.Contains(action, "NewVM"):
// Don't Initialize in case there is a lock file
if _, err := os.Stat("/var/lib/.inizer.VM"); err != nil {
inize.InizeVm()
//Create LockFile to prevent reInializing the VM
os.Create(LOCKFILE)
}
fallthrough
default:
inize.ResetPassword()
inize.AssignPrivatIP()
inize.ResizeDisk()
}
}
func main() {
// Set logging output, append to file and create if not exist
f, err := os.OpenFile(LOGFILE, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("Error opening logfile: %v", err)
}
defer f.Close()
log.SetOutput(f)
inize.DoUpdate()
ActUponAction()
}