server_client.go raw
1 package storm
2
3 import liquidweb "github.com/liquidweb/liquidweb-go"
4
5 // ServerBackend is the interface for storm servers.
6 type ServerBackend interface {
7 Create(ServerParams) (*Server, error)
8 List(ServerListParams) (*ServerList, error)
9 Details(string) (*Server, error)
10 Update(ServerParams) (*Server, error)
11 Destroy(string) (*ServerDeletion, error)
12 Status(string) (*ServerStatus, error)
13 Stop(string, ...bool) (*ServerStop, error)
14 Reboot(string) (*ServerReboot, error)
15 Start(string) (*ServerStart, error)
16 }
17
18 // ServerClient is the API client for storm servers.
19 type ServerClient struct {
20 Backend liquidweb.Backend
21 }
22
23 // List will fetch a list of storm servers.
24 func (c *ServerClient) List(params ServerListParams) (*ServerList, error) {
25 var result ServerList
26 err := c.Backend.CallIntoInterface("v1/Storm/Server/list", params, &result)
27 if err != nil {
28 return nil, err
29 }
30
31 return &result, nil
32 }
33
34 // Create a new storm server.
35 func (c *ServerClient) Create(params ServerParams) (*Server, error) {
36 var result Server
37 err := c.Backend.CallIntoInterface("v1/Storm/Server/create", params, &result)
38 if err != nil {
39 return nil, err
40 }
41
42 return &result, nil
43 }
44
45 // Details fetches the details for a storm server.
46 func (c *ServerClient) Details(id string) (*Server, error) {
47 var result Server
48 params := ServerParams{UniqID: id}
49
50 err := c.Backend.CallIntoInterface("v1/Storm/Server/details", params, &result)
51 if err != nil {
52 return nil, err
53 }
54
55 return &result, nil
56 }
57
58 // Update a storm server.
59 func (c *ServerClient) Update(params ServerParams) (*Server, error) {
60 var result Server
61
62 err := c.Backend.CallIntoInterface("v1/Storm/Server/update", params, &result)
63 if err != nil {
64 return nil, err
65 }
66
67 return &result, nil
68 }
69
70 // Destroy a storm server.
71 func (c *ServerClient) Destroy(id string) (*ServerDeletion, error) {
72 var result ServerDeletion
73 params := ServerParams{UniqID: id}
74
75 err := c.Backend.CallIntoInterface("v1/Storm/Server/destroy", params, &result)
76 if err != nil {
77 return nil, err
78 }
79
80 return &result, nil
81 }
82
83 // Status returns the current status of a storm server.
84 func (c *ServerClient) Status(id string) (*ServerStatus, error) {
85 var result ServerStatus
86 params := ServerParams{UniqID: id}
87
88 err := c.Backend.CallIntoInterface("v1/Storm/Server/status", params, &result)
89 if err != nil {
90 return nil, err
91 }
92
93 return &result, nil
94 }
95
96 // Stop a storm server.
97 func (c *ServerClient) Stop(uniqId string, force ...bool) (*ServerStop, error) {
98 var result ServerStop
99 args := map[string]interface{}{
100 "uniq_id": uniqId,
101 }
102
103 if len(force) > 0 {
104 args["force"] = force[0]
105 }
106 err := c.Backend.CallIntoInterface("bleed/server/shutdown", args, &result)
107 if err != nil {
108 return nil, err
109 }
110
111 return &result, nil
112 }
113
114 // Reboot a storm server.
115 func (c *ServerClient) Reboot(uniqId string) (*ServerReboot, error) {
116 var result ServerReboot
117 args := map[string]interface{}{
118 "uniq_id": uniqId,
119 }
120
121 err := c.Backend.CallIntoInterface("bleed/storm/server/reboot", args, &result)
122 if err != nil {
123 return nil, err
124 }
125
126 return &result, nil
127 }
128
129 // Start a Storm Server.
130 func (c *ServerClient) Start(uniqId string) (*ServerStart, error) {
131 var result ServerStart
132 args := map[string]interface{}{
133 "uniq_id": uniqId,
134 }
135
136 err := c.Backend.CallIntoInterface("bleed/server/start", args, &result)
137 if err != nil {
138 return nil, err
139 }
140
141 return &result, nil
142 }
143