-
Notifications
You must be signed in to change notification settings - Fork 23
/
instance.go
55 lines (43 loc) · 956 Bytes
/
instance.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
package compute
import (
"fmt"
"strings"
gcpcompute "google.golang.org/api/compute/v1"
)
type Instance struct {
client instancesClient
name string
clearerName string
zone string
}
func NewInstance(client instancesClient, name, zone string, tags *gcpcompute.Tags) Instance {
clearerName := name
extra := []string{}
if tags != nil && len(tags.Items) > 0 {
for _, tag := range tags.Items {
extra = append(extra, tag)
}
}
if len(extra) > 0 {
clearerName = fmt.Sprintf("%s (%s)", name, strings.Join(extra, ", "))
}
return Instance{
client: client,
name: name,
clearerName: clearerName,
zone: zone,
}
}
func (i Instance) Delete() error {
err := i.client.DeleteInstance(i.zone, i.name)
if err != nil {
return fmt.Errorf("Delete: %s", err)
}
return nil
}
func (i Instance) Name() string {
return i.clearerName
}
func (i Instance) Type() string {
return "Compute Instance"
}