fog 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/README.rdoc +79 -2
  2. data/VERSION +1 -1
  3. data/fog.gemspec +28 -6
  4. data/lib/fog.rb +10 -7
  5. data/lib/fog/aws.rb +35 -9
  6. data/lib/fog/aws/ec2.rb +82 -69
  7. data/lib/fog/aws/models/ec2/address.rb +23 -1
  8. data/lib/fog/aws/models/ec2/addresses.rb +26 -2
  9. data/lib/fog/aws/models/ec2/instance.rb +135 -0
  10. data/lib/fog/aws/models/ec2/instances.rb +56 -0
  11. data/lib/fog/aws/models/ec2/key_pair.rb +17 -2
  12. data/lib/fog/aws/models/ec2/key_pairs.rb +29 -3
  13. data/lib/fog/aws/models/ec2/security_group.rb +41 -0
  14. data/lib/fog/aws/models/ec2/security_groups.rb +62 -0
  15. data/lib/fog/aws/models/ec2/snapshot.rb +12 -12
  16. data/lib/fog/aws/models/ec2/snapshots.rb +43 -21
  17. data/lib/fog/aws/models/ec2/volume.rb +21 -10
  18. data/lib/fog/aws/models/ec2/volumes.rb +30 -4
  19. data/lib/fog/aws/models/s3/buckets.rb +5 -8
  20. data/lib/fog/aws/models/s3/objects.rb +4 -7
  21. data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +63 -27
  22. data/lib/fog/aws/requests/ec2/create_security_group.rb +3 -3
  23. data/lib/fog/aws/requests/ec2/describe_images.rb +65 -35
  24. data/lib/fog/aws/requests/ec2/describe_instances.rb +2 -0
  25. data/lib/fog/aws/requests/ec2/get_console_output.rb +52 -21
  26. data/lib/fog/aws/requests/ec2/reboot_instances.rb +52 -19
  27. data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +63 -27
  28. data/lib/fog/aws/requests/ec2/run_instances.rb +1 -1
  29. data/lib/fog/aws/requests/ec2/terminate_instances.rb +14 -10
  30. data/lib/fog/aws/s3.rb +31 -35
  31. data/lib/fog/aws/simpledb.rb +19 -22
  32. data/lib/fog/collection.rb +3 -3
  33. data/lib/fog/connection.rb +2 -2
  34. data/lib/fog/errors.rb +1 -1
  35. data/lib/fog/model.rb +3 -3
  36. data/spec/aws/models/ec2/address_spec.rb +84 -0
  37. data/spec/aws/models/ec2/addresses_spec.rb +70 -0
  38. data/spec/aws/models/ec2/key_pair_spec.rb +84 -0
  39. data/spec/aws/models/ec2/key_pairs_spec.rb +71 -0
  40. data/spec/aws/models/ec2/security_group_spec.rb +84 -0
  41. data/spec/aws/models/ec2/security_groups_spec.rb +71 -0
  42. data/spec/aws/models/ec2/snapshot_spec.rb +93 -0
  43. data/spec/aws/models/ec2/snapshots_spec.rb +74 -0
  44. data/spec/aws/models/ec2/volume_spec.rb +84 -0
  45. data/spec/aws/models/ec2/volumes_spec.rb +70 -0
  46. data/spec/aws/models/s3/bucket_spec.rb +0 -1
  47. data/spec/aws/models/s3/buckets_spec.rb +2 -11
  48. data/spec/aws/requests/ec2/describe_security_groups_spec.rb +1 -1
  49. data/spec/aws/requests/ec2/get_console_output_spec.rb +9 -0
  50. data/spec/aws/requests/ec2/reboot_instances_spec.rb +11 -2
  51. data/spec/aws/requests/ec2/run_instances_spec.rb +1 -1
  52. data/spec/spec_helper.rb +1 -1
  53. metadata +26 -4
  54. data/LICENSE +0 -20
@@ -8,11 +8,22 @@ module Fog
8
8
 
9
9
  class Addresses < Fog::Collection
10
10
 
11
+ attribute :public_ip
12
+
13
+ def initialize(attributes)
14
+ @public_ip ||= []
15
+ super
16
+ end
17
+
11
18
  def all(public_ip = [])
12
19
  data = connection.describe_addresses(public_ip).body
13
- addresses = Fog::AWS::EC2::Addresses.new(:connection => connection)
20
+ addresses = Fog::AWS::EC2::Addresses.new({
21
+ :connection => connection,
22
+ :public_ip => public_ip
23
+ }.merge!(attributes))
14
24
  data['addressesSet'].each do |address|
15
25
  addresses << Fog::AWS::EC2::Address.new({
26
+ :addresses => self,
16
27
  :connection => connection
17
28
  }.merge!(address))
18
29
  end
@@ -25,8 +36,21 @@ module Fog
25
36
  address
26
37
  end
27
38
 
39
+ def get(public_ip)
40
+ all(public_ip).first
41
+ rescue Fog::Errors::BadRequest
42
+ nil
43
+ end
44
+
28
45
  def new
29
- Fog::AWS::S3::Address.new(:connection => connection)
46
+ Fog::AWS::EC2::Address.new(
47
+ :addresses => self,
48
+ :connection => connection
49
+ )
50
+ end
51
+
52
+ def reload
53
+ all(public_ip)
30
54
  end
31
55
 
32
56
  end
@@ -0,0 +1,135 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ class Instance < Fog::Model
6
+
7
+ attribute :ami_launch_index, 'amiLaunchIndex'
8
+ attribute :availability_zone, 'availabilityZone'
9
+ attribute :dns_name, 'dnsName'
10
+ attribute :group_id, 'groupId'
11
+ attribute :image_id, 'imageId'
12
+ attribute :instance_id, 'instanceId'
13
+ attribute :instance_state, 'instanceState'
14
+ attribute :instance_type, 'instanceType'
15
+ attribute :kernel_id, 'kernelId'
16
+ attribute :key_name, 'keyName'
17
+ attribute :launch_time, 'launchTime'
18
+ attribute :monitoring
19
+ attribute :placement
20
+ attribute :product_codes, 'productCodes'
21
+ attribute :private_dns_name, 'privateDnsName'
22
+ attribute :ramdisk_id, 'ramdiskId'
23
+ attribute :reason
24
+ attribute :user_data
25
+
26
+ def address
27
+ connection.addresses.select {|address| address.instance_id == @instance_id}.first
28
+ end
29
+
30
+ def address=(new_address)
31
+ new_address.instance_id = @instance_id
32
+ connection.associate_address(@instance_id, new_address.public_ip)
33
+ end
34
+
35
+ def destroy
36
+ connection.terminate_instances(@instance_id)
37
+ true
38
+ end
39
+
40
+ # def security_group
41
+ # connection.security_groups.all(@group_id)
42
+ # end
43
+ #
44
+ # def security_group=(new_security_group)
45
+ # @group_id = new_security_group.name
46
+ # end
47
+
48
+ def key_pair
49
+ connection.keypairs.all(@key_name).first
50
+ end
51
+
52
+ def key_pair=(new_keypair)
53
+ @key_name = new_keypair.name
54
+ end
55
+
56
+ def instances
57
+ @instances
58
+ end
59
+
60
+ def monitoring=(new_monitoring)
61
+ if new_monitoring.is_a?(Hash)
62
+ @monitoring = new_monitoring['state']
63
+ else
64
+ @monitoring = new_monitoring
65
+ end
66
+ end
67
+
68
+ def placement=(new_placement)
69
+ if placement.is_a?(Hash)
70
+ @availability_zone = new_placement['availabilityZone']
71
+ else
72
+ @availability_zone = new_placement
73
+ end
74
+ end
75
+
76
+ def reload
77
+ new_attributes = instances.all(@instance_id).first.attributes
78
+ merge_attributes(new_attributes)
79
+ end
80
+
81
+ def save
82
+ options = {}
83
+ if @availability_zone
84
+ options['Placement.AvailabilityZone'] = @availability_zone
85
+ end
86
+ if @group_id
87
+ options['groupId'] = @group_id
88
+ end
89
+ if @instance_type
90
+ options['instanceType'] = @instance_type
91
+ end
92
+ if @kernel_id
93
+ options['KernelId'] = @kernel_id
94
+ end
95
+ if @key_name
96
+ options['KeyName'] = @key_name
97
+ end
98
+ if @monitoring
99
+ options['Monitoring.Enabled'] = @monitoring
100
+ end
101
+ if @ramdisk_id
102
+ options['RamdiskId'] = @ramdisk_id
103
+ end
104
+ if @user_data
105
+ options['UserData'] = @user_data
106
+ end
107
+ data = connection.run_instances(@image_id, 1, 1, options)
108
+ merge_attributes(data.body['instancesSet'].first)
109
+ true
110
+ end
111
+
112
+ def volumes
113
+ connection.volumes.all.select {|volume| volume.instance_id == @instance_id}
114
+ end
115
+
116
+ def volume=(new_volume)
117
+ new_volume.instance_id = @instance_id
118
+ connection.attach_volume(@instance_id, new_volume.volume_id, new_volume.device)
119
+ end
120
+
121
+ private
122
+
123
+ def instance_state=(new_instance_state)
124
+ @instance_state = new_instance_state['name']
125
+ end
126
+
127
+ def instances=(new_instances)
128
+ @instances = new_instances
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,56 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ def instances
6
+ Fog::AWS::EC2::Instances.new(:connection => self)
7
+ end
8
+
9
+ class Instances < Fog::Collection
10
+
11
+ attribute :instance_id
12
+
13
+ def all(instance_id = [])
14
+ data = connection.describe_instances(instance_id)
15
+ instances = Fog::AWS::EC2::Instances.new({
16
+ :connection => connection
17
+ }.merge!(attributes))
18
+ data['instancesSet'].each do |instance|
19
+ instances << Fog::AWS::EC2::Instances.new({
20
+ :connection => connection,
21
+ :instances => self
22
+ }.merge!(instance))
23
+ end
24
+ instances
25
+ end
26
+
27
+ def create(attributes = {})
28
+ instance = new(attributes)
29
+ instance.save
30
+ instance
31
+ end
32
+
33
+ def get(instance_id)
34
+ all(instance_id).first
35
+ rescue Fog::Errors::BadRequest
36
+ nil
37
+ end
38
+
39
+ def new(attributes = {})
40
+ Fog::AWS::EC2::Instance.new(
41
+ attributes.merge!(
42
+ :connection => connection,
43
+ :instances => self
44
+ )
45
+ )
46
+ end
47
+
48
+ def reload
49
+ all(instance_id)
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -8,18 +8,33 @@ module Fog
8
8
  attribute :material, 'keyMaterial'
9
9
  attribute :name, 'keyName'
10
10
 
11
- def delete
11
+ def destroy
12
12
  connection.delete_key_pair(@name)
13
13
  true
14
14
  end
15
15
 
16
+ def key_pairs
17
+ @key_pairs
18
+ end
19
+
20
+ def reload
21
+ new_attributes = key_pairs.all(@name).first.attributes
22
+ merge_attributes(new_attributes)
23
+ end
24
+
16
25
  def save
17
26
  data = connection.create_key_pair(@name).body
18
27
  new_attributes = data.reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
19
- update_attributes(new_attributes)
28
+ merge_attributes(new_attributes)
20
29
  true
21
30
  end
22
31
 
32
+ private
33
+
34
+ def key_pairs=(new_key_pairs)
35
+ @key_pairs = new_key_pairs
36
+ end
37
+
23
38
  end
24
39
 
25
40
  end
@@ -8,12 +8,23 @@ module Fog
8
8
 
9
9
  class KeyPairs < Fog::Collection
10
10
 
11
+ attribute :key_name
12
+
13
+ def initialize(attributes)
14
+ @key_name ||= []
15
+ super
16
+ end
17
+
11
18
  def all(key_name = [])
12
19
  data = connection.describe_key_pairs(key_name).body
13
- key_pairs = Fog::AWS::EC2::KeyPairs.new(:connection => connection)
20
+ key_pairs = Fog::AWS::EC2::KeyPairs.new({
21
+ :connection => connection,
22
+ :key_name => key_name
23
+ }.merge!(attributes))
14
24
  data['keySet'].each do |key|
15
25
  key_pairs << Fog::AWS::EC2::KeyPair.new({
16
- :connection => connection
26
+ :connection => connection,
27
+ :key_pairs => self
17
28
  }.merge!(key))
18
29
  end
19
30
  key_pairs
@@ -25,8 +36,23 @@ module Fog
25
36
  bucket
26
37
  end
27
38
 
39
+ def get(key_name)
40
+ all(key_name).first
41
+ rescue Fog::Errors::BadRequest
42
+ nil
43
+ end
44
+
28
45
  def new(attributes = {})
29
- Fog::AWS::EC2::KeyPair.new(attributes.merge!(:connection => connection))
46
+ Fog::AWS::EC2::KeyPair.new(
47
+ attributes.merge!(
48
+ :connection => connection,
49
+ :key_pairs => self
50
+ )
51
+ )
52
+ end
53
+
54
+ def reload
55
+ all(key_name)
30
56
  end
31
57
 
32
58
  end
@@ -0,0 +1,41 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ class SecurityGroup < Fog::Model
6
+
7
+ attribute :group_description, 'groupDescription'
8
+ attribute :group_name, 'groupName'
9
+ attribute :ip_permissions, 'ipPermissions'
10
+ attribute :owner_id, 'ownerId'
11
+
12
+ def destroy
13
+ connection.delete_security_group(@group_name)
14
+ true
15
+ end
16
+
17
+ def reload
18
+ new_attributes = security_groups.get(@group_name).attributes
19
+ merge_attributes(new_attributes)
20
+ end
21
+
22
+ def save
23
+ data = connection.create_security_group(@group_name, @group_description).body
24
+ true
25
+ end
26
+
27
+ def security_groups
28
+ @security_groups
29
+ end
30
+
31
+ private
32
+
33
+ def security_groups=(new_security_groups)
34
+ @security_groups = new_security_groups
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,62 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ def security_groups
6
+ Fog::AWS::EC2::SecurityGroups.new(:connection => self)
7
+ end
8
+
9
+ class SecurityGroups < Fog::Collection
10
+
11
+ attribute :group_name
12
+
13
+ def initialize(attributes)
14
+ @group_name ||= []
15
+ super
16
+ end
17
+
18
+ def all(group_name = [])
19
+ data = connection.describe_security_groups(group_name).body
20
+ security_groups = Fog::AWS::EC2::SecurityGroups.new({
21
+ :connection => connection,
22
+ :group_name => group_name
23
+ }.merge!(attributes))
24
+ data['securityGroupInfo'].each do |security_group|
25
+ security_groups << Fog::AWS::EC2::SecurityGroup.new({
26
+ :connection => connection,
27
+ :security_groups => self
28
+ }.merge!(security_group))
29
+ end
30
+ security_groups
31
+ end
32
+
33
+ def create(attributes = {})
34
+ security_group = new(attributes)
35
+ security_group.save
36
+ security_group
37
+ end
38
+
39
+ def get(group_name)
40
+ all(group_name).first
41
+ rescue Fog::Errors::BadRequest
42
+ nil
43
+ end
44
+
45
+ def new(attributes = {})
46
+ Fog::AWS::EC2::SecurityGroup.new(
47
+ attributes.merge!(
48
+ :connection => connection,
49
+ :security_groups => self
50
+ )
51
+ )
52
+ end
53
+
54
+ def reload
55
+ all(group_name)
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -8,31 +8,31 @@ module Fog
8
8
  attribute :snapshot_id, 'snapshotId'
9
9
  attribute :start_time, 'startTime'
10
10
  attribute :status
11
- attribute :volumeId, 'volumeId'
11
+ attribute :volume_id, 'volumeId'
12
12
 
13
- def delete
13
+ def destroy
14
14
  connection.delete_snapshot(@snapshot_id)
15
15
  true
16
16
  end
17
17
 
18
+ def reload
19
+ new_attributes = snapshots.get(@snapshot_id).attributes
20
+ merge_attributes(new_attributes)
21
+ end
22
+
18
23
  def save
19
- data = connection.create_snapshot(@volume.volume_id).body
24
+ data = connection.create_snapshot(volume_id).body
20
25
  new_attributes = data.reject {|key,value| key == 'requestId'}
21
- update_attributes(new_attributes)
26
+ merge_attributes(new_attributes)
22
27
  true
23
28
  end
24
29
 
25
30
  def snapshots
26
- @snapshots ||= begin
27
- Fog::AWS::S3::Snapshots.new(
28
- :connection => connection,
29
- :volume => self
30
- )
31
- end
31
+ @snapshots
32
32
  end
33
33
 
34
34
  def volume
35
- @volume
35
+ connection.describe_volumes(@volume_id)
36
36
  end
37
37
 
38
38
  private
@@ -42,7 +42,7 @@ module Fog
42
42
  end
43
43
 
44
44
  def volume=(new_volume)
45
- @volume = new_volume
45
+ @volume_id = new_volume.volume_id
46
46
  end
47
47
 
48
48
  end