knife-google 1.3.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +1 -0
- data/.travis.yml +15 -3
- data/CHANGELOG.md +4 -6
- data/Gemfile +3 -9
- data/README.md +208 -355
- data/RELEASE_NOTES.md +8 -17
- data/Rakefile +8 -49
- data/knife-google.gemspec +20 -17
- data/lib/chef/knife/cloud/google_service.rb +491 -0
- data/lib/chef/knife/cloud/google_service_helpers.rb +62 -0
- data/lib/chef/knife/cloud/google_service_options.rb +58 -0
- data/lib/chef/knife/google_disk_create.rb +40 -44
- data/lib/chef/knife/google_disk_delete.rb +22 -40
- data/lib/chef/knife/google_disk_list.rb +57 -51
- data/lib/chef/knife/google_project_quotas.rb +59 -0
- data/lib/chef/knife/google_region_list.rb +43 -102
- data/lib/chef/knife/google_region_quotas.rb +77 -0
- data/lib/chef/knife/google_server_create.rb +224 -505
- data/lib/chef/knife/google_server_delete.rb +20 -78
- data/lib/chef/knife/google_server_list.rb +42 -53
- data/lib/chef/knife/google_server_show.rb +44 -0
- data/lib/chef/knife/google_zone_list.rb +39 -50
- data/lib/knife-google/version.rb +3 -2
- data/spec/cloud/google_service_helpers_spec.rb +120 -0
- data/spec/cloud/google_service_spec.rb +832 -0
- data/spec/google_disk_create_spec.rb +72 -0
- data/spec/google_disk_delete_spec.rb +64 -0
- data/spec/google_disk_list_spec.rb +93 -0
- data/spec/google_project_quotas_spec.rb +63 -0
- data/spec/google_region_list_spec.rb +65 -0
- data/spec/google_region_quotas_spec.rb +108 -0
- data/spec/google_server_create_spec.rb +177 -0
- data/spec/google_server_delete_spec.rb +39 -0
- data/spec/google_server_list_spec.rb +77 -0
- data/spec/google_server_show_spec.rb +60 -0
- data/spec/google_zone_list_spec.rb +59 -0
- metadata +91 -114
- data/CONTRIB.md +0 -64
- data/lib/chef/knife/google_base.rb +0 -76
- data/lib/chef/knife/google_project_list.rb +0 -178
- data/lib/chef/knife/google_setup.rb +0 -31
- data/lib/google/compute.rb +0 -47
- data/lib/google/compute/client.rb +0 -216
- data/lib/google/compute/config.rb +0 -23
- data/lib/google/compute/creatable_resource_collection.rb +0 -55
- data/lib/google/compute/deletable_resource_collection.rb +0 -51
- data/lib/google/compute/disk.rb +0 -38
- data/lib/google/compute/exception.rb +0 -30
- data/lib/google/compute/firewall.rb +0 -65
- data/lib/google/compute/global_operation.rb +0 -60
- data/lib/google/compute/image.rb +0 -29
- data/lib/google/compute/listable_resource_collection.rb +0 -33
- data/lib/google/compute/machine_type.rb +0 -36
- data/lib/google/compute/mixins/utils.rb +0 -58
- data/lib/google/compute/network.rb +0 -29
- data/lib/google/compute/project.rb +0 -76
- data/lib/google/compute/region.rb +0 -31
- data/lib/google/compute/region_operation.rb +0 -62
- data/lib/google/compute/resource.rb +0 -81
- data/lib/google/compute/resource_collection.rb +0 -78
- data/lib/google/compute/server.rb +0 -88
- data/lib/google/compute/server/attached_disk.rb +0 -39
- data/lib/google/compute/server/network_interface.rb +0 -38
- data/lib/google/compute/server/network_interface/access_config.rb +0 -35
- data/lib/google/compute/server/serial_port_output.rb +0 -31
- data/lib/google/compute/snapshot.rb +0 -30
- data/lib/google/compute/version.rb +0 -19
- data/lib/google/compute/zone.rb +0 -34
- data/lib/google/compute/zone_operation.rb +0 -62
- data/spec/chef/knife/google_base_spec.rb +0 -46
- data/spec/chef/knife/google_disk_create_spec.rb +0 -37
- data/spec/chef/knife/google_disk_delete_spec.rb +0 -64
- data/spec/chef/knife/google_disk_list_spec.rb +0 -36
- data/spec/chef/knife/google_region_list_spec.rb +0 -32
- data/spec/chef/knife/google_server_create_spec.rb +0 -138
- data/spec/chef/knife/google_server_delete_spec.rb +0 -127
- data/spec/chef/knife/google_server_list_spec.rb +0 -39
- data/spec/chef/knife/google_setup_spec.rb +0 -24
- data/spec/chef/knife/google_zone_list_spec.rb +0 -32
- data/spec/data/client.json +0 -14
- data/spec/data/compute-v1.json +0 -6734
- data/spec/data/disk.json +0 -14
- data/spec/data/firewall.json +0 -13
- data/spec/data/global_operation.json +0 -36
- data/spec/data/image.json +0 -12
- data/spec/data/machine_type.json +0 -24
- data/spec/data/network.json +0 -10
- data/spec/data/project.json +0 -21
- data/spec/data/region.json +0 -23
- data/spec/data/serial_port_output.json +0 -5
- data/spec/data/server.json +0 -46
- data/spec/data/snapshot.json +0 -12
- data/spec/data/zone.json +0 -22
- data/spec/data/zone_operation.json +0 -36
- data/spec/google/compute/disk_spec.rb +0 -115
- data/spec/google/compute/firewall_spec.rb +0 -129
- data/spec/google/compute/global_operation_spec.rb +0 -62
- data/spec/google/compute/image_spec.rb +0 -75
- data/spec/google/compute/machine_type_spec.rb +0 -53
- data/spec/google/compute/network_spec.rb +0 -68
- data/spec/google/compute/project_spec.rb +0 -71
- data/spec/google/compute/region_spec.rb +0 -51
- data/spec/google/compute/server_spec.rb +0 -118
- data/spec/google/compute/snapshot_spec.rb +0 -57
- data/spec/google/compute/zone_operation_spec.rb +0 -62
- data/spec/google/compute/zone_spec.rb +0 -51
- data/spec/spec_helper.rb +0 -45
- data/spec/support/mocks.rb +0 -62
- data/spec/support/resource_examples.rb +0 -70
- data/spec/support/spec_google_base.rb +0 -60
@@ -1,62 +0,0 @@
|
|
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
|
-
require 'spec_helper'
|
15
|
-
|
16
|
-
describe Google::Compute::GlobalOperation do
|
17
|
-
|
18
|
-
before(:each) do
|
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
|
-
end
|
23
|
-
|
24
|
-
let(:client) do
|
25
|
-
Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like Google::Compute::Resource
|
29
|
-
|
30
|
-
it '#list should return an array of global operations' do
|
31
|
-
@mock_api_client.should_receive(:execute).
|
32
|
-
with(:api_method => mock_compute.global_operations.list,
|
33
|
-
:parameters => { :project => 'mock-project'}, :body_object => nil).
|
34
|
-
and_return(mock_response(Google::Compute::GlobalOperation, true))
|
35
|
-
|
36
|
-
operations = client.globalOperations.list
|
37
|
-
operations.should_not be_empty
|
38
|
-
operations.all?{|o| o.is_a?(Google::Compute::GlobalOperation)}.should be_true
|
39
|
-
end
|
40
|
-
|
41
|
-
it '#get should return an individual global operation' do
|
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'}, :body_object => nil).
|
45
|
-
and_return(mock_response(Google::Compute::GlobalOperation))
|
46
|
-
|
47
|
-
operation = client.globalOperations.get('mock-global-operation')
|
48
|
-
operation.should be_a_kind_of Google::Compute::GlobalOperation
|
49
|
-
operation.name.should eq('mock-global-operation')
|
50
|
-
operation.should respond_to(:progress)
|
51
|
-
operation.start_time.should be_a_kind_of(Time)
|
52
|
-
end
|
53
|
-
|
54
|
-
it '#delete should delete an existing global operation' do
|
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'}, :body_object => nil).
|
58
|
-
and_return(mock_response)
|
59
|
-
|
60
|
-
client.globalOperations.delete('mock-global-operation')
|
61
|
-
end
|
62
|
-
end
|
@@ -1,75 +0,0 @@
|
|
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
|
-
require 'spec_helper'
|
15
|
-
|
16
|
-
describe Google::Compute::Image do
|
17
|
-
|
18
|
-
before(:each) do
|
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
|
-
end
|
23
|
-
|
24
|
-
let(:client) do
|
25
|
-
Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like Google::Compute::Resource
|
29
|
-
|
30
|
-
it '#get should return an individual image' do
|
31
|
-
@mock_api_client.should_receive(:execute).
|
32
|
-
with(:api_method => mock_compute.images.get,
|
33
|
-
:parameters => {'image' => 'mock-image', :project => 'mock-project'}, :body_object => nil).
|
34
|
-
and_return(mock_response(Google::Compute::Image))
|
35
|
-
image = client.images.get('mock-image')
|
36
|
-
image.should be_a_kind_of Google::Compute::Image
|
37
|
-
image.name.should eq('mock-image')
|
38
|
-
image.raw_disk.should have_key('source')
|
39
|
-
image.raw_disk.should have_key('containerType')
|
40
|
-
end
|
41
|
-
|
42
|
-
it '#list should return an array of images' do
|
43
|
-
@mock_api_client.should_receive(:execute).
|
44
|
-
with(:api_method => mock_compute.images.list,
|
45
|
-
:parameters => { :project => 'mock-project'}, :body_object => nil).
|
46
|
-
and_return(mock_response(Google::Compute::Image, true))
|
47
|
-
images = client.images.list
|
48
|
-
images.should_not be_empty
|
49
|
-
images.all?{|i| i.is_a?(Google::Compute::Image)}.should be_true
|
50
|
-
end
|
51
|
-
it '#create should create a new image' do
|
52
|
-
storage = 'https://www.googleapis.com/storage/projects/mock-project/bucket/object'
|
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'}).
|
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')
|
63
|
-
|
64
|
-
o.should be_a_kind_of Google::Compute::GlobalOperation
|
65
|
-
end
|
66
|
-
|
67
|
-
it '#delete should delete an existing image' do
|
68
|
-
@mock_api_client.should_receive(:execute).
|
69
|
-
with(:api_method => mock_compute.images.delete,
|
70
|
-
:parameters => { :project => 'mock-project', 'image' => 'mock-image'}, :body_object => nil).
|
71
|
-
and_return(mock_response(Google::Compute::GlobalOperation))
|
72
|
-
o = client.images.delete('mock-image')
|
73
|
-
o.should be_a_kind_of Google::Compute::GlobalOperation
|
74
|
-
end
|
75
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
-
#
|
3
|
-
# Copyright 2013 Google Inc.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
require 'spec_helper'
|
17
|
-
|
18
|
-
describe Google::Compute::MachineType do
|
19
|
-
|
20
|
-
before(:each) do
|
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
|
-
end
|
25
|
-
|
26
|
-
let(:client) do
|
27
|
-
Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
|
28
|
-
end
|
29
|
-
|
30
|
-
it_should_behave_like Google::Compute::Resource
|
31
|
-
|
32
|
-
it '#get should return an individual machine types' do
|
33
|
-
|
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'}, :body_object => nil).
|
37
|
-
and_return(mock_response(Google::Compute::MachineType))
|
38
|
-
|
39
|
-
machine_type = client.machine_types.get('mock-machine-type')
|
40
|
-
machine_type.should be_a_kind_of Google::Compute::MachineType
|
41
|
-
machine_type.name.should eq('mock-machine-type')
|
42
|
-
machine_type.guest_cpus.should be_a_kind_of(Fixnum)
|
43
|
-
end
|
44
|
-
it '#list should return an array of machine types' do
|
45
|
-
@mock_api_client.should_receive(:execute).
|
46
|
-
with(:api_method => mock_compute.machine_types.list,
|
47
|
-
:parameters => { :project => 'mock-project'}, :body_object => nil).
|
48
|
-
and_return(mock_response(Google::Compute::MachineType, true))
|
49
|
-
mts = client.machine_types.list
|
50
|
-
mts.should_not be_empty
|
51
|
-
mts.all?{|mt| mt.is_a?(Google::Compute::MachineType)}.should be_true
|
52
|
-
end
|
53
|
-
end
|
@@ -1,68 +0,0 @@
|
|
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
|
-
require 'spec_helper'
|
15
|
-
|
16
|
-
describe Google::Compute::Network do
|
17
|
-
|
18
|
-
before(:each) do
|
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
|
-
end
|
23
|
-
|
24
|
-
let(:client) do
|
25
|
-
Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like Google::Compute::Resource
|
29
|
-
|
30
|
-
it '#get should return an individual network' do
|
31
|
-
@mock_api_client.should_receive(:execute).
|
32
|
-
with(:api_method => mock_compute.networks.get,
|
33
|
-
:parameters => {'network' => 'mock-network', :project => 'mock-project'}, :body_object => nil).
|
34
|
-
and_return(mock_response(Google::Compute::Network))
|
35
|
-
network = client.networks.get('mock-network')
|
36
|
-
network.should be_a_kind_of Google::Compute::Network
|
37
|
-
network.name.should eq('mock-network')
|
38
|
-
network.should respond_to(:ip_v4_range)
|
39
|
-
end
|
40
|
-
|
41
|
-
it '#list should return an array of networks' do
|
42
|
-
@mock_api_client.should_receive(:execute).
|
43
|
-
with(:api_method => mock_compute.networks.list,
|
44
|
-
:parameters => { :project => 'mock-project'}, :body_object => nil).
|
45
|
-
and_return(mock_response(Google::Compute::Network, true))
|
46
|
-
networks = client.networks.list
|
47
|
-
networks.should_not be_empty
|
48
|
-
networks.all?{|n| n.is_a?(Google::Compute::Network)}.should be_true
|
49
|
-
end
|
50
|
-
|
51
|
-
it '#create should create a new network' do
|
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'}).
|
56
|
-
and_return(mock_response(Google::Compute::GlobalOperation))
|
57
|
-
o = client.networks.create(:name => 'mock-network', :IPv4Range => '122.12.0.0/16')
|
58
|
-
o.should be_a_kind_of Google::Compute::GlobalOperation
|
59
|
-
end
|
60
|
-
|
61
|
-
it '#delete should delete an existing network' do
|
62
|
-
@mock_api_client.should_receive(:execute).
|
63
|
-
with(:api_method => mock_compute.networks.delete,
|
64
|
-
:parameters => {'network' => 'mock-network', :project => 'mock-project'}, :body_object => nil).
|
65
|
-
and_return(mock_response(Google::Compute::GlobalOperation))
|
66
|
-
client.networks.delete('mock-network')
|
67
|
-
end
|
68
|
-
end
|
@@ -1,71 +0,0 @@
|
|
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
|
-
require 'spec_helper'
|
15
|
-
|
16
|
-
describe Google::Compute::Project do
|
17
|
-
|
18
|
-
before(:each) do
|
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
|
-
end
|
23
|
-
|
24
|
-
let(:client) do
|
25
|
-
Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like Google::Compute::Resource
|
29
|
-
|
30
|
-
it '#get should return an individual project' do
|
31
|
-
@mock_api_client.should_receive(:execute).
|
32
|
-
with(:api_method => mock_compute.projects.get,
|
33
|
-
:parameters => {:project => 'mock-project', 'project' => 'mock-project'}, :body_object => nil).
|
34
|
-
and_return(mock_response(Google::Compute::Project))
|
35
|
-
project = client.projects.get('mock-project')
|
36
|
-
project.should be_a_kind_of Google::Compute::Project
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#setCommonInstanceMetadata'
|
40
|
-
|
41
|
-
before(:each) do
|
42
|
-
Google::Compute::Resource.any_instance.stub(:update!)
|
43
|
-
end
|
44
|
-
|
45
|
-
let(:project) do
|
46
|
-
Google::Compute::Project.new(mock_hash(Google::Compute::Project).
|
47
|
-
merge(:dispatcher => client.dispatcher))
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should be able to add common instance metadata' do
|
51
|
-
@mock_api_client.should_receive(:execute).
|
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
|
-
and_return(mock_response)
|
58
|
-
project.add_common_instance_metadata!('testKey' => 'testValue')
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should be able to remove common instance metadata' do
|
62
|
-
@mock_api_client.should_receive(:execute).
|
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
|
-
and_return(mock_response)
|
68
|
-
project.remove_common_instance_metadata!('mock-key' => 'mock-value')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
@@ -1,51 +0,0 @@
|
|
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
|
@@ -1,118 +0,0 @@
|
|
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
|
-
require 'spec_helper'
|
15
|
-
|
16
|
-
describe Google::Compute::Server do
|
17
|
-
|
18
|
-
before(:each) do
|
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
|
-
end
|
23
|
-
|
24
|
-
let(:client) do
|
25
|
-
Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like Google::Compute::Resource
|
29
|
-
|
30
|
-
it '#get should return an individual Server' do
|
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'}, :body_object => nil).
|
34
|
-
and_return(mock_response(Google::Compute::Server))
|
35
|
-
instance = client.instances.get(:name => 'mock-instance', :zone => 'mock-zone')
|
36
|
-
instance.should be_a_kind_of Google::Compute::Server
|
37
|
-
instance.name.should eq('mock-instance')
|
38
|
-
instance.disks.should be_a_kind_of(Array)
|
39
|
-
instance.network_interfaces.should be_a_kind_of(Array)
|
40
|
-
end
|
41
|
-
|
42
|
-
it '#list should return an array of Servers' do
|
43
|
-
@mock_api_client.should_receive(:execute).
|
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
|
-
instances.should_not be_empty
|
49
|
-
instances.all?{|i| i.is_a?(Google::Compute::Server)}.should be_true
|
50
|
-
end
|
51
|
-
|
52
|
-
it '#create should create an server' do
|
53
|
-
project_url ='https://www.googleapis.com/compute/v1/projects/mock-project'
|
54
|
-
zone = project_url + '/zones/europe-west1-a'
|
55
|
-
disk = project_url + zone + '/disks/mock-disk'
|
56
|
-
machine_type = project_url + '/global/machineTypes/n1-highcpu-2'
|
57
|
-
image = 'https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7'
|
58
|
-
network = project_url + '/global/networks/api-network'
|
59
|
-
access_config = {'name' => 'External NAT', 'type' => 'ONE_TO_ONE_NAT'}
|
60
|
-
|
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',
|
65
|
-
:image => image,
|
66
|
-
:zone => 'mock-zone',
|
67
|
-
:disks => [disk],
|
68
|
-
:machineType => machine_type,
|
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]}])
|
79
|
-
end
|
80
|
-
|
81
|
-
it '#delete should delete an server' do
|
82
|
-
@mock_api_client.should_receive(:execute).
|
83
|
-
with(:api_method => mock_compute.instances.delete,
|
84
|
-
:parameters => {:project => 'mock-project', :instance => 'mock-instance', :zone => 'mock-zone'},
|
85
|
-
:body_object => nil).
|
86
|
-
and_return(mock_response(Google::Compute::ZoneOperation))
|
87
|
-
o = client.instances.delete(:instance => 'mock-instance', :zone => 'mock-zone')
|
88
|
-
end
|
89
|
-
|
90
|
-
describe 'with a specific server' do
|
91
|
-
|
92
|
-
before(:each) do
|
93
|
-
Google::Compute::Resource.any_instance.stub(:update!)
|
94
|
-
end
|
95
|
-
|
96
|
-
let(:instance) do
|
97
|
-
Google::Compute::Server.new(mock_hash(Google::Compute::Server).
|
98
|
-
merge(:dispatcher => client.dispatcher))
|
99
|
-
end
|
100
|
-
|
101
|
-
it '#addAccessConfig should add access config to an existing server' do
|
102
|
-
end
|
103
|
-
|
104
|
-
it '#deleteAccessConfig should delete access config to an existing server' do
|
105
|
-
end
|
106
|
-
|
107
|
-
it '#serialPort should return serial port output of an existing server' do
|
108
|
-
zone = 'https://www.googleapis.com/compute/v1/projects/mock-project/zones/mock-zone'
|
109
|
-
@mock_api_client.should_receive(:execute).
|
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))
|
114
|
-
instance.serial_port_output.should be_a_kind_of(Google::Compute::SerialPortOutput)
|
115
|
-
instance.serial_port_output.contents.should_not be_empty
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|