-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (77 loc) · 2.57 KB
/
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
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
/**
When we launch for the first time, we need to :
A - Check if VirtualBox and Putty, Ssh are installed
B - Always get the list of VM
C - json file exist?
D - If not, ask for installation:
List of Virtualbox's VMs:
1. "CentOS 7"
2. "Ubuntu 16.04.3 Server"
Select the vm to launch: _
D - Save new JSON file
E - If yes, check if the default vm is still in the list we got from (B)
*/
package main
import (
"fmt"
"./vmbox"
"./vmjson"
"./vmputty"
)
// JSONFILENAME : JSON Filename
const JSONFILENAME = "lavie.json"
func extractJSON(filename string) {
// Open, read and get the structurized data from json file
configVM := vmjson.GetJSON(filename)
// Just print the data we got
fmt.Println("Default access entity:", configVM.Access)
fmt.Println("access.ssh:")
fmt.Println("Program:", configVM.SSH.Program)
fmt.Println("access.putty:")
fmt.Println("Program:", configVM.Putty.Program)
fmt.Println("Default Session:", configVM.Putty.Default)
// we iterate through JSONconfig.sessions
count := len(configVM.Putty.Sessions)
fmt.Printf("There is %d sessions:\n", count)
for i := 0; i < count; i++ {
fmt.Println(configVM.Putty.Sessions[i])
}
count = len(configVM.VirtualBoxVMS)
fmt.Printf("There is %d VMs:\n", count)
for i := 0; i < count; i++ {
fmt.Println(" Name:", configVM.VirtualBoxVMS[i].Name)
fmt.Println(" UUID:", configVM.VirtualBoxVMS[i].UUID)
fmt.Println(" User:", configVM.VirtualBoxVMS[i].Username)
fmt.Println(" Pass:", configVM.VirtualBoxVMS[i].Password)
fmt.Println("----------")
}
}
// In 'vboxmanage.go' init() is always called, regardless if there's main or not,
// so if you import a package that has an init function, it will be executed
func main() {
if vmbox.VBoxManagePath != "" {
fmt.Println("VboxManage is in the following directory:", vmbox.VBoxManagePath)
fmt.Println("----------")
listVMS, _ := vmbox.ListVMS()
fmt.Printf("List of %d Virtualbox's VMs:\n", len(listVMS))
for _, listVM := range listVMS {
fmt.Printf("%-40s - UUID: %s\n", listVM.Name, listVM.UUID)
}
fmt.Println("----------")
} else {
fmt.Println("VirtualBox is not installed or cannot find VBoxManage.exe")
}
fmt.Println("List of Putty's sessions:")
sessions, count := vmputty.GetPuttySession()
if count > 0 {
fmt.Println("Putty have", count, "sessions:")
for _, session := range sessions {
fmt.Println("-", session)
}
} else {
fmt.Println("There is no Putty's sessions available.")
}
fmt.Println("----------")
fmt.Printf("Data in %s file:\n", JSONFILENAME)
extractJSON(JSONFILENAME)
}