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,3 @@
1
+ :description: Fedora 10
2
+ :owner_id: fedoraproject
3
+ :architecture: i386
@@ -0,0 +1,3 @@
1
+ :description: JBoss
2
+ :owner_id: mockuser
3
+ :architecture: i386
@@ -0,0 +1,8 @@
1
+ :name: MockUserInstance
2
+ :state: RUNNING
3
+ :image_id: img3
4
+ :owner_id: mockuser
5
+ :public_addresses: [ img3.inst1.public.com ]
6
+ :private_addresses: [ img3.inst1.private.com ]
7
+ :flavor_id: m1-small
8
+ :realm_id: us
@@ -0,0 +1,8 @@
1
+ :name: AnotherInstance
2
+ :state: RUNNING
3
+ :image_id: img1
4
+ :owner_id: anotheruser
5
+ :public_addresses: [ img1.inst2.public.com ]
6
+ :private_addresses: [ img1.inst2.private.com ]
7
+ :flavor_id: m1-small
8
+ :realm_id: us
@@ -0,0 +1,4 @@
1
+ :owner_id: fedoraproject
2
+ :created: Wed Jul 29 18:15:24 UTC 2009
3
+ :state: COMPLETED
4
+ :storage_volume_id: vol1
@@ -0,0 +1,4 @@
1
+ :owner_id: mockuser
2
+ :created: Wed Jul 29 18:15:24 UTC 2009
3
+ :state: COMPLETED
4
+ :storage_volume_id: vol2
@@ -0,0 +1,4 @@
1
+ :owner_id: mockuser
2
+ :created: Wed Jul 29 18:15:24 UTC 2009
3
+ :state: COMPLETED
4
+ :storage_volume_id: vol2
@@ -0,0 +1,6 @@
1
+ :owner_id: fedoraproject
2
+ :created: Thu Jul 30 14:35:11 UTC 2009
3
+ :state: AVAILABLE
4
+ :capacity: 1
5
+ :device:
6
+ :instance_id:
@@ -0,0 +1,6 @@
1
+ :owner_id: mockuser
2
+ :created: Thu Jul 30 14:35:11 UTC 2009
3
+ :state: AVAILABLE
4
+ :capacity: 1
5
+ :device:
6
+ :instance_id:
@@ -0,0 +1,6 @@
1
+ :owner_id: mockuser
2
+ :created: Thu Jul 30 14:35:11 UTC 2009
3
+ :state: IN-USE
4
+ :capacity: 1
5
+ :device: /dev/sda1
6
+ :instance_id: inst1
@@ -0,0 +1,3 @@
1
+ :description: Fedora 10
2
+ :owner_id: fedoraproject
3
+ :architecture: x86_64
@@ -0,0 +1,3 @@
1
+ :description: Fedora 10
2
+ :owner_id: fedoraproject
3
+ :architecture: i386
@@ -0,0 +1,3 @@
1
+ :description: JBoss
2
+ :owner_id: mockuser
3
+ :architecture: i386
@@ -0,0 +1,8 @@
1
+ :name: MockUserInstance
2
+ :state: RUNNING
3
+ :image_id: img3
4
+ :owner_id: mockuser
5
+ :public_addresses: [ img3.inst1.public.com ]
6
+ :private_addresses: [ img3.inst1.private.com ]
7
+ :flavor_id: m1-small
8
+ :realm_id: us
@@ -0,0 +1,8 @@
1
+ :name: AnotherInstance
2
+ :state: RUNNING
3
+ :image_id: img1
4
+ :owner_id: anotheruser
5
+ :public_addresses: [ img1.inst2.public.com ]
6
+ :private_addresses: [ img1.inst2.private.com ]
7
+ :flavor_id: m1-small
8
+ :realm_id: us
@@ -0,0 +1,4 @@
1
+ :owner_id: fedoraproject
2
+ :created: Wed Jul 29 18:15:24 UTC 2009
3
+ :state: COMPLETED
4
+ :storage_volume_id: vol1
@@ -0,0 +1,4 @@
1
+ :owner_id: mockuser
2
+ :created: Wed Jul 29 18:15:24 UTC 2009
3
+ :state: COMPLETED
4
+ :storage_volume_id: vol2
@@ -0,0 +1,4 @@
1
+ :owner_id: mockuser
2
+ :created: Wed Jul 29 18:15:24 UTC 2009
3
+ :state: COMPLETED
4
+ :storage_volume_id: vol2
@@ -0,0 +1,6 @@
1
+ :owner_id: fedoraproject
2
+ :created: Thu Jul 30 14:35:11 UTC 2009
3
+ :state: AVAILABLE
4
+ :capacity: 1
5
+ :device:
6
+ :instance_id:
@@ -0,0 +1,6 @@
1
+ :owner_id: mockuser
2
+ :created: Thu Jul 30 14:35:11 UTC 2009
3
+ :state: AVAILABLE
4
+ :capacity: 1
5
+ :device:
6
+ :instance_id:
@@ -0,0 +1,6 @@
1
+ :owner_id: mockuser
2
+ :created: Thu Jul 30 14:35:11 UTC 2009
3
+ :state: IN-USE
4
+ :capacity: 1
5
+ :device: /dev/sda1
6
+ :instance_id: inst1
@@ -0,0 +1,67 @@
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 "flavors" do
22
+
23
+ it_should_behave_like "all resources"
24
+
25
+ it "should allow retrieval of all flavors" do
26
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
27
+ flavors = client.flavors
28
+ flavors.should_not be_empty
29
+ flavors.each do |flavor|
30
+ flavor.uri.should_not be_nil
31
+ flavor.uri.should be_a(String)
32
+ flavor.architecture.should_not be_nil
33
+ flavor.architecture.should be_a(String)
34
+ flavor.storage.should_not be_nil
35
+ flavor.storage.should be_a(Float)
36
+ flavor.memory.should_not be_nil
37
+ flavor.memory.should be_a(Float)
38
+ end
39
+ end
40
+ end
41
+
42
+ it "should allow filtering of flavors by architecture" do
43
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
44
+ flavors = client.flavors( :architecture=>'i386' )
45
+ flavors.should_not be_empty
46
+ flavors.size.should eql( 1 )
47
+ flavors.first.architecture.should eql( 'i386' )
48
+ end
49
+ end
50
+
51
+ it "should allow fetching a flavor by id" do
52
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
53
+ flavor = client.flavor( 'm1-small' )
54
+ flavor.should_not be_nil
55
+ flavor.id.should eql( 'm1-small' )
56
+ end
57
+ end
58
+
59
+ it "should allow fetching a flavor by URI" do
60
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
61
+ flavor = client.fetch_flavor( API_URL + '/flavors/m1-small' )
62
+ flavor.should_not be_nil
63
+ flavor.id.should eql( 'm1-small' )
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,104 @@
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 "images" do
22
+
23
+ it_should_behave_like "all resources"
24
+
25
+ it "should allow retrieval of all images" do
26
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
27
+ images = client.images
28
+ images.should_not be_empty
29
+ images.size.should eql( 3 )
30
+ images.each do |image|
31
+ image.uri.should_not be_nil
32
+ image.uri.should be_a(String)
33
+ image.description.should_not be_nil
34
+ image.description.should be_a(String)
35
+ image.architecture.should_not be_nil
36
+ image.architecture.should be_a(String)
37
+ image.owner_id.should_not be_nil
38
+ image.owner_id.should be_a(String)
39
+ end
40
+ end
41
+ end
42
+
43
+ it "should allow retrieval of my own images" do
44
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
45
+ images = client.images( :owner_id=>:self )
46
+ images.should_not be_empty
47
+ images.size.should eql( 1 )
48
+ images.each do |image|
49
+ image.uri.should_not be_nil
50
+ image.uri.should be_a(String)
51
+ image.description.should_not be_nil
52
+ image.description.should be_a(String)
53
+ image.architecture.should_not be_nil
54
+ image.architecture.should be_a(String)
55
+ image.owner_id.should_not be_nil
56
+ image.owner_id.should be_a(String)
57
+ end
58
+ end
59
+ end
60
+
61
+ it "should allow retrieval of a single image by ID" do
62
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
63
+ image = client.image( 'img1' )
64
+ image.should_not be_nil
65
+ image.uri.should eql( API_URL + '/images/img1' )
66
+ image.id.should eql( 'img1' )
67
+ image.architecture.should eql( 'x86_64' )
68
+ end
69
+ end
70
+
71
+ it "should allow retrieval of a single image by URI" do
72
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
73
+ image = client.fetch_image( API_URL + '/images/img1' )
74
+ image.should_not be_nil
75
+ image.uri.should eql( API_URL + '/images/img1' )
76
+ image.id.should eql( 'img1' )
77
+ image.architecture.should eql( 'x86_64' )
78
+ end
79
+ end
80
+
81
+ describe "filtering by architecture" do
82
+ it "return matching images" do
83
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
84
+ images = client.images( :architecture=>'x86_64' )
85
+ images.should_not be_empty
86
+ images.each do |image|
87
+ image.architecture.should eql( 'x86_64' )
88
+ end
89
+ images = client.images( :architecture=>'i386' )
90
+ images.should_not be_empty
91
+ images.each do |image|
92
+ image.architecture.should eql( 'i386' )
93
+ end
94
+ end
95
+ end
96
+
97
+ it "should return an empty array for no matches" do
98
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
99
+ images = client.images( :architecture=>'8088' )
100
+ images.should be_empty
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,59 @@
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 "initializing the client" do
21
+
22
+ it "should parse valid API URIs" do
23
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
24
+ client.api_host.should eql( API_HOST )
25
+ client.api_port.should eql( API_PORT.to_i )
26
+ client.api_path.should eql( API_PATH )
27
+ end
28
+
29
+ it "should discover entry points upon connection" do
30
+ DeltaCloud.new( "name", "password", API_URL ) do |client|
31
+ client.entry_points[:flavors].should eql( "#{API_URL}/flavors" )
32
+ client.entry_points[:images].should eql( "#{API_URL}/images" )
33
+ client.entry_points[:instances].should eql( "#{API_URL}/instances" )
34
+ client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage_volumes" )
35
+ client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage_snapshots" )
36
+ end
37
+ end
38
+
39
+ it "should provide the current driver name via client" do
40
+ DeltaCloud.new( "name", "password", API_URL ) do |client|
41
+ client.driver_name.should eql( 'mock' )
42
+ end
43
+ end
44
+
45
+ it "should provide the current driver name without client" do
46
+ DeltaCloud.driver_name( API_URL ).should eql( 'mock' )
47
+ end
48
+
49
+ describe "without a block" do
50
+ before( :each ) do
51
+ reload_fixtures
52
+ end
53
+ it "should connect without a block" do
54
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
55
+ client.images.should_not be_nil
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,77 @@
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
+ =begin
22
+ Spec::Matchers.define :include_transition do |action,to|
23
+ match do |transitions|
24
+ found = transitions.find{|e| e.action.to_s == action.to_s && e.to.to_s == to.to_s }
25
+ ! found.nil?
26
+ end
27
+ end
28
+ =end
29
+
30
+ describe "instance-states" do
31
+
32
+ it_should_behave_like "all resources"
33
+
34
+ it "should allow retrieval of instance-state information" do
35
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
36
+ instance_states = client.instance_states
37
+ instance_states.should_not be_nil
38
+ instance_states.should_not be_empty
39
+
40
+ instance_states[0].name.should eql( 'start' )
41
+ instance_states[0].transitions.size.should eql( 1 )
42
+ instance_states[0].transitions[0].should_not be_auto
43
+
44
+ instance_states[1].name.should eql( 'pending' )
45
+ instance_states[1].transitions.size.should eql( 1 )
46
+ instance_states[1].transitions[0].should be_auto
47
+
48
+ instance_states[2].name.should eql( 'running' )
49
+ instance_states[2].transitions.size.should eql( 2 )
50
+ includes_transition( instance_states[2].transitions, :reboot, :running ).should be_true
51
+ includes_transition( instance_states[2].transitions, :stop, :stopped ).should be_true
52
+ end
53
+ end
54
+
55
+ it "should allow retrieval of a single instance-state blob" do
56
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
57
+ instance_state = client.instance_state( :pending )
58
+ instance_state.should_not be_nil
59
+ instance_state.name.should eql( 'pending' )
60
+ instance_state.transitions.size.should eql( 1 )
61
+ instance_state.transitions[0].should be_auto
62
+
63
+ instance_state = client.instance_state( :running )
64
+ instance_state.name.should eql( 'running' )
65
+ instance_state.transitions.size.should eql( 2 )
66
+ includes_transition( instance_state.transitions, :reboot, :running ).should be_true
67
+ includes_transition( instance_state.transitions, :stop, :stopped ).should be_true
68
+ end
69
+ end
70
+
71
+ def includes_transition( transitions, action, to )
72
+ found = transitions.find{|e| e.action.to_s == action.to_s && e.to.to_s == to.to_s }
73
+ ! found.nil?
74
+ end
75
+
76
+
77
+ end