knife-google 1.3.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,62 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2016 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class Chef::Knife::Cloud
20
+ module GoogleServiceHelpers
21
+ REQUIRED_KEYS = [:gce_project, :gce_zone]
22
+
23
+ def create_service_instance
24
+ Chef::Knife::Cloud::GoogleService.new(
25
+ project: locate_config_value(:gce_project),
26
+ zone: locate_config_value(:gce_zone),
27
+ wait_time: locate_config_value(:request_timeout),
28
+ refresh_rate: locate_config_value(:request_refresh_rate),
29
+ max_pages: locate_config_value(:max_pages),
30
+ max_page_size: locate_config_value(:max_page_size)
31
+ )
32
+ end
33
+
34
+ def check_for_missing_config_values!(*keys)
35
+ keys_to_check = REQUIRED_KEYS + keys
36
+
37
+ missing = keys_to_check.select { |x| locate_config_value(x).nil? }
38
+
39
+ unless missing.empty?
40
+ message = "The following required parameters are missing: #{missing.join(', ')}"
41
+ ui.error(message)
42
+ raise message
43
+ end
44
+ end
45
+
46
+ def private_ip_for(server)
47
+ server.network_interfaces.first.network_ip
48
+ rescue NoMethodError
49
+ "unknown"
50
+ end
51
+
52
+ def public_ip_for(server)
53
+ server.network_interfaces.first.access_configs.first.nat_ip
54
+ rescue NoMethodError
55
+ "unknown"
56
+ end
57
+
58
+ def valid_disk_size?(size)
59
+ size.between?(10, 10_000)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2016 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class Chef::Knife::Cloud
20
+ module GoogleServiceOptions
21
+ def self.included(includer)
22
+ includer.class_eval do
23
+ option :gce_project,
24
+ long: "--gce-project PROJECT",
25
+ description: "Name of the Google Cloud project to use"
26
+
27
+ option :gce_zone,
28
+ short: "-Z ZONE",
29
+ long: "--gce-zone ZONE",
30
+ description: "Name of the Google Compute Engine zone to use"
31
+
32
+ option :gce_max_pages,
33
+ long: "--gce-max-pages NUMPAGES",
34
+ description: "Maximum number of pages to request for paginated listing requests, defaults to 20",
35
+ default: 20,
36
+ proc: proc { |pages| pages.to_i }
37
+
38
+ option :gce_max_page_size,
39
+ long: "--gce-max-page-size NUMPAGES",
40
+ description: "Maximum number of items per page to request for paginated listing requests, defaults to 100",
41
+ default: 100,
42
+ proc: proc { |items| items.to_i }
43
+
44
+ option :request_refresh_rate,
45
+ long: "--request-refresh-rate SECS",
46
+ description: "Number of seconds to sleep between each check of the request status, defaults to 2",
47
+ default: 2,
48
+ proc: proc { |secs| secs.to_i }
49
+
50
+ option :request_timeout,
51
+ long: "--request-timeout SECS",
52
+ description: "Number of seconds to wait for a request to complete, defaults to 600",
53
+ default: 600,
54
+ proc: proc { |secs| secs.to_i }
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,4 +1,8 @@
1
- # Copyright 2013 Google Inc. All Rights Reserved.
1
+ #
2
+ # Author:: Paul Rossman (<paulrossman@google.com>)
3
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
+ # Copyright:: Copyright 2015-2016 Google Inc., Chef Software, Inc.
5
+ # License:: Apache License, Version 2.0
2
6
  #
3
7
  # Licensed under the Apache License, Version 2.0 (the "License");
4
8
  # you may not use this file except in compliance with the License.
@@ -11,58 +15,50 @@
11
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
16
  # See the License for the specific language governing permissions and
13
17
  # limitations under the License.
14
- #
15
- require 'chef/knife/google_base'
16
18
 
17
- class Chef
18
- class Knife
19
- class GoogleDiskCreate < Knife
19
+ require "chef/knife"
20
+ require "chef/knife/cloud/command"
21
+ require "chef/knife/cloud/google_service"
22
+ require "chef/knife/cloud/google_service_helpers"
23
+ require "chef/knife/cloud/google_service_options"
20
24
 
21
- include Knife::GoogleBase
25
+ class Chef::Knife::Cloud
26
+ class GoogleDiskCreate < Command
27
+ include GoogleServiceHelpers
28
+ include GoogleServiceOptions
22
29
 
23
- banner "knife google disk create NAME --gce-disk-size N -Z ZONE (options)"
30
+ banner "knife google disk create NAME --gce-disk-size N (options)"
24
31
 
25
- deps do
26
- require 'google/compute'
27
- end
32
+ option :disk_size,
33
+ long: "--gce-disk-size SIZE",
34
+ description: "Size of the persistent disk between 10 and 10000 GB, specified in GB; default is '10' GB",
35
+ default: 10,
36
+ proc: proc { |size| size.to_i }
28
37
 
29
- option :zone,
30
- :short => "-Z ZONE",
31
- :long => "--gce-zone ZONE",
32
- :description => "The Zone for this disk",
33
- :required => true
38
+ option :disk_type,
39
+ long: "--gce-disk-type TYPE",
40
+ description: "Disk type to use to create the disk. Possible values are 'pd-standard', 'pd-ssd' and 'local-ssd'; default is 'pd-standard'",
41
+ default: "pd-standard"
34
42
 
35
- option :disk_size,
36
- :long => "--gce-disk-size SIZE",
37
- :description => "Size of the persistent disk between 1 and 10000 GB, specified in GB; default is '1' GB",
38
- :default => "1"
43
+ option :disk_source,
44
+ long: "--gce-disk-source_image IMAGE_URL",
45
+ description: "GCE disk source image to use when creating disk, such as projects/centos-cloud/global/images/centos-7-v20160216; optional, if not supplied, a blank disk will be created",
46
+ default: nil
39
47
 
40
- def run
41
- $stdout.sync = true
42
- unless @name_args.size > 0
43
- ui.error("Please provide the name of the new disk")
44
- exit 1
45
- end
46
-
47
- begin
48
- zone = client.zones.get(config[:zone])
49
- rescue Google::Compute::ResourceNotFound
50
- ui.error("Zone '#{config[:zone]}' not found")
51
- exit 1
52
- end
48
+ def validate_params!
49
+ check_for_missing_config_values!(:disk_size, :disk_type)
50
+ raise "Please specify a disk name." unless @name_args.first
51
+ raise "Disk size must be between 10 and 10,000" unless valid_disk_size?(locate_config_value(:disk_size))
52
+ super
53
+ end
53
54
 
54
- begin
55
- disk_size = config[:disk_size].to_i
56
- raise if !disk_size.between?(1, 10000)
57
- rescue
58
- ui.error("Size of the persistent disk must be between 1 and 10000 GB.")
59
- exit 1
60
- end
55
+ def execute_command
56
+ name = @name_args.first
57
+ size = locate_config_value(:disk_size)
58
+ type = locate_config_value(:disk_type)
59
+ src = locate_config_value(:disk_source)
61
60
 
62
- zone_operation = client.disks.create(:name => @name_args.first,
63
- :sizeGb => config[:disk_size],
64
- :zone => zone.name)
65
- end
61
+ service.create_disk(name, size, type, src)
66
62
  end
67
63
  end
68
64
  end
@@ -1,4 +1,8 @@
1
- # Copyright 2013 Google Inc. All Rights Reserved.
1
+ #
2
+ # Author:: Paul Rossman (<paulrossman@google.com>)
3
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
+ # Copyright:: Copyright 2015-2016 Google Inc., Chef Software, Inc.
5
+ # License:: Apache License, Version 2.0
2
6
  #
3
7
  # Licensed under the Apache License, Version 2.0 (the "License");
4
8
  # you may not use this file except in compliance with the License.
@@ -11,50 +15,28 @@
11
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
16
  # See the License for the specific language governing permissions and
13
17
  # limitations under the License.
14
- #
15
- require 'chef/knife/google_base'
16
-
17
- class Chef
18
- class Knife
19
- class GoogleDiskDelete < Knife
20
18
 
21
- include Knife::GoogleBase
19
+ require "chef/knife"
20
+ require "chef/knife/cloud/command"
21
+ require "chef/knife/cloud/google_service"
22
+ require "chef/knife/cloud/google_service_helpers"
23
+ require "chef/knife/cloud/google_service_options"
22
24
 
23
- banner "knife google disk delete NAME -Z ZONE (options)"
25
+ class Chef::Knife::Cloud
26
+ class GoogleDiskDelete < Command
27
+ include GoogleServiceHelpers
28
+ include GoogleServiceOptions
24
29
 
25
- deps do
26
- require 'google/compute'
27
- end
30
+ banner "knife google disk delete NAME [NAME] (options)"
28
31
 
29
- option :zone,
30
- :short => "-Z ZONE",
31
- :long => "--gce-zone ZONE",
32
- :description => "The Zone for this disk",
33
- :required => true
34
-
35
- def run
36
- unless @name_args.size > 0
37
- ui.error("Please provide the name of the disk to be deleted")
38
- exit 1
39
- end
40
-
41
- begin
42
- zone = client.zones.get(config[:zone])
43
- rescue Google::Compute::ResourceNotFound
44
- ui.error("Zone '#{config[:zone]}' not found")
45
- exit 1
46
- end
32
+ def validate_params!
33
+ check_for_missing_config_values!
34
+ raise "You must specify at least one disk to delete." if @name_args.empty?
35
+ super
36
+ end
47
37
 
48
- begin
49
- disk = client.disks.get(:zone=>zone.name, :disk=>@name_args.first)
50
- ui.confirm("Are you sure you want to delete disk '#{zone.name}:#{disk.name}'")
51
- zone_operation = client.disks.delete(:zone=>zone.name, :disk=>disk.name)
52
- ui.warn("Disk '#{zone.name}:#{disk.name}' deleted")
53
- rescue Google::Compute::ResourceNotFound
54
- ui.error("Disk '#{zone.name}:#{@name_args.first}' not found")
55
- exit 1
56
- end
57
- end
38
+ def execute_command
39
+ @name_args.each { |disk| service.delete_disk(disk) }
58
40
  end
59
41
  end
60
42
  end
@@ -1,4 +1,8 @@
1
- # Copyright 2013 Google Inc. All Rights Reserved.
1
+ #
2
+ # Author:: Paul Rossman (<paulrossman@google.com>)
3
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
+ # Copyright:: Copyright 2015-2016 Google Inc., Chef Software, Inc.
5
+ # License:: Apache License, Version 2.0
2
6
  #
3
7
  # Licensed under the Apache License, Version 2.0 (the "License");
4
8
  # you may not use this file except in compliance with the License.
@@ -11,65 +15,67 @@
11
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
16
  # See the License for the specific language governing permissions and
13
17
  # limitations under the License.
14
- #
15
- require 'chef/knife/google_base'
16
18
 
17
- class Chef
18
- class Knife
19
- class GoogleDiskList < Knife
19
+ require "chef/knife"
20
+ require "chef/knife/cloud/list_resource_command"
21
+ require "chef/knife/cloud/google_service"
22
+ require "chef/knife/cloud/google_service_helpers"
23
+ require "chef/knife/cloud/google_service_options"
20
24
 
21
- include Knife::GoogleBase
25
+ class Chef::Knife::Cloud
26
+ class GoogleDiskList < ResourceListCommand
27
+ include GoogleServiceHelpers
28
+ include GoogleServiceOptions
22
29
 
23
- banner "knife google disk list -Z ZONE (options)"
30
+ banner "knife google disk list"
31
+
32
+ def validate_params!
33
+ check_for_missing_config_values!
34
+ super
35
+ end
24
36
 
25
- option :zone,
26
- :short => "-Z ZONE",
27
- :long => "--gce-zone ZONE",
28
- :description => "The Zone for disk listing",
29
- :required => true
37
+ def before_exec_command
38
+ @columns_with_info = [
39
+ { label: "Zone", key: "name" },
40
+ { label: "Status", key: "status", value_callback: method(:format_status_value) },
41
+ { label: "Size (GB)", key: "size_gb" },
42
+ { label: "Type", key: "type", value_callback: method(:format_disk_type) },
43
+ { label: "Source Image", key: "source_image", value_callback: method(:format_source_image) },
44
+ { label: "Attached To", key: "users", value_callback: method(:format_users) },
45
+ ]
30
46
 
31
- def run
32
- $stdout.sync = true
47
+ @sort_by_field = "name"
48
+ end
49
+
50
+ def query_resource
51
+ service.list_disks
52
+ end
33
53
 
34
- begin
35
- zone = client.zones.get(config[:zone])
36
- rescue Google::Compute::ResourceNotFound
37
- ui.error("Zone '#{config[:zone]}' not found")
38
- exit 1
39
- end
54
+ def format_status_value(status)
55
+ status = status.downcase
56
+ status_color = if status == "ready"
57
+ :green
58
+ else
59
+ :red
60
+ end
40
61
 
41
- disk_list = [
42
- ui.color("name", :bold),
43
- ui.color('zone', :bold),
44
- ui.color('source snapshot', :bold),
45
- ui.color('size (in GB)', :bold),
46
- ui.color('status', :bold)].flatten.compact
62
+ ui.color(status, status_color)
63
+ end
64
+
65
+ def format_disk_type(type)
66
+ type.split("/").last
67
+ end
68
+
69
+ def format_source_image(source)
70
+ return "unknown" if source.nil? || source.empty?
71
+
72
+ source.split("/").last(4).join("/")
73
+ end
47
74
 
48
- output_column_count = disk_list.length
75
+ def format_users(users)
76
+ return "none" if users.nil? || users.empty?
49
77
 
50
- client.disks.list(:zone=>zone.name).each do |disk|
51
- disk_list << disk.name
52
- disk_list << selflink2name(disk.zone)
53
- if disk.source_snapshot.nil?
54
- disk_list << " "
55
- else
56
- disk_list << selflink2name(disk.source_snapshot)
57
- end
58
- disk_list << disk.size_gb
59
- disk_list << begin
60
- status = disk.status.downcase
61
- case status
62
- when 'stopping', 'stopped', 'terminated'
63
- ui.color(status, :red)
64
- when 'requested', 'provisioning', 'staging'
65
- ui.color(status, :yellow)
66
- else
67
- ui.color(status, :green)
68
- end
69
- end
70
- end
71
- ui.info(ui.list(disk_list, :uneven_columns_across, output_column_count))
72
- end
78
+ users.map { |user| user.split("/").last(5).join("/") }.join(", ")
73
79
  end
74
80
  end
75
81
  end
@@ -0,0 +1,59 @@
1
+ #
2
+ # Author:: Paul Rossman (<paulrossman@google.com>)
3
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
+ # Copyright:: Copyright 2015-2016 Google Inc., Chef Software, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require "chef/knife"
20
+ require "chef/knife/cloud/list_resource_command"
21
+ require "chef/knife/cloud/google_service"
22
+ require "chef/knife/cloud/google_service_helpers"
23
+ require "chef/knife/cloud/google_service_options"
24
+
25
+ class Chef::Knife::Cloud
26
+ class GoogleProjectQuotas < ResourceListCommand
27
+ include GoogleServiceHelpers
28
+ include GoogleServiceOptions
29
+
30
+ banner "knife google project quotas"
31
+
32
+ def validate_params!
33
+ check_for_missing_config_values!
34
+ super
35
+ end
36
+
37
+ def before_exec_command
38
+ @columns_with_info = [
39
+ { label: "Quota", key: "metric", value_callback: method(:format_name) },
40
+ { label: "Limit", key: "limit", value_callback: method(:format_number) },
41
+ { label: "Usage", key: "usage", value_callback: method(:format_number) },
42
+ ]
43
+
44
+ @sort_by_field = "metric"
45
+ end
46
+
47
+ def query_resource
48
+ service.list_project_quotas
49
+ end
50
+
51
+ def format_name(name)
52
+ name.split("_").map { |x| x.capitalize }.join(" ")
53
+ end
54
+
55
+ def format_number(number)
56
+ number % 1 == 0 ? number.to_i.to_s : number.to_s
57
+ end
58
+ end
59
+ end