diff --git a/lib/oci_utils/impl/oci_network_config_main.py b/lib/oci_utils/impl/oci_network_config_main.py index 8a47db3..314d433 100644 --- a/lib/oci_utils/impl/oci_network_config_main.py +++ b/lib/oci_utils/impl/oci_network_config_main.py @@ -23,6 +23,7 @@ from oci_utils.impl.oci_resources import OCIVNIC from oci_utils.impl.row_printer import TablePrinter from oci_utils.impl.row_printer import TextPrinter +from oci_utils.impl.row_printer import get_row_printer_impl from oci_utils.impl.row_printer_helpers import IndentPrinter from oci_utils.impl.row_printer_helpers import get_value_data from oci_utils.impl.row_printer_helpers import initialise_column_lengths @@ -123,6 +124,28 @@ def def_show_parser(s_parser): return show_parser +def def_show_os_parser(s_parser): + """ + Define the show_os subparser. + + Parameters + ---------- + s_parser: subparsers. + + Returns + ------- + ArgumentParser: the show subcommand parser. + """ + show_os_parser = s_parser.add_parser('show-os', + description='Display the current network interface configuration as well as the VNIC configuration from OCI.', + help='Display the current network interface configuration as well as the VNIC configuration from OCI.') + show_os_parser.add_argument('--output-mode', + choices=('parsable', 'table', 'json', 'text'), + help='Set output mode.', + default='table') + return show_os_parser + + def def_show_vnics_parser(s_parser): """ Define the show_vnics subparser @@ -532,6 +555,9 @@ def get_arg_parser(): # show _ = def_show_parser(subparser) # + # show-os + _ = def_show_os_parser(subparser) + # # show-vnics _ = def_show_vnics_parser(subparser) # @@ -1001,7 +1027,26 @@ def _display_subnet(interface): return nw_conf -def show_os_network_config(vnic_utils): +def do_show_os_network_config(show_args): + """ + Display the current network interface configuration as well as the VNIC configuration from OCI. + + Parameters + ---------- + show_args: namespace + The command line arguments. + + Returns + ------- + int: 0 on success, 1 otherwise. + """ + _logger.debug('%s', where_am_i()) + vnic_utils = get_vnic_utils(show_args) + show_os_network_config(vnic_utils, show_args.output_mode) + return 0 + + +def show_os_network_config(vnic_utils, mode): """ Display the current network interface configuration as well as the VNIC configuration from OCI. @@ -1010,6 +1055,9 @@ def show_os_network_config(vnic_utils): vnic_utils : The VNIC configuration instance. + mode : str + The output mode + Returns ------- No return value. @@ -1034,8 +1082,8 @@ def _get_subnet(_, interface): ['STATE', 6, 'STATE'], ['MAC', 18, 'MAC'], ['VNIC ID', 95, 'VNIC']) - printer = TablePrinter(title=_title, columns=_columns, column_separator=' ', text_truncate=False) - + printerKlass = get_row_printer_impl(mode) + printer = printerKlass(title=_title, columns=_columns, text_truncate=False) printer.printHeader() for item in ret: printer.printRow(item) @@ -1062,8 +1110,7 @@ def show_network(show_args): network_config = vnic_utils.get_network_config() network_config = update_network_config(network_config) # - # for compatibility mode, oci-network-config show should provide the same output as oci-network-config --show; - # if output-mode is specified, compatiblity requirement is dropped. + # for compatibility mode (when compat-ouptut is set), oci-network-config show should provide the same output as oci-network-config --show; showerror = False if show_args.compat_output: compat_show_vnics_information() @@ -1074,8 +1121,8 @@ def show_network(show_args): _logger.debug('Cannot show information', exc_info=True) _logger.error('Cannot show information: %s', str(e)) showerror = True - if show_args.output_mode == 'table': - show_os_network_config(vnic_utils) + if not show_args.compat_output: + show_os_network_config(vnic_utils, show_args.output_mode) return False if showerror else True @@ -2038,6 +2085,7 @@ def main(): """ sub_commands = {'usage': show_usage, 'show': show_network, + 'show-os': do_show_os_network_config, 'show-vnics': show_vnics, 'show-vnics-all': show_vnics_all, 'show-vcns': show_vcns, diff --git a/man/man1/oci-network-config.1 b/man/man1/oci-network-config.1 index 0264647..2be0d3e 100644 --- a/man/man1/oci-network-config.1 +++ b/man/man1/oci-network-config.1 @@ -16,6 +16,9 @@ usage .B oci-network-config show [-h|--help] [-I ITEM|--include ITEM] [-X ITEM|--exclude ITEM] [--output-mode MODE] [--details] +.B oci-network-config +show-os [-h|--help] [--output-mode MODE] + .B oci-network-config show-vcns [-h|--help] [--output-mode MODE] [--details] [--ocid VCN_OCID] [--name VCN_NAME] [--no-truncate]