diff --git a/.changelogs/1.0.4/89_add_version_output.yml b/.changelogs/1.0.4/89_add_version_output.yml new file mode 100644 index 0000000..9df848d --- /dev/null +++ b/.changelogs/1.0.4/89_add_version_output.yml @@ -0,0 +1,2 @@ +added: + - Add version output cli arg. [#89] diff --git a/README.md b/README.md index 2ff95e8..5f775c2 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ The following options and parameters are currently supported: | -j | --json | Returns a JSON of the VM movement. | Unset | | -b | --best-node | Returns the best next node for a VM/CT placement (useful for further usage with Terraform/Ansible). | Unset | | -m | --maintenance | Sets node(s) to maintenance mode & moves workloads away. | Unset | +| -v | --version | Returns the ProxLB version on stdout. | Unset | ### Balancing #### General diff --git a/proxlb b/proxlb index c2a5f09..3dcc878 100755 --- a/proxlb +++ b/proxlb @@ -209,9 +209,17 @@ def initialize_args(): argparser.add_argument('-j', '--json', help='Return a JSON of the VM movement.', action='store_true', required=False) argparser.add_argument('-b', '--best-node', help='Returns the best next node.', action='store_true', required=False) argparser.add_argument('-m', '--maintenance', help='Sets node to maintenance mode & moves workloads away.', type=str, required=False) + argparser.add_argument('-v', '--version', help='Returns the current ProxLB version.', action='store_true', required=False) return argparser.parse_args() +def proxlb_output_version(): + """ Print ProxLB version information on CLI. """ + print(f'{__appname__} version {__version__}\nRequired config version: >= {__config_version__}') + print('ProxLB support: https://github.com/gyptazy/ProxLB\nDeveloper: gyptazy.com') + sys.exit(0) + + def initialize_config_path(app_args): """ Initialize path to ProxLB config file. """ info_prefix = 'Info: [config]:' @@ -1495,6 +1503,8 @@ def main(): # Initialize PAS. initialize_logger('CRITICAL') app_args = initialize_args() + if app_args.version: + proxlb_output_version() config_path = initialize_config_path(app_args) pre_validations(config_path)