knife-oci 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59081952975a5ed82060447d1f172d47aa62095a
4
+ data.tar.gz: 62d68779e1ff5d745c428d941e60c7ff3455b9d4
5
+ SHA512:
6
+ metadata.gz: 2fb72b40c8c75d8f842eadf9f065a5251655eb3a88e91836cc8410e7280c611ed3e3ed31796556b8aabb16efbe187b2bcf063c2fad2ef235b7af21a8f223e4c2
7
+ data.tar.gz: 83a4e16965ddf3436f239a5218f57926d3e400a4b96d0449ffb504f7fb6e7b47789d73f4dc851dd6169c5aa4b5a6d2c42fa0a4535e1db2e5a835a37c5aebe543
data/LICENSE.txt ADDED
@@ -0,0 +1,82 @@
1
+ Copyright (c) 2017, Oracle and/or its affiliates.  All rights reserved.
2
+
3
+ This software is dual-licensed to you under the Universal Permissive License (UPL) and Apache License 2.0.  See below for license terms.  You may choose either license, or both.
4
+  ____________________________
5
+ The Universal Permissive License (UPL), Version 1.0
6
+ Copyright (c) 2017, Oracle and/or its affiliates.  All rights reserved.
7
+
8
+ Subject to the condition set forth below, permission is hereby granted to any person obtaining a copy of this software, associated documentation and/or data (collectively the "Software"), free of charge and under any and all copyright rights in the Software, and any and all patent rights owned or freely licensable by each licensor hereunder covering either (i) the unmodified Software as contributed to or provided by such licensor, or (ii) the Larger Works (as defined below), to deal in both
9
+
10
+ (a) the Software, and
11
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if one is included with the Software (each a "Larger Work" to which the Software is contributed by such licensors),
12
+
13
+ without restriction, including without limitation the rights to copy, create derivative works of, display, perform, and distribute the Software and make, use, sell, offer for sale, import, export, have made, and have sold the Software and the Larger Work(s), and to sublicense the foregoing rights on either these or other terms.
14
+
15
+ This license is subject to the following condition:
16
+
17
+ The above copyright notice and either this complete permission notice or at a minimum a reference to the UPL must be included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+ The Apache Software License, Version 2.0
22
+ Copyright (c) 2017, Oracle and/or its affiliates.  All rights reserved.
23
+
24
+ Licensed under the Apache License, Version 2.0 (the "License"); You may not use this product except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. A copy of the license is also reproduced below. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
25
+
26
+ Apache License
27
+
28
+ Version 2.0, January 2004
29
+
30
+ http://www.apache.org/licenses/
31
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
32
+ 1. Definitions.
33
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
34
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
35
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
36
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
37
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
38
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
39
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
40
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
41
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
42
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
43
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
44
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
45
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
46
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
47
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
48
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
49
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
50
+
51
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
52
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
53
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
54
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
55
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
56
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
57
+ END OF TERMS AND CONDITIONS
58
+
59
+ APPENDIX: How to apply the Apache License to your work.
60
+
61
+ To apply the Apache License to your work, attach the following
62
+ boilerplate notice, with the fields enclosed by brackets "[]"
63
+ replaced with your own identifying information. (Don't include
64
+ the brackets!) The text should be enclosed in the appropriate
65
+ comment syntax for the file format. We also recommend that a
66
+ file or class name and description of purpose be included on the
67
+ same "printed page" as the copyright notice for easier
68
+ identification within third-party archives.
69
+
70
+ Copyright [yyyy] [name of copyright owner]
71
+
72
+ Licensed under the Apache License, Version 2.0 (the "License");
73
+ you may not use this file except in compliance with the License.
74
+ You may obtain a copy of the License at
75
+
76
+ http://www.apache.org/licenses/LICENSE-2.0
77
+
78
+ Unless required by applicable law or agreed to in writing, software
79
+ distributed under the License is distributed on an "AS IS" BASIS,
80
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
81
+ See the License for the specific language governing permissions and
82
+ limitations under the License.
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'chef/knife/oci_common_options'
5
+ require 'chef/knife/oci_helper'
6
+
7
+ class Chef
8
+ class Knife
9
+ # List availability domains
10
+ class OciAdList < Knife
11
+ banner 'knife oci ad list (options)'
12
+
13
+ include OciHelper
14
+ include OciCommonOptions
15
+
16
+ deps do
17
+ require 'oci'
18
+ end
19
+
20
+ def run
21
+ options = {}
22
+ columns = []
23
+
24
+ list_for_display, last_response = get_display_results(options) do |client_options|
25
+ response = identity_client.list_availability_domains(compartment_id, client_options)
26
+
27
+ items = response_to_list(response) do |item|
28
+ [item.name]
29
+ end
30
+ [response, items]
31
+ end
32
+
33
+ display_list_from_array(list_for_display, columns.length)
34
+ warn_if_page_is_truncated(last_response)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'knife-oci/version'
5
+
6
+ class Chef
7
+ class Knife
8
+ # Options that should be included in all OCI commands
9
+ module OciCommonOptions
10
+ def self.included(includer)
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
+
16
+ option :oci_config_file,
17
+ long: '--oci-config-file FILE',
18
+ description: 'The path to the OCI config file. Default: ~/.oci/config'
19
+
20
+ option :oci_profile,
21
+ long: '--oci-profile PROFILE',
22
+ description: 'The profile to load from the OCI config file. Default: DEFAULT'
23
+ end
24
+ # all commands except compartment list get a compartment-id option
25
+ return if includer.to_s == 'Chef::Knife::OciCompartmentList'
26
+ includer.class_eval do
27
+ option :compartment_id,
28
+ long: '--compartment-id COMPARTMENT',
29
+ description: 'The OCID of the compartment.'
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'chef/knife/oci_common_options'
5
+ require 'chef/knife/oci_helper'
6
+
7
+ class Chef
8
+ class Knife
9
+ # List OCI compartments
10
+ class OciCompartmentList < Knife
11
+ banner 'knife oci compartment list (options)'
12
+
13
+ include OciHelper
14
+ include OciCommonOptions
15
+
16
+ deps do
17
+ require 'oci'
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
+ columns = ['Display Name', 'ID']
29
+
30
+ list_for_display = config[:format] == 'summary' ? bold(columns) : []
31
+ list_data, last_response = get_display_results(options) do |client_options|
32
+ response = identity_client.list_compartments(oci_config.tenancy, client_options)
33
+
34
+ items = response_to_list(response) do |item|
35
+ [item.name, item.id]
36
+ end
37
+ [response, items]
38
+ end
39
+ list_for_display += list_data
40
+
41
+ display_list_from_array(list_for_display, columns.length)
42
+ warn_if_page_is_truncated(last_response)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,208 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'knife-oci/version'
5
+
6
+ # rubocop:disable Metrics/ModuleLength
7
+ class Chef
8
+ class Knife
9
+ # OCI helper module
10
+ module OciHelper
11
+ def oci_config
12
+ unless @oci_config
13
+ @oci_config = OCI::ConfigFileLoader.load_config(config_file_location: config_file_location, profile_name: config_file_profile)
14
+ @oci_config.region = config[:region] if config[:region]
15
+
16
+ @oci_config.additional_user_agent = "Oracle-ChefKnifeOCI/#{::Knife::OCI::VERSION}"
17
+ end
18
+
19
+ @oci_config
20
+ end
21
+
22
+ def config_file_location
23
+ # Load first from command line args if available, then from knife.rb, then use the default.
24
+ # For backwards compatibility with knife-bmcs, if oci version is not found in knife.rb, then check for bmcs version.
25
+ config[:oci_config_file] || Chef::Config[:knife][:oci_config_file] || Chef::Config[:knife][:bmcs_config_file] || OCI::ConfigFileLoader::DEFAULT_CONFIG_FILE
26
+ end
27
+
28
+ def config_file_profile
29
+ # Load first from command line args if available, then from knife.rb, then use the default.
30
+ # For backwards compatibility with knife-bmcs, if oci version is not found in knife.rb, then check for bmcs version.
31
+ config[:oci_profile] || Chef::Config[:knife][:oci_profile] || Chef::Config[:knife][:bmcs_profile] || OCI::ConfigFileLoader::DEFAULT_PROFILE
32
+ end
33
+
34
+ def compute_client
35
+ @compute_client ||= OCI::Core::ComputeClient.new(config: oci_config)
36
+ end
37
+
38
+ def network_client
39
+ @network_client ||= OCI::Core::VirtualNetworkClient.new(config: oci_config)
40
+ end
41
+
42
+ def identity_client
43
+ @identity_client ||= OCI::Identity::IdentityClient.new(config: oci_config)
44
+ end
45
+
46
+ # Get the compartment ID first from the command line args if available, then from the knife.rb
47
+ # file, and if neither of those is specified then use the tenancy.
48
+ def compartment_id
49
+ @compartment_id ||= config[:compartment_id] || Chef::Config[:knife][:compartment_id] || oci_config.tenancy
50
+ end
51
+
52
+ def error_and_exit(message)
53
+ ui.error message
54
+ exit(1)
55
+ end
56
+
57
+ def validate_required_params(required_params, params)
58
+ missing_params = required_params.select do |param|
59
+ params[param].nil?
60
+ end
61
+
62
+ error_and_exit("Missing the following required parameters: #{missing_params.join(', ').tr('_', '-')}") unless missing_params.empty?
63
+ end
64
+
65
+ def warn_if_page_is_truncated(response)
66
+ ui.warn('This list has been truncated. To view more items, increase the limit.') if response.headers.include? 'opc-next-page'
67
+ end
68
+
69
+ def next_page_token(response)
70
+ return response.headers['opc-next-page'] if response.headers.include? 'opc-next-page'
71
+ nil
72
+ end
73
+
74
+ def get_display_results(options)
75
+ max_results = config[:limit] ? Integer(config[:limit]) : nil
76
+
77
+ num_fetched_results = 0
78
+ list_for_display = []
79
+ response = nil
80
+ loop do
81
+ response, new_items = yield(options)
82
+
83
+ list_for_display += new_items
84
+ num_fetched_results += response.data.length if response.data
85
+ break if next_page_token(response).nil?
86
+ break if max_results && num_fetched_results >= max_results
87
+ options[:page] = next_page_token(response)
88
+ options[:limit] = (max_results - num_fetched_results).to_s if max_results
89
+ end
90
+ [list_for_display, response]
91
+ end
92
+
93
+ def bold(list)
94
+ bolded_list = []
95
+ list.each do |column|
96
+ bolded_list += [ui.color(column, :bold)]
97
+ end
98
+ bolded_list.flatten.compact
99
+ end
100
+
101
+ # Return data in summary mode format
102
+ def _summary_list(list)
103
+ list_for_display = []
104
+
105
+ if list
106
+ list.each do |item|
107
+ display_item = yield(item, list_for_display)
108
+ list_for_display += display_item if display_item
109
+ end
110
+ end
111
+
112
+ list_for_display
113
+ end
114
+
115
+ # Return data in non-summary mode format.
116
+ def _non_summary_list(list)
117
+ list_for_display = []
118
+ list.each do |item|
119
+ list_for_display += [item.to_hash]
120
+ end
121
+
122
+ list_for_display
123
+ end
124
+
125
+ # Return a one dimensional array of data based on API response.
126
+ # Result is compatible with display_list_from_array.
127
+ def response_to_list(response, &block)
128
+ list = if response.data.nil?
129
+ []
130
+ else
131
+ response.data.is_a?(Array) ? response.data : [response.data]
132
+ end
133
+
134
+ return _summary_list(list, &block) if config[:format] == 'summary'
135
+ _non_summary_list(list)
136
+ end
137
+
138
+ # Display a list using a one dimensional array as input
139
+ #
140
+ # Example output in summary mode:
141
+ # display_list_from_array(['a','b', 'c', 'd'], 2)
142
+ # a b
143
+ # c d
144
+ def display_list_from_array(list_for_display, num_columns)
145
+ if config[:format] == 'summary'
146
+ num_columns = 1 if num_columns < 1
147
+ puts ui.list(list_for_display, :uneven_columns_across, num_columns)
148
+ else
149
+ ui.output(list_for_display)
150
+ end
151
+ end
152
+
153
+ # Return a true or false with the confirmation result.
154
+ # Note: user prompt is bypassed with --yes to confirm automatically.
155
+ def confirm(prompt)
156
+ return true if config[:yes]
157
+ valid_responses = %w[yes no y n]
158
+ response = nil
159
+ 3.times do
160
+ response = ui.ask(prompt).downcase
161
+ break if valid_responses.include? response
162
+ ui.warn "Valid responses are #{valid_responses}"
163
+ end
164
+ response.match(/^y/)
165
+ end
166
+
167
+ def check_can_access_instance(instance_id)
168
+ response = compute_client.get_instance(instance_id)
169
+ error_and_exit 'Instance is already in terminated state' if response && response.data && response.data.lifecycle_state == OCI::Core::Models::Instance::LIFECYCLE_STATE_TERMINATED
170
+ rescue OCI::Errors::ServiceError => service_error
171
+ raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
172
+ error_and_exit 'Instance not authorized or not found'
173
+ else
174
+ return response
175
+ end
176
+
177
+ def show_value(key, value, color = :cyan)
178
+ ui.msg "#{ui.color(key, color)}: #{value}" if value && !value.to_s.empty?
179
+ end
180
+
181
+ # rubocop:disable Metrics/CyclomaticComplexity
182
+ def display_server_info(config, instance, vnics)
183
+ show_value('Display Name', instance.display_name)
184
+ show_value('Instance ID', instance.id)
185
+ show_value('Lifecycle State', instance.lifecycle_state)
186
+ show_value('Availability Domain', instance.availability_domain)
187
+ show_value('Compartment Name', instance.compartment_name) if instance.respond_to? :compartment_name
188
+ show_value('Compartment ID', instance.compartment_id)
189
+ show_value('Region', instance.region)
190
+ show_value('Image Name', instance.image_name) if instance.respond_to? :image_name
191
+ show_value('Image ID', instance.image_id)
192
+ show_value('Shape', instance.shape)
193
+ show_value('VCN Name', instance.vcn_name) if instance.respond_to? :vcn_name
194
+ show_value('VCN ID', instance.vcn_id) if instance.respond_to? :vcn_id
195
+ show_value('Launched', instance.launchtime) if instance.respond_to? :launchtime
196
+ vnics.each_index do |index|
197
+ prefix = vnics[index].is_primary ? 'Primary' : 'Secondary'
198
+ show_value("#{prefix} Public IP Address", vnics[index].public_ip)
199
+ show_value("#{prefix} Private IP Address", vnics[index].private_ip)
200
+ show_value("#{prefix} Hostname", vnics[index].hostname_label)
201
+ show_value("#{prefix} FQDN", vnics[index].fqdn) if vnics[index].respond_to? :fqdn
202
+ show_value("#{prefix} Subnet Name", vnics[index].subnet_name) if vnics[index].respond_to? :subnet_name
203
+ end
204
+ show_value('Node Name', config[:chef_node_name])
205
+ end
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'chef/knife/oci_common_options'
5
+ require 'chef/knife/oci_helper'
6
+
7
+ class Chef
8
+ class Knife
9
+ # List available images
10
+ class OciImageList < Knife
11
+ banner 'knife oci image list (options)'
12
+
13
+ include OciHelper
14
+ include OciCommonOptions
15
+
16
+ deps do
17
+ require 'oci'
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
+ columns = ['Display Name', 'ID', 'OS', 'OS Version']
29
+
30
+ list_for_display = config[:format] == 'summary' ? bold(columns) : []
31
+ list_data, last_response = get_display_results(options) do |client_options|
32
+ response = compute_client.list_images(compartment_id, client_options)
33
+
34
+ items = response_to_list(response) do |image|
35
+ [image.display_name, image.id, image.operating_system, image.operating_system_version]
36
+ end
37
+ [response, items]
38
+ end
39
+ list_for_display += list_data
40
+
41
+ display_list_from_array(list_for_display, columns.length)
42
+ warn_if_page_is_truncated(last_response)
43
+ end
44
+ end
45
+ end
46
+ end