Class: Chef::Knife::BmcsCompartmentList

Inherits:
Chef::Knife show all
Includes:
BmcsCommonOptions, BmcsHelper
Defined in:
lib/chef/knife/bmcs_compartment_list.rb

Overview

List BMCS compartments

Instance Method Summary collapse

Methods included from BmcsCommonOptions

included

Methods included from BmcsHelper

#bmcs_config, #check_can_access_instance, #compartment_id, #compute_client, #confirm, #display_list, #display_server_info, #error_and_exit, #identity_client, #network_client, #show_value, #validate_required_params, #warn_if_page_is_truncated

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chef/knife/bmcs_compartment_list.rb', line 24

def run
  options = {}
  options[:limit] = config[:limit] if config[:limit]

  response = identity_client.list_compartments(bmcs_config.tenancy, options)
  # Check whether there is a next page to decide whether to show an 'output is truncated' warning.
  # TODO: expected to be addressed server-side in a future release at which point this special
  # handling can be removed.
  show_truncated_warning = false
  if response && response.headers.include?('opc-next-page')
    response_page2 = identity_client.list_compartments(bmcs_config.tenancy, options.merge(page: response.headers['opc-next-page']))
    show_truncated_warning = response_page2 && response_page2.data && !response_page2.data.empty?
  end

  display_list(response, ['Display Name', 'ID'], warn_on_truncated: show_truncated_warning) do |item|
    [item.name, item.id]
  end
end