aws 2.8.0 → 2.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c38fd2deb323c9e2f72657e91cfb0dbe1459db27
4
+ data.tar.gz: 4c765626d31f5faeb9a948c178675c7f8041e3d0
5
+ SHA512:
6
+ metadata.gz: b0b97fc689f97c1c801299a41e7b48b5dab41c1b17fdb4b8f7fb6418925ae0c836ef08a09ff765b150d80919cb01f490fe93f59b14078fa0d02417a323e67481
7
+ data.tar.gz: 68b859896d374a0de243949a861673275d447af64697f711be7aa19ff4fe8774134e18e40962f19d52fc505d6680bfa9968fc0209baaca30eb2ee6f461934988
@@ -0,0 +1,3 @@
1
+ /.project
2
+ pkg
3
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,66 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
12
+
13
+ require 'rdoc/task'
14
+ Rake::RDocTask.new do |rdoc|
15
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
16
+
17
+ rdoc.rdoc_dir = 'doc'
18
+ rdoc.title = "iron_mq #{version}"
19
+ rdoc.rdoc_files.include('README*')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ desc "Test just the SQS interface"
24
+ task :testsqs do
25
+ require 'test/test_credentials'
26
+ require 'test/http_connection'
27
+ TestCredentials.get_credentials
28
+ require 'test/sqs/test_sqs.rb'
29
+ end
30
+
31
+ desc "Test just the S3 interface"
32
+ task :tests3 do
33
+ require 'test/test_credentials'
34
+ require 'test/http_connection'
35
+ TestCredentials.get_credentials
36
+ require 'test/s3/test_s3.rb'
37
+ end
38
+
39
+ desc "Test just the S3 interface using local stubs"
40
+ task :tests3local do
41
+ require 'test/test_credentials'
42
+ require 'test/http_connection'
43
+ TestCredentials.get_credentials
44
+ require 'test/s3/test_s3_stubbed.rb'
45
+ end
46
+
47
+ desc "Test just the EC2 interface"
48
+ task :testec2 do
49
+ require 'test/test_credentials'
50
+ TestCredentials.get_credentials
51
+ require 'test/ec2/test_ec2.rb'
52
+ end
53
+
54
+ desc "Test just the SDB interface"
55
+ task :testsdb do
56
+ require 'test/test_credentials'
57
+ TestCredentials.get_credentials
58
+ require 'test/sdb/test_sdb.rb'
59
+ end
60
+
61
+ desc "Test CloudFront interface"
62
+ task :testacf do
63
+ require 'test/test_credentials'
64
+ TestCredentials.get_credentials
65
+ require 'test/acf/test_acf.rb'
66
+ end
@@ -0,0 +1,25 @@
1
+
2
+ require File.expand_path('../lib/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Travis Reeder", "Chad Arimura", "RightScale"]
6
+ gem.email = ["travis@appoxy.com"]
7
+ gem.description = "AWS Ruby Library for interfacing with Amazon Web Services including EC2, S3, SQS, SimpleDB and most of their other services as well. By http://www.appoxy.com"
8
+ gem.summary = "AWS Ruby Library for interfacing with Amazon Web Services including EC2, S3, SQS, SimpleDB and most of their other services as well. By http://www.appoxy.com"
9
+ gem.homepage = "http://github.com/appoxy/aws/"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "aws"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Aws::VERSION
17
+
18
+ gem.required_rubygems_version = ">= 1.3.6"
19
+ gem.required_ruby_version = Gem::Requirement.new(">= 1.8")
20
+ gem.add_runtime_dependency "uuidtools", ">= 0"
21
+ gem.add_runtime_dependency "xml-simple", ">= 0"
22
+ gem.add_runtime_dependency "http_connection", ">= 0"
23
+
24
+ end
25
+
@@ -1521,6 +1521,95 @@ module Aws
1521
1521
  on_exception
1522
1522
  end
1523
1523
 
1524
+ # Describe network interfaces in a VPC
1525
+ # http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeNetworkInterfaces.html
1526
+ #
1527
+ # ec2.describe_network_interfaces
1528
+ # ec2.describe_network_interfaces(ifaceId1, ifaceId2, ...,
1529
+ # 'Filter.1.Name' => 'addresses.primary',
1530
+ # 'Filter.1.Value.1' => true,
1531
+ # 'Filter.2.Name' => ...)
1532
+ def describe_network_interfaces(*args)
1533
+ if args.last.is_a?(Hash)
1534
+ filters = args.pop.dup
1535
+ else
1536
+ filters = {}
1537
+ end
1538
+ ids = hash_params('NetworkInterfaceId', args)
1539
+ params = filters.merge(ids)
1540
+ params['Version'] = "2013-02-01"
1541
+ link = generate_request('DescribeNetworkInterfaces', params)
1542
+ request_info(link, QEc2NetworkInterfacesParser.new(:logger => @logger))
1543
+ rescue Exception
1544
+ on_exception
1545
+ end
1546
+
1547
+ # Create a new network interface in a VPC
1548
+ # http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateNetworkInterface.html
1549
+ #
1550
+ # ec2.create_network_interface("subnet-a61dafcf")
1551
+ def create_network_interface(subnet_id, *args)
1552
+ if args.last.is_a?(Hash)
1553
+ params = args.pop.dup
1554
+ else
1555
+ params = {}
1556
+ end
1557
+ params.merge!({'SubnetId' => subnet_id, 'Version' => "2013-02-01"})
1558
+ link = generate_request('CreateNetworkInterface', params)
1559
+ request_info(link, QEc2NetworkInterfacesParser.new(:logger => @logger))
1560
+ rescue Exception
1561
+ on_exception
1562
+ end
1563
+
1564
+ # Attach a network interface to an instance
1565
+ # http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-AttachNetworkInterface.html
1566
+ #
1567
+ # ec2.attach_network_interface("eni-ffda3197", "i-9cc316fe", 1)
1568
+ def attach_network_interface(network_interface_id, instance_id, device_index)
1569
+ params = {
1570
+ "NetworkInterfaceId" => network_interface_id,
1571
+ "InstanceId" => instance_id,
1572
+ "DeviceIndex" => device_index,
1573
+ "Version" => "2013-02-01",
1574
+ }
1575
+ link = generate_request('AttachNetworkInterface', params)
1576
+ request_info(link, QEc2AttachNetworkInterfaceParser.new(:logger => @logger))
1577
+ rescue Exception
1578
+ on_exception
1579
+ end
1580
+
1581
+ # Detach a network interface from an instance
1582
+ # http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DetachNetworkInterface.html
1583
+ #
1584
+ # ec2.detach_network_interface("eni-attach-d94b09b0")
1585
+ # ec2.detach_network_interface("eni-attach-d94b09b0", true)
1586
+ def detach_network_interface(attachment_id, force=false)
1587
+ params = {
1588
+ "AttachmentId" => attachment_id,
1589
+ "Force" => force,
1590
+ "Version" => "2013-02-01",
1591
+ }
1592
+ link = generate_request('DetachNetworkInterface', params)
1593
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
1594
+ rescue Exception
1595
+ on_exception
1596
+ end
1597
+
1598
+ # Delete a network interface from a VPC
1599
+ # http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteNetworkInterface.html
1600
+ #
1601
+ # ec2.delete_network_interface("eni-ffda3197")
1602
+ def delete_network_interface(network_interface_id)
1603
+ params = {
1604
+ "NetworkInterfaceId" => network_interface_id,
1605
+ "Version" => "2013-02-01",
1606
+ }
1607
+ link = generate_request('DeleteNetworkInterface', params)
1608
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
1609
+ rescue Exception
1610
+ on_exception
1611
+ end
1612
+
1524
1613
  # Create subnet in a VPC
1525
1614
  # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSubnet.html
1526
1615
  #
@@ -2465,6 +2554,179 @@ module Aws
2465
2554
  end
2466
2555
  end
2467
2556
 
2557
+ class QEc2NetworkInterfacesParser < AwsParser #:nodoc:
2558
+ def initialize(opts = {})
2559
+ super(opts)
2560
+ @level = ['top']
2561
+ end
2562
+
2563
+ def tagstart(name, attribute)
2564
+ case name
2565
+ when 'groupSet'
2566
+ @level.push(name)
2567
+ @iface[:group_set] = []
2568
+ @group_item = {}
2569
+ when 'attachment'
2570
+ @level.push(name)
2571
+ @iface[:attachment] = {}
2572
+ when 'tagSet'
2573
+ @level.push(name)
2574
+ @iface[:tag_set] = []
2575
+ @tag_set_item = {}
2576
+ when 'association'
2577
+ @level.push(name)
2578
+ @association = {}
2579
+ when 'privateIpAddressesSet'
2580
+ @level.push(name)
2581
+ @iface[:private_ip_addresses_set] = []
2582
+ @ip_address_item = {}
2583
+ when 'networkInterface'
2584
+ @iface = {}
2585
+ when 'item'
2586
+ @iface = {} if @level.last == 'top'
2587
+ end
2588
+ end
2589
+
2590
+ def tagend(name)
2591
+ wrapper = @level.last
2592
+ case wrapper
2593
+ when 'top' # parse top level
2594
+ case name
2595
+ when 'networkInterfaceId'
2596
+ @iface[:network_interface_id] = @text
2597
+ when 'subnetId'
2598
+ @iface[:subnet_id] = @text
2599
+ when 'vpcId'
2600
+ @iface[:vpc_id] = @text
2601
+ when 'availabilityZone'
2602
+ @iface[:availability_zone] = @text
2603
+ when 'description'
2604
+ @iface[:description] = @text
2605
+ when 'ownerId'
2606
+ @iface[:owner_id] = @text
2607
+ when 'requesterId'
2608
+ @iface[:requester_id] = @text
2609
+ when 'requesterManaged'
2610
+ @iface[:requester_managed] = @text
2611
+ when 'status'
2612
+ @iface[:status] = @text
2613
+ when 'macAddress'
2614
+ @iface[:mac_address] = @text
2615
+ when 'privateIpAddress'
2616
+ @iface[:private_ip_address] = @text
2617
+ when 'privateDnsName'
2618
+ @iface[:private_dns_name] = @text
2619
+ when 'sourceDestCheck'
2620
+ @iface[:source_dest_check] = @text
2621
+ when 'networkInterface'
2622
+ @result = @iface
2623
+ when 'item'
2624
+ @result << @iface
2625
+ end
2626
+ when 'groupSet' # parse gorupset
2627
+ case name
2628
+ when 'groupId'
2629
+ @group_item[:group_id] = @text
2630
+ when 'groupName'
2631
+ @group_item[:group_name] = @text
2632
+ when 'item'
2633
+ @iface[:group_set] << @group_item
2634
+ @group_item = {}
2635
+ when 'groupSet'
2636
+ @level.pop
2637
+ end
2638
+ when 'attachment' # parse attachment
2639
+ case name
2640
+ when 'attachmentId'
2641
+ @iface[:attachment][:attachment_id] = @text
2642
+ when 'instanceId'
2643
+ @iface[:attachment][:instance_id] = @text
2644
+ when 'instanceOwnerId'
2645
+ @iface[:attachment][:instance_owner_id] = @text
2646
+ when 'deviceIndex'
2647
+ @iface[:attachment][:device_index] = @text
2648
+ when 'status'
2649
+ @iface[:attachment][:status] = @text
2650
+ when 'attachTime'
2651
+ @iface[:attachment][:attach_time] = @text
2652
+ when 'deleteOnTermination'
2653
+ @iface[:attachment][:delete_on_termination] = @text
2654
+ when 'attachment'
2655
+ @level.pop
2656
+ end
2657
+ when 'tagSet' # parse tagset
2658
+ case name
2659
+ when 'key'
2660
+ @tag_set_item[:key] = @text
2661
+ when 'value'
2662
+ @tag_set_item[:value] = @text
2663
+ when 'item'
2664
+ @iface[:tag_set] << @tag_set_item
2665
+ @tag_set_item = {}
2666
+ when 'tagSet'
2667
+ @level.pop
2668
+ end
2669
+ when 'association' # parse assoc
2670
+ case name
2671
+ when 'publicIp'
2672
+ @association[:public_ip] = @text
2673
+ when 'publicDnsName'
2674
+ @association[:public_dns_name] = @text
2675
+ when 'ipOwnerId'
2676
+ @association[:ip_owner_id] = @text
2677
+ when 'allocationID'
2678
+ @association[:allocation_id] = @text
2679
+ when 'associationID'
2680
+ @association[:association_id] = @text
2681
+ when 'association'
2682
+ @level.pop
2683
+
2684
+ # `association` can belong both to `NetworkInterfaceType` and `NetworkInterfacePrivateIpAddressesSetItemType`
2685
+ if @level.last == 'top'
2686
+ @iface[:association] = @association
2687
+ else
2688
+ @ip_address_item[:association] = @association
2689
+ end
2690
+ end
2691
+ when 'privateIpAddressesSet' # parse pirvate addresses set
2692
+ case name
2693
+ when 'privateIpAddress'
2694
+ @ip_address_item[:private_ip_address] = @text
2695
+ when 'privateDnsName'
2696
+ @ip_address_item[:private_dns_name] = @text
2697
+ when 'primary'
2698
+ @ip_address_item[:primary] = @text
2699
+ when 'item'
2700
+ @iface[:private_ip_addresses_set] << @ip_address_item
2701
+ @ip_address_item = {}
2702
+ when 'privateIpAddressesSet'
2703
+ @level.pop
2704
+ end
2705
+ end
2706
+ end
2707
+
2708
+ def reset
2709
+ @result = []
2710
+ end
2711
+ end
2712
+
2713
+ class QEc2AttachNetworkInterfaceParser < AwsParser #:nodoc:
2714
+ def initialize(opts = {})
2715
+ super(opts)
2716
+ end
2717
+
2718
+ def tagend(name)
2719
+ case name
2720
+ when 'attachmentId'
2721
+ @result['attachment_id'] = @text
2722
+ end
2723
+ end
2724
+
2725
+ def reset
2726
+ @result = {}
2727
+ end
2728
+ end
2729
+
2468
2730
  class QEc2SubnetsParser < AwsParser #:nodoc
2469
2731
  def initialize(wrapper, opts = {})
2470
2732
  super(opts)
@@ -0,0 +1,3 @@
1
+ module Aws
2
+ VERSION = "2.9.1"
3
+ end
@@ -0,0 +1,148 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
3
+
4
+ class TestAcf < Test::Unit::TestCase
5
+
6
+ RIGHT_OBJECT_TEXT = 'Right test message'
7
+
8
+ STDOUT.sync = true
9
+
10
+ def setup
11
+ TestCredentials.get_credentials
12
+ @acf= Aws::AcfInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
13
+ @s3 = Aws::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
14
+ @bucket_name = "right-acf-awesome-test-bucket-0001"
15
+ @bucket_domain = "#{@bucket_name}.s3.amazonaws.com"
16
+ end
17
+
18
+ def test_01_list_distributions_part1
19
+ distributions = nil
20
+ assert_nothing_raised(Aws::AwsError) do
21
+ distributions = @acf.list_distributions
22
+ end
23
+ assert distributions.is_a?(Array)
24
+ end
25
+
26
+ def test_02_try_to_create_for_bad_bucket
27
+ # a bucket does not exist
28
+ assert_raise(Aws::AwsError) do
29
+ @acf.create_distribution("right-cloudfront-awesome-test-bucket-not-exist", "Mustn't to be born", true)
30
+ end
31
+ # a bucket is not a domain naming complied guy
32
+ bucket_name = 'right_cloudfront_awesome_test_bucket_BAD'
33
+ @s3.bucket(bucket_name, :create)
34
+ assert_raise(Aws::AwsError) do
35
+ @acf.create_distribution(bucket_name, "Mustn't to be born", true)
36
+ end
37
+ end
38
+
39
+ def test_03_create
40
+ comment = 'WooHoo!!!'
41
+ # create a test bucket
42
+ @s3.bucket(@bucket_name, :create)
43
+ # create a distribution
44
+ distribution = @acf.create_distribution(@bucket_domain, comment, true)
45
+ assert_equal comment, distribution[:comment]
46
+ assert distribution[:cnames].size == 0
47
+ assert distribution[:enabled]
48
+ end
49
+
50
+ def test_04_list_distributions_part2
51
+ distributions = @acf.list_distributions
52
+ assert distributions.size > 0
53
+ end
54
+
55
+ def get_test_distribution
56
+ @acf.list_distributions.select{ |d| d[:origin] == @bucket_domain }.first
57
+ end
58
+
59
+ def test_05_get_distribution
60
+ old = get_test_distribution
61
+ assert_nothing_raised do
62
+ @acf.get_distribution(old[:aws_id])
63
+ end
64
+ end
65
+
66
+ def test_06_get_and_set_config
67
+ config = nil
68
+ old = get_test_distribution
69
+ assert_nothing_raised do
70
+ config = @acf.get_distribution_config(old[:aws_id])
71
+ end
72
+ # change a config
73
+ config[:enabled] = false
74
+ config[:cnames] << 'x1.myawesomesite.com'
75
+ config[:cnames] << 'x2.myawesomesite.com'
76
+ # set config
77
+ set_config_result = nil
78
+ assert_nothing_raised do
79
+ set_config_result = @acf.set_distribution_config(old[:aws_id], config)
80
+ end
81
+ assert set_config_result
82
+ # reget the config and check
83
+ new_config = nil
84
+ assert_nothing_raised do
85
+ new_config = @acf.get_distribution_config(old[:aws_id])
86
+ end
87
+ assert !new_config[:enabled]
88
+ assert_equal new_config[:cnames].sort, ['x1.myawesomesite.com', 'x2.myawesomesite.com']
89
+ assert_not_equal config[:e_tag], new_config[:e_tag]
90
+
91
+ # try to update the old config again (must fail because ETAG has changed)
92
+ assert_raise(Aws::AwsError) do
93
+ @acf.set_distribution_config(old[:aws_id], config)
94
+ end
95
+ end
96
+
97
+ def test_07_caching
98
+ # enable caching
99
+ @acf.params[:cache] = true
100
+ # list distributions
101
+ @acf.list_distributions
102
+ # list the distributions again - cache should hit
103
+ assert_raise(Aws::AwsNoChange) do
104
+ @acf.list_distributions
105
+ end
106
+ # disable caching
107
+ @acf.params[:cache] = true
108
+ end
109
+
110
+ def test_08_delete_distribution
111
+ # we need ETAG so use get_distribution
112
+ distribution = @acf.get_distribution(get_test_distribution[:aws_id])
113
+ # try to delete a distribution
114
+ # should fail because
115
+ if distribution[:status] == 'InProgress'
116
+ # should fail because the distribution is not deployed yet
117
+ assert_raise(Aws::AwsError) do
118
+ @acf.delete_distribution(distribution[:aws_id], distribution[:e_tag])
119
+ end
120
+ # wait for a deployed state
121
+ print "waiting up to 5 min while the distribution is being deployed: "
122
+ 100.times do
123
+ print '.'
124
+ distribution = @acf.get_distribution(distribution[:aws_id])
125
+ if distribution[:status] == 'Deployed'
126
+ print ' done'
127
+ break
128
+ end
129
+ sleep 3
130
+ end
131
+ puts
132
+ end
133
+
134
+ # only disabled and deployed distribution can be deleted
135
+ assert_equal 'Deployed', distribution[:status]
136
+ assert !distribution[:enabled]
137
+
138
+ # delete the distribution
139
+ assert_nothing_raised do
140
+ @acf.delete_distribution(distribution[:aws_id], distribution[:e_tag])
141
+ end
142
+ end
143
+
144
+ def test_09_drop_bucket
145
+ assert @s3.bucket(@bucket_name).delete
146
+ end
147
+
148
+ end