fog 0.0.29 → 0.0.30
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/fog +18 -11
- data/fog.gemspec +43 -14
- data/lib/fog.rb +7 -1
- data/lib/fog/aws/ec2.rb +0 -7
- data/lib/fog/aws/models/ec2/address.rb +22 -26
- data/lib/fog/aws/models/ec2/addresses.rb +7 -22
- data/lib/fog/aws/models/ec2/instance.rb +2 -15
- data/lib/fog/aws/models/ec2/instances.rb +6 -23
- data/lib/fog/aws/models/ec2/key_pair.rb +2 -17
- data/lib/fog/aws/models/ec2/key_pairs.rb +6 -23
- data/lib/fog/aws/models/ec2/security_group.rb +18 -22
- data/lib/fog/aws/models/ec2/security_groups.rb +6 -23
- data/lib/fog/aws/models/ec2/snapshot.rb +2 -15
- data/lib/fog/aws/models/ec2/snapshots.rb +7 -20
- data/lib/fog/aws/models/ec2/volume.rb +23 -22
- data/lib/fog/aws/models/ec2/volumes.rb +8 -22
- data/lib/fog/aws/models/s3/bucket.rb +1 -1
- data/lib/fog/aws/models/s3/buckets.rb +3 -20
- data/lib/fog/aws/models/s3/objects.rb +11 -22
- data/lib/fog/aws/requests/ec2/allocate_address.rb +1 -1
- data/lib/fog/aws/requests/ec2/associate_address.rb +2 -2
- data/lib/fog/aws/requests/ec2/attach_volume.rb +2 -2
- data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +1 -1
- data/lib/fog/aws/requests/ec2/create_key_pair.rb +2 -2
- data/lib/fog/aws/requests/ec2/create_security_group.rb +2 -2
- data/lib/fog/aws/requests/ec2/create_snapshot.rb +2 -2
- data/lib/fog/aws/requests/ec2/create_volume.rb +3 -3
- data/lib/fog/aws/requests/ec2/delete_key_pair.rb +1 -1
- data/lib/fog/aws/requests/ec2/delete_security_group.rb +2 -2
- data/lib/fog/aws/requests/ec2/delete_snapshot.rb +2 -2
- data/lib/fog/aws/requests/ec2/delete_volume.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_addresses.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_availability_zones.rb +1 -1
- data/lib/fog/aws/requests/ec2/describe_images.rb +1 -1
- data/lib/fog/aws/requests/ec2/describe_instances.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_regions.rb +1 -1
- data/lib/fog/aws/requests/ec2/describe_security_groups.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_snapshots.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_volumes.rb +2 -2
- data/lib/fog/aws/requests/ec2/detach_volume.rb +2 -2
- data/lib/fog/aws/requests/ec2/disassociate_address.rb +2 -2
- data/lib/fog/aws/requests/ec2/get_console_output.rb +2 -2
- data/lib/fog/aws/requests/ec2/reboot_instances.rb +2 -2
- data/lib/fog/aws/requests/ec2/release_address.rb +2 -2
- data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +1 -1
- data/lib/fog/aws/requests/ec2/run_instances.rb +2 -2
- data/lib/fog/aws/requests/ec2/terminate_instances.rb +2 -2
- data/lib/fog/aws/requests/s3/copy_object.rb +2 -2
- data/lib/fog/aws/requests/s3/delete_bucket.rb +3 -3
- data/lib/fog/aws/requests/s3/delete_object.rb +2 -2
- data/lib/fog/aws/requests/s3/get_bucket.rb +2 -2
- data/lib/fog/aws/requests/s3/get_bucket_location.rb +2 -2
- data/lib/fog/aws/requests/s3/get_object.rb +2 -2
- data/lib/fog/aws/requests/s3/get_request_payment.rb +2 -2
- data/lib/fog/aws/requests/s3/get_service.rb +1 -1
- data/lib/fog/aws/requests/s3/head_object.rb +1 -1
- data/lib/fog/aws/requests/s3/put_bucket.rb +1 -1
- data/lib/fog/aws/requests/s3/put_object.rb +2 -2
- data/lib/fog/aws/requests/s3/put_request_payment.rb +1 -1
- data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +2 -2
- data/lib/fog/aws/requests/simpledb/create_domain.rb +1 -1
- data/lib/fog/aws/requests/simpledb/delete_attributes.rb +2 -2
- data/lib/fog/aws/requests/simpledb/delete_domain.rb +1 -1
- data/lib/fog/aws/requests/simpledb/domain_metadata.rb +2 -2
- data/lib/fog/aws/requests/simpledb/get_attributes.rb +2 -2
- data/lib/fog/aws/requests/simpledb/list_domains.rb +1 -1
- data/lib/fog/aws/requests/simpledb/put_attributes.rb +1 -1
- data/lib/fog/aws/requests/simpledb/select.rb +1 -1
- data/lib/fog/aws/s3.rb +0 -7
- data/lib/fog/aws/simpledb.rb +0 -4
- data/lib/fog/collection.rb +35 -7
- data/lib/fog/connection.rb +10 -130
- data/lib/fog/model.rb +18 -13
- data/lib/fog/parser.rb +0 -5
- data/lib/fog/rackspace.rb +35 -15
- data/lib/fog/rackspace/files.rb +36 -6
- data/lib/fog/rackspace/models/servers/server.rb +2 -16
- data/lib/fog/rackspace/models/servers/servers.rb +6 -21
- data/lib/fog/rackspace/requests/files/delete_container.rb +38 -0
- data/lib/fog/rackspace/requests/files/delete_object.rb +39 -0
- data/lib/fog/rackspace/requests/files/get_container.rb +61 -0
- data/lib/fog/rackspace/requests/files/get_containers.rb +5 -7
- data/lib/fog/rackspace/requests/files/head_container.rb +44 -0
- data/lib/fog/rackspace/requests/files/head_containers.rb +1 -1
- data/lib/fog/rackspace/requests/files/put_container.rb +38 -0
- data/lib/fog/rackspace/requests/files/put_object.rb +41 -0
- data/lib/fog/rackspace/requests/servers/create_image.rb +6 -0
- data/lib/fog/rackspace/requests/servers/create_server.rb +21 -2
- data/lib/fog/rackspace/requests/servers/delete_server.rb +18 -3
- data/lib/fog/rackspace/requests/servers/get_server_details.rb +17 -5
- data/lib/fog/rackspace/requests/servers/list_addresses.rb +52 -0
- data/lib/fog/rackspace/requests/servers/list_flavors.rb +2 -4
- data/lib/fog/rackspace/requests/servers/list_flavors_detail.rb +41 -0
- data/lib/fog/rackspace/requests/servers/list_images.rb +1 -1
- data/lib/fog/rackspace/requests/servers/list_images_detail.rb +1 -1
- data/lib/fog/rackspace/requests/servers/list_private_addresses.rb +50 -0
- data/lib/fog/rackspace/requests/servers/list_public_addresses.rb +50 -0
- data/lib/fog/rackspace/requests/servers/list_servers.rb +11 -2
- data/lib/fog/rackspace/requests/servers/list_servers_detail.rb +17 -2
- data/lib/fog/rackspace/requests/servers/reboot_server.rb +3 -6
- data/lib/fog/rackspace/requests/servers/update_server.rb +18 -5
- data/lib/fog/rackspace/servers.rb +20 -0
- data/spec/aws/models/ec2/address_spec.rb +4 -4
- data/spec/aws/models/ec2/instance_spec.rb +6 -6
- data/spec/aws/models/ec2/key_pair_spec.rb +5 -5
- data/spec/aws/models/ec2/security_group_spec.rb +5 -5
- data/spec/aws/models/ec2/snapshot_spec.rb +8 -8
- data/spec/aws/models/ec2/snapshots_spec.rb +6 -6
- data/spec/aws/models/ec2/volume_spec.rb +6 -5
- data/spec/aws/models/ec2/volumes_spec.rb +4 -4
- data/spec/aws/requests/ec2/associate_address_spec.rb +2 -2
- data/spec/aws/requests/ec2/attach_volume_spec.rb +2 -2
- data/spec/aws/requests/ec2/create_key_pair_spec.rb +1 -1
- data/spec/aws/requests/ec2/create_security_group_spec.rb +1 -1
- data/spec/aws/requests/ec2/create_snapshot_spec.rb +1 -1
- data/spec/aws/requests/ec2/delete_security_group_spec.rb +1 -1
- data/spec/aws/requests/ec2/delete_snapshot_spec.rb +1 -1
- data/spec/aws/requests/ec2/delete_volume_spec.rb +2 -2
- data/spec/aws/requests/ec2/describe_addresses_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_instances_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_key_pairs_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_security_groups_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_snapshots_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_volumes_spec.rb +1 -1
- data/spec/aws/requests/ec2/detach_volume_spec.rb +1 -1
- data/spec/aws/requests/ec2/disassociate_address_spec.rb +1 -1
- data/spec/aws/requests/ec2/get_console_output_spec.rb +1 -1
- data/spec/aws/requests/ec2/reboot_instances_spec.rb +1 -1
- data/spec/aws/requests/ec2/release_address_spec.rb +1 -1
- data/spec/aws/requests/ec2/terminate_instances_spec.rb +1 -1
- data/spec/aws/requests/s3/copy_object_spec.rb +4 -5
- data/spec/aws/requests/s3/delete_bucket_spec.rb +3 -4
- data/spec/aws/requests/s3/delete_object_spec.rb +2 -3
- data/spec/aws/requests/s3/get_bucket_location_spec.rb +1 -1
- data/spec/aws/requests/s3/get_bucket_spec.rb +4 -6
- data/spec/aws/requests/s3/get_object_spec.rb +6 -10
- data/spec/aws/requests/s3/get_request_payment_spec.rb +1 -1
- data/spec/aws/requests/s3/head_object_spec.rb +2 -4
- data/spec/aws/requests/s3/put_object_spec.rb +4 -7
- data/spec/aws/requests/s3/put_request_payment_spec.rb +1 -1
- data/spec/aws/requests/simpledb/batch_put_attributes_spec.rb +1 -1
- data/spec/aws/requests/simpledb/delete_attributes_spec.rb +1 -1
- data/spec/aws/requests/simpledb/domain_metadata_spec.rb +1 -1
- data/spec/aws/requests/simpledb/get_attributes_spec.rb +1 -1
- data/spec/aws/requests/simpledb/put_attributes_spec.rb +1 -1
- data/spec/rackspace/requests/files/delete_container_spec.rb +24 -0
- data/spec/rackspace/requests/files/delete_object_spec.rb +37 -0
- data/spec/rackspace/requests/files/get_container_spec.rb +33 -0
- data/spec/rackspace/requests/files/get_containers_spec.rb +12 -1
- data/spec/rackspace/requests/files/head_container_spec.rb +30 -0
- data/spec/rackspace/requests/files/head_containers_spec.rb +9 -1
- data/spec/rackspace/requests/files/put_container_spec.rb +15 -0
- data/spec/rackspace/requests/files/put_object_spec.rb +20 -0
- data/spec/rackspace/requests/servers/create_image_spec.rb +16 -2
- data/spec/rackspace/requests/servers/create_server_spec.rb +1 -1
- data/spec/rackspace/requests/servers/delete_image_spec.rb +32 -0
- data/spec/rackspace/requests/servers/delete_server_spec.rb +1 -1
- data/spec/rackspace/requests/servers/get_server_details_spec.rb +1 -1
- data/spec/rackspace/requests/servers/list_addresses_spec.rb +34 -0
- data/spec/rackspace/requests/servers/list_flavors_detail_spec.rb +17 -0
- data/spec/rackspace/requests/servers/list_flavors_spec.rb +6 -3
- data/spec/rackspace/requests/servers/list_images_detail_spec.rb +18 -0
- data/spec/rackspace/requests/servers/list_images_spec.rb +5 -2
- data/spec/rackspace/requests/servers/list_private_addresses_spec.rb +32 -0
- data/spec/rackspace/requests/servers/list_public_addresses_spec.rb +32 -0
- data/spec/rackspace/requests/servers/list_servers_detail_spec.rb +1 -1
- data/spec/rackspace/requests/servers/reboot_server_spec.rb +31 -0
- data/spec/rackspace/requests/servers/update_server_spec.rb +33 -0
- data/spec/spec_helper.rb +5 -1
- metadata +50 -14
- data/benchs/headers_split_vs_match.rb +0 -18
- data/benchs/stripping.rb +0 -26
- data/lib/fog/errors.rb +0 -145
- data/lib/fog/response.rb +0 -12
- data/spec/rackspace/requests/servers/delete_image.rb +0 -12
- data/spec/rackspace/requests/servers/list_images_detail.rb +0 -12
- data/spec/rackspace/requests/servers/reboot_server.rb +0 -12
- data/spec/rackspace/requests/servers/update_server.rb +0 -12
@@ -4,25 +4,16 @@ module Fog
|
|
4
4
|
|
5
5
|
class KeyPair < Fog::Model
|
6
6
|
|
7
|
+
identity :name, 'keyName'
|
8
|
+
|
7
9
|
attribute :fingerprint, 'keyFingerprint'
|
8
10
|
attribute :material, 'keyMaterial'
|
9
|
-
attribute :name, 'keyName'
|
10
11
|
|
11
12
|
def destroy
|
12
13
|
connection.delete_key_pair(@name)
|
13
14
|
true
|
14
15
|
end
|
15
16
|
|
16
|
-
def key_pairs
|
17
|
-
@key_pairs
|
18
|
-
end
|
19
|
-
|
20
|
-
def reload
|
21
|
-
if new_key_pair = key_pairs.get(@name)
|
22
|
-
merge_attributes(new_key_pair.attributes)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
17
|
def save
|
27
18
|
data = connection.create_key_pair(@name).body
|
28
19
|
new_attributes = data.reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
|
@@ -30,12 +21,6 @@ module Fog
|
|
30
21
|
true
|
31
22
|
end
|
32
23
|
|
33
|
-
private
|
34
|
-
|
35
|
-
def key_pairs=(new_key_pairs)
|
36
|
-
@key_pairs = new_key_pairs
|
37
|
-
end
|
38
|
-
|
39
24
|
end
|
40
25
|
|
41
26
|
end
|
@@ -10,12 +10,14 @@ module Fog
|
|
10
10
|
|
11
11
|
attribute :key_name
|
12
12
|
|
13
|
+
model Fog::AWS::EC2::KeyPair
|
14
|
+
|
13
15
|
def initialize(attributes)
|
14
16
|
@key_name ||= []
|
15
17
|
super
|
16
18
|
end
|
17
19
|
|
18
|
-
def all(key_name =
|
20
|
+
def all(key_name = @key_name)
|
19
21
|
data = connection.describe_key_pairs(key_name).body
|
20
22
|
key_pairs = Fog::AWS::EC2::KeyPairs.new({
|
21
23
|
:connection => connection,
|
@@ -23,40 +25,21 @@ module Fog
|
|
23
25
|
}.merge!(attributes))
|
24
26
|
data['keySet'].each do |key|
|
25
27
|
key_pairs << Fog::AWS::EC2::KeyPair.new({
|
26
|
-
:
|
27
|
-
:
|
28
|
+
:collection => key_pairs,
|
29
|
+
:connection => connection
|
28
30
|
}.merge!(key))
|
29
31
|
end
|
30
32
|
key_pairs
|
31
33
|
end
|
32
34
|
|
33
|
-
def create(attributes = {})
|
34
|
-
bucket = new(attributes)
|
35
|
-
bucket.save
|
36
|
-
bucket
|
37
|
-
end
|
38
|
-
|
39
35
|
def get(key_name)
|
40
36
|
if key_name
|
41
37
|
all(key_name).first
|
42
38
|
end
|
43
|
-
rescue
|
39
|
+
rescue Excon::Errors::BadRequest
|
44
40
|
nil
|
45
41
|
end
|
46
42
|
|
47
|
-
def new(attributes = {})
|
48
|
-
Fog::AWS::EC2::KeyPair.new(
|
49
|
-
attributes.merge!(
|
50
|
-
:connection => connection,
|
51
|
-
:key_pairs => self
|
52
|
-
)
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
def reload
|
57
|
-
all(key_name)
|
58
|
-
end
|
59
|
-
|
60
43
|
end
|
61
44
|
|
62
45
|
end
|
@@ -4,16 +4,28 @@ module Fog
|
|
4
4
|
|
5
5
|
class SecurityGroup < Fog::Model
|
6
6
|
|
7
|
+
identity :group_name, 'groupName'
|
8
|
+
|
7
9
|
attribute :group_description, 'groupDescription'
|
8
|
-
attribute :group_name, 'groupName'
|
9
10
|
attribute :ip_permissions, 'ipPermissions'
|
10
11
|
attribute :owner_id, 'ownerId'
|
11
12
|
|
12
|
-
def
|
13
|
-
|
14
|
-
'GroupName'
|
15
|
-
|
16
|
-
|
13
|
+
def authorize_group_and_owner(group, owner)
|
14
|
+
connection.authorize_security_group_ingress(
|
15
|
+
'GroupName' => @group_name,
|
16
|
+
'SourceSecurityGroupName' => group,
|
17
|
+
'SourceSecurityGroupOwnerId' => owner
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def authorize_port_range(range, options = {})
|
22
|
+
connection.authorize_security_group_ingress(
|
23
|
+
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0',
|
24
|
+
'FromPort' => range.min,
|
25
|
+
'GroupName' => @group_name,
|
26
|
+
'ToPort' => range.max,
|
27
|
+
'IpProtocol' => options[:ip_protocol] || 'tcp'
|
28
|
+
)
|
17
29
|
end
|
18
30
|
|
19
31
|
def destroy
|
@@ -21,27 +33,11 @@ module Fog
|
|
21
33
|
true
|
22
34
|
end
|
23
35
|
|
24
|
-
def reload
|
25
|
-
if new_security_group = security_groups.get(@group_name)
|
26
|
-
merge_attributes(new_security_group.attributes)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
36
|
def save
|
31
37
|
data = connection.create_security_group(@group_name, @group_description).body
|
32
38
|
true
|
33
39
|
end
|
34
40
|
|
35
|
-
def security_groups
|
36
|
-
@security_groups
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def security_groups=(new_security_groups)
|
42
|
-
@security_groups = new_security_groups
|
43
|
-
end
|
44
|
-
|
45
41
|
end
|
46
42
|
|
47
43
|
end
|
@@ -10,12 +10,14 @@ module Fog
|
|
10
10
|
|
11
11
|
attribute :group_name
|
12
12
|
|
13
|
+
model Fog::AWS::EC2::SecurityGroup
|
14
|
+
|
13
15
|
def initialize(attributes)
|
14
16
|
@group_name ||= []
|
15
17
|
super
|
16
18
|
end
|
17
19
|
|
18
|
-
def all(group_name =
|
20
|
+
def all(group_name = @group_name)
|
19
21
|
data = connection.describe_security_groups(group_name).body
|
20
22
|
security_groups = Fog::AWS::EC2::SecurityGroups.new({
|
21
23
|
:connection => connection,
|
@@ -23,40 +25,21 @@ module Fog
|
|
23
25
|
}.merge!(attributes))
|
24
26
|
data['securityGroupInfo'].each do |security_group|
|
25
27
|
security_groups << Fog::AWS::EC2::SecurityGroup.new({
|
26
|
-
:
|
27
|
-
:
|
28
|
+
:collection => security_groups,
|
29
|
+
:connection => connection
|
28
30
|
}.merge!(security_group))
|
29
31
|
end
|
30
32
|
security_groups
|
31
33
|
end
|
32
34
|
|
33
|
-
def create(attributes = {})
|
34
|
-
security_group = new(attributes)
|
35
|
-
security_group.save
|
36
|
-
security_group
|
37
|
-
end
|
38
|
-
|
39
35
|
def get(group_name)
|
40
36
|
if group_name
|
41
37
|
all(group_name).first
|
42
38
|
end
|
43
|
-
rescue
|
39
|
+
rescue Excon::Errors::BadRequest
|
44
40
|
nil
|
45
41
|
end
|
46
42
|
|
47
|
-
def new(attributes = {})
|
48
|
-
Fog::AWS::EC2::SecurityGroup.new(
|
49
|
-
attributes.merge!(
|
50
|
-
:connection => connection,
|
51
|
-
:security_groups => self
|
52
|
-
)
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
def reload
|
57
|
-
all(group_name)
|
58
|
-
end
|
59
|
-
|
60
43
|
end
|
61
44
|
|
62
45
|
end
|
@@ -4,8 +4,9 @@ module Fog
|
|
4
4
|
|
5
5
|
class Snapshot < Fog::Model
|
6
6
|
|
7
|
+
identity :snapshot_id, 'snapshotId'
|
8
|
+
|
7
9
|
attribute :progress
|
8
|
-
attribute :snapshot_id, 'snapshotId'
|
9
10
|
attribute :start_time, 'startTime'
|
10
11
|
attribute :status
|
11
12
|
attribute :volume_id, 'volumeId'
|
@@ -15,12 +16,6 @@ module Fog
|
|
15
16
|
true
|
16
17
|
end
|
17
18
|
|
18
|
-
def reload
|
19
|
-
if new_snapshot = snapshots.get(@snapshot_id)
|
20
|
-
merge_attributes(new_snapshot.attributes)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
19
|
def save
|
25
20
|
data = connection.create_snapshot(volume_id).body
|
26
21
|
new_attributes = data.reject {|key,value| key == 'requestId'}
|
@@ -28,20 +23,12 @@ module Fog
|
|
28
23
|
true
|
29
24
|
end
|
30
25
|
|
31
|
-
def snapshots
|
32
|
-
@snapshots
|
33
|
-
end
|
34
|
-
|
35
26
|
def volume
|
36
27
|
connection.describe_volumes(@volume_id)
|
37
28
|
end
|
38
29
|
|
39
30
|
private
|
40
31
|
|
41
|
-
def snapshots=(new_snapshots)
|
42
|
-
@snapshots = new_snapshots
|
43
|
-
end
|
44
|
-
|
45
32
|
def volume=(new_volume)
|
46
33
|
@volume_id = new_volume.volume_id
|
47
34
|
end
|
@@ -13,12 +13,14 @@ module Fog
|
|
13
13
|
attribute :snapshot_id
|
14
14
|
attribute :volume_id
|
15
15
|
|
16
|
+
model Fog::AWS::EC2::Snapshot
|
17
|
+
|
16
18
|
def initialize(attributes)
|
17
19
|
@snapshot_id ||= []
|
18
20
|
super
|
19
21
|
end
|
20
22
|
|
21
|
-
def all(snapshot_id =
|
23
|
+
def all(snapshot_id = @snapshot_id)
|
22
24
|
data = connection.describe_snapshots(snapshot_id).body
|
23
25
|
snapshots = Fog::AWS::EC2::Snapshots.new({
|
24
26
|
:connection => connection,
|
@@ -26,8 +28,8 @@ module Fog
|
|
26
28
|
}.merge!(attributes))
|
27
29
|
data['snapshotSet'].each do |snapshot|
|
28
30
|
snapshots << Fog::AWS::EC2::Snapshot.new({
|
29
|
-
:
|
30
|
-
:
|
31
|
+
:collection => snapshots,
|
32
|
+
:connection => connection
|
31
33
|
}.merge!(snapshot))
|
32
34
|
end
|
33
35
|
if volume_id
|
@@ -36,37 +38,22 @@ module Fog
|
|
36
38
|
snapshots
|
37
39
|
end
|
38
40
|
|
39
|
-
def create(attributes = {})
|
40
|
-
snapshot = new(attributes)
|
41
|
-
snapshot.save
|
42
|
-
snapshot
|
43
|
-
end
|
44
|
-
|
45
41
|
def get(snapshot_id)
|
46
42
|
if snapshot_id
|
47
43
|
all(snapshot_id).first
|
48
44
|
end
|
49
|
-
rescue
|
45
|
+
rescue Excon::Errors::BadRequest
|
50
46
|
nil
|
51
47
|
end
|
52
48
|
|
53
49
|
def new(attributes = {})
|
54
|
-
snapshot =
|
55
|
-
attributes.merge!(
|
56
|
-
:connection => connection,
|
57
|
-
:snapshots => self
|
58
|
-
)
|
59
|
-
)
|
50
|
+
snapshot = super(attributes)
|
60
51
|
if volume_id
|
61
52
|
snapshot.volume_id = volume_id
|
62
53
|
end
|
63
54
|
snapshot
|
64
55
|
end
|
65
56
|
|
66
|
-
def reload
|
67
|
-
all(snapshot_id)
|
68
|
-
end
|
69
|
-
|
70
57
|
end
|
71
58
|
|
72
59
|
end
|
@@ -4,6 +4,8 @@ module Fog
|
|
4
4
|
|
5
5
|
class Volume < Fog::Model
|
6
6
|
|
7
|
+
identity :volume_id, 'volumeId'
|
8
|
+
|
7
9
|
attribute :attach_time, 'attachTime'
|
8
10
|
attribute :availability_zone, 'availabilityZone'
|
9
11
|
attribute :create_time, 'createTime'
|
@@ -12,7 +14,6 @@ module Fog
|
|
12
14
|
attribute :size
|
13
15
|
attribute :snapshot_id, 'snapshotId'
|
14
16
|
attribute :status
|
15
|
-
attribute :volume_id, 'volumeId'
|
16
17
|
|
17
18
|
def initialize(attributes = {})
|
18
19
|
if attributes['attachmentSet']
|
@@ -27,21 +28,10 @@ module Fog
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def instance=(new_instance)
|
30
|
-
if
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
elsif new_instance
|
36
|
-
@instance = nil
|
37
|
-
@instance_id = new_instance.instance_id
|
38
|
-
connection.attach_volume(@instance_id, @volume_id, @device)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def reload
|
43
|
-
if new_volume = volumes.get(@volume_id)
|
44
|
-
merge_attributes(new_volume.attributes)
|
31
|
+
if new_instance
|
32
|
+
attach(new_instance)
|
33
|
+
else
|
34
|
+
detach
|
45
35
|
end
|
46
36
|
end
|
47
37
|
|
@@ -59,14 +49,25 @@ module Fog
|
|
59
49
|
connection.snapshots(:volume_id => volume_id)
|
60
50
|
end
|
61
51
|
|
62
|
-
def volumes
|
63
|
-
@volumes
|
64
|
-
end
|
65
|
-
|
66
52
|
private
|
67
53
|
|
68
|
-
def
|
69
|
-
|
54
|
+
def attach(new_instance)
|
55
|
+
if new_record?
|
56
|
+
@instance = new_instance
|
57
|
+
@availability_zone = new_instance.availability_zone
|
58
|
+
elsif new_instance
|
59
|
+
@instance = nil
|
60
|
+
@instance_id = new_instance.instance_id
|
61
|
+
connection.attach_volume(@instance_id, @volume_id, @device)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def detach
|
66
|
+
@instance = nil
|
67
|
+
@instance_id = nil
|
68
|
+
unless new_record?
|
69
|
+
connection.detach_volume(@volume_id)
|
70
|
+
end
|
70
71
|
end
|
71
72
|
|
72
73
|
end
|
@@ -13,12 +13,14 @@ module Fog
|
|
13
13
|
attribute :volume_id
|
14
14
|
attribute :instance
|
15
15
|
|
16
|
+
model Fog::AWS::EC2::Volume
|
17
|
+
|
16
18
|
def initialize(attributes)
|
17
19
|
@volume_id ||= []
|
18
20
|
super
|
19
21
|
end
|
20
22
|
|
21
|
-
def all(volume_id =
|
23
|
+
def all(volume_id = @volume_id)
|
22
24
|
data = connection.describe_volumes(volume_id).body
|
23
25
|
volumes = Fog::AWS::EC2::Volumes.new({
|
24
26
|
:connection => connection,
|
@@ -26,42 +28,26 @@ module Fog
|
|
26
28
|
}.merge!(attributes))
|
27
29
|
data['volumeSet'].each do |volume|
|
28
30
|
volumes << Fog::AWS::EC2::Volume.new({
|
29
|
-
:
|
30
|
-
:
|
31
|
+
:collection => volumes,
|
32
|
+
:connection => connection
|
31
33
|
}.merge!(volume))
|
32
34
|
end
|
33
35
|
if instance
|
34
|
-
volumes = volumes.select {|volume| volume.instance_id == instance.
|
36
|
+
volumes = volumes.select {|volume| volume.instance_id == instance.instance_id}
|
35
37
|
end
|
36
38
|
volumes
|
37
39
|
end
|
38
40
|
|
39
|
-
def create(attributes = {})
|
40
|
-
volume = new(attributes)
|
41
|
-
volume.save
|
42
|
-
volume
|
43
|
-
end
|
44
|
-
|
45
41
|
def get(volume_id)
|
46
42
|
if volume_id
|
47
43
|
all(volume_id).first
|
48
44
|
end
|
49
|
-
rescue
|
45
|
+
rescue Excon::Errors::BadRequest
|
50
46
|
nil
|
51
47
|
end
|
52
48
|
|
53
49
|
def new(attributes = {})
|
54
|
-
|
55
|
-
attributes.merge!(
|
56
|
-
:connection => connection,
|
57
|
-
:instance => instance,
|
58
|
-
:volumes => self
|
59
|
-
)
|
60
|
-
)
|
61
|
-
end
|
62
|
-
|
63
|
-
def reload
|
64
|
-
all(volume_id)
|
50
|
+
super({ :instance => instance }.merge!(attributes))
|
65
51
|
end
|
66
52
|
|
67
53
|
end
|