knife-bmcs 1.0.0 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be2e5406c2c26806829a393a11214ab8d49a8ff3
4
- data.tar.gz: 6a562eda67b9f8d5261f60921e4d7de5b5d8e310
3
+ metadata.gz: 47f21fe0f6507245c1d3c9fc95ce4829a1407844
4
+ data.tar.gz: 8ef24336bf304e95dc87dda20f77876c8514c79c
5
5
  SHA512:
6
- metadata.gz: 362935ec20291a749046113c309cf0e3156d52be47cd6b022fae2c994790125613b5ca26c6880bf5c6a30d9b8769d4d15eca205eadbe62e414c9cb2de0527c58
7
- data.tar.gz: fad73265958e040f3e802903f2ef9d78782c1066ce9203f7b119f5a9dbcab27710f6e8064090d55a3a8428f6cff6cca7e5bf718a94518a5d816817bc10c00d75
6
+ metadata.gz: 91c53c4058855c927b702d15f51597866cf46cbee60cef988553da91c747d22a72e3ab6b6a38d18378b83cc80745ddb035da7ae7c8cee05bef1986645fd50b8e
7
+ data.tar.gz: 6576f47751f12f4d38344eee22cff27745cfbb1619b7c4ba1d46e87d33ac59b02702898f2c186ccd97b885f97386c5be529b170e5a9682b44365e1fa96a95b3e
@@ -9,6 +9,10 @@ class Chef
9
9
  module BmcsCommonOptions
10
10
  def self.included(includer)
11
11
  includer.class_eval do
12
+ option :region,
13
+ long: '--region REGION',
14
+ description: 'The region to make calls against. (e.g., `us-ashburn-1`)'
15
+
12
16
  option :bmcs_config_file,
13
17
  long: '--bmcs-config-file FILE',
14
18
  description: 'The path to the Oracle BMCS config file. Default: ~/.oraclebmc/config'
@@ -16,7 +20,10 @@ class Chef
16
20
  option :bmcs_profile,
17
21
  long: '--bmcs-profile PROFILE',
18
22
  description: 'The profile to load from the Oracle BMCS config file. Default: DEFAULT'
19
-
23
+ end
24
+ # all commands except compartment list get a compartment-id option
25
+ return if includer.to_s == 'Chef::Knife::BmcsCompartmentList'
26
+ includer.class_eval do
20
27
  option :compartment_id,
21
28
  long: '--compartment-id COMPARTMENT',
22
29
  description: 'The OCID of the compartment.'
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'chef/knife/bmcs_common_options'
5
+ require 'chef/knife/bmcs_helper'
6
+
7
+ class Chef
8
+ class Knife
9
+ # List BMCS compartments
10
+ class BmcsCompartmentList < Knife
11
+ banner 'knife bmcs compartment list (options)'
12
+
13
+ include BmcsHelper
14
+ include BmcsCommonOptions
15
+
16
+ deps do
17
+ require 'oraclebmc'
18
+ end
19
+
20
+ option :limit,
21
+ long: '--limit LIMIT',
22
+ description: 'The maximum number of items to return.'
23
+
24
+ def run
25
+ options = {}
26
+ options[:limit] = config[:limit] if config[:limit]
27
+
28
+ response = identity_client.list_compartments(bmcs_config.tenancy, options)
29
+ # Check whether there is a next page to decide whether to show an 'output is truncated' warning.
30
+ # TODO: expected to be addressed server-side in a future release at which point this special
31
+ # handling can be removed.
32
+ show_truncated_warning = false
33
+ if response && response.headers.include?('opc-next-page')
34
+ response_page2 = identity_client.list_compartments(bmcs_config.tenancy, options.merge(page: response.headers['opc-next-page']))
35
+ show_truncated_warning = response_page2 && response_page2.data && !response_page2.data.empty?
36
+ end
37
+
38
+ display_list(response, ['Display Name', 'ID'], warn_on_truncated: show_truncated_warning) do |item|
39
+ [item.name, item.id]
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -3,6 +3,7 @@
3
3
  require 'chef/knife'
4
4
  require 'knife-bmcs/version'
5
5
 
6
+ # rubocop:disable Metrics/ModuleLength
6
7
  class Chef
7
8
  class Knife
8
9
  # BMCS helper module
@@ -13,6 +14,7 @@ class Chef
13
14
  config_file = config[:bmcs_config_file] || Chef::Config[:knife][:bmcs_config_file] || OracleBMC::ConfigFileLoader::DEFAULT_CONFIG_FILE
14
15
  profile = config[:bmcs_profile] || Chef::Config[:knife][:bmcs_profile] || OracleBMC::ConfigFileLoader::DEFAULT_PROFILE
15
16
  @bmcs_config = OracleBMC::ConfigFileLoader.load_config(config_file_location: config_file, profile_name: profile)
17
+ @bmcs_config.region = config[:region] if config[:region]
16
18
 
17
19
  @bmcs_config.additional_user_agent = "Oracle-ChefKnifeBMCS/#{::Knife::BMCS::VERSION}"
18
20
  end
@@ -48,15 +50,21 @@ class Chef
48
50
  params[param].nil?
49
51
  end
50
52
 
51
- error_and_exit("Missing the following required parameters: #{missing_params.join(', ').tr!('_', '-')}") unless missing_params.empty?
53
+ error_and_exit("Missing the following required parameters: #{missing_params.join(', ').tr('_', '-')}") unless missing_params.empty?
52
54
  end
53
55
 
54
56
  def warn_if_page_is_truncated(response)
55
57
  ui.warn('This list has been truncated. To view more items, increase the limit.') if response.headers.include? 'opc-next-page'
56
58
  end
57
59
 
58
- def display_list(response, columns)
59
- list = response.data
60
+ # TODO: Method should be refactored to reduce complexity.
61
+ # rubocop:disable Metrics/PerceivedComplexity
62
+ def display_list(response, columns, warn_on_truncated: true)
63
+ list = if response.data.nil?
64
+ []
65
+ else
66
+ response.data.is_a?(Array) ? response.data : [response.data]
67
+ end
60
68
  list_for_display = []
61
69
 
62
70
  if config[:format] == 'summary'
@@ -87,7 +95,52 @@ class Chef
87
95
  ui.output(list_for_display)
88
96
  end
89
97
 
90
- warn_if_page_is_truncated(response)
98
+ warn_if_page_is_truncated(response) if warn_on_truncated
99
+ end
100
+
101
+ # Return a true or false with the confirmation result.
102
+ # Note: user prompt is bypassed with --yes to confirm automatically.
103
+ def confirm(prompt)
104
+ return true if config[:yes]
105
+ valid_responses = %w[yes no y n]
106
+ response = nil
107
+ 3.times do
108
+ response = ui.ask(prompt).downcase
109
+ break if valid_responses.include? response
110
+ ui.warn "Valid responses are #{valid_responses}"
111
+ end
112
+ response.match(/^y/)
113
+ end
114
+
115
+ def check_can_access_instance(instance_id)
116
+ response = compute_client.get_instance(instance_id)
117
+ error_and_exit 'Instance is already in terminated state' if response && response.data && response.data.lifecycle_state == OracleBMC::Core::Models::Instance::LIFECYCLE_STATE_TERMINATED
118
+ rescue OracleBMC::Errors::ServiceError => service_error
119
+ raise unless service_error.serviceCode == 'NotAuthorizedOrNotFound'
120
+ error_and_exit 'Instance not authorized or not found'
121
+ else
122
+ return response
123
+ end
124
+
125
+ def show_value(key, value, color = :cyan)
126
+ ui.msg "#{ui.color(key, color)}: #{value}" if value && !value.to_s.empty?
127
+ end
128
+
129
+ def display_server_info(config, instance, vnics)
130
+ show_value('Display Name', instance.display_name)
131
+ show_value('Instance ID', instance.id)
132
+ show_value('Availability Domain', instance.availability_domain)
133
+ show_value('Compartment ID', instance.compartment_id)
134
+ show_value('Region', instance.region)
135
+ show_value('Image ID', instance.image_id)
136
+ show_value('Shape', instance.shape)
137
+ vnics.each_index do |index|
138
+ prefix = vnics[index].is_primary ? 'Primary' : 'Secondary'
139
+ show_value("#{prefix} Public IP Address", vnics[index].public_ip)
140
+ show_value("#{prefix} Private IP Address", vnics[index].private_ip)
141
+ show_value("#{prefix} Hostname", vnics[index].hostname_label)
142
+ end
143
+ show_value('Node Name', config[:chef_node_name])
91
144
  end
92
145
  end
93
146
  end
@@ -8,7 +8,8 @@ require 'chef/knife/bmcs_common_options'
8
8
  SSH_PORT = 22
9
9
 
10
10
  WAIT_FOR_SSH_INTERVAL_SECONDS = 2
11
- WAIT_FOR_SSH_MAX_SECONDS = 180
11
+ DEFAULT_WAIT_FOR_SSH_MAX_SECONDS = 180
12
+ DEFAULT_WAIT_TO_STABILIZE_SECONDS = 40
12
13
 
13
14
  class Chef
14
15
  class Knife
@@ -35,7 +36,7 @@ class Chef
35
36
 
36
37
  option :availability_domain,
37
38
  long: '--availability-domain AD',
38
- description: 'The Availability Domain of the instance.'
39
+ description: 'The Availability Domain of the instance. (required)'
39
40
 
40
41
  option :display_name,
41
42
  long: '--display-name NAME',
@@ -49,7 +50,7 @@ class Chef
49
50
 
50
51
  option :image_id,
51
52
  long: '--image-id IMAGE',
52
- description: 'The OCID of the image used to boot the instance.'
53
+ description: 'The OCID of the image used to boot the instance. (required)'
53
54
 
54
55
  option :metadata,
55
56
  long: '--metadata METADATA',
@@ -57,18 +58,18 @@ class Chef
57
58
 
58
59
  option :shape,
59
60
  long: '--shape SHAPE',
60
- description: 'The shape of an instance. The shape determines the number of CPUs, amount of memory, and other resources allocated to the instance.'
61
+ description: 'The shape of an instance. The shape determines the number of CPUs, amount of memory, and other resources allocated to the instance. (required)'
61
62
 
62
63
  option :ssh_authorized_keys_file,
63
64
  long: '--ssh-authorized-keys-file FILE',
64
65
  description: 'A file containing one or more public SSH keys to be included in the ~/.ssh/authorized_keys file for the default user on the instance. '\
65
66
  'Use a newline character to separate multiple keys. The SSH keys must be in the format necessary for the authorized_keys file. This parameter '\
66
67
  "is a convenience wrapper around the 'ssh_authorized_keys' field of the --metadata parameter. Populating both values in the same call will result "\
67
- 'in an error. For more info see documentation: https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/requests/LaunchInstanceDetails.'
68
+ 'in an error. For more info see documentation: https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/requests/LaunchInstanceDetails. (required)'
68
69
 
69
70
  option :subnet_id,
70
71
  long: '--subnet-id SUBNET',
71
- description: 'The OCID of the subnet.'
72
+ description: 'The OCID of the subnet. (required)'
72
73
 
73
74
  option :user_data_file,
74
75
  long: '--user-data-file FILE',
@@ -90,7 +91,7 @@ class Chef
90
91
  option :identity_file,
91
92
  short: '-i FILE',
92
93
  long: '--identity-file IDENTITY_FILE',
93
- description: 'The SSH identity file used for authentication. This must correspond to a public SSH key provided by --ssh-authorized-keys-file.'
94
+ description: 'The SSH identity file used for authentication. This must correspond to a public SSH key provided by --ssh-authorized-keys-file. (required)'
94
95
 
95
96
  option :chef_node_name,
96
97
  short: '-N NAME',
@@ -104,9 +105,18 @@ class Chef
104
105
  proc: ->(o) { o.split(/[\s,]+/) },
105
106
  default: []
106
107
 
108
+ option :wait_to_stabilize,
109
+ long: '--wait-to-stabilize SECONDS',
110
+ description: "Duration to pause after SSH becomes reachable. Default: #{DEFAULT_WAIT_TO_STABILIZE_SECONDS}"
111
+
112
+ option :wait_for_ssh_max,
113
+ long: '--wait-for-ssh-max SECONDS',
114
+ description: "The maximum time to wait for SSH to become reachable. Default: #{DEFAULT_WAIT_FOR_SSH_MAX_SECONDS}"
115
+
107
116
  def run
108
117
  $stdout.sync = true
109
- validate_required_params(%i[availability_domain image_id shape subnet_id identity_file], config)
118
+ validate_required_params(%i[availability_domain image_id shape subnet_id identity_file ssh_authorized_keys_file], config)
119
+ validate_wait_options
110
120
 
111
121
  metadata = merge_metadata
112
122
  error_and_exit 'SSH authorized keys must be specified.' unless metadata['ssh_authorized_keys']
@@ -141,7 +151,7 @@ class Chef
141
151
  show_value('Public IP Address', vnic.public_ip)
142
152
  show_value('Private IP Address', vnic.private_ip)
143
153
 
144
- unless wait_for_ssh(vnic.public_ip, SSH_PORT, WAIT_FOR_SSH_INTERVAL_SECONDS, WAIT_FOR_SSH_MAX_SECONDS)
154
+ unless wait_for_ssh(vnic.public_ip, SSH_PORT, WAIT_FOR_SSH_INTERVAL_SECONDS, config[:wait_for_ssh_max])
145
155
  error_and_exit 'Timed out while waiting for SSH access.'
146
156
  end
147
157
 
@@ -157,17 +167,7 @@ class Chef
157
167
  ui.msg "Created and bootstrapped node '#{config[:chef_node_name]}'."
158
168
  ui.msg "\n"
159
169
 
160
- show_value('Display Name', instance.display_name)
161
- show_value('Instance ID', instance.id)
162
- show_value('Availability Domain', instance.availability_domain)
163
- show_value('Compartment ID', instance.compartment_id)
164
- show_value('Region', instance.region)
165
- show_value('Image ID', instance.image_id)
166
- show_value('Shape', instance.shape)
167
- show_value('Public IP Address', vnic.public_ip)
168
- show_value('Private IP Address', vnic.private_ip)
169
- show_value('Hostname', vnic.hostname_label)
170
- show_value('Node Name', config[:chef_node_name])
170
+ display_server_info(config, instance, [vnic])
171
171
  end
172
172
 
173
173
  def bootstrap(name)
@@ -187,11 +187,24 @@ class Chef
187
187
  bootstrap.run
188
188
  end
189
189
 
190
+ def validate_wait_option(p, default)
191
+ arg_name = "--#{p.to_s.tr('_', '-')}"
192
+ config[p] = config[p].to_s.empty? ? default : Integer(config[p])
193
+ error_and_exit "#{arg_name} must be 0 or greater" if config[p] < 0
194
+ rescue
195
+ error_and_exit "#{arg_name} must be numeric"
196
+ end
197
+
198
+ def validate_wait_options
199
+ validate_wait_option(:wait_to_stabilize, DEFAULT_WAIT_TO_STABILIZE_SECONDS)
200
+ validate_wait_option(:wait_for_ssh_max, DEFAULT_WAIT_FOR_SSH_MAX_SECONDS)
201
+ end
202
+
190
203
  def wait_to_stabilize
191
204
  # This extra sleep even after getting SSH access is necessary. It's not clear why, but without it we often get
192
205
  # errors about missing a password for ssh, or sometimes errors during bootstrapping. (Note that plugins for other
193
206
  # cloud providers have similar sleeps.)
194
- sleep(40)
207
+ Kernel.sleep(config[:wait_to_stabilize])
195
208
  end
196
209
 
197
210
  def wait_for_ssh(hostname, ssh_port, interval_seconds, max_time_seconds)
@@ -303,10 +316,6 @@ class Chef
303
316
  print ui.color("done\n", :magenta)
304
317
  end
305
318
 
306
- def show_value(key, value, color = :cyan)
307
- ui.msg "#{ui.color(key, color)}: #{value}" if value && !value.to_s.empty?
308
- end
309
-
310
319
  def get_file_content(file_name_param)
311
320
  file_name = config[file_name_param]
312
321
  return if file_name.nil?
@@ -0,0 +1,105 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'chef/knife/bmcs_helper'
5
+ require 'chef/knife/bmcs_common_options'
6
+
7
+ # max interval for polling the server state
8
+ MAX_INTERVAL_SECONDS = 3
9
+
10
+ class Chef
11
+ class Knife
12
+ # Server Delete Command: Delete a BMCS instance.
13
+ class BmcsServerDelete < Knife
14
+ banner 'knife bmcs server delete (options)'
15
+
16
+ include BmcsHelper
17
+ include BmcsCommonOptions
18
+
19
+ deps do
20
+ require 'oraclebmc'
21
+ require 'chef/knife/bootstrap'
22
+ end
23
+
24
+ option :instance_id,
25
+ long: '--instance-id INSTANCE',
26
+ description: 'The OCID of the instance to be deleted. (required)'
27
+
28
+ option :wait,
29
+ long: '--wait SECONDS',
30
+ description: 'Wait for the instance to be terminated. 0=infinite'
31
+
32
+ def run
33
+ $stdout.sync = true
34
+ validate_required_params(%i[instance_id], config)
35
+ wait_for = validate_wait
36
+
37
+ confirm_deletion
38
+
39
+ check_can_access_instance(config[:instance_id])
40
+
41
+ terminate_instance(config[:instance_id])
42
+
43
+ wait_for_instance_terminated(config[:instance_id], wait_for) if wait_for
44
+ end
45
+
46
+ def terminate_instance(instance_id)
47
+ compute_client.terminate_instance(instance_id)
48
+
49
+ ui.msg "Initiated delete of instance #{instance_id}"
50
+ end
51
+
52
+ def wait_for_instance_terminated(instance_id, wait_for)
53
+ print ui.color('Waiting for instance to terminate...', :magenta)
54
+ begin
55
+ begin
56
+ compute_client.get_instance(instance_id).wait_until(:lifecycle_state,
57
+ OracleBMC::Core::Models::Instance::LIFECYCLE_STATE_TERMINATED,
58
+ get_wait_options(wait_for)) do
59
+ show_progress
60
+ end
61
+ ensure
62
+ end_progress_indicator
63
+ end
64
+ rescue OracleBMC::Waiter::Errors::MaximumWaitTimeExceededError
65
+ error_and_exit 'Timeout exceeded while waiting for instance to terminate'
66
+ rescue OracleBMC::Errors::ServiceError => service_error
67
+ raise unless service_error.serviceCode == 'NotAuthorizedOrNotFound'
68
+ # we'll soak this exception since the terminate may have completed before we started waiting for it.
69
+ ui.warn 'Instance not authorized or not found'
70
+ end
71
+ end
72
+
73
+ def validate_wait
74
+ wait_for = nil
75
+ if config[:wait]
76
+ wait_for = Integer(config[:wait])
77
+ error_and_exit 'Wait value must be 0 or greater' if wait_for < 0
78
+ end
79
+ wait_for
80
+ end
81
+
82
+ def get_wait_options(wait_for)
83
+ opts = {
84
+ max_interval_seconds: MAX_INTERVAL_SECONDS
85
+ }
86
+ opts[:max_wait_seconds] = wait_for if wait_for > 0
87
+ opts
88
+ end
89
+
90
+ def confirm_deletion
91
+ return if confirm('Delete server? (y/n)')
92
+ error_and_exit 'Server delete canceled.'
93
+ end
94
+
95
+ def show_progress
96
+ print ui.color('.', :magenta)
97
+ $stdout.flush
98
+ end
99
+
100
+ def end_progress_indicator
101
+ print ui.color("done\n", :magenta)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -6,7 +6,8 @@ require 'chef/knife/bmcs_helper'
6
6
 
7
7
  class Chef
8
8
  class Knife
9
- # List BMCS instances. Note that this list all instances in a compartment, not just those that are set up as Chef nodes.
9
+ # List BMCS instances. Note that this lists all instances in a
10
+ # compartment, not just those that are set up as Chef nodes.
10
11
  class BmcsServerList < Knife
11
12
  banner 'knife bmcs server list (options)'
12
13
 
@@ -27,8 +28,11 @@ class Chef
27
28
 
28
29
  response = compute_client.list_instances(compartment_id, options)
29
30
 
30
- display_list(response, ['Display Name', 'ID', 'State']) do |item|
31
- [item.display_name, item.id, item.lifecycle_state]
31
+ display_list(response,
32
+ ['Display Name', 'State', 'ID']) do |item|
33
+ [item.display_name,
34
+ item.lifecycle_state,
35
+ item.id]
32
36
  end
33
37
  end
34
38
  end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'chef/knife/bmcs_common_options'
5
+ require 'chef/knife/bmcs_helper'
6
+
7
+ class Chef
8
+ class Knife
9
+ # List BMCS instances. Note that this lists all instances in a
10
+ # compartment, not just those that are set up as Chef nodes.
11
+ class BmcsServerShow < Knife
12
+ banner 'knife bmcs server show (options)'
13
+
14
+ include BmcsHelper
15
+ include BmcsCommonOptions
16
+
17
+ deps do
18
+ require 'oraclebmc'
19
+ end
20
+
21
+ option :instance_id,
22
+ long: '--instance_id LIMIT',
23
+ description: 'The OCID of the server to display. (required)'
24
+
25
+ def run
26
+ validate_required_params(%i[instance_id], config)
27
+ vnic_array = []
28
+ server = check_can_access_instance(config[:instance_id])
29
+ error_and_exit 'Unable to retrieve instance' unless server.data
30
+ vnics = compute_client.list_vnic_attachments(compartment_id, instance_id: config[:instance_id])
31
+ vnics.data && vnics.data.each do |vnic|
32
+ next unless vnic.lifecycle_state == 'ATTACHED'
33
+ begin
34
+ vnic_info = network_client.get_vnic(vnic.vnic_id, {})
35
+ rescue OracleBMC::Errors::ServiceError => service_error
36
+ raise unless service_error.serviceCode == 'NotAuthorizedOrNotFound'
37
+ else
38
+ # for now, only display information for primary vnic
39
+ if vnic_info.data.is_primary == true
40
+ vnic_array.push(vnic_info.data)
41
+ break
42
+ end
43
+ end
44
+ end
45
+
46
+ display_server_info(config, server.data, vnic_array)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'chef/knife/bmcs_common_options'
5
+ require 'chef/knife/bmcs_helper'
6
+
7
+ class Chef
8
+ class Knife
9
+ # List BMCS subnets in a VCN.
10
+ class BmcsSubnetList < Knife
11
+ banner 'knife bmcs subnet list (options)'
12
+
13
+ include BmcsHelper
14
+ include BmcsCommonOptions
15
+
16
+ deps do
17
+ require 'oraclebmc'
18
+ end
19
+
20
+ option :limit,
21
+ long: '--limit LIMIT',
22
+ description: 'The maximum number of items to return.'
23
+
24
+ option :vcn_id,
25
+ long: '--vcn-id VCN',
26
+ description: 'The VCN ID to list subnets for. (required)'
27
+
28
+ def run
29
+ validate_required_params(%i[vcn_id], config)
30
+ options = {}
31
+ options[:limit] = config[:limit] if config[:limit]
32
+
33
+ response = network_client.list_subnets(compartment_id, config[:vcn_id], options)
34
+
35
+ display_list(response, ['Display Name', 'ID', 'CIDR Block', 'Availability Domain', 'State']) do |item|
36
+ [item.display_name, item.id, item.cidr_block, item.availability_domain, item.lifecycle_state]
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'chef/knife/bmcs_common_options'
5
+ require 'chef/knife/bmcs_helper'
6
+
7
+ class Chef
8
+ class Knife
9
+ # List BMCS VCNs. Note that this lists all VCNs in a compartment, not just those that are set up as Chef nodes.
10
+ class BmcsVcnList < Knife
11
+ banner 'knife bmcs vcn list (options)'
12
+
13
+ include BmcsHelper
14
+ include BmcsCommonOptions
15
+
16
+ deps do
17
+ require 'oraclebmc'
18
+ end
19
+
20
+ option :limit,
21
+ long: '--limit LIMIT',
22
+ description: 'The maximum number of items to return.'
23
+
24
+ def run
25
+ options = {}
26
+ options[:limit] = config[:limit] if config[:limit]
27
+
28
+ response = network_client.list_vcns(compartment_id, options)
29
+
30
+ display_list(response, ['Display Name', 'ID', 'CIDR Block', 'State']) do |item|
31
+ [item.display_name, item.id, item.cidr_block, item.lifecycle_state]
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Knife
4
4
  module BMCS
5
- VERSION = '1.0.0'.freeze
5
+ VERSION = '1.1.0'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-bmcs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oracle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-08 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oraclebmc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
- - - '>='
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.2.1
22
+ version: 1.2.4
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ~>
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '1.0'
30
- - - '>='
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.2.1
32
+ version: 1.2.4
33
33
  description: ''
34
34
  email:
35
35
  - brian.gustafson@oracle.com
@@ -38,14 +38,19 @@ executables: []
38
38
  extensions: []
39
39
  extra_rdoc_files: []
40
40
  files:
41
- - ./lib/chef/knife/bmcs_ad_list.rb
42
- - ./lib/chef/knife/bmcs_common_options.rb
43
- - ./lib/chef/knife/bmcs_helper.rb
44
- - ./lib/chef/knife/bmcs_image_list.rb
45
- - ./lib/chef/knife/bmcs_server_create.rb
46
- - ./lib/chef/knife/bmcs_server_list.rb
47
- - ./lib/chef/knife/bmcs_shape_list.rb
48
- - ./lib/knife-bmcs/version.rb
41
+ - "./lib/chef/knife/bmcs_ad_list.rb"
42
+ - "./lib/chef/knife/bmcs_common_options.rb"
43
+ - "./lib/chef/knife/bmcs_compartment_list.rb"
44
+ - "./lib/chef/knife/bmcs_helper.rb"
45
+ - "./lib/chef/knife/bmcs_image_list.rb"
46
+ - "./lib/chef/knife/bmcs_server_create.rb"
47
+ - "./lib/chef/knife/bmcs_server_delete.rb"
48
+ - "./lib/chef/knife/bmcs_server_list.rb"
49
+ - "./lib/chef/knife/bmcs_server_show.rb"
50
+ - "./lib/chef/knife/bmcs_shape_list.rb"
51
+ - "./lib/chef/knife/bmcs_subnet_list.rb"
52
+ - "./lib/chef/knife/bmcs_vcn_list.rb"
53
+ - "./lib/knife-bmcs/version.rb"
49
54
  - LICENSE.txt
50
55
  homepage: https://github.com/oracle/knife-bmcs
51
56
  licenses:
@@ -58,17 +63,17 @@ require_paths:
58
63
  - lib
59
64
  required_ruby_version: !ruby/object:Gem::Requirement
60
65
  requirements:
61
- - - '>='
66
+ - - ">="
62
67
  - !ruby/object:Gem::Version
63
68
  version: 2.2.0
64
69
  required_rubygems_version: !ruby/object:Gem::Requirement
65
70
  requirements:
66
- - - '>='
71
+ - - ">="
67
72
  - !ruby/object:Gem::Version
68
73
  version: '0'
69
74
  requirements: []
70
75
  rubyforge_project:
71
- rubygems_version: 2.0.14
76
+ rubygems_version: 2.6.8
72
77
  signing_key:
73
78
  specification_version: 4
74
79
  summary: Chef Knife Plugin for Oracle Bare Metal Cloud Services