aria.ops.definition.parameter
1# Copyright 2022 VMware, Inc. 2# SPDX-License-Identifier: Apache-2.0 3from __future__ import annotations 4 5from abc import ABC 6from typing import Optional 7from typing import Union 8 9from aria.ops.definition.assertions import validate_key 10from aria.ops.definition.exceptions import DuplicateKeyException 11 12 13class Parameter(ABC): 14 def __init__( 15 self, 16 key: str, 17 label: Optional[str] = None, 18 description: Optional[str] = None, 19 default: Optional[Union[str, int]] = None, 20 required: bool = True, 21 advanced: bool = False, 22 display_order: int = 0, 23 ) -> None: 24 """ 25 :param key: Used to identify the parameter. 26 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 27 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 28 :param default: The default value of the parameter. 29 :param required: True if user is required to provide this parameter. Defaults to True. 30 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 31 :param display_order: Determines the order parameters will be displayed in the UI. 32 """ 33 self.key = validate_key(key, "Parameter/Identifier") 34 self.label = label 35 if label is None: 36 self.label = key 37 self.description = description 38 self.default = default 39 self.required = required 40 self.advanced = advanced 41 self.display_order = display_order 42 43 def to_json(self) -> dict: 44 return { 45 "key": self.key, 46 "label": self.label, 47 "description": self.description, 48 "required": self.required, 49 "ident_type": 1 if not self.advanced else 2, 50 "enum": False, 51 "display_order": self.display_order, 52 } 53 54 55class IntParameter(Parameter): 56 def __init__( 57 self, 58 key: str, 59 label: Optional[str] = None, 60 description: Optional[str] = None, 61 default: Optional[int] = None, 62 required: bool = True, 63 advanced: bool = False, 64 display_order: int = 0, 65 ) -> None: 66 """ 67 :param key: Used to identify the parameter. 68 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 69 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 70 :param default: The default value of the parameter. 71 :param required: True if user is required to provide this parameter. Defaults to True. 72 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 73 :param display_order: Determines the order parameters will be displayed in the UI. 74 """ 75 super().__init__( 76 key, label, description, default, required, advanced, display_order 77 ) 78 79 def to_json(self) -> dict: 80 return super().to_json() | { 81 "type": "integer", 82 "default": str(self.default) if self.default is not None else None, 83 } 84 85 86class StringParameter(Parameter): 87 def __init__( 88 self, 89 key: str, 90 label: Optional[str] = None, 91 description: Optional[str] = None, 92 default: Optional[str] = None, 93 max_length: int = 512, 94 required: bool = True, 95 advanced: bool = False, 96 display_order: int = 0, 97 ) -> None: 98 """ 99 :param key: Used to identify the parameter. 100 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 101 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 102 :param default: The default value of the parameter. 103 :param max_length: The max length of the parameter value. Defaults to 512. 104 :param required: True if user is required to provide this parameter. Defaults to True. 105 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 106 :param display_order: Determines the order parameters will be displayed in the UI. 107 """ 108 super().__init__( 109 key, label, description, default, required, advanced, display_order 110 ) 111 self.max_length = max_length 112 113 def to_json(self) -> dict: 114 return super().to_json() | { 115 "type": "string", 116 "length": int(self.max_length), 117 "default": self.default, 118 } 119 120 121class EnumParameter(Parameter): 122 def __init__( 123 self, 124 key: str, 125 values: list[Union[str, tuple[str, str]]], 126 label: Optional[str] = None, 127 description: Optional[str] = None, 128 default: Optional[str] = None, 129 required: bool = True, 130 advanced: bool = False, 131 display_order: int = 0, 132 ) -> None: 133 """ 134 :param key: Used to identify the parameter. 135 :param values: An array containing all enum values. If 'default' is specified and not part of this array, it 136 will be added as an additional enum value. Enum values are not localizable. 137 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 138 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 139 :param default: The default value of the parameter. 140 :param required: True if user is required to provide this parameter. Defaults to True. 141 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 142 :param display_order: Determines the order parameters will be displayed in the UI. 143 """ 144 super().__init__( 145 key, label, description, default, required, advanced, display_order 146 ) 147 if len(values) > len(set(values)): 148 raise DuplicateKeyException( 149 f"Duplicate enum value in parameter {key}: {values}." 150 ) 151 152 self.values = values 153 self.default = default 154 155 if ( 156 default not in [v[0] if isinstance(v, tuple) else v for v in self.values] 157 and default is not None 158 ): 159 self.values.append((default, default)) 160 161 def to_json(self) -> dict: 162 return super().to_json() | { 163 "type": "string", 164 "enum": True, 165 "enum_values": [ 166 { 167 "key": str(value[0]) if isinstance(value, tuple) else value, 168 "label": str(value[1]) if isinstance(value, tuple) else value, 169 "display_order": display_order, 170 } 171 for display_order, value in enumerate(self.values) 172 ], 173 "default": self.default, 174 }
class
Parameter(abc.ABC):
14class Parameter(ABC): 15 def __init__( 16 self, 17 key: str, 18 label: Optional[str] = None, 19 description: Optional[str] = None, 20 default: Optional[Union[str, int]] = None, 21 required: bool = True, 22 advanced: bool = False, 23 display_order: int = 0, 24 ) -> None: 25 """ 26 :param key: Used to identify the parameter. 27 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 28 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 29 :param default: The default value of the parameter. 30 :param required: True if user is required to provide this parameter. Defaults to True. 31 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 32 :param display_order: Determines the order parameters will be displayed in the UI. 33 """ 34 self.key = validate_key(key, "Parameter/Identifier") 35 self.label = label 36 if label is None: 37 self.label = key 38 self.description = description 39 self.default = default 40 self.required = required 41 self.advanced = advanced 42 self.display_order = display_order 43 44 def to_json(self) -> dict: 45 return { 46 "key": self.key, 47 "label": self.label, 48 "description": self.description, 49 "required": self.required, 50 "ident_type": 1 if not self.advanced else 2, 51 "enum": False, 52 "display_order": self.display_order, 53 }
Helper class that provides a standard way to create an ABC using inheritance.
Parameter( key: str, label: Optional[str] = None, description: Optional[str] = None, default: Union[str, int, NoneType] = None, required: bool = True, advanced: bool = False, display_order: int = 0)
15 def __init__( 16 self, 17 key: str, 18 label: Optional[str] = None, 19 description: Optional[str] = None, 20 default: Optional[Union[str, int]] = None, 21 required: bool = True, 22 advanced: bool = False, 23 display_order: int = 0, 24 ) -> None: 25 """ 26 :param key: Used to identify the parameter. 27 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 28 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 29 :param default: The default value of the parameter. 30 :param required: True if user is required to provide this parameter. Defaults to True. 31 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 32 :param display_order: Determines the order parameters will be displayed in the UI. 33 """ 34 self.key = validate_key(key, "Parameter/Identifier") 35 self.label = label 36 if label is None: 37 self.label = key 38 self.description = description 39 self.default = default 40 self.required = required 41 self.advanced = advanced 42 self.display_order = display_order
Parameters
- key: Used to identify the parameter.
- label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
- description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI.
- default: The default value of the parameter.
- required: True if user is required to provide this parameter. Defaults to True.
- advanced: True if the parameter should be collapsed by default. Defaults to False.
- display_order: Determines the order parameters will be displayed in the UI.
56class IntParameter(Parameter): 57 def __init__( 58 self, 59 key: str, 60 label: Optional[str] = None, 61 description: Optional[str] = None, 62 default: Optional[int] = None, 63 required: bool = True, 64 advanced: bool = False, 65 display_order: int = 0, 66 ) -> None: 67 """ 68 :param key: Used to identify the parameter. 69 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 70 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 71 :param default: The default value of the parameter. 72 :param required: True if user is required to provide this parameter. Defaults to True. 73 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 74 :param display_order: Determines the order parameters will be displayed in the UI. 75 """ 76 super().__init__( 77 key, label, description, default, required, advanced, display_order 78 ) 79 80 def to_json(self) -> dict: 81 return super().to_json() | { 82 "type": "integer", 83 "default": str(self.default) if self.default is not None else None, 84 }
Helper class that provides a standard way to create an ABC using inheritance.
IntParameter( key: str, label: Optional[str] = None, description: Optional[str] = None, default: Optional[int] = None, required: bool = True, advanced: bool = False, display_order: int = 0)
57 def __init__( 58 self, 59 key: str, 60 label: Optional[str] = None, 61 description: Optional[str] = None, 62 default: Optional[int] = None, 63 required: bool = True, 64 advanced: bool = False, 65 display_order: int = 0, 66 ) -> None: 67 """ 68 :param key: Used to identify the parameter. 69 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 70 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 71 :param default: The default value of the parameter. 72 :param required: True if user is required to provide this parameter. Defaults to True. 73 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 74 :param display_order: Determines the order parameters will be displayed in the UI. 75 """ 76 super().__init__( 77 key, label, description, default, required, advanced, display_order 78 )
Parameters
- key: Used to identify the parameter.
- label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
- description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI.
- default: The default value of the parameter.
- required: True if user is required to provide this parameter. Defaults to True.
- advanced: True if the parameter should be collapsed by default. Defaults to False.
- display_order: Determines the order parameters will be displayed in the UI.
87class StringParameter(Parameter): 88 def __init__( 89 self, 90 key: str, 91 label: Optional[str] = None, 92 description: Optional[str] = None, 93 default: Optional[str] = None, 94 max_length: int = 512, 95 required: bool = True, 96 advanced: bool = False, 97 display_order: int = 0, 98 ) -> None: 99 """ 100 :param key: Used to identify the parameter. 101 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 102 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 103 :param default: The default value of the parameter. 104 :param max_length: The max length of the parameter value. Defaults to 512. 105 :param required: True if user is required to provide this parameter. Defaults to True. 106 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 107 :param display_order: Determines the order parameters will be displayed in the UI. 108 """ 109 super().__init__( 110 key, label, description, default, required, advanced, display_order 111 ) 112 self.max_length = max_length 113 114 def to_json(self) -> dict: 115 return super().to_json() | { 116 "type": "string", 117 "length": int(self.max_length), 118 "default": self.default, 119 }
Helper class that provides a standard way to create an ABC using inheritance.
StringParameter( key: str, label: Optional[str] = None, description: Optional[str] = None, default: Optional[str] = None, max_length: int = 512, required: bool = True, advanced: bool = False, display_order: int = 0)
88 def __init__( 89 self, 90 key: str, 91 label: Optional[str] = None, 92 description: Optional[str] = None, 93 default: Optional[str] = None, 94 max_length: int = 512, 95 required: bool = True, 96 advanced: bool = False, 97 display_order: int = 0, 98 ) -> None: 99 """ 100 :param key: Used to identify the parameter. 101 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 102 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 103 :param default: The default value of the parameter. 104 :param max_length: The max length of the parameter value. Defaults to 512. 105 :param required: True if user is required to provide this parameter. Defaults to True. 106 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 107 :param display_order: Determines the order parameters will be displayed in the UI. 108 """ 109 super().__init__( 110 key, label, description, default, required, advanced, display_order 111 ) 112 self.max_length = max_length
Parameters
- key: Used to identify the parameter.
- label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
- description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI.
- default: The default value of the parameter.
- max_length: The max length of the parameter value. Defaults to 512.
- required: True if user is required to provide this parameter. Defaults to True.
- advanced: True if the parameter should be collapsed by default. Defaults to False.
- display_order: Determines the order parameters will be displayed in the UI.
122class EnumParameter(Parameter): 123 def __init__( 124 self, 125 key: str, 126 values: list[Union[str, tuple[str, str]]], 127 label: Optional[str] = None, 128 description: Optional[str] = None, 129 default: Optional[str] = None, 130 required: bool = True, 131 advanced: bool = False, 132 display_order: int = 0, 133 ) -> None: 134 """ 135 :param key: Used to identify the parameter. 136 :param values: An array containing all enum values. If 'default' is specified and not part of this array, it 137 will be added as an additional enum value. Enum values are not localizable. 138 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 139 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 140 :param default: The default value of the parameter. 141 :param required: True if user is required to provide this parameter. Defaults to True. 142 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 143 :param display_order: Determines the order parameters will be displayed in the UI. 144 """ 145 super().__init__( 146 key, label, description, default, required, advanced, display_order 147 ) 148 if len(values) > len(set(values)): 149 raise DuplicateKeyException( 150 f"Duplicate enum value in parameter {key}: {values}." 151 ) 152 153 self.values = values 154 self.default = default 155 156 if ( 157 default not in [v[0] if isinstance(v, tuple) else v for v in self.values] 158 and default is not None 159 ): 160 self.values.append((default, default)) 161 162 def to_json(self) -> dict: 163 return super().to_json() | { 164 "type": "string", 165 "enum": True, 166 "enum_values": [ 167 { 168 "key": str(value[0]) if isinstance(value, tuple) else value, 169 "label": str(value[1]) if isinstance(value, tuple) else value, 170 "display_order": display_order, 171 } 172 for display_order, value in enumerate(self.values) 173 ], 174 "default": self.default, 175 }
Helper class that provides a standard way to create an ABC using inheritance.
EnumParameter( key: str, values: list[typing.Union[str, tuple[str, str]]], label: Optional[str] = None, description: Optional[str] = None, default: Optional[str] = None, required: bool = True, advanced: bool = False, display_order: int = 0)
123 def __init__( 124 self, 125 key: str, 126 values: list[Union[str, tuple[str, str]]], 127 label: Optional[str] = None, 128 description: Optional[str] = None, 129 default: Optional[str] = None, 130 required: bool = True, 131 advanced: bool = False, 132 display_order: int = 0, 133 ) -> None: 134 """ 135 :param key: Used to identify the parameter. 136 :param values: An array containing all enum values. If 'default' is specified and not part of this array, it 137 will be added as an additional enum value. Enum values are not localizable. 138 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 139 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 140 :param default: The default value of the parameter. 141 :param required: True if user is required to provide this parameter. Defaults to True. 142 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 143 :param display_order: Determines the order parameters will be displayed in the UI. 144 """ 145 super().__init__( 146 key, label, description, default, required, advanced, display_order 147 ) 148 if len(values) > len(set(values)): 149 raise DuplicateKeyException( 150 f"Duplicate enum value in parameter {key}: {values}." 151 ) 152 153 self.values = values 154 self.default = default 155 156 if ( 157 default not in [v[0] if isinstance(v, tuple) else v for v in self.values] 158 and default is not None 159 ): 160 self.values.append((default, default))
Parameters
- key: Used to identify the parameter.
- values: An array containing all enum values. If 'default' is specified and not part of this array, it will be added as an additional enum value. Enum values are not localizable.
- label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
- description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI.
- default: The default value of the parameter.
- required: True if user is required to provide this parameter. Defaults to True.
- advanced: True if the parameter should be collapsed by default. Defaults to False.
- display_order: Determines the order parameters will be displayed in the UI.
def
to_json(self) -> dict:
162 def to_json(self) -> dict: 163 return super().to_json() | { 164 "type": "string", 165 "enum": True, 166 "enum_values": [ 167 { 168 "key": str(value[0]) if isinstance(value, tuple) else value, 169 "label": str(value[1]) if isinstance(value, tuple) else value, 170 "display_order": display_order, 171 } 172 for display_order, value in enumerate(self.values) 173 ], 174 "default": self.default, 175 }