knife-google 1.1.0 → 1.2.0
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.
- checksums.yaml +15 -0
- data/README.md +155 -66
- data/knife-google.gemspec +2 -1
- data/lib/chef/knife/google_base.rb +1 -1
- data/lib/chef/knife/google_disk_create.rb +17 -9
- data/lib/chef/knife/google_disk_delete.rb +2 -2
- data/lib/chef/knife/google_disk_list.rb +8 -8
- data/lib/chef/knife/google_project_list.rb +178 -0
- data/lib/chef/knife/google_region_list.rb +125 -0
- data/lib/chef/knife/google_server_create.rb +174 -46
- data/lib/chef/knife/google_server_delete.rb +9 -13
- data/lib/chef/knife/google_server_list.rb +5 -6
- data/lib/chef/knife/google_zone_list.rb +22 -28
- data/lib/google/compute.rb +2 -1
- data/lib/google/compute/client.rb +12 -7
- data/lib/google/compute/creatable_resource_collection.rb +12 -1
- data/lib/google/compute/disk.rb +0 -2
- data/lib/google/compute/image.rb +1 -2
- data/lib/google/compute/project.rb +2 -2
- data/lib/google/compute/{kernel.rb → region.rb} +12 -1
- data/lib/google/compute/region_operation.rb +62 -0
- data/lib/google/compute/server.rb +3 -2
- data/lib/google/compute/server/attached_disk.rb +3 -3
- data/lib/google/compute/zone.rb +6 -4
- data/lib/google/compute/zone_operation.rb +11 -9
- data/lib/knife-google/version.rb +1 -1
- data/spec/chef/knife/google_base_spec.rb +4 -4
- data/spec/chef/knife/google_disk_create_spec.rb +8 -7
- data/spec/chef/knife/google_disk_delete_spec.rb +15 -16
- data/spec/chef/knife/google_disk_list_spec.rb +6 -6
- data/spec/chef/knife/google_region_list_spec.rb +32 -0
- data/spec/chef/knife/google_server_create_spec.rb +78 -44
- data/spec/chef/knife/google_server_delete_spec.rb +37 -37
- data/spec/chef/knife/google_server_list_spec.rb +8 -7
- data/spec/chef/knife/google_setup_spec.rb +1 -2
- data/spec/chef/knife/google_zone_list_spec.rb +4 -4
- data/spec/data/{compute-v1beta15.json → compute-v1.json} +700 -246
- data/spec/data/disk.json +3 -4
- data/spec/data/firewall.json +2 -2
- data/spec/data/global_operation.json +3 -3
- data/spec/data/image.json +2 -2
- data/spec/data/machine_type.json +1 -1
- data/spec/data/network.json +1 -1
- data/spec/data/project.json +1 -1
- data/spec/data/region.json +23 -0
- data/spec/data/serial_port_output.json +1 -1
- data/spec/data/server.json +7 -7
- data/spec/data/snapshot.json +2 -2
- data/spec/data/zone.json +7 -15
- data/spec/data/zone_operation.json +3 -3
- data/spec/google/compute/disk_spec.rb +32 -32
- data/spec/google/compute/firewall_spec.rb +37 -37
- data/spec/google/compute/global_operation_spec.rb +9 -9
- data/spec/google/compute/image_spec.rb +17 -17
- data/spec/google/compute/machine_type_spec.rb +7 -7
- data/spec/google/compute/network_spec.rb +14 -14
- data/spec/google/compute/project_spec.rb +17 -17
- data/spec/google/compute/region_spec.rb +51 -0
- data/spec/google/compute/server_spec.rb +35 -42
- data/spec/google/compute/snapshot_spec.rb +11 -11
- data/spec/google/compute/zone_operation_spec.rb +9 -9
- data/spec/google/compute/zone_spec.rb +7 -7
- data/spec/spec_helper.rb +1 -0
- data/spec/support/mocks.rb +10 -10
- data/spec/support/resource_examples.rb +7 -7
- data/spec/support/spec_google_base.rb +4 -0
- metadata +14 -26
- data/spec/data/kernel.json +0 -15
- data/spec/google/compute/kernel_spec.rb +0 -49
@@ -16,9 +16,9 @@ require 'spec_helper'
|
|
16
16
|
describe Google::Compute::GlobalOperation do
|
17
17
|
|
18
18
|
before(:each) do
|
19
|
-
@mock_api_client=
|
20
|
-
@mock_api_client.stub
|
21
|
-
Google::APIClient.stub
|
19
|
+
@mock_api_client=double(Google::APIClient, :authorization= => {}, :auto_refresh_token= => {})
|
20
|
+
@mock_api_client.stub(:discovered_api).and_return(mock_compute)
|
21
|
+
Google::APIClient.stub(:new).and_return(@mock_api_client)
|
22
22
|
end
|
23
23
|
|
24
24
|
let(:client) do
|
@@ -29,8 +29,8 @@ describe Google::Compute::GlobalOperation do
|
|
29
29
|
|
30
30
|
it '#list should return an array of global operations' do
|
31
31
|
@mock_api_client.should_receive(:execute).
|
32
|
-
with(:api_method=>mock_compute.global_operations.list,
|
33
|
-
:parameters=>{ :project=>'mock-project'}
|
32
|
+
with(:api_method => mock_compute.global_operations.list,
|
33
|
+
:parameters => { :project => 'mock-project'}, :body_object => nil).
|
34
34
|
and_return(mock_response(Google::Compute::GlobalOperation, true))
|
35
35
|
|
36
36
|
operations = client.globalOperations.list
|
@@ -40,8 +40,8 @@ describe Google::Compute::GlobalOperation do
|
|
40
40
|
|
41
41
|
it '#get should return an individual global operation' do
|
42
42
|
@mock_api_client.should_receive(:execute).
|
43
|
-
with(:api_method=>mock_compute.global_operations.get,
|
44
|
-
:parameters=>{'globalOperation'=>'mock-global-operation', :project=>'mock-project'}
|
43
|
+
with(:api_method => mock_compute.global_operations.get,
|
44
|
+
:parameters => {'globalOperation' => 'mock-global-operation', :project => 'mock-project'}, :body_object => nil).
|
45
45
|
and_return(mock_response(Google::Compute::GlobalOperation))
|
46
46
|
|
47
47
|
operation = client.globalOperations.get('mock-global-operation')
|
@@ -53,8 +53,8 @@ describe Google::Compute::GlobalOperation do
|
|
53
53
|
|
54
54
|
it '#delete should delete an existing global operation' do
|
55
55
|
@mock_api_client.should_receive(:execute).
|
56
|
-
with(:api_method=>mock_compute.global_operations.delete,
|
57
|
-
:parameters=>{'globalOperation'=>'mock-global-operation', :project=>'mock-project'}
|
56
|
+
with(:api_method => mock_compute.global_operations.delete,
|
57
|
+
:parameters => {'globalOperation' => 'mock-global-operation', :project => 'mock-project'}, :body_object => nil).
|
58
58
|
and_return(mock_response)
|
59
59
|
|
60
60
|
client.globalOperations.delete('mock-global-operation')
|
@@ -16,9 +16,9 @@ require 'spec_helper'
|
|
16
16
|
describe Google::Compute::Image do
|
17
17
|
|
18
18
|
before(:each) do
|
19
|
-
@mock_api_client=
|
20
|
-
@mock_api_client.stub
|
21
|
-
Google::APIClient.stub
|
19
|
+
@mock_api_client=double(Google::APIClient, :authorization= => {}, :auto_refresh_token= => {})
|
20
|
+
@mock_api_client.stub(:discovered_api).and_return(mock_compute)
|
21
|
+
Google::APIClient.stub(:new).and_return(@mock_api_client)
|
22
22
|
end
|
23
23
|
|
24
24
|
let(:client) do
|
@@ -29,8 +29,8 @@ describe Google::Compute::Image do
|
|
29
29
|
|
30
30
|
it '#get should return an individual image' do
|
31
31
|
@mock_api_client.should_receive(:execute).
|
32
|
-
with(:api_method=>mock_compute.images.get,
|
33
|
-
:parameters=>{'image'=>'mock-image', :project=>'mock-project'}
|
32
|
+
with(:api_method => mock_compute.images.get,
|
33
|
+
:parameters => {'image' => 'mock-image', :project => 'mock-project'}, :body_object => nil).
|
34
34
|
and_return(mock_response(Google::Compute::Image))
|
35
35
|
image = client.images.get('mock-image')
|
36
36
|
image.should be_a_kind_of Google::Compute::Image
|
@@ -41,8 +41,8 @@ describe Google::Compute::Image do
|
|
41
41
|
|
42
42
|
it '#list should return an array of images' do
|
43
43
|
@mock_api_client.should_receive(:execute).
|
44
|
-
with(:api_method=>mock_compute.images.list,
|
45
|
-
:parameters=>{ :project=>'mock-project'}
|
44
|
+
with(:api_method => mock_compute.images.list,
|
45
|
+
:parameters => { :project => 'mock-project'}, :body_object => nil).
|
46
46
|
and_return(mock_response(Google::Compute::Image, true))
|
47
47
|
images = client.images.list
|
48
48
|
images.should_not be_empty
|
@@ -51,23 +51,23 @@ describe Google::Compute::Image do
|
|
51
51
|
it '#create should create a new image' do
|
52
52
|
storage = 'https://www.googleapis.com/storage/projects/mock-project/bucket/object'
|
53
53
|
@mock_api_client.should_receive(:execute).
|
54
|
-
with(:api_method=>mock_compute.images.insert,
|
55
|
-
:parameters=>{ :project=>'mock-project'},
|
56
|
-
:body_object=>{:name=>'mock-image',
|
57
|
-
:rawDisk=>{'containerType'=>'TAR','source'=>storage},
|
58
|
-
:sourceType=>'RAW'}).
|
54
|
+
with(:api_method => mock_compute.images.insert,
|
55
|
+
:parameters => { :project => 'mock-project'},
|
56
|
+
:body_object => {:name => 'mock-image',
|
57
|
+
:rawDisk => {'containerType' => 'TAR', 'source' => storage},
|
58
|
+
:sourceType => 'RAW'}).
|
59
59
|
and_return(mock_response(Google::Compute::GlobalOperation))
|
60
|
-
o = client.images.create(:name=>'mock-image',
|
61
|
-
:rawDisk=>{'containerType'=>'TAR','source'=>storage},
|
62
|
-
:sourceType=>'RAW')
|
60
|
+
o = client.images.create(:name => 'mock-image',
|
61
|
+
:rawDisk => {'containerType' => 'TAR', 'source' => storage},
|
62
|
+
:sourceType => 'RAW')
|
63
63
|
|
64
64
|
o.should be_a_kind_of Google::Compute::GlobalOperation
|
65
65
|
end
|
66
66
|
|
67
67
|
it '#delete should delete an existing image' do
|
68
68
|
@mock_api_client.should_receive(:execute).
|
69
|
-
with(:api_method=>mock_compute.images.delete,
|
70
|
-
:parameters=>{ :project=>'mock-project','image'=>'mock-image'}
|
69
|
+
with(:api_method => mock_compute.images.delete,
|
70
|
+
:parameters => { :project => 'mock-project', 'image' => 'mock-image'}, :body_object => nil).
|
71
71
|
and_return(mock_response(Google::Compute::GlobalOperation))
|
72
72
|
o = client.images.delete('mock-image')
|
73
73
|
o.should be_a_kind_of Google::Compute::GlobalOperation
|
@@ -18,9 +18,9 @@ require 'spec_helper'
|
|
18
18
|
describe Google::Compute::MachineType do
|
19
19
|
|
20
20
|
before(:each) do
|
21
|
-
@mock_api_client=
|
22
|
-
@mock_api_client.stub
|
23
|
-
Google::APIClient.stub
|
21
|
+
@mock_api_client=double(Google::APIClient, :authorization= => {}, :auto_refresh_token= => {})
|
22
|
+
@mock_api_client.stub(:discovered_api).and_return(mock_compute)
|
23
|
+
Google::APIClient.stub(:new).and_return(@mock_api_client)
|
24
24
|
end
|
25
25
|
|
26
26
|
let(:client) do
|
@@ -32,8 +32,8 @@ describe Google::Compute::MachineType do
|
|
32
32
|
it '#get should return an individual machine types' do
|
33
33
|
|
34
34
|
@mock_api_client.should_receive(:execute).
|
35
|
-
with(:api_method=>mock_compute.machine_types.get,
|
36
|
-
:parameters=>{'machineType'=>'mock-machine-type', :project=>'mock-project'}
|
35
|
+
with(:api_method => mock_compute.machine_types.get,
|
36
|
+
:parameters => {'machineType' => 'mock-machine-type', :project => 'mock-project'}, :body_object => nil).
|
37
37
|
and_return(mock_response(Google::Compute::MachineType))
|
38
38
|
|
39
39
|
machine_type = client.machine_types.get('mock-machine-type')
|
@@ -43,8 +43,8 @@ describe Google::Compute::MachineType do
|
|
43
43
|
end
|
44
44
|
it '#list should return an array of machine types' do
|
45
45
|
@mock_api_client.should_receive(:execute).
|
46
|
-
with(:api_method=>mock_compute.machine_types.list,
|
47
|
-
:parameters=>{ :project=>'mock-project'}
|
46
|
+
with(:api_method => mock_compute.machine_types.list,
|
47
|
+
:parameters => { :project => 'mock-project'}, :body_object => nil).
|
48
48
|
and_return(mock_response(Google::Compute::MachineType, true))
|
49
49
|
mts = client.machine_types.list
|
50
50
|
mts.should_not be_empty
|
@@ -16,9 +16,9 @@ require 'spec_helper'
|
|
16
16
|
describe Google::Compute::Network do
|
17
17
|
|
18
18
|
before(:each) do
|
19
|
-
@mock_api_client=
|
20
|
-
@mock_api_client.stub
|
21
|
-
Google::APIClient.stub
|
19
|
+
@mock_api_client=double(Google::APIClient, :authorization= => {}, :auto_refresh_token= => {})
|
20
|
+
@mock_api_client.stub(:discovered_api).and_return(mock_compute)
|
21
|
+
Google::APIClient.stub(:new).and_return(@mock_api_client)
|
22
22
|
end
|
23
23
|
|
24
24
|
let(:client) do
|
@@ -26,11 +26,11 @@ describe Google::Compute::Network do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it_should_behave_like Google::Compute::Resource
|
29
|
-
|
29
|
+
|
30
30
|
it '#get should return an individual network' do
|
31
31
|
@mock_api_client.should_receive(:execute).
|
32
|
-
with(:api_method=>mock_compute.networks.get,
|
33
|
-
:parameters=>{'network'=>'mock-network', :project=>'mock-project'}
|
32
|
+
with(:api_method => mock_compute.networks.get,
|
33
|
+
:parameters => {'network' => 'mock-network', :project => 'mock-project'}, :body_object => nil).
|
34
34
|
and_return(mock_response(Google::Compute::Network))
|
35
35
|
network = client.networks.get('mock-network')
|
36
36
|
network.should be_a_kind_of Google::Compute::Network
|
@@ -40,8 +40,8 @@ describe Google::Compute::Network do
|
|
40
40
|
|
41
41
|
it '#list should return an array of networks' do
|
42
42
|
@mock_api_client.should_receive(:execute).
|
43
|
-
with(:api_method=>mock_compute.networks.list,
|
44
|
-
:parameters=>{ :project=>'mock-project'}
|
43
|
+
with(:api_method => mock_compute.networks.list,
|
44
|
+
:parameters => { :project => 'mock-project'}, :body_object => nil).
|
45
45
|
and_return(mock_response(Google::Compute::Network, true))
|
46
46
|
networks = client.networks.list
|
47
47
|
networks.should_not be_empty
|
@@ -50,18 +50,18 @@ describe Google::Compute::Network do
|
|
50
50
|
|
51
51
|
it '#create should create a new network' do
|
52
52
|
@mock_api_client.should_receive(:execute).
|
53
|
-
with(:api_method=>mock_compute.networks.insert,
|
54
|
-
:parameters=>{ :project=>'mock-project'},
|
55
|
-
:body_object=>{:name=>'mock-network', :IPv4Range=>'122.12.0.0/16'}).
|
53
|
+
with(:api_method => mock_compute.networks.insert,
|
54
|
+
:parameters => { :project => 'mock-project'},
|
55
|
+
:body_object => {:name => 'mock-network', :IPv4Range => '122.12.0.0/16'}).
|
56
56
|
and_return(mock_response(Google::Compute::GlobalOperation))
|
57
|
-
o = client.networks.create(:name=>'mock-network', :IPv4Range=>'122.12.0.0/16')
|
57
|
+
o = client.networks.create(:name => 'mock-network', :IPv4Range => '122.12.0.0/16')
|
58
58
|
o.should be_a_kind_of Google::Compute::GlobalOperation
|
59
59
|
end
|
60
60
|
|
61
61
|
it '#delete should delete an existing network' do
|
62
62
|
@mock_api_client.should_receive(:execute).
|
63
|
-
with(:api_method=>mock_compute.networks.delete,
|
64
|
-
:parameters=>{'network'=>'mock-network', :project=>'mock-project'}
|
63
|
+
with(:api_method => mock_compute.networks.delete,
|
64
|
+
:parameters => {'network' => 'mock-network', :project => 'mock-project'}, :body_object => nil).
|
65
65
|
and_return(mock_response(Google::Compute::GlobalOperation))
|
66
66
|
client.networks.delete('mock-network')
|
67
67
|
end
|
@@ -16,9 +16,9 @@ require 'spec_helper'
|
|
16
16
|
describe Google::Compute::Project do
|
17
17
|
|
18
18
|
before(:each) do
|
19
|
-
@mock_api_client=
|
20
|
-
@mock_api_client.stub
|
21
|
-
Google::APIClient.stub
|
19
|
+
@mock_api_client=double(Google::APIClient, :authorization= => {}, :auto_refresh_token= => {})
|
20
|
+
@mock_api_client.stub(:discovered_api).and_return(mock_compute)
|
21
|
+
Google::APIClient.stub(:new).and_return(@mock_api_client)
|
22
22
|
end
|
23
23
|
|
24
24
|
let(:client) do
|
@@ -29,8 +29,8 @@ describe Google::Compute::Project do
|
|
29
29
|
|
30
30
|
it '#get should return an individual project' do
|
31
31
|
@mock_api_client.should_receive(:execute).
|
32
|
-
with(:api_method=>mock_compute.projects.get,
|
33
|
-
:parameters=>{:project=>'mock-project','project'=>'mock-project'}
|
32
|
+
with(:api_method => mock_compute.projects.get,
|
33
|
+
:parameters => {:project => 'mock-project', 'project' => 'mock-project'}, :body_object => nil).
|
34
34
|
and_return(mock_response(Google::Compute::Project))
|
35
35
|
project = client.projects.get('mock-project')
|
36
36
|
project.should be_a_kind_of Google::Compute::Project
|
@@ -44,28 +44,28 @@ describe Google::Compute::Project do
|
|
44
44
|
|
45
45
|
let(:project) do
|
46
46
|
Google::Compute::Project.new(mock_hash(Google::Compute::Project).
|
47
|
-
|
47
|
+
merge(:dispatcher => client.dispatcher))
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should be able to add common instance metadata' do
|
51
51
|
@mock_api_client.should_receive(:execute).
|
52
|
-
with(:api_method=>mock_compute.projects.set_common_instance_metadata,
|
53
|
-
|
54
|
-
|
55
|
-
'items'=>[{'key'=>'mock-key', 'value'=>'mock-value'},
|
56
|
-
{'key'=>'testKey', 'value'=>'testValue'}]}).
|
52
|
+
with(:api_method => mock_compute.projects.set_common_instance_metadata,
|
53
|
+
:parameters => {:project => 'mock-project'},
|
54
|
+
:body_object => {'kind' => 'compute#metadata',
|
55
|
+
'items' => [{'key' => 'mock-key', 'value' => 'mock-value'},
|
56
|
+
{'key' => 'testKey', 'value' => 'testValue'}]}).
|
57
57
|
and_return(mock_response)
|
58
|
-
project.add_common_instance_metadata!('testKey'=>'testValue')
|
58
|
+
project.add_common_instance_metadata!('testKey' => 'testValue')
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should be able to remove common instance metadata' do
|
62
62
|
@mock_api_client.should_receive(:execute).
|
63
|
-
with(:api_method=>mock_compute.projects.set_common_instance_metadata,
|
64
|
-
|
65
|
-
|
66
|
-
'items'=>[]}).
|
63
|
+
with(:api_method => mock_compute.projects.set_common_instance_metadata,
|
64
|
+
:parameters => {:project => 'mock-project'},
|
65
|
+
:body_object => {'kind' => 'compute#metadata',
|
66
|
+
'items' => []}).
|
67
67
|
and_return(mock_response)
|
68
|
-
project.remove_common_instance_metadata!('mock-key'=>'mock-value')
|
68
|
+
project.remove_common_instance_metadata!('mock-key' => 'mock-value')
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
describe Google::Compute::Region do
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
@mock_api_client=double(Google::APIClient, :authorization= => {}, :auto_refresh_token= => {})
|
21
|
+
@mock_api_client.stub(:discovered_api).and_return(mock_compute)
|
22
|
+
Google::APIClient.stub(:new).and_return(@mock_api_client)
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:client) do
|
26
|
+
Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like Google::Compute::Resource
|
30
|
+
|
31
|
+
it '#get should return an individual region' do
|
32
|
+
@mock_api_client.should_receive(:execute).
|
33
|
+
with(:api_method => mock_compute.regions.get,
|
34
|
+
:parameters => {"region" => "mock-region", :project => "mock-project"}, :body_object => nil).
|
35
|
+
and_return(mock_response(Google::Compute::Region))
|
36
|
+
region = client.regions.get('mock-region')
|
37
|
+
region.should be_a_kind_of Google::Compute::Region
|
38
|
+
region.name.should eq('mock-region')
|
39
|
+
end
|
40
|
+
|
41
|
+
it '#list should return an array of regions' do
|
42
|
+
@mock_api_client.should_receive(:execute).
|
43
|
+
with(:api_method => mock_compute.regions.list,
|
44
|
+
:parameters => {:project => 'mock-project'}, :body_object => nil).
|
45
|
+
and_return(mock_response(Google::Compute::Region, true))
|
46
|
+
regions = client.regions.list
|
47
|
+
regions.should_not be_empty
|
48
|
+
regions.all?{|region| region.is_a?(Google::Compute::Region)}.should be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -16,9 +16,9 @@ require 'spec_helper'
|
|
16
16
|
describe Google::Compute::Server do
|
17
17
|
|
18
18
|
before(:each) do
|
19
|
-
@mock_api_client=
|
20
|
-
@mock_api_client.stub
|
21
|
-
Google::APIClient.stub
|
19
|
+
@mock_api_client=double(Google::APIClient, :authorization= => {}, :auto_refresh_token= => {})
|
20
|
+
@mock_api_client.stub(:discovered_api).and_return(mock_compute)
|
21
|
+
Google::APIClient.stub(:new).and_return(@mock_api_client)
|
22
22
|
end
|
23
23
|
|
24
24
|
let(:client) do
|
@@ -29,10 +29,10 @@ describe Google::Compute::Server do
|
|
29
29
|
|
30
30
|
it '#get should return an individual Server' do
|
31
31
|
@mock_api_client.should_receive(:execute).
|
32
|
-
with(:api_method=>mock_compute.instances.get,
|
33
|
-
:parameters=>{:instance=>'mock-instance', :project=>'mock-project', :zone=>'mock-zone'}
|
32
|
+
with(:api_method => mock_compute.instances.get,
|
33
|
+
:parameters => {:instance => 'mock-instance', :project => 'mock-project', :zone => 'mock-zone'}, :body_object => nil).
|
34
34
|
and_return(mock_response(Google::Compute::Server))
|
35
|
-
instance = client.instances.get(:name=>'mock-instance', :zone=>'mock-zone')
|
35
|
+
instance = client.instances.get(:name => 'mock-instance', :zone => 'mock-zone')
|
36
36
|
instance.should be_a_kind_of Google::Compute::Server
|
37
37
|
instance.name.should eq('mock-instance')
|
38
38
|
instance.disks.should be_a_kind_of(Array)
|
@@ -41,57 +41,50 @@ describe Google::Compute::Server do
|
|
41
41
|
|
42
42
|
it '#list should return an array of Servers' do
|
43
43
|
@mock_api_client.should_receive(:execute).
|
44
|
-
with(:api_method=>mock_compute.instances.list,
|
45
|
-
:parameters=>{:project=>'mock-project', :zone=>'mock-zone'}
|
46
|
-
and_return(mock_response(Google::Compute::Server,true))
|
47
|
-
instances = client.instances.list(:zone=>'mock-zone')
|
44
|
+
with(:api_method => mock_compute.instances.list,
|
45
|
+
:parameters => {:project => 'mock-project', :zone => 'mock-zone'}, :body_object => nil).
|
46
|
+
and_return(mock_response(Google::Compute::Server, true))
|
47
|
+
instances = client.instances.list(:zone => 'mock-zone')
|
48
48
|
instances.should_not be_empty
|
49
49
|
instances.all?{|i| i.is_a?(Google::Compute::Server)}.should be_true
|
50
50
|
end
|
51
51
|
|
52
52
|
it '#create should create an server' do
|
53
|
-
project_url ='https://www.googleapis.com/compute/
|
53
|
+
project_url ='https://www.googleapis.com/compute/v1/projects/mock-project'
|
54
54
|
zone = project_url + '/zones/europe-west1-a'
|
55
55
|
disk = project_url + zone + '/disks/mock-disk'
|
56
56
|
machine_type = project_url + '/global/machineTypes/n1-highcpu-2'
|
57
|
-
image = 'https://www.googleapis.com/compute/
|
57
|
+
image = 'https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7'
|
58
58
|
network = project_url + '/global/networks/api-network'
|
59
59
|
access_config = {'name' => 'External NAT', 'type' => 'ONE_TO_ONE_NAT'}
|
60
60
|
|
61
61
|
@mock_api_client.should_receive(:execute).
|
62
|
-
with(:api_method=>mock_compute.instances.insert,
|
63
|
-
:parameters=>{:project=>'mock-project', :zone=>'mock-zone'},
|
64
|
-
:body_object=>{:name =>'mock-instance',
|
62
|
+
with(:api_method => mock_compute.instances.insert,
|
63
|
+
:parameters => {:project => 'mock-project', :zone => 'mock-zone'},
|
64
|
+
:body_object => {:name => 'mock-instance',
|
65
65
|
:image => image,
|
66
66
|
:zone => 'mock-zone',
|
67
67
|
:disks => [disk],
|
68
68
|
:machineType => machine_type,
|
69
|
-
:metadata =>{'items'=>[{'key'=>'someKey','value'=>'someValue'}]},
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:disks=>[disk],
|
80
|
-
:metadata=>{'items'=>[{'key'=>'someKey','value'=>'someValue'}]},
|
81
|
-
:zone=>'mock-zone',
|
82
|
-
:networkInterfaces => [{'network'=>network,
|
83
|
-
'accessConfigs' => [access_config]
|
84
|
-
}]
|
85
|
-
)
|
69
|
+
:metadata => {'items' => [{'key' => 'someKey', 'value' => 'someValue'}]},
|
70
|
+
:networkInterfaces => [{'network' => network, 'accessConfigs' => [access_config]}]
|
71
|
+
}).and_return(mock_response(Google::Compute::ZoneOperation))
|
72
|
+
o = client.instances.create(:name => 'mock-instance',
|
73
|
+
:image => image,
|
74
|
+
:zone => 'mock-zone',
|
75
|
+
:disks => [disk],
|
76
|
+
:machineType => machine_type,
|
77
|
+
:metadata => {'items' => [{'key' => 'someKey', 'value' => 'someValue'}]},
|
78
|
+
:networkInterfaces => [{'network' => network, 'accessConfigs' => [access_config]}])
|
86
79
|
end
|
87
80
|
|
88
81
|
it '#delete should delete an server' do
|
89
82
|
@mock_api_client.should_receive(:execute).
|
90
|
-
with(:api_method=>mock_compute.instances.delete,
|
91
|
-
:parameters=>{:project=>'mock-project', :instance=>'mock-instance', :zone=>'mock-zone'},
|
92
|
-
:body_object=>nil).
|
83
|
+
with(:api_method => mock_compute.instances.delete,
|
84
|
+
:parameters => {:project => 'mock-project', :instance => 'mock-instance', :zone => 'mock-zone'},
|
85
|
+
:body_object => nil).
|
93
86
|
and_return(mock_response(Google::Compute::ZoneOperation))
|
94
|
-
o = client.instances.delete(:instance=>'mock-instance', :zone=>'mock-zone')
|
87
|
+
o = client.instances.delete(:instance => 'mock-instance', :zone => 'mock-zone')
|
95
88
|
end
|
96
89
|
|
97
90
|
describe 'with a specific server' do
|
@@ -102,7 +95,7 @@ describe Google::Compute::Server do
|
|
102
95
|
|
103
96
|
let(:instance) do
|
104
97
|
Google::Compute::Server.new(mock_hash(Google::Compute::Server).
|
105
|
-
|
98
|
+
merge(:dispatcher => client.dispatcher))
|
106
99
|
end
|
107
100
|
|
108
101
|
it '#addAccessConfig should add access config to an existing server' do
|
@@ -112,12 +105,12 @@ describe Google::Compute::Server do
|
|
112
105
|
end
|
113
106
|
|
114
107
|
it '#serialPort should return serial port output of an existing server' do
|
115
|
-
zone = 'https://www.googleapis.com/compute/
|
108
|
+
zone = 'https://www.googleapis.com/compute/v1/projects/mock-project/zones/mock-zone'
|
116
109
|
@mock_api_client.should_receive(:execute).
|
117
|
-
with(:api_method=>mock_compute.instances.get_serial_port_output,
|
118
|
-
|
119
|
-
|
120
|
-
|
110
|
+
with(:api_method => mock_compute.instances.get_serial_port_output,
|
111
|
+
:parameters => {:project => 'mock-project', :instance => 'mock-instance', :zone => zone},
|
112
|
+
:body_object => nil).
|
113
|
+
and_return(mock_response(Google::Compute::SerialPortOutput))
|
121
114
|
instance.serial_port_output.should be_a_kind_of(Google::Compute::SerialPortOutput)
|
122
115
|
instance.serial_port_output.contents.should_not be_empty
|
123
116
|
end
|