diff --git a/virtualbox/pybox/Parser.py b/virtualbox/pybox/Parser.py index adefed7..ae4659d 100644 --- a/virtualbox/pybox/Parser.py +++ b/virtualbox/pybox/Parser.py @@ -1,5 +1,5 @@ # pylint: disable=invalid-name -#!/usr/bin/python3 +# !/usr/bin/python3 # # SPDX-License-Identifier: Apache-2.0 # @@ -7,10 +7,56 @@ """ Parser to handle command line arguments """ + import argparse import re from argparse import ArgumentParser, RawTextHelpFormatter import getpass +from enum import Enum + + +class StringEnum(Enum): + """This class aims to serve as a parent class for a parser + type checker""" + + @classmethod + def get_members_values(cls): + """Static method that returns a list of enum members values""" + return [v.value for v in cls.__members__.values()] + + +class SetupType(StringEnum): + """Class aimed to help parser choose between installation + predefined types""" + + AIO_SX = 'AIO-SX' + AIO_DX = 'AIO-DX' + STANDARD = 'STANDARD' + STORAGE = 'STORAGE' + + +class VboxNetworkType(StringEnum): + """Class aimed to help parser choose between virtual box + network types""" + + HOST_ONLY = 'hostonly' + NAT = 'nat' + + +class SecurityProfile(StringEnum): + """Class aimed to help parser choose between + security profile types""" + + STANDARD = 'standard' + EXTENDED = 'extended' + + +class LabInstallationType(StringEnum): + """Class aimed to help parser choose between + lab installation types""" + + GRAPHICAL = 'graphical' + SERIAL = 'serial' def validate_password(pwd: str): @@ -55,16 +101,9 @@ def parse_setup_config(parser: ArgumentParser): """ Mutate parser with CLI arguments related to the setup type """ - parser.add_argument("--setup-type", help= - """ - Type of setup: - AIO-SX - AIO-DX - STANDARD - STORAGE - """, - choices=['AIO-SX', 'AIO-DX', 'STANDARD', 'STORAGE'], - type=str, + parser.add_argument("--setup-type", + help=f"Expected value is one of {SetupType.get_members_values()}", + type=SetupType, required=True) parser.add_argument("--controllers", help= """ @@ -174,7 +213,8 @@ def parse_config_location(parser: ArgumentParser): parser.add_argument("--ansible-controller-config", help= """ Path to a local YAML file to be copied as localhost.yml - to the home directory of the controller-0. NOTE: System password value is updated dynamically with user defined --password. + to the home directory of the controller-0. + NOTE: System password value is updated dynamically with user defined --password. """, type=str) parser.add_argument("--vbox-home-dir", help= @@ -244,7 +284,7 @@ def parse_networking(parser: ArgumentParser): parser.add_argument("--vboxnet-name", help= """ - Which host only network to use for setup. + Which network to use for setup. """, type=str) parser.add_argument("--vboxnet-ip", help= @@ -258,13 +298,10 @@ def parse_networking(parser: ArgumentParser): Add a new NAT interface to hosts. """, action='store_true') - parser.add_argument("--vboxnet-type", help= - """ - Type of vbox network, either hostonly on nat - """, - choices=['hostonly', 'nat'], - type=str, - default='hostonly') + parser.add_argument("--vboxnet-type", + help=f"Expected value is one of {VboxNetworkType.get_members_values()}", + type=VboxNetworkType, + default=VboxNetworkType.HOST_ONLY) parser.add_argument("--nat-controller-floating-local-ssh-port", help= """ When oam network is configured as 'nat' a port on