fog 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.25
1
+ 0.0.26
data/fog.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fog}
8
- s.version = "0.0.25"
8
+ s.version = "0.0.26"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["geemus (Wesley Beary)"]
12
- s.date = %q{2009-10-22}
12
+ s.date = %q{2009-10-23}
13
13
  s.default_executable = %q{fog}
14
14
  s.description = %q{brings clouds to you}
15
15
  s.email = %q{me@geemus.com}
@@ -34,8 +34,9 @@ module Fog
34
34
  end
35
35
 
36
36
  def reload
37
- new_attributes = addresses.get(@public_ip).attributes
38
- merge_attributes(new_attributes)
37
+ if new_address = addresses.get(@public_ip)
38
+ merge_attributes(new_address.attributes)
39
+ end
39
40
  end
40
41
 
41
42
  def save
@@ -43,7 +43,9 @@ module Fog
43
43
  end
44
44
 
45
45
  def get(public_ip)
46
- all(public_ip).first
46
+ if public_ip
47
+ all(public_ip).first
48
+ end
47
49
  rescue Fog::Errors::BadRequest
48
50
  nil
49
51
  end
@@ -68,8 +68,9 @@ module Fog
68
68
  end
69
69
 
70
70
  def reload
71
- new_attributes = instances.all(@instance_id).first.attributes
72
- merge_attributes(new_attributes)
71
+ if new_instance = instances.get(@instance_id)
72
+ merge_attributes(new_instance.attributes)
73
+ end
73
74
  end
74
75
 
75
76
  def save
@@ -110,7 +111,11 @@ module Fog
110
111
  private
111
112
 
112
113
  def instance_state=(new_instance_state)
113
- @instance_state = new_instance_state['name']
114
+ if new_instance_state.is_a?(Hash)
115
+ @instance_state = new_instance_state['name']
116
+ else
117
+ @instance_state = new_instance_state
118
+ end
114
119
  end
115
120
 
116
121
  def instances=(new_instances)
@@ -39,7 +39,9 @@ module Fog
39
39
  end
40
40
 
41
41
  def get(instance_id)
42
- all(instance_id).first
42
+ if instance_id
43
+ all(instance_id).first
44
+ end
43
45
  rescue Fog::Errors::BadRequest
44
46
  nil
45
47
  end
@@ -18,8 +18,9 @@ module Fog
18
18
  end
19
19
 
20
20
  def reload
21
- new_attributes = key_pairs.all(@name).first.attributes
22
- merge_attributes(new_attributes)
21
+ if new_key_pair = key_pairs.get(@name)
22
+ merge_attributes(new_key_pair.attributes)
23
+ end
23
24
  end
24
25
 
25
26
  def save
@@ -37,7 +37,9 @@ module Fog
37
37
  end
38
38
 
39
39
  def get(key_name)
40
- all(key_name).first
40
+ if key_name
41
+ all(key_name).first
42
+ end
41
43
  rescue Fog::Errors::BadRequest
42
44
  nil
43
45
  end
@@ -15,8 +15,9 @@ module Fog
15
15
  end
16
16
 
17
17
  def reload
18
- new_attributes = security_groups.get(@group_name).attributes
19
- merge_attributes(new_attributes)
18
+ if new_security_group = security_groups.get(@group_name)
19
+ merge_attributes(new_security_group.attributes)
20
+ end
20
21
  end
21
22
 
22
23
  def save
@@ -37,7 +37,9 @@ module Fog
37
37
  end
38
38
 
39
39
  def get(group_name)
40
- all(group_name).first
40
+ if group_name
41
+ all(group_name).first
42
+ end
41
43
  rescue Fog::Errors::BadRequest
42
44
  nil
43
45
  end
@@ -16,8 +16,9 @@ module Fog
16
16
  end
17
17
 
18
18
  def reload
19
- new_attributes = snapshots.get(@snapshot_id).attributes
20
- merge_attributes(new_attributes)
19
+ if new_snapshot = snapshots.get(@snapshot_id)
20
+ merge_attributes(new_snapshot.attributes)
21
+ end
21
22
  end
22
23
 
23
24
  def save
@@ -43,7 +43,9 @@ module Fog
43
43
  end
44
44
 
45
45
  def get(snapshot_id)
46
- all(snapshot_id).first
46
+ if snapshot_id
47
+ all(snapshot_id).first
48
+ end
47
49
  rescue Fog::Errors::BadRequest
48
50
  nil
49
51
  end
@@ -29,6 +29,9 @@ module Fog
29
29
  def instance=(new_instance)
30
30
  if !@volume_id
31
31
  @instance = new_instance
32
+ if new_instance
33
+ @availability_zone = new_instance.availability_zone
34
+ end
32
35
  elsif new_instance
33
36
  @instance = nil
34
37
  @instance_id = new_instance.instance_id
@@ -37,8 +40,9 @@ module Fog
37
40
  end
38
41
 
39
42
  def reload
40
- new_attributes = volumes.get(@volume_id).attributes
41
- merge_attributes(new_attributes)
43
+ if new_volume = volumes.get(@volume_id)
44
+ merge_attributes(new_volume.attributes)
45
+ end
42
46
  end
43
47
 
44
48
  def save
@@ -43,7 +43,9 @@ module Fog
43
43
  end
44
44
 
45
45
  def get(volume_id)
46
- all(volume_id).first
46
+ if volume_id
47
+ all(volume_id).first
48
+ end
47
49
  rescue Fog::Errors::BadRequest
48
50
  nil
49
51
  end
@@ -4,14 +4,11 @@ module Fog
4
4
 
5
5
  class Bucket < Fog::Model
6
6
 
7
+ identity :name, 'Name'
8
+
7
9
  attribute :creation_date, 'CreationDate'
8
- attribute :name, 'Name'
9
10
  attribute :owner
10
11
 
11
- def buckets
12
- @buckets
13
- end
14
-
15
12
  def destroy
16
13
  connection.delete_bucket(@name)
17
14
  true
@@ -24,6 +21,10 @@ module Fog
24
21
  data.body['LocationConstraint']
25
22
  end
26
23
 
24
+ def location=(new_location)
25
+ @location = new_location
26
+ end
27
+
27
28
  def objects
28
29
  @objects ||= begin
29
30
  Fog::AWS::S3::Objects.new(
@@ -43,11 +44,6 @@ module Fog
43
44
  @payer = new_payer
44
45
  end
45
46
 
46
- def reload
47
- new_attributes = buckets.get(@name).attributes
48
- merge_attributes(new_attributes)
49
- end
50
-
51
47
  def save
52
48
  options = {}
53
49
  if @location
@@ -57,12 +53,6 @@ module Fog
57
53
  true
58
54
  end
59
55
 
60
- private
61
-
62
- def buckets=(new_buckets)
63
- @buckets = new_buckets
64
- end
65
-
66
56
  end
67
57
 
68
58
  end
@@ -14,7 +14,7 @@ module Fog
14
14
  buckets = Fog::AWS::S3::Buckets.new(:connection => connection)
15
15
  data['Buckets'].each do |bucket|
16
16
  buckets << Fog::AWS::S3::Bucket.new({
17
- :buckets => buckets,
17
+ :collection => buckets,
18
18
  :connection => connection,
19
19
  :owner => owner
20
20
  }.merge!(bucket))
@@ -34,7 +34,7 @@ module Fog
34
34
  })
35
35
  data = connection.get_bucket(name, options).body
36
36
  bucket = Fog::AWS::S3::Bucket.new({
37
- :buckets => self,
37
+ :collection => self,
38
38
  :connection => connection,
39
39
  :name => data['Name']
40
40
  })
@@ -50,7 +50,7 @@ module Fog
50
50
  bucket.objects << Fog::AWS::S3::Object.new({
51
51
  :bucket => bucket,
52
52
  :connection => connection,
53
- :objects => self,
53
+ :collection => bucket.objects,
54
54
  :owner => owner
55
55
  }.merge!(object))
56
56
  end
@@ -62,8 +62,8 @@ module Fog
62
62
  def new(attributes = {})
63
63
  Fog::AWS::S3::Bucket.new(
64
64
  attributes.merge!(
65
- :connection => connection,
66
- :buckets => self
65
+ :collection => self,
66
+ :connection => connection
67
67
  )
68
68
  )
69
69
  end
@@ -4,11 +4,12 @@ module Fog
4
4
 
5
5
  class Object < Fog::Model
6
6
 
7
+ identity :key, 'Key'
8
+
7
9
  attribute :body
8
10
  attribute :content_length, 'Content-Length'
9
11
  attribute :content_type, 'Content-Type'
10
12
  attribute :etag, ['Etag', 'ETag']
11
- attribute :key, 'Key'
12
13
  attribute :last_modified, ['Last-Modified', 'LastModified']
13
14
  attribute :owner
14
15
  attribute :size, 'Size'
@@ -37,15 +38,6 @@ module Fog
37
38
  true
38
39
  end
39
40
 
40
- def objects
41
- @objects
42
- end
43
-
44
- def reload
45
- new_attributes = objects.get(@key).attributes
46
- merge_attributes(new_attributes)
47
- end
48
-
49
41
  def save(options = {})
50
42
  data = connection.put_object(bucket.name, @key, @body, options)
51
43
  @etag = data.headers['ETag']
@@ -58,10 +50,6 @@ module Fog
58
50
  @bucket = new_bucket
59
51
  end
60
52
 
61
- def objects=(new_objects)
62
- @objects = new_objects
63
- end
64
-
65
53
  end
66
54
 
67
55
  end
@@ -11,7 +11,7 @@ module Fog
11
11
  attribute :prefix, 'Prefix'
12
12
 
13
13
  def all(options = {})
14
- bucket.buckets.get(
14
+ bucket.collection.get(
15
15
  bucket.name,
16
16
  options.reject {|key, value| !['delimiter', 'marker', 'max-keys', 'prefix'].include?(key)}
17
17
  ).objects
@@ -40,8 +40,8 @@ module Fog
40
40
  end
41
41
  object = Fog::AWS::S3::Object.new({
42
42
  :bucket => bucket,
43
- :connection => connection,
44
- :objects => self
43
+ :collection => self,
44
+ :connection => connection
45
45
  }.merge!(object_data))
46
46
  object
47
47
  rescue Fog::Errors::NotFound
@@ -64,8 +64,8 @@ module Fog
64
64
  end
65
65
  object = Fog::AWS::S3::Object.new({
66
66
  :bucket => bucket,
67
- :connection => connection,
68
- :objects => self
67
+ :collection => self,
68
+ :connection => connection
69
69
  }.merge!(object_data))
70
70
  object
71
71
  rescue Fog::Errors::NotFound
@@ -75,8 +75,8 @@ module Fog
75
75
  def new(attributes = {})
76
76
  Fog::AWS::S3::Object.new({
77
77
  :bucket => bucket,
78
- :connection => connection,
79
- :objects => self
78
+ :collection => self,
79
+ :connection => connection
80
80
  }.merge!(attributes))
81
81
  end
82
82
 
@@ -41,25 +41,39 @@ else
41
41
 
42
42
  def attach_volume(instance_id, volume_id, device)
43
43
  response = Fog::Response.new
44
- response.status = 200
45
- instance = Fog::AWS::EC2.data[:instances][instance_id]
46
- volume = Fog::AWS::EC2.data[:volumes][volume_id]
47
- if instance && volume
48
- data = {
49
- 'attachTime' => Time.now,
50
- 'device' => device,
51
- 'instanceId' => instance_id,
52
- 'status' => 'attaching',
53
- 'volumeId' => volume_id
54
- }
55
- volume['attachmentSet'] << data
44
+ if instance_id && volume_id && device
56
45
  response.status = 200
57
- response.body = {
58
- 'requestId' => Fog::AWS::Mock.request_id
59
- }.merge!(data)
46
+ instance = Fog::AWS::EC2.data[:instances][instance_id]
47
+ volume = Fog::AWS::EC2.data[:volumes][volume_id]
48
+ if instance && volume
49
+ data = {
50
+ 'attachTime' => Time.now,
51
+ 'device' => device,
52
+ 'instanceId' => instance_id,
53
+ 'status' => 'attaching',
54
+ 'volumeId' => volume_id
55
+ }
56
+ volume['attachmentSet'] << data
57
+ response.status = 200
58
+ response.body = {
59
+ 'requestId' => Fog::AWS::Mock.request_id
60
+ }.merge!(data)
61
+ else
62
+ response.status = 400
63
+ raise(Fog::Errors.status_error(200, 400, response))
64
+ end
60
65
  else
61
66
  response.status = 400
62
- raise(Fog::Errors.status_error(200, 400, response))
67
+ response.body = {
68
+ 'Code' => 'MissingParameter'
69
+ }
70
+ if !instance_id
71
+ response['Message'] = 'The request must contain the parameter instance_id'
72
+ elsif !volume_id
73
+ response['Message'] = 'The request must contain the parameter volume_id'
74
+ else
75
+ response['Message'] = 'The request must contain the parameter device'
76
+ end
63
77
  end
64
78
  response
65
79
  end
@@ -41,21 +41,33 @@ else
41
41
 
42
42
  def create_volume(availability_zone, size, snapshot_id = nil)
43
43
  response = Fog::Response.new
44
- response.status = 200
45
- volume_id = Fog::AWS::Mock.volume_id
46
- data = {
47
- 'availabilityZone' => availability_zone,
48
- 'attachmentSet' => [],
49
- 'createTime' => Time.now,
50
- 'size' => size,
51
- 'snapshotId' => snapshot_id || '',
52
- 'status' => 'creating',
53
- 'volumeId' => volume_id
54
- }
55
- Fog::AWS::EC2.data[:volumes][volume_id] = data
56
- response.body = {
57
- 'requestId' => Fog::AWS::Mock.request_id
58
- }.merge!(data.reject {|key,value| !['availabilityZone','createTime','size','snapshotId','status','volumeId'].include?(key) })
44
+ if availability_zone && size
45
+ response.status = 200
46
+ volume_id = Fog::AWS::Mock.volume_id
47
+ data = {
48
+ 'availabilityZone' => availability_zone,
49
+ 'attachmentSet' => [],
50
+ 'createTime' => Time.now,
51
+ 'size' => size,
52
+ 'snapshotId' => snapshot_id || '',
53
+ 'status' => 'creating',
54
+ 'volumeId' => volume_id
55
+ }
56
+ Fog::AWS::EC2.data[:volumes][volume_id] = data
57
+ response.body = {
58
+ 'requestId' => Fog::AWS::Mock.request_id
59
+ }.merge!(data.reject {|key,value| !['availabilityZone','createTime','size','snapshotId','status','volumeId'].include?(key) })
60
+ else
61
+ response.status = 400
62
+ response.body = {
63
+ 'Code' => 'MissingParameter'
64
+ }
65
+ unless availability_zone
66
+ response['Message'] = 'The request must contain the parameter availability_zone'
67
+ else
68
+ response['Message'] = 'The request must contain the parameter size'
69
+ end
70
+ end
59
71
  response
60
72
  end
61
73
 
@@ -79,7 +79,7 @@ unless Fog.mocking?
79
79
  response.headers[capitalize(header[0])] = header[1]
80
80
  end
81
81
 
82
- unless params[:method] == 'HEAD'
82
+ unless params[:method] == 'HEAD' || [204, 304, *(100..199)].include?(response.status)
83
83
  if (error && params[:error_parser]) || params[:parser]
84
84
  if error
85
85
  parser = params[:error_parser]
@@ -105,18 +105,22 @@ unless Fog.mocking?
105
105
  end
106
106
  elsif response.headers['Transfer-Encoding'] == 'chunked'
107
107
  while true
108
+ chunk_size = connection.readline.chomp!.to_i(16)
108
109
  # 2 == "/r/n".length
109
- chunk_size = connection.readline.chomp!.to_i(16) + 2
110
- chunk = connection.read(chunk_size)[0...-2]
111
- if error || !params[:block]
112
- body << chunk
113
- else
114
- params[:block].call(chunk)
115
- end
116
- if chunk_size == 2
110
+ chunk = connection.read(chunk_size + 2)[0...-2]
111
+ if chunk_size == 0
117
112
  break
113
+ else
114
+ if error || !params[:block]
115
+ body << chunk
116
+ else
117
+ params[:block].call(chunk)
118
+ end
118
119
  end
119
120
  end
121
+ elsif response.headers['Connection'] == 'close'
122
+ body << connection.read
123
+ @connection = nil
120
124
  end
121
125
 
122
126
  if parser
data/lib/fog/model.rb CHANGED
@@ -11,6 +11,11 @@ module Fog
11
11
  end
12
12
  end
13
13
 
14
+ def self.identity(name, other_names = [])
15
+ @identity = name
16
+ self.attribute(name, other_names)
17
+ end
18
+
14
19
  def self.aliases
15
20
  @aliases ||= {}
16
21
  end
@@ -19,6 +24,10 @@ module Fog
19
24
  @attributes ||= []
20
25
  end
21
26
 
27
+ def identity
28
+ send(self.class.instance_variable_get('@identity'))
29
+ end
30
+
22
31
  def initialize(new_attributes = {})
23
32
  merge_attributes(new_attributes)
24
33
  end
@@ -39,6 +48,10 @@ module Fog
39
48
  attributes
40
49
  end
41
50
 
51
+ def collection
52
+ @collection
53
+ end
54
+
42
55
  def merge_attributes(new_attributes = {})
43
56
  for key, value in new_attributes
44
57
  if aliased_key = self.class.aliases[key]
@@ -50,8 +63,17 @@ module Fog
50
63
  self
51
64
  end
52
65
 
66
+ def reload
67
+ new_attributes = collection.get(identity).attributes
68
+ merge_attributes(new_attributes)
69
+ end
70
+
53
71
  private
54
72
 
73
+ def collection=(new_collection)
74
+ @collection = new_collection
75
+ end
76
+
55
77
  def connection=(new_connection)
56
78
  @connection = new_connection
57
79
  end
@@ -39,7 +39,7 @@ describe 'Fog::AWS::EC2::Volume' do
39
39
  describe "#destroy" do
40
40
 
41
41
  it "should return true if the volume is deleted" do
42
- volume = ec2.volumes.create
42
+ volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
43
43
  volume.destroy.should be_true
44
44
  end
45
45
 
@@ -47,39 +47,56 @@ describe 'Fog::AWS::EC2::Volume' do
47
47
 
48
48
  describe "#instance=" do
49
49
  before(:each) do
50
- @volume = ec2.volumes.new
51
50
  @instance = ec2.instances.create(:image_id => GENTOO_AMI)
51
+ @volume = ec2.volumes.new(:availability_zone => @instance.availability_zone, :size => 1, :device => 'dev/sdz1')
52
+ while @instance.instance_state == 'pending'
53
+ @instance.reload
54
+ end
55
+ while @volume.status == 'creating'
56
+ @volume.reload
57
+ end
52
58
  end
53
59
 
54
60
  after(:each) do
61
+ @instance.destroy
55
62
  if @volume.volume_id
56
63
  @volume.destroy
57
64
  end
58
- @instance.destroy
59
65
  end
60
66
 
61
- it "should not attach to instance if the address has not been saved" do
67
+ it "should not attach to instance if the volume has not been saved" do
62
68
  @volume.instance = @instance
63
69
  @volume.instance_id.should_not == @instance.instance_id
64
70
  end
65
71
 
66
- it "should attach to instance when the address is saved" do
72
+ it "should change the availability_zone if the volume has not been saved" do
73
+ @volume.instance = @instance
74
+ @volume.availability_zone.should == @instance.availability_zone
75
+ end
76
+
77
+ it "should attach to instance when the volume is saved" do
67
78
  @volume.instance = @instance
68
79
  @volume.save.should be_true
69
80
  @volume.instance_id.should == @instance.instance_id
70
81
  end
71
82
 
72
- it "should attach to instance to an already saved address" do
83
+ it "should attach to instance to an already saved volume" do
73
84
  @volume.save.should be_true
74
85
  @volume.instance = @instance
75
86
  @volume.instance_id.should == @instance.instance_id
76
87
  end
88
+
89
+ it "should not change the availability_zone if the volume has been saved" do
90
+ @volume.save.should be_true
91
+ @volume.instance = @instance
92
+ @volume.availability_zone.should == @instance.availability_zone
93
+ end
77
94
  end
78
95
 
79
96
  describe "#reload" do
80
97
 
81
98
  before(:each) do
82
- @volume = ec2.volumes.create
99
+ @volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
83
100
  @reloaded = @volume.reload
84
101
  end
85
102
 
@@ -100,7 +117,7 @@ describe 'Fog::AWS::EC2::Volume' do
100
117
  describe "#save" do
101
118
 
102
119
  before(:each) do
103
- @volume = ec2.volumes.new
120
+ @volume = ec2.volumes.new(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
104
121
  end
105
122
 
106
123
  it "should return true when it succeeds" do
@@ -108,7 +125,7 @@ describe 'Fog::AWS::EC2::Volume' do
108
125
  @volume.destroy
109
126
  end
110
127
 
111
- it "should not exist in addresses before save" do
128
+ it "should not exist in volumes before save" do
112
129
  @volume.volumes.get(@volume.volume_id).should be_nil
113
130
  end
114
131
 
@@ -16,15 +16,15 @@ describe 'Fog::AWS::S3::Bucket' do
16
16
 
17
17
  end
18
18
 
19
- describe "#buckets" do
19
+ describe "#collection" do
20
20
 
21
21
  it "should return a Fog::AWS::S3::Buckets" do
22
- s3.buckets.new.buckets.should be_a(Fog::AWS::S3::Buckets)
22
+ s3.buckets.new.collection.should be_a(Fog::AWS::S3::Buckets)
23
23
  end
24
24
 
25
25
  it "should be the buckets the bucket is related to" do
26
26
  buckets = s3.buckets
27
- buckets.new.buckets.should == buckets
27
+ buckets.new.collection.should == buckets
28
28
  end
29
29
 
30
30
  end
@@ -115,12 +115,12 @@ describe 'Fog::AWS::S3::Bucket' do
115
115
  end
116
116
 
117
117
  it "should not exist in buckets before save" do
118
- @bucket.buckets.all.map {|bucket| bucket.name}.include?(@bucket.name).should be_false
118
+ s3.buckets.all.map {|bucket| bucket.name}.include?(@bucket.name).should be_false
119
119
  end
120
120
 
121
121
  it "should exist in buckets after save" do
122
122
  @bucket.save
123
- @bucket.buckets.all.map {|bucket| bucket.name}.include?(@bucket.name).should be_true
123
+ s3.buckets.all.map {|bucket| bucket.name}.include?(@bucket.name).should be_true
124
124
  @bucket.destroy
125
125
  end
126
126
 
data/spec/spec_helper.rb CHANGED
@@ -80,4 +80,6 @@ def eventually(max_delay = 16, &block)
80
80
  end
81
81
  end
82
82
 
83
- GENTOO_AMI = 'ami-5ee70037'
83
+ unless defined?(GENTOO_AMI)
84
+ GENTOO_AMI = 'ami-5ee70037'
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus (Wesley Beary)
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-22 00:00:00 -07:00
12
+ date: 2009-10-23 00:00:00 -07:00
13
13
  default_executable: fog
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency