@@ -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
0 commit comments