-
Notifications
You must be signed in to change notification settings - Fork 10
/
ec2.class.php
executable file
·1398 lines (1267 loc) · 61.4 KB
/
ec2.class.php
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
<?php
/**
* File: Amazon EC2
* Amazon Elastic Compute Cloud (http://aws.amazon.com/ec2)
*
* Version:
* 2010.01.10
*
* Copyright:
* 2006-2009 Foleeo, Inc., and contributors.
*
* License:
* Simplified BSD License - http://opensource.org/licenses/bsd-license.php
*
* See Also:
* CloudFusion - http://getcloudfusion.com
* Amazon EC2 - http://aws.amazon.com/ec2
*/
/*%******************************************************************************************%*/
// CONSTANTS
/**
* Constant: EC2_DEFAULT_URL
* Specify the default queue URL.
*/
define('EC2_DEFAULT_URL', 'ec2.amazonaws.com');
/**
* Constant: EC2_LOCATION_US
* Specify the queue URL for the U.S.-specific hostname.
*/
define('EC2_LOCATION_US', 'us-east-1.');
/**
* Constant: EC2_LOCATION_EU
* Specify the queue URL for the E.U.-specific hostname.
*/
define('EC2_LOCATION_EU', 'eu-west-1.');
/*%******************************************************************************************%*/
// EXCEPTIONS
/**
* Exception: EC2_Exception
* Default EC2 Exception.
*/
class EC2_Exception extends Exception {}
/*%******************************************************************************************%*/
// MAIN CLASS
/**
* Class: AmazonEC2
* Container for all Amazon EC2-related methods. Inherits additional methods from CloudFusion.
*
* Extends:
* CloudFusion
*
* Example Usage:
* (start code)
* require_once('cloudfusion.class.php');
*
* // Instantiate a new AmazonEC2 object using the settings from the config.inc.php file.
* $s3 = new AmazonEC2();
*
* // Instantiate a new AmazonEC2 object using these specific settings.
* $s3 = new AmazonEC2($key, $secret_key);
* (end)
*/
class AmazonEC2 extends CloudFusion
{
/**
* Property: hostname
* Stores the hostname to use to make the request.
*/
var $hostname;
/*%******************************************************************************************%*/
// CONSTRUCTOR
/**
* Method: __construct()
* The constructor
*
* Access:
* public
*
* Parameters:
* key - _string_ (Optional) Your Amazon API Key. If blank, it will look for the <AWS_KEY> constant.
* secret_key - _string_ (Optional) Your Amazon API Secret Key. If blank, it will look for the <AWS_SECRET_KEY> constant.
* account_id - _string_ (Optional) Your Amazon Account ID, without hyphens. If blank, it will look for the <AWS_ACCOUNT_ID> constant.
*
* Returns:
* _boolean_ false if no valid values are set, otherwise true.
*
* See Also:
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/__construct.phps
*/
public function __construct($key = null, $secret_key = null, $account_id = null)
{
$this->api_version = '2008-12-01';
$this->hostname = EC2_DEFAULT_URL;
if (!$key && !defined('AWS_KEY'))
{
throw new EC2_Exception('No account key was passed into the constructor, nor was it set in the AWS_KEY constant.');
}
if (!$secret_key && !defined('AWS_SECRET_KEY'))
{
throw new EC2_Exception('No account secret was passed into the constructor, nor was it set in the AWS_SECRET_KEY constant.');
}
if (!$account_id && !defined('AWS_ACCOUNT_ID'))
{
throw new EC2_Exception('No Amazon account ID was passed into the constructor, nor was it set in the AWS_ACCOUNT_ID constant.');
}
return parent::__construct($key, $secret_key, $account_id);
}
/*%******************************************************************************************%*/
// MISCELLANEOUS
/**
* Method: set_locale()
* By default EC2 will self-select the most appropriate locale. This allows you to explicitly sets the locale for EC2 to use.
*
* Access:
* public
*
* Parameters:
* locale - _string_ (Required) The locale to explicitly set for EC2. Available options are <EC2_LOCATION_US> and <EC2_LOCATION_EU>.
*
* Returns:
* void
*
* See Also:
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/set_locale.phps
*/
public function set_locale($locale)
{
$this->hostname = $locale . EC2_DEFAULT_URL;
}
/*%******************************************************************************************%*/
// AVAILABILITY ZONES
/**
* Method: describe_availability_zones()
* Describes availability zones that are currently available to the account and their states.
*
* Access:
* public
*
* Parameters:
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* ZoneName.n - _string_ (Optional) Name of an availability zone.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DescribeAvailabilityZones.html
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/describe_availability_zones.phps
*/
public function describe_availability_zones($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('DescribeAvailabilityZones', $opt, $this->hostname);
}
/*%******************************************************************************************%*/
// ELASTIC IP ADDRESSES
/**
* Method: allocate_address()
* Acquires an elastic IP address for use with your account.
*
* Access:
* public
*
* Parameters:
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-AllocateAddress.html
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/elastic_ip.phps
* Related - <associate_address()>, <describe_addresses()>, <disassociate_address()>, <release_address()>
*/
public function allocate_address($returnCurlHandle = null)
{
$opt = array();
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('AllocateAddress', $opt, $this->hostname);
}
/**
* Method: associate_address()
* Associates an elastic IP address with an instance.
*
* If the IP address is currently assigned to another instance, the IP address is assigned to the new instance. This is an idempotent operation. If you enter it more than once, Amazon EC2 does not return an error.
*
* Access:
* public
*
* Parameters:
* instance_id - _string_ (Required) The instance to which the IP address is assigned.
* public_ip - _string_ (Required) IP address that you are assigning to the instance, retrieved from <allocate_address()>.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-AssociateAddress.html
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/elastic_ip.phps
* Related - <allocate_address()>, <describe_addresses()>, <disassociate_address()>, <release_address()>
*/
public function associate_address($instance_id, $public_ip, $returnCurlHandle = null)
{
$opt = array();
$opt['InstanceId'] = $instance_id;
$opt['PublicIp'] = $public_ip;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('AssociateAddress', $opt, $this->hostname);
}
/**
* Method: describe_addresses()
* Lists elastic IP addresses assigned to your account.
*
* Access:
* public
*
* Parameters:
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* PublicIp.1 - _string_ (Required but can be empty) One Elastic IP addresses to describe.
* PublicIp.n - _string_ (Optional) More than one Elastic IP addresses to describe.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DescribeAddresses.html
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/elastic_ip.phps
* Related - <allocate_address()>, <associate_address()>, <disassociate_address()>, <release_address()>
*/
public function describe_addresses($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('DescribeAddresses', $opt, $this->hostname);
}
/**
* Method: disassociate_address()
* Disassociates the specified elastic IP address from the instance to which it is assigned.
*
* This is an idempotent operation. If you enter it more than once, Amazon EC2 does not return an error.
*
* Access:
* public
*
* Parameters:
* public_ip - _string_ (Required) IP address that you are disassociating from the instance.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DisassociateAddress.html
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/elastic_ip.phps
* Related - <allocate_address()>, <associate_address()>, <describe_addresses()>, <release_address()>
*/
public function disassociate_address($public_ip, $returnCurlHandle = null)
{
$opt = array();
$opt['PublicIp'] = $public_ip;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('DisassociateAddress', $opt, $this->hostname);
}
/**
* Method: release_address()
* Releases an elastic IP address associated with your account. If you run this operation on an elastic IP address that is already released, the address might be assigned to another account which will cause Amazon EC2 to return an error.
*
* Releasing an IP address automatically disassociates it from any instance with which it is associated. For more information, see <disassociate_address()>.
*
* After releasing an elastic IP address, it is released to the IP address pool and might no longer be available to your account. Make sure to update your DNS records and any servers or devices that communicate with the address.
*
* Access:
* public
*
* Parameters:
* public_ip - _string_ (Required) IP address that you are releasing from your account.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-ReleaseAddress.html
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/elastic_ip.phps
* Related - <allocate_address()>, <associate_address()>, <describe_addresses()>, <disassociate_address()>
*/
public function release_address($public_ip, $returnCurlHandle = null)
{
if (!$opt) $opt = array();
$opt['PublicIp'] = $public_ip;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('ReleaseAddress', $opt, $this->hostname);
}
/*%******************************************************************************************%*/
// EBS SNAPSHOTS TO S3
/**
* Method: create_snapshot()
* Creates a snapshot of an Amazon EBS volume and stores it in Amazon S3. You can use snapshots for backups, to launch instances from identical snapshots, and to save data before shutting down an instance. For more information, see Amazon Elastic Block Store.
*
* Access:
* public
*
* Parameters:
* volume_id - _string_ (Required) The ID of the Amazon EBS volume to snapshot. Must be a volume that you own.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-CreateSnapshot.html
* Related - <describe_snapshots()>, <delete_snapshot()>
*/
public function create_snapshot($volume_id, $returnCurlHandle = null)
{
$opt = array();
$opt['VolumeId'] = $volume_id;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('CreateSnapshot', $opt, $this->hostname);
}
/**
* Method: describe_snapshots()
* Describes the status of Amazon EBS snapshots.
*
* Access:
* public
*
* Parameters:
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* SnapshotId.n - _string_ (Optional) The ID of the Amazon EBS snapshot.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DescribeSnapshots.html
* Related - <create_snapshot()>, <delete_snapshot()>
*/
public function describe_snapshots($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('DescribeSnapshots', $opt, $this->hostname);
}
/**
* Method: delete_snapshot()
* Deletes a snapshot of an Amazon EBS volume that is stored in Amazon S3.
*
* Access:
* public
*
* Parameters:
* snapshot_id - _string_ (Optional) The ID of the Amazon EBS snapshot to delete.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DeleteSnapshot.html
* Related - <create_snapshot()>, <describe_snapshots()>
*/
public function delete_snapshot($snapshot_id, $returnCurlHandle = null)
{
$opt = array();
$opt['SnapshotId'] = $snapshot_id;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('DeleteSnapshot', $opt, $this->hostname);
}
/*%******************************************************************************************%*/
// EBS VOLUMES
/**
* Method: create_volume()
* Creates a new Amazon EBS volume that you can mount from any Amazon EC2 instance. You must specify an availability zone when creating a volume. The volume and any instance to which it attaches must be in the same availability zone.
*
* Access:
* public
*
* Parameters:
* sizesnapid - _mixed_ (Required) Either the size of the volume in GB as an integer (from 1 to 1024), or the ID of the snapshot from which to create the new volume as a string.
* zone - _string_ (Required) The availability zone in which to create the new volume.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-CreateVolume.html
* Related - <describe_volumes()>, <attach_volume()>, <detach_volume()>, <delete_volume()>
*/
public function create_volume($sizesnapid, $zone, $returnCurlHandle = null)
{
$opt = array();
$opt['AvailabilityZone'] = $zone;
$opt['returnCurlHandle'] = $returnCurlHandle;
if (is_numeric($sizesnapid))
{
$opt['Size'] = $sizesnapid;
}
else
{
$opt['SnapshotId'] = $sizesnapid;
}
return $this->authenticate('CreateVolume', $opt, $this->hostname);
}
/**
* Method: describe_volumes()
* Lists one or more Amazon EBS volumes that you own. If you do not specify any volumes, Amazon EBS returns all volumes that you own.
*
* Access:
* public
*
* Parameters:
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* VolumeId.n - _string_ (Optional) The ID of the volume to list.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DescribeVolumes.html
* Related - <create_volume()>, <attach_volume()>, <detach_volume()>, <delete_volume()>
*/
public function describe_volumes($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('DescribeVolumes', $opt, $this->hostname);
}
/**
* Method: attach_volume()
* Attaches an Amazon EBS volume to an instance.
*
* Access:
* public
*
* Parameters:
* volume_id - _string_ (Required) The ID of the Amazon EBS volume.
* instance_id - _string_ (Required) The ID of the instance to which the volume attaches.
* device - _string_ (Required) Specifies how the device is exposed to the instance (e.g., /dev/sdh). For information on standard storage locations, see Storage Locations.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-AttachVolume.html
* Storage Locations - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/instance-storage.html#storage-locations
* Related - <create_volume()>, <describe_volumes()>, <detach_volume()>, <delete_volume()>
*/
public function attach_volume($volume_id, $instance_id, $device, $returnCurlHandle = null)
{
$opt = array();
$opt['VolumeId'] = $volume_id;
$opt['InstanceId'] = $instance_id;
$opt['Device'] = $device;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('AttachVolume', $opt, $this->hostname);
}
/**
* Method: detach_volume()
* Detaches an Amazon EBS volume from an instance.
*
* Access:
* public
*
* Parameters:
* volume_id - _string_ (Required) The ID of the Amazon EBS volume.
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* InstanceId - _string_ (Optional) The ID of the instance from which the volume will detach.
* Device - _string_ (Optional) The name of the device.
* Force - _boolean_ (Optional) Forces detachment if the previous detachment attempt did not occur cleanly (logging into an instance, unmounting the volume, and detaching normally). This option can lead to data loss or a corrupted file system. Use this option only as a last resort to detach an instance from a failed instance. The instance will not have an opportunity to flush file system caches nor file system meta data. If you use this option, you must perform file system check and repair procedures.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DetachVolume.html
* Related - <create_volume()>, <describe_volumes()>, <attach_volume()>, <delete_volume()>
*/
public function detach_volume($volume_id, $opt = null)
{
if (!$opt) $opt = array();
$opt['VolumeId'] = $volume_id;
return $this->authenticate('DetachVolume', $opt, $this->hostname);
}
/**
* Method: delete_volume()
* Deletes an Amazon EBS volume.
*
* Access:
* public
*
* Parameters:
* volume_id - _string_ (Required) The ID of the Amazon EBS volume.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DeleteVolume.html
* Related - <create_volume()>, <describe_volumes()>, <attach_volume()>, <detach_volume()>
*/
public function delete_volume($volume_id, $returnCurlHandle = null)
{
$opt = array();
$opt['VolumeId'] = $volume_id;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('DeleteVolume', $opt, $this->hostname);
}
/*%******************************************************************************************%*/
// MISCELLANEOUS
/**
* Method: get_console_output()
* Retrieves console output for the specified instance. Instance console output is buffered and posted shortly after instance boot, reboot, and termination. Amazon EC2 preserves the most recent 64 KB output which will be available for at least one hour after the most recent post.
*
* Access:
* public
*
* Parameters:
* instance_id - _string_ (Required) An instance ID returned from a previous call to <run_instances()>.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-GetConsoleOutput.html
* Related - <reboot_instances()>
*/
public function get_console_output($instance_id, $returnCurlHandle = null)
{
$opt = array();
$opt['InstanceId'] = $instance_id;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('GetConsoleOutput', $opt, $this->hostname);
}
/**
* Method: reboot_instances()
* Requests a reboot of one or more instances. This operation is asynchronous; it only queues a request to reboot the specified instance(s). The operation will succeed if the instances are valid and belong to the user. Requests to reboot terminated instances are ignored.
*
* Access:
* public
*
* Parameters:
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* InstanceId.1 - _string_ (Required) One instance ID returned from previous calls to <run_instances()>.
* InstanceId.n - _string_ (Optional) More than one instance IDs returned from previous calls to <run_instances()>.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-RebootInstances.html
* Related - <get_console_output()>
*/
public function reboot_instances($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('RebootInstances', $opt, $this->hostname);
}
/*%******************************************************************************************%*/
// IMAGES
/**
* Method: deregister_image()
* De-registers an AMI. Once de-registered, instances of the AMI may no longer be launched.
*
* Access:
* public
*
* Parameters:
* image_id - _string_ (Required) Unique ID of a machine image, returned by a call to <register_image()> or <describe_images()>.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DeregisterImage.html
* Related - <describe_images()>, <register_image()>
*/
public function deregister_image($image_id, $returnCurlHandle = null)
{
$opt = array();
$opt['ImageId'] = $image_id;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('DeregisterImage', $opt, $this->hostname);
}
/**
* Method: describe_images()
* The DescribeImages operation returns information about AMIs, AKIs, and ARIs available to the user. Information returned includes image type, product codes, architecture, and kernel and RAM disk IDs. Images available to the user include public images available for any user to launch, private images owned by the user making the request, and private images owned by other users for which the user has explicit launch permissions.
*
* Launch permissions fall into three categories: (a) 'public' where the owner of the AMI granted launch permissions for the AMI to the all group. All users have launch permissions for these AMIs. (b) 'explicit' where the owner of the AMI granted launch permissions to a specific user. (c) 'implicit' where a user has implicit launch permissions for all AMIs he or she owns.
*
* The list of AMIs returned can be modified by specifying AMI IDs, AMI owners, or users with launch permissions. If no options are specified, Amazon EC2 returns all AMIs for which the user has launch permissions.
*
* If you specify one or more AMI IDs, only AMIs that have the specified IDs are returned. If you specify an invalid AMI ID, a fault is returned. If you specify an AMI ID for which you do not have access, it will not be included in the returned results.
*
* If you specify one or more AMI owners, only AMIs from the specified owners and for which you have access are returned. The results can include the account IDs of the specified owners, amazon for AMIs owned by Amazon or self for AMIs that you own.
*
* If you specify a list of executable users, only users that have launch permissions for the AMIs are returned. You can specify account IDs (if you own the AMI(s)), self for AMIs for which you own or have explicit permissions, or all for public AMIs.
*
* Access:
* public
*
* Parameters:
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* ExecutableBy.n - _string_ (Optional) Describe AMIs that the specified users have launch permissions for. Accepts Amazon account ID, 'self', or 'all' for public AMIs.
* ImageId.n - _string_ (Optional) A list of image descriptions.
* Owner.n - _string_ (Optional) Owners of AMIs to describe.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DescribeImages.html
* Related - <deregister_image()>, <register_image()>
*/
public function describe_images($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('DescribeImages', $opt, $this->hostname);
}
/**
* Method: register_image()
* Registers an AMI with Amazon EC2. Images must be registered before they can be launched. For more information, see <run_instances()>.
*
* Each AMI is associated with an unique ID which is provided by the Amazon EC2 service through the <register_image()> operation. During registration, Amazon EC2 retrieves the specified image manifest from Amazon S3 and verifies that the image is owned by the user registering the image.
*
* The image manifest is retrieved once and stored within the Amazon EC2. Any modifications to an image in Amazon S3 invalidates this registration. If you make changes to an image, deregister the previous image and register the new image. For more information, see <deregister_image()>.
*
* Access:
* public
*
* Parameters:
* image_location - _string_ (Required) Full path to your AMI manifest in Amazon S3 storage (i.e. mybucket/myimage.manifest.xml).
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-RegisterImage.html
* Related - <deregister_image()>, <describe_images()>
*/
public function register_image($image_location, $returnCurlHandle = null)
{
$opt = array();
$opt['ImageLocation'] = $image_location;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('RegisterImage', $opt, $this->hostname);
}
/*%******************************************************************************************%*/
// IMAGE ATTRIBUTES
/**
* Method: describe_image_attribute()
* Returns information about an attribute of an AMI. Only one attribute may be specified per call.
*
* Access:
* public
*
* Parameters:
* image_id - _string_ (Required) ID of the AMI for which an attribute will be described, returned by a call to <register_image()> or <describe_images()>.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DescribeImageAttribute.html
* Related - <modify_image_attribute()>, <reset_image_attribute()>
*/
public function describe_image_attribute($image_id, $returnCurlHandle = null)
{
$opt = array();
$opt['ImageId'] = $image_id;
$opt['returnCurlHandle'] = $returnCurlHandle;
// This is the only supported value in the current release.
$opt['Attribute'] = 'launchPermission';
return $this->authenticate('DescribeImageAttribute', $opt, $this->hostname);
}
/**
* Method: modify_image_attribute()
* Modifies an attribute of an AMI.
*
* Access:
* public
*
* Parameters:
* image_id - _string_ (Required) AMI ID to modify an attribute on.
* attribute - _string_ (Required) Specifies the attribute to modify. Supports 'launchPermission' and 'productCodes'.
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* OperationType - _string_ (Required for 'launchPermission' Attribute) Specifies the operation to perform on the attribute. Supports 'add' and 'remove'.
* UserId.n - _string_ (Required for 'launchPermission' Attribute) User IDs to add to or remove from the 'launchPermission' attribute.
* UserGroup.n - _string_ (Required for 'launchPermission' Attribute) User groups to add to or remove from the 'launchPermission' attribute. Currently, only the 'all' group is available, specifiying all Amazon EC2 users.
* ProductCode.n - _string_ (Required for 'productCodes' Attribute) Attaches product codes to the AMI. Currently only one product code may be associated with an AMI. Once set, the product code can not be changed or reset.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-ModifyImageAttribute.html
* Related - <describe_image_attribute()>, <reset_image_attribute()>
*/
public function modify_image_attribute($image_id, $attribute, $opt = null)
{
if (!$opt) $opt = array();
$opt['ImageId'] = $image_id;
$opt['Attribute'] = $attribute;
return $this->authenticate('ModifyImageAttribute', $opt, $this->hostname);
}
/**
* Method: reset_image_attribute()
* Resets an attribute of an AMI to its default value (the productCodes attribute cannot be reset).
*
* Access:
* public
*
* Parameters:
* image_id - _string_ (Required) ID of the AMI for which an attribute will be described, returned by a call to <register_image()> or <describe_images()>.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-ResetImageAttribute.html
* Related - <describe_image_attribute()>, <modify_image_attribute()>
*/
public function reset_image_attribute($image_id, $returnCurlHandle = null)
{
$opt = array();
$opt['ImageId'] = $image_id;
$opt['returnCurlHandle'] = $returnCurlHandle;
// This is the only supported value in the current release.
$opt['Attribute'] = 'launchPermission';
return $this->authenticate('ResetImageAttribute', $opt, $this->hostname);
}
/*%******************************************************************************************%*/
// INSTANCES
/**
* Method: confirm_product_instance()
* Returns true if the given product code is attached to the instance with the given instance ID. The operation returns false if the product code is not attached to the instance.
*
* Can only be executed by the owner of the AMI. This feature is useful when an AMI owner is providing support and wants to verify whether a user's instance is eligible.
*
* Access:
* public
*
* Parameters:
* product_code - _string_ (Required) The product code to confirm is attached to the instance.
* instance_id - _string_ (Required) The instance for which to confirm the product code.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-ConfirmProductInstance.html
* Related - <describe_instances()>, <run_instances()>, <terminate_instances()>
*/
public function confirm_product_instance($product_code, $instance_id, $returnCurlHandle = null)
{
$opt = array();
$opt['ProductCode'] = $product_code;
$opt['InstanceId'] = $instance_id;
$opt['returnCurlHandle'] = $returnCurlHandle;
return $this->authenticate('ConfirmProductInstance', $opt, $this->hostname);
}
/**
* Method: describe_instances()
* Returns information about instances owned by the user making the request.
*
* Access:
* public
*
* Parameters:
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* InstanceId.n - _string_ (Required) Set of instances IDs to get the status of.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-DescribeInstances.html
* Related - <confirm_product_instance()>, <run_instances()>, <terminate_instances()>
*/
public function describe_instances($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('DescribeInstances', $opt, $this->hostname);
}
/**
* Method: run_instances()
* The RunInstances operation launches a specified number of instances. The Query version of <run_instances()> only allows instances of a single AMI to be launched in one call. This is different from the SOAP API version of the call, but similar to the ec2-run-instances command line tool.
*
* If Amazon EC2 cannot launch the minimum number AMIs you request, no instances launch. If there is insufficient capacity to launch the maximum number of AMIs you request, Amazon EC2 launches as many as possible to satisfy the requested maximum values.
*
* Every instance is launched in a security group. If you do not specify a security group at launch, the instances start in your default security group. For more information on creating security groups, see <create_security_group()>.
*
* You can provide an optional key pair ID for each image in the launch request (for more information, see <create_key_pair()>). All instances that are created from images that use this key pair will have access to the associated public key at boot. You can use this key to provide secure access to an instance of an image on a per-instance basis. Amazon EC2 public images use this feature to provide secure access without passwords. IMPORTANT: Launching public images without a key pair ID will leave them inaccessible.
*
* The public key material is made available to the instance at boot time by placing it in the openssh_id.pub file on a logical device that is exposed to the instance as /dev/sda2 (the instance store). The format of this file is suitable for use as an entry within ~/.ssh/authorized_keys (the OpenSSH format). This can be done at boot (e.g., as part of rc.local) allowing for secure access without passwords.
*
* Optional user data can be provided in the launch request. All instances that collectively comprise the launch request have access to this data For more information, see Instance Metadata. NOTE: If any of the AMIs have a product code attached for which the user has not subscribed, the <run_instances()> call will fail.
*
* IMPORTANT: We strongly recommend using the 2.6.18 Xen stock kernel with the c1.medium and c1.xlarge instances. Although the default Amazon EC2 kernels will work, the new kernels provide greater stability and performance for these instance types. For more information about kernels, see Kernels, RAM Disks, and Block Device Mappings.
*
* Access:
* public
*
* Parameters:
* image_id - _string_ (Required) ID of the AMI to launch instances based on.
* min_count - _integer_ (Required) Minimum number of instances to launch.
* max_count - _integer_ (Required) Maximum number of instances to launch.
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* BlockDeviceMapping.n.DeviceName - _string_ (Optional; Required if BlockDeviceMapping.n.VirtualName is used) Specifies the device to which you are mapping a virtual name. For example: sdb.
* BlockDeviceMapping.n.VirtualName - _string_ (Optional; Required if BlockDeviceMapping.n.DeviceName is used) Specifies the virtual name to map to the corresponding device name. For example: instancestore0.
* InstanceType - _string_ (Optional) Specifies the instance type. Options include 'm1.small', 'm1.large', 'm1.xlarge', 'c1.medium', and 'c1.xlarge'. Defaults to 'm1.small'.
* KernelId - _string_ (Optional) The ID of the kernel with which to launch the instance. For information on finding available kernel IDs, see ec2-describe-images.
* KeyName - _string_ (Optional) Name of the keypair to launch instances with.
* Placement.AvailabilityZone - _string_ (Optional) Specifies the availability zone in which to launch the instance(s). To display a list of availability zones in which you can launch the instances, use the <describe_availability_zones()> operation. Default is determined by Amazon EC2.
* RamdiskId - _string_ (Optional) The ID of the RAM disk with which to launch the instance. Some kernels require additional drivers at launch. Check the kernel requirements for information on whether you need to specify a RAM disk. To find kernel requirements, go to the Resource Center and search for the kernel ID.
* SecurityGroup.n - _string_ (Optional) Names of the security groups to associate the instances with.
* UserData - _string_ (Optional) The user data available to the launched instances. This should be base64-encoded. See the UserDataType data type for encoding details.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-RunInstances.html
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/elastic_ip.phps
* Related - <confirm_product_instance()>, <describe_instances()>, <terminate_instances()>
*/
public function run_instances($image_id, $min_count, $max_count, $opt = null)
{
if (!$opt) $opt = array();
$opt['ImageId'] = $image_id;
$opt['MinCount'] = $min_count;
$opt['MaxCount'] = $max_count;
return $this->authenticate('RunInstances', $opt, $this->hostname);
}
/**
* Method: terminate_instances()
* Shuts down one or more instances. This operation is idempotent and terminating an instance that is in the process of shutting down (or already terminated) will succeed.
*
* Access:
* public
*
* Parameters:
* opt - _array_ (Optional) Associative array of parameters which can have the following keys:
*
* Keys for the $opt parameter:
* InstanceId.1 - _string_ (Required) One instance ID returned from previous calls to <run_instances()>.
* InstanceId.n - _string_ (Optional) More than one instance IDs returned from previous calls to <run_instances()>.
* returnCurlHandle - _boolean_ (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests.
*
* Returns:
* <ResponseCore> object
*
* See Also:
* AWS Method - http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/ApiReference-Query-TerminateInstances.html
* Example Usage - http://getcloudfusion.com/docs/examples/ec2/elastic_ip.phps
* Related - <confirm_product_instance()>, <describe_instances()>, <run_instances()>
*/
public function terminate_instances($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('TerminateInstances', $opt, $this->hostname);
}
/*%******************************************************************************************%*/
// KEYPAIRS
/**