forked from cloudscale-ch/cloudscale-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_image_imports.go
103 lines (83 loc) · 3.01 KB
/
custom_image_imports.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
package cloudscale
import (
"context"
"fmt"
"net/http"
)
const customImageImportsBasePath = "v1/custom-images/import"
type CustomImageStub struct {
HREF string `json:"href,omitempty"`
UUID string `json:"uuid,omitempty"`
Name string `json:"name,omitempty"`
}
type CustomImageImport struct {
TaggedResource
// Just use omitempty everywhere. This makes it easy to use restful. Errors
// will be coming from the API if something is disabled.
HREF string `json:"href,omitempty"`
UUID string `json:"uuid,omitempty"`
CustomImage CustomImageStub `json:"custom_image,omitempty"`
URL string `json:"url,omitempty"`
Status string `json:"status,omitempty"`
ErrorMessage string `json:"error_message,omitempty"`
}
type CustomImageImportRequest struct {
TaggedResourceRequest
URL string `json:"url,omitempty"`
Name string `json:"name,omitempty"`
Slug string `json:"slug,omitempty"`
UserDataHandling string `json:"user_data_handling,omitempty"`
FirmwareType string `json:"firmware_type,omitempty"`
SourceFormat string `json:"source_format,omitempty"`
Zones []string `json:"zones,omitempty"`
}
type CustomImageImportsService interface {
Create(ctx context.Context, createRequest *CustomImageImportRequest) (*CustomImageImport, error)
Get(ctx context.Context, CustomImageImportID string) (*CustomImageImport, error)
List(ctx context.Context, modifiers ...ListRequestModifier) ([]CustomImageImport, error)
}
type CustomImageImportsServiceOperations struct {
client *Client
}
func (s CustomImageImportsServiceOperations) Create(ctx context.Context, createRequest *CustomImageImportRequest) (*CustomImageImport, error) {
path := customImageImportsBasePath
req, err := s.client.NewRequest(ctx, http.MethodPost, path, createRequest)
if err != nil {
return nil, err
}
customImageImport := new(CustomImageImport)
err = s.client.Do(ctx, req, customImageImport)
if err != nil {
return nil, err
}
return customImageImport, nil
}
func (s CustomImageImportsServiceOperations) Get(ctx context.Context, CustomImageImportID string) (*CustomImageImport, error) {
path := fmt.Sprintf("%s/%s", customImageImportsBasePath, CustomImageImportID)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}
customImageImport := new(CustomImageImport)
err = s.client.Do(ctx, req, customImageImport)
if err != nil {
return nil, err
}
return customImageImport, nil
}
func (s CustomImageImportsServiceOperations) List(ctx context.Context, modifiers ...ListRequestModifier) ([]CustomImageImport, error) {
path := customImageImportsBasePath
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}
for _, modifier := range modifiers {
modifier(req)
}
customImageImports := []CustomImageImport{}
err = s.client.Do(ctx, req, &customImageImports)
if err != nil {
return nil, err
}
return customImageImports, nil
}