aria.ops.definition.object_type

  1#  Copyright 2022 VMware, Inc.
  2#  SPDX-License-Identifier: Apache-2.0
  3from __future__ import annotations
  4
  5from collections import OrderedDict
  6from typing import Optional
  7from typing import Union
  8
  9from aria.ops.definition.assertions import validate_key
 10from aria.ops.definition.exceptions import DuplicateKeyException
 11from aria.ops.definition.group import GroupType
 12from aria.ops.definition.parameter import EnumParameter
 13from aria.ops.definition.parameter import IntParameter
 14from aria.ops.definition.parameter import Parameter
 15from aria.ops.definition.parameter import StringParameter
 16
 17
 18class ObjectType(GroupType):  # type: ignore
 19    def __init__(self, key: str, label: Optional[str] = None):
 20        """
 21        Create a new object type definition
 22        :param key: The key of the object type
 23        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
 24        """
 25        self.key = validate_key(key, "Object type")
 26        self.label = label
 27        if label is None:
 28            self.label = key
 29        self.identifiers: dict = OrderedDict()
 30        super().__init__()
 31
 32    def define_string_identifier(
 33        self,
 34        key: str,
 35        label: Optional[str] = None,
 36        required: bool = True,
 37        is_part_of_uniqueness: bool = True,
 38        default: Optional[str] = None,
 39    ) -> ObjectType:
 40        """
 41        Create a new string identifier and apply it to this object type definition.
 42        All identifiers marked as 'part of uniqueness' are used to determine object identification. If none exist, the
 43        object name will be used for identification.
 44        :param key: Used to identify the parameter.
 45        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
 46        :param required: True if this parameter is required. Defaults to True.
 47        :param is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
 48        :param default: The default value of the parameter.
 49        :return The created String Identifier.
 50        """
 51        parameter = StringParameter(
 52            key,
 53            label,
 54            required=required,
 55            advanced=not is_part_of_uniqueness,
 56            default=default,
 57            display_order=len(self.identifiers),
 58        )
 59        self.add_identifier(parameter)
 60        return self
 61
 62    def define_int_identifier(
 63        self,
 64        key: str,
 65        label: Optional[str] = None,
 66        required: bool = True,
 67        is_part_of_uniqueness: bool = True,
 68        default: Optional[int] = None,
 69    ) -> ObjectType:
 70        """
 71        Create a new int identifier and apply it to this object type definition.
 72        All identifiers marked 'part of uniqueness' are used to determine object identification. If none exist, the
 73        object name will be used for identification.
 74        :param key: Used to identify the parameter.
 75        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
 76        :param required: True if this parameter is required. Defaults to True.
 77        :param is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
 78        :param default: The default value of the parameter.
 79        :return The created Int Identifier.
 80        """
 81        parameter = IntParameter(
 82            key,
 83            label,
 84            required=required,
 85            advanced=not is_part_of_uniqueness,
 86            default=default,
 87            display_order=len(self.identifiers),
 88        )
 89        self.add_identifier(parameter)
 90        return self
 91
 92    def define_enum_identifier(
 93        self,
 94        key: str,
 95        values: list[Union[str, tuple[str, str]]],
 96        label: Optional[str] = None,
 97        required: bool = True,
 98        is_part_of_uniqueness: bool = True,
 99        default: Optional[str] = None,
100    ) -> ObjectType:
101        """
102        Create a new enum identifier and apply it to this object type definition.
103        All identifiers marked as 'part of uniqueness' are used to determine object identification. If none exist, the
104        object name will be used for identification.
105        :param key: Used to identify the parameter.
106        :param values: An array containing all enum values. If 'default' is specified and not part of this array, it
107               will be added as an additional enum value (values are case-sensitive). Enum values are not localizable.
108        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
109        :param required: True if this parameter is required. Defaults to True.
110        :param is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
111        :param default: The default value of the parameter.
112        :return The created Enum Identifier.
113        """
114        parameter = EnumParameter(
115            key,
116            values,
117            label,
118            required=required,
119            advanced=not is_part_of_uniqueness,
120            default=default,
121            display_order=len(self.identifiers),
122        )
123        self.add_identifier(parameter)
124        return self
125
126    def add_identifiers(self, identifiers: list[Parameter]) -> None:
127        """
128        :param identifiers: A list of identifiers to add to this object type
129        :return: None
130        """
131        for identifier in identifiers:
132            self.add_identifier(identifier)
133
134    def add_identifier(self, identifier: Parameter) -> None:
135        """
136        Add an identifier to this object type. All 'identifying' identifiers are used to determine object uniqueness.
137        If no 'identifying' identifiers exist, they object name will be used for uniqueness.
138        :param identifier: The identifier to add to the object type definition.
139        :return: None
140        """
141        key = identifier.key
142        if key in self.identifiers:
143            raise DuplicateKeyException(
144                f"Identifier with key {key} already exists in object type {self.key}."
145            )
146        self.identifiers[key] = identifier
147
148    def to_json(self) -> dict:
149        return {  # type: ignore
150            "key": self.key,
151            "label": self.label,
152            "identifiers": [
153                identifier.to_json() for identifier in self.identifiers.values()
154            ],
155        } | super().to_json()
class ObjectType(aria.ops.definition.group.GroupType):
 19class ObjectType(GroupType):  # type: ignore
 20    def __init__(self, key: str, label: Optional[str] = None):
 21        """
 22        Create a new object type definition
 23        :param key: The key of the object type
 24        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
 25        """
 26        self.key = validate_key(key, "Object type")
 27        self.label = label
 28        if label is None:
 29            self.label = key
 30        self.identifiers: dict = OrderedDict()
 31        super().__init__()
 32
 33    def define_string_identifier(
 34        self,
 35        key: str,
 36        label: Optional[str] = None,
 37        required: bool = True,
 38        is_part_of_uniqueness: bool = True,
 39        default: Optional[str] = None,
 40    ) -> ObjectType:
 41        """
 42        Create a new string identifier and apply it to this object type definition.
 43        All identifiers marked as 'part of uniqueness' are used to determine object identification. If none exist, the
 44        object name will be used for identification.
 45        :param key: Used to identify the parameter.
 46        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
 47        :param required: True if this parameter is required. Defaults to True.
 48        :param is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
 49        :param default: The default value of the parameter.
 50        :return The created String Identifier.
 51        """
 52        parameter = StringParameter(
 53            key,
 54            label,
 55            required=required,
 56            advanced=not is_part_of_uniqueness,
 57            default=default,
 58            display_order=len(self.identifiers),
 59        )
 60        self.add_identifier(parameter)
 61        return self
 62
 63    def define_int_identifier(
 64        self,
 65        key: str,
 66        label: Optional[str] = None,
 67        required: bool = True,
 68        is_part_of_uniqueness: bool = True,
 69        default: Optional[int] = None,
 70    ) -> ObjectType:
 71        """
 72        Create a new int identifier and apply it to this object type definition.
 73        All identifiers marked 'part of uniqueness' are used to determine object identification. If none exist, the
 74        object name will be used for identification.
 75        :param key: Used to identify the parameter.
 76        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
 77        :param required: True if this parameter is required. Defaults to True.
 78        :param is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
 79        :param default: The default value of the parameter.
 80        :return The created Int Identifier.
 81        """
 82        parameter = IntParameter(
 83            key,
 84            label,
 85            required=required,
 86            advanced=not is_part_of_uniqueness,
 87            default=default,
 88            display_order=len(self.identifiers),
 89        )
 90        self.add_identifier(parameter)
 91        return self
 92
 93    def define_enum_identifier(
 94        self,
 95        key: str,
 96        values: list[Union[str, tuple[str, str]]],
 97        label: Optional[str] = None,
 98        required: bool = True,
 99        is_part_of_uniqueness: bool = True,
100        default: Optional[str] = None,
101    ) -> ObjectType:
102        """
103        Create a new enum identifier and apply it to this object type definition.
104        All identifiers marked as 'part of uniqueness' are used to determine object identification. If none exist, the
105        object name will be used for identification.
106        :param key: Used to identify the parameter.
107        :param values: An array containing all enum values. If 'default' is specified and not part of this array, it
108               will be added as an additional enum value (values are case-sensitive). Enum values are not localizable.
109        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
110        :param required: True if this parameter is required. Defaults to True.
111        :param is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
112        :param default: The default value of the parameter.
113        :return The created Enum Identifier.
114        """
115        parameter = EnumParameter(
116            key,
117            values,
118            label,
119            required=required,
120            advanced=not is_part_of_uniqueness,
121            default=default,
122            display_order=len(self.identifiers),
123        )
124        self.add_identifier(parameter)
125        return self
126
127    def add_identifiers(self, identifiers: list[Parameter]) -> None:
128        """
129        :param identifiers: A list of identifiers to add to this object type
130        :return: None
131        """
132        for identifier in identifiers:
133            self.add_identifier(identifier)
134
135    def add_identifier(self, identifier: Parameter) -> None:
136        """
137        Add an identifier to this object type. All 'identifying' identifiers are used to determine object uniqueness.
138        If no 'identifying' identifiers exist, they object name will be used for uniqueness.
139        :param identifier: The identifier to add to the object type definition.
140        :return: None
141        """
142        key = identifier.key
143        if key in self.identifiers:
144            raise DuplicateKeyException(
145                f"Identifier with key {key} already exists in object type {self.key}."
146            )
147        self.identifiers[key] = identifier
148
149    def to_json(self) -> dict:
150        return {  # type: ignore
151            "key": self.key,
152            "label": self.label,
153            "identifiers": [
154                identifier.to_json() for identifier in self.identifiers.values()
155            ],
156        } | super().to_json()

Helper class that provides a standard way to create an ABC using inheritance.

ObjectType(key: str, label: Optional[str] = None)
20    def __init__(self, key: str, label: Optional[str] = None):
21        """
22        Create a new object type definition
23        :param key: The key of the object type
24        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
25        """
26        self.key = validate_key(key, "Object type")
27        self.label = label
28        if label is None:
29            self.label = key
30        self.identifiers: dict = OrderedDict()
31        super().__init__()

Create a new object type definition

Parameters
  • key: The key of the object type
  • label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
def define_string_identifier( self, key: str, label: Optional[str] = None, required: bool = True, is_part_of_uniqueness: bool = True, default: Optional[str] = None) -> aria.ops.definition.object_type.ObjectType:
33    def define_string_identifier(
34        self,
35        key: str,
36        label: Optional[str] = None,
37        required: bool = True,
38        is_part_of_uniqueness: bool = True,
39        default: Optional[str] = None,
40    ) -> ObjectType:
41        """
42        Create a new string identifier and apply it to this object type definition.
43        All identifiers marked as 'part of uniqueness' are used to determine object identification. If none exist, the
44        object name will be used for identification.
45        :param key: Used to identify the parameter.
46        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
47        :param required: True if this parameter is required. Defaults to True.
48        :param is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
49        :param default: The default value of the parameter.
50        :return The created String Identifier.
51        """
52        parameter = StringParameter(
53            key,
54            label,
55            required=required,
56            advanced=not is_part_of_uniqueness,
57            default=default,
58            display_order=len(self.identifiers),
59        )
60        self.add_identifier(parameter)
61        return self

Create a new string identifier and apply it to this object type definition. All identifiers marked as 'part of uniqueness' are used to determine object identification. If none exist, the object name will be used for identification.

Parameters
  • key: Used to identify the parameter.
  • label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
  • required: True if this parameter is required. Defaults to True.
  • is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
  • default: The default value of the parameter. :return The created String Identifier.
def define_int_identifier( self, key: str, label: Optional[str] = None, required: bool = True, is_part_of_uniqueness: bool = True, default: Optional[int] = None) -> aria.ops.definition.object_type.ObjectType:
63    def define_int_identifier(
64        self,
65        key: str,
66        label: Optional[str] = None,
67        required: bool = True,
68        is_part_of_uniqueness: bool = True,
69        default: Optional[int] = None,
70    ) -> ObjectType:
71        """
72        Create a new int identifier and apply it to this object type definition.
73        All identifiers marked 'part of uniqueness' are used to determine object identification. If none exist, the
74        object name will be used for identification.
75        :param key: Used to identify the parameter.
76        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
77        :param required: True if this parameter is required. Defaults to True.
78        :param is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
79        :param default: The default value of the parameter.
80        :return The created Int Identifier.
81        """
82        parameter = IntParameter(
83            key,
84            label,
85            required=required,
86            advanced=not is_part_of_uniqueness,
87            default=default,
88            display_order=len(self.identifiers),
89        )
90        self.add_identifier(parameter)
91        return self

Create a new int identifier and apply it to this object type definition. All identifiers marked 'part of uniqueness' are used to determine object identification. If none exist, the object name will be used for identification.

Parameters
  • key: Used to identify the parameter.
  • label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
  • required: True if this parameter is required. Defaults to True.
  • is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
  • default: The default value of the parameter. :return The created Int Identifier.
def define_enum_identifier( self, key: str, values: list[typing.Union[str, tuple[str, str]]], label: Optional[str] = None, required: bool = True, is_part_of_uniqueness: bool = True, default: Optional[str] = None) -> aria.ops.definition.object_type.ObjectType:
 93    def define_enum_identifier(
 94        self,
 95        key: str,
 96        values: list[Union[str, tuple[str, str]]],
 97        label: Optional[str] = None,
 98        required: bool = True,
 99        is_part_of_uniqueness: bool = True,
100        default: Optional[str] = None,
101    ) -> ObjectType:
102        """
103        Create a new enum identifier and apply it to this object type definition.
104        All identifiers marked as 'part of uniqueness' are used to determine object identification. If none exist, the
105        object name will be used for identification.
106        :param key: Used to identify the parameter.
107        :param values: An array containing all enum values. If 'default' is specified and not part of this array, it
108               will be added as an additional enum value (values are case-sensitive). Enum values are not localizable.
109        :param label: Label that is displayed in the VMware Aria Operations UI. Defaults to the key.
110        :param required: True if this parameter is required. Defaults to True.
111        :param is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
112        :param default: The default value of the parameter.
113        :return The created Enum Identifier.
114        """
115        parameter = EnumParameter(
116            key,
117            values,
118            label,
119            required=required,
120            advanced=not is_part_of_uniqueness,
121            default=default,
122            display_order=len(self.identifiers),
123        )
124        self.add_identifier(parameter)
125        return self

Create a new enum identifier and apply it to this object type definition. All identifiers marked as 'part of uniqueness' are used to determine object identification. If none exist, the object name will be used for identification.

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.
  • required: True if this parameter is required. Defaults to True.
  • is_part_of_uniqueness: True if the parameter should be used for object identification. Defaults to True.
  • default: The default value of the parameter. :return The created Enum Identifier.
def add_identifiers(self, identifiers: list[aria.ops.definition.parameter.Parameter]) -> None:
127    def add_identifiers(self, identifiers: list[Parameter]) -> None:
128        """
129        :param identifiers: A list of identifiers to add to this object type
130        :return: None
131        """
132        for identifier in identifiers:
133            self.add_identifier(identifier)
Parameters
  • identifiers: A list of identifiers to add to this object type
Returns

None

def add_identifier(self, identifier: aria.ops.definition.parameter.Parameter) -> None:
135    def add_identifier(self, identifier: Parameter) -> None:
136        """
137        Add an identifier to this object type. All 'identifying' identifiers are used to determine object uniqueness.
138        If no 'identifying' identifiers exist, they object name will be used for uniqueness.
139        :param identifier: The identifier to add to the object type definition.
140        :return: None
141        """
142        key = identifier.key
143        if key in self.identifiers:
144            raise DuplicateKeyException(
145                f"Identifier with key {key} already exists in object type {self.key}."
146            )
147        self.identifiers[key] = identifier

Add an identifier to this object type. All 'identifying' identifiers are used to determine object uniqueness. If no 'identifying' identifiers exist, they object name will be used for uniqueness.

Parameters
  • identifier: The identifier to add to the object type definition.
Returns

None

def to_json(self) -> dict:
149    def to_json(self) -> dict:
150        return {  # type: ignore
151            "key": self.key,
152            "label": self.label,
153            "identifiers": [
154                identifier.to_json() for identifier in self.identifiers.values()
155            ],
156        } | super().to_json()