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.
Files changed (111) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -3
  4. data/CHANGELOG.md +4 -6
  5. data/Gemfile +3 -9
  6. data/README.md +208 -355
  7. data/RELEASE_NOTES.md +8 -17
  8. data/Rakefile +8 -49
  9. data/knife-google.gemspec +20 -17
  10. data/lib/chef/knife/cloud/google_service.rb +491 -0
  11. data/lib/chef/knife/cloud/google_service_helpers.rb +62 -0
  12. data/lib/chef/knife/cloud/google_service_options.rb +58 -0
  13. data/lib/chef/knife/google_disk_create.rb +40 -44
  14. data/lib/chef/knife/google_disk_delete.rb +22 -40
  15. data/lib/chef/knife/google_disk_list.rb +57 -51
  16. data/lib/chef/knife/google_project_quotas.rb +59 -0
  17. data/lib/chef/knife/google_region_list.rb +43 -102
  18. data/lib/chef/knife/google_region_quotas.rb +77 -0
  19. data/lib/chef/knife/google_server_create.rb +224 -505
  20. data/lib/chef/knife/google_server_delete.rb +20 -78
  21. data/lib/chef/knife/google_server_list.rb +42 -53
  22. data/lib/chef/knife/google_server_show.rb +44 -0
  23. data/lib/chef/knife/google_zone_list.rb +39 -50
  24. data/lib/knife-google/version.rb +3 -2
  25. data/spec/cloud/google_service_helpers_spec.rb +120 -0
  26. data/spec/cloud/google_service_spec.rb +832 -0
  27. data/spec/google_disk_create_spec.rb +72 -0
  28. data/spec/google_disk_delete_spec.rb +64 -0
  29. data/spec/google_disk_list_spec.rb +93 -0
  30. data/spec/google_project_quotas_spec.rb +63 -0
  31. data/spec/google_region_list_spec.rb +65 -0
  32. data/spec/google_region_quotas_spec.rb +108 -0
  33. data/spec/google_server_create_spec.rb +177 -0
  34. data/spec/google_server_delete_spec.rb +39 -0
  35. data/spec/google_server_list_spec.rb +77 -0
  36. data/spec/google_server_show_spec.rb +60 -0
  37. data/spec/google_zone_list_spec.rb +59 -0
  38. metadata +91 -114
  39. data/CONTRIB.md +0 -64
  40. data/lib/chef/knife/google_base.rb +0 -76
  41. data/lib/chef/knife/google_project_list.rb +0 -178
  42. data/lib/chef/knife/google_setup.rb +0 -31
  43. data/lib/google/compute.rb +0 -47
  44. data/lib/google/compute/client.rb +0 -216
  45. data/lib/google/compute/config.rb +0 -23
  46. data/lib/google/compute/creatable_resource_collection.rb +0 -55
  47. data/lib/google/compute/deletable_resource_collection.rb +0 -51
  48. data/lib/google/compute/disk.rb +0 -38
  49. data/lib/google/compute/exception.rb +0 -30
  50. data/lib/google/compute/firewall.rb +0 -65
  51. data/lib/google/compute/global_operation.rb +0 -60
  52. data/lib/google/compute/image.rb +0 -29
  53. data/lib/google/compute/listable_resource_collection.rb +0 -33
  54. data/lib/google/compute/machine_type.rb +0 -36
  55. data/lib/google/compute/mixins/utils.rb +0 -58
  56. data/lib/google/compute/network.rb +0 -29
  57. data/lib/google/compute/project.rb +0 -76
  58. data/lib/google/compute/region.rb +0 -31
  59. data/lib/google/compute/region_operation.rb +0 -62
  60. data/lib/google/compute/resource.rb +0 -81
  61. data/lib/google/compute/resource_collection.rb +0 -78
  62. data/lib/google/compute/server.rb +0 -88
  63. data/lib/google/compute/server/attached_disk.rb +0 -39
  64. data/lib/google/compute/server/network_interface.rb +0 -38
  65. data/lib/google/compute/server/network_interface/access_config.rb +0 -35
  66. data/lib/google/compute/server/serial_port_output.rb +0 -31
  67. data/lib/google/compute/snapshot.rb +0 -30
  68. data/lib/google/compute/version.rb +0 -19
  69. data/lib/google/compute/zone.rb +0 -34
  70. data/lib/google/compute/zone_operation.rb +0 -62
  71. data/spec/chef/knife/google_base_spec.rb +0 -46
  72. data/spec/chef/knife/google_disk_create_spec.rb +0 -37
  73. data/spec/chef/knife/google_disk_delete_spec.rb +0 -64
  74. data/spec/chef/knife/google_disk_list_spec.rb +0 -36
  75. data/spec/chef/knife/google_region_list_spec.rb +0 -32
  76. data/spec/chef/knife/google_server_create_spec.rb +0 -138
  77. data/spec/chef/knife/google_server_delete_spec.rb +0 -127
  78. data/spec/chef/knife/google_server_list_spec.rb +0 -39
  79. data/spec/chef/knife/google_setup_spec.rb +0 -24
  80. data/spec/chef/knife/google_zone_list_spec.rb +0 -32
  81. data/spec/data/client.json +0 -14
  82. data/spec/data/compute-v1.json +0 -6734
  83. data/spec/data/disk.json +0 -14
  84. data/spec/data/firewall.json +0 -13
  85. data/spec/data/global_operation.json +0 -36
  86. data/spec/data/image.json +0 -12
  87. data/spec/data/machine_type.json +0 -24
  88. data/spec/data/network.json +0 -10
  89. data/spec/data/project.json +0 -21
  90. data/spec/data/region.json +0 -23
  91. data/spec/data/serial_port_output.json +0 -5
  92. data/spec/data/server.json +0 -46
  93. data/spec/data/snapshot.json +0 -12
  94. data/spec/data/zone.json +0 -22
  95. data/spec/data/zone_operation.json +0 -36
  96. data/spec/google/compute/disk_spec.rb +0 -115
  97. data/spec/google/compute/firewall_spec.rb +0 -129
  98. data/spec/google/compute/global_operation_spec.rb +0 -62
  99. data/spec/google/compute/image_spec.rb +0 -75
  100. data/spec/google/compute/machine_type_spec.rb +0 -53
  101. data/spec/google/compute/network_spec.rb +0 -68
  102. data/spec/google/compute/project_spec.rb +0 -71
  103. data/spec/google/compute/region_spec.rb +0 -51
  104. data/spec/google/compute/server_spec.rb +0 -118
  105. data/spec/google/compute/snapshot_spec.rb +0 -57
  106. data/spec/google/compute/zone_operation_spec.rb +0 -62
  107. data/spec/google/compute/zone_spec.rb +0 -51
  108. data/spec/spec_helper.rb +0 -45
  109. data/spec/support/mocks.rb +0 -62
  110. data/spec/support/resource_examples.rb +0 -70
  111. data/spec/support/spec_google_base.rb +0 -60
@@ -1,29 +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 Network < Resource
18
-
19
- attr_reader :ip_v4_range, :gateway_ipv4
20
-
21
- def from_hash(data)
22
- super(data)
23
- @ip_v4_range = data["IPv4Range"]
24
- @gateway_ipv4 = data["gatewayIPv4"]
25
- end
26
-
27
- end
28
- end
29
- end
@@ -1,76 +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 Project < Resource
18
-
19
- attr_reader :common_instance_metadata, :quotas
20
-
21
- def from_hash(data)
22
- super(data)
23
- @common_instance_metadata = data["commonInstanceMetadata"]
24
- @quotas = data["quotas"]
25
- end
26
-
27
- def set_common_instance_metadata(metadata)
28
- data = @dispatcher.dispatch(:api_method=>api_resource.set_common_instance_metadata,
29
- :parameters=>{:project=>name},
30
- :body_object=>{
31
- "kind" => "compute#metadata",
32
- "items" => metadata
33
- }
34
- )
35
- update!
36
- end
37
-
38
- def add_common_instance_metadata!(options)
39
- temp_metadata = @common_instance_metadata["items"]
40
- options.keys.each do |k|
41
- if common_instance_metadata["items"].any?{|metadata| metadata["key"] == k}
42
- raise ParameterValidation, "Key:'#{k}' already exist in common server metadata"
43
- else
44
- temp_metadata << {'key'=>k ,'value'=> options[k]}
45
- end
46
- end
47
- set_common_instance_metadata(temp_metadata)
48
- end
49
-
50
- def remove_common_instance_metadata!(options)
51
- temp_metadata = common_instance_metadata["items"]
52
- options.keys.each do |k|
53
- unless common_instance_metadata["items"].any?{|metadata| metadata['key'] == k}
54
- raise ParameterValidation, "Key:'#{k}' does not exist in common server metadata"
55
- else
56
- temp_metadata.delete({'key'=>k, 'value'=> options[k]})
57
- end
58
- end
59
- set_common_instance_metadata(temp_metadata)
60
- end
61
-
62
- def update_common_instance_metadata!(options)
63
- temp_metadata = @common_instance_metadata["items"]
64
- options.keys.each do |k|
65
- if common_instance_metadata["items"].any?{|metadata| metadata["key"] == k}
66
- metadata = common_instance_metadata["items"].select{|metadata| metadata["key"] == k}.first
67
- temp_metadata.delete(metadata)
68
- end
69
- temp_metadata << { 'key' => k, 'value'=> options[k]}
70
- end
71
- set_common_instance_metadata(temp_metadata)
72
- end
73
-
74
- end
75
- end
76
- 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
- module Google
16
- module Compute
17
- class Region < Resource
18
-
19
- attr_reader :status, :zones
20
- attr_reader :quotas, :deprecated
21
-
22
- def from_hash(region_data)
23
- super(region_data)
24
- @status = region_data["status"]
25
- @zones = region_data["zones"]
26
- @quotas = region_data["quotas"]
27
- @deprecated = region_data["deprecated"]
28
- end
29
- end
30
- end
31
- 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 RegionOperation < 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,81 +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/exception'
16
- require 'multi_json'
17
- require 'google/compute/mixins/utils'
18
-
19
- module Google
20
- module Compute
21
- class Resource
22
- include Utils
23
-
24
- attr_reader :kind, :id, :creation_timestamp
25
- attr_reader :name, :description, :self_link, :dispatcher
26
-
27
- def initialize(resource_data)
28
- from_hash(resource_data)
29
- end
30
-
31
- def to_s
32
- name
33
- end
34
-
35
- def project
36
- if self.is_a?(Google::Compute::Project)
37
- name
38
- else
39
- self_link=~Regexp.new('/projects/(.*?)/')
40
- $1
41
- end
42
- end
43
-
44
- def api_resource
45
- # MacineType => machine_types
46
- # Servers => instances
47
- collection_name = self.class.name.split('::').last.snake_case + "s"
48
- if collection_name == "servers"
49
- @dispatcher.compute.send("instances")
50
- else
51
- @dispatcher.compute.send(collection_name)
52
- end
53
- end
54
-
55
- def type
56
- kind.split('#').last
57
- end
58
-
59
- def self.class_name
60
- name.split('::').last.downcase
61
- end
62
-
63
- def update!
64
- data= @dispatcher.dispatch(:api_method=>api_resource.get,:parameters=>{type =>name})
65
- from_hash(data.merge(:dispatcher => @dispatcher))
66
- end
67
-
68
- def from_hash(resource_data)
69
- @kind = resource_data["kind"]
70
- @name = resource_data["name"]
71
- @self_link = resource_data["selfLink"]
72
- @id = resource_data["id"].to_i
73
- @description = resource_data["description"]
74
- unless resource_data["creationTimestamp"].nil?
75
- @creation_timestamp = Time.parse(resource_data["creationTimestamp"])
76
- end
77
- @dispatcher = resource_data[:dispatcher]
78
- end
79
- end
80
- end
81
- end
@@ -1,78 +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 ResourceCollection
18
-
19
- attr_reader :dispatcher
20
-
21
- def initialize(options)
22
- @dispatcher = options[:dispatcher]
23
- @resource_class= options[:resource_class]
24
- end
25
-
26
- def get(options={})
27
- if options.is_a?(String)
28
- options = name_to_hash(options)
29
- elsif options.is_a?(Google::Compute::Resource)
30
- options = name_to_hash(options.name)
31
- elsif options.is_a?(Hash) && options.has_key?(:name)
32
- options.merge!(name_to_hash(options[:name]))
33
- options.delete(:name)
34
- elsif options.is_a?(Hash) && options.has_key?(@resource_class.class_name.to_sym)
35
- else
36
- raise ParameterValidation, "argument must be :" +
37
- "name of the resource, or "+
38
- "a resource object, or " +
39
- "a hash with a key as resource name, eg ({:disk=>'xxx'}) , or " +
40
- "a hash with a :name key " +
41
- "you have passed '#{options.inspect}'"
42
- end
43
- if options.is_a?(Hash) && options.has_key?("server")
44
- options[:instance] = options["server"]
45
- options.delete("server")
46
- end
47
- data = @dispatcher.dispatch(:api_method=>api_resource.get, :parameters=>options)
48
- @resource_class.new(data.merge(:dispatcher=>@dispatcher))
49
- end
50
-
51
- def name_to_hash(resource_name)
52
- {downcase_first_letter(resource_class_name) => resource_name}
53
- end
54
-
55
- def downcase_first_letter(word)
56
- word.sub(/^[A-Z]/) {|f| f.downcase}
57
- end
58
-
59
- def resource_class_name
60
- name = @resource_class.name.split('::').last
61
- end
62
-
63
- def project
64
- @dispatcher.project
65
- end
66
-
67
- def api_resource
68
- # Servers => instances
69
- collection_name = resource_class_name.snake_case + "s"
70
- if collection_name == "servers"
71
- @dispatcher.compute.send("instances")
72
- else
73
- @dispatcher.compute.send(collection_name)
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,88 +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/serial_port_output'
16
- require 'google/compute/server/network_interface'
17
- require 'google/compute/server/attached_disk'
18
-
19
- module Google
20
- module Compute
21
- class Server < Resource
22
-
23
- attr_reader :tags, :machine_type, :status, :status_message, :zone
24
- attr_reader :network_interfaces, :disks, :metadata, :service_accounts
25
- attr_reader :scheduling
26
-
27
- def from_hash(data)
28
- super(data)
29
- @tags = data["tags"]
30
- @machine_type = data["machineType"]
31
- @status = data["status"]
32
- @status_message = data["statusMessage"]
33
- @zone = data["zone"]
34
- @network_interfaces = []
35
- if data["networkInterfaces"] || data["networkInterfaces"].is_a?(Array)
36
- data["networkInterfaces"].each do |interface|
37
- @network_interfaces << NetworkInterface.new(interface)
38
- end
39
- end
40
- @disks = []
41
- if data["disks"] || data["disks"].is_a?(Array)
42
- data["disks"].each do |disk_data|
43
- @disks << AttachedDisk.new(disk_data)
44
- end
45
- end
46
- @metadata = data["metadata"]
47
- @service_accounts = data["service_accounts"]
48
- @scheduling = data["scheduling"]
49
- end
50
-
51
- def serial_port_output
52
- @serial_port_output ||= begin
53
- data = @dispatcher.dispatch(:api_method => api_resource.get_serial_port_output,
54
- :parameters=>{ :project =>project, :zone=>zone,
55
- :instance => name
56
- })
57
- SerialPortOutput.new(data)
58
- end
59
- end
60
-
61
- def add_access_config(options={})
62
- interface = options.delete(:network_interface)
63
- interface = interface.name if interface.is_a?(Network::Interface)
64
- body_object = options[:access_config].to_hash
65
- data = @dispatcher.dispatch(:api_method => api_resource.add_access_config,
66
- :parameters=>{ :project => project,
67
- :instance => name,
68
- :network_interface => interface
69
- },
70
- :body_object => body_object)
71
- ZoneOperation.new(data.merge!(:dispatcher=>@dispatcher))
72
- end
73
-
74
- def delete_access_config(options={})
75
- interface = options.delete(:network_interface)
76
- interface = interface.name if interface.is_a?(Network::Interface)
77
- access_config = options[:access_config].to_hash if options[:access_config].is_a?(AccessConfig)
78
- data = @dispatcher.dispatch(:api_method => api_resource.delete_access_config,
79
- :parameters=>{ :project =>project,
80
- :instance => name,
81
- :network_interface => interface,
82
- :access_config => access_configs
83
- })
84
- ZoneOperation.new(data.merge!(:dispatcher=>@dispatcher))
85
- end
86
- end
87
- end
88
- end