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
@@ -6,33 +6,44 @@ module Fog
6
6
 
7
7
  identity :id
8
8
 
9
- attribute :admin_pass, 'adminPass'
10
- attribute :name
11
- attribute :image_id, 'imageId'
9
+ attribute :addresses
10
+ attribute :password, 'adminPass'
12
11
  attribute :flavor_id, 'flavorId'
13
12
  attribute :host_id, 'hostId'
14
- attribute :status
13
+ attribute :image_id, 'imageId'
14
+ attribute :metadata
15
+ attribute :name
15
16
  attribute :personality
16
17
  attribute :progress
17
- attribute :addresses
18
- attribute :metadata
18
+ attribute :status
19
19
 
20
20
  def destroy
21
21
  requires :id
22
-
23
22
  connection.delete_server(@id)
24
23
  true
25
24
  end
26
25
 
26
+ def flavor
27
+ requires :flavor_id
28
+ connection.flavors.get(@flavor_id)
29
+ end
30
+
31
+ def image
32
+ requires :image_id
33
+ connection.images.get(@image_id)
34
+ end
35
+
27
36
  def images
28
37
  requires :id
29
-
30
38
  connection.images(:server => self)
31
39
  end
32
40
 
41
+ def ready?
42
+ @status == 'ACTIVE'
43
+ end
44
+
33
45
  def reboot(type = 'SOFT')
34
46
  requires :id
35
-
36
47
  connection.reboot_server(@id, type)
37
48
  true
38
49
  end
@@ -23,7 +23,9 @@ module Fog
23
23
  end
24
24
 
25
25
  def get(server_id)
26
- connection.get_server_details(server_id)
26
+ if server = connection.get_server_details(server_id).body['server']
27
+ new(server)
28
+ end
27
29
  rescue Excon::Errors::NotFound
28
30
  nil
29
31
  end
@@ -57,14 +57,15 @@ module Fog
57
57
  @path = uri.path
58
58
  @port = uri.port
59
59
  @scheme = uri.scheme
60
- @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
61
60
  end
62
61
 
63
62
  def request(params)
63
+ @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
64
64
  response = @connection.request({
65
65
  :body => params[:body],
66
66
  :expects => params[:expects],
67
67
  :headers => {
68
+ 'Content-Type' => 'application/json',
68
69
  'X-Auth-Token' => @auth_token
69
70
  }.merge!(params[:headers] || {}),
70
71
  :host => @host,
@@ -9,7 +9,7 @@ describe 'Fog::AWS::EC2::Address' do
9
9
  'instanceId' => 'i-00000000',
10
10
  'publicIp' => '0.0.0.0'
11
11
  )
12
- address.instance_id.should == 'i-00000000'
12
+ address.server_id.should == 'i-00000000'
13
13
  address.public_ip.should == '0.0.0.0'
14
14
  end
15
15
 
@@ -37,24 +37,24 @@ describe 'Fog::AWS::EC2::Address' do
37
37
 
38
38
  end
39
39
 
40
- describe "#instance=" do
40
+ describe "#server=" do
41
41
  before(:each) do
42
42
  @address = ec2.addresses.new
43
- @instance = ec2.instances.create(:image_id => GENTOO_AMI)
43
+ @server = ec2.servers.create(:image_id => GENTOO_AMI)
44
44
  end
45
45
 
46
46
  after(:each) do
47
47
  if @address.public_ip
48
48
  @address.destroy
49
49
  end
50
- @instance.destroy
50
+ @server.destroy
51
51
  end
52
52
 
53
- it "should associate with instance to an already saved address" do
53
+ it "should associate with server to an already saved address" do
54
54
  @address.save.should be_true
55
- @instance.wait_for { state == 'running' }
56
- @address.instance = @instance
57
- @address.instance_id.should == @instance.id
55
+ @server.wait_for { state == 'running' }
56
+ @address.server = @server
57
+ @address.server_id.should == @server.id
58
58
  end
59
59
  end
60
60
 
@@ -0,0 +1,109 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../../shared_examples/server_examples'
3
+
4
+ describe 'Fog::AWS::EC2::Server' do
5
+
6
+ it_should_behave_like "Server"
7
+
8
+ subject { @server = @servers.new(:image_id => GENTOO_AMI) }
9
+
10
+ before(:each) do
11
+ @servers = ec2.servers
12
+ end
13
+
14
+ after(:each) do
15
+ if @server && !@server.new_record?
16
+ @server.wait_for { ready? }
17
+ @server.destroy.should be_true
18
+ end
19
+ end
20
+
21
+ describe "#initialize" do
22
+
23
+ it "should remap attributes from parser" do
24
+ server = @servers.new({
25
+ 'amiLaunchIndex' => 'ami_launch_index',
26
+ 'dnsName' => 'dns_name',
27
+ 'groupId' => 'group_id',
28
+ 'imageId' => 'image_id',
29
+ 'instanceId' => 'instance_id',
30
+ 'instanceType' => 'instance_type',
31
+ 'kernelId' => 'kernel_id',
32
+ 'keyName' => 'key_name',
33
+ 'launchTime' => 'launch_time',
34
+ 'productCodes' => 'product_codes',
35
+ 'privateDnsName' => 'private_dns_name',
36
+ 'ramdiskId' => 'ramdisk_id'
37
+ })
38
+ server.ami_launch_index.should == 'ami_launch_index'
39
+ server.dns_name.should == 'dns_name'
40
+ server.group_id.should == 'group_id'
41
+ server.image_id.should == 'image_id'
42
+ server.id.should == 'instance_id'
43
+ server.flavor.should == 'instance_type'
44
+ server.kernel_id.should == 'kernel_id'
45
+ server.key_name.should == 'key_name'
46
+ server.created_at.should == 'launch_time'
47
+ server.product_codes.should == 'product_codes'
48
+ server.private_dns_name.should == 'private_dns_name'
49
+ server.ramdisk_id.should == 'ramdisk_id'
50
+ end
51
+
52
+ end
53
+
54
+ describe "#addresses" do
55
+
56
+ it "should return a Fog::AWS::EC2::Addresses" do
57
+ subject.save
58
+ subject.addresses.should be_a(Fog::AWS::EC2::Addresses)
59
+ end
60
+
61
+ end
62
+
63
+ describe "#state" do
64
+ it "should remap values out of hash" do
65
+ server = Fog::AWS::EC2::Server.new({
66
+ 'instanceState' => { 'name' => 'instance_state' },
67
+ })
68
+ server.state.should == 'instance_state'
69
+ end
70
+ end
71
+
72
+ describe "#key_pair" do
73
+ it "should have tests"
74
+ end
75
+
76
+ describe "#key_pair=" do
77
+ it "should have tests"
78
+ end
79
+
80
+ describe "#monitoring=" do
81
+ it "should remap values out of hash" do
82
+ server = Fog::AWS::EC2::Server.new({
83
+ 'monitoring' => { 'state' => true }
84
+ })
85
+ server.monitoring.should == true
86
+ end
87
+ end
88
+
89
+ describe "#placement=" do
90
+
91
+ it "should remap values into availability_zone" do
92
+ server = Fog::AWS::EC2::Server.new({
93
+ 'placement' => { 'availabilityZone' => 'availability_zone' }
94
+ })
95
+ server.availability_zone.should == 'availability_zone'
96
+ end
97
+
98
+ end
99
+
100
+ describe "#volumes" do
101
+
102
+ it "should return a Fog::AWS::EC2::Volumes" do
103
+ subject.save
104
+ subject.volumes.should be_a(Fog::AWS::EC2::Volumes)
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe 'Fog::AWS::EC2::Servers' do
4
+
5
+ subject { @server = @servers.create(:image_id => GENTOO_AMI) }
6
+
7
+ before(:each) do
8
+ @servers = ec2.servers
9
+ end
10
+
11
+ after(:each) do
12
+ if @server && !@server.new_record?
13
+ @server.destroy
14
+ end
15
+ end
16
+
17
+ describe "#all" do
18
+
19
+ it "should include persisted servers" do
20
+ eventually do
21
+ @servers.all.map {|server| server.id}.should include(subject.id)
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ describe "#get" do
28
+
29
+ it "should return a matching server if one exists" do
30
+ eventually do
31
+ get = @servers.get(subject.id)
32
+ subject.attributes.should == get.attributes
33
+ end
34
+ end
35
+
36
+ it "should return nil if no matching server exists" do
37
+ @servers.get('i-00000000').should be_nil
38
+ end
39
+
40
+ end
41
+
42
+ describe "#reload" do
43
+
44
+ it "should reset attributes to remote state" do
45
+ servers = @servers.all
46
+ reloaded = servers.reload
47
+ servers.attributes.should == reloaded.attributes
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -11,7 +11,7 @@ describe 'Fog::AWS::EC2::Snapshots' do
11
11
  'volumeId' => 'vol-00000000'
12
12
  )
13
13
  snapshot.id.should == 'snap-00000000'
14
- snapshot.start_time.should == 'now'
14
+ snapshot.created_at.should == 'now'
15
15
  snapshot.volume_id.should == 'vol-00000000'
16
16
  end
17
17
 
@@ -35,6 +35,7 @@ describe 'Fog::AWS::EC2::Snapshots' do
35
35
  it "should return true if the snapshot is deleted" do
36
36
  volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
37
37
  snapshot = volume.snapshots.create
38
+ snapshot.wait_for { status == "completed" }
38
39
  snapshot.destroy.should be_true
39
40
  volume.destroy
40
41
  end
@@ -13,10 +13,10 @@ describe 'Fog::AWS::EC2::Volume' do
13
13
  'snapshotId' => 'snap-00000000',
14
14
  'volumeId' => 'vol-00000000'
15
15
  )
16
- volume.attach_time.should == 'now'
16
+ volume.attached_at.should == 'now'
17
17
  volume.availability_zone.should == 'us-east-1a'
18
- volume.create_time.should == 'recently'
19
- volume.instance_id.should == 'i-00000000'
18
+ volume.created_at.should == 'recently'
19
+ volume.server_id.should == 'i-00000000'
20
20
  volume.snapshot_id.should == 'snap-00000000'
21
21
  volume.id.should == 'vol-00000000'
22
22
  end
@@ -45,49 +45,49 @@ describe 'Fog::AWS::EC2::Volume' do
45
45
 
46
46
  end
47
47
 
48
- describe "#instance=" do
48
+ describe "#server=" do
49
49
  before(:each) do
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
- @instance.wait_for { state == 'running' }
50
+ @server = ec2.servers.create(:image_id => GENTOO_AMI)
51
+ @volume = ec2.volumes.new(:availability_zone => @server.availability_zone, :size => 1, :device => '/dev/sdz1')
52
+ @server.wait_for { state == 'running' }
53
53
  end
54
54
 
55
55
  after(:each) do
56
- @instance.destroy
56
+ @server.destroy
57
57
  if @volume.id
58
58
  @volume.wait_for { status == 'attached' }
59
- @volume.instance = nil
59
+ @volume.server = nil
60
60
  @volume.wait_for { status == 'available' }
61
61
  @volume.destroy
62
62
  end
63
63
  end
64
64
 
65
- it "should not attach to instance if the volume has not been saved" do
66
- @volume.instance = @instance
67
- @volume.instance_id.should_not == @instance.id
65
+ it "should not attach to server if the volume has not been saved" do
66
+ @volume.server = @server
67
+ @volume.server_id.should_not == @server.id
68
68
  end
69
69
 
70
70
  it "should change the availability_zone if the volume has not been saved" do
71
- @volume.instance = @instance
72
- @volume.availability_zone.should == @instance.availability_zone
71
+ @volume.server = @server
72
+ @volume.availability_zone.should == @server.availability_zone
73
73
  end
74
74
 
75
- it "should attach to instance when the volume is saved" do
76
- @volume.instance = @instance
75
+ it "should attach to server when the volume is saved" do
76
+ @volume.server = @server
77
77
  @volume.save.should be_true
78
- @volume.instance_id.should == @instance.id
78
+ @volume.server_id.should == @server.id
79
79
  end
80
80
 
81
- it "should attach to instance to an already saved volume" do
81
+ it "should attach to server to an already saved volume" do
82
82
  @volume.save.should be_true
83
- @volume.instance = @instance
84
- @volume.instance_id.should == @instance.id
83
+ @volume.server = @server
84
+ @volume.server_id.should == @server.id
85
85
  end
86
86
 
87
87
  it "should not change the availability_zone if the volume has been saved" do
88
88
  @volume.save.should be_true
89
- @volume.instance = @instance
90
- @volume.availability_zone.should == @instance.availability_zone
89
+ @volume.server = @server
90
+ @volume.availability_zone.should == @server.availability_zone
91
91
  end
92
92
  end
93
93
 
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe 'Fog::AWS::S3::Directories' do
4
+
5
+ describe "#all" do
6
+
7
+ it "should include persisted directories" do
8
+ @directory = s3.directories.create(:name => 'fogdirectoryname')
9
+ s3.directories.all.map {|directory| @directory.name}.should include('fogdirectoryname')
10
+ @directory.destroy
11
+ end
12
+
13
+ end
14
+
15
+ describe "#create" do
16
+
17
+ it "should exist on s3" do
18
+ directory = s3.directories.create(:name => 'fogdirectoryname')
19
+ s3.directories.get(directory.name).should_not be_nil
20
+ directory.destroy
21
+ end
22
+
23
+ end
24
+
25
+ describe "#get" do
26
+
27
+ it "should return a Fog::AWS::S3::Directory if a matching directory exists" do
28
+ directory = s3.directories.create(:name => 'fogdirectoryname')
29
+ get = s3.directories.get('fogdirectoryname')
30
+ directory.attributes.should == get.attributes
31
+ directory.destroy
32
+ end
33
+
34
+ it "should return nil if no matching directory exists" do
35
+ s3.directories.get('fogdirectoryname').should be_nil
36
+ end
37
+
38
+ end
39
+
40
+ describe "#reload" do
41
+
42
+ it "should reload data" do
43
+ directories = s3.directories
44
+ directories.should == directories.reload
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,112 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe 'Fog::AWS::S3::Directory' do
4
+
5
+ describe "#initialize" do
6
+
7
+ it "should remap attributes from parser" do
8
+ now = Time.now
9
+ directory = Fog::AWS::S3::Directory.new(
10
+ 'CreationDate' => now,
11
+ 'Name' => 'directoryname'
12
+ )
13
+ directory.creation_date.should == now
14
+ directory.name.should == 'directoryname'
15
+ end
16
+
17
+ end
18
+
19
+ describe "#collection" do
20
+
21
+ it "should be the directories the directory is related to" do
22
+ directories = s3.directories
23
+ directories.new.collection.should == directories
24
+ end
25
+
26
+ end
27
+
28
+ describe "#destroy" do
29
+
30
+ it "should return true if the directory is deleted" do
31
+ directory = s3.directories.create(:name => 'fogmodeldirectory')
32
+ directory.destroy.should be_true
33
+ end
34
+
35
+ it "should return false if the directory does not exist" do
36
+ directory = s3.directories.new(:name => 'fogmodeldirectory')
37
+ directory.destroy.should be_false
38
+ end
39
+
40
+ end
41
+
42
+ describe "#location" do
43
+
44
+ it "should return the location constraint" do
45
+ directory = s3.directories.create(:name => 'fogmodeleudirectory', :location => 'EU')
46
+ directory.location.should == 'EU'
47
+ eu_s3.directories.get('fogmodeleudirectory').destroy
48
+ end
49
+
50
+ end
51
+
52
+ describe "#payer" do
53
+
54
+ it "should return the request payment value" do
55
+ directory = s3.directories.create(:name => 'fogmodeldirectory')
56
+ directory.payer.should == 'BucketOwner'
57
+ directory.destroy.should be_true
58
+ end
59
+
60
+ end
61
+
62
+ describe "#payer=" do
63
+
64
+ it "should set the request payment value" do
65
+ directory = s3.directories.create(:name => 'fogmodeldirectory')
66
+ (directory.payer = 'Requester').should == 'Requester'
67
+ directory.destroy.should
68
+ end
69
+
70
+ end
71
+
72
+ describe "#reload" do
73
+
74
+ before(:each) do
75
+ @directory = s3.directories.create(:name => 'fogmodeldirectory')
76
+ @reloaded = @directory.reload
77
+ end
78
+
79
+ after(:each) do
80
+ @directory.destroy
81
+ end
82
+
83
+ it "should reset attributes to remote state" do
84
+ @directory.attributes.should == @reloaded.attributes
85
+ end
86
+
87
+ end
88
+
89
+ describe "#save" do
90
+
91
+ before(:each) do
92
+ @directory = s3.directories.new(:name => 'fogmodeldirectory')
93
+ end
94
+
95
+ it "should return true when it succeeds" do
96
+ @directory.save.should be_true
97
+ @directory.destroy
98
+ end
99
+
100
+ it "should not exist in directories before save" do
101
+ s3.directories.all.map {|directory| directory.name}.include?(@directory.name).should be_false
102
+ end
103
+
104
+ it "should exist in directories after save" do
105
+ @directory.save
106
+ s3.directories.all.map {|directory| directory.name}.include?(@directory.name).should be_true
107
+ @directory.destroy
108
+ end
109
+
110
+ end
111
+
112
+ end