-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
81 lines (64 loc) · 1.77 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
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/czerwonk/ovirt_api/api"
)
const version string = "0.2.3"
var (
showVersion = flag.Bool("version", false, "Prints version info")
listenAddress = flag.String("listen-address", ":11337", "Address to listen for web service requests")
user = flag.String("username", "user@internal", "API username")
pass = flag.String("password", "", "API password")
apiURL = flag.String("api-url", "https://ovirt.engine/ovirt-engine/api", "API url")
insecure = flag.Bool("insecure", false, "Skip SSL verification")
templateFile = flag.String("template", "ovirt_vm_template.xml", "Template file path")
debug = flag.Bool("debug", false, "Enables verbose output")
)
func init() {
flag.Usage = func() {
fmt.Println("Usage: ovirt-zero-touch [ ... ]\n\nParameters:")
fmt.Println()
flag.PrintDefaults()
}
}
func main() {
flag.Parse()
if *showVersion {
printVersion()
os.Exit(0)
}
log.Println("ovirt-zero-touch " + version)
h := newHandler(newAPIClient, loadTemaplate)
log.Println("Server started. Start listening on " + *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, h))
}
func printVersion() {
fmt.Println("ovirt-zero-touch")
fmt.Printf("Version: %s\n", version)
fmt.Println("Author(s): Daniel Czerwonk")
}
func loadTemaplate() ([]byte, error) {
return ioutil.ReadFile(*templateFile)
}
type apiClientAdapter struct {
*api.Client
}
func newAPIClient() (apiClient, error) {
opts := []api.ClientOption{}
if *insecure {
opts = append(opts, api.WithInsecure())
}
if *debug {
opts = append(opts, api.WithDebug())
}
c, err := api.NewClient(*apiURL, *user, *pass, opts...)
if err != nil {
return nil, err
}
return &apiClientAdapter{c}, nil
}