-
Notifications
You must be signed in to change notification settings - Fork 0
/
hypervisors.go
144 lines (122 loc) · 3.63 KB
/
hypervisors.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package goarubacloud
import (
"fmt"
"log"
)
const hypervisorsPath = "GetHypervisors"
// HypervisorsService is an interface for interfacing with the Hypervisors
// endpoints of the Arubacloud API
type HypervisorsService interface {
GetHypervisors() ([]Hypervisor, *Response, error)
FindOsTemplate(HypervisorType, string) (*OSTemplate, error)
}
// HypervisorsServiceOp handles communication with the Hypervisor related methods of the
// Arubacloud API.
type HypervisorsServiceOp struct {
client *Client
}
var _ HypervisorsService = &HypervisorsServiceOp{}
func (s *HypervisorsServiceOp) GetHypervisors() ([]Hypervisor, *Response, error) {
req, err := s.client.NewRequest(hypervisorsPath, nil)
if err != nil {
return nil, nil, err
}
root := new(hypervisorsRoot)
resp, err := s.client.Do(req, root)
if err != nil {
return nil, resp, err
}
return root.Hypervisors, resp, err
}
func (s *HypervisorsServiceOp)FindOsTemplate(hypervisorType HypervisorType, name string)(*OSTemplate, error) {
hypervisors, _, err := s.client.Hypervisors.GetHypervisors()
if err != nil {
log.Println("[ERROR] Unable to fetch hypervisors: ", err)
return nil, err
}
var hypervisor *Hypervisor
for _, hypervisorItem := range hypervisors {
if hypervisorItem.HypervisorType == hypervisorType {
hypervisor = &hypervisorItem
break
}
}
if hypervisor == nil {
return nil, fmt.Errorf("Hypervisor not found for type: %s", hypervisorType)
}
for _, template := range hypervisor.Templates {
if template.Description == name {
return &template, nil
}
}
return nil, fmt.Errorf("Hypervisor '%s' doesn't support template with name '%s'",hypervisorType, name)
}
type HypervisorType int
const (
Microsoft_Hyper_V HypervisorType = 1 + iota
VMWare_Cloud_Pro
Microsoft_Hyper_V_Low_Cost
VMWare_Cloud_Smart
)
var hypervisors = [...]string{
"Microsoft Hyper-V (Cloud Pro)",
"VMWare (Cloud Pro)",
"Microsoft Hyper-V Low Cost (Cloud Pro)",
"VMWare (Cloud Smart)",
}
// String returns the name of the Hypervisor.
func (m HypervisorType) String() string {
return hypervisors[m-1]
}
type Hypervisor struct {
HypervisorServerType int
HypervisorType HypervisorType
Templates []OSTemplate `json:"Templates"`
}
type OSTemplate struct {
ApplianceType int
ArchitectureType int
CompanyID int
CompatiblePreConfiguredPackages []interface{}
Description string
Enabled bool
ExportEnabled bool
FeatureTypes []interface{}
Icon interface{}
Id int
IdentificationCode string
Ipv6Compatible bool
Name string
OSFamily int
OSVersion string
OwnerUserId string
ParentTemplateID int
ProductId int
ResourceBounds []ResourceBounds
Revision string
SshKeyInitializationSupported bool
TemplateExtendedDescription string
TemplateOwnershipType int
TemplatePassword string
TemplateSellingStatus int
TemplateStatus interface{}
TemplateType int
TemplateUsername string
ToolsAvailable bool
}
type ResourceBounds struct {
ResourceType int
Default int
Min int
Max int
}
type OSTemplateDetails struct {
Id int
Name string
Description string
ResourceType int
ResourceId int
CompanyId int
ProductId int
UserId int
}