aria.ops.definition.adapter_definition
1# Copyright 2022-2023 VMware, Inc. 2# SPDX-License-Identifier: Apache-2.0 3from __future__ import annotations 4 5import sys 6from collections import OrderedDict 7from typing import Optional 8 9from aria.ops.definition.assertions import validate_key 10from aria.ops.definition.credential_type import CredentialType 11from aria.ops.definition.exceptions import DuplicateKeyException 12from aria.ops.definition.exceptions import KeyException 13from aria.ops.definition.group import GroupType 14from aria.ops.definition.object_type import ObjectType 15from aria.ops.definition.parameter import EnumParameter 16from aria.ops.definition.parameter import IntParameter 17from aria.ops.definition.parameter import Parameter 18from aria.ops.definition.parameter import StringParameter 19from aria.ops.pipe_utils import write_to_pipe 20 21 22class AdapterDefinition(GroupType): # type: ignore 23 def __init__( 24 self, 25 key: str, 26 label: Optional[str] = None, 27 adapter_instance_key: Optional[str] = None, 28 adapter_instance_label: Optional[str] = None, 29 version: int = 1, 30 ): 31 """ 32 :param key: The adapter key is used to identify the adapter and its object types. It must be unique across 33 all Management Packs. 34 :param label: Label that is displayed in the VMware Aria Operations UI for this adapter. Defaults to the key. 35 :param adapter_instance_key: Object type of the adapter instance object. Defaults to 36 '{adapter key}_adapter_instance'. 37 :param adapter_instance_label: Label that is displayed in the VMware Aria Operations UI for the adapter instance 38 object type. Defaults to '{adapter label} Adapter Instance'. 39 :param version: Version of the definition. This should be incremented for new releases of the adapter. 40 """ 41 key = validate_key(key, "Adapter") 42 if not key[0].isalpha(): 43 raise KeyException("Adapter key must start with a letter.") 44 if len(key.split()) > 1: 45 raise KeyException("Adapter key cannot contain whitespace.") 46 if not all(c.isalnum() or c == "_" for c in key): 47 raise KeyException( 48 "Adapter key cannot contain special characters besides '_'." 49 ) 50 51 self.key = key 52 53 self.label = label 54 if label is None: 55 self.label = key 56 57 self.adapter_instance_key = adapter_instance_key 58 if adapter_instance_key is None: 59 self.adapter_instance_key = f"{self.key}_adapter_instance" 60 61 self.adapter_instance_label = adapter_instance_label 62 if adapter_instance_label is None: 63 self.adapter_instance_label = f"{self.label} Adapter Instance" 64 65 self.version = version 66 self.parameters: dict = OrderedDict() 67 self.credentials: dict = {} 68 self.object_types: dict = {} 69 70 super().__init__() 71 72 def to_json(self) -> dict: 73 return { 74 "adapter_key": self.key, 75 "adapter_label": self.label, 76 "describe_version": self.version, 77 "schema_version": 1, 78 "adapter_instance": { 79 "key": self.adapter_instance_key, 80 "label": self.adapter_instance_label, 81 "identifiers": [ 82 identifier.to_json() for identifier in self.parameters.values() 83 ], 84 } 85 | super().to_json(), 86 "credential_types": [ 87 credential_type.to_json() 88 for credential_type in self.credentials.values() 89 ], 90 "object_types": [ 91 object_type.to_json() for object_type in self.object_types.values() 92 ], 93 } 94 95 def send_results(self, output_pipe: str = sys.argv[-1]) -> None: 96 """Opens the output pipe and sends results directly back to the server 97 98 This method can only be called once per server request. 99 """ 100 # The server always invokes methods with the output file as the last argument 101 write_to_pipe(output_pipe, self.to_json()) 102 103 def define_string_parameter( 104 self, 105 key: str, 106 label: Optional[str] = None, 107 description: Optional[str] = None, 108 default: Optional[str] = None, 109 max_length: int = 512, 110 required: bool = True, 111 advanced: bool = False, 112 ) -> StringParameter: 113 """ 114 Create a new string parameter and add it to the adapter instance. The user will be asked to provide a value for 115 this parameter each time a new account/adapter instance is created. 116 :param key: Used to identify the parameter 117 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 118 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 119 :param default: The default value of the parameter. 120 :param max_length: The max length of the parameter value. Defaults to 512. 121 :param required: True if user is required to provide this parameter. Defaults to True. 122 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 123 :return The created string parameter definition. 124 """ 125 parameter = StringParameter( 126 key, 127 label, 128 description, 129 default, 130 max_length, 131 required, 132 advanced, 133 display_order=len(self.parameters), 134 ) 135 self.add_parameter(parameter) 136 return parameter 137 138 def define_int_parameter( 139 self, 140 key: str, 141 label: Optional[str] = None, 142 description: Optional[str] = None, 143 default: Optional[int] = None, 144 required: bool = True, 145 advanced: bool = False, 146 ) -> IntParameter: 147 """ 148 Create a new integer parameter and add it to the adapter instance. The user will be asked to provide a value for 149 this parameter each time a new account/adapter instance is created. 150 :param key: Used to identify the parameter 151 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 152 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 153 :param default: The default value of the parameter. 154 :param required: True if user is required to provide this parameter. Defaults to True. 155 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 156 :return The created int parameter definition. 157 """ 158 parameter = IntParameter( 159 key, 160 label, 161 description, 162 default, 163 required, 164 advanced, 165 display_order=len(self.parameters), 166 ) 167 self.add_parameter(parameter) 168 return parameter 169 170 def define_enum_parameter( 171 self, 172 key: str, 173 values: list[str], 174 label: Optional[str] = None, 175 description: Optional[str] = None, 176 default: Optional[str] = None, 177 required: bool = True, 178 advanced: bool = False, 179 ) -> EnumParameter: 180 """ 181 Create a new enum parameter and add it to the adapter instance. The user will be asked to provide a value for 182 this parameter each time a new account/adapter instance is created. 183 :param key: Used to identify the parameter 184 :param values: An array containing all enum values. If 'default' is specified and not part of this array, it 185 will be added as an additional enum value (values are case-sensitive). Enum values are not localizable. 186 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 187 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 188 :param default: The default value of the parameter. 189 :param required: True if user is required to provide this parameter. Defaults to True. 190 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 191 :return The created enum parameter definition. 192 """ 193 parameter = EnumParameter( 194 key, 195 values, 196 label, 197 description, 198 default, 199 required, 200 advanced, 201 display_order=len(self.parameters), 202 ) 203 self.add_parameter(parameter) 204 return parameter 205 206 def add_parameter(self, parameter: Parameter) -> None: 207 """ 208 Add a parameter to the adapter instance. The user will be asked to provide a value for 209 this parameter each time a new account/adapter instance is created. 210 :param parameter: The parameter to add to the adapter instance. 211 :return: None 212 """ 213 key = parameter.key 214 if key in self.parameters: 215 raise DuplicateKeyException( 216 f"Parameter with key {key} already exists in adapter definition." 217 ) 218 self.parameters[key] = parameter 219 220 def define_credential_type( 221 self, key: str = "default_credential", label: Optional[str] = None 222 ) -> CredentialType: 223 """ 224 Create a new credential type and add it to this adapter instance. When more than one credential types are 225 present, The user will be required to select the type and then fill in the parameters for that type, as only 226 one credential type can be used for any given adapter instance. 227 :param key: Used to identify the credential type 228 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 229 :return The created credential type. 230 """ 231 credential = CredentialType(key, label) 232 self.add_credential_type(credential) 233 return credential 234 235 def add_credential_types(self, credential_types: list[CredentialType]) -> None: 236 """ 237 Add a list of credential types to the adapter instance. 238 :param credential_types: A list of credential types to add. 239 :return: None 240 """ 241 for credential_type in credential_types: 242 self.add_credential_type(credential_type) 243 244 def add_credential_type(self, credential_type: CredentialType) -> None: 245 """ 246 Add a credential type to the adapter instance. When more than one credential types are present, The user will 247 be required to select the type and then fill in the parameters for that type, as only one credential type can be 248 used for any given adapter instance. 249 :param credential_type: The credential type to add. 250 :return: None 251 """ 252 key = credential_type.key 253 if key in self.credentials: 254 raise DuplicateKeyException( 255 f"Credential type with key {key} already exists in adapter definition." 256 ) 257 self.credentials[key] = credential_type 258 259 def define_object_type(self, key: str, label: Optional[str] = None) -> ObjectType: 260 """ 261 Create a new object type definition and add it to this adapter definition. 262 :param key: The object type 263 :param label: Label that is displayed in the VMware Aria Operations UI for this object type. Defaults to the key. 264 :return: The created object type definition 265 """ 266 object_type = ObjectType(key, label) 267 self.add_object_type(object_type) 268 return object_type 269 270 def add_object_types(self, object_types: list[ObjectType]) -> None: 271 """ 272 Adds a list of object types to this adapter definition 273 :param object_types: A list of object type definitions. 274 :return: None 275 """ 276 for object_type in object_types: 277 self.add_object_type(object_type) 278 279 def add_object_type(self, object_type: ObjectType) -> None: 280 """ 281 Adds an object type to this adapter definition 282 :param object_type: An object type definition. 283 :return: None 284 """ 285 key = object_type.key 286 if key in self.object_types: 287 raise DuplicateKeyException( 288 f"Object type with key {key} already exists in adapter definition." 289 ) 290 self.object_types[key] = object_type
23class AdapterDefinition(GroupType): # type: ignore 24 def __init__( 25 self, 26 key: str, 27 label: Optional[str] = None, 28 adapter_instance_key: Optional[str] = None, 29 adapter_instance_label: Optional[str] = None, 30 version: int = 1, 31 ): 32 """ 33 :param key: The adapter key is used to identify the adapter and its object types. It must be unique across 34 all Management Packs. 35 :param label: Label that is displayed in the VMware Aria Operations UI for this adapter. Defaults to the key. 36 :param adapter_instance_key: Object type of the adapter instance object. Defaults to 37 '{adapter key}_adapter_instance'. 38 :param adapter_instance_label: Label that is displayed in the VMware Aria Operations UI for the adapter instance 39 object type. Defaults to '{adapter label} Adapter Instance'. 40 :param version: Version of the definition. This should be incremented for new releases of the adapter. 41 """ 42 key = validate_key(key, "Adapter") 43 if not key[0].isalpha(): 44 raise KeyException("Adapter key must start with a letter.") 45 if len(key.split()) > 1: 46 raise KeyException("Adapter key cannot contain whitespace.") 47 if not all(c.isalnum() or c == "_" for c in key): 48 raise KeyException( 49 "Adapter key cannot contain special characters besides '_'." 50 ) 51 52 self.key = key 53 54 self.label = label 55 if label is None: 56 self.label = key 57 58 self.adapter_instance_key = adapter_instance_key 59 if adapter_instance_key is None: 60 self.adapter_instance_key = f"{self.key}_adapter_instance" 61 62 self.adapter_instance_label = adapter_instance_label 63 if adapter_instance_label is None: 64 self.adapter_instance_label = f"{self.label} Adapter Instance" 65 66 self.version = version 67 self.parameters: dict = OrderedDict() 68 self.credentials: dict = {} 69 self.object_types: dict = {} 70 71 super().__init__() 72 73 def to_json(self) -> dict: 74 return { 75 "adapter_key": self.key, 76 "adapter_label": self.label, 77 "describe_version": self.version, 78 "schema_version": 1, 79 "adapter_instance": { 80 "key": self.adapter_instance_key, 81 "label": self.adapter_instance_label, 82 "identifiers": [ 83 identifier.to_json() for identifier in self.parameters.values() 84 ], 85 } 86 | super().to_json(), 87 "credential_types": [ 88 credential_type.to_json() 89 for credential_type in self.credentials.values() 90 ], 91 "object_types": [ 92 object_type.to_json() for object_type in self.object_types.values() 93 ], 94 } 95 96 def send_results(self, output_pipe: str = sys.argv[-1]) -> None: 97 """Opens the output pipe and sends results directly back to the server 98 99 This method can only be called once per server request. 100 """ 101 # The server always invokes methods with the output file as the last argument 102 write_to_pipe(output_pipe, self.to_json()) 103 104 def define_string_parameter( 105 self, 106 key: str, 107 label: Optional[str] = None, 108 description: Optional[str] = None, 109 default: Optional[str] = None, 110 max_length: int = 512, 111 required: bool = True, 112 advanced: bool = False, 113 ) -> StringParameter: 114 """ 115 Create a new string parameter and add it to the adapter instance. The user will be asked to provide a value for 116 this parameter each time a new account/adapter instance is created. 117 :param key: Used to identify the parameter 118 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 119 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 120 :param default: The default value of the parameter. 121 :param max_length: The max length of the parameter value. Defaults to 512. 122 :param required: True if user is required to provide this parameter. Defaults to True. 123 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 124 :return The created string parameter definition. 125 """ 126 parameter = StringParameter( 127 key, 128 label, 129 description, 130 default, 131 max_length, 132 required, 133 advanced, 134 display_order=len(self.parameters), 135 ) 136 self.add_parameter(parameter) 137 return parameter 138 139 def define_int_parameter( 140 self, 141 key: str, 142 label: Optional[str] = None, 143 description: Optional[str] = None, 144 default: Optional[int] = None, 145 required: bool = True, 146 advanced: bool = False, 147 ) -> IntParameter: 148 """ 149 Create a new integer parameter and add it to the adapter instance. The user will be asked to provide a value for 150 this parameter each time a new account/adapter instance is created. 151 :param key: Used to identify the parameter 152 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 153 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 154 :param default: The default value of the parameter. 155 :param required: True if user is required to provide this parameter. Defaults to True. 156 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 157 :return The created int parameter definition. 158 """ 159 parameter = IntParameter( 160 key, 161 label, 162 description, 163 default, 164 required, 165 advanced, 166 display_order=len(self.parameters), 167 ) 168 self.add_parameter(parameter) 169 return parameter 170 171 def define_enum_parameter( 172 self, 173 key: str, 174 values: list[str], 175 label: Optional[str] = None, 176 description: Optional[str] = None, 177 default: Optional[str] = None, 178 required: bool = True, 179 advanced: bool = False, 180 ) -> EnumParameter: 181 """ 182 Create a new enum parameter and add it to the adapter instance. The user will be asked to provide a value for 183 this parameter each time a new account/adapter instance is created. 184 :param key: Used to identify the parameter 185 :param values: An array containing all enum values. If 'default' is specified and not part of this array, it 186 will be added as an additional enum value (values are case-sensitive). Enum values are not localizable. 187 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 188 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 189 :param default: The default value of the parameter. 190 :param required: True if user is required to provide this parameter. Defaults to True. 191 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 192 :return The created enum parameter definition. 193 """ 194 parameter = EnumParameter( 195 key, 196 values, 197 label, 198 description, 199 default, 200 required, 201 advanced, 202 display_order=len(self.parameters), 203 ) 204 self.add_parameter(parameter) 205 return parameter 206 207 def add_parameter(self, parameter: Parameter) -> None: 208 """ 209 Add a parameter to the adapter instance. The user will be asked to provide a value for 210 this parameter each time a new account/adapter instance is created. 211 :param parameter: The parameter to add to the adapter instance. 212 :return: None 213 """ 214 key = parameter.key 215 if key in self.parameters: 216 raise DuplicateKeyException( 217 f"Parameter with key {key} already exists in adapter definition." 218 ) 219 self.parameters[key] = parameter 220 221 def define_credential_type( 222 self, key: str = "default_credential", label: Optional[str] = None 223 ) -> CredentialType: 224 """ 225 Create a new credential type and add it to this adapter instance. When more than one credential types are 226 present, The user will be required to select the type and then fill in the parameters for that type, as only 227 one credential type can be used for any given adapter instance. 228 :param key: Used to identify the credential type 229 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 230 :return The created credential type. 231 """ 232 credential = CredentialType(key, label) 233 self.add_credential_type(credential) 234 return credential 235 236 def add_credential_types(self, credential_types: list[CredentialType]) -> None: 237 """ 238 Add a list of credential types to the adapter instance. 239 :param credential_types: A list of credential types to add. 240 :return: None 241 """ 242 for credential_type in credential_types: 243 self.add_credential_type(credential_type) 244 245 def add_credential_type(self, credential_type: CredentialType) -> None: 246 """ 247 Add a credential type to the adapter instance. When more than one credential types are present, The user will 248 be required to select the type and then fill in the parameters for that type, as only one credential type can be 249 used for any given adapter instance. 250 :param credential_type: The credential type to add. 251 :return: None 252 """ 253 key = credential_type.key 254 if key in self.credentials: 255 raise DuplicateKeyException( 256 f"Credential type with key {key} already exists in adapter definition." 257 ) 258 self.credentials[key] = credential_type 259 260 def define_object_type(self, key: str, label: Optional[str] = None) -> ObjectType: 261 """ 262 Create a new object type definition and add it to this adapter definition. 263 :param key: The object type 264 :param label: Label that is displayed in the VMware Aria Operations UI for this object type. Defaults to the key. 265 :return: The created object type definition 266 """ 267 object_type = ObjectType(key, label) 268 self.add_object_type(object_type) 269 return object_type 270 271 def add_object_types(self, object_types: list[ObjectType]) -> None: 272 """ 273 Adds a list of object types to this adapter definition 274 :param object_types: A list of object type definitions. 275 :return: None 276 """ 277 for object_type in object_types: 278 self.add_object_type(object_type) 279 280 def add_object_type(self, object_type: ObjectType) -> None: 281 """ 282 Adds an object type to this adapter definition 283 :param object_type: An object type definition. 284 :return: None 285 """ 286 key = object_type.key 287 if key in self.object_types: 288 raise DuplicateKeyException( 289 f"Object type with key {key} already exists in adapter definition." 290 ) 291 self.object_types[key] = object_type
Helper class that provides a standard way to create an ABC using inheritance.
24 def __init__( 25 self, 26 key: str, 27 label: Optional[str] = None, 28 adapter_instance_key: Optional[str] = None, 29 adapter_instance_label: Optional[str] = None, 30 version: int = 1, 31 ): 32 """ 33 :param key: The adapter key is used to identify the adapter and its object types. It must be unique across 34 all Management Packs. 35 :param label: Label that is displayed in the VMware Aria Operations UI for this adapter. Defaults to the key. 36 :param adapter_instance_key: Object type of the adapter instance object. Defaults to 37 '{adapter key}_adapter_instance'. 38 :param adapter_instance_label: Label that is displayed in the VMware Aria Operations UI for the adapter instance 39 object type. Defaults to '{adapter label} Adapter Instance'. 40 :param version: Version of the definition. This should be incremented for new releases of the adapter. 41 """ 42 key = validate_key(key, "Adapter") 43 if not key[0].isalpha(): 44 raise KeyException("Adapter key must start with a letter.") 45 if len(key.split()) > 1: 46 raise KeyException("Adapter key cannot contain whitespace.") 47 if not all(c.isalnum() or c == "_" for c in key): 48 raise KeyException( 49 "Adapter key cannot contain special characters besides '_'." 50 ) 51 52 self.key = key 53 54 self.label = label 55 if label is None: 56 self.label = key 57 58 self.adapter_instance_key = adapter_instance_key 59 if adapter_instance_key is None: 60 self.adapter_instance_key = f"{self.key}_adapter_instance" 61 62 self.adapter_instance_label = adapter_instance_label 63 if adapter_instance_label is None: 64 self.adapter_instance_label = f"{self.label} Adapter Instance" 65 66 self.version = version 67 self.parameters: dict = OrderedDict() 68 self.credentials: dict = {} 69 self.object_types: dict = {} 70 71 super().__init__()
Parameters
- key: The adapter key is used to identify the adapter and its object types. It must be unique across all Management Packs.
- label: Label that is displayed in the VMware Aria Operations UI for this adapter. Defaults to the key.
- adapter_instance_key: Object type of the adapter instance object. Defaults to '{adapter key}_adapter_instance'.
- adapter_instance_label: Label that is displayed in the VMware Aria Operations UI for the adapter instance object type. Defaults to '{adapter label} Adapter Instance'.
- version: Version of the definition. This should be incremented for new releases of the adapter.
73 def to_json(self) -> dict: 74 return { 75 "adapter_key": self.key, 76 "adapter_label": self.label, 77 "describe_version": self.version, 78 "schema_version": 1, 79 "adapter_instance": { 80 "key": self.adapter_instance_key, 81 "label": self.adapter_instance_label, 82 "identifiers": [ 83 identifier.to_json() for identifier in self.parameters.values() 84 ], 85 } 86 | super().to_json(), 87 "credential_types": [ 88 credential_type.to_json() 89 for credential_type in self.credentials.values() 90 ], 91 "object_types": [ 92 object_type.to_json() for object_type in self.object_types.values() 93 ], 94 }
96 def send_results(self, output_pipe: str = sys.argv[-1]) -> None: 97 """Opens the output pipe and sends results directly back to the server 98 99 This method can only be called once per server request. 100 """ 101 # The server always invokes methods with the output file as the last argument 102 write_to_pipe(output_pipe, self.to_json())
Opens the output pipe and sends results directly back to the server
This method can only be called once per server request.
104 def define_string_parameter( 105 self, 106 key: str, 107 label: Optional[str] = None, 108 description: Optional[str] = None, 109 default: Optional[str] = None, 110 max_length: int = 512, 111 required: bool = True, 112 advanced: bool = False, 113 ) -> StringParameter: 114 """ 115 Create a new string parameter and add it to the adapter instance. The user will be asked to provide a value for 116 this parameter each time a new account/adapter instance is created. 117 :param key: Used to identify the parameter 118 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 119 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 120 :param default: The default value of the parameter. 121 :param max_length: The max length of the parameter value. Defaults to 512. 122 :param required: True if user is required to provide this parameter. Defaults to True. 123 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 124 :return The created string parameter definition. 125 """ 126 parameter = StringParameter( 127 key, 128 label, 129 description, 130 default, 131 max_length, 132 required, 133 advanced, 134 display_order=len(self.parameters), 135 ) 136 self.add_parameter(parameter) 137 return parameter
Create a new string parameter and add it to the adapter instance. The user will be asked to provide a value for this parameter each time a new account/adapter instance is created.
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. :return The created string parameter definition.
139 def define_int_parameter( 140 self, 141 key: str, 142 label: Optional[str] = None, 143 description: Optional[str] = None, 144 default: Optional[int] = None, 145 required: bool = True, 146 advanced: bool = False, 147 ) -> IntParameter: 148 """ 149 Create a new integer parameter and add it to the adapter instance. The user will be asked to provide a value for 150 this parameter each time a new account/adapter instance is created. 151 :param key: Used to identify the parameter 152 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 153 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 154 :param default: The default value of the parameter. 155 :param required: True if user is required to provide this parameter. Defaults to True. 156 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 157 :return The created int parameter definition. 158 """ 159 parameter = IntParameter( 160 key, 161 label, 162 description, 163 default, 164 required, 165 advanced, 166 display_order=len(self.parameters), 167 ) 168 self.add_parameter(parameter) 169 return parameter
Create a new integer parameter and add it to the adapter instance. The user will be asked to provide a value for this parameter each time a new account/adapter instance is created.
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. :return The created int parameter definition.
171 def define_enum_parameter( 172 self, 173 key: str, 174 values: list[str], 175 label: Optional[str] = None, 176 description: Optional[str] = None, 177 default: Optional[str] = None, 178 required: bool = True, 179 advanced: bool = False, 180 ) -> EnumParameter: 181 """ 182 Create a new enum parameter and add it to the adapter instance. The user will be asked to provide a value for 183 this parameter each time a new account/adapter instance is created. 184 :param key: Used to identify the parameter 185 :param values: An array containing all enum values. If 'default' is specified and not part of this array, it 186 will be added as an additional enum value (values are case-sensitive). Enum values are not localizable. 187 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 188 :param description: More in-depth explanation of the parameter. Displayed as a tooltip in the VMware Aria Operations UI. 189 :param default: The default value of the parameter. 190 :param required: True if user is required to provide this parameter. Defaults to True. 191 :param advanced: True if the parameter should be collapsed by default. Defaults to False. 192 :return The created enum parameter definition. 193 """ 194 parameter = EnumParameter( 195 key, 196 values, 197 label, 198 description, 199 default, 200 required, 201 advanced, 202 display_order=len(self.parameters), 203 ) 204 self.add_parameter(parameter) 205 return parameter
Create a new enum parameter and add it to the adapter instance. The user will be asked to provide a value for this parameter each time a new account/adapter instance is created.
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 (values are case-sensitive). 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. :return The created enum parameter definition.
207 def add_parameter(self, parameter: Parameter) -> None: 208 """ 209 Add a parameter to the adapter instance. The user will be asked to provide a value for 210 this parameter each time a new account/adapter instance is created. 211 :param parameter: The parameter to add to the adapter instance. 212 :return: None 213 """ 214 key = parameter.key 215 if key in self.parameters: 216 raise DuplicateKeyException( 217 f"Parameter with key {key} already exists in adapter definition." 218 ) 219 self.parameters[key] = parameter
Add a parameter to the adapter instance. The user will be asked to provide a value for this parameter each time a new account/adapter instance is created.
Parameters
- parameter: The parameter to add to the adapter instance.
Returns
None
221 def define_credential_type( 222 self, key: str = "default_credential", label: Optional[str] = None 223 ) -> CredentialType: 224 """ 225 Create a new credential type and add it to this adapter instance. When more than one credential types are 226 present, The user will be required to select the type and then fill in the parameters for that type, as only 227 one credential type can be used for any given adapter instance. 228 :param key: Used to identify the credential type 229 :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. 230 :return The created credential type. 231 """ 232 credential = CredentialType(key, label) 233 self.add_credential_type(credential) 234 return credential
Create a new credential type and add it to this adapter instance. When more than one credential types are present, The user will be required to select the type and then fill in the parameters for that type, as only one credential type can be used for any given adapter instance.
Parameters
- key: Used to identify the credential type
- label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key. :return The created credential type.
236 def add_credential_types(self, credential_types: list[CredentialType]) -> None: 237 """ 238 Add a list of credential types to the adapter instance. 239 :param credential_types: A list of credential types to add. 240 :return: None 241 """ 242 for credential_type in credential_types: 243 self.add_credential_type(credential_type)
Add a list of credential types to the adapter instance.
Parameters
- credential_types: A list of credential types to add.
Returns
None
245 def add_credential_type(self, credential_type: CredentialType) -> None: 246 """ 247 Add a credential type to the adapter instance. When more than one credential types are present, The user will 248 be required to select the type and then fill in the parameters for that type, as only one credential type can be 249 used for any given adapter instance. 250 :param credential_type: The credential type to add. 251 :return: None 252 """ 253 key = credential_type.key 254 if key in self.credentials: 255 raise DuplicateKeyException( 256 f"Credential type with key {key} already exists in adapter definition." 257 ) 258 self.credentials[key] = credential_type
Add a credential type to the adapter instance. When more than one credential types are present, The user will be required to select the type and then fill in the parameters for that type, as only one credential type can be used for any given adapter instance.
Parameters
- credential_type: The credential type to add.
Returns
None
260 def define_object_type(self, key: str, label: Optional[str] = None) -> ObjectType: 261 """ 262 Create a new object type definition and add it to this adapter definition. 263 :param key: The object type 264 :param label: Label that is displayed in the VMware Aria Operations UI for this object type. Defaults to the key. 265 :return: The created object type definition 266 """ 267 object_type = ObjectType(key, label) 268 self.add_object_type(object_type) 269 return object_type
Create a new object type definition and add it to this adapter definition.
Parameters
- key: The object type
- label: Label that is displayed in the VMware Aria Operations UI for this object type. Defaults to the key.
Returns
The created object type definition
271 def add_object_types(self, object_types: list[ObjectType]) -> None: 272 """ 273 Adds a list of object types to this adapter definition 274 :param object_types: A list of object type definitions. 275 :return: None 276 """ 277 for object_type in object_types: 278 self.add_object_type(object_type)
Adds a list of object types to this adapter definition
Parameters
- object_types: A list of object type definitions.
Returns
None
280 def add_object_type(self, object_type: ObjectType) -> None: 281 """ 282 Adds an object type to this adapter definition 283 :param object_type: An object type definition. 284 :return: None 285 """ 286 key = object_type.key 287 if key in self.object_types: 288 raise DuplicateKeyException( 289 f"Object type with key {key} already exists in adapter definition." 290 ) 291 self.object_types[key] = object_type
Adds an object type to this adapter definition
Parameters
- object_type: An object type definition.
Returns
None