Skip to content

Commit 2ae2e32

Browse files
authored
Merge pull request #33 from liquidweb/cloud-server-create-fixes
fix CloudConfigDetails struct and massage params.Type more if it looks incorrect
2 parents 32376d6 + d4c9331 commit 2ae2e32

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

instance/cloudServerCreate.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,16 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
110110
if params.ConfigId <= 0 {
111111
return "", fmt.Errorf("--config_id is required when not specifying --private-parent")
112112
}
113-
113+
// not on a private parent, shouldnt pass private parent flags
114+
if params.Memory != -1 {
115+
return "", fmt.Errorf("--memory should not be passed with --config-id")
116+
}
117+
if params.Diskspace != -1 {
118+
return "", fmt.Errorf("--diskspace should not be passed with --config-id")
119+
}
120+
if params.Vcpu != -1 {
121+
return "", fmt.Errorf("--vcpu should not be passed with --config-id")
122+
}
114123
}
115124

116125
if params.Template == "" && params.BackupId == -1 && params.ImageId == -1 {
@@ -146,7 +155,6 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
146155
// buildout args for bleed/server/create
147156
createArgs := map[string]interface{}{
148157
"domain": params.Hostname,
149-
"type": params.Type,
150158
"pool_ips": params.PoolIps,
151159
"new_ips": params.Ips,
152160
"zone": params.Zone,
@@ -196,6 +204,24 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
196204
createArgs["image_id"] = params.ImageId
197205
}
198206

207+
// when creating with a config-id, adjust the Type param for bare-metal types if blatantly wrong
208+
var configDetails apiTypes.CloudConfigDetails
209+
if params.ConfigId != -1 {
210+
if err := ci.CallLwApiInto("bleed/storm/config/details",
211+
map[string]interface{}{"id": params.ConfigId}, &configDetails); err != nil {
212+
return "", err
213+
}
214+
if configDetails.Category == "bare-metal" {
215+
if isWindows {
216+
params.Type = "SS.VM.WIN"
217+
} else {
218+
params.Type = "SS.VM"
219+
}
220+
} else if configDetails.Category == "bare-metal-r" {
221+
params.Type = "SS.VM.R"
222+
}
223+
}
224+
199225
// windows servers need special arguments
200226
if isWindows {
201227
if params.WinAv == "" {
@@ -204,20 +230,15 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
204230
createArgs["features"].(map[string]interface{})["WinAV"] = params.WinAv
205231
createArgs["features"].(map[string]interface{})["WindowsLicense"] = "Windows"
206232
if params.Type == "SS.VPS" {
207-
createArgs["type"] = "SS.VPS.WIN"
233+
params.Type = "SS.VPS.WIN"
208234
}
209235
if params.MsSql == "" {
210236
params.MsSql = "None"
211237
}
212238
var coreCnt int
213239
if params.Vcpu == -1 {
214240
// standard config_id create, fetch configs core count and use it
215-
var details apiTypes.CloudConfigDetails
216-
if err := ci.CallLwApiInto("bleed/storm/config/details",
217-
map[string]interface{}{"id": params.ConfigId}, &details); err != nil {
218-
return "", err
219-
}
220-
coreCnt = cast.ToInt(details.Vcpu)
241+
coreCnt = cast.ToInt(configDetails.Vcpu)
221242
} else {
222243
// private parent, use vcpu flag
223244
coreCnt = params.Vcpu
@@ -228,6 +249,8 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
228249
}
229250
}
230251

252+
createArgs["type"] = params.Type
253+
231254
if params.PrivateParent != "" {
232255
createArgs["parent"] = params.PrivateParent
233256
createArgs["vcpu"] = params.Vcpu

types/api/cloud.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ type CloudConfigDetails struct {
213213
RamTotal int64 `json:"ram_total,omitempty" mapstructure:"ram_total"`
214214
RamAvailable int64 `json:"ram_available,omitempty" mapstructure:"ram_available"`
215215
RaidLevel int64 `json:"raid_level,omitempty" mapstructure:"raid_level"`
216-
DiskType int64 `json:"disk_type,omitempty" mapstructure:"disk_type"`
216+
DiskType string `json:"disk_type,omitempty" mapstructure:"disk_type"`
217217
DiskTotal int64 `json:"disk_total,omitempty" mapstructure:"disk_total"`
218218
DiskCount int64 `json:"disk_count,omitempty" mapstructure:"disk_count"`
219219
CpuSpeed int64 `json:"cpu_speed,omitempty" mapstructure:"cpu_speed"`
220-
CpuModel int64 `json:"cpu_model,omitempty" mapstructure:"cpu_model"`
220+
CpuModel string `json:"cpu_model,omitempty" mapstructure:"cpu_model"`
221221
CpuHyperthreading int64 `json:"cpu_hyperthreading,omitempty" mapstructure:"cpu_hyperthreading"`
222222
CpuCount int64 `json:"cpu_count,omitempty" mapstructure:"cpu_count"`
223223
CpuCores int64 `json:"cpu_cores,omitempty" mapstructure:"cpu_cores"`

0 commit comments

Comments
 (0)