|
441 | 441 | ] |
442 | 442 |
|
443 | 443 | # azure container storage |
| 444 | +# azure container storage |
| 445 | +container_storage_versions = [ |
| 446 | + "1", |
| 447 | + "2" |
| 448 | +] |
| 449 | + |
444 | 450 | storage_pool_types = [ |
445 | 451 | CONST_STORAGE_POOL_TYPE_AZURE_DISK, |
446 | 452 | CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK, |
@@ -1028,8 +1034,14 @@ def load_arguments(self, _): |
1028 | 1034 | # azure container storage |
1029 | 1035 | c.argument( |
1030 | 1036 | "enable_azure_container_storage", |
1031 | | - arg_type=get_enum_type(storage_pool_types), |
1032 | | - help="enable azure container storage and define storage pool type", |
| 1037 | + arg_type=_get_enable_azure_container_storage_type(), |
| 1038 | + help="enable azure container storage. Can be used as a flag (defaults to True) or with a" |
| 1039 | + " storage pool type value: (azureDisk, ephemeralDisk, elasticSan)", |
| 1040 | + ) |
| 1041 | + c.argument( |
| 1042 | + "container_storage_version", |
| 1043 | + arg_type=get_enum_type(container_storage_versions), |
| 1044 | + help="set azure container storage version, the latest version will be installed by default", |
1033 | 1045 | ) |
1034 | 1046 | c.argument( |
1035 | 1047 | "storage_pool_name", |
@@ -1488,13 +1500,21 @@ def load_arguments(self, _): |
1488 | 1500 | # azure container storage |
1489 | 1501 | c.argument( |
1490 | 1502 | "enable_azure_container_storage", |
1491 | | - arg_type=get_enum_type(storage_pool_types), |
1492 | | - help="enable azure container storage and define storage pool type", |
| 1503 | + arg_type=_get_enable_azure_container_storage_type(), |
| 1504 | + help="enable azure container storage. Can be used as a flag (defaults to True) or with a" |
| 1505 | + " storage pool type value: (azureDisk, ephemeralDisk, elasticSan)", |
1493 | 1506 | ) |
1494 | 1507 | c.argument( |
1495 | 1508 | "disable_azure_container_storage", |
1496 | | - arg_type=get_enum_type(disable_storage_pool_types), |
1497 | | - help="disable azure container storage or any one of the storage pool types", |
| 1509 | + arg_type=_get_disable_azure_container_storage_type(), |
| 1510 | + help="disable azure container storage or any one of the storage pool types." |
| 1511 | + " Can be used as a flag (defaults to True) or with a storagepool type value:" |
| 1512 | + " azureDisk, ephemeralDisk, elasticSan, all (to disable all storage pools).", |
| 1513 | + ) |
| 1514 | + c.argument( |
| 1515 | + "container_storage_version", |
| 1516 | + arg_type=get_enum_type(container_storage_versions), |
| 1517 | + help="set azure container storage version, the latest version will be installed by default", |
1498 | 1518 | ) |
1499 | 1519 | c.argument( |
1500 | 1520 | "storage_pool_name", |
@@ -2922,3 +2942,65 @@ def _get_default_install_location(exe_name): |
2922 | 2942 | else: |
2923 | 2943 | install_location = None |
2924 | 2944 | return install_location |
| 2945 | + |
| 2946 | + |
| 2947 | +def _get_enable_azure_container_storage_type(): |
| 2948 | + """Custom argument type that accepts both None and enum values""" |
| 2949 | + import argparse |
| 2950 | + from azure.cli.core.azclierror import InvalidArgumentValueError |
| 2951 | + |
| 2952 | + class AzureContainerStorageAction(argparse.Action): |
| 2953 | + def __call__(self, parser, namespace, values, option_string=None): |
| 2954 | + if values is None: |
| 2955 | + # When used as a flag without value, set as True |
| 2956 | + setattr(namespace, self.dest, True) |
| 2957 | + return |
| 2958 | + |
| 2959 | + if isinstance(values, str): |
| 2960 | + # Handle enum values (case insensitive) |
| 2961 | + for storage_type in storage_pool_types: |
| 2962 | + if values.lower() == storage_type.lower(): |
| 2963 | + setattr(namespace, self.dest, storage_type) |
| 2964 | + return |
| 2965 | + |
| 2966 | + # Invalid value |
| 2967 | + valid_values = storage_pool_types |
| 2968 | + raise InvalidArgumentValueError( |
| 2969 | + f"Invalid value '{values}'. Valid values are: {', '.join(valid_values)}" |
| 2970 | + ) |
| 2971 | + |
| 2972 | + return CLIArgumentType( |
| 2973 | + nargs='?', # Optional argument |
| 2974 | + action=AzureContainerStorageAction, |
| 2975 | + ) |
| 2976 | + |
| 2977 | + |
| 2978 | +def _get_disable_azure_container_storage_type(): |
| 2979 | + """Custom argument type that accepts both None and enum values""" |
| 2980 | + import argparse |
| 2981 | + from azure.cli.core.azclierror import InvalidArgumentValueError |
| 2982 | + |
| 2983 | + class AzureContainerStorageAction(argparse.Action): |
| 2984 | + def __call__(self, parser, namespace, values, option_string=None): |
| 2985 | + if values is None: |
| 2986 | + # When used as a flag without value, set as True |
| 2987 | + setattr(namespace, self.dest, True) |
| 2988 | + return |
| 2989 | + |
| 2990 | + if isinstance(values, str): |
| 2991 | + # Handle enum values (case insensitive) |
| 2992 | + for storage_type in disable_storage_pool_types: |
| 2993 | + if values.lower() == storage_type.lower(): |
| 2994 | + setattr(namespace, self.dest, storage_type) |
| 2995 | + return |
| 2996 | + |
| 2997 | + # Invalid value |
| 2998 | + valid_values = disable_storage_pool_types |
| 2999 | + raise InvalidArgumentValueError( |
| 3000 | + f"Invalid value '{values}'. Valid values are: {', '.join(valid_values)}" |
| 3001 | + ) |
| 3002 | + |
| 3003 | + return CLIArgumentType( |
| 3004 | + nargs='?', # Optional argument |
| 3005 | + action=AzureContainerStorageAction, |
| 3006 | + ) |
0 commit comments