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,39 +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
|
-
# Google compute engine, attached disk of an instance
|
16
|
-
|
17
|
-
require 'google/compute/mixins/utils'
|
18
|
-
|
19
|
-
module Google
|
20
|
-
module Compute
|
21
|
-
|
22
|
-
class AttachedDisk
|
23
|
-
include Utils
|
24
|
-
|
25
|
-
attr_reader :kind, :index, :type, :mode
|
26
|
-
attr_reader :source, :device_name, :boot
|
27
|
-
|
28
|
-
def initialize(data)
|
29
|
-
@kind = data["kind"]
|
30
|
-
@index = data["index"]
|
31
|
-
@type = data["type"]
|
32
|
-
@mode= data["mode"]
|
33
|
-
@source = data["source"]
|
34
|
-
@device_name = data["deviceName"]
|
35
|
-
@boot = data["boot"]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,38 +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 'google/compute/server/network_interface/access_config'
|
16
|
-
require 'google/compute/mixins/utils'
|
17
|
-
|
18
|
-
module Google
|
19
|
-
module Compute
|
20
|
-
class NetworkInterface
|
21
|
-
include Utils
|
22
|
-
|
23
|
-
attr_reader :name, :network, :network_ip, :access_configs
|
24
|
-
|
25
|
-
def initialize(data)
|
26
|
-
@name = data["name"]
|
27
|
-
@network = data["network"]
|
28
|
-
@network_ip = data["networkIP"]
|
29
|
-
@access_configs=[]
|
30
|
-
if data["accessConfigs"] && data["accessConfigs"].is_a?(Array)
|
31
|
-
data["accessConfigs"].each do |config|
|
32
|
-
@access_configs << AccessConfig.new(config)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,35 +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 'google/compute/mixins/utils'
|
16
|
-
|
17
|
-
module Google
|
18
|
-
module Compute
|
19
|
-
class NetworkInterface
|
20
|
-
class AccessConfig
|
21
|
-
|
22
|
-
include Utils
|
23
|
-
|
24
|
-
attr_reader :kind, :name, :type, :nat_ip
|
25
|
-
|
26
|
-
def initialize(data)
|
27
|
-
@kind = data["kind"]
|
28
|
-
@name = data["name"]
|
29
|
-
@type = data["type"]
|
30
|
-
@nat_ip = data["natIP"]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,31 +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 '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
|
@@ -1,30 +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
|
-
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
|
@@ -1,19 +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
|
-
module Google
|
16
|
-
module Compute
|
17
|
-
VERSION = '1.0.0'
|
18
|
-
end
|
19
|
-
end
|
data/lib/google/compute/zone.rb
DELETED
@@ -1,34 +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 'google/compute/resource'
|
16
|
-
#require 'google/compute/region'
|
17
|
-
|
18
|
-
module Google
|
19
|
-
module Compute
|
20
|
-
class Zone < Resource
|
21
|
-
|
22
|
-
attr_reader :status, :maintenance_windows
|
23
|
-
attr_reader :deprecated, :region
|
24
|
-
|
25
|
-
def from_hash(zone_data)
|
26
|
-
super(zone_data)
|
27
|
-
@status = zone_data["status"]
|
28
|
-
@maintenance_windows = zone_data["maintenanceWindows"]
|
29
|
-
@deprecated = zone_data["deprecated"]
|
30
|
-
@region = zone_data["region"]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -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
|
-
|
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 :zone, :client_operation_id, :operation_type
|
24
|
-
attr_reader :target_link, :target_id, :status
|
25
|
-
attr_reader :status_message, :user, :progress
|
26
|
-
attr_reader :insert_time, :start_time, :end_time
|
27
|
-
attr_reader :error, :warnings, :http_error_status_code
|
28
|
-
attr_reader :http_error_message, :region
|
29
|
-
|
30
|
-
def from_hash(data)
|
31
|
-
super(data)
|
32
|
-
@zone = data["zone"]
|
33
|
-
@client_operation_id = data["clientOperationId"]
|
34
|
-
@operation_type = data["operationType"]
|
35
|
-
@target_link= data["targetLink"]
|
36
|
-
@target_id = data["targetId"]
|
37
|
-
@status = data["status"]
|
38
|
-
@status_message = data["statusMessage"]
|
39
|
-
@user = data["user"]
|
40
|
-
@progress = data["progress"]
|
41
|
-
@insert_time = Time.parse( data["insertTime"] )
|
42
|
-
@start_time = Time.parse( data["startTime"] )
|
43
|
-
@end_time = Time.parse( data["endTime"] ) if data.key?("endTime")
|
44
|
-
@error = data["error"]
|
45
|
-
@warnings = data["warnings"]
|
46
|
-
@http_error_status_code = data["httpErrorMessage"]
|
47
|
-
@http_error_message = data["httpErrorMessage"]
|
48
|
-
@region = data["region"]
|
49
|
-
end
|
50
|
-
|
51
|
-
def wait_for_completion!(options={})
|
52
|
-
timeout = options[:timeout] || 60
|
53
|
-
status = Timeout::timeout(timeout, OperationTimeout) do
|
54
|
-
until progress==100
|
55
|
-
sleep 2
|
56
|
-
progress= get_self.progress
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,46 +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
|
-
|
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(double(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/v1/projects/mock-project/category/resource').
|
30
|
-
should eq('resource')
|
31
|
-
end
|
32
|
-
|
33
|
-
it "#msg_pair should invoke ui.info with label : 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
|
@@ -1,37 +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
|
-
|
16
|
-
require 'spec_helper'
|
17
|
-
|
18
|
-
describe Chef::Knife::GoogleDiskCreate do
|
19
|
-
let(:knife_plugin) do
|
20
|
-
Chef::Knife::GoogleDiskCreate.new(
|
21
|
-
[stored_disk.name, "-Z"+stored_zone.name])
|
22
|
-
end
|
23
|
-
|
24
|
-
it "#run should invoke compute api to create a disk" do
|
25
|
-
zones = double(Google::Compute::ListableResourceCollection)
|
26
|
-
zones.should_receive(:get).
|
27
|
-
with(stored_zone.name).and_return(stored_zone)
|
28
|
-
disks = double(Google::Compute::CreatableResourceCollection)
|
29
|
-
disks.should_receive(:create).
|
30
|
-
with(:name => stored_disk.name, :sizeGb => 10, :zone => stored_zone.name).
|
31
|
-
and_return(stored_zone_operation)
|
32
|
-
client = double(Google::Compute::Client, :zones => zones, :disks => disks)
|
33
|
-
Google::Compute::Client.stub(:from_json).and_return(client)
|
34
|
-
knife_plugin.config[:disk_size] = 10
|
35
|
-
knife_plugin.run
|
36
|
-
end
|
37
|
-
end
|
@@ -1,64 +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 Chef::Knife::GoogleDiskDelete do
|
18
|
-
let(:knife_plugin) do
|
19
|
-
Chef::Knife::GoogleDiskDelete.new([stored_disk.name, "-Z"+stored_zone.name])
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should print out error message if the disk is not found" do
|
23
|
-
zones = double(Google::Compute::ListableResourceCollection)
|
24
|
-
zones.should_receive(:get).with(stored_zone.name).
|
25
|
-
and_return(stored_zone)
|
26
|
-
disks = double(Google::Compute::DeletableResourceCollection)
|
27
|
-
disks.should_receive(:get).
|
28
|
-
with(:zone => stored_zone.name, :disk => stored_disk.name).
|
29
|
-
and_raise(Google::Compute::ResourceNotFound)
|
30
|
-
disks.should_not_receive(:delete)
|
31
|
-
client = double(Google::Compute::Client,
|
32
|
-
:disks => disks, :zones => zones)
|
33
|
-
Google::Compute::Client.stub(:from_json).and_return(client)
|
34
|
-
|
35
|
-
knife_plugin.config[:yes] = true
|
36
|
-
knife_plugin.ui.should_receive(:error).
|
37
|
-
with("Disk '#{stored_zone.name}:#{stored_disk.name}' not found")
|
38
|
-
knife_plugin.stub(:msg_pair)
|
39
|
-
expect {
|
40
|
-
knife_plugin.run
|
41
|
-
}.to raise_error(SystemExit)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should invoke api delete method when run is called" do
|
45
|
-
zones = double(Google::Compute::ListableResourceCollection)
|
46
|
-
zones.should_receive(:get).with(stored_zone.name).
|
47
|
-
and_return(stored_zone)
|
48
|
-
disks = double(Google::Compute::DeletableResourceCollection)
|
49
|
-
disks.should_receive(:get).
|
50
|
-
with(:zone => stored_zone.name, :disk => stored_disk.name).
|
51
|
-
and_return(stored_disk)
|
52
|
-
disks.should_receive(:delete).
|
53
|
-
with(:zone => stored_zone.name, :disk => stored_disk.name)
|
54
|
-
client = double(Google::Compute::Client,
|
55
|
-
:zones => zones, :disks => disks)
|
56
|
-
Google::Compute::Client.stub(:from_json).
|
57
|
-
and_return(client)
|
58
|
-
knife_plugin.config[:yes] = true
|
59
|
-
knife_plugin.ui.should_receive(:warn).
|
60
|
-
with("Disk '#{stored_zone.name}:#{stored_disk.name}' deleted")
|
61
|
-
knife_plugin.stub(:msg_pair)
|
62
|
-
knife_plugin.run
|
63
|
-
end
|
64
|
-
end
|