def add_network_latency_using_iptables(self, cur_message):
        
        results             = build_dict("FAILED", "Add Network Latency Event Not Started", {
                                            "Nodes"     : [],
                                            "Errors"    : []
                                    })

        try:

            self.m_cur_count    += 1

            self.lg("Handling - Add Network Latency Eventer(" + str(json.dumps(cur_message)) + ")", 6)

            ssh_host            = str(cur_message["Host"])
            ssh_user            = str(cur_message["User"])

            commands_to_run     = cur_message["Commands"]
            count_idx           = 0

            values              = {
                                    "PID"   : None,
                                }

            all_success         = False
            err_msg             = "Add Network Latency Event Failed"

            for ssh_command in commands_to_run:
                
                valid_command   = True

                # Allow for edits before running:
                remote_command  = str(ssh_command)

                if count_idx == 1:
                    
                    if str(values["PID"]) != "" and str(values["PID"]).lower() != "none":
                        remote_command  = remote_command.replace("%i", str(values["PID"]))

                        if values["PID"] != "":
                            self.lg("Add Network Latency Event Broker(" + str(ssh_host) + ") with PID(" + str(values["PID"]) + ") Command(" + str(remote_command) + ")", 6)
                        else:
                            valid_command   = False

                    else:
                        err_msg     = "Failed to find a valid Broker PID for Add Network Latency Event Broker(" + str(ssh_host) + ") with PID(" + str(values["PID"]) + ") Command(" + str(remote_command) + ")"
                        self.elg(err_msg, True)
                        results     = build_dict("FAILED", str(err_msg), { "Nodes" : [], "Errors" : [] })
                        return results

                # end of prescreening for kill command

                if valid_command:
                    proc            = subprocess.Popen(remote_command, shell=True, stdout=subprocess.PIPE)
                    std_rows        = proc.communicate()[0].split("\n")

                    # On Docker containers the iptables performs this in one command
                    if len(commands_to_run) == 1:
                        self.lg("Done Adding Network Latency Event", 6)
                        all_success = True
                        break

                    # For killing the broker the first command gets the PID
                    else:
                        if len(std_rows) == 1:

                            if count_idx == 0:
                                err_msg     = "Failed to Add Network Latency Event with Error(" + str(std_rows) + ")"
                                self.elg(err_msg, True)
                                results     = build_dict("FAILED", str(err_msg), { "Nodes" : [], "Errors" : [] })
                                return results

                            else:
                                all_success = True

                        else:
                            if count_idx == 0:
                                values["PID"]   = str(std_rows[0].replace("   ", " ").replace("  ", " ").split(" ")[1]).strip().lstrip()
                                if values["PID"] != "":
                                    self.lg("Add Network Latency Event Broker(" + str(ssh_host) + ") with PID(" + str(values["PID"]) + ")", 6)
                # end of valid command

                count_idx       += 1

            # end of for all commands
            
            if all_success:
                
                cluster_nodes   = self.return_all_cluster_node_details()

                if "Expected" in cur_message:

                    self.lg("Checking Cluster", 6)
                    # Confirm the cluster is as expected after introducing a network latency event to it:
                    all_valid       = False

                    if cluster_nodes["Status"] == "SUCCESS":
                    
                        self.lg("Validing Expected(" + str(len(cur_message["Expected"])) + ") Cluster(" + str(len(cluster_nodes["Record"]["Nodes"])) + ")", 6)

                        errors      = []

                        if len(cur_message["Expected"]) == len(cluster_nodes["Record"]["Nodes"]):

                            # This is looks like it should be refactored...

                            for expected_node in cur_messages["Expected"]["Messages"]:

                                found_node          = False

                                for cluster_node in cluster_nodes["Record"]["Nodes"]:
                                    if str(cluster_node["Name"]).lower().strip().lstrip() == str(expected_node["Name"]).lower().strip().lstrip():
                                        found_node  = True
                                        for key in expected_node:
                                            if key not in cluster_node:
                                                errors.append("Missing Expected(" + str(expected_node["Name"]) + ") with a Cluster Key(" + str(key) + ")")
                                            # if it is missing
                                            else:
                                                if cluster_node[key].strip().lstrip() != expected_node[key].lstrip().strip():
                                                    errors.append("Cluster Node(" + str(cluster_node["Name"]) + ") Key(" + str(key) + ") Value(" + str(cluster_node[key]) + ") Does not match Expected(" + str(expected_node["Name"]) + ") Value(" + str(expected_node[key]) + ")")
                                        # for each expected key on the node
                                    # if the cluster's name matches the expected

                                # end for all cluster nodes

                            # end for all expecteds
                        else:
                            errors.append("Cluster Node Mismatch Expected(" + str(len(cur_message["Expected"])) + ") Cluster(" + str(len(cluster_nodes["Record"]["Nodes"])) + ")")
                        # if there are expectations on the cluster's new status, perform the validation and build the errors

                        if len(errors) == 0:
                            results = build_dict("SUCCESS", "", { "Nodes" : cluster_nodes["Record"]["Nodes"], "Errors" : [] })
                        else:
                            results = build_dict("FAILED",  "", { "Nodes" : cluster_nodes["Record"]["Nodes"], "Errors" : [] })
                            
                    # end of if cluster_nodes["Status"] == "SUCCESS"
                else:
                    results         = build_dict("SUCCESS", "", { "Nodes" : cluster_nodes["Record"]["Nodes"], "Errors" : [] })
                # if success

            # all success 
            else:
                results             = build_dict("FAILED", str(err_msg), { "Nodes" : [], "Errors" : [] })
            # end of if/else

        except Exception,k:
            err_msg     = "Failed Add Network Latency Event Number(" + str(self.m_message_number) + ") Message(" + str(cur_message) + ") with Ex(" + str(k) + ")"
            self.elg(err_msg, True)
            results     = build_dict("FAILED", str(err_msg), { "Nodes" : [], "Errors" : [] })

            self.m_message_number   += 1
        # end of try/ex

        return results
    # end of add_network_latency_using_iptables
Default handler for adding network latency using iptables
dataset/ETHPy150Open GetLevvel/message-simulator/src/rabbit_message_publisher.py/RabbitMessagePublisher.add_network_latency_using_iptables