@@ -38,16 +38,22 @@ const (
38
38
dockerPrivateConfig = "{ \" ca\" : \" %s\" , \" server-cert\" : \" %s\" , \" server-key\" : \" %s\" }"
39
39
dockerDirExistsMessage = "Docker directory exists"
40
40
41
- missingDockerCertsError = "You should generate docker certificates first. Info can be found here: https://docs.docker.com/articles/https/"
41
+ missingDockerCertsError = "Can not find docker certificates folder %s. You should generate docker certificates first. Info can be found here: https://docs.docker.com/articles/https/"
42
42
provisioningConfDoesNotExistsError = "You should set azure VM provisioning config first"
43
43
invalidCertExtensionError = "Certificate %s is invalid. Please specify %s certificate."
44
44
invalidOSError = "You must specify correct OS param. Valid values are 'Linux' and 'Windows'"
45
45
)
46
46
47
- // REGION PUBLIC METHODS STARTS
47
+ //Region public methods starts
48
48
49
49
func CreateAzureVM (role * Role , dnsName , location string ) error {
50
-
50
+ if len (dnsName ) == 0 {
51
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "dnsName" )
52
+ }
53
+ if len (location ) == 0 {
54
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "location" )
55
+ }
56
+
51
57
err := locationClient .ResolveLocation (location )
52
58
if err != nil {
53
59
return err
@@ -90,7 +96,13 @@ func CreateAzureVM(role *Role, dnsName, location string) error {
90
96
}
91
97
92
98
func CreateHostedService (dnsName , location string ) (string , error ) {
93
-
99
+ if len (dnsName ) == 0 {
100
+ return "" , fmt .Errorf (azure .ParamNotSpecifiedError , "dnsName" )
101
+ }
102
+ if len (location ) == 0 {
103
+ return "" , fmt .Errorf (azure .ParamNotSpecifiedError , "location" )
104
+ }
105
+
94
106
err := locationClient .ResolveLocation (location )
95
107
if err != nil {
96
108
return "" , err
@@ -112,7 +124,10 @@ func CreateHostedService(dnsName, location string) (string, error) {
112
124
}
113
125
114
126
func DeleteHostedService (dnsName string ) error {
115
-
127
+ if len (dnsName ) == 0 {
128
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "dnsName" )
129
+ }
130
+
116
131
requestURL := fmt .Sprintf (azureHostedServiceURL , dnsName )
117
132
requestId , err := azure .SendAzureDeleteRequest (requestURL )
118
133
if err != nil {
@@ -124,6 +139,19 @@ func DeleteHostedService(dnsName string) error {
124
139
}
125
140
126
141
func CreateAzureVMConfiguration (name , instanceSize , imageName , location string ) (* Role , error ) {
142
+ if len (name ) == 0 {
143
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "name" )
144
+ }
145
+ if len (instanceSize ) == 0 {
146
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "instanceSize" )
147
+ }
148
+ if len (imageName ) == 0 {
149
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "imageName" )
150
+ }
151
+ if len (location ) == 0 {
152
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "location" )
153
+ }
154
+
127
155
fmt .Println ("Creating azure VM configuration... " )
128
156
129
157
err := locationClient .ResolveLocation (location )
@@ -140,6 +168,16 @@ func CreateAzureVMConfiguration(name, instanceSize, imageName, location string)
140
168
}
141
169
142
170
func AddAzureLinuxProvisioningConfig (azureVMConfig * Role , userName , password , certPath string ) (* Role , error ) {
171
+ if len (userName ) == 0 {
172
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "userName" )
173
+ }
174
+ if len (password ) == 0 {
175
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "password" )
176
+ }
177
+ if len (certPath ) == 0 {
178
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "certPath" )
179
+ }
180
+
143
181
fmt .Println ("Adding azure provisioning configuration... " )
144
182
145
183
configurationSets := ConfigurationSets {}
@@ -168,7 +206,20 @@ func AddAzureLinuxProvisioningConfig(azureVMConfig *Role, userName, password, ce
168
206
return azureVMConfig , nil
169
207
}
170
208
171
- func SetAzureVMExtension (azureVMConfiguration * Role , name string , publisher string , version string , referenceName string , state string , publicConfigurationValue string , privateConfigurationValue string ) (* Role ) {
209
+ func SetAzureVMExtension (azureVMConfiguration * Role , name string , publisher string , version string , referenceName string , state string , publicConfigurationValue string , privateConfigurationValue string ) (* Role , error ) {
210
+ if len (name ) == 0 {
211
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "name" )
212
+ }
213
+ if len (publisher ) == 0 {
214
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "publisher" )
215
+ }
216
+ if len (version ) == 0 {
217
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "version" )
218
+ }
219
+ if len (referenceName ) == 0 {
220
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "referenceName" )
221
+ }
222
+
172
223
fmt .Printf ("Setting azure VM extension: %s... \n " , name )
173
224
174
225
extension := ResourceExtensionReference {}
@@ -198,10 +249,14 @@ func SetAzureVMExtension(azureVMConfiguration *Role, name string, publisher stri
198
249
199
250
azureVMConfiguration .ResourceExtensionReferences .ResourceExtensionReference = append (azureVMConfiguration .ResourceExtensionReferences .ResourceExtensionReference , extension )
200
251
201
- return azureVMConfiguration
252
+ return azureVMConfiguration , nil
202
253
}
203
254
204
255
func SetAzureDockerVMExtension (azureVMConfiguration * Role , dockerCertDir string , dockerPort int , version string ) (* Role , error ) {
256
+ if len (dockerCertDir ) == 0 {
257
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "dockerCertDir" )
258
+ }
259
+
205
260
if len (version ) == 0 {
206
261
version = "0.3"
207
262
}
@@ -217,11 +272,18 @@ func SetAzureDockerVMExtension(azureVMConfiguration *Role, dockerCertDir string,
217
272
return nil , err
218
273
}
219
274
220
- azureVMConfiguration = SetAzureVMExtension (azureVMConfiguration , "DockerExtension" , "MSOpenTech.Extensions" , version , "DockerExtension" , "enable" , publicConfiguration , privateConfiguration )
275
+ azureVMConfiguration , err = SetAzureVMExtension (azureVMConfiguration , "DockerExtension" , "MSOpenTech.Extensions" , version , "DockerExtension" , "enable" , publicConfiguration , privateConfiguration )
221
276
return azureVMConfiguration , nil
222
277
}
223
278
224
279
func GetVMDeployment (cloudserviceName , deploymentName string ) (* VMDeployment , error ) {
280
+ if len (cloudserviceName ) == 0 {
281
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "cloudserviceName" )
282
+ }
283
+ if len (deploymentName ) == 0 {
284
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "deploymentName" )
285
+ }
286
+
225
287
deployment := new (VMDeployment )
226
288
227
289
requestURL := fmt .Sprintf (azureDeploymentURL , cloudserviceName , deploymentName )
@@ -239,7 +301,13 @@ func GetVMDeployment(cloudserviceName, deploymentName string) (*VMDeployment, er
239
301
}
240
302
241
303
func DeleteVMDeployment (cloudserviceName , deploymentName string ) error {
242
-
304
+ if len (cloudserviceName ) == 0 {
305
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "cloudserviceName" )
306
+ }
307
+ if len (deploymentName ) == 0 {
308
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "deploymentName" )
309
+ }
310
+
243
311
requestURL := fmt .Sprintf (azureDeploymentURL , cloudserviceName , deploymentName )
244
312
requestId , err := azure .SendAzureDeleteRequest (requestURL )
245
313
if err != nil {
@@ -251,6 +319,16 @@ func DeleteVMDeployment(cloudserviceName, deploymentName string) error {
251
319
}
252
320
253
321
func GetRole (cloudserviceName , deploymentName , roleName string ) (* Role , error ) {
322
+ if len (cloudserviceName ) == 0 {
323
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "cloudserviceName" )
324
+ }
325
+ if len (deploymentName ) == 0 {
326
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "deploymentName" )
327
+ }
328
+ if len (roleName ) == 0 {
329
+ return nil , fmt .Errorf (azure .ParamNotSpecifiedError , "roleName" )
330
+ }
331
+
254
332
role := new (Role )
255
333
256
334
requestURL := fmt .Sprintf (azureRoleURL , cloudserviceName , deploymentName , roleName )
@@ -267,7 +345,17 @@ func GetRole(cloudserviceName, deploymentName, roleName string) (*Role, error) {
267
345
return role , nil
268
346
}
269
347
270
- func StartRole (cloudserviceName , deploymentName , roleName string ) (error ) {
348
+ func StartRole (cloudserviceName , deploymentName , roleName string ) error {
349
+ if len (cloudserviceName ) == 0 {
350
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "cloudserviceName" )
351
+ }
352
+ if len (deploymentName ) == 0 {
353
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "deploymentName" )
354
+ }
355
+ if len (roleName ) == 0 {
356
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "roleName" )
357
+ }
358
+
271
359
startRoleOperation := createStartRoleOperation ()
272
360
273
361
startRoleOperationBytes , err := xml .Marshal (startRoleOperation )
@@ -285,7 +373,17 @@ func StartRole(cloudserviceName, deploymentName, roleName string) (error) {
285
373
return nil
286
374
}
287
375
288
- func ShutdownRole (cloudserviceName , deploymentName , roleName string ) (error ) {
376
+ func ShutdownRole (cloudserviceName , deploymentName , roleName string ) error {
377
+ if len (cloudserviceName ) == 0 {
378
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "cloudserviceName" )
379
+ }
380
+ if len (deploymentName ) == 0 {
381
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "deploymentName" )
382
+ }
383
+ if len (roleName ) == 0 {
384
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "roleName" )
385
+ }
386
+
289
387
shutdownRoleOperation := createShutdowRoleOperation ()
290
388
291
389
shutdownRoleOperationBytes , err := xml .Marshal (shutdownRoleOperation )
@@ -303,7 +401,17 @@ func ShutdownRole(cloudserviceName, deploymentName, roleName string) (error) {
303
401
return nil
304
402
}
305
403
306
- func RestartRole (cloudserviceName , deploymentName , roleName string ) (error ) {
404
+ func RestartRole (cloudserviceName , deploymentName , roleName string ) error {
405
+ if len (cloudserviceName ) == 0 {
406
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "cloudserviceName" )
407
+ }
408
+ if len (deploymentName ) == 0 {
409
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "deploymentName" )
410
+ }
411
+ if len (roleName ) == 0 {
412
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "roleName" )
413
+ }
414
+
307
415
restartRoleOperation := createRestartRoleOperation ()
308
416
309
417
restartRoleOperationBytes , err := xml .Marshal (restartRoleOperation )
@@ -321,7 +429,17 @@ func RestartRole(cloudserviceName, deploymentName, roleName string) (error) {
321
429
return nil
322
430
}
323
431
324
- func DeleteRole (cloudserviceName , deploymentName , roleName string ) (error ) {
432
+ func DeleteRole (cloudserviceName , deploymentName , roleName string ) error {
433
+ if len (cloudserviceName ) == 0 {
434
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "cloudserviceName" )
435
+ }
436
+ if len (deploymentName ) == 0 {
437
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "deploymentName" )
438
+ }
439
+ if len (roleName ) == 0 {
440
+ return fmt .Errorf (azure .ParamNotSpecifiedError , "roleName" )
441
+ }
442
+
325
443
requestURL := fmt .Sprintf (azureRoleURL , cloudserviceName , deploymentName , roleName )
326
444
requestId , azureErr := azure .SendAzureDeleteRequest (requestURL )
327
445
if azureErr != nil {
@@ -332,10 +450,10 @@ func DeleteRole(cloudserviceName, deploymentName, roleName string) (error) {
332
450
return nil
333
451
}
334
452
335
- // REGION PUBLIC METHODS ENDS
453
+ //Region public methods ends
336
454
337
455
338
- // REGION PRIVATE METHODS STARTS
456
+ //Region private methods starts
339
457
340
458
func createStartRoleOperation () StartRoleOperation {
341
459
startRoleOperation := StartRoleOperation {}
@@ -377,7 +495,8 @@ func createDockerPrivateConfig(dockerCertDir string) (string, error) {
377
495
if _ , err := os .Stat (certDir ); err == nil {
378
496
fmt .Println (dockerDirExistsMessage )
379
497
} else {
380
- return "" , errors .New (missingDockerCertsError )
498
+ errorMessage := fmt .Sprintf (missingDockerCertsError , certDir )
499
+ return "" , errors .New (errorMessage )
381
500
}
382
501
383
502
caCert , err := parseFileToBase64String (path .Join (certDir , "ca.pem" ))
@@ -666,6 +785,4 @@ func createEndpoint(name string, protocol string, extertalPort int, internalPort
666
785
return endpoint
667
786
}
668
787
669
- // REGION PRIVATE METHODS ENDS
670
-
671
-
788
+ //Region private methods ends
0 commit comments