def _is_dual_password(attribute_info):
    """
    Returns true if the specified attribute information indicates a dual-password field.
    This means the WLST type is password, and the WLST name ends with "Encrypted".
    :param attribute_info: the attribute information to be checked
    :return: True if this is a dual-password field, False otherwise
    """
    wlst_name = dictionary_utils.get_element(attribute_info,
                                             WLST_NAME)  # type: str
    wlst_type = dictionary_utils.get_element(attribute_info, WLST_TYPE)
    return (wlst_type
            == 'password') and wlst_name.endswith(_dual_password_suffix)
Exemple #2
0
    def _add_jndi_properties(self, property_name_nodes, location):
        """
        Add each property entry from property nodes and set its attributes.
        A two-pass approach is required since the new folder's name does not always match the property name.
        :param property_name_nodes: the nodes containing property names
        :param location: the WLST location where the properties should be added
        """
        _method_name = '_add_jndi_properties'
        if len(property_name_nodes) == 0:
            return

        parent_type, parent_name = self.get_location_type_and_name(location)
        is_online = self.wlst_mode == WlstModes.ONLINE
        if is_online and deployer_utils.is_in_resource_group_or_template(location):
            self.logger.info('WLSDPLY-09501', JNDI_PROPERTY, parent_type, parent_name, class_name=self._class_name,
                             method_name=_method_name)
            return

        foreign_server_path = self.alias_helper.get_wlst_subfolders_path(location)
        properties_location = LocationContext(location).append_location(JNDI_PROPERTY)
        properties_token = self.alias_helper.get_name_token(properties_location)
        name_attribute = self.alias_helper.get_wlst_attribute_name(properties_location, KEY)
        mbean_type = self.alias_helper.get_wlst_mbean_type(properties_location)

        # loop once to create and name any missing folders.
        folder_map = self._build_folder_map(properties_location, properties_token, name_attribute)

        for property_name in property_name_nodes:
            folder_name = dictionary_utils.get_element(folder_map, property_name)
            if folder_name is None:
                self.wlst_helper.cd(foreign_server_path)
                new_property = self.wlst_helper.create(property_name, mbean_type)
                new_property.setKey(property_name)

        # loop a second time to set attributes
        new_folder_map = self._build_folder_map(properties_location, properties_token, name_attribute)

        for property_name in property_name_nodes:
            is_add = property_name not in folder_map
            log_helper.log_updating_named_folder(JNDI_PROPERTY, property_name, parent_type, parent_name, is_add,
                                                 self._class_name, _method_name)

            folder_name = dictionary_utils.get_element(new_folder_map, property_name)
            properties_location.add_name_token(properties_token, folder_name)
            self.wlst_helper.cd(self.alias_helper.get_wlst_attributes_path(properties_location))

            property_nodes = property_name_nodes[property_name]
            self.set_attributes(properties_location, property_nodes)
def _write_block(key, lines, template_hash, file_writer):
    """
    Write a block of lines to the file writer, making substitutions as necessary.
    This method does not currently handle nested blocks.
    :param key: the key of this block
    :param lines: the lines to be output
    :param template_hash: the parent hash
    :param file_writer: to write the output
    """
    value = dictionary_utils.get_element(template_hash, key)

    # skip block for value of False, None, or empty collection
    if not value:
        return

    # if value is not a list, make it a list with one item
    if not isinstance(value, list):
        value = [value]

    for list_element in value:
        for line in lines:
            # this does not account for nested blocks

            if isinstance(list_element, dict):
                line = _substitute_line(line, list_element)
            file_writer.write(line + "\n")
def __process_args(args):
    """
    Process the command-line arguments and prompt the user for any missing information
    :param args: the command-line arguments list
    :raises CLAException: if an error occurs while validating and processing the command-line arguments
    """
    global __wlst_mode

    cla_util = CommandLineArgUtil(_program_name, __required_arguments,
                                  __optional_arguments)
    required_arg_map, optional_arg_map = cla_util.process_args(args)

    domain_type = dictionary_utils.get_element(
        optional_arg_map, CommandLineArgUtil.DOMAIN_TYPE_SWITCH)
    if domain_type is None:
        domain_type = 'WLS'
    domain_typedef = DomainTypedef(_program_name, domain_type)
    optional_arg_map[CommandLineArgUtil.DOMAIN_TYPEDEF] = domain_typedef

    __verify_required_args_present(required_arg_map)
    __wlst_mode = __process_online_args(optional_arg_map)
    __process_archive_filename_arg(required_arg_map)
    __process_variable_filename_arg(optional_arg_map)

    combined_arg_map = optional_arg_map.copy()
    combined_arg_map.update(required_arg_map)

    return ModelContext(_program_name, combined_arg_map)
    def get_variable_file(self):
        if self._variable_file is None:
            variable_file_name = dictionary_utils.get_element(self._settings_id_dict,
                                                              TestDefSettings.VARIABLE_FILE)
            self._variable_file = testing_helper.verify_file_exists(variable_file_name, self._logger)

        return self._variable_file
Exemple #6
0
    def _finalize_folder(self, current_folder, past_folder, change_folder,
                         location):
        """
        Perform any adjustments after a folder has been evaluated.
        :param current_folder: folder in the current model
        :param past_folder: corresponding folder in the past model
        :param change_folder: the folder with the changed attributes and sub-folders
        :param location: the location for the specified folders
        """
        _method_name = '_finalize_folder'

        folder_path = []
        if location is not None:
            folder_path = location.get_model_folders()

        # Application and Library should include SourcePath if they have any other elements
        if (len(folder_path) == 1) and (folder_path[0]
                                        in self.SOURCE_PATH_FOLDERS):
            if change_folder and (SOURCE_PATH not in change_folder):
                # if SourcePath not present, past and current folder had matching values
                source_path = dictionary_utils.get_element(
                    current_folder, SOURCE_PATH)
                if source_path is not None:
                    comment = exception_helper.get_message(
                        'WLSDPLY-05714', SOURCE_PATH)
                    _add_comment(comment, change_folder)
                    change_folder[SOURCE_PATH] = source_path
 def get_wls_credentials_name(self):
     """
     Returns the method for handling credentials in the model.
     :return: the method for handling credentials
     """
     return dictionary_utils.get_element(self.config_dictionary,
                                         WLS_CREDENTIALS_NAME)
def process_target_arguments(argument_map):
    """
    If the -target option is in the argument map, verify that -output_dir is specified.
    If variables_file was not specified, add it with the file <outputDir>/<targetName>_variable.properties .
    :param argument_map: the argument map to be checked and possibly modified
    """
    _method_name = 'process_target_arguments'

    if CommandLineArgUtil.TARGET_SWITCH in argument_map:
        target_name = argument_map[CommandLineArgUtil.TARGET_SWITCH]

        # if -target is specified -output_dir is required
        output_dir = dictionary_utils.get_element(
            argument_map, CommandLineArgUtil.OUTPUT_DIR_SWITCH)
        if (output_dir is None) or (not os.path.isdir(output_dir)):
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-01642', CommandLineArgUtil.OUTPUT_DIR_SWITCH,
                CommandLineArgUtil.TARGET_SWITCH, target_name)
            __logger.throwing(ex,
                              class_name=__class_name,
                              method_name=_method_name)
            raise ex

        # Set the -variable_file parameter if not present with default
        if CommandLineArgUtil.VARIABLE_FILE_SWITCH not in argument_map:
            path = os.path.join(output_dir,
                                target_name + "_variable.properties")
            argument_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = path
 def get_validation_method(self):
     """
     Return the validation method for this target environment.
     :return: the validation method, or None
     """
     return dictionary_utils.get_element(self.config_dictionary,
                                         'validation_method')
Exemple #10
0
    def _set_mbean_attribute(self, location, model_key, model_value, set_method_map):
        """
        Set the attributes for the MBean that require an MBean value to set at the specified location.
        :param location: the location
        :param model_key: the model attribute name
        :param model_value: the model attribute value
        :param set_method_map: the set method map that maps the attribute names requiring MBean
                               values to the attribute setter method name
        :raises: CreateException: if an error occurs
        """
        _method_name = '_set_mbean_attribute'

        set_method_info = dictionary_utils.get_dictionary_element(set_method_map, model_key)
        set_method_name = dictionary_utils.get_element(set_method_info, 'set_method')

        if set_method_name is not None:
            try:
                self.logger.finest('WLSDPLY-12114', model_key, model_value, set_method_name,
                                   class_name=self.__class_name, method_name=_method_name)
                set_method = getattr(self.attribute_setter, set_method_name)
                set_method(location, model_key, model_value, None)
            except AttributeError, ae:
                ex = exception_helper.create_create_exception('WLSDPLY-12104', set_method_name, model_key,
                                                              self.alias_helper.get_model_folder_path(location),
                                                              error=ae)
                self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
                raise ex
def find_user_name(property_name, model_dictionary):
    """
    Determine the user name associated with the specified property name.
    Return None if the property name is not part of a paired secret with .username and .password .
    Return <user> if the property name is paired, but user is not found.
    Currently only supports user for JDBC.[name].PasswordEncrypted
    Needs a much better implementation for future expansion.
    :param property_name: the property name, such as JDBC.Generic2.PasswordEncrypted
    :param model_dictionary: for looking up the user name
    :return: the matching user name, a substitution string, or None
    """
    matches = _jdbc_pattern.findall(property_name)
    if matches:
        name = matches[0]
        resources = dictionary_utils.get_dictionary_element(
            model_dictionary, RESOURCES)
        system_resources = dictionary_utils.get_dictionary_element(
            resources, JDBC_SYSTEM_RESOURCE)
        datasource = dictionary_utils.get_dictionary_element(
            system_resources, name)
        jdbc_resources = dictionary_utils.get_dictionary_element(
            datasource, JDBC_RESOURCE)
        driver_params = dictionary_utils.get_dictionary_element(
            jdbc_resources, JDBC_DRIVER_PARAMS)
        properties = dictionary_utils.get_dictionary_element(
            driver_params, PROPERTIES)
        user = dictionary_utils.get_dictionary_element(properties, "user")
        value = dictionary_utils.get_element(user, "Value")
        if value is None:
            return "<user>"
        else:
            return value

    return None
Exemple #12
0
    def _configure_handler(self, handler_name, handler, document, existing_names, config_location):
        """
        Configure the specified handler in the document.
        The handler will be added if it is not currently in the document.
        :param handler_name: the name of the handler to be configured
        :param handler: the dictionary of the handler to be configured
        :param document: the document to be updated
        :param existing_names: the names of existing handlers
        :param config_location: the location of ODL configuration in the model
        """
        _method_name = '_configure_handler'

        handler_location = LocationContext(config_location).append_location(_HANDLER)
        token = self.alias_helper.get_name_token(handler_location)
        handler_location.add_name_token(token, handler_name)
        handler_path = self.alias_helper.get_model_folder_path(handler_location)

        handler_class = dictionary_utils.get_element(handler, _CLASS)

        if handler_name not in existing_names:
            # new handlers must have a class specified.
            # we can't determine if a handler is new or existing during validation.
            if handler_class is None:
                self.logger.severe('WLSDPLY-19701', handler_name, handler_path,
                                   class_name=self.__class_name, method_name=_method_name)
                return
            try:
                document.addHandler(handler_name, str(handler_class))
            except IllegalArgumentException, iae:
                self.logger.severe('WLSDPLY-19702', handler_name, handler_path, iae.getLocalizedMessage(),
                                   class_name=self.__class_name, method_name=_method_name)
 def get_credentials_method(self):
     """
     Returns the method for handling credentials in the model.
     :return: the method for handling credentials
     """
     return dictionary_utils.get_element(self.config_dictionary,
                                         CREDENTIALS_METHOD)
Exemple #14
0
def __process_model_args(argument_map):
    """
    Determine if the model file was passed separately or requires extraction from the archive.
    :param argument_map: the arguments map
    :raises CLAException: if the arguments were not valid or an error occurred extracting the model from the archive
    """
    _method_name = '__process_model_args'

    cla_helper.validate_optional_archive(_program_name, argument_map)

    try:
        cla_helper.validate_model_present(_program_name, argument_map)
    except CLAException, ce:
        # in lax validation mode, if no model is found, log at INFO and exit
        method = dictionary_utils.get_element(
            argument_map, CommandLineArgUtil.VALIDATION_METHOD)
        if method == CommandLineArgUtil.LAX_VALIDATION_METHOD:
            __logger.info('WLSDPLY-20032',
                          _program_name,
                          class_name=_class_name,
                          method_name=_method_name)
            model_context = model_context_helper.create_exit_context(
                _program_name)
            tool_exit.end(model_context, CommandLineArgUtil.PROG_OK_EXIT_CODE)
        raise ce
    def _get_clusters_and_members_map(self):
        """
        Get a map keyed by cluster name with values that are a list of member server names
        :return: the cluster name to member server names map
        :raises: BundleAwareException of the specified type: is an error occurs reading from the aliases or WLST
        """
        _method_name = '_get_clusters_and_members_map'

        self.logger.entering(class_name=self.__class_name,
                             method_name=_method_name)
        server_location = LocationContext().append_location(SERVER)
        server_list_path = self.aliases.get_wlst_list_path(server_location)
        server_names = self.wlst_helper.get_existing_object_list(
            server_list_path)
        server_token = self.aliases.get_name_token(server_location)
        cluster_map = OrderedDict()
        for server_name in server_names:
            server_location.add_name_token(server_token, server_name)
            server_attributes_path = self.aliases.get_wlst_attributes_path(
                server_location)
            self.wlst_helper.cd(server_attributes_path)

            server_attributes_map = self.wlst_helper.lsa()
            cluster_name = dictionary_utils.get_element(
                server_attributes_map, CLUSTER)
            if string_utils.is_empty(cluster_name):
                # if server is not part of a cluster, continue with the next server
                continue

            if cluster_name not in cluster_map:
                cluster_map[cluster_name] = list()
            cluster_map[cluster_name].append(server_name)

        clusters_location = LocationContext().append_location(CLUSTER)
        cluster_list_path = self.aliases.get_wlst_list_path(clusters_location)
        cluster_names = self.wlst_helper.get_existing_object_list(
            cluster_list_path)
        cluster_token = self.aliases.get_name_token(clusters_location)
        # Add the cluster with dynamic servers, if not already in the cluster member list.
        # A cluster may contain both dynamic and configured servers (referred to as mixed cluster).
        # Add a token marking DYNAMIC SERVERS in the member list.
        for cluster_name in cluster_names:
            cluster_location = LocationContext(clusters_location)
            cluster_location.add_name_token(cluster_token, cluster_name)
            cluster_attributes_path = self.aliases.get_wlst_attributes_path(
                cluster_location)
            self.wlst_helper.cd(cluster_attributes_path)
            cluster_location.append_location(DYNAMIC_SERVERS)
            wlst_subfolder_name = self.aliases.get_wlst_mbean_type(
                cluster_location)
            if self.wlst_helper.subfolder_exists(wlst_subfolder_name):
                if cluster_name not in cluster_map:
                    cluster_map[cluster_name] = list()
                cluster_map[cluster_name].append(DYNAMIC_SERVERS)

        self.logger.exiting(class_name=self.__class_name,
                            method_name=_method_name,
                            result=cluster_map)
        return cluster_map
Exemple #16
0
    def _add_group_params(self, group_name_nodes, location):
        """
        Add each group param entry from group name nodes and set its attributes.
        A two-pass approach is required since the new folder's name does not always match the group name.
        Special processing for error destination attributes (build mbean)
        :param group_name_nodes: the nodes containing group parameter names
        :param location: the WLST location where the parameters should be added
        """
        _method_name = '_add_group_params'
        if len(group_name_nodes) == 0:
            return

        parent_type, parent_name = self.get_location_type_and_name(location)
        template_path = self.alias_helper.get_wlst_subfolders_path(location)
        groups_location = LocationContext(location)
        groups_location.append_location(GROUP_PARAMS)
        groups_token = self.alias_helper.get_name_token(groups_location)
        name_attribute = self.alias_helper.get_wlst_attribute_name(groups_location, SUB_DEPLOYMENT_NAME)
        mbean_type = self.alias_helper.get_wlst_mbean_type(groups_location)

        # loop once to create and name any missing folders.
        folder_map = self._build_folder_map(groups_location, groups_token, name_attribute)

        for group_name in group_name_nodes:
            sub_deployment_name = self._get_subdeployment_name(group_name_nodes, group_name)
            folder_name = dictionary_utils.get_element(folder_map, sub_deployment_name)
            if folder_name is None:
                self.wlst_helper.cd(template_path)
                group = self.wlst_helper.create(sub_deployment_name, mbean_type)
                group.setSubDeploymentName(sub_deployment_name)

        # loop a second time to set attributes
        new_folder_map = self._build_folder_map(groups_location, groups_token, name_attribute)

        for group_name in group_name_nodes:
            sub_deployment_name = self._get_subdeployment_name(group_name_nodes, group_name)
            is_add = sub_deployment_name not in folder_map
            log_helper.log_updating_named_folder(GROUP_PARAMS, group_name, parent_type, parent_name, is_add,
                                                 self._class_name, _method_name)

            folder_name = dictionary_utils.get_element(new_folder_map, sub_deployment_name)
            groups_location.add_name_token(groups_token, folder_name)
            self.wlst_helper.cd(self.alias_helper.get_wlst_attributes_path(groups_location))

            group_nodes = group_name_nodes[group_name]
            self.set_attributes(groups_location, group_nodes)
 def get_additional_output_types(self):
     """
     Return the additional output types for this target environment.
     This is a list of keys that map to output types.
     """
     types = dictionary_utils.get_element(self.config_dictionary, 'additional_output')
     if types is not None:
         return types.split(',')
     return []
Exemple #18
0
def _apply_filter(model, the_filter):
    """
    Apply the specified filter to the specified model.
    :param model: the model to be filtered
    :param filter: a dictionary containing the filter parameters
    :return: True if the specified filter was applied, False otherwise
    :raises: BundleAwareException of the specified type: if an error occurs
    """
    _method_name = '_apply_filter'
    id = dictionary_utils.get_element(the_filter, 'id')
    if id is not None:
        return _apply_id_filter(model, id)

    path = dictionary_utils.get_element(the_filter, 'path')
    if path is not None:
        return _apply_path_filter(model, path)

    __logger.severe('WLSDPLY-20019', str(__filter_file_location), class_name=__class_name, method_name=_method_name)
    return False
Exemple #19
0
 def _get_name_key(self, key):
     """
     Return the key to be used for the name in a dictionary list element.
     :param key: the folder key in the model
     :return: the name key
     """
     key = dictionary_utils.get_element(self.NAME_KEY_MAP, key)
     if key is not None:
         return key
     return 'name'
 def get_additional_secrets(self):
     """
     Return a list of secrets to be included in the create secrets script.
     :return: a list of secrets
     """
     secrets = dictionary_utils.get_element(self.config_dictionary,
                                            'additional_secrets')
     if secrets is not None:
         return secrets.split(',')
     return []
Exemple #21
0
    def get_env_var_value(self, env_var_alias):
        env_var_value = None
        env_var_name = dictionary_utils.get_element(self._env_vars_dict, env_var_alias)
        if env_var_name is None:
            metadata_path = '%s/%s' % (testing_constants.ENV_VARS, env_var_alias)
            env_var_name = self._test_def_metadata.get_default_value(metadata_path)

        if env_var_name is not None and env_var_name in os.environ:
            env_var_value = os.environ[env_var_name]
        return env_var_value
def _get_non_encrypted_wlst_name(attribute_info):
    """
    Returns the prefix portion of the WLST name from the specified attribute information.
    It is assumed that the attribute information is confirmed to be dual-password.
    :param attribute_info: the attribute information to be checked
    :return: the prefix portion of the WLST name
    """
    wlst_name = dictionary_utils.get_element(attribute_info,
                                             WLST_NAME)  # type: str
    return wlst_name[0:-len(_dual_password_suffix)]
def get_server_count(cluster_name, cluster_values, model_dictionary, aliases):
    """
    Determine the number of servers associated with a cluster.
    :param cluster_name: the name of the cluster
    :param cluster_values: the value map for the cluster
    :param model_dictionary: the model dictionary
    :param aliases: aliases instance for validation
    :return: the number of servers
    """
    if DYNAMIC_SERVERS in cluster_values:
        # for dynamic clusters, return the value of DynamicClusterSize
        dynamic_servers_dict = cluster_values[DYNAMIC_SERVERS]
        location = LocationContext()
        location.append_location(CLUSTER)
        location.add_name_token(aliases.get_name_token(location), 'cluster')
        location.append_location(DYNAMIC_SERVERS)
        location.add_name_token(aliases.get_name_token(location), 'server')
        present, __ = aliases.is_valid_model_attribute_name(
            location, DYNAMIC_CLUSTER_SIZE)
        if present == ValidationCodes.VALID:
            cluster_size_value = dictionary_utils.get_element(
                dynamic_servers_dict, DYNAMIC_CLUSTER_SIZE)
        else:
            cluster_size_value = dictionary_utils.get_element(
                dynamic_servers_dict, MAX_DYNAMIC_SERVER_COUNT)
        if cluster_size_value is not None:
            return alias_utils.convert_to_type('integer', cluster_size_value)
    else:
        # for other clusters, return the number of servers assigned to this cluster
        count = 0
        topology = dictionary_utils.get_dictionary_element(
            model_dictionary, TOPOLOGY)
        servers = dictionary_utils.get_dictionary_element(topology, SERVER)
        for server_name, server_value in servers.items():
            server_cluster = dictionary_utils.get_element(
                server_value, CLUSTER)
            if str(server_cluster) == cluster_name:
                count = count + 1
        return count

    return 0
 def _get_subdeployment_name(self, group_nodes, group_name):
     """
     Returns the derived sub-deployment name for the specified group name.
     The sub-deployment name attribute is returned if specified, otherwise the group name is returned.
     :param group_nodes: the group nodes from the model
     :param group_name: the group name being examined
     :return: the derived sub-deployment name
     """
     sub_deployment_name = dictionary_utils.get_element(group_nodes, SUB_DEPLOYMENT_NAME)
     if sub_deployment_name is not None:
         return sub_deployment_name
     return group_name
 def _check_destination_template(self, destination_nodes, location):
     """
     Check the destination nodes for a template element, and create a placeholder template if required.
     :param destination_nodes: the destination nodes to be examined
     :param location: the location of the destination parent
     """
     for name in destination_nodes:
         child_nodes = dictionary_utils.get_dictionary_element(destination_nodes, name)
         template_name = dictionary_utils.get_element(child_nodes, TEMPLATE)
         if template_name is not None:
             self._create_placeholder_jms_template(template_name, location)
     return
def create_typedef(program_name, argument_map):
    """
    Create a domain typedef object for use with a model context.
    :param program_name: the program name, used for logging
    :param argument_map: the argument map that may contain a domain type
    :return: a typedef object
    """
    domain_type = dictionary_utils.get_element(
        argument_map, CommandLineArgUtil.DOMAIN_TYPE_SWITCH)
    if domain_type is None:
        domain_type = 'WLS'
    return DomainTypedef(program_name, domain_type)
Exemple #27
0
    def _get_server_group_targeting_limits(self, server_group_targeting_limits,
                                           clusters_map):
        """
        Get any server group targeting limits specified in the model, converting any cluster
        names to the list of members.  This method assumes that the limits dictionary is not
        None or empty.
        :param server_group_targeting_limits: the raw server group targeting_limits from the model
        :param clusters_map: the map of cluster names to member server names
        :return: the map of server groups to server names to target
        """
        _method_name = '_get_server_group_targeting_limits'

        self.logger.entering(str(server_group_targeting_limits),
                             str(clusters_map),
                             class_name=self.__class_name,
                             method_name=_method_name)
        sg_targeting_limits = copy.deepcopy(server_group_targeting_limits)
        for server_group_name, sg_targeting_limit in sg_targeting_limits.iteritems(
        ):
            if type(sg_targeting_limit) is str:
                if MODEL_LIST_DELIMITER in sg_targeting_limit:
                    sg_targeting_limit = sg_targeting_limit.split(
                        MODEL_LIST_DELIMITER)
                else:
                    # convert a single value into a list of one...
                    new_list = list()
                    new_list.append(sg_targeting_limit)
                    sg_targeting_limit = new_list

            # Convert any references to a cluster name into the list of member server names
            new_list = list()
            for target_name in sg_targeting_limit:
                target_name = target_name.strip()
                if target_name in clusters_map:
                    cluster_members = dictionary_utils.get_element(
                        clusters_map, target_name)
                    if DYNAMIC_SERVERS in cluster_members:
                        # This will need special handling to target server group resources
                        cluster_members.remove(DYNAMIC_SERVERS)
                        cluster_members.add(target_name)
                    new_list.extend(cluster_members)
                else:
                    # Assume it is a server name and add it to the new list
                    # Stand-alone Managed Servers were not added to the cluster: server_name_list map
                    # which was built from the existing servers and clusters.
                    new_list.append(target_name)
            sg_targeting_limits[server_group_name] = new_list

        self.logger.exiting(class_name=self.__class_name,
                            method_name=_method_name,
                            result=sg_targeting_limits)
        return sg_targeting_limits
def _substitute_line(line, template_hash):
    """
    Substitute any tokens in the specified line with values from the template hash.
    :param line: the line to be evaluated
    :param template_hash: a map of keys and values
    :return: the revised line
    """
    matches = _substitution_pattern.findall(line)
    for token, value in matches:
        replacement = dictionary_utils.get_element(template_hash, value)
        if replacement is not None:
            line = line.replace(token, replacement)
    return line
def get_mapped_key(schema_path):
    """
    Because the WDT model does not support hyphenated lists, the name of each item in a
    multiple folder sometimes corresponds to one of its attributes, usually "name".
    If a different attribute name is used for the path, return that name.
    If the default 'name' is returned, caller should verify that it is an available attribute.
    :param schema_path: the slash-delimited path of the elements (no multi-element names)
    :return: the attribute key to be used
    """
    mapped_key = dictionary_utils.get_element(MULTI_KEYS, schema_path)
    if mapped_key is not None:
        return mapped_key
    return 'name'
    def _build_resource_name(self, mapping_type, mapping_name, mapping):
        """
        Build the resource name based on elements in the mapping element from the model.
        Example: type=<remote>, protocol=http, remoteHost=my.host, remotePort=7020, path=/myapp, method=POST
        :param mapping_type: the type of the mapping, such as 'CrossDomain'
        :param mapping_name: the mapping name from the model, such as 'map1'
        :param mapping: the mapping element from the model
        :return: the resource name
        """

        # for cross-domain mapping, use domain for remote host, and set cross-domain protocol
        if mapping_type == CROSS_DOMAIN:
            remote_host = self._get_required_attribute(mapping, REMOTE_DOMAIN,
                                                       mapping_type,
                                                       mapping_name)
            protocol = CROSS_DOMAIN_PROTOCOL
        else:
            remote_host = self._get_required_attribute(mapping, REMOTE_HOST,
                                                       mapping_type,
                                                       mapping_name)
            protocol = dictionary_utils.get_element(mapping, PROTOCOL)

        # build a map of available values, some may be None
        resource_name_values = {
            ID_METHOD: dictionary_utils.get_element(mapping, METHOD),
            ID_PATH: dictionary_utils.get_element(mapping, PATH),
            ID_PROTOCOL: protocol,
            ID_REMOTE_HOST: remote_host,
            ID_REMOTE_PORT: dictionary_utils.get_element(mapping, REMOTE_PORT)
        }

        # build the resource name string
        resource_name = 'type=<remote>'
        for field in RESOURCE_FIELDS:
            value = dictionary_utils.get_element(resource_name_values, field)
            if value is not None:
                resource_name += ', %s=%s' % (field, value)

        return resource_name