/
main.go
109 lines (96 loc) · 3.89 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/metal3-io/baremetal-operator/cmd/make-bm-worker/templates"
)
func main() {
var username = flag.String("user", "", "username for BMC")
var password = flag.String("password", "", "password for BMC")
var bmcAddress = flag.String("address", "", "address URL for BMC")
var disableCertificateVerification = flag.Bool("disableCertificateVerification", false, "will skip certificate validation when true")
var hardwareProfile = flag.String("hardwareprofile", "", "hardwareProfile to be used")
var macAddress = flag.String("boot-mac", "", "boot-mac for bootMACAddress")
var bootMode = flag.String("boot-mode", "", "boot-mode for host (UEFI, UEFISecureBoot or legacy)")
var verbose = flag.Bool("v", false, "turn on verbose output")
var consumer = flag.String(
"consumer", "", "specify name of a related, existing, consumer to link")
var consumerNamespace = flag.String(
"consumer-namespace", "", "specify namespace of a related, existing, consumer to link")
var automatedCleaningMode = flag.String(
"automatedCleaningMode", "", "automatic cleaning mode for host (metadata or disabled)")
var imageURL = flag.String("image-url", "", "url for the image")
var imageChecksum = flag.String("image-checksum", "", "checksum for the image")
var imageChecksumType = flag.String(
"image-checksum-type", "", "checksum algorithm for the image (md5, sha256 or sha512)")
var imageFormat = flag.String(
"image-format", "", "format of the image (raw, qcow2, vdi, vmdk, or live-iso)")
flag.Parse()
hostName := flag.Arg(0)
if hostName == "" {
fmt.Fprintf(os.Stderr, "Missing name argument\n")
os.Exit(1)
}
if *username == "" {
fmt.Fprintf(os.Stderr, "Missing -user argument\n")
os.Exit(1)
}
if *password == "" {
fmt.Fprintf(os.Stderr, "Missing -password argument\n")
os.Exit(1)
}
if *bmcAddress == "" {
fmt.Fprintf(os.Stderr, "Missing -address argument\n")
os.Exit(1)
}
if *bootMode != "" && *bootMode != "UEFI" && *bootMode != "UEFISecureBoot" && *bootMode != "legacy" {
fmt.Fprintf(os.Stderr, "Invalid boot mode %q, use \"UEFI\", \"UEFISecureBoot\" or \"legacy\"\n", *bootMode)
os.Exit(1)
}
if *automatedCleaningMode != "" && *automatedCleaningMode != "metadata" && *automatedCleaningMode != "disabled" {
fmt.Fprintf(os.Stderr, "Invalid automatic cleaning mode %q, use \"metadata\" or \"disabled\"\n", *automatedCleaningMode)
os.Exit(1)
}
switch *imageChecksumType {
case "", "md5", "sha256", "sha512", "auto":
default:
fmt.Fprintf(os.Stderr, "Invalid image checksum type %q, use \"md5\", \"sha256\", \"sha512\" or \"auto\"\n", *imageChecksumType)
os.Exit(1)
}
switch *imageFormat {
case "", "raw", "qcow2", "vdi", "vmdk", "live-iso":
default:
fmt.Fprintf(os.Stderr, "Invalid image format %q, use \"raw\", \"qcow2\", \"vdi\", \"vmdk\" or \"live-iso\"\n", *imageFormat)
os.Exit(1)
}
template := templates.Template{
Name: strings.Replace(hostName, "_", "-", -1),
BMCAddress: *bmcAddress,
DisableCertificateVerification: *disableCertificateVerification,
Username: *username,
Password: *password,
HardwareProfile: *hardwareProfile,
BootMacAddress: *macAddress,
Consumer: strings.TrimSpace(*consumer),
ConsumerNamespace: strings.TrimSpace(*consumerNamespace),
AutomatedCleaningMode: *automatedCleaningMode,
ImageURL: *imageURL,
ImageChecksum: *imageChecksum,
ImageChecksumType: *imageChecksumType,
ImageFormat: *imageFormat,
}
if bootMode != nil {
template.BootMode = *bootMode
}
if *verbose {
fmt.Fprintf(os.Stderr, "%v", template)
}
result, err := template.Render()
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", err)
os.Exit(1)
}
fmt.Fprint(os.Stdout, result)
}