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,23 +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 'mixlib/config'
|
16
|
-
|
17
|
-
module Google
|
18
|
-
module Compute
|
19
|
-
class Config
|
20
|
-
extend Mixlib::Config
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,55 +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 autoload :d 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 CreatableResourceCollection < DeletableResourceCollection
|
18
|
-
|
19
|
-
def create(options={})
|
20
|
-
if ["Server"].include? self.resource_class_name
|
21
|
-
data = @dispatcher.dispatch(:api_method => api_resource.insert,
|
22
|
-
:parameters=>{:project=>project, :zone=>options[:zone]},
|
23
|
-
:body_object => options )
|
24
|
-
ZoneOperation.new(data.merge!(:dispatcher=>@dispatcher))
|
25
|
-
elsif ["Disk"].include? self.resource_class_name
|
26
|
-
if options[:sourceImage].nil?
|
27
|
-
data = @dispatcher.dispatch(:api_method => api_resource.insert,
|
28
|
-
:parameters=>{:project=>project, :zone=>options[:zone]},
|
29
|
-
:body_object => options)
|
30
|
-
else
|
31
|
-
data = @dispatcher.dispatch(:api_method => api_resource.insert,
|
32
|
-
:parameters=>{:project=>project, :zone=>options[:zone], :sourceImage=>options[:sourceImage]},
|
33
|
-
:body_object => options)
|
34
|
-
end
|
35
|
-
ZoneOperation.new(data.merge!(:dispatcher=>@dispatcher))
|
36
|
-
else
|
37
|
-
data = @dispatcher.dispatch(:api_method => api_resource.insert,
|
38
|
-
:parameters=>{:project=>project},
|
39
|
-
:body_object => options )
|
40
|
-
GlobalOperation.new(data.merge!(:dispatcher=>@dispatcher))
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def insert(options={})
|
45
|
-
create(options)
|
46
|
-
end
|
47
|
-
|
48
|
-
def create_snapshot(options={})
|
49
|
-
data = @dispatcher.dispatch(:api_method => api_resource.create_snapshot, :parameters=>options)
|
50
|
-
ZoneOperation.new(data.merge!(:dispatcher=>@dispatcher)) unless data.nil?
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -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 'google/compute/listable_resource_collection'
|
16
|
-
|
17
|
-
module Google
|
18
|
-
module Compute
|
19
|
-
class DeletableResourceCollection < ListableResourceCollection
|
20
|
-
|
21
|
-
def initialize(options)
|
22
|
-
super(options)
|
23
|
-
options[:resource_class].class_eval do
|
24
|
-
def delete!
|
25
|
-
options={type=>name}
|
26
|
-
data = @dispatcher.dispatch(:api_method => api_resource.delete, :parameters=>options)
|
27
|
-
if ["Server", "Disk"].include? self.resource_class_name
|
28
|
-
ZoneOperation.new(data.merge!(:dispatcher=>@dispatcher)) unless data.nil?
|
29
|
-
else
|
30
|
-
GlobalOperation.new(data.merge!(:dispatcher=>@dispatcher)) unless data.nil?
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def delete(options)
|
37
|
-
if options.is_a?(Resource)
|
38
|
-
options = name_to_hash(options.name)
|
39
|
-
elsif options.is_a?(String)
|
40
|
-
options = name_to_hash(options)
|
41
|
-
end
|
42
|
-
data = @dispatcher.dispatch(:api_method => api_resource.delete, :parameters=>options)
|
43
|
-
if ["Server", "Disk"].include? self.resource_class_name
|
44
|
-
ZoneOperation.new(data.merge!(:dispatcher=>@dispatcher)) unless data.nil?
|
45
|
-
else
|
46
|
-
GlobalOperation.new(data.merge!(:dispatcher=>@dispatcher)) unless data.nil?
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/lib/google/compute/disk.rb
DELETED
@@ -1,38 +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
|
-
|
17
|
-
require 'google/compute/resource'
|
18
|
-
require 'google/compute/zone'
|
19
|
-
|
20
|
-
module Google
|
21
|
-
module Compute
|
22
|
-
class Disk < Resource
|
23
|
-
|
24
|
-
attr_reader :zone, :size_gb, :status, :options
|
25
|
-
attr_reader :source_snapshot, :source_snapshot_id
|
26
|
-
|
27
|
-
def from_hash(disk_data)
|
28
|
-
super(disk_data)
|
29
|
-
@zone = disk_data["zone"]
|
30
|
-
@size_gb = disk_data["sizeGb"]
|
31
|
-
@status = disk_data["status"]
|
32
|
-
@options = disk_data["options"]
|
33
|
-
@source_snapshot = disk_data["sourceSnapshot"]
|
34
|
-
@source_snapshot_id = disk_data["sourceSnapshotId"]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,30 +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
|
-
|
17
|
-
require 'faraday'
|
18
|
-
module Google
|
19
|
-
module Compute
|
20
|
-
class ParameterValidation < ArgumentError; end
|
21
|
-
class BadRequest < RuntimeError; end
|
22
|
-
class MethodNotOverridden < RuntimeError; end
|
23
|
-
class ClientUnitialized < RuntimeError; end
|
24
|
-
class OperationTimeout < RuntimeError; end
|
25
|
-
class HashConvert < RuntimeError; end
|
26
|
-
class ResourceNotFound < RuntimeError; end
|
27
|
-
class ConnectionFail < Faraday::Error::ConnectionFailed; end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
@@ -1,65 +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 Firewall < Resource
|
18
|
-
|
19
|
-
attr_reader :network, :source_ranges, :source_tags
|
20
|
-
attr_reader :target_tags, :allowed
|
21
|
-
|
22
|
-
def source_tags=(tags)
|
23
|
-
raise ParameterValidation, " tags must be an array of words" unless tags.is_a?(Array)
|
24
|
-
patch(:sourceTags=>tags)
|
25
|
-
update!
|
26
|
-
end
|
27
|
-
|
28
|
-
def target_tags=(tags)
|
29
|
-
raise ParameterValidation, " tags must be an array of words" unless tags.is_a?(Array)
|
30
|
-
patch(:targetTags=>tags)
|
31
|
-
update!
|
32
|
-
end
|
33
|
-
|
34
|
-
def source_ranges=(ranges)
|
35
|
-
raise ParameterValidation, " source ranges must be an array of words" unless ranges.is_a?(Array)
|
36
|
-
patch(:sourceRanges => ranges)
|
37
|
-
update!
|
38
|
-
end
|
39
|
-
|
40
|
-
def allowed=(allowed)
|
41
|
-
raise ParameterValidation, "allowed ingress rules must be an array of hashes" unless allowed.is_a?(Array)
|
42
|
-
patch(:allowed => allowed)
|
43
|
-
update!
|
44
|
-
end
|
45
|
-
|
46
|
-
def from_hash(data)
|
47
|
-
super(data)
|
48
|
-
@network = data["network"]
|
49
|
-
@source_ranges = data["sourceRanges"]
|
50
|
-
@source_tags = data["sourceTags"]
|
51
|
-
@target_tags = data["targetTags"]
|
52
|
-
@allowed = data["allowed"]
|
53
|
-
end
|
54
|
-
|
55
|
-
def patch(body_object)
|
56
|
-
body_object[:name] = name unless body_object.has_key?(:name)
|
57
|
-
body_object[:network] = network unless body_object.has_key?(:network)
|
58
|
-
data = @dispatcher.dispatch(:api_method => api_resource.patch,
|
59
|
-
:parameters=>{:firewall => name },
|
60
|
-
:body_object => body_object)
|
61
|
-
GlobalOperation.new(data.merge!(:dispatcher=>@dispatcher))
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,60 +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 GlobalOperation < 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/google/compute/image.rb
DELETED
@@ -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 Image < Resource
|
18
|
-
|
19
|
-
attr_reader :source_type, :raw_disk, :deprecated
|
20
|
-
|
21
|
-
def from_hash(data)
|
22
|
-
super(data)
|
23
|
-
@source_type = data["sourceType"]
|
24
|
-
@raw_disk = data["rawDisk"]
|
25
|
-
@deprecated = data["deprecated"]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,33 +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 autoload :d 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_collection'
|
16
|
-
|
17
|
-
module Google
|
18
|
-
module Compute
|
19
|
-
class ListableResourceCollection < ResourceCollection
|
20
|
-
|
21
|
-
def list(options={})
|
22
|
-
data = @dispatcher.dispatch(:api_method => api_resource.list, :parameters=>options)
|
23
|
-
items = []
|
24
|
-
if data.has_key?("items")
|
25
|
-
data["items"].each do |item|
|
26
|
-
items << @resource_class.new(item.merge!(:dispatcher=>@dispatcher))
|
27
|
-
end
|
28
|
-
end
|
29
|
-
items
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,36 +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 MachineType < Resource
|
18
|
-
|
19
|
-
attr_reader :memory_mb, :image_space_gb, :available_zone, :maximum_persistent_disks
|
20
|
-
attr_reader :guest_cpus, :ephemeral_disks, :maximum_persistent_disks_size_gb
|
21
|
-
attr_reader :deprecated
|
22
|
-
|
23
|
-
def from_hash(data)
|
24
|
-
super(data)
|
25
|
-
@memory_mb = data["memoryMb"]
|
26
|
-
@image_space_gb = data["imageSpaceGb"]
|
27
|
-
@available_zone = data["availableZone"]
|
28
|
-
@maximum_persistent_disks = data["maximumPersistentDisks"]
|
29
|
-
@guest_cpus = data["guestCpus"].to_i
|
30
|
-
@ephemeral_disks = data["ephemeralDisks"]
|
31
|
-
@maximum_persistent_disks_size_gb = data["maximumPersistentDisksSizeGb"]
|
32
|
-
@deprecated = data["deprecated"]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,58 +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 'multi_json'
|
15
|
-
require 'google/compute/exception'
|
16
|
-
|
17
|
-
module Google
|
18
|
-
module Compute
|
19
|
-
module Utils
|
20
|
-
|
21
|
-
def first_letter_lowercase_camelize(word)
|
22
|
-
first, *rest = word.split('_')
|
23
|
-
first + rest.map(&:capitalize).join
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_hash
|
27
|
-
hash={}
|
28
|
-
instance_variables.each do |variable|
|
29
|
-
variable_name = first_letter_lowercase_camelize( variable.to_s.sub(/^@/,'') )
|
30
|
-
next if variable_name == 'dispatcher'
|
31
|
-
variable_value = instance_variable_get(variable)
|
32
|
-
if variable_value.is_a?(String)
|
33
|
-
hash[variable_name] = variable_value
|
34
|
-
elsif variable_value.is_a?(Array)
|
35
|
-
hash[variable_name] = variable_value.collect{|v|
|
36
|
-
v.respond_to?(:to_hash) ? v.to_hash : v
|
37
|
-
}
|
38
|
-
elsif variable_value.is_a?(Hash)
|
39
|
-
hash[variable_name] = Hash[variable_value.collect{ |k,v|
|
40
|
-
[k, v.respond_to?(:to_hash) ? v.to_hash : v ]}
|
41
|
-
]
|
42
|
-
elsif variable_value.is_a?(Time)
|
43
|
-
hash[variable_name] = variable_value.to_s
|
44
|
-
elsif variable_value.respond_to?(:to_hash)
|
45
|
-
hash[variable_name] = variable_value.to_hash
|
46
|
-
else
|
47
|
-
hash[variable_name] = variable_value.to_s
|
48
|
-
end
|
49
|
-
end
|
50
|
-
hash
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_json
|
54
|
-
MultiJson.dump(to_hash)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|