@@ -70,14 +70,14 @@ func (s *CloudServerCreateParams) UnmarshalYAML(unmarshal func(interface{}) erro
7070 return nil
7171}
7272
73- func (ci * Client ) CloudServerCreate (params * CloudServerCreateParams ) string {
73+ func (ci * Client ) CloudServerCreate (params * CloudServerCreateParams ) ( string , error ) {
7474 var err error
7575
7676 // if passed a private-parent flag, derive its uniq_id
7777 if params .PrivateParent != "" {
7878 params .PrivateParent , err = ci .DerivePrivateParentUniqId (params .PrivateParent )
7979 if err != nil {
80- ci . Die ( err )
80+ return "" , err
8181 }
8282 }
8383
@@ -94,27 +94,27 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) string {
9494 // sanity check flags
9595 if params .PrivateParent != "" {
9696 if params .ConfigId > 0 {
97- ci . Die ( fmt .Errorf ("--config_id must be 0 or omitted when specifying --private-parent" ) )
97+ return "" , fmt .Errorf ("--config_id must be 0 or omitted when specifying --private-parent" )
9898 }
9999 // create on a private parent. diskspace, memory, vcpu are required.
100100 if params .Memory == - 1 {
101- ci . Die ( fmt .Errorf ("--memory is required when specifying --private-parent" ) )
101+ return "" , fmt .Errorf ("--memory is required when specifying --private-parent" )
102102 }
103103 if params .Diskspace == - 1 {
104- ci . Die ( fmt .Errorf ("--diskspace is required when specifying --private-parent" ) )
104+ return "" , fmt .Errorf ("--diskspace is required when specifying --private-parent" )
105105 }
106106 if params .Vcpu == - 1 {
107- ci . Die ( fmt .Errorf ("--vcpu is required when specifying --private-parent" ) )
107+ return "" , fmt .Errorf ("--vcpu is required when specifying --private-parent" )
108108 }
109109 } else {
110110 if params .ConfigId <= 0 {
111- ci . Die ( fmt .Errorf ("--config_id is required when not specifying --private-parent" ) )
111+ return "" , fmt .Errorf ("--config_id is required when not specifying --private-parent" )
112112 }
113113
114114 }
115115
116116 if params .Template == "" && params .BackupId == - 1 && params .ImageId == - 1 {
117- ci . Die ( fmt .Errorf ("at least one of the following flags must be set --template --image-id --backup-id" ) )
117+ return "" , fmt .Errorf ("at least one of the following flags must be set --template --image-id --backup-id" )
118118 }
119119
120120 validateFields := map [interface {}]interface {}{
@@ -140,7 +140,7 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) string {
140140 validateFields [params .Diskspace ] = "PositiveInt"
141141 }
142142 if err := validate .Validate (validateFields ); err != nil {
143- ci . Die ( err )
143+ return "" , err
144144 }
145145
146146 // buildout args for bleed/server/create
@@ -175,7 +175,7 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) string {
175175 var details apiTypes.CloudBackupDetails
176176 err := ci .CallLwApiInto ("bleed/storm/backup/details" , apiArgs , & details )
177177 if err != nil {
178- ci . Die ( err )
178+ return "" , err
179179 }
180180 if strings .Contains (strings .ToUpper (details .Template ), "WINDOWS" ) {
181181 isWindows = true
@@ -188,7 +188,7 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) string {
188188 var details apiTypes.CloudImageDetails
189189 err := ci .CallLwApiInto ("bleed/storm/image/details" , apiArgs , & details )
190190 if err != nil {
191- ci . Die ( err )
191+ return "" , err
192192 }
193193 if strings .Contains (strings .ToUpper (details .Template ), "WINDOWS" ) {
194194 isWindows = true
@@ -215,7 +215,7 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) string {
215215 var details apiTypes.CloudConfigDetails
216216 if err := ci .CallLwApiInto ("bleed/storm/config/details" ,
217217 map [string ]interface {}{"id" : params .ConfigId }, & details ); err != nil {
218- ci . Die ( err )
218+ return "" , err
219219 }
220220 coreCnt = cast .ToInt (details .Vcpu )
221221 } else {
@@ -245,8 +245,10 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) string {
245245
246246 result , err := ci .LwCliApiClient .Call ("bleed/server/create" , createArgs )
247247 if err != nil {
248- ci . Die ( err )
248+ return "" , err
249249 }
250250
251- return cast .ToString (result .(map [string ]interface {})["uniq_id" ])
251+ params .uniqId = cast .ToString (result .(map [string ]interface {})["uniq_id" ])
252+
253+ return params .uniqId , nil
252254}
0 commit comments