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
@@ -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
|
-
#
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
25
|
+
class Chef::Knife::Cloud
|
26
|
+
class GoogleDiskCreate < Command
|
27
|
+
include GoogleServiceHelpers
|
28
|
+
include GoogleServiceOptions
|
22
29
|
|
23
|
-
|
30
|
+
banner "knife google disk create NAME --gce-disk-size N (options)"
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
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
|
-
#
|
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
|
-
|
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
|
-
|
25
|
+
class Chef::Knife::Cloud
|
26
|
+
class GoogleDiskDelete < Command
|
27
|
+
include GoogleServiceHelpers
|
28
|
+
include GoogleServiceOptions
|
24
29
|
|
25
|
-
|
26
|
-
require 'google/compute'
|
27
|
-
end
|
30
|
+
banner "knife google disk delete NAME [NAME] (options)"
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
49
|
-
|
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
|
-
#
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
25
|
+
class Chef::Knife::Cloud
|
26
|
+
class GoogleDiskList < ResourceListCommand
|
27
|
+
include GoogleServiceHelpers
|
28
|
+
include GoogleServiceOptions
|
22
29
|
|
23
|
-
|
30
|
+
banner "knife google disk list"
|
31
|
+
|
32
|
+
def validate_params!
|
33
|
+
check_for_missing_config_values!
|
34
|
+
super
|
35
|
+
end
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
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
|
-
|
32
|
-
|
47
|
+
@sort_by_field = "name"
|
48
|
+
end
|
49
|
+
|
50
|
+
def query_resource
|
51
|
+
service.list_disks
|
52
|
+
end
|
33
53
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
75
|
+
def format_users(users)
|
76
|
+
return "none" if users.nil? || users.empty?
|
49
77
|
|
50
|
-
|
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
|