server.go raw
1 package storm
2
3 import (
4 "encoding/json"
5 "errors"
6 "net"
7 "strconv"
8
9 liquidweb "github.com/liquidweb/liquidweb-go"
10 "github.com/liquidweb/liquidweb-go/types"
11 )
12
13 // ServerListParams is the set parameters used when listing Storm Servers.
14 type ServerListParams struct {
15 liquidweb.PageParams
16 Parent string `json:"parent,omitempty"`
17 }
18
19 // ServerParams is the set of parameters used when creating or updating a Storm Server.
20 type ServerParams struct {
21 UniqID string `json:"uniq_id,omitempty"`
22 BackupEnabled int `json:"backup_enabled,omitempty"`
23 BackupID int `json:"backup_id,omitempty"`
24 BackupPlan string `json:"backup_plan,omitempty"`
25 BackupQuota int `json:"backup_quota,omitempty"`
26 BandwidthQuota string `json:"bandwidth_quota,omitempty"`
27 ConfigID int `json:"config_id,omitempty"`
28 Domain string `json:"domain,omitempty"`
29 ImageID int `json:"image_id,omitempty"`
30 IPCount int `json:"ip_count,omitempty"`
31 MSSQL string `json:"ms_sql,omitempty"`
32 Password string `json:"password,omitempty"`
33 PublicSSHKey string `json:"public_ssh_key,omitempty"`
34 Template string `json:"template,omitempty"`
35 Zone int `json:"zone,omitempty"`
36 }
37
38 // Server represents the underlying Storm VPS.
39 type Server struct {
40 ACCNT types.FlexInt `json:"accnt,omitempty"`
41 Active types.FlexInt `json:"active,omitempty"`
42 BackupEnabled types.FlexInt `json:"backup_enabled,omitempty"`
43 BackupPlan string `json:"backup_plan,omitempty"`
44 BackupQuota types.FlexInt `json:"backup_quota,omitempty"`
45 BackupSize string `json:"backup_size,omitempty"`
46 BandwidthQuota string `json:"bandwidth_quota,omitempty"`
47 ConfigDescription string `json:"config_description,omitempty"`
48 ConfigID types.FlexInt `json:"config_id,omitempty"`
49 CreateDate types.Timestamp `json:"create_date,omitempty"`
50 DiskSpace types.FlexInt `json:"disk_space,omitempty"`
51 Domain string `json:"domain,omitempty"`
52 IP net.IP `json:"ip,omitempty"`
53 IPCount types.FlexInt `json:"ip_count,omitempty"`
54 ManageLevel string `json:"manage_level,omitempty"`
55 Memory types.FlexInt `json:"memory,omitempty"`
56 Template string `json:"template,omitempty"`
57 TemplateDescription string `json:"template_description,omitempty"`
58 Type string `json:"type,omitempty"`
59 UniqID string `json:"uniq_id,omitempty"`
60 VCPU types.FlexInt `json:"vcpu,omitempty"`
61 Zone ServerZone `json:"zone,omitempty"`
62 }
63
64 // ServerZone represents a numerical representation of the zone data.
65 // Normally, it is nested object like network.Zone
66 type ServerZone types.FlexInt
67
68 func (sz *ServerZone) String() string {
69 return strconv.Itoa(int(*sz))
70 }
71
72 // UnmarshalJSON parses Liquid Web's structured zone data.
73 func (sz *ServerZone) UnmarshalJSON(b []byte) error {
74 data := make(map[string]interface{})
75 err := json.Unmarshal(b, &data)
76 if err != nil {
77 return err
78 }
79
80 zid, ok := data["id"].(float64)
81 if !ok {
82 return errors.New("zone id (id) not present")
83 }
84
85 *sz = ServerZone(types.FlexInt(zid))
86
87 return nil
88 }
89
90 // MarshalJSON marshalls the ServerZone type.
91 func (sz *ServerZone) MarshalJSON() ([]byte, error) {
92 return []byte(sz.String()), nil
93 }
94
95 // ServerStatus represents status of a Storm Server.
96 type ServerStatus struct {
97 DetailedStatus string `json:"detailed_status,omitempty"`
98 Progress types.FlexInt `json:"progress,omitempty"`
99 Running []ServerRunningStatus `json:"running,omitempty"`
100 Status string `json:"status,omitempty"`
101 }
102
103 // ServerStop represents a stopped Storm Server response.
104 type ServerStop struct {
105 Shutdown string `json:"shutdown"`
106 }
107
108 // ServerReboot represents a rebooteed Storm Server response.
109 type ServerReboot struct {
110 Rebooted string `json:"rebooted"`
111 }
112
113 // ServerStart represents a started Storm Server response.
114 type ServerStart struct {
115 Started string `json:"started"`
116 }
117
118 // ServerRunningStatus represents a detailed status step of a Storm Server.
119 type ServerRunningStatus struct {
120 CurrentStep string `json:"current_step,omitempty"`
121 DetailedStatus string `json:"detailed_status,omitempty"`
122 Name string `json:"name,omitempty"`
123 Status string `json:"status,omitempty"`
124 }
125
126 // ServerDeletion represents the API result when deleting a Storm Server.
127 type ServerDeletion struct {
128 Destroyed string `json:"destroyed"`
129 }
130
131 // ServerStates represents the various states the server can be in.
132 var ServerStates = []string{
133 "Building",
134 "Cloning",
135 "Resizing",
136 "Moving",
137 "Booting",
138 "Stopping",
139 "Restarting",
140 "Rebooting",
141 "Shutting Down",
142 "Restoring Backup",
143 "Creating Image",
144 "Deleting Image",
145 "Restoring Image",
146 "Re-Imaging",
147 "Updating Firewall",
148 "Updating Network",
149 "Adding IPs",
150 "Removing IP",
151 "Destroying",
152 "Shutdown", // Undocumented
153 "Provisioning", // Undocumented
154 }
155
156 // ServerList is an envelope for the API result containing either a list of storm configs or an error.
157 type ServerList struct {
158 liquidweb.ListMeta
159 Items []Server
160 }
161