steamcannon-deltacloud-client 0.0.9.7.1-java

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 (42) hide show
  1. data/COPYING +176 -0
  2. data/Rakefile +61 -0
  3. data/bin/deltacloudc +158 -0
  4. data/init.rb +20 -0
  5. data/lib/deltacloud.rb +586 -0
  6. data/lib/documentation.rb +98 -0
  7. data/lib/plain_formatter.rb +86 -0
  8. data/specs/data/images/img1.yml +4 -0
  9. data/specs/data/images/img2.yml +4 -0
  10. data/specs/data/images/img3.yml +4 -0
  11. data/specs/data/instances/inst0.yml +16 -0
  12. data/specs/data/instances/inst1.yml +9 -0
  13. data/specs/data/instances/inst2.yml +9 -0
  14. data/specs/data/storage_snapshots/snap1.yml +4 -0
  15. data/specs/data/storage_snapshots/snap2.yml +4 -0
  16. data/specs/data/storage_snapshots/snap3.yml +4 -0
  17. data/specs/data/storage_volumes/vol1.yml +6 -0
  18. data/specs/data/storage_volumes/vol2.yml +6 -0
  19. data/specs/data/storage_volumes/vol3.yml +6 -0
  20. data/specs/fixtures/images/img1.yml +4 -0
  21. data/specs/fixtures/images/img2.yml +4 -0
  22. data/specs/fixtures/images/img3.yml +4 -0
  23. data/specs/fixtures/instances/inst0.yml +16 -0
  24. data/specs/fixtures/instances/inst1.yml +9 -0
  25. data/specs/fixtures/instances/inst2.yml +9 -0
  26. data/specs/fixtures/storage_snapshots/snap1.yml +4 -0
  27. data/specs/fixtures/storage_snapshots/snap2.yml +4 -0
  28. data/specs/fixtures/storage_snapshots/snap3.yml +4 -0
  29. data/specs/fixtures/storage_volumes/vol1.yml +6 -0
  30. data/specs/fixtures/storage_volumes/vol2.yml +6 -0
  31. data/specs/fixtures/storage_volumes/vol3.yml +6 -0
  32. data/specs/hardware_profiles_spec.rb +78 -0
  33. data/specs/images_spec.rb +105 -0
  34. data/specs/initialization_spec.rb +60 -0
  35. data/specs/instance_states_spec.rb +78 -0
  36. data/specs/instances_spec.rb +191 -0
  37. data/specs/realms_spec.rb +64 -0
  38. data/specs/shared/resources.rb +30 -0
  39. data/specs/spec_helper.rb +52 -0
  40. data/specs/storage_snapshot_spec.rb +77 -0
  41. data/specs/storage_volume_spec.rb +89 -0
  42. metadata +191 -0
@@ -0,0 +1,86 @@
1
+ module DeltaCloud
2
+ module PlainFormatter
3
+ module FormatObject
4
+
5
+ class Base
6
+ def initialize(obj)
7
+ @obj = obj
8
+ end
9
+ end
10
+
11
+ class Image < Base
12
+ def format
13
+ sprintf("%-10s | %-20s | %-6s | %-20s | %15s",
14
+ @obj.id[0,10],
15
+ @obj.name ? @obj.name[0, 20]: 'unknown',
16
+ @obj.architecture[0,6],
17
+ @obj.description[0,20],
18
+ @obj.owner_id[0,15]
19
+ )
20
+ end
21
+ end
22
+
23
+ class Realm < Base
24
+ def format
25
+ sprintf("%-10s | %-15s | %-5s | %10s GB",
26
+ @obj.id[0, 10],
27
+ @obj.name[0, 15],
28
+ @obj.state[0,5],
29
+ @obj.limit.to_s[0,10]
30
+ )
31
+ end
32
+ end
33
+
34
+ class HardwareProfile < Base
35
+ def format
36
+ sprintf("%-15s | %-6s | %10s | %10s ", @obj.id[0, 15],
37
+ @obj.architecture.value[0,6], @obj.memory.value.to_s[0,10], @obj.storage.value.to_s[0,10])
38
+ end
39
+ end
40
+
41
+ class Instance < Base
42
+ def format
43
+ sprintf("%-15s | %-15s | %-15s | %10s | %32s | %32s",
44
+ @obj.id ? @obj.id[0,15] : '-',
45
+ @obj.name ? @obj.name[0,15] : 'unknown',
46
+ @obj.image.name ? @obj.image.name[0,15] : 'unknown',
47
+ @obj.state ? @obj.state.to_s[0,10] : 'unknown',
48
+ @obj.public_addresses.join(',')[0,32],
49
+ @obj.private_addresses.join(',')[0,32]
50
+ )
51
+ end
52
+ end
53
+
54
+ class StorageVolume < Base
55
+ def format
56
+ sprintf("%-10s | %15s GB | %-10s | %-10s | %-15s",
57
+ @obj.id[0,10],
58
+ @obj.capacity ? @obj.capacity.to_s[0,15] : 'unknown',
59
+ @obj.device ? @obj.device[0,10] : 'unknown',
60
+ @obj.respond_to?('state') ? @obj.state[0,10] : 'unknown',
61
+ @obj.instance ? @obj.instance.name[0,15] : 'unknown'
62
+ )
63
+ end
64
+ end
65
+
66
+ class StorageSnapshot < Base
67
+ def format
68
+ sprintf("%-10s | %-15s | %-6s | %15s",
69
+ @obj.id[0,10],
70
+ @obj.storage_volume.respond_to?('name') ? @obj.storage_volume.name[0, 15] : 'unknown',
71
+ @obj.state ? @obj.state[0,10] : 'unknown',
72
+ @obj.created ? @obj.created[0,19] : 'unknown'
73
+ )
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ def format(obj)
80
+ object_name = obj.class.name.classify.gsub(/^DeltaCloud::API::/, '')
81
+ format_class = DeltaCloud::PlainFormatter::FormatObject.const_get(object_name)
82
+ format_class.new(obj).format
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,4 @@
1
+ :description: Fedora 10
2
+ :owner_id: fedoraproject
3
+ :architecture: x86_64
4
+ :id: img1
@@ -0,0 +1,4 @@
1
+ :description: Fedora 10
2
+ :owner_id: fedoraproject
3
+ :architecture: i386
4
+ :id: img2
@@ -0,0 +1,4 @@
1
+ :description: JBoss
2
+ :owner_id: mockuser
3
+ :architecture: i386
4
+ :id: img3
@@ -0,0 +1,16 @@
1
+ ---
2
+ :realm_id: us
3
+ :public_addresses:
4
+ - img1.inst0.public.com
5
+ :state: RUNNING
6
+ :name: "Mock Instance With Profile Change"
7
+ :private_addresses:
8
+ - img1.inst0.private.com
9
+ :image_id: img1
10
+ :instance_profile: !ruby/object:InstanceProfile
11
+ id: m1-large
12
+ memory: "12288"
13
+ :owner_id: mockuser
14
+ :actions:
15
+ - :reboot
16
+ - :stop
@@ -0,0 +1,9 @@
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
+ :realm_id: us
8
+ :instance_profile: !ruby/object:InstanceProfile
9
+ id: m1-small
@@ -0,0 +1,9 @@
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
+ :realm_id: us
8
+ :instance_profile: !ruby/object:InstanceProfile
9
+ id: m1-large
@@ -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,4 @@
1
+ :description: Fedora 10
2
+ :owner_id: fedoraproject
3
+ :architecture: x86_64
4
+ :id: img1
@@ -0,0 +1,4 @@
1
+ :description: Fedora 10
2
+ :owner_id: fedoraproject
3
+ :architecture: i386
4
+ :id: img2
@@ -0,0 +1,4 @@
1
+ :description: JBoss
2
+ :owner_id: mockuser
3
+ :architecture: i386
4
+ :id: img3
@@ -0,0 +1,16 @@
1
+ ---
2
+ :realm_id: us
3
+ :public_addresses:
4
+ - img1.inst0.public.com
5
+ :state: RUNNING
6
+ :name: "Mock Instance With Profile Change"
7
+ :private_addresses:
8
+ - img1.inst0.private.com
9
+ :image_id: img1
10
+ :instance_profile: !ruby/object:InstanceProfile
11
+ id: m1-large
12
+ memory: "12288"
13
+ :owner_id: mockuser
14
+ :actions:
15
+ - :reboot
16
+ - :stop
@@ -0,0 +1,9 @@
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
+ :realm_id: us
8
+ :instance_profile: !ruby/object:InstanceProfile
9
+ id: m1-small
@@ -0,0 +1,9 @@
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
+ :realm_id: us
8
+ :instance_profile: !ruby/object:InstanceProfile
9
+ id: m1-large
@@ -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,78 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # Licensed to the Apache Software Foundation (ASF) under one or more
5
+ # contributor license agreements. See the NOTICE file distributed with
6
+ # this work for additional information regarding copyright ownership. The
7
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance with the
9
+ # License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
+ # License for the specific language governing permissions and limitations
17
+ # under the License.
18
+
19
+
20
+ require 'specs/spec_helper'
21
+
22
+ def prop_check(prop, value_class)
23
+ if prop.present?
24
+ prop.value.should_not be_nil
25
+ prop.value.should be_a(value_class)
26
+ end
27
+ end
28
+
29
+ describe "hardware_profiles" do
30
+
31
+ it_should_behave_like "all resources"
32
+
33
+ it "should allow retrieval of all hardware profiles" do
34
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
35
+ hardware_profiles = client.hardware_profiles
36
+ hardware_profiles.should_not be_empty
37
+ hardware_profiles.each do |hwp|
38
+ hwp.uri.should_not be_nil
39
+ hwp.uri.should be_a(String)
40
+ prop_check(hwp.architecture, String) if hwp.architecture
41
+ end
42
+ end
43
+ end
44
+
45
+ it "should allow filtering of hardware_profiles by architecture" do
46
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
47
+ hardware_profiles = client.hardware_profiles( :architecture=>'i386' )
48
+ hardware_profiles.should_not be_empty
49
+ hardware_profiles.size.should eql( 2 )
50
+ hardware_profiles.first.architecture.value.should eql( 'i386' )
51
+ end
52
+ end
53
+
54
+ it "should allow fetching a hardware_profile by id" do
55
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
56
+ hwp = client.hardware_profile( 'm1-small' )
57
+ hwp.should_not be_nil
58
+ hwp.id.should eql( 'm1-small' )
59
+ end
60
+ end
61
+
62
+ it "should allow fetching different hardware_profiles" do
63
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
64
+ hwp1 = client.hardware_profile( 'm1-small' )
65
+ hwp2 = client.hardware_profile( 'm1-xlarge' )
66
+ hwp1.storage.value.should_not eql(hwp2.storage.value)
67
+ hwp1.memory.value.should_not eql(hwp2.memory.value)
68
+ end
69
+
70
+ it "should allow fetching a hardware_profile by URI" do
71
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
72
+ hwp = client.fetch_hardware_profile( API_URL + '/hardware_profiles/m1-small' )
73
+ hwp.should_not be_nil
74
+ hwp.id.should eql( 'm1-small' )
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,105 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # Licensed to the Apache Software Foundation (ASF) under one or more
5
+ # contributor license agreements. See the NOTICE file distributed with
6
+ # this work for additional information regarding copyright ownership. The
7
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance with the
9
+ # License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
+ # License for the specific language governing permissions and limitations
17
+ # under the License.
18
+
19
+
20
+ require 'specs/spec_helper'
21
+
22
+ describe "images" do
23
+
24
+ it_should_behave_like "all resources"
25
+
26
+ it "should allow retrieval of all images" do
27
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
28
+ images = client.images
29
+ images.should_not be_empty
30
+ images.size.should eql( 3 )
31
+ images.each do |image|
32
+ image.uri.should_not be_nil
33
+ image.uri.should be_a(String)
34
+ image.description.should_not be_nil
35
+ image.description.should be_a(String)
36
+ image.architecture.should_not be_nil
37
+ image.architecture.should be_a(String)
38
+ image.owner_id.should_not be_nil
39
+ image.owner_id.should be_a(String)
40
+ end
41
+ end
42
+ end
43
+
44
+ it "should allow retrieval of my own images" do
45
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
46
+ images = client.images( :owner_id=>:self )
47
+ images.should_not be_empty
48
+ images.size.should eql( 1 )
49
+ images.each do |image|
50
+ image.uri.should_not be_nil
51
+ image.uri.should be_a(String)
52
+ image.description.should_not be_nil
53
+ image.description.should be_a(String)
54
+ image.architecture.should_not be_nil
55
+ image.architecture.should be_a(String)
56
+ image.owner_id.should_not be_nil
57
+ image.owner_id.should be_a(String)
58
+ end
59
+ end
60
+ end
61
+
62
+ it "should allow retrieval of a single image by ID" do
63
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
64
+ image = client.image( 'img1' )
65
+ image.should_not be_nil
66
+ image.uri.should eql( API_URL + '/images/img1' )
67
+ image.id.should eql( 'img1' )
68
+ image.architecture.should eql( 'x86_64' )
69
+ end
70
+ end
71
+
72
+ it "should allow retrieval of a single image by URI" do
73
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
74
+ image = client.fetch_image( API_URL + '/images/img1' )
75
+ image.should_not be_nil
76
+ image.uri.should eql( API_URL + '/images/img1' )
77
+ image.id.should eql( 'img1' )
78
+ image.architecture.should eql( 'x86_64' )
79
+ end
80
+ end
81
+
82
+ describe "filtering by architecture" do
83
+ it "return matching images" do
84
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
85
+ images = client.images( :architecture=>'x86_64' )
86
+ images.should_not be_empty
87
+ images.each do |image|
88
+ image.architecture.should eql( 'x86_64' )
89
+ end
90
+ images = client.images( :architecture=>'i386' )
91
+ images.should_not be_empty
92
+ images.each do |image|
93
+ image.architecture.should eql( 'i386' )
94
+ end
95
+ end
96
+ end
97
+
98
+ it "should return an empty array for no matches" do
99
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
100
+ images = client.images( :architecture=>'8088' )
101
+ images.should be_empty
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,60 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # Licensed to the Apache Software Foundation (ASF) under one or more
5
+ # contributor license agreements. See the NOTICE file distributed with
6
+ # this work for additional information regarding copyright ownership. The
7
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance with the
9
+ # License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
+ # License for the specific language governing permissions and limitations
17
+ # under the License.
18
+
19
+ require 'specs/spec_helper'
20
+
21
+ describe "initializing the client" do
22
+
23
+ it "should parse valid API URIs" do
24
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
25
+ client.api_host.should eql( API_HOST )
26
+ client.api_port.should eql( API_PORT.to_i )
27
+ client.api_path.should eql( API_PATH )
28
+ end
29
+
30
+ it "should discover entry points upon connection" do
31
+ DeltaCloud.new( "name", "password", API_URL ) do |client|
32
+ client.entry_points[:hardware_profiles].should eql( "#{API_URL}/hardware_profiles" )
33
+ client.entry_points[:images].should eql( "#{API_URL}/images" )
34
+ client.entry_points[:instances].should eql( "#{API_URL}/instances" )
35
+ client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage_volumes" )
36
+ client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage_snapshots" )
37
+ end
38
+ end
39
+
40
+ it "should provide the current driver name via client" do
41
+ DeltaCloud.new( "name", "password", API_URL ) do |client|
42
+ client.driver_name.should eql( 'mock' )
43
+ end
44
+ end
45
+
46
+ it "should provide the current driver name without client" do
47
+ DeltaCloud.driver_name( API_URL ).should eql( 'mock' )
48
+ end
49
+
50
+ describe "without a block" do
51
+ before( :each ) do
52
+ reload_fixtures
53
+ end
54
+ it "should connect without a block" do
55
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
56
+ client.images.should_not be_nil
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,78 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # Licensed to the Apache Software Foundation (ASF) under one or more
5
+ # contributor license agreements. See the NOTICE file distributed with
6
+ # this work for additional information regarding copyright ownership. The
7
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance with the
9
+ # License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
+ # License for the specific language governing permissions and limitations
17
+ # under the License.
18
+
19
+
20
+ require 'specs/spec_helper'
21
+
22
+ =begin
23
+ Spec::Matchers.define :include_transition do |action,to|
24
+ match do |transitions|
25
+ found = transitions.find{|e| e.action.to_s == action.to_s && e.to.to_s == to.to_s }
26
+ ! found.nil?
27
+ end
28
+ end
29
+ =end
30
+
31
+ describe "instance-states" do
32
+
33
+ it_should_behave_like "all resources"
34
+
35
+ it "should allow retrieval of instance-state information" do
36
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
37
+ instance_states = client.instance_states
38
+ instance_states.should_not be_nil
39
+ instance_states.should_not be_empty
40
+
41
+ instance_states[0].name.should eql( 'start' )
42
+ instance_states[0].transitions.size.should eql( 1 )
43
+ instance_states[0].transitions[0].should_not be_auto
44
+
45
+ instance_states[1].name.should eql( 'pending' )
46
+ instance_states[1].transitions.size.should eql( 1 )
47
+ instance_states[1].transitions[0].should be_auto
48
+
49
+ instance_states[2].name.should eql( 'running' )
50
+ instance_states[2].transitions.size.should eql( 2 )
51
+ includes_transition( instance_states[2].transitions, :reboot, :running ).should be_true
52
+ includes_transition( instance_states[2].transitions, :stop, :stopped ).should be_true
53
+ end
54
+ end
55
+
56
+ it "should allow retrieval of a single instance-state blob" do
57
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
58
+ instance_state = client.instance_state( :pending )
59
+ instance_state.should_not be_nil
60
+ instance_state.name.should eql( 'pending' )
61
+ instance_state.transitions.size.should eql( 1 )
62
+ instance_state.transitions[0].should be_auto
63
+
64
+ instance_state = client.instance_state( :running )
65
+ instance_state.name.should eql( 'running' )
66
+ instance_state.transitions.size.should eql( 2 )
67
+ includes_transition( instance_state.transitions, :reboot, :running ).should be_true
68
+ includes_transition( instance_state.transitions, :stop, :stopped ).should be_true
69
+ end
70
+ end
71
+
72
+ def includes_transition( transitions, action, to )
73
+ found = transitions.find{|e| e.action.to_s == action.to_s && e.to.to_s == to.to_s }
74
+ ! found.nil?
75
+ end
76
+
77
+
78
+ end