-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.go
97 lines (79 loc) · 2.27 KB
/
functions.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
95
96
97
package main
import (
"crypto/tls"
"flag"
"fmt"
"net/http"
"os"
"syscall"
"golang.org/x/term"
)
func ProgUsage() bool {
fmt.Println("Usage : nvgm [--server <PC Name>] [--user <Username>] [--help] [--usage] [--secure-mode] [--debug-mode] [--old-pc]")
fmt.Println("\nFor any improvement request or bug report, please do it on : https://github.com/Golgautier/nutanix_vg_manager")
os.Exit(1)
return true
}
// This function get PE connection info from parameters or from STDIN
func GetPrismInfo() {
// Define all parameters
PC := flag.String("server", "", "Prism Element IP of FQDN")
User := flag.String("user", "", "Prism Element User")
help := flag.Bool("help", false, "Request usage")
usage := flag.Bool("usage", false, "Request usage")
secure := flag.Bool("secure-mode", false, "Request usage")
debug := flag.Bool("debug-mode", false, "Request usage")
compatibility := flag.Bool("old-pc", false, "Request usage")
flag.Parse()
if *help || *usage {
ProgUsage()
}
// Affect or request server value
if *PC == string("") {
fmt.Printf("Please enter Prism Central IP or FQDN : ")
fmt.Scanln(&MyPrism.PC)
} else {
MyPrism.PC = *PC
}
// Affect or request user value
if *User == string("") {
fmt.Printf("Please enter Prism User : ")
fmt.Scanln(&MyPrism.User)
} else {
MyPrism.User = *User
}
// Request password
fmt.Printf("Please enter Prism password for " + MyPrism.User + " : ")
tmp, _ := term.ReadPassword(int(syscall.Stdin))
fmt.Println("")
MyPrism.Password = string(tmp)
// Define API call mode
MyPrism.Mode = "password"
// Deactivate SSL Check
if *secure {
ActivateSSLCheck(true)
} else {
ActivateSSLCheck(false)
}
if *debug {
MyPrism.ActivateDebug("./debug.log")
}
if *compatibility {
MyPrism.Compatibility = true
fmt.Println("Compatibility mode activated (for 2023.2 < PC < 2024.1)")
} else {
MyPrism.Compatibility = false
}
}
// =========== ActivateSSLCheck ===========
func ActivateSSLCheck(value bool) {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: !value}
}
// // =========== CheckErr ===========
// // This function is will handle errors
// func CheckErr(context string, err error) {
// if err != nil {
// fmt.Println("ERROR", context, " : ", err.Error())
// os.Exit(2)
// }
// }