-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathosImages.go
92 lines (77 loc) · 2.83 KB
/
osImages.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
package solus
import (
"context"
"fmt"
"gopkg.in/guregu/null.v4"
)
// OsImagesService handles all available methods with OS image.
type OsImagesService service
// OsImage represent an OS image.
type OsImage struct {
ID int `json:"id"`
Name string `json:"name"`
Icon Icon `json:"icon"`
Versions []OsImageVersion `json:"versions,omitempty"`
IsDefault bool `json:"is_default,omitempty"`
IsVisible bool `json:"is_visible,omitempty"`
Position float32 `json:"position"`
}
// OsImageRequest represents available properties for creating a new OS image.
type OsImageRequest struct {
Name string `json:"name"`
IconID null.Int `json:"icon_id"`
IsVisible bool `json:"is_visible"`
}
// OsImagesResponse represents paginated list of OS images.
// This cursor can be used for iterating over all available OS images.
type OsImagesResponse struct {
paginatedResponse
Data []OsImage `json:"data"`
}
type osImageResponse struct {
Data OsImage `json:"data"`
}
// List lists OS images.
func (s *OsImagesService) List(ctx context.Context, filter *FilterOsImages) (OsImagesResponse, error) {
resp := OsImagesResponse{
paginatedResponse: paginatedResponse{
service: (*service)(s),
},
}
return resp, s.client.list(ctx, "os_images", &resp, withFilter(filter.data))
}
// Get gets specified OS image.
func (s *OsImagesService) Get(ctx context.Context, id int) (OsImage, error) {
var resp osImageResponse
return resp.Data, s.client.get(ctx, fmt.Sprintf("os_images/%d", id), &resp)
}
// Create creates specified OS image.
func (s *OsImagesService) Create(ctx context.Context, data OsImageRequest) (OsImage, error) {
var resp osImageResponse
return resp.Data, s.client.create(ctx, "os_images", data, &resp)
}
// Update updates specified OS image.
func (s *OsImagesService) Update(ctx context.Context, id int, data OsImageRequest) (OsImage, error) {
var resp osImageResponse
return resp.Data, s.client.update(ctx, fmt.Sprintf("os_images/%d", id), data, &resp)
}
// Delete deletes specified OS image.
func (s *OsImagesService) Delete(ctx context.Context, id int) error {
return s.client.syncDelete(ctx, fmt.Sprintf("os_images/%d", id))
}
// CreateVersion creates a new version for the specified OS image.
func (s *OsImagesService) CreateVersion(
ctx context.Context,
osImageID int,
data OsImageVersionRequest,
) (OsImageVersion, error) {
var resp osImageVersionResponse
return resp.Data, s.client.create(ctx, fmt.Sprintf("os_images/%d/versions", osImageID), data, &resp)
}
// ListVersion lists specified OS image versions.
func (s *OsImagesService) ListVersion(ctx context.Context, osImageID int) ([]OsImageVersion, error) {
var resp struct {
Data []OsImageVersion `json:"data"`
}
return resp.Data, s.client.list(ctx, fmt.Sprintf("os_images/%d/versions", osImageID), &resp)
}