FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cloudstack/awsapi/src/com/cloud/stack/CloudStackApi.java at master · jonludlam/cloudstack · GitHub
jonludlam
/
cloudstack
Public
forked from
apache/cloudstack
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cloudstack
/
awsapi
/
src
/
com
/
cloud
/
stack
/
CloudStackApi.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
2603 lines (2484 loc) · 102 KB
Breadcrumbs
cloudstack
/
awsapi
/
src
/
com
/
cloud
/
stack
/
CloudStackApi.java
Copy path
File metadata and controls
2603 lines (2484 loc) · 102 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package
com
.
cloud
.
stack
;
import
java
.
util
.
List
;
import
org
.
apache
.
log4j
.
Logger
;
import
com
.
google
.
gson
.
reflect
.
TypeToken
;
import
com
.
cloud
.
stack
.
models
.
ApiConstants
;
import
com
.
cloud
.
stack
.
models
.
CloudStackAccount
;
import
com
.
cloud
.
stack
.
models
.
CloudStackCapabilities
;
import
com
.
cloud
.
stack
.
models
.
CloudStackDiskOffering
;
import
com
.
cloud
.
stack
.
models
.
CloudStackEvent
;
import
com
.
cloud
.
stack
.
models
.
CloudStackEventType
;
import
com
.
cloud
.
stack
.
models
.
CloudStackExtractTemplate
;
import
com
.
cloud
.
stack
.
models
.
CloudStackIdentifier
;
import
com
.
cloud
.
stack
.
models
.
CloudStackInfoResponse
;
import
com
.
cloud
.
stack
.
models
.
CloudStackInstanceGroup
;
import
com
.
cloud
.
stack
.
models
.
CloudStackIpAddress
;
import
com
.
cloud
.
stack
.
models
.
CloudStackKeyPair
;
import
com
.
cloud
.
stack
.
models
.
CloudStackKeyValue
;
import
com
.
cloud
.
stack
.
models
.
CloudStackLoadBalancerRule
;
import
com
.
cloud
.
stack
.
models
.
CloudStackNetwork
;
import
com
.
cloud
.
stack
.
models
.
CloudStackNetworkOffering
;
import
com
.
cloud
.
stack
.
models
.
CloudStackOsCategory
;
import
com
.
cloud
.
stack
.
models
.
CloudStackOsType
;
import
com
.
cloud
.
stack
.
models
.
CloudStackPasswordData
;
import
com
.
cloud
.
stack
.
models
.
CloudStackPortForwardingRule
;
import
com
.
cloud
.
stack
.
models
.
CloudStackResourceLimit
;
import
com
.
cloud
.
stack
.
models
.
CloudStackResourceTag
;
import
com
.
cloud
.
stack
.
models
.
CloudStackSecurityGroup
;
import
com
.
cloud
.
stack
.
models
.
CloudStackServiceOffering
;
import
com
.
cloud
.
stack
.
models
.
CloudStackSnapshot
;
import
com
.
cloud
.
stack
.
models
.
CloudStackSnapshotPolicy
;
import
com
.
cloud
.
stack
.
models
.
CloudStackTemplate
;
import
com
.
cloud
.
stack
.
models
.
CloudStackTemplatePermission
;
import
com
.
cloud
.
stack
.
models
.
CloudStackUserVm
;
import
com
.
cloud
.
stack
.
models
.
CloudStackVolume
;
import
com
.
cloud
.
stack
.
models
.
CloudStackZone
;
/**
* The goal here is to wrap the actual CloudStack API calls...
*
*
*/
public
class
CloudStackApi
{
protected
final
static
Logger
logger
=
Logger
.
getLogger
(
CloudStackApi
.
class
);
private
CloudStackClient
_client
;
private
String
apiKey
;
private
String
secretKey
;
/**
*
*/
public
CloudStackApi
(
String
cloudStackServiceHost
,
String
port
,
Boolean
bSslEnabled
) {
if
(
port
!=
null
) {
// initialize port to 8080, incase port is NULL
int
ourPort
=
8080
;
if
(
port
!=
null
)
ourPort
=
Integer
.
parseInt
(
port
);
_client
=
new
CloudStackClient
(
cloudStackServiceHost
,
ourPort
,
bSslEnabled
);
}
else
{
_client
=
new
CloudStackClient
(
cloudStackServiceHost
);
}
apiKey
=
null
;
secretKey
=
null
;
}
/**
* @return the apiKey
*/
public
String
getApiKey
() {
return
apiKey
;
}
/**
* @return the secretKey
*/
public
String
getSecretKey
() {
return
secretKey
;
}
/**
* @param apiKey the apiKey to set
*/
public
void
setApiKey
(
String
apiKey
) {
this
.
apiKey
=
apiKey
;
}
/**
* @param secretKey the secretKey to set
*/
public
void
setSecretKey
(
String
secretKey
) {
this
.
secretKey
=
secretKey
;
}
// Virtual Machines
/**
* deploy a virtual machine
*
* @param serviceOfferingId
* @param templateId
* @param zoneId
* @param account
* @param diskOfferingId
* @param displayName
* @param domainId
* @param group
* @param hostId
* @param hypervisor
* @param keyPair
* @param name
* @param networkId
* @param securityGroupIds
* @param securityGroupNames
* @param size
* @param userData
* @return
* @throws Exception
*/
public
CloudStackUserVm
deployVirtualMachine
(
String
serviceOfferingId
,
String
templateId
,
String
zoneId
,
String
account
,
String
diskOfferingId
,
String
displayName
,
String
domainId
,
String
group
,
String
hostId
,
String
hypervisor
,
String
keyPair
,
String
name
,
String
networkId
,
String
securityGroupIds
,
String
securityGroupNames
,
Long
size
,
String
userData
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
DEPLOY_VIRTUAL_MACHINE
);
if
(
cmd
!=
null
) {
// these are required
cmd
.
setParam
(
ApiConstants
.
SERVICE_OFFERING_ID
,
serviceOfferingId
);
cmd
.
setParam
(
ApiConstants
.
TEMPLATE_ID
,
templateId
);
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
// these aren't
if
(
account
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNT
,
account
);
if
(
diskOfferingId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DISK_OFFERING_ID
,
diskOfferingId
);
if
(
displayName
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DISPLAY_NAME
,
displayName
);
if
(
domainId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DOMAIN_ID
,
domainId
);
if
(
group
!=
null
)
cmd
.
setParam
(
ApiConstants
.
GROUP
,
group
);
if
(
hostId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
HOST_ID
,
hostId
);
if
(
hypervisor
!=
null
)
cmd
.
setParam
(
ApiConstants
.
HYPERVISOR
,
hypervisor
);
if
(
keyPair
!=
null
)
cmd
.
setParam
(
ApiConstants
.
SSH_KEYPAIR
,
keyPair
);
if
(
name
!=
null
)
cmd
.
setParam
(
ApiConstants
.
NAME
,
name
);
if
(
networkId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
NETWORK_IDS
,
networkId
);
if
(
securityGroupIds
!=
null
)
cmd
.
setParam
(
ApiConstants
.
SECURITY_GROUP_IDS
,
securityGroupIds
);
if
(
securityGroupNames
!=
null
)
cmd
.
setParam
(
ApiConstants
.
SECURITY_GROUP_NAMES
,
securityGroupNames
);
if
(
size
!=
null
)
cmd
.
setParam
(
ApiConstants
.
SIZE
,
size
.
toString
());
if
(
userData
!=
null
)
cmd
.
setParam
(
ApiConstants
.
USER_DATA
,
userData
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
DEPLOY_VIRTUAL_MACHINE_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* destroy's a virtual machine
*
* @param id
* @return
* @throws Exception
*/
public
CloudStackUserVm
destroyVirtualMachine
(
String
id
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
DESTROY_VIRTUAL_MACHINE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
DESTROY_VIRTUAL_MACHINE_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* reboot a virtual machine
*
* @param id
* @return
* @throws Exception
*/
public
CloudStackUserVm
rebootVirtualMachine
(
String
id
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
REBOOT_VIRTUAL_MACHINE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
REBOOT_VIRTUAL_MACHINE_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* start a virtual machine
*
* @param id
* @return
* @throws Exception
*/
public
CloudStackUserVm
startVirtualMachine
(
String
id
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
START_VIRTUAL_MACHINE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
START_VIRTUAL_MACHINE_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* stop a virtual machine
*
* @param id
* @param forced
* @return
* @throws Exception
*/
public
CloudStackUserVm
stopVirtualMachine
(
String
id
,
Boolean
forced
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
STOP_VIRTUAL_MACHINE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
forced
!=
null
)
cmd
.
setParam
(
ApiConstants
.
FORCED
,
forced
.
toString
());
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
STOP_VIRTUAL_MACHINE_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* reset password for virtual machine
*
* @param id
* @return
* @throws Exception
*/
public
CloudStackUserVm
resetPasswordForVirtualMachine
(
String
id
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
RESET_PASSWORD_FOR_VIRTUAL_MACHINE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
RESET_PASSWORD_FOR_VIRTUAL_MACHINE_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* change service for virtual machine
*
* @param id
* @param serviceOfferingId
* @return
* @throws Exception
*/
public
CloudStackUserVm
changeServiceForVirtualMachine
(
String
id
,
String
serviceOfferingId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
CHANGE_SERVICE_FOR_VIRTUAL_MACHINE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
cmd
.
setParam
(
ApiConstants
.
SERVICE_OFFERING_ID
,
serviceOfferingId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
CHANGE_SERVICE_FOR_VIRTUAL_MACHINE_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* update a virtual machine
*
* @param id
* @param displayName
* @param group
* @param haEnable
* @param osTypeId
* @param userData
* @return
* @throws Exception
*/
public
CloudStackUserVm
updateVirtualMachine
(
String
id
,
String
displayName
,
String
group
,
Boolean
haEnable
,
String
osTypeId
,
String
userData
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
UPDATE_VIRTUAL_MACHINE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
displayName
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DISPLAY_NAME
,
displayName
);
if
(
group
!=
null
)
cmd
.
setParam
(
ApiConstants
.
GROUP
,
group
);
if
(
haEnable
!=
null
)
cmd
.
setParam
(
ApiConstants
.
HA_ENABLE
,
haEnable
.
toString
());
if
(
osTypeId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
OS_TYPE_ID
,
osTypeId
);
if
(
userData
!=
null
)
cmd
.
setParam
(
ApiConstants
.
USER_DATA
,
userData
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
UPDATE_VIRTUAL_MACHINE_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* list virtual machines
*
* @param account
* @param accountId
* @param forVirtualNetwork
* @param groupId
* @param hostId
* @param hypervisor
* @param id
* @param isRecursive
* @param keyWord
* @param name
* @param networkId
* @param podId
* @param state
* @param storageId
* @param zoneId
* @return
* @throws Exception
*/
public
List
<
CloudStackUserVm
>
listVirtualMachines
(
String
account
,
String
accountId
,
Boolean
listAll
,
Boolean
forVirtualNetwork
,
String
groupId
,
String
hostId
,
String
hypervisor
,
String
id
,
Boolean
isRecursive
,
String
keyWord
,
String
name
,
String
networkId
,
String
podId
,
String
state
,
String
storageId
,
String
zoneId
,
List
<
CloudStackKeyValue
>
resourceTags
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
LIST_VIRTUAL_MACHINES
);
if
(
cmd
!=
null
) {
if
(
account
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNT
,
account
);
if
(
accountId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNT_ID
,
accountId
);
if
(
listAll
!=
null
)
cmd
.
setParam
(
ApiConstants
.
LIST_ALL
,
listAll
.
toString
());
if
(
forVirtualNetwork
!=
null
)
cmd
.
setParam
(
ApiConstants
.
FOR_VIRTUAL_NETWORK
,
forVirtualNetwork
.
toString
());
if
(
groupId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
GROUP_ID
,
groupId
);
if
(
hostId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
HOST_ID
,
hostId
);
if
(
hypervisor
!=
null
)
cmd
.
setParam
(
ApiConstants
.
HYPERVISOR
,
hypervisor
);
if
(
id
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
isRecursive
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_RECURSIVE
,
isRecursive
.
toString
());
if
(
keyWord
!=
null
)
cmd
.
setParam
(
ApiConstants
.
KEYWORD
,
keyWord
);
if
(
name
!=
null
)
cmd
.
setParam
(
ApiConstants
.
NAME
,
name
);
if
(
networkId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
NETWORK_ID
,
networkId
);
if
(
podId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
POD_ID
,
podId
);
if
(
state
!=
null
)
cmd
.
setParam
(
ApiConstants
.
STATE
,
state
);
if
(
storageId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
STORAGE_ID
,
storageId
);
if
(
zoneId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
if
(
resourceTags
!=
null
&&
resourceTags
.
size
() >
0
)
cmd
=
setParams
(
cmd
,
null
,
null
,
resourceTags
);
}
return
_client
.
listCall
(
cmd
,
apiKey
,
secretKey
,
ApiConstants
.
LIST_VIRTUAL_MACHINES_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
new
TypeToken
<
List
<
CloudStackUserVm
>>() {
}.
getType
());
}
/**
* get password from virtual machine
*
* @param id
* @return
* @throws Exception
*/
public
CloudStackPasswordData
getVMPassword
(
String
id
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
GET_VM_PASSWORD
);
if
(
cmd
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
// TODO: This probably isn't right. Need to test with an instance that has a VM Password
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
GET_VM_PASSWORD_RESPONSE
,
ApiConstants
.
PASSWORD
,
CloudStackPasswordData
.
class
);
}
// Templates
//<a href="user/createTemplate.html">createTemplate (A)</a>
/**
* create a Template
*
* @param displayText
* @param name
* @param osTypeId
* @param bits
* @param isFeatured
* @param isPublic
* @param passwordEnabled
* @param requiresHVM
* @param snapshotId
* @param volumeId
* @return
* @throws Exception
*/
public
CloudStackTemplate
createTemplate
(
String
displayText
,
String
name
,
String
osTypeId
,
String
bits
,
Boolean
isFeatured
,
Boolean
isPublic
,
Boolean
passwordEnabled
,
Boolean
requiresHVM
,
String
snapshotId
,
String
volumeId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
CREATE_TEMPLATE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
DISPLAY_TEXT
,
displayText
);
cmd
.
setParam
(
ApiConstants
.
NAME
,
name
);
cmd
.
setParam
(
ApiConstants
.
OS_TYPE_ID
,
osTypeId
);
if
(
bits
!=
null
)
cmd
.
setParam
(
ApiConstants
.
BITS
,
bits
);
if
(
isFeatured
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_FEATURED
,
isFeatured
.
toString
());
if
(
isPublic
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_PUBLIC
,
isPublic
.
toString
());
if
(
passwordEnabled
!=
null
)
cmd
.
setParam
(
ApiConstants
.
PASSWORD_ENABLED
,
passwordEnabled
.
toString
());
if
(
requiresHVM
!=
null
)
cmd
.
setParam
(
ApiConstants
.
REQUIRES_HVM
,
requiresHVM
.
toString
());
if
(
snapshotId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
SNAPSHOT_ID
,
snapshotId
);
if
(
volumeId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
VOLUME_ID
,
volumeId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
CREATE_TEMPLATE_RESPONSE
,
ApiConstants
.
TEMPLATE
,
CloudStackTemplate
.
class
);
}
/**
* register a template
*
* @param displayText
* @param format
* @param hypervisor
* @param name
* @param osTypeId
* @param url
* @param zoneId
* @param account
* @param bits
* @param checksum
* @param domainId
* @param isExtractable
* @param isFeatured
* @param isPublic
* @param passwordEnabled
* @param requiresHVM
* @return
* @throws Exception
*/
public
List
<
CloudStackTemplate
>
registerTemplate
(
String
displayText
,
String
format
,
String
hypervisor
,
String
name
,
String
osTypeId
,
String
url
,
String
zoneId
,
String
account
,
String
bits
,
String
checksum
,
String
domainId
,
Boolean
isExtractable
,
Boolean
isFeatured
,
Boolean
isPublic
,
Boolean
passwordEnabled
,
Boolean
requiresHVM
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
REGISTER_TEMPLATE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
DISPLAY_TEXT
,
displayText
);
cmd
.
setParam
(
ApiConstants
.
FORMAT
,
format
);
cmd
.
setParam
(
ApiConstants
.
HYPERVISOR
,
hypervisor
);
cmd
.
setParam
(
ApiConstants
.
NAME
,
name
);
cmd
.
setParam
(
ApiConstants
.
OS_TYPE_ID
,
osTypeId
);
cmd
.
setParam
(
ApiConstants
.
URL
,
url
);
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
if
(
account
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNT
,
account
);
if
(
bits
!=
null
)
cmd
.
setParam
(
ApiConstants
.
BITS
,
bits
);
if
(
checksum
!=
null
)
cmd
.
setParam
(
ApiConstants
.
CHECKSUM
,
checksum
);
if
(
domainId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DOMAIN_ID
,
domainId
);
if
(
isExtractable
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_EXTRACTABLE
,
isExtractable
.
toString
());
if
(
isFeatured
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_FEATURED
,
isFeatured
.
toString
());
if
(
isPublic
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_PUBLIC
,
isPublic
.
toString
());
if
(
passwordEnabled
!=
null
)
cmd
.
setParam
(
ApiConstants
.
PASSWORD_ENABLED
,
passwordEnabled
.
toString
());
if
(
requiresHVM
!=
null
)
cmd
.
setParam
(
ApiConstants
.
REQUIRES_HVM
,
requiresHVM
.
toString
());
}
return
_client
.
listCall
(
cmd
,
apiKey
,
secretKey
,
ApiConstants
.
REGISTER_TEMPLATE_RESPONSE
,
ApiConstants
.
TEMPLATE
,
new
TypeToken
<
List
<
CloudStackTemplate
>>() {
}.
getType
());
}
/**
* update's a template
*
* @param id
* @param bootable
* @param displayText
* @param format
* @param name
* @param osTypeId
* @param passwordEnabled
* @return
* @throws Exception
*/
public
CloudStackTemplate
updateTemplate
(
String
id
,
Boolean
bootable
,
String
displayText
,
String
format
,
String
name
,
String
osTypeId
,
Boolean
passwordEnabled
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
UPDATE_TEMPLATE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
bootable
!=
null
)
cmd
.
setParam
(
ApiConstants
.
BOOTABLE
,
bootable
.
toString
());
if
(
displayText
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DISPLAY_TEXT
,
displayText
);
if
(
format
!=
null
)
cmd
.
setParam
(
ApiConstants
.
FORMAT
,
format
);
if
(
name
!=
null
)
cmd
.
setParam
(
ApiConstants
.
NAME
,
name
);
if
(
osTypeId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
OS_TYPE_ID
,
osTypeId
);
if
(
passwordEnabled
!=
null
)
cmd
.
setParam
(
ApiConstants
.
PASSWORD_ENABLED
,
passwordEnabled
.
toString
());
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
false
,
ApiConstants
.
UPDATE_TEMPLATE_RESPONSE
,
ApiConstants
.
TEMPLATE
,
CloudStackTemplate
.
class
);
}
/**
* copy a template
*
* @param id (required)
* @param destZoneId (required)
* @param sourceZoneId (required)
* @return
* @throws Exception
*/
public
CloudStackTemplate
copyTemplate
(
String
id
,
String
destZoneId
,
String
sourceZoneId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
COPY_TEMPLATE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
cmd
.
setParam
(
ApiConstants
.
DESTINATION_ZONE_ID
,
destZoneId
);
cmd
.
setParam
(
ApiConstants
.
SOURCE_ZONE_ID
,
sourceZoneId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
COPY_TEMPLATE_RESPONSE
,
ApiConstants
.
TEMPLATE
,
CloudStackTemplate
.
class
);
}
/**
* Deletes a template from the system. All virtual machines using the deleted template will not be affected.
*
* @param id (required)
* @param zoneId
* @return
* @throws Exception
*/
public
CloudStackInfoResponse
deleteTemplate
(
String
id
,
String
zoneId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
DELETE_TEMPLATE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
zoneId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
DELETE_TEMPLATE_RESPONSE
,
null
,
CloudStackInfoResponse
.
class
);
}
/**
* List all public, private, and privileged templates
*
* @param templateFilter (required)
* @param account
* @param domainId
* @param hypervisor
* @param id
* @param keyWord
* @param name
* @param zoneId
* @return
* @throws Exception
*/
public
List
<
CloudStackTemplate
>
listTemplates
(
String
templateFilter
,
String
account
,
String
domainId
,
String
hypervisor
,
String
id
,
String
keyWord
,
String
name
,
String
zoneId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
LIST_TEMPLATES
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
TEMPLATE_FILTER
,
templateFilter
);
if
(
account
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNT
,
account
);
if
(
domainId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DOMAIN_ID
,
domainId
);
if
(
hypervisor
!=
null
)
cmd
.
setParam
(
ApiConstants
.
HYPERVISOR
,
hypervisor
);
if
(
id
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
keyWord
!=
null
)
cmd
.
setParam
(
ApiConstants
.
KEYWORD
,
keyWord
);
if
(
name
!=
null
)
cmd
.
setParam
(
ApiConstants
.
NAME
,
name
);
if
(
zoneId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
}
return
_client
.
listCall
(
cmd
,
apiKey
,
secretKey
,
ApiConstants
.
LIST_TEMPLATES_RESPONSE
,
ApiConstants
.
TEMPLATE
,
new
TypeToken
<
List
<
CloudStackTemplate
>>() {
}.
getType
());
}
/**
* Updates a template visibility permissions. A public template is visible to all accounts within the same domain.
* A private template is visible only to the owner of the template. A priviledged template is a private template with account
* permissions added. Only accounts specified under the template permissions are visible to them.
*
* @param id
* @param accounts
* @param isExtractable
* @param isFeatured
* @param isPublic
* @param op
* @return
* @throws Exception
*/
public
CloudStackInfoResponse
updateTemplatePermissions
(
String
id
,
String
accounts
,
Boolean
isExtractable
,
Boolean
isFeatured
,
Boolean
isPublic
,
String
op
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
UPDATE_TEMPLATE_PERMISSIONS
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
accounts
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNTS
,
accounts
);
if
(
isExtractable
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_EXTRACTABLE
,
isExtractable
.
toString
());
if
(
isFeatured
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_FEATURED
,
isFeatured
.
toString
());
if
(
isPublic
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_PUBLIC
,
isPublic
.
toString
());
if
(
op
!=
null
)
cmd
.
setParam
(
ApiConstants
.
OP
,
op
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
false
,
ApiConstants
.
UPDATE_TEMPLATE_PERMISSIONS_RESPONSE
,
null
,
CloudStackInfoResponse
.
class
);
}
/**
* List template visibility and all accounts that have permissions to view this template.
*
* @param id
* @param account
* @param domainId
* @return
* @throws Exception
*/
public
CloudStackTemplatePermission
listTemplatePermissions
(
String
id
,
String
account
,
String
domainId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
LIST_TEMPLATE_PERMISSIONS
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
account
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNT
,
account
);
if
(
domainId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DOMAIN_ID
,
domainId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
false
,
ApiConstants
.
LIST_TEMPLATE_PERMISSIONS_RESPONSE
,
ApiConstants
.
TEMPLATE_PERMISSION
,
CloudStackTemplatePermission
.
class
);
}
/**
* Extracts a template
*
* @param id
* @param mode
* @param zoneId
* @param url
* @return
* @throws Exception
*/
public
CloudStackExtractTemplate
extractTemplate
(
String
id
,
String
mode
,
String
zoneId
,
String
url
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
EXTRACT_TEMPLATE
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
cmd
.
setParam
(
ApiConstants
.
MODE
,
mode
);
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
if
(
url
!=
null
)
cmd
.
setParam
(
ApiConstants
.
URL
,
url
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
EXTRACT_TEMPLATE_RESPONSE
,
null
,
CloudStackExtractTemplate
.
class
);
}
// ISO's
/**
* Attaches an ISO to a virtual machine
*
* @param id
* @param virtualMachineId
* @return
* @throws Exception
*/
public
CloudStackUserVm
attachIso
(
String
id
,
String
virtualMachineId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
ATTACH_ISO
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
cmd
.
setParam
(
ApiConstants
.
VIRTUAL_MACHINE_ID
,
virtualMachineId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
ATTACH_ISO_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* Detaches any ISO file (if any) currently attached to a virtual machine.
*
* @param virtualMachineId
* @return
* @throws Exception
*/
public
CloudStackUserVm
detachIso
(
String
virtualMachineId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
DETACH_ISO
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
VIRTUAL_MACHINE_ID
,
virtualMachineId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
DETACH_ISO_RESPONSE
,
ApiConstants
.
VIRTUAL_MACHINE
,
CloudStackUserVm
.
class
);
}
/**
* Lists all available ISO files.
*
* @param account
* @param bootable
* @param domainId
* @param hypervisor
* @param id
* @param isoFilter
* @param isPublic
* @param isReady
* @param keyWord
* @param name
* @param zoneId
* @return
* @throws Exception
*/
public
List
<
CloudStackTemplate
>
listIsos
(
String
account
,
Boolean
bootable
,
String
domainId
,
String
hypervisor
,
String
id
,
String
isoFilter
,
Boolean
isPublic
,
Boolean
isReady
,
String
keyWord
,
String
name
,
String
zoneId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
LIST_ISOS
);
if
(
cmd
!=
null
) {
if
(
account
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNT
,
account
);
if
(
bootable
!=
null
)
cmd
.
setParam
(
ApiConstants
.
BOOTABLE
,
bootable
.
toString
());
if
(
domainId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DOMAIN_ID
,
domainId
);
if
(
hypervisor
!=
null
)
cmd
.
setParam
(
ApiConstants
.
HYPERVISOR
,
hypervisor
);
if
(
id
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
isoFilter
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ISO_FILTER
,
isoFilter
);
if
(
isPublic
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_PUBLIC
,
isPublic
.
toString
());
if
(
isReady
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_READY
,
isReady
.
toString
());
if
(
keyWord
!=
null
)
cmd
.
setParam
(
ApiConstants
.
KEYWORD
,
keyWord
);
if
(
name
!=
null
)
cmd
.
setParam
(
ApiConstants
.
NAME
,
name
);
if
(
zoneId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
}
return
_client
.
listCall
(
cmd
,
apiKey
,
secretKey
,
ApiConstants
.
LIST_ISOS_RESPONSE
,
ApiConstants
.
TEMPLATE
,
new
TypeToken
<
List
<
CloudStackTemplate
>>() {
}.
getType
());
}
/**
* Registers an existing ISO into the Cloud.com Cloud.
*
* @param displayText
* @param name
* @param url
* @param zoneId
* @param account
* @param bootable
* @param domainId
* @param isExtractable
* @param isFeatured
* @param isPublic
* @param osTypeId
* @return
* @throws Exception
*/
public
CloudStackTemplate
registerIso
(
String
displayText
,
String
name
,
String
url
,
String
zoneId
,
String
account
,
Boolean
bootable
,
String
domainId
,
Boolean
isExtractable
,
Boolean
isFeatured
,
Boolean
isPublic
,
String
osTypeId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
REGISTER_ISO
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
DISPLAY_TEXT
,
displayText
);
cmd
.
setParam
(
ApiConstants
.
NAME
,
name
);
cmd
.
setParam
(
ApiConstants
.
URL
,
url
);
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
if
(
account
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNT
,
account
);
if
(
bootable
!=
null
)
cmd
.
setParam
(
ApiConstants
.
BOOTABLE
,
bootable
.
toString
());
if
(
domainId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DOMAIN_ID
,
domainId
);
if
(
isExtractable
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_EXTRACTABLE
,
isExtractable
.
toString
());
if
(
isFeatured
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_FEATURED
,
isFeatured
.
toString
());
if
(
isPublic
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_PUBLIC
,
isPublic
.
toString
());
if
(
osTypeId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
OS_TYPE_ID
,
osTypeId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
false
,
ApiConstants
.
REGISTER_ISO_RESPONSE
,
ApiConstants
.
TEMPLATE
,
CloudStackTemplate
.
class
);
}
/**
* Updates an ISO
*
* @param id
* @param bootable
* @param displayText
* @param format
* @param name
* @param osTypeId
* @param passwordEnabled
* @return
* @throws Exception
*/
public
CloudStackTemplate
updateIso
(
String
id
,
Boolean
bootable
,
String
displayText
,
String
format
,
String
name
,
String
osTypeId
,
Boolean
passwordEnabled
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
UPDATE_ISO
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
bootable
!=
null
)
cmd
.
setParam
(
ApiConstants
.
BOOTABLE
,
bootable
.
toString
());
if
(
displayText
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DISPLAY_TEXT
,
displayText
);
if
(
format
!=
null
)
cmd
.
setParam
(
ApiConstants
.
FORMAT
,
format
);
if
(
name
!=
null
)
cmd
.
setParam
(
ApiConstants
.
NAME
,
name
);
if
(
osTypeId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
OS_TYPE_ID
,
osTypeId
);
if
(
passwordEnabled
!=
null
)
cmd
.
setParam
(
ApiConstants
.
PASSWORD_ENABLED
,
passwordEnabled
.
toString
());
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
false
,
ApiConstants
.
UPDATE_ISO_RESPONSE
,
ApiConstants
.
TEMPLATE
,
CloudStackTemplate
.
class
);
}
/**
* Deletes an ISO
*
* @param id
* @param zoneId
* @return
* @throws Exception
*/
public
CloudStackInfoResponse
deleteIso
(
String
id
,
String
zoneId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
DELETE_ISO
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
DELETE_ISO_RESPONSE
,
null
,
CloudStackInfoResponse
.
class
);
}
/**
* Copies a template from one zone to another
*
* @param id
* @param destZoneId
* @param sourceZoneId
* @return
* @throws Exception
*/
public
CloudStackTemplate
copyIso
(
String
id
,
String
destZoneId
,
String
sourceZoneId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
COPY_ISO
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
cmd
.
setParam
(
ApiConstants
.
DESTINATION_ZONE_ID
,
destZoneId
);
cmd
.
setParam
(
ApiConstants
.
SOURCE_ZONE_ID
,
sourceZoneId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
COPY_ISO_RESPONSE
,
ApiConstants
.
TEMPLATE
,
CloudStackTemplate
.
class
);
}
/**
* Updates ISO permissions
*
* @param id
* @param accounts
* @param isExtractable
* @param isFeatured
* @param isPublic
* @param op
* @return
* @throws Exception
*/
public
CloudStackInfoResponse
updateIsoPermissions
(
String
id
,
String
accounts
,
Boolean
isExtractable
,
Boolean
isFeatured
,
Boolean
isPublic
,
String
op
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
UPDATE_ISO_PERMISSIONS
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
accounts
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNTS
,
accounts
);
if
(
isExtractable
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_EXTRACTABLE
,
isExtractable
.
toString
());
if
(
isFeatured
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_FEATURED
,
isFeatured
.
toString
());
if
(
isPublic
!=
null
)
cmd
.
setParam
(
ApiConstants
.
IS_PUBLIC
,
isPublic
.
toString
());
if
(
op
!=
null
)
cmd
.
setParam
(
ApiConstants
.
OP
,
op
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
false
,
ApiConstants
.
UPDATE_ISO_PERMISSIONS_RESPONSE
,
null
,
CloudStackInfoResponse
.
class
);
}
/**
* List template visibility and all accounts that have permissions to view this template
* @param id
* @param account
* @param domainId
* @return
* @throws Exception
*/
public
List
<
CloudStackTemplatePermission
>
listIsoPermissions
(
String
id
,
String
account
,
String
domainId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
LIST_ISO_PERMISSIONS
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
account
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ACCOUNT
,
account
);
if
(
domainId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DOMAIN_ID
,
domainId
);
}
return
_client
.
listCall
(
cmd
,
apiKey
,
secretKey
,
ApiConstants
.
LIST_ISO_PERMISSIONS_RESPONSE
,
ApiConstants
.
TEMPLATE
,
new
TypeToken
<
List
<
CloudStackTemplatePermission
>>() {
}.
getType
());
}
/**
* Extracts an iso
*
* @param id
* @param mode
* @param zoneId
* @param url
* @return
* @throws Exception
*/
public
CloudStackExtractTemplate
extractIso
(
String
id
,
String
mode
,
String
zoneId
,
String
url
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
EXTRACT_ISO
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
cmd
.
setParam
(
ApiConstants
.
MODE
,
mode
);
cmd
.
setParam
(
ApiConstants
.
ZONE_ID
,
zoneId
);
if
(
url
!=
null
)
cmd
.
setParam
(
ApiConstants
.
URL
,
url
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
EXTRACT_ISO_RESPONSE
,
ApiConstants
.
TEMPLATE
,
CloudStackExtractTemplate
.
class
);
}
// Volumes
/**
* Attaches a disk volume to a virtual machine
*
* @param id
* @param virtualMachineId
* @param deviceId
* @return
* @throws Exception
*/
public
CloudStackVolume
attachVolume
(
String
id
,
String
virtualMachineId
,
String
deviceId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
ATTACH_VOLUME
);
if
(
cmd
!=
null
) {
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
cmd
.
setParam
(
ApiConstants
.
VIRTUAL_MACHINE_ID
,
virtualMachineId
);
if
(
deviceId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DEVICE_ID
,
deviceId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
ATTACH_VOLUME_RESPONSE
,
ApiConstants
.
VOLUME
,
CloudStackVolume
.
class
);
}
/**
* Detaches a disk volume from a virtual machine
*
* @param deviceId
* @param id
* @param virtualMachineId
* @return
* @throws Exception
*/
public
CloudStackVolume
detachVolume
(
String
deviceId
,
String
id
,
String
virtualMachineId
)
throws
Exception
{
CloudStackCommand
cmd
=
new
CloudStackCommand
(
ApiConstants
.
DETACH_VOLUME
);
if
(
cmd
!=
null
) {
if
(
deviceId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
DEVICE_ID
,
deviceId
);
if
(
id
!=
null
)
cmd
.
setParam
(
ApiConstants
.
ID
,
id
);
if
(
virtualMachineId
!=
null
)
cmd
.
setParam
(
ApiConstants
.
VIRTUAL_MACHINE_ID
,
virtualMachineId
);
}
return
_client
.
call
(
cmd
,
apiKey
,
secretKey
,
true
,
ApiConstants
.
DETACH_VOLUME_RESPONSE
,
ApiConstants
.
VOLUME
,
CloudStackVolume
.
class
);
}
/**
* Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it
*
* @param name
* @param account
* @param diskOfferingId
* @param domainId
* @param size
* @param snapshotId
* @param zoneId
* @return
* @throws Exception
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL