-
Notifications
You must be signed in to change notification settings - Fork 1
/
compute_content_library.go
161 lines (137 loc) · 4.72 KB
/
compute_content_library.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package client
import (
"context"
"time"
)
type ContentLibraryClient struct {
c *Client
}
func (c *ComputeClient) ContentLibrary() *ContentLibraryClient {
return &ContentLibraryClient{c.c}
}
type ContentLibrary struct {
ID string `terraform:"id"`
Name string `terraform:"name"`
MachineManagerID string `terraform:"machine_manager_id"`
Type string `terraform:"type"`
Datastore DatastoreLink `terraform:"datastore"`
}
type DatastoreLink struct {
ID string `terraform:"id"`
Name string `terraform:"name"`
}
type ContentLibraryFilter struct {
Name string `filter:"name"`
MachineManagerId string `filter:"machineManagerId"`
}
func (c *ContentLibraryClient) List(ctx context.Context, filter *ContentLibraryFilter) ([]*ContentLibrary, error) {
r := c.c.newRequest("GET", "/compute/v1/vcenters/content_libraries")
r.addFilter(filter)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
}
defer closeResponseBody(resp)
if err := requireOK(resp); err != nil {
return nil, err
}
var out []*ContentLibrary
if err := decodeBody(resp, &out); err != nil {
return nil, err
}
return out, nil
}
func (c *ContentLibraryClient) Read(ctx context.Context, id string) (*ContentLibrary, error) {
r := c.c.newRequest("GET", "/compute/v1/vcenters/content_libraries/%s", id)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
}
defer closeResponseBody(resp)
found, err := requireNotFoundOrOK(resp, 403)
if err != nil || !found {
return nil, err
}
var out ContentLibrary
if err := decodeBody(resp, &out); err != nil {
return nil, err
}
return &out, nil
}
type ContentLibraryItem struct {
ID string `terraform:"id"`
ContentLibraryId string `terraform:"content_library_id"`
Name string `terraform:"name"`
Description string `terraform:"description"`
Type string `terraform:"type"`
CreationTime time.Time `terraform:"creation_time"`
Size int `terraform:"size"`
Stored bool `terraform:"stored"`
LastModifiedTime string `terraform:"last_modified_time"`
OvfProperties []string `terraform:"ovf_properties"`
}
type ContentLibraryItemFilter struct {
Name string `filter:"name"`
ContentLibraryId string `terraform:"content_library_id"`
}
func (c *ContentLibraryClient) ListItems(ctx context.Context, filter *ContentLibraryItemFilter) ([]*ContentLibraryItem, error) {
r := c.c.newRequest("GET", "/compute/v1/vcenters/content_libraries/%s/items", filter.ContentLibraryId)
r.addFilter(filter)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
}
defer closeResponseBody(resp)
found, err := requireNotFoundOrOK(resp, 403)
if err != nil || !found {
return nil, err
}
var out []*ContentLibraryItem
if err := decodeBody(resp, &out); err != nil {
return nil, err
}
return out, nil
}
func (c *ContentLibraryClient) ReadItem(ctx context.Context, contentLibraryId, contentLibraryItemId string) (*ContentLibraryItem, error) {
r := c.c.newRequest("GET", "/compute/v1/vcenters/content_libraries/%s/items/%s", contentLibraryId, contentLibraryItemId)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
}
defer closeResponseBody(resp)
found, err := requireNotFoundOrOK(resp, 403)
if err != nil || !found {
return nil, err
}
var out ContentLibraryItem
if err := decodeBody(resp, &out); err != nil {
return nil, err
}
return &out, nil
}
type ComputeContentLibraryItemDeployRequest struct {
ContentLibraryId string `json:"-"`
ContentLibraryItemId string `json:"contentLibraryItemId"`
Name string `json:"name"`
HostClusterId string `json:"hostClusterId,omitempty"`
HostId string `json:"hostId,omitempty"`
DatastoreId string `json:"datastoreId,"`
DatacenterId string `json:"datacenterId,omitempty"`
PowerOn bool `json:"powerOn"`
DisksProvisioningType string `json:"disksProvisioningType,omitempty"`
DeployOptions []*DeployOption `json:"deployOptions,omitempty"`
NetworkData []*NetworkData `json:"networkData,omitempty"`
}
type DeployOption struct {
ID string `json:"id"`
Value string `json:"value"`
}
type NetworkData struct {
NetworkAdapterId string `json:"networkAdapterId"`
NetworkId string `json:"networkId"`
}
func (c *ContentLibraryClient) Deploy(ctx context.Context, req *ComputeContentLibraryItemDeployRequest) (string, error) {
r := c.c.newRequest("POST", "/compute/v1/vcenters/content_libraries/%s/items", req.ContentLibraryId)
r.obj = req
return c.c.doRequestAndReturnActivity(ctx, r)
}