def _discover_artificial_folder(self, model_subfolder_type, location,
                                 name_token):
     """
     Discover the subfolder that has an artificial connection; the subfolder contains multiple different types
     under one MBean. The model must contain the subfolder type, the artificial type that specifies which it is,
     and the name of the subfolder. This folder is only one layer deep. No need to continue to discover
     additional subfolders
     :param model_subfolder_type: type of the model subfolder
     :param location: context containing the current location information
     :param name_token: for use in the location to contain the folder name
     :return: dictionary containing the discovered folder attributes
     """
     _method_name = '_discover_artifical_folder'
     _logger.entering(model_subfolder_type,
                      str(location),
                      name_token,
                      class_name=_class_name,
                      method_name=_method_name)
     subfolder_result = OrderedDict()
     names = self._find_names_in_folder(location)
     if names is not None:
         for name in names:
             massaged = self._inspect_artificial_folder_name(name, location)
             location.add_name_token(name_token, massaged)
             artificial = self._get_artificial_type(location)
             if artificial is None:
                 if self._alias_helper.is_custom_folder_allowed(location):
                     _logger.fine('WLSDPLY-06148',
                                  model_subfolder_type,
                                  massaged,
                                  location.get_folder_path(),
                                  class_name=_class_name,
                                  method_name=_method_name)
                     subfolder_result.update(
                         self._custom_folder.discover_custom_mbean(
                             location, model_subfolder_type, massaged))
                 else:
                     _logger.warning(
                         'WLSDPLY-06123',
                         self._alias_helper.get_model_folder_path(location),
                         class_name=_class_name,
                         method_name=_method_name)
             else:
                 _logger.finer('WLSDPLY-06120',
                               artificial,
                               massaged,
                               model_subfolder_type,
                               class_name=_class_name,
                               method_name=_method_name)
                 location.append_location(artificial)
                 subfolder_result[massaged] = OrderedDict()
                 subfolder_result[massaged][artificial] = OrderedDict()
                 self._populate_model_parameters(
                     subfolder_result[massaged][artificial], location)
                 location.pop_location()
             location.remove_name_token(name_token)
     _logger.exiting(class_name=_class_name,
                     method_name=_method_name,
                     result=subfolder_result)
     return subfolder_result
 def __init__(self, args=None):
     self._args = args
     # Save OS environment variables into a Python dictionary
     self._env = os.environ
     self._oracle_homes = PyOrderedDict()
     self._java_homes = PyOrderedDict()
     self._required_versions = PyOrderedDict()
    def _process_multiple_folder(self, model_value, item_info, schema_path, model_path):
        """
        Process a multiple-element model section.
        There should be a dictionary of names, each containing a sub-folder.
        :param model_value: the model contents for a folder
        :param item_info: describes the contents of the sub-folder for each element
        :param schema_path: the path of schema elements (no multi-element names), used for supported check
        :param model_path: the path of model elements (including multi-element names), used for logging
        """
        child_list = list()
        for name in model_value:
            name_map = model_value[name]
            next_target_dict = PyOrderedDict()
            next_model_path = model_path + "/" + name
            self._process_folder(name_map, item_info, next_target_dict, schema_path, next_model_path)

            # see if the model name should become an attribute in the target dict
            mapped_name = get_mapped_key(schema_path)
            properties = wko_schema_helper.get_properties(item_info)
            if (mapped_name in properties.keys()) and (mapped_name not in next_target_dict.keys()):
                _add_to_top(next_target_dict, mapped_name, name)

            child_list.append(next_target_dict)

        return child_list
Esempio n. 4
0
    def get_eor_fields(self, metadata_path=None):
        """

        :return:
        """
        eor_fields = {}
        temp_dict = PyOrderedDict()
        iterators = [self._test_def_metadata_dict.iteritems()]
        while iterators:
            current_iterator = iterators.pop()
            for field_name, field_value in current_iterator:
                if TestDefMetadata.REQUIRED in field_value:
                    if TestDefMetadata.EOR_FIELDS in field_value:
                        temp_dict[field_name] = self._test_def_metadata_index[field_name]
                else:
                    iterators.append(current_iterator)
                    iterators.append(field_value.iteritems())

        if temp_dict:
            for key, value in temp_dict.iteritems():
                for metadata_path_token in value:
                    if metadata_path_token not in eor_fields:
                        eor_fields[metadata_path_token] = [key]
                    else:
                        eor_fields[metadata_path_token].append(key)

        if metadata_path is not None and metadata_path in eor_fields:
            eor_fields = {metadata_path: eor_fields[metadata_path]}

        return eor_fields
Esempio n. 5
0
    def discover_custom_mbean(self, base_location, model_type, mbean_name):
        """
        Discover the Custom MBean attributes using its MBeanInfo.
        :param base_location: the current context for the location
        :param model_type: The parent type of the custom MBean
        :param mbean_name: the name of the custom MBean instance
        :raises: BundleAwareException of the specified type: if an error occurs
        """
        _method_name = 'discover_custom_mbean'
        _logger.entering(base_location.get_folder_path(), model_type, mbean_name,
                         class_name=_class_name, method_name=_method_name)
        location = LocationContext(base_location)
        subfolder_result = PyOrderedDict()

        attribute_helper = self._info_helper.get_info_attribute_helper(location)
        if attribute_helper is None:
            _logger.warning('WLSDPLY-06753', model_type, str(attribute_helper), mbean_name,
                            class_name=_class_name, method_name=_method_name)
        else:
            subfolder_result[mbean_name] = PyOrderedDict()
            _logger.finer('WLSDPLY-06757', attribute_helper.mbean_string(),
                          class_name=_class_name, method_name=_method_name)
            short_name = attribute_helper.get_mbean_name()
            # This is not like other custom interface names and should be changed to be more flexible
            interface_name = security_provider_interface_name(attribute_helper.get_mbean_instance(),
                                                              attribute_helper.get_mbean_interface_name())
            subfolder_result[mbean_name][interface_name] = PyOrderedDict()
            _logger.info('WLSDPLY-06751', model_type, short_name, class_name=_class_name, method_name=_method_name)
            _logger.info('WLSDPLY-06752', mbean_name, model_type, short_name,
                         class_name=_class_name, method_name=_method_name)
            subfolder_result[mbean_name][interface_name] = self.get_model_attribute_map(location, attribute_helper)
        _logger.exiting(class_name=_class_name, method_name=_method_name)
        return subfolder_result
Esempio n. 6
0
 def inject_variables_keyword_dictionary(self, injector_file_list):
     """
     Takes a variable keyword dictionary and returns a variables for file in a dictionary
     :param injector_file_list: list of injector files for processing variable injection
     :return: variables_dictionary containing the variable properties to persist to the variable file
     """
     _method_name = 'inject_variables_keyword_dictionary'
     _logger.entering(injector_file_list,
                      class_name=_class_name,
                      method_name=_method_name)
     variable_dictionary = OrderedDict()
     for filename in injector_file_list:
         injector_dictionary = _load_injector_file(
             self._replace_tokens(filename))
         entries = self.inject_variables(injector_dictionary)
         if entries:
             _logger.finer('WLSDPLY-19513',
                           filename,
                           class_name=_class_name,
                           method_name=_method_name)
             variable_dictionary.update(entries)
     _logger.exiting(class_name=_class_name,
                     method_name=_method_name,
                     result=variable_dictionary)
     return variable_dictionary
    def testIteritems(self):
        my_ordered_dict = OrderedDict()
        my_ordered_dict['nba_player'] = 'Steph Curry'
        my_ordered_dict['nba_mvp_count'] = 1
        my_ordered_dict['is_retired'] = False
        my_ordered_dict['nba_finals_years'] = ['2015', '2016', '2017']

        result = isinstance(my_ordered_dict, dict)
        self.assertEqual(result, True,
                         'expected ordered dict to be an instance of dict')

        # A myOrderedDict.iteritems() needs to work like
        # a built-in Python dict

        expected_keys = [
            'nba_player', 'nba_mvp_count', 'is_retired', 'nba_finals_years'
        ]
        expected_values = ['Steph Curry', 1, False, ['2015', '2016', '2017']]

        index = 0
        for key, value in my_ordered_dict.iteritems():
            self.assertEqual(
                key, expected_keys[index],
                'expected key at position %s to be %s' %
                (str(index), expected_keys[index]))
            self.assertEqual(value, expected_values[index])
            index += 1
 def testOrderedDictDictUpdate(self):
     dict1 = OrderedDict()
     dict1['entry1'] = 'you'
     dict2 = dict()
     dict2['entry2'] = 'me'
     dict1.update(dict2)
     self.assertEqual(
         'entry1' in dict1 and 'entry2' in dict1, True,
         "expected ordereddict1 to contain 'entry1' and 'entry2' keys")
    def testKeys(self):
        my_ordered_dict = OrderedDict()
        my_ordered_dict['nba_player'] = 'Steph Curry'
        my_ordered_dict['nba_mvp_count'] = 1
        my_ordered_dict['is_retired'] = False
        my_ordered_dict['nba_finals_years'] = ['2015', '2016', '2017']

        expected = ['nba_player', 'nba_mvp_count', 'is_retired', 'nba_finals_years']
        keys = my_ordered_dict.keys()
        self.assertEqual(len(expected), len(keys),
                         'expected the ordered dict keys to be the same length as the expected keys')
        for i, key in enumerate(keys):
            self.assertEqual(key, expected[i], 'expected key at position %s to be %s' % (str(i), expected[i]))
    def testValues(self):
        my_ordered_dict = OrderedDict()
        my_ordered_dict['nba_player'] = 'Steph Curry'
        my_ordered_dict['nba_mvp_count'] = 1
        my_ordered_dict['is_retired'] = False
        my_ordered_dict['nba_finals_years'] = ['2015', '2016', '2017']

        expected_values = ['Steph Curry', 1, False, ['2015', '2016', '2017']]
        values = my_ordered_dict.values()
        self.assertEqual(len(expected_values), len(values),
                         'expected the ordered dict values to be the same length as the expected values')
        for i, value in enumerate(values):
            self.assertEqual(value, expected_values[i],
                             'expected value at position %s to be %s' % (str(i), str(expected_values[i])))
    def testCopyConstructorKeyOrdering(self):
        my_ordered_dict = OrderedDict()
        my_ordered_dict['one'] = 1
        my_ordered_dict['two'] = 2
        my_ordered_dict['five'] = 5
        my_ordered_dict['three'] = 3
        my_ordered_dict['four'] = 4

        copy_ordered_dict = OrderedDict(my_ordered_dict)

        # A myOrderedDict.keys() needs to return the keys, in the
        # exact order that they were inserted
        expected = ['one', 'two', 'five', 'three', 'four']
        copy_ordered_dict_keys = copy_ordered_dict.keys()
        for i in range(len(expected)):
            self.assertEqual(copy_ordered_dict_keys[i], expected[i])
Esempio n. 12
0
    def _process_fields(self, model_dict, folder_names, attributes_map,
                        location, target_dict):
        """
        Transfer folders and attributes from the model dictionary to the target domain resource dictionary.
        For the top level, the folders and attributes are not derived directly from the location.
        :param model_dict: the source model dictionary
        :param folder_names: the names of the folders at this location
        :param attributes_map: the map of attribute names to types for this location
        :param location: the location used for alias processing
        :param target_dict: the target dictionary for the domain resource file.
       """
        for key, model_value in model_dict.items():
            if key in attributes_map.keys():
                type_name = attributes_map[key]
                target_dict[key] = _get_target_value(model_value, type_name)

            elif key in folder_names:
                child_location = LocationContext(location).append_location(key)

                if self._aliases.supports_multiple_mbean_instances(
                        child_location):
                    target_dict[key] = self._build_dictionary_list(
                        key, model_value, child_location)
                else:
                    if key not in target_dict:
                        target_dict[key] = PyOrderedDict()
                    target_child_dict = target_dict[key]
                    self._process_location_fields(model_value, child_location,
                                                  target_child_dict)
        return
Esempio n. 13
0
    def __init__(self, test_def_file_name, test_def_metadata_file, logger):
        """

        :param test_def_file_name:
        :param test_def_metadata_file:
        :param logger:
        """
        _method_name = '__init__'

        self._test_def_file_name = test_def_file_name
        self._logger = logger

        # test_def_metadata_file will be a string object, if the
        # -test_def_metadata_file command line parameter was
        # not provided. In that case, we need to use the metadata
        # file inside the installer archive.
        use_archive = isinstance(test_def_metadata_file, str)

        if use_archive:
            self._logger.info('WLSDPLY-09850', test_def_metadata_file, class_name=_class_name, method_name=_method_name)
        else:
            self._logger.info('WLSDPLY-09851', test_def_metadata_file, class_name=_class_name, method_name=_method_name)

        self._test_def_metadata_dict = _load_test_def_metadata(test_def_metadata_file, self._logger, use_archive)
        self._logger.finer('self._test_def_metadata_dict={0}', str(self._test_def_metadata_dict),
                           class_name=_class_name, method_name=_method_name)
        self._test_def_metadata_index = self.__populate_test_def_metadata_index(self._test_def_metadata_dict,
                                                                                [], PyOrderedDict())
        self._logger.finer('self._test_def_metadata_index={0}', str(self._test_def_metadata_index),
                           class_name=_class_name, method_name=_method_name)
Esempio n. 14
0
    def _compare_properties(self, current_value, past_value, key,
                            change_folder):
        """
        Compare values of a properties attribute from the current and past folders.
        The change value and any comments will be added to the change folder.
        :param current_value: the value from the current model
        :param past_value: the value from the past model
        :param key: the key of the attribute
        :param change_folder: the folder in the change model to be updated
        """
        property_dict = PyOrderedDict()
        for property_key in current_value:
            current_property_value = current_value[property_key]
            if property_key in past_value:
                past_property_value = past_value[property_key]
                if past_property_value != current_property_value:
                    comment = property_key + ": '" + str(
                        past_property_value) + "'"
                    _add_comment(comment, property_dict)
                    property_dict[property_key] = current_property_value
            else:
                property_dict[property_key] = current_property_value

        # property values don't support delete notation,
        # so any deleted keys in the current value will be ignored.

        if property_dict:
            change_folder[key] = property_dict
Esempio n. 15
0
    def __init__(self, name, logger=None):
        self.name = name
        if logger is None:
            self._logger = _logger
        else:
            self._logger = logger

        self._excludes_dict = PyOrderedDict()
Esempio n. 16
0
    def inject_variables(self, injector_dictionary):
        """
        Iterate through the injector dictionary that was loaded from the file for the model
        injector file keyword.
        :param injector_dictionary:
        :return: variable dictionary containing the variable string and model value entries
        """
        variable_dict = OrderedDict()
        if injector_dictionary:
            location = LocationContext()
            domain_token = self.__aliases.get_name_token(location)
            location.add_name_token(domain_token, _fake_name_marker)
            for injector, injector_values in injector_dictionary.iteritems():
                entries_dict = self.__inject_variable(location, injector,
                                                      injector_values)
                if len(entries_dict) > 0:
                    variable_dict.update(entries_dict)

        return variable_dict
    def testOrderedDictSort(self):
        dict1 = OrderedDict()
        dict1['SecurityConfig.myrealm.IoT-IDCS-Authenticator.ClientSecretEncrypted'] = ''
        dict1['AdminUserName'] = ''
        dict1['ServerTemp.ms-template.SSL.ListenPort'] = '8100'
        dict1['AdminPassword'] = ''
        dict1['JDBC.IoTServerDS.user.Value'] = 'admin'
        dict1['SecurityConfig.CredentialEncrypted'] = ''
        dict1['JDBC.IoTServerDS.PasswordEncrypted'] = ''
        dict1['SecurityConfig.NodeManagerUsername'] = '******'

        sorted_dict = OrderedDict()
        sorted_keys = dict1.keys()
        sorted_keys.sort()
        for key in sorted_keys:
            sorted_dict[key] = dict1[key]

        self.assertEqual(sorted_dict.values()[-1], '8100',
                         'expected dictionary to be sorted by name')
Esempio n. 18
0
 def __init__(self, logger, args):
     self._logger = logger
     self.__raw_args = args
     self.__x_args = OrderedDict()
     self.__xx_args = OrderedDict()
     self.__sys_props = OrderedDict()
     self.__client_server_args = list()
     self.__unsorted_args = list()
     self.__parse_args()
     return
Esempio n. 19
0
    def _compare_named_folders(self, current_folder, past_folder, location,
                               attributes_location):
        """
        Compare current and past named folders using the specified locations.
        A named folder is a subfolder of a multiple-MBean folder, such as topology/Server/my-server
        :param current_folder: a folder in the current model
        :param past_folder: corresponding folder in the past model
        :param location: the location for the specified folders
        :param attributes_location: the attribute location for the specified folders
        :return: a dictionary of differences between these folders
        """
        change_folder = PyOrderedDict()

        for name in current_folder:
            # check if name is present in both folders.
            # if found, compare the two folders recursively.
            if name in past_folder:
                next_current = current_folder[name]
                next_past = past_folder[name]
                location.add_name_token(self._aliases.get_name_token(location),
                                        name)
                attributes_location.add_name_token(
                    self._aliases.get_name_token(attributes_location), name)
                changes = self._compare_folder_contents(
                    next_current, next_past, location, attributes_location)
                if changes:
                    change_folder[name] = changes

            # check for added names.
            # if found, add the entire folder contents.
            else:
                change_folder[name] = current_folder[name]
                pass

        # check for deleted names.
        # if name is not in the current folder, add its delete name.
        for name in past_folder:
            if name not in current_folder:
                delete_name = model_helper.get_delete_name(name)
                change_folder[delete_name] = PyOrderedDict()

        return change_folder
Esempio n. 20
0
    def __get_all_fields(self):
        all_fields = PyOrderedDict()
        iterators = [self._test_def_metadata_dict.iteritems()]
        while iterators:
            current_iterator = iterators.pop()
            for field_name, field_value in current_iterator:
                if TestDefMetadata.REQUIRED in field_value:
                    all_fields[field_name] = self._test_def_metadata_index[field_name]
                else:
                    iterators.append(current_iterator)
                    iterators.append(field_value.iteritems())

        return all_fields
Esempio n. 21
0
 def __init__(self, current_dict, past_dict):
     self.final_changed_model = PyOrderedDict()
     self.current_dict = current_dict
     self.past_dict = past_dict
     self.set_current = sets.Set()
     self.set_past = sets.Set()
     if self.current_dict and len(self.current_dict.keys()) > 0:
         for item in self.current_dict.keys():
             self.set_current.add(item)
     if self.past_dict and len(self.past_dict.keys()) > 0:
         for item in self.past_dict.keys():
             self.set_past.add(item)
     self.intersect = self.set_current.intersection(self.set_past)
Esempio n. 22
0
 def __init__(self, model_files, model_context, logger, output_dir=None):
     self.model_files = model_files
     self.output_dir = output_dir
     self.model_context = model_context
     self._aliases = Aliases(model_context=model_context,
                             wlst_mode=WlstModes.OFFLINE,
                             exception_type=ExceptionType.COMPARE)
     self._logger = logger
     self._name_tokens_location = LocationContext()
     self._name_tokens_location.add_name_token('DOMAIN', "testdomain")
     self.current_dict = None
     self.cache = OrderedDict()
     self.secrets_to_generate = sets.Set()
    def check_and_tokenize(self, model_dict, attribute, location):
        """
        If the specified attribute is a security credential, add it to the injector,
        and replace the value in the model dictionary with the token.
        :param model_dict: the model dictionary containing the attribute
        :param attribute: the name of the attribute
        :param location: the location of the attribute
        """
        aliases = self.get_aliases()
        attribute_type = aliases.get_model_attribute_type(location, attribute)
        folder_path = '.'.join(location.get_model_folders())
        model_value = model_dict[attribute]

        if attribute_type == CREDENTIAL:
            injector_commands = OrderedDict()
            injector_commands.update({VARIABLE_VALUE: model_value})
            self.custom_injection(model_dict, attribute, location,
                                  injector_commands)

        elif attribute_type == PASSWORD:
            # STANDARD_PASSWORD_INJECTOR provides an empty value for the mapping
            self.custom_injection(model_dict, attribute, location,
                                  STANDARD_PASSWORD_INJECTOR)

        elif folder_path.endswith(self.JDBC_PROPERTIES_PATH):
            token = aliases.get_name_token(location)
            property_name = location.get_name_for_token(token)
            if (property_name == DRIVER_PARAMS_USER_PROPERTY) and (
                    attribute == DRIVER_PARAMS_PROPERTY_VALUE):
                injector_commands = OrderedDict()
                injector_commands.update({VARIABLE_VALUE: model_value})
                self.custom_injection(model_dict, attribute, location,
                                      injector_commands)

        elif folder_path.endswith(MAIL_SESSION) and (attribute == PROPERTIES):
            # users and passwords are property assignments
            value = model_dict[attribute]
            is_string = isinstance(value, str)

            # for discover, value is a string at this point
            if is_string:
                model_dict[attribute] = OrderedDict()
                split = value.split(';')
                for assign in split:
                    halves = assign.split('=')
                    model_dict[attribute][halves[0]] = halves[1]

            self.custom_injection(model_dict, attribute, location,
                                  self.USER_COMMANDS)
            self.custom_injection(model_dict, attribute, location,
                                  self.PASSWORD_COMMANDS)

            if is_string:
                properties = model_dict[attribute]
                assigns = []
                for key in properties:
                    assigns.append('%s=%s' % (key, properties[key]))
                model_dict[attribute] = ';'.join(assigns)
def _add_to_top(dictionary, key, item):
    """
    Add an item to the beginning of an ordered dictionary.
    :param dictionary: the dictionary
    :param key: the key of the item to be added
    :param item: the item to be added
    """
    temp_dict = PyOrderedDict()
    for each_key in dictionary:
        temp_dict[each_key] = dictionary[each_key]
    dictionary.clear()
    dictionary[key] = item
    for each_key in temp_dict:
        dictionary[each_key] = temp_dict[each_key]
    def _create_domain_resource_dictionary(self):
        """
        Build the resource file structure from the kubernetes section of the model.
        :return: the resource file structure
        """
        kubernetes_map = self._model.get_model_kubernetes()

        resource_dict = PyOrderedDict()

        schema = wko_schema_helper.get_domain_resource_schema(ExceptionType.DEPLOY)

        model_path = KUBERNETES + ":"
        self._process_folder(kubernetes_map, schema, resource_dict, None, model_path)
        return resource_dict
Esempio n. 26
0
    def _process_folder(self, model_dict, schema_folder, target_dict,
                        schema_path, model_path):
        """
        Transfer folders and attributes from the model dictionary to the target domain resource dictionary.
        :param model_dict: the source model dictionary
        :param schema_folder: the schema for this folder
        :param target_dict: the target dictionary for the domain resource file.
        :param schema_path: the path of schema elements (no multi-element names), used for supported check
        :param model_path: the path of model elements (including multi-element names), used for logging
        """
        folder_properties = schema_folder["properties"]

        for key, model_value in model_dict.items():
            properties = folder_properties[key]

            if wko_schema_helper.is_single_folder(properties):
                # single object instance
                next_schema_path = wko_schema_helper.append_path(
                    schema_path, key)
                next_model_path = model_path + "/" + key
                if not wko_schema_helper.is_unsupported_folder(
                        next_schema_path):
                    next_target_dict = PyOrderedDict()
                    target_dict[key] = next_target_dict
                    self._process_folder(model_value, properties,
                                         next_target_dict, next_schema_path,
                                         next_model_path)

            elif wko_schema_helper.is_multiple_folder(properties):
                # multiple object instances
                next_schema_path = wko_schema_helper.append_path(
                    schema_path, key)
                next_model_path = model_path + "/" + key
                if not wko_schema_helper.is_unsupported_folder(
                        next_schema_path):
                    item_info = wko_schema_helper.get_array_item_info(
                        properties)
                    target_dict[key] = \
                        self._process_multiple_folder(model_value, item_info, next_schema_path, next_model_path)

            elif wko_schema_helper.is_simple_map(properties):
                # map of key / value pairs
                target_dict[key] = model_value

            else:
                # simple type or array of simple type, such as number, string
                property_type = wko_schema_helper.get_type(properties)
                target_dict[key] = _get_target_value(model_value,
                                                     property_type)
Esempio n. 27
0
    def _create_domain_resource_dictionary(self):
        """
        Build the resource file structure from the kubernetes section of the model.
        :return: the resource file structure
        """
        kubernetes_map = self._model.get_model_kubernetes()

        resource_dict = PyOrderedDict()

        attribute_location = self._aliases.get_model_section_attribute_location(KUBERNETES)
        top_attributes_map = self._aliases.get_model_attribute_names_and_types(attribute_location)
        top_folders = self._aliases.get_model_section_top_level_folder_names(KUBERNETES)

        self._process_fields(kubernetes_map, top_folders, top_attributes_map, LocationContext(), resource_dict)
        return resource_dict
Esempio n. 28
0
 def _build_dictionary_list(self, model_key, name_dictionary, location):
     """
     Build a dictionary list object based on the name dictionary and location.
     :param name_dictionary: a dictionary containing named levels
     :param location: the location used for alias resolution
     :return:
     """
     child_list = DictionaryList()
     for name in name_dictionary:
         model_named_dict = name_dictionary[name]
         name_key = self._get_name_key(model_key)
         target_list_dict = PyOrderedDict()
         target_list_dict[name_key] = name
         self._process_location_fields(model_named_dict, location, target_list_dict)
         child_list.append(target_list_dict)
     return child_list
Esempio n. 29
0
    def get_model_attribute_map(self, location, attribute_helper):
        """
        Return a map of the MBean's attributes, in model format, which do not have default values.
        :param location: location context for the current MBean
        :param attribute_helper: context for the current MBean
        :return: model ready dictionary of the discovered MBean
        """
        _method_name = 'get_model_attribute_map'
        _logger.entering(str(attribute_helper), class_name=_class_name, method_name=_method_name)
        mbean_attributes = PyOrderedDict()
        for attribute_name in attribute_helper.get_mbean_attributes():
            model_value = self.get_model_attribute_value(attribute_helper, attribute_name)
            if model_value is not None:
                mbean_attributes[attribute_name] = model_value
                self.__inject_token(location, mbean_attributes, attribute_name)

        _logger.exiting(class_name=_class_name, method_name=_method_name)
        return mbean_attributes
Esempio n. 30
0
def create_dictionary(value):
    """
    Convert the value that is a dict, properties or map type to a python dictionary.
    :param value: value to be converted to python dictionary
    :return: python dictionary of key, value from original type
    """
    my_dict = PyOrderedDict()
    if not is_empty(value):
        if isinstance(value, dict) or isinstance(value, PyOrderedDict):
            for key, item in value.items():
                my_dict[key] = item
        elif isinstance(value, Properties):
            for key in value.stringPropertyNames():
                my_dict[key] = value.getProperty(key)
        elif isinstance(value, Map):
            for result in value.entrySet():
                my_dict[result.getKey()] = result.getValue()
    return my_dict