/
hcloud.go
56 lines (53 loc) · 1.21 KB
/
hcloud.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
package state
import (
"bytes"
)
func (s *HCloudServerCreateOpts) Args() ([]string, *bytes.Buffer, error) {
args := []string{
"server", "create",
// required
"--type", s.Type,
"--image", s.Image,
"--name", s.Name,
}
if s.Location != nil {
args = append(args, "--location", *s.Location)
}
if s.Datacenter != nil {
args = append(args, "--datacenter", *s.Datacenter)
}
if s.StartAfterCreate {
args = append(args, "--start-after-create")
}
if s.Automount {
args = append(args, "--automount")
}
for _, value := range s.Labels {
args = append(args, "--label", value)
}
for _, value := range s.Volumes {
args = append(args, "--volume", value)
}
for _, value := range s.Networks {
args = append(args, "--network", value)
}
for _, value := range s.Firewalls {
args = append(args, "--firewall", value)
}
if s.PlacementGroup != nil {
args = append(args, "--placement-group", *s.PlacementGroup)
}
var data bytes.Buffer
if s.UserData != nil {
content, err := s.UserData.Content()
if err != nil {
return nil, nil, err
}
_, err = data.Write([]byte(content))
if err != nil {
return nil, nil, err
}
args = append(args, "--user-data-from-file", "-")
}
return args, &data, nil
}