bbrowning-deltacloud-client 0.0.9.7-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.
@@ -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
@@ -0,0 +1,191 @@
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 "instances" do
23
+
24
+ it_should_behave_like "all resources"
25
+
26
+ it "should allow retrieval of all instances" do
27
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
28
+ instances = client.instances
29
+ instances.should_not be_empty
30
+ instances.each do |instance|
31
+ instance.uri.should_not be_nil
32
+ instance.uri.should be_a( String )
33
+ instance.owner_id.should_not be_nil
34
+ instance.owner_id.should be_a( String )
35
+ instance.image.should_not be_nil
36
+ instance.image.should be_a( DeltaCloud::API::Image )
37
+ instance.hardware_profile.should_not be_nil
38
+ instance.hardware_profile.should be_a( DeltaCloud::API::HardwareProfile )
39
+ instance.state.should_not be_nil
40
+ instance.state.should be_a( String )
41
+ instance.public_addresses.should_not be_nil
42
+ instance.public_addresses.should_not be_empty
43
+ instance.public_addresses.should be_a( Array )
44
+ instance.private_addresses.should_not be_nil
45
+ instance.private_addresses.should_not be_empty
46
+ instance.private_addresses.should be_a( Array )
47
+ end
48
+ end
49
+ end
50
+
51
+ it "should allow navigation from instance to image" do
52
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
53
+ instances = client.instances
54
+ instances.should_not be_empty
55
+ instance = instances.first
56
+ instance.image.should_not be_nil
57
+ instance.image.description.should_not be_nil
58
+ instance.image.description.should be_a(String)
59
+ end
60
+ end
61
+
62
+ it "should allow retrieval of a single instance" do
63
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
64
+ instance = client.instance( "inst0" )
65
+ instance.should_not be_nil
66
+ instance.name.should_not be_nil
67
+ instance.name.should eql( 'Mock Instance With Profile Change' )
68
+ instance.uri.should_not be_nil
69
+ instance.uri.should be_a( String )
70
+ instance.owner_id.should eql( "mockuser" )
71
+ instance.public_addresses.first.should eql( "img1.inst0.public.com" )
72
+ instance.image.should_not be_nil
73
+ instance.image.uri.should eql( API_URL + "/images/img1" )
74
+ instance.hardware_profile.should_not be_nil
75
+ instance.hardware_profile.should_not be_nil
76
+ instance.hardware_profile.uri.should eql( API_URL + "/hardware_profiles/m1-large" )
77
+ instance.hardware_profile.memory.value.should eql(10240.0)
78
+ instance.hardware_profile.storage.value.should eql(850.0)
79
+ instance.state.should eql( "RUNNING" )
80
+ instance.actions.should_not be_nil
81
+ end
82
+ end
83
+
84
+ it "should allow creation of new instances with reasonable defaults" do
85
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
86
+ instance = client.create_instance( 'img1', :name=>'TestInstance' )
87
+ instance.should_not be_nil
88
+ instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} )
89
+ instance.id.should match( /inst[0-9]+/ )
90
+ instance.name.should eql( 'TestInstance' )
91
+ instance.image.id.should eql( 'img1' )
92
+ instance.hardware_profile.id.should eql( 'm1-large' )
93
+ instance.realm.id.should eql( 'us' )
94
+ end
95
+ end
96
+
97
+ it "should allow creation of new instances with specific realm" do
98
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
99
+ instance = client.create_instance( 'img1', :realm=>'eu' )
100
+ instance.should_not be_nil
101
+ instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} )
102
+ instance.id.should match( /inst[0-9]+/ )
103
+ instance.image.id.should eql( 'img1' )
104
+ instance.hardware_profile.id.should eql( 'm1-large' )
105
+ instance.realm.id.should eql( 'eu' )
106
+ end
107
+ end
108
+
109
+ it "should allow creation of new instances with specific hardware profile" do
110
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
111
+ instance = client.create_instance( 'img1',
112
+ :hardware_profile=>'m1-xlarge' )
113
+ instance.should_not be_nil
114
+ instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} )
115
+ instance.id.should match( /inst[0-9]+/ )
116
+ instance.image.id.should eql( 'img1' )
117
+ instance.hardware_profile.id.should eql( 'm1-xlarge' )
118
+ instance.realm.id.should eql( 'us' )
119
+ end
120
+ end
121
+
122
+ it "should allow creation of new instances with specific hardware profile overriding memory" do
123
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
124
+ hwp = { :id => 'm1-xlarge', :memory => 32768 }
125
+ instance = client.create_instance( 'img1', :hardware_profile=> hwp )
126
+ instance.should_not be_nil
127
+ instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} )
128
+ instance.id.should match( /inst[0-9]+/ )
129
+ instance.image.id.should eql( 'img1' )
130
+ instance.hardware_profile.id.should eql( 'm1-xlarge' )
131
+ instance.hardware_profile.memory.value.should eql(12288.0)
132
+ instance.realm.id.should eql( 'us' )
133
+ end
134
+ end
135
+
136
+ it "should allow creation of new instances with specific realm and hardware profile" do
137
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
138
+ instance = client.create_instance( 'img1', :realm=>'eu',
139
+ :hardware_profile=>'m1-xlarge' )
140
+ instance.should_not be_nil
141
+ instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} )
142
+ instance.id.should match( /inst[0-9]+/ )
143
+ instance.image.id.should eql( 'img1' )
144
+ instance.hardware_profile.id.should eql( 'm1-xlarge' )
145
+ instance.realm.id.should eql( 'eu' )
146
+ end
147
+ end
148
+
149
+ it "should allow fetching of instances by id" do
150
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
151
+ instance = client.instance( 'inst1' )
152
+ instance.should_not be_nil
153
+ instance.uri.should_not be_nil
154
+ instance.uri.should be_a( String )
155
+ end
156
+ end
157
+
158
+ it "should allow fetching of instances by URI" do
159
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
160
+ instance = client.fetch_instance( API_URL + '/instances/inst1' )
161
+ instance.should_not be_nil
162
+ instance.uri.should eql( API_URL + '/instances/inst1' )
163
+ instance.id.should eql( 'inst1' )
164
+ end
165
+ end
166
+
167
+ describe "performing actions on instances" do
168
+ it "should allow actions that are valid" do
169
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
170
+ instance = client.instance( 'inst1' )
171
+ instance.should_not be_nil
172
+ instance.state.should eql( "RUNNING" )
173
+ instance.uri.should eql( API_URL + '/instances/inst1' )
174
+ instance.id.should eql( 'inst1' )
175
+ instance.stop!
176
+ instance.state.should eql( "STOPPED" )
177
+ instance.start!
178
+ instance.state.should eql( "RUNNING" )
179
+ end
180
+ end
181
+
182
+ it "should not allow actions that are invalid" do
183
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
184
+ instance = client.instance( 'inst1' )
185
+ instance.should_not be_nil
186
+ instance.state.should eql( "RUNNING" )
187
+ lambda{instance.start}.should raise_error
188
+ end
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,64 @@
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 "realms" do
22
+
23
+ it_should_behave_like "all resources"
24
+
25
+ it "should allow retrieval of all realms" do
26
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
27
+ realms = client.realms
28
+ realms.should_not be_empty
29
+ realms.each do |realm|
30
+ realm.uri.should_not be_nil
31
+ realm.uri.should be_a(String)
32
+ realm.id.should_not be_nil
33
+ realm.id.should be_a(String)
34
+ realm.name.should_not be_nil
35
+ realm.name.should be_a(String)
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ it "should allow fetching a realm by id" do
42
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
43
+ realm = client.realm( 'us' )
44
+ realm.should_not be_nil
45
+ realm.id.should eql( 'us' )
46
+ realm.name.should eql( 'United States' )
47
+ realm.state.should eql( 'AVAILABLE' )
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
+ end
54
+ end
55
+
56
+ it "should allow fetching a realm by URI" do
57
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
58
+ realm = client.fetch_realm( API_URL + '/realms/us' )
59
+ realm.should_not be_nil
60
+ realm.id.should eql( 'us' )
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,30 @@
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
+ shared_examples_for "all resources" do
21
+
22
+ before(:each) do
23
+ reload_fixtures
24
+ end
25
+
26
+ after(:each) do
27
+ #clean_fixtures
28
+ end
29
+
30
+ end
@@ -0,0 +1,52 @@
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 'rubygems'
20
+ require 'yaml'
21
+ require 'fileutils'
22
+
23
+ api_host = ENV['API_HOST']
24
+ ( api_host = 'localhost' ) if api_host.nil?
25
+ ( api_host = 'localhost' ) if api_host == ''
26
+
27
+ api_port = ENV['API_PORT']
28
+ ( api_port = 3001 ) if api_port.nil?
29
+ ( api_port = 3001 ) if api_port == ''
30
+
31
+ API_HOST = api_host
32
+ API_PORT = api_port
33
+ API_PATH = '/api'
34
+
35
+ API_URL = "http://#{API_HOST}:#{API_PORT}#{API_PATH}"
36
+ API_NAME = 'mockuser'
37
+ API_PASSWORD = 'mockpassword'
38
+
39
+ $: << File.dirname( __FILE__ ) + '/../lib'
40
+ require 'deltacloud'
41
+
42
+ def clean_fixtures
43
+ FileUtils.rm_rf( File.dirname( __FILE__ ) + '/data' )
44
+ end
45
+
46
+ def reload_fixtures
47
+ clean_fixtures
48
+ FileUtils.cp_r( File.dirname( __FILE__) + '/fixtures', File.dirname( __FILE__ ) + '/data' )
49
+ end
50
+
51
+ $: << File.dirname( __FILE__ )
52
+ require 'shared/resources'