fog 0.0.39 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/README.rdoc +88 -31
  2. data/Rakefile +25 -2
  3. data/VERSION +1 -1
  4. data/bin/fog +57 -43
  5. data/fog.gemspec +52 -23
  6. data/lib/fog.rb +7 -4
  7. data/lib/fog/aws/ec2.rb +6 -2
  8. data/lib/fog/aws/models/ec2/address.rb +13 -13
  9. data/lib/fog/aws/models/ec2/addresses.rb +5 -5
  10. data/lib/fog/aws/models/ec2/flavor.rb +19 -0
  11. data/lib/fog/aws/models/ec2/flavors.rb +43 -0
  12. data/lib/fog/aws/models/ec2/image.rb +24 -0
  13. data/lib/fog/aws/models/ec2/images.rb +44 -0
  14. data/lib/fog/aws/models/ec2/{instance.rb → server.rb} +22 -10
  15. data/lib/fog/aws/models/ec2/{instances.rb → servers.rb} +12 -12
  16. data/lib/fog/aws/models/ec2/snapshot.rb +2 -2
  17. data/lib/fog/aws/models/ec2/volume.rb +17 -17
  18. data/lib/fog/aws/models/ec2/volumes.rb +5 -5
  19. data/lib/fog/aws/models/s3/{buckets.rb → directories.rb} +16 -13
  20. data/lib/fog/aws/models/s3/{bucket.rb → directory.rb} +5 -10
  21. data/lib/fog/aws/models/s3/{object.rb → file.rb} +16 -18
  22. data/lib/fog/aws/models/s3/{objects.rb → files.rb} +19 -19
  23. data/lib/fog/aws/requests/ec2/run_instances.rb +1 -1
  24. data/lib/fog/aws/s3.rb +6 -6
  25. data/lib/fog/rackspace/files.rb +6 -3
  26. data/lib/fog/rackspace/models/servers/flavor.rb +26 -1
  27. data/lib/fog/rackspace/models/servers/image.rb +3 -3
  28. data/lib/fog/rackspace/models/servers/server.rb +20 -9
  29. data/lib/fog/rackspace/models/servers/servers.rb +3 -1
  30. data/lib/fog/rackspace/servers.rb +2 -1
  31. data/spec/aws/models/ec2/address_spec.rb +8 -8
  32. data/spec/aws/models/ec2/server_spec.rb +109 -0
  33. data/spec/aws/models/ec2/servers_spec.rb +52 -0
  34. data/spec/aws/models/ec2/snapshot_spec.rb +2 -1
  35. data/spec/aws/models/ec2/volume_spec.rb +22 -22
  36. data/spec/aws/models/s3/directories_spec.rb +49 -0
  37. data/spec/aws/models/s3/directory_spec.rb +112 -0
  38. data/spec/aws/models/s3/file_spec.rb +106 -0
  39. data/spec/aws/models/s3/files_spec.rb +116 -0
  40. data/spec/rackspace/models/servers/server_spec.rb +51 -0
  41. data/spec/shared_examples/server_examples.rb +42 -0
  42. data/spec/spec_helper.rb +1 -1
  43. metadata +51 -22
  44. data/spec/aws/models/ec2/instance_spec.rb +0 -161
  45. data/spec/aws/models/ec2/instances_spec.rb +0 -70
  46. data/spec/aws/models/s3/bucket_spec.rb +0 -129
  47. data/spec/aws/models/s3/buckets_spec.rb +0 -70
  48. data/spec/aws/models/s3/object_spec.rb +0 -121
  49. data/spec/aws/models/s3/objects_spec.rb +0 -141
data/lib/fog.rb CHANGED
@@ -40,11 +40,14 @@ module Fog
40
40
 
41
41
  def self.credentials(key = :default)
42
42
  @credentials ||= begin
43
- credentials = {}
44
- File.open(File.expand_path('~/.fog')) do |file|
45
- credentials = YAML.load(file.read)[key]
43
+ path = File.expand_path('~/.fog')
44
+ if File.exists?(path)
45
+ File.open(path) do |file|
46
+ YAML.load(file.read)[key]
47
+ end
48
+ else
49
+ nil
46
50
  end
47
- credentials
48
51
  end
49
52
  end
50
53
 
@@ -22,12 +22,16 @@ module Fog
22
22
  def self.reload
23
23
  load "fog/aws/models/ec2/address.rb"
24
24
  load "fog/aws/models/ec2/addresses.rb"
25
- load "fog/aws/models/ec2/instance.rb"
26
- load "fog/aws/models/ec2/instances.rb"
25
+ load "fog/aws/models/ec2/flavor.rb"
26
+ load "fog/aws/models/ec2/flavors.rb"
27
+ load "fog/aws/models/ec2/image.rb"
28
+ load "fog/aws/models/ec2/images.rb"
27
29
  load "fog/aws/models/ec2/key_pair.rb"
28
30
  load "fog/aws/models/ec2/key_pairs.rb"
29
31
  load "fog/aws/models/ec2/security_group.rb"
30
32
  load "fog/aws/models/ec2/security_groups.rb"
33
+ load "fog/aws/models/ec2/server.rb"
34
+ load "fog/aws/models/ec2/servers.rb"
31
35
  load "fog/aws/models/ec2/snapshot.rb"
32
36
  load "fog/aws/models/ec2/snapshots.rb"
33
37
  load "fog/aws/models/ec2/volume.rb"
@@ -6,7 +6,7 @@ module Fog
6
6
 
7
7
  identity :public_ip, 'publicIp'
8
8
 
9
- attribute :instance_id, 'instanceId'
9
+ attribute :server_id, 'instanceId'
10
10
 
11
11
  def destroy
12
12
  requires :public_ip
@@ -15,9 +15,9 @@ module Fog
15
15
  true
16
16
  end
17
17
 
18
- def instance=(new_instance)
19
- if new_instance
20
- associate(new_instance)
18
+ def server=(new_server)
19
+ if new_server
20
+ associate(new_server)
21
21
  else
22
22
  disassociate
23
23
  end
@@ -26,27 +26,27 @@ module Fog
26
26
  def save
27
27
  data = connection.allocate_address
28
28
  @public_ip = data.body['publicIp']
29
- if @instance
30
- self.instance = @instance
29
+ if @server
30
+ self.server = @server
31
31
  end
32
32
  true
33
33
  end
34
34
 
35
35
  private
36
36
 
37
- def associate(new_instance)
37
+ def associate(new_server)
38
38
  if new_record?
39
- @instance = new_instance
39
+ @server = new_server
40
40
  else
41
- @instance = nil
42
- @instance_id = new_instance.id
43
- connection.associate_address(@instance_id, @public_ip)
41
+ @server = nil
42
+ @server_id = new_server.id
43
+ connection.associate_address(@server_id, @public_ip)
44
44
  end
45
45
  end
46
46
 
47
47
  def disassociate
48
- @instance = nil
49
- @instance_id = nil
48
+ @server = nil
49
+ @server_id = nil
50
50
  unless new_record?
51
51
  connection.disassociate_address(@public_ip)
52
52
  end
@@ -11,7 +11,7 @@ module Fog
11
11
  class Addresses < Fog::Collection
12
12
 
13
13
  attribute :public_ip
14
- attribute :instance
14
+ attribute :server
15
15
 
16
16
  model Fog::AWS::EC2::Address
17
17
 
@@ -31,8 +31,8 @@ module Fog
31
31
  data['addressesSet'].each do |address|
32
32
  addresses << new(address.reject {|key, value| value.nil? || value.empty? })
33
33
  end
34
- if instance
35
- addresses = addresses.select {|address| address.instance_id == instance.id}
34
+ if server
35
+ addresses = addresses.select {|address| address.instance_id == server.id}
36
36
  end
37
37
  self.replace(addresses)
38
38
  end
@@ -46,8 +46,8 @@ module Fog
46
46
  end
47
47
 
48
48
  def new(attributes = {})
49
- if instance
50
- super({ :instance => instance }.merge!(attributes))
49
+ if server
50
+ super({ :server => server }.merge!(attributes))
51
51
  else
52
52
  super(attributes)
53
53
  end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ class Flavor < Fog::Model
6
+
7
+ identity :id
8
+
9
+ attribute :bits
10
+ attribute :cores
11
+ attribute :disk
12
+ attribute :name
13
+ attribute :ram
14
+
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ def flavors
6
+ Fog::AWS::EC2::Flavors.new(:connection => self)
7
+ end
8
+
9
+ class Flavors < Fog::Collection
10
+
11
+ model Fog::AWS::EC2::Flavor
12
+
13
+ def all
14
+ if @loaded
15
+ clear
16
+ end
17
+ @loaded = true
18
+ data = [
19
+ { :bits => 32, :cores => 1, :disk => 160, :id => 'm1.small', :name => 'Small Instance', :ram => 1740.8},
20
+ { :bits => 64, :cores => 4, :disk => 850, :id => 'm1.large', :name => 'Large Instance', :ram => 7680},
21
+ { :bits => 64, :cores => 8, :disk => 1690, :id => 'm1.xlarge', :name => 'Extra Large Instance', :ram => 15360},
22
+
23
+ { :bits => 32, :cores => 5, :disk => 350, :id => 'c1.medium', :name => 'High-CPU Medium', :ram => 1740.8},
24
+ { :bits => 64, :cores => 20, :disk => 1690, :id => 'c1.xlarge', :name => 'High-CPU Extra Large', :ram => 7168},
25
+
26
+ { :bits => 64, :cores => 13, :disk => 850, :id => 'm2.2xlarge', :name => 'High Memory Double Extra Large', :ram => 35020.8},
27
+ { :bits => 64, :cores => 26, :disk => 1690, :id => 'm2.4xlarge', :name => 'High Memory Quadruple Extra Large', :ram => 70041.6},
28
+ ]
29
+ for flavor in data
30
+ self << new(flavor)
31
+ end
32
+ self
33
+ end
34
+
35
+ def get(flavor_id)
36
+ all.detect {|flavor| flavor.id = flavor_id}
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,24 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ class Image < Fog::Model
6
+
7
+ identity :id, 'imageId'
8
+
9
+ attribute :architecture
10
+ attribute :location, 'imageLocation'
11
+ attribute :owner_id, 'imageOwnerId'
12
+ attribute :state, 'imageState'
13
+ attribute :type, 'imageType'
14
+ attribute :is_public, 'isPublic'
15
+ attribute :kernel_id, 'kernelId'
16
+ attribute :platform
17
+ attribute :product_codes, 'productCodes'
18
+ attribute :ramdisk_id, 'ramdiskId'
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ def images
6
+ Fog::AWS::EC2::Images.new(:connection => self)
7
+ end
8
+
9
+ class Images < Fog::Collection
10
+
11
+ attribute :image_id
12
+
13
+ model Fog::AWS::EC2::Image
14
+
15
+ def initialize(attributes)
16
+ @image_id ||= []
17
+ super
18
+ end
19
+
20
+ def all(image_id = @image_id)
21
+ @image_id = image_id
22
+ if @loaded
23
+ clear
24
+ end
25
+ @loaded = true
26
+ data = connection.describe_images('ImageId' => image_id).body
27
+ data['imagesSet'].each do |image|
28
+ self << new(image)
29
+ end
30
+ self
31
+ end
32
+
33
+ def get(image_id)
34
+ if image_id
35
+ all(image_id).first
36
+ end
37
+ rescue Excon::Errors::BadRequest
38
+ nil
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -2,7 +2,7 @@ module Fog
2
2
  module AWS
3
3
  class EC2
4
4
 
5
- class Instance < Fog::Model
5
+ class Server < Fog::Model
6
6
 
7
7
  identity :id, 'instanceId'
8
8
 
@@ -12,10 +12,10 @@ module Fog
12
12
  attribute :group_id, 'groupId'
13
13
  attribute :image_id, 'imageId'
14
14
  attribute :state, 'instanceState'
15
- attribute :type, 'instanceType'
15
+ attribute :flavor_id, 'instanceType'
16
16
  attribute :kernel_id, 'kernelId'
17
17
  attribute :key_name, 'keyName'
18
- attribute :launch_time, 'launchTime'
18
+ attribute :created_at, 'launchTime'
19
19
  attribute :monitoring
20
20
  attribute :product_codes, 'productCodes'
21
21
  attribute :private_dns_name, 'privateDnsName'
@@ -26,7 +26,7 @@ module Fog
26
26
  def addresses
27
27
  requires :id
28
28
 
29
- connection.addresses(:instance => self)
29
+ connection.addresses(:server => self)
30
30
  end
31
31
 
32
32
  def destroy
@@ -44,6 +44,18 @@ module Fog
44
44
  # @group_id = new_security_group.name
45
45
  # end
46
46
 
47
+ def flavor_id
48
+ @flavor && @flavor.id || 'm1.small'
49
+ end
50
+
51
+ def flavor=(new_flavor)
52
+ @flavor = new_flavor
53
+ end
54
+
55
+ def flavor
56
+ @flavor || connection.flavors.all.detect {|flavor| flavor.id == @flavor_id}
57
+ end
58
+
47
59
  def key_pair
48
60
  requires :key_name
49
61
 
@@ -70,9 +82,12 @@ module Fog
70
82
  end
71
83
  end
72
84
 
85
+ def ready?
86
+ @state == 'running'
87
+ end
88
+
73
89
  def reboot
74
90
  requires :id
75
-
76
91
  connection.reboot_instances(@id)
77
92
  true
78
93
  end
@@ -80,16 +95,13 @@ module Fog
80
95
  def save
81
96
  requires :image_id
82
97
 
83
- options = {}
98
+ options = {'InstanceType' => flavor}
84
99
  if @availability_zone
85
100
  options['Placement.AvailabilityZone'] = @availability_zone
86
101
  end
87
102
  if @group_id
88
103
  options['SecurityGroup'] = @group_id
89
104
  end
90
- if @type
91
- options['InstanceType'] = @type
92
- end
93
105
  if @kernel_id
94
106
  options['KernelId'] = @kernel_id
95
107
  end
@@ -113,7 +125,7 @@ module Fog
113
125
  def volumes
114
126
  requires :id
115
127
 
116
- connection.volumes(:instance => self)
128
+ connection.volumes(:server => self)
117
129
  end
118
130
 
119
131
  private
@@ -2,28 +2,28 @@ module Fog
2
2
  module AWS
3
3
  class EC2
4
4
 
5
- def instances
6
- Fog::AWS::EC2::Instances.new(:connection => self)
5
+ def servers
6
+ Fog::AWS::EC2::Servers.new(:connection => self)
7
7
  end
8
8
 
9
- class Instances < Fog::Collection
9
+ class Servers < Fog::Collection
10
10
 
11
- attribute :instance_id
11
+ attribute :server_id
12
12
 
13
- model Fog::AWS::EC2::Instance
13
+ model Fog::AWS::EC2::Server
14
14
 
15
15
  def initialize(attributes)
16
- @instance_id ||= []
16
+ @server_id ||= []
17
17
  super
18
18
  end
19
19
 
20
- def all(instance_id = @instance_id)
21
- @instance_id = instance_id
20
+ def all(server_id = @server_id)
21
+ @server_id = server_id
22
22
  if @loaded
23
23
  clear
24
24
  end
25
25
  @loaded = true
26
- data = connection.describe_instances(instance_id).body
26
+ data = connection.describe_instances(server_id).body
27
27
  data['reservationSet'].each do |reservation|
28
28
  reservation['instancesSet'].each do |instance|
29
29
  self << new(instance)
@@ -32,9 +32,9 @@ module Fog
32
32
  self
33
33
  end
34
34
 
35
- def get(instance_id)
36
- if instance_id
37
- all(instance_id).first
35
+ def get(server_id)
36
+ if server_id
37
+ all(server_id).first
38
38
  end
39
39
  rescue Excon::Errors::BadRequest
40
40
  nil
@@ -7,9 +7,9 @@ module Fog
7
7
  identity :id, 'snapshotId'
8
8
 
9
9
  attribute :progress
10
- attribute :start_time, 'startTime'
10
+ attribute :created_at, 'startTime'
11
11
  attribute :status
12
- attribute :volume_id, 'volumeId'
12
+ attribute :volume_id, 'volumeId'
13
13
 
14
14
  def destroy
15
15
  requires :id
@@ -6,11 +6,11 @@ module Fog
6
6
 
7
7
  identity :id, 'volumeId'
8
8
 
9
- attribute :attach_time, 'attachTime'
9
+ attribute :attached_at, 'attachTime'
10
10
  attribute :availability_zone, 'availabilityZone'
11
- attribute :create_time, 'createTime'
11
+ attribute :created_at, 'createTime'
12
12
  attribute :device
13
- attribute :instance_id, 'instanceId'
13
+ attribute :server_id, 'instanceId'
14
14
  attribute :size
15
15
  attribute :snapshot_id, 'snapshotId'
16
16
  attribute :status
@@ -29,9 +29,9 @@ module Fog
29
29
  true
30
30
  end
31
31
 
32
- def instance=(new_instance)
33
- if new_instance
34
- attach(new_instance)
32
+ def server=(new_server)
33
+ if new_server
34
+ attach(new_server)
35
35
  else
36
36
  detach
37
37
  end
@@ -43,8 +43,8 @@ module Fog
43
43
  data = connection.create_volume(@availability_zone, @size, @snapshot_id).body
44
44
  new_attributes = data.reject {|key,value| key == 'requestId'}
45
45
  merge_attributes(new_attributes)
46
- if @instance
47
- self.instance = @instance
46
+ if @server
47
+ self.server = @server
48
48
  end
49
49
  true
50
50
  end
@@ -57,20 +57,20 @@ module Fog
57
57
 
58
58
  private
59
59
 
60
- def attach(new_instance)
60
+ def attach(new_server)
61
61
  if new_record?
62
- @instance = new_instance
63
- @availability_zone = new_instance.availability_zone
64
- elsif new_instance
65
- @instance = nil
66
- @instance_id = new_instance.id
67
- connection.attach_volume(@instance_id, @id, @device)
62
+ @server = new_server
63
+ @availability_zone = new_server.availability_zone
64
+ elsif new_server
65
+ @server = nil
66
+ @server_id = new_server.id
67
+ connection.attach_volume(@server_id, @id, @device)
68
68
  end
69
69
  end
70
70
 
71
71
  def detach
72
- @instance = nil
73
- @instance_id = nil
72
+ @server = nil
73
+ @server_id = nil
74
74
  unless new_record?
75
75
  connection.detach_volume(@id)
76
76
  end