knife-google 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/CONTRIB.md +64 -0
- data/Gemfile +11 -0
- data/README.md +287 -0
- data/Rakefile +53 -0
- data/knife-google.gemspec +26 -0
- data/lib/chef/knife/google_base.rb +39 -68
- data/lib/chef/knife/google_disk_create.rb +60 -0
- data/lib/chef/knife/google_disk_delete.rb +60 -0
- data/lib/chef/knife/google_disk_list.rb +75 -0
- data/lib/chef/knife/google_server_create.rb +273 -184
- data/lib/chef/knife/google_server_delete.rb +74 -32
- data/lib/chef/knife/google_server_list.rb +45 -64
- data/lib/chef/knife/google_setup.rb +31 -0
- data/lib/chef/knife/google_zone_list.rb +78 -0
- data/lib/google/compute.rb +46 -0
- data/lib/google/compute/client.rb +188 -0
- data/lib/google/compute/config.rb +23 -0
- data/lib/google/compute/creatable_resource_collection.rb +38 -0
- data/lib/google/compute/deletable_resource_collection.rb +51 -0
- data/lib/google/compute/disk.rb +40 -0
- data/lib/google/compute/exception.rb +28 -0
- data/lib/google/compute/firewall.rb +65 -0
- data/lib/google/compute/global_operation.rb +60 -0
- data/lib/google/compute/image.rb +30 -0
- data/lib/google/compute/kernel.rb +20 -0
- data/lib/google/compute/listable_resource_collection.rb +33 -0
- data/lib/google/compute/machine_type.rb +36 -0
- data/lib/google/compute/mixins/utils.rb +58 -0
- data/lib/google/compute/network.rb +29 -0
- data/lib/google/compute/project.rb +76 -0
- data/lib/google/compute/resource.rb +81 -0
- data/lib/google/compute/resource_collection.rb +78 -0
- data/lib/google/compute/server.rb +87 -0
- data/lib/google/compute/server/attached_disk.rb +39 -0
- data/lib/google/compute/server/network_interface.rb +38 -0
- data/lib/google/compute/server/network_interface/access_config.rb +35 -0
- data/lib/google/compute/server/serial_port_output.rb +31 -0
- data/lib/google/compute/snapshot.rb +30 -0
- data/lib/google/compute/version.rb +19 -0
- data/lib/google/compute/zone.rb +32 -0
- data/lib/google/compute/zone_operation.rb +60 -0
- data/lib/knife-google/version.rb +18 -2
- data/spec/chef/knife/google_base_spec.rb +46 -0
- data/spec/chef/knife/google_disk_create_spec.rb +36 -0
- data/spec/chef/knife/google_disk_delete_spec.rb +65 -0
- data/spec/chef/knife/google_disk_list_spec.rb +36 -0
- data/spec/chef/knife/google_server_create_spec.rb +84 -0
- data/spec/chef/knife/google_server_delete_spec.rb +105 -0
- data/spec/chef/knife/google_server_list_spec.rb +39 -0
- data/spec/chef/knife/google_setup_spec.rb +25 -0
- data/spec/chef/knife/google_zone_list_spec.rb +32 -0
- data/spec/data/client.json +14 -0
- data/spec/data/compute-v1beta14.json +3386 -0
- data/spec/data/disk.json +15 -0
- data/spec/data/firewall.json +13 -0
- data/spec/data/global_operation.json +36 -0
- data/spec/data/image.json +12 -0
- data/spec/data/kernel.json +15 -0
- data/spec/data/machine_type.json +24 -0
- data/spec/data/network.json +10 -0
- data/spec/data/project.json +21 -0
- data/spec/data/serial_port_output.json +5 -0
- data/spec/data/server.json +46 -0
- data/spec/data/snapshot.json +12 -0
- data/spec/data/zone.json +30 -0
- data/spec/data/zone_operation.json +36 -0
- data/spec/google/compute/disk_spec.rb +105 -0
- data/spec/google/compute/firewall_spec.rb +128 -0
- data/spec/google/compute/global_operation_spec.rb +62 -0
- data/spec/google/compute/image_spec.rb +75 -0
- data/spec/google/compute/kernel_spec.rb +49 -0
- data/spec/google/compute/machine_type_spec.rb +53 -0
- data/spec/google/compute/network_spec.rb +68 -0
- data/spec/google/compute/project_spec.rb +71 -0
- data/spec/google/compute/server_spec.rb +125 -0
- data/spec/google/compute/snapshot_spec.rb +69 -0
- data/spec/google/compute/zone_operation_spec.rb +62 -0
- data/spec/google/compute/zone_spec.rb +50 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/mocks.rb +62 -0
- data/spec/support/resource_examples.rb +70 -0
- data/spec/support/spec_google_base.rb +56 -0
- metadata +121 -31
- data/README.rdoc +0 -96
@@ -0,0 +1,31 @@
|
|
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 'google/compute/mixins/utils'
|
16
|
+
|
17
|
+
module Google
|
18
|
+
module Compute
|
19
|
+
class SerialPortOutput
|
20
|
+
include Utils
|
21
|
+
|
22
|
+
attr_reader :kind, :self_link, :contents
|
23
|
+
|
24
|
+
def initialize(data)
|
25
|
+
@kind = data["kind"]
|
26
|
+
@contents = data["contents"]
|
27
|
+
@self_link = data["selfLink"]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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
|
+
module Google
|
16
|
+
module Compute
|
17
|
+
class Snapshot < Resource
|
18
|
+
|
19
|
+
attr_reader :disk_size_gb, :status, :source_disk, :source_disk_id
|
20
|
+
|
21
|
+
def from_hash(data)
|
22
|
+
super(data)
|
23
|
+
@disk_size_gb = data["diskSizeGb"]
|
24
|
+
@status = data["status"]
|
25
|
+
@source_disk = data["sourceDisk"]
|
26
|
+
@source_disk_id = data["sourceDiskId"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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
|
+
module Google
|
16
|
+
module Compute
|
17
|
+
VERSION = '1.0.0'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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
|
+
module Google
|
16
|
+
module Compute
|
17
|
+
class Zone < Resource
|
18
|
+
|
19
|
+
attr_reader :maintenance_windows, :available_machine_type, :status
|
20
|
+
attr_reader :quotas, :deprecated
|
21
|
+
|
22
|
+
def from_hash(zone_data)
|
23
|
+
super(zone_data)
|
24
|
+
@status = zone_data["status"]
|
25
|
+
@maintenance_windows = zone_data["maintenanceWindows"]
|
26
|
+
@available_machine_type = zone_data["availableMachineType"]
|
27
|
+
@quotas = zone_data["quotas"]
|
28
|
+
@deprecated = zone_data["deprecated"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
# Google compute engine, operation resource reference
|
16
|
+
|
17
|
+
require 'timeout'
|
18
|
+
|
19
|
+
module Google
|
20
|
+
module Compute
|
21
|
+
class ZoneOperation < Resource
|
22
|
+
|
23
|
+
attr_reader :target_link, :target_id, :client_operation_id
|
24
|
+
attr_reader :status, :status_message, :user, :progress
|
25
|
+
attr_reader :insert_time, :start_time, :end_time
|
26
|
+
attr_reader :http_error_status_code, :http_error_message
|
27
|
+
attr_reader :error, :warnings, :operation_type, :zone
|
28
|
+
|
29
|
+
def from_hash(data)
|
30
|
+
super(data)
|
31
|
+
@target_link= data["targetLink"]
|
32
|
+
@target_id = data["targetId"]
|
33
|
+
@client_operation_id = data["clientOperationId"]
|
34
|
+
@status = data["status"]
|
35
|
+
@status_message = data["statusMessage"]
|
36
|
+
@user = data["user"]
|
37
|
+
@progress = data["progress"]
|
38
|
+
@insert_time = Time.parse( data["insertTime"] )
|
39
|
+
@start_time = Time.parse( data["startTime"] )
|
40
|
+
@end_time = Time.parse( data["endTime"] ) if data.key?("endTime")
|
41
|
+
@http_error_status_code = data["httpErrorMessage"]
|
42
|
+
@http_error_message = data["httpErrorMessage"]
|
43
|
+
@error = data["error"]
|
44
|
+
@warnings = data["warnings"]
|
45
|
+
@operation_type = data["operationType"]
|
46
|
+
@zone = data["zone"]
|
47
|
+
end
|
48
|
+
|
49
|
+
def wait_for_completion!(options={})
|
50
|
+
timeout = options[:timeout] || 60
|
51
|
+
status = Timeout::timeout(timeout, OperationTimeout) do
|
52
|
+
until progress==100
|
53
|
+
sleep 2
|
54
|
+
progress= get_self.progress
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/knife-google/version.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
-
|
2
|
-
|
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
|
+
module Knife
|
16
|
+
module Google
|
17
|
+
VERSION = "1.0.0"
|
18
|
+
end
|
3
19
|
end
|
@@ -0,0 +1,46 @@
|
|
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
|
+
|
16
|
+
require 'spec_helper'
|
17
|
+
|
18
|
+
describe Chef::Knife::GoogleBase do
|
19
|
+
let(:knife_plugin) { Chef::Knife::GoogleServerList.new(["-Z"+stored_zone.name]) }
|
20
|
+
|
21
|
+
it "#client should return a Google::Compute::Client" do
|
22
|
+
Google::Compute::Client.should_receive(:from_json).
|
23
|
+
and_return(mock(Google::Compute::Client))
|
24
|
+
knife_plugin.client
|
25
|
+
end
|
26
|
+
|
27
|
+
it "#selflink2name should return name from a seleflink url" do
|
28
|
+
knife_plugin.selflink2name(
|
29
|
+
'https://www.googleapis.com/compute/v1beta14/projects/mock-project/category/resource').
|
30
|
+
should eq('resource')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "#msg_pair should invoke ui.info with labe : value string" do
|
34
|
+
knife_plugin.ui.should_receive(:info).
|
35
|
+
with("#{knife_plugin.ui.color("label", :cyan)}: value")
|
36
|
+
knife_plugin.msg_pair("label","value")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "#private_ips should extract private ip as an array from a GCE server" do
|
40
|
+
knife_plugin.private_ips(stored_instance).should eq(['10.100.0.10'])
|
41
|
+
end
|
42
|
+
|
43
|
+
it "#public_ips should extract private ip as an array from a GCE server" do
|
44
|
+
knife_plugin.public_ips(stored_instance).should eq(['11.1.1.11'])
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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 Chef::Knife::GoogleDiskCreate do
|
18
|
+
|
19
|
+
let(:knife_plugin) do
|
20
|
+
Chef::Knife::GoogleDiskCreate.new(
|
21
|
+
[stored_disk.name, "-Z"+stored_zone.name, "-s14"])
|
22
|
+
end
|
23
|
+
|
24
|
+
it "#run should invoke compute api to create a disk" do
|
25
|
+
zones = mock(Google::Compute::ListableResourceCollection)
|
26
|
+
zones.should_receive(:get).
|
27
|
+
with(stored_zone.name).and_return(stored_zone)
|
28
|
+
disks = mock(Google::Compute::CreatableResourceCollection)
|
29
|
+
disks.should_receive(:create).
|
30
|
+
with(:zone=>stored_zone.name, :name=>stored_disk.name, :sizeGb=>"14").
|
31
|
+
and_return(stored_zone_operation)
|
32
|
+
client = mock(Google::Compute::Client, :zones=>zones, :disks=>disks)
|
33
|
+
Google::Compute::Client.stub!(:from_json).and_return(client)
|
34
|
+
knife_plugin.run
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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 Chef::Knife::GoogleDiskDelete do
|
18
|
+
|
19
|
+
let(:knife_plugin) do
|
20
|
+
Chef::Knife::GoogleDiskDelete.new([stored_disk.name, "-Z"+stored_zone.name])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should print out error message if the disk is not found" do
|
24
|
+
zones = mock(Google::Compute::ListableResourceCollection)
|
25
|
+
zones.should_receive(:get).with(stored_zone.name).
|
26
|
+
and_return(stored_zone)
|
27
|
+
disks = mock(Google::Compute::DeletableResourceCollection)
|
28
|
+
disks.should_receive(:get).
|
29
|
+
with(:zone=>stored_zone.name, :disk=>stored_disk.name).
|
30
|
+
and_raise(Google::Compute::ResourceNotFound)
|
31
|
+
disks.should_not_receive(:delete)
|
32
|
+
client = mock(Google::Compute::Client,
|
33
|
+
:disks=>disks, :zones=>zones)
|
34
|
+
Google::Compute::Client.stub!(:from_json).and_return(client)
|
35
|
+
|
36
|
+
knife_plugin.config[:yes] = true
|
37
|
+
knife_plugin.ui.should_receive(:error).
|
38
|
+
with("Disk '#{stored_zone.name}:#{stored_disk.name}' not found")
|
39
|
+
knife_plugin.stub!(:msg_pair)
|
40
|
+
expect {
|
41
|
+
knife_plugin.run
|
42
|
+
}.to raise_error(SystemExit)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should invoke api delete method when run is called" do
|
46
|
+
zones = mock(Google::Compute::ListableResourceCollection)
|
47
|
+
zones.should_receive(:get).with(stored_zone.name).
|
48
|
+
and_return(stored_zone)
|
49
|
+
disks = mock(Google::Compute::DeletableResourceCollection)
|
50
|
+
disks.should_receive(:get).
|
51
|
+
with(:zone=>stored_zone.name, :disk=>stored_disk.name).
|
52
|
+
and_return(stored_disk)
|
53
|
+
disks.should_receive(:delete).
|
54
|
+
with(:zone=>stored_zone.name, :disk=>stored_disk.name)
|
55
|
+
client = mock(Google::Compute::Client,
|
56
|
+
:zones=>zones,:disks=>disks)
|
57
|
+
Google::Compute::Client.stub!(:from_json).
|
58
|
+
and_return(client)
|
59
|
+
knife_plugin.config[:yes] = true
|
60
|
+
knife_plugin.ui.should_receive(:warn).
|
61
|
+
with("Disk '#{stored_zone.name}:#{stored_disk.name}' deleted")
|
62
|
+
knife_plugin.stub!(:msg_pair)
|
63
|
+
knife_plugin.run
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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 Chef::Knife::GoogleDiskList do
|
18
|
+
|
19
|
+
let(:knife_plugin) do
|
20
|
+
Chef::Knife::GoogleDiskList.new(["-Z"+stored_zone.name])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should enlist all the GCE disks when run invoked" do
|
24
|
+
zones = mock(Google::Compute::ListableResourceCollection)
|
25
|
+
zones.should_receive(:get).with(stored_zone.name).
|
26
|
+
and_return(stored_zone)
|
27
|
+
disks = mock(Google::Compute::ListableResourceCollection)
|
28
|
+
disks.should_receive(:list).with(:zone=>stored_zone.name).
|
29
|
+
and_return([stored_disk])
|
30
|
+
|
31
|
+
client = mock(Google::Compute::Client, :disks=>disks, :zones=>zones)
|
32
|
+
Google::Compute::Client.stub!(:from_json).and_return(client)
|
33
|
+
$stdout.should_receive(:write).with(kind_of(String))
|
34
|
+
knife_plugin.run
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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 Chef::Knife::GoogleServerCreate do
|
18
|
+
|
19
|
+
let(:knife_plugin) do
|
20
|
+
Chef::Knife::GoogleServerCreate.new(["-m"+stored_machine_type.name,
|
21
|
+
"-I"+stored_image.name, "-n"+stored_network.name,
|
22
|
+
"-Z"+stored_zone.name, stored_instance.name])
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#run should invoke compute api to create an server" do
|
26
|
+
zones = mock(Google::Compute::ListableResourceCollection)
|
27
|
+
zones.should_receive(:get).with(stored_zone.name).
|
28
|
+
and_return(stored_zone)
|
29
|
+
|
30
|
+
machine_types = mock(Google::Compute::ListableResourceCollection)
|
31
|
+
machine_types.should_receive(:get).with(stored_machine_type.name).
|
32
|
+
and_return(stored_machine_type)
|
33
|
+
|
34
|
+
images = mock(Google::Compute::ListableResourceCollection)
|
35
|
+
images.should_receive(:get).
|
36
|
+
with({:project=>"google", :name=>stored_image.name}).
|
37
|
+
and_return(stored_image)
|
38
|
+
|
39
|
+
networks = mock(Google::Compute::ListableResourceCollection)
|
40
|
+
networks.should_receive(:get).with(stored_network.name).
|
41
|
+
and_return(stored_network)
|
42
|
+
|
43
|
+
instances = mock(Google::Compute::ListableResourceCollection)
|
44
|
+
instances.should_receive(:create).with(
|
45
|
+
{:name=>stored_instance.name, :image=>stored_image.self_link,
|
46
|
+
:machineType=>stored_machine_type.self_link, :disks=>[],
|
47
|
+
:metadata=>{"items"=>[]}, :zone=>stored_zone.name,
|
48
|
+
:networkInterfaces=>[
|
49
|
+
{"network"=>stored_network.self_link,
|
50
|
+
"accessConfigs"=>[
|
51
|
+
{"name"=>"External NAT", "type"=>"ONE_TO_ONE_NAT"}]}],
|
52
|
+
:tags=>nil}).and_return(stored_zone_operation)
|
53
|
+
|
54
|
+
instances.should_receive(:get).
|
55
|
+
with(:zone=>stored_zone.name, :name=>stored_instance.name).
|
56
|
+
and_return(stored_instance)
|
57
|
+
|
58
|
+
client = mock(Google::Compute::Client, :instances=>instances,
|
59
|
+
:images=>images, :zones=>zones,:machine_types=>machine_types,
|
60
|
+
:networks=>networks)
|
61
|
+
Google::Compute::Client.stub!(:from_json).and_return(client)
|
62
|
+
|
63
|
+
knife_plugin.config[:disks]=[]
|
64
|
+
knife_plugin.config[:metadata]=[]
|
65
|
+
knife_plugin.config[:public_ip]='EPHEMERAL'
|
66
|
+
knife_plugin.ui.stub!(:info)
|
67
|
+
|
68
|
+
knife_plugin.stub!(:wait_for_sshd)
|
69
|
+
knife_plugin.should_receive(:bootstrap_for_node).
|
70
|
+
with(stored_instance,'10.100.0.10').
|
71
|
+
and_return(mock("Chef::Knife::Bootstrap",:run=>true))
|
72
|
+
|
73
|
+
knife_plugin.run
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "without appropriate command line options" do
|
77
|
+
it "should throw exception when required params are not passed" do
|
78
|
+
$stdout.stub!(:write) # lets not print those error messages
|
79
|
+
expect {
|
80
|
+
Chef::Knife::GoogleServerCreate.new([ "NAME"])
|
81
|
+
}.to raise_error(SystemExit)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|