deltacloud-client 0.0.2

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 (47) hide show
  1. data/COPYING +502 -0
  2. data/Rakefile +39 -0
  3. data/credentials.yml +2 -0
  4. data/init.rb +19 -0
  5. data/lib/dcloud/base_model.rb +80 -0
  6. data/lib/dcloud/flavor.rb +43 -0
  7. data/lib/dcloud/image.rb +46 -0
  8. data/lib/dcloud/instance.rb +97 -0
  9. data/lib/dcloud/realm.rb +47 -0
  10. data/lib/dcloud/state.rb +30 -0
  11. data/lib/dcloud/storage_snapshot.rb +50 -0
  12. data/lib/dcloud/storage_volume.rb +53 -0
  13. data/lib/dcloud/transition.rb +35 -0
  14. data/lib/deltacloud.rb +356 -0
  15. data/specs/data/images/img1.yml +3 -0
  16. data/specs/data/images/img2.yml +3 -0
  17. data/specs/data/images/img3.yml +3 -0
  18. data/specs/data/instances/inst1.yml +8 -0
  19. data/specs/data/instances/inst2.yml +8 -0
  20. data/specs/data/storage_snapshots/snap1.yml +4 -0
  21. data/specs/data/storage_snapshots/snap2.yml +4 -0
  22. data/specs/data/storage_snapshots/snap3.yml +4 -0
  23. data/specs/data/storage_volumes/vol1.yml +6 -0
  24. data/specs/data/storage_volumes/vol2.yml +6 -0
  25. data/specs/data/storage_volumes/vol3.yml +6 -0
  26. data/specs/fixtures/images/img1.yml +3 -0
  27. data/specs/fixtures/images/img2.yml +3 -0
  28. data/specs/fixtures/images/img3.yml +3 -0
  29. data/specs/fixtures/instances/inst1.yml +8 -0
  30. data/specs/fixtures/instances/inst2.yml +8 -0
  31. data/specs/fixtures/storage_snapshots/snap1.yml +4 -0
  32. data/specs/fixtures/storage_snapshots/snap2.yml +4 -0
  33. data/specs/fixtures/storage_snapshots/snap3.yml +4 -0
  34. data/specs/fixtures/storage_volumes/vol1.yml +6 -0
  35. data/specs/fixtures/storage_volumes/vol2.yml +6 -0
  36. data/specs/fixtures/storage_volumes/vol3.yml +6 -0
  37. data/specs/flavors_spec.rb +67 -0
  38. data/specs/images_spec.rb +104 -0
  39. data/specs/initialization_spec.rb +59 -0
  40. data/specs/instance_states_spec.rb +77 -0
  41. data/specs/instances_spec.rb +171 -0
  42. data/specs/realms_spec.rb +65 -0
  43. data/specs/shared/resources.rb +29 -0
  44. data/specs/spec_helper.rb +54 -0
  45. data/specs/storage_snapshot_spec.rb +76 -0
  46. data/specs/storage_volume_spec.rb +86 -0
  47. metadata +108 -0
@@ -0,0 +1,171 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+
19
+ require 'specs/spec_helper'
20
+
21
+ describe "instances" do
22
+
23
+ it_should_behave_like "all resources"
24
+
25
+ it "should allow retrieval of all instances" do
26
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
27
+ instances = client.instances
28
+ instances.should_not be_empty
29
+ instances.each do |instance|
30
+ instance.uri.should_not be_nil
31
+ instance.uri.should be_a( String )
32
+ instance.owner_id.should_not be_nil
33
+ instance.owner_id.should be_a( String )
34
+ instance.image.should_not be_nil
35
+ instance.image.should be_a( DCloud::Image )
36
+ instance.flavor.should_not be_nil
37
+ instance.flavor.should be_a( DCloud::Flavor )
38
+ instance.state.should_not be_nil
39
+ instance.state.should be_a( String )
40
+ instance.public_addresses.should_not be_nil
41
+ instance.public_addresses.should_not be_empty
42
+ instance.public_addresses.should be_a( Array )
43
+ instance.private_addresses.should_not be_nil
44
+ instance.private_addresses.should_not be_empty
45
+ instance.private_addresses.should be_a( Array )
46
+ end
47
+ end
48
+ end
49
+
50
+ it "should allow navigation from instance to image" do
51
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
52
+ instances = client.instances
53
+ instances.should_not be_empty
54
+ instance = instances.first
55
+ instance.image.should_not be_nil
56
+ instance.image.description.should_not be_nil
57
+ instance.image.description.should be_a(String)
58
+ end
59
+ end
60
+
61
+ it "should allow retrieval of a single instance" do
62
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
63
+ instance = client.instance( "inst1" )
64
+ instance.should_not be_nil
65
+ instance.name.should_not be_nil
66
+ instance.name.should eql( 'MockUserInstance' )
67
+ instance.uri.should_not be_nil
68
+ instance.uri.should be_a( String )
69
+ instance.owner_id.should eql( "mockuser" )
70
+ instance.public_addresses.first.should eql( "img3.inst1.public.com" )
71
+ instance.image.should_not be_nil
72
+ instance.image.uri.should eql( API_URL + "/images/img3" )
73
+ instance.flavor.should_not be_nil
74
+ instance.flavor.uri.should eql( API_URL + "/flavors/m1-small" )
75
+ instance.state.should eql( "RUNNING" )
76
+ instance.actions.should_not be_nil
77
+ end
78
+ end
79
+
80
+ it "should allow creation of new instances with reasonable defaults" do
81
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
82
+ instance = client.create_instance( 'img1', :name=>'TestInstance' )
83
+ instance.should_not be_nil
84
+ instance.uri.should eql( API_URL + '/instances/inst3' )
85
+ instance.id.should eql( 'inst3' )
86
+ instance.name.should eql( 'TestInstance' )
87
+ instance.image.id.should eql( 'img1' )
88
+ instance.flavor.id.should eql( 'm1-large' )
89
+ instance.realm.id.should eql( 'us' )
90
+ end
91
+ end
92
+
93
+ it "should allow creation of new instances with specific realm" do
94
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
95
+ instance = client.create_instance( 'img1', :realm=>'eu' )
96
+ instance.should_not be_nil
97
+ instance.uri.should eql( API_URL + '/instances/inst3' )
98
+ instance.id.should eql( 'inst3' )
99
+ instance.image.id.should eql( 'img1' )
100
+ instance.flavor.id.should eql( 'm1-large' )
101
+ instance.realm.id.should eql( 'eu' )
102
+ end
103
+ end
104
+
105
+ it "should allow creation of new instances with specific flavor" do
106
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
107
+ instance = client.create_instance( 'img1', :flavor=>'m1-xlarge' )
108
+ instance.should_not be_nil
109
+ instance.uri.should eql( API_URL + '/instances/inst3' )
110
+ instance.id.should eql( 'inst3' )
111
+ instance.image.id.should eql( 'img1' )
112
+ instance.flavor.id.should eql( 'm1-xlarge' )
113
+ instance.realm.id.should eql( 'us' )
114
+ end
115
+ end
116
+
117
+ it "should allow creation of new instances with specific realm and flavor" do
118
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
119
+ instance = client.create_instance( 'img1', :realm=>'eu', :flavor=>'m1-xlarge' )
120
+ instance.should_not be_nil
121
+ instance.uri.should eql( API_URL + '/instances/inst3' )
122
+ instance.id.should eql( 'inst3' )
123
+ instance.image.id.should eql( 'img1' )
124
+ instance.flavor.id.should eql( 'm1-xlarge' )
125
+ instance.realm.id.should eql( 'eu' )
126
+ end
127
+ end
128
+
129
+ it "should allow fetching of instances by id" do
130
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
131
+ instance = client.instance( 'inst1' )
132
+ instance.should_not be_nil
133
+ instance.uri.should_not be_nil
134
+ instance.uri.should be_a( String )
135
+ end
136
+ end
137
+
138
+ it "should allow fetching of instances by URI" do
139
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
140
+ instance = client.fetch_instance( API_URL + '/instances/inst1' )
141
+ instance.should_not be_nil
142
+ instance.uri.should eql( API_URL + '/instances/inst1' )
143
+ instance.id.should eql( 'inst1' )
144
+ end
145
+ end
146
+
147
+ describe "performing actions on instances" do
148
+ it "should allow actions that are valid" do
149
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
150
+ instance = client.instance( 'inst1' )
151
+ instance.should_not be_nil
152
+ instance.state.should eql( "RUNNING" )
153
+ instance.uri.should eql( API_URL + '/instances/inst1' )
154
+ instance.id.should eql( 'inst1' )
155
+ instance.stop!
156
+ instance.state.should eql( "STOPPED" )
157
+ instance.start!
158
+ instance.state.should eql( "RUNNING" )
159
+ end
160
+ end
161
+
162
+ it "should not allow actions that are invalid" do
163
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
164
+ instance = client.instance( 'inst1' )
165
+ instance.should_not be_nil
166
+ instance.state.should eql( "RUNNING" )
167
+ lambda{instance.start}.should raise_error
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,65 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ require 'specs/spec_helper'
19
+
20
+ describe "realms" do
21
+
22
+ it_should_behave_like "all resources"
23
+
24
+ it "should allow retrieval of all realms" do
25
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
26
+ realms = client.realms
27
+ realms.should_not be_empty
28
+ realms.each do |realm|
29
+ realm.uri.should_not be_nil
30
+ realm.uri.should be_a(String)
31
+ realm.id.should_not be_nil
32
+ realm.id.should be_a(String)
33
+ realm.name.should_not be_nil
34
+ realm.name.should be_a(String)
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ it "should allow fetching a realm by id" do
41
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
42
+ realm = client.realm( 'us' )
43
+ realm.should_not be_nil
44
+ realm.id.should eql( 'us' )
45
+ realm.name.should eql( 'United States' )
46
+ realm.state.should eql( 'AVAILABLE' )
47
+ realm.limit.should eql( :unlimited )
48
+ realm = client.realm( 'eu' )
49
+ realm.should_not be_nil
50
+ realm.id.should eql( 'eu' )
51
+ realm.name.should eql( 'Europe' )
52
+ realm.state.should eql( 'AVAILABLE' )
53
+ realm.limit.should eql( :unlimited )
54
+ end
55
+ end
56
+
57
+ it "should allow fetching a realm by URI" do
58
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
59
+ realm = client.fetch_realm( API_URL + '/realms/us' )
60
+ realm.should_not be_nil
61
+ realm.id.should eql( 'us' )
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+
19
+ shared_examples_for "all resources" do
20
+
21
+ before(:each) do
22
+ reload_fixtures
23
+ end
24
+
25
+ after(:each) do
26
+ #clean_fixtures
27
+ end
28
+
29
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ require 'rubygems'
19
+ require 'yaml'
20
+ require 'fileutils'
21
+
22
+ api_host = ENV['API_HOST']
23
+ ( api_host = 'localhost' ) if api_host.nil?
24
+ ( api_host = 'localhost' ) if api_host == ''
25
+
26
+ api_port = ENV['API_PORT']
27
+ ( api_port = 3000 ) if api_port.nil?
28
+ ( api_port = 3000 ) if api_port == ''
29
+
30
+ API_HOST = api_host
31
+ API_PORT = api_port
32
+ API_PATH = '/api'
33
+
34
+ API_URL = "http://#{API_HOST}:#{API_PORT}#{API_PATH}"
35
+
36
+ credentials = YAML.load( File.read( File.dirname( __FILE__ ) + '/../credentials.yml' ) )
37
+
38
+ API_NAME = credentials['name']
39
+ API_PASSWORD = credentials['password']
40
+
41
+ $: << File.dirname( __FILE__ ) + '/../lib'
42
+ require 'deltacloud'
43
+
44
+ def clean_fixtures
45
+ FileUtils.rm_rf( File.dirname( __FILE__ ) + '/data' )
46
+ end
47
+
48
+ def reload_fixtures
49
+ clean_fixtures
50
+ FileUtils.cp_r( File.dirname( __FILE__) + '/fixtures', File.dirname( __FILE__ ) + '/data' )
51
+ end
52
+
53
+ $: << File.dirname( __FILE__ )
54
+ require 'shared/resources'
@@ -0,0 +1,76 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+
19
+ require 'specs/spec_helper'
20
+
21
+ describe "storage snapshot" do
22
+
23
+ it_should_behave_like "all resources"
24
+
25
+ it "allow retrieval of all storage volumes owned by the current user" do
26
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
27
+ client.connect do |client|
28
+ storage_snapshots = client.storage_snapshots
29
+ storage_snapshots.should_not be_nil
30
+ storage_snapshots.should_not be_empty
31
+ ids = storage_snapshots.collect{|e| e.id}
32
+ ids.size.should eql( 2 )
33
+ ids.should include( 'snap2' )
34
+ ids.should include( 'snap3' )
35
+ end
36
+ end
37
+
38
+ it "should allow fetching of storage volume by id" do
39
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
40
+ client.connect do |client|
41
+ storage_snapshot = client.storage_snapshot( 'snap2' )
42
+ storage_snapshot.should_not be_nil
43
+ storage_snapshot.id.should eql( 'snap2' )
44
+ storage_snapshot.storage_volume.capacity.should eql( 1.0 )
45
+ storage_snapshot.storage_volume.id.should eql( 'vol2' )
46
+ end
47
+ end
48
+
49
+ it "should allow fetching of storage volume by URI" do
50
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
51
+ client.connect do |client|
52
+ storage_snapshot = client.fetch_storage_snapshot( API_URL + '/storage_snapshots/snap2' )
53
+ storage_snapshot.should_not be_nil
54
+ storage_snapshot.id.should eql( 'snap2' )
55
+ storage_snapshot.storage_volume.capacity.should eql( 1.0 )
56
+ storage_snapshot.storage_volume.id.should eql( 'vol2' )
57
+ end
58
+ end
59
+
60
+ it "should return nil for unknown storage volume by ID" do
61
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
62
+ client.connect do |client|
63
+ storage_snapshot = client.storage_snapshot( "bogus" )
64
+ storage_snapshot.should be_nil
65
+ end
66
+ end
67
+
68
+ it "should return nil for unknown storage volume by URI" do
69
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
70
+ client.connect do |client|
71
+ storage_snapshot = client.fetch_storage_snapshot( API_URL + '/storage_snapshots/bogus' )
72
+ storage_snapshot.should be_nil
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,86 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+
19
+ require 'specs/spec_helper'
20
+
21
+ describe "storage volumes" do
22
+
23
+ it_should_behave_like "all resources"
24
+
25
+ it "allow retrieval of all storage volumes owned by the current user" do
26
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
27
+ client.connect do |client|
28
+ storage_volumes = client.storage_volumes
29
+ storage_volumes.should_not be_nil
30
+ storage_volumes.should_not be_empty
31
+ ids = storage_volumes.collect{|e| e.id}
32
+ ids.size.should eql( 2 )
33
+ ids.should include( 'vol2' )
34
+ ids.should include( 'vol3' )
35
+ end
36
+ end
37
+
38
+ it "should allow fetching of storage volume by id" do
39
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
40
+ client.connect do |client|
41
+ storage_volume = client.storage_volume( 'vol3' )
42
+ storage_volume.id.should eql( 'vol3' )
43
+ storage_volume.uri.should eql( API_URL + '/storage_volumes/vol3' )
44
+ storage_volume.state.should eql( 'IN-USE' )
45
+ storage_volume.capacity.should eql( 1.0 )
46
+ storage_volume.device.should eql( '/dev/sda1' )
47
+ storage_volume.instance.should_not be_nil
48
+ storage_volume.instance.id.should eql( 'inst1' )
49
+ storage_volume.instance.flavor.architecture.should eql( 'i386' )
50
+ end
51
+ end
52
+
53
+ it "should allow fetching of storage volume by URI" do
54
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
55
+ client.connect do |client|
56
+ storage_volume = client.fetch_storage_volume( API_URL + '/storage_volumes/vol3' )
57
+ storage_volume.should_not be_nil
58
+ storage_volume.id.should eql( 'vol3' )
59
+ storage_volume.uri.should eql( API_URL + '/storage_volumes/vol3' )
60
+ storage_volume.state.should eql( 'IN-USE' )
61
+ storage_volume.capacity.should eql( 1.0 )
62
+ storage_volume.device.should eql( '/dev/sda1' )
63
+ storage_volume.instance.should_not be_nil
64
+ storage_volume.instance.id.should eql( 'inst1' )
65
+ storage_volume.instance.flavor.architecture.should eql( 'i386' )
66
+ end
67
+ end
68
+
69
+ it "should return nil for unknown storage volume by ID" do
70
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
71
+ client.connect do |client|
72
+ storage_volume = client.storage_volume( 'bogus' )
73
+ storage_volume.should be_nil
74
+ end
75
+ end
76
+
77
+ it "should return nil for unknown storage volume by URI" do
78
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
79
+ client.connect do |client|
80
+ storage_volume = client.fetch_storage_volume( API_URL + '/storage_volumes/bogus' )
81
+ storage_volume.should be_nil
82
+ end
83
+ end
84
+
85
+
86
+ end