def run(ObjectList, CurrVal, Iteration, TagList, IgnoreEmptyTags):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogInfo("IteratorConfigRotateTrafficMixWeightsCommand.run()")

    count = int(CurrVal)

    tml = dm_utils.process_inputs_for_objects(ObjectList, TagList, "StmTrafficMix")
    for tm in tml:
        e = etree.fromstring(tm.Get('MixInfo'))
        # Pull the information we need for this MIX group...
        load = float(e.get('Load'))
        load_unit = e.get('LoadUnit')
        original_weights = e.get('OriginalWeightList')
        if original_weights is None:
            e.set('OriginalWeightList', e.get('WeightList'))
        e.set('WeightList', e.get('OriginalWeightList'))
        tm.Set('MixInfo', etree.tostring(e))

        # The default rotation is to the right, so we need to negate the count to rotate left...
        rotate_weights(-count, tm)

        # Reallocate the load based upon the new weights...
        with AutoCommand('spirent.methodology.traffic.AllocateTrafficMixLoad1Command') as alloc:
            alloc.Set('StmTrafficMix', tm.GetObjectHandle())
            alloc.Set('TagName', '')
            alloc.Set('Load', load)
            alloc.Set('LoadUnit', load_unit)
            alloc.Execute()

    # The configurator must keep the results framework in sync with the iteration framework.
    # What we want to do is pass information to the results framework to let it know that
    # a new iteration is taking place and a meaningful value that it can display.
    this_cmd = get_this_cmd()
    update_results_with_current_value('Non-conformant Streams', count, Iteration, this_cmd)

    return True
def run(ObjectList, TagList, IgnoreEmptyTags, CurrVal, Iteration):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogInfo("run")

    # Find the StmTrafficMix objects
    tm_list = dm_utils.process_inputs_for_objects(ObjectList, TagList,
                                                  "StmTrafficMix")
    # Find the StreamBlocks
    sb_list = dm_utils.process_inputs_for_objects(ObjectList, TagList,
                                                  "StreamBlock")
    sb_dict = {}
    for sb in sb_list:
        sb_dict[sb.GetObjectHandle()] = sb

    # Merge the lists
    for tm in tm_list:
        sb_list = get_traffic_mix_streamblocks(tm)
        for sb in sb_list:
            sb_dict[sb.GetObjectHandle()] = sb

    plLogger.LogInfo("modifying streamblocks: ")
    for sb_hnd in sb_dict.keys():
        plLogger.LogInfo("sb: " + sb_dict[sb_hnd].Get("Name"))

    # Strip whitespace
    CurrVal = "".join(CurrVal.split())

    # Process frame size from CurrVal
    match = parse_iterate_mode_input(CurrVal)

    plLogger.LogInfo("match: " + str(match) + " for " + CurrVal)

    if match is not None:
        for sb in sb_dict.values():
            # Configure the Streamblock
            if match["type"] == "fixed":
                plLogger.LogInfo("Fixed frame size")
                # Fixed Frame Size
                sb.Set("FrameLengthMode", ENUM_FRAME_LENGTH_MODE_FIXED)
                sb.Set("FixedFrameLength", match["start"])
            elif match["type"] == "incr":
                # Incr Frame Size
                plLogger.LogInfo("Incr frame size")
                sb.Set("FrameLengthMode", ENUM_FRAME_LENGTH_MODE_INCR)
                sb.Set("MinFrameLength", match["start"])
                sb.Set("StepFrameLength", match["step"])
                sb.Set("MaxFrameLength", match["end"])
            elif match["type"] == "rand":
                plLogger.LogInfo("Random frame size")
                # Random Frame Size
                sb.Set("FrameLengthMode", ENUM_FRAME_LENGTH_MODE_RANDOM)
                sb.Set("MinFrameLength", match["start"])
                sb.Set("MaxFrameLength", match["end"])
            elif match["type"] == "imix":
                plLogger.LogInfo("IMIX frame size")
                frame_len_dist_handle = get_frame_len_dist(match["name"])
                if frame_len_dist_handle == 0:
                    plLogger.LogError("Invalid IMIX distribution named: " +
                                      match["name"])
                    return False
                sb.Set("FrameLengthMode", ENUM_FRAME_LENGTH_MODE_IMIX)

                # Need to remove any affiliated FrameLengthDistribution objects
                # before we can add a new one (should only be one)
                rel_name = "AffiliationFrameLengthDistribution"
                fld_list = sb.GetObjects("FrameLengthDistribution",
                                         RelationType(rel_name))
                for fld in fld_list:
                    sb.RemoveObject(fld, RelationType(rel_name))
                sb.AddObject(frame_len_dist_handle,
                             RelationType(rel_name))
            else:
                plLogger.LogError("Invalid frame size mode: " +
                                  str(match["type"]))
                return False
    else:
        plLogger.LogError("Invalid frame size: " + str(CurrVal))
        return False

    # Update the results
    hnd_reg = CHandleRegistry.Instance()
    this_cmd = hnd_reg.Find(__commandHandle__)
    update_results_with_current_value('FrameSize', CurrVal, Iteration, this_cmd)
    return True
def run(ObjectList, TagList, IgnoreEmptyTags, CurrVal,
        Iteration, ClassName, PropertyName):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogInfo("IteratorConfigPropertyValueCommand.run")

    # Validate ClassName
    valid_class, ret_name = dm_utils.validate_classname(ClassName)
    if not valid_class:
        plLogger.LogError("Invalid ClassName: " + str(ClassName))
        return False

    # Validate PropertyName
    prop_list = [p.lower() for p in CMeta.GetProperties(ClassName)]
    if PropertyName.lower() not in prop_list:
        plLogger.LogError("Invalid PropertyName: " + str(PropertyName) +
                          " given for class: " + str(ClassName))
        return False

    if not IgnoreEmptyTags:
        if tag_utils.is_any_empty_tags_given_string_names(TagList, ClassName):
            plLogger.LogError("No tagged objects for TagList: " +
                              str(TagList))
            return False

    # Find the objects
    obj_list = dm_utils.process_inputs_for_objects(ObjectList, TagList,
                                                   ClassName)
    if len(obj_list) == 0:
        plLogger.LogInfo("No objects of type " + ClassName +
                         " to configure.")
        return True

    plLogger.LogDebug("obj_list contains: " + str(len(obj_list)))

    # Set the new value
    prop_meta = CMeta.GetPropertyMeta(ClassName, PropertyName)
    for obj in obj_list:
        plLogger.LogDebug("setting obj " + obj.Get("Name") + "'s " +
                          PropertyName + " to " + CurrVal)
        if prop_meta["isCollection"]:
            plLogger.LogDebug(PropertyName + " is a collection")
            try:
                val_list = ast.literal_eval(CurrVal)
                if isinstance(val_list, list):
                    obj.SetCollection(PropertyName,
                                      [str(val) for val in val_list])
                else:
                    obj.SetCollection(PropertyName, [str(val_list)])
            except ValueError:
                plLogger.LogError("Was not able to to set collection " +
                                  "property: " + PropertyName + " of " +
                                  ClassName + " to " + CurrVal)
                return False
        else:
            # Scalar
            obj.Set(PropertyName, CurrVal)

    # Update the results
    hnd_reg = CHandleRegistry.Instance()
    this_cmd = hnd_reg.Find(__commandHandle__)
    res_name = ClassName + "." + PropertyName
    update_results_with_current_value(res_name, CurrVal, Iteration, this_cmd)
    return True