<h3 dir="auto">Bug report</h3>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="318464008" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/11137" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/11137/hovercard" href="https://github.com/matplotlib/matplotlib/pull/11137">#11137</a> deprecated the kwargs <code class="notranslate">*min/*max</code> of <code class="notranslate">set_*lim</code> (after some disussion there and in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="325690991" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/11293" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/11293/hovercard" href="https://github.com/matplotlib/matplotlib/pull/11293">#11293</a>).</p>
<p dir="auto"><a href="https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.axis.html" rel="nofollow">Axes.axis</a> uses the <code class="notranslate">*min</code>, <code class="notranslate">*max</code> parameter names as well. Currently, this does not support <code class="notranslate">left, right, bottom, top</code> at all.</p>
<p dir="auto">This is an inconsistency within the current API, and if we're serious with the change <code class="notranslate">Axes.axis()</code> whould have to be changes as well.</p>
<h3 dir="auto">Bug report</h3>
<p dir="auto">I wrote a little script that creates graphs with matplotlib library, unfortunately, I am getting the exception below when I run that code... I couldn't find any documentation about how to fix it..</p>

<p dir="auto"><strong>Code for reproduction</strong></p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import requests
import logging
import datetime
import time
from time import sleep
import sys
import paramiko
import csv
import re
import threading
import optparse
import json
import os
import shutil
import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot as plt
from matplotlib import style
import numpy as np

#TODO -
'''
1. Creating graphs every hour
2. run script with NEO process + sending REST API in background+ generating reports. 
3. sending the graphs via email 
'''



#consts
global_csv_path = str(os.path.abspath(__file__)).split(&quot;script&quot;)[0] + &quot;csv&quot; + os.sep
global_graphs_path = str(os.path.abspath(__file__)).split(&quot;script&quot;)[0] + &quot;graphs&quot; + os.sep
global_ram_path = os.path.join(global_csv_path, 'RestAPI_loop_ram.csv')
global_cpu_path = os.path.join(global_csv_path, 'RestAPI_loop_cpu.csv')
global_requests_path = os.path.join(global_csv_path, 'RestAPI_loop_requests.csv')
counter = 0
stop = False
total = 0
ufm_processes_name_list = ['mysqld','opensm','ModelMain','periodic_report_runner','unhealthy_ports_main','ibpm','UFMHealthConfiguration']

def create_ufm_health_report(ip, username, password):
    counter = 1
    url = 'http://$ip/ufmRest/reports/Fabric_Health'
    url = url.replace('$ip',ip)
    ufm_payload =r&quot;&quot;&quot;
    {
        &quot;duplicate_nodes&quot;: true,
        &quot;map_guids_desc&quot;: false,
        &quot;ufm_alarms&quot;: true,
        &quot;sm_state&quot;: true,
        &quot;firmware&quot;: true,
        &quot;cables&quot;: false,
        &quot;non_opt_links&quot;: true,
        &quot;non_opt_speed_width&quot;: true,
        &quot;link_speed&quot;: &quot;ALL&quot;,
        &quot;link_width&quot;: &quot;ALL&quot;,
        &quot;eye_open&quot;: false,
        &quot;duplicate_zero_and_lids&quot;: true
    }
    &quot;&quot;&quot;
    while not stop:
        logging.info( str(counter) + &quot;# Sending Fabric Health Report...&quot;)
        r = requests.post(url = url, auth=(username, password), data=ufm_payload)
        if str(r.status_code) == '202':
            logging.info(&quot;Fabric Health succeeded... &quot;)
        else:
            logging.error(&quot;Fabric Health Failed... status code equals {}&quot;.format(str(r.status_code)))
        counter+=1
        
        
def creating_directory(path):
    logging.debug(&quot;Start to create directory inside &quot; + str(path))
    #Try to remove backslash from the end:
    path = path.rstrip()
    try:
        if os.path.exists(path):
            shutil.rmtree(path)
        os.mkdir(path)
    except OSError as ex:
        logging.error(&quot;Creation of the directory failed&quot; +str(ex))
        sys.exit(1)
    else:
        logging.info(&quot;Successfully created the directory %s &quot; % path)


def findRegex(output, regex_search):
    pattern =re.compile(pattern=regex_search)
    matches_list = pattern.findall(source=output)
    if len(matches_list) &gt; 0:
        logging.debug(&quot;Regex:&quot; + regex_search + &quot; Was found!&quot;)
        return matches_list
    else:
        logging.critical(&quot;Regex was not found!:&quot; + regex_search )
        return []

def createshell(ssh):
    shell = ssh.invoke_shell()
    shell.settimeout(0.5)
    shell.recv(1024)
    #time.sleep(10)
    return shell

def run_par_cmd(cmd, expect, shell):
    '''

      :param shell:
      :param cmd: cmd command like ' show version'
      :param expect: string to look for like '
      :return: 0 if the expected string was found in output.
      '''
    # sleeping for 3 seconds to the command will be executed after shell prompt is printed.
    shell.send(cmd + '\n')
    out = ''
    while True:
        try:
            tmp = shell.recv(1024)
            if not tmp:
                break
        except Exception as e:
            break
        out += tmp.decode(&quot;utf-8&quot;)
    ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
    out = ansi_escape.sub('', out)
    if expect not in out:
        return (1, out)
    return (0, out)


def SSHConnect(ip,username, passowrd):
    ssh = paramiko.SSHClient()
    logging.info(msg=&quot;Open SSH Client to :&quot; + str(ip))
    try:
        ssh.set_missing_host_key_policy(policy=paramiko.AutoAddPolicy())
        ssh.connect(ip, port=22, username=username, password=passowrd, allow_agent=False, look_for_keys=False)
    except Exception as ex:
        logging.error(msg=&quot;SSH Client wasn't established!&quot;)
        sys.exit(0)
    return ssh

def ChangeToShellMode(shell):
    #result should be '0'
    result = run_enable_configure_terminal(shell)
    if int(result) != 0:
        logging.error(&quot;Can't run \'_shell\' command..\n&quot; + &quot;exiting&quot;)
        exit(1)
    else:
        command = &quot;_shell&quot;
        expect = '~]#'
        try:
            logging.info(&quot;Changing UFM APL from CLI Mode to SHELL mode&quot;)
            result, output = run_par_cmd(cmd=command, expect=expect, shell=shell)
        except Exception as ex:
            logging.error(&quot;Got Exception while trying to change for SHELL mode&quot; + str(ex))
        if int(result) == 0:
            logging.info(&quot;_shell command was executed successfully!&quot;)
        else:
            logging.error(&quot;couldn't find expected output while running shell command..\nPlease make sure License is installed!&quot;)

def get_ram_total_used(output, regex_ram, counter):
    matches = findRegex(output, regex_ram)
    if matches:
        cpu_value_total, cpu_value_used = matches[0][2], matches[0][4]
        logging.info(str(counter) + &quot;# RAM value is :\t&quot; + str((float(cpu_value_used)/float(cpu_value_total))*100)+'%')
        return float(cpu_value_used)/float(cpu_value_total)
    else:
        logging.error(&quot;Couldn't retrived RAM usage according to given regex!&quot;)
        return -1

def GetRAMUsage(shell ,counter):
    command = r&quot;&quot;&quot;free -t&quot;&quot;&quot;
    expected = 'total'
    mode ='a'
    regex_ram = r'([Total:]{6})(\s*)(\d*)(\s*)(\d*)'
    if counter == 0:
        mode = 'w'

    #file = os.path.realpath(__file__) + os.sep + '..' + os.sep + os.path.join('csv' , 'RestAPI_loop_ram.csv')
    with open(global_ram_path, mode, newline='') as csvfile:
        fieldnames = ['iteration number', 'RAM']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        time_started = datetime.datetime.now()
        try:
            logging.info(&quot;Measuring RAM USage...&quot;)
            result, output = run_par_cmd(cmd=command, expect=expected, shell=shell)
        except Exception as ex:
            logging.error(&quot;Got Exception while trying to retrieve RAM utilization , &quot; + str(ex))
            print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), type(ex).__name__, ex)
        else:
            if int(result) == 0:
                logging.debug( str(counter) +&quot;# get RAM command was executed successfully!&quot;)
            else:
                logging.error(&quot;couldn't find expected output while running \'free -t\' command..\n&quot;)
                print(&quot;expected: &quot; + expected + '\n' +&quot;Output : \n&quot; + output+'\n\n')
                return None
            ram_total = str(get_ram_total_used(output, regex_ram, counter))
            if  str(ram_total) == '-1' :
                logging.error(&quot;Couldn't calculate RAM usage&quot;)
                return None
            else:
                writer.writerow({'iteration number': counter, 'RAM': str(float(ram_total)*100)})
        csvfile.close()

def GetCPUUsage(shell, counter):
    command = r&quot;&quot;&quot;grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage &quot;%&quot;}'&quot;&quot;&quot;
    expected = '%'
    regex = r'[0-1]{1}\.{1}[0-9]*'
    mode ='a'
    if counter == 0:
        mode = 'w'
    #file = os.path.realpath(__file__) + os.sep + '..' + os.sep +  os.path.join( 'csv', 'RestAPI_loop_cpu.csv')
    with open(global_cpu_path ,mode=mode, newline='') as csvfile:
        fieldnames = ['iteration number', 'CPU']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        time_started = datetime.datetime.now()
        try:
            logging.info(&quot;Measuring CPU USage...&quot;)
            result, output = run_par_cmd(cmd=command, expect=expected, shell=shell)
        except Exception as ex:
            logging.error(&quot;Got Exception while trying to retrieve CPU utilization , &quot; + str(ex))
        else:
            if int(result) == 0:
                logging.debug(&quot;CPU command was executed successfully!&quot;)
            else:
                logging.error(&quot;couldn't find expected output while running CPU command..&quot;)
                return None
            cpu_value = findRegex(output ,regex)
            if cpu_value:
                cpu_value_flt = float(cpu_value[0])
                if 0.0 &lt;= cpu_value_flt &lt;= 100.0:
                #if cpu_value_str &lt;= 100.0 and cpu_value_str &gt;= 0.0:
                    logging.info( str(counter)+ &quot;# CPU usage is:\t &quot; + str(cpu_value_flt) + '%')
                    writer.writerow({'iteration number': str(counter), 'CPU': str(cpu_value_flt*100)})
                else:
                    logging.error(&quot;Not Matched Regex!\nCouldn't retrevied CPU usage according to given regex!&quot;)
            else:
                logging.error(&quot;Couldn't retrieved CPU usage!&quot;)
        csvfile.close()

def messurement_host_performance(shells, loops):

    i = 0
    lst = []

    while stop == False:
        try:
            logging.debug(&quot;Running CPU/RAM performance test #&quot;+ str(i))
            t1 = threading.Thread(target=GetCPUUsage,  args=(shells[0],i))
            t2 = threading.Thread(target=GetRAMUsage, args=(shells[1],i))
            t1.start()
            t2.start()
            t1.join()
            t2.join()
            i+=1
        except Exception as ex:
            logging.error(&quot;Exception on starting thread&quot; + ex)
    logging.info(&quot;Performance measurement is completed!&quot;)

def run_enable_configure_terminal(shell):
    commandsList = ['enable' , 'configure terminal']
    expectedList = ['#', '(config)']
    for cmd,expect in zip(commandsList,expectedList):
        result, output = run_par_cmd(cmd=cmd, expect=expect, shell=shell)
        if ((int(result) == 0 )and (len(output) &gt; 0 )):
            logging.info(cmd+ &quot; command run successfully&quot;)
        else:
            logging.error(&quot;can't run &quot;+cmd+&quot; command&quot;)
            sys.exit(1)
    return False

def get_vmsize_of_process_by_process_id(shell, process_vm):
    cmd = 'cat /proc/x/status'
    cmd = str(cmd).replace('x',process_vm)
    expected = 'VmSize'
    regex_search='(VmSize:)(\s*)(\d*)(\s*)(kB)'
    vm_size = None

    result, output = run_par_cmd(cmd, expected,shell)
    if ((int(result) == 0) and (len(output) &gt; 0)):
        logging.info(cmd + &quot; command run successfully&quot;)
    else:
        logging.error(&quot;can't run &quot; + cmd + &quot; command&quot;)
        sys.exit(1)
    matches = findRegex(output, regex_search)
    if matches:
        vm_size = str(matches[0][2])
    else:
        logging.error(&quot;No matches were found for vmsize&quot;)
    return vm_size
def continue_loop(counter,started_time, loops, time):
    if time is not None:
        if (started_time + datetime.timedelta(hours=int(time)) &gt; datetime.datetime.now()):
            return True
        else:
            return False
    else:
        if loops is not None:
            if (int(counter) &lt; int(loops)):
                return True
            else:
                return False
def send_ufm_rest_get_pkey(shell, ip, username, password, private_key_path,certificate_path):

    url = r'http://ip/ufmRest/resources/pkeys'
    url = url.replace('ip',ip)
    payload = r'''{
          &quot;pkey&quot;: &quot;0x1&quot;,
          &quot;index0&quot;: false,
          &quot;ip_over_ib&quot;: true,
          &quot;membership&quot;: &quot;full&quot;,
          &quot;guids&quot;: [
    &quot;98039b0300671ec0&quot;
  ]
}'''
    s = requests.session()
    s.auth = (username, password)
    if ((private_key_path is not None) and (certificate_path is not None)):
        # Using SSL certification
        s.cert = (certificate_path, private_key_path)
    else:
        logging.info(&quot;Using Basic Authentication&quot;)

    try:
        logging.info(&quot;creating new pkey with rest request &quot;)
        r = s.post(url=url, data=payload)
    except Exception as e:
        logging.error(&quot;exception in UFM rest request&quot;)
    logging.info(&quot;creating new pkey with rest request was send successfully.&quot;)
    return r

def run_rest_in_loop(shell,ip, prodcut_type, loops,time, username, password, private_key_path, certificate_path):
    counter = 0
    success = 0
    time_started = datetime.datetime.now()

    #file = os.path.realpath(__file__) + os.sep +'..' + os.sep + os.path.join('csv', 'RestAPI_loop_requests.csv')
    with open(global_requests_path, 'w', newline='') as csvfile:
        fieldnames = ['iteration number', 'time', 'Response Code', 'Succeeded']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        while continue_loop(counter,time_started,loops,time):
            request_send_time = datetime.datetime.now()
            logging.info(str(counter) + &quot;# sending Rest request&quot;)
            counter += 1
            try:
                if (prodcut_type == 'ufm'):
                    r = send_ufm_rest_get_pkey(shell,ip,username,password,private_key_path,certificate_path)
                elif (prodcut_type == 'neo'):
                    r = send_neo_ports_rest_api(ip)
                    #TODO - missing UFM Aplliance Rest
            except Exception as ex:
                logging.error(&quot;Exception on sending REST request&quot; + str(counter) + &quot;\n&quot; + str(ex))
                sys.exit(1)
            request_end_time = datetime.datetime.now()
            total_requst_time = str(request_end_time - request_send_time)
            request_status_code = r.status_code
            if (str(r.status_code) == '200'):
                success += 1
                writer.writerow(
                    {'iteration number': str(counter), 'time': str(time_started), 'Response Code': str(request_status_code),
                     'Succeeded': 'Yes'})
                logging.info(&quot;Total time for request #&quot; + str(counter) + &quot; is\t\t\t &quot; + total_requst_time)
            else:
                logging.error(&quot;Request # &quot; + str(counter) + &quot; Failed!&quot; + &quot;Status Code is: &quot; + str(request_status_code))
                writer.writerow(
                    {'iteration number': counter, 'time': total_requst_time, 'Response Code': request_status_code,
                     'Succeeded': 'No'})
        csvfile.close()
    end_time = datetime.datetime.now()
    total_time = end_time - time_started
    logging.info(&quot;Total time for &quot; + str(counter) + ' loops' + &quot; was\t\t\t&quot; + str(total_time) + &quot;\t\tNumber of Success Requests:\t &quot; + str(success) + &quot;/&quot; + str(counter))
    global stop
    stop = True


def virtual_memory_of_processes(shell, loops, product_type):
    base_regex = r&quot;&quot;&quot;(\s{3,6})(\d{4,6})(\s{3,6})(\d*)(\s*)(\d*)(.*)(ufm/)(.*)&quot;&quot;&quot;
    global ufm_processes_name_list
    logging.debug(&quot; Running ps -ef command to check running processes&quot;)
    expected = product_type
    command = 'ps -ef | grep '+ product_type
    i=0

    while stop == False:
        try:
            result, output = run_par_cmd(cmd=command, expect=expected, shell=shell)
        except Exception as ex:
            logging.error(&quot;exception in ps -ef command&quot;)
        if int(result) != -1:
            for process_name in ufm_processes_name_list:
                regex_search = base_regex + '('+process_name + ')'
                matches = findRegex(output, regex_search)
                if matches:
                    process_vm = str(matches[0][1])
                    vm_size = get_vmsize_of_process_by_process_id(shell, process_vm)
                    logging.info( str(i) + &quot;# virtual memory of &quot; + str(process_name) + &quot; = &quot; + str(vm_size))
                    write_process_to_csv(i, process_name,vm_size)
                else:
                    logging.error(&quot;couldn't find process virtual memory according to given regex&quot;)
            i += 1
        else:
            logging.error(&quot;couldn't find expected result in ps -ef command&quot;)
def get_product_name_by_url(url):

    if int(str(url).find('ufm')) != -1:
        return 'ufm'
    elif int(str(url).find('neo')) != -1:
        return 'neo'
    else:
        return -1

def create_graphs():
    global ufm_processes_name_list
    logging.info(&quot;Creating Graphs for processes&quot;)

    dt = str(datetime.datetime.now()).split(&quot;.&quot;)[0].replace(&quot; &quot;,&quot;_&quot;).replace(&quot;:&quot;,&quot;-&quot;)
    #Creating sub folder for graphs_time
    current_graph_folder = global_graphs_path + dt + os.sep
    creating_directory(current_graph_folder)

    for process_name in ufm_processes_name_list:
        filename = global_csv_path + 'RestAPI_loop_' + str(process_name) + '.csv'
        create_graph(filename, str(process_name), 'VMSize(kb)','iterations',current_graph_folder,process_name )
    logging.info(&quot;Creating Graphs for processes completed successfully&quot;)
    logging.info(&quot;Creating Graphs for CPU/RAM usage&quot;)
    for name in ('ram','cpu'):
        filename = global_csv_path + 'RestAPI_loop_' + name + '.csv'
        create_graph(filename, str(name),  name +'(%)','iterations',current_graph_folder,name)

def write_process_to_csv(i, process_name,process_vm):

    #csv_path = os.path.realpath(__file__) + os.sep + '..' + os.sep + os.path.join('csv')
    filename = global_csv_path + 'RestAPI_loop_' + str(process_name)+ '.csv'
    mode = 'a'
    if i == 0:
        mode = 'w'
    try:
        logging.debug(&quot;Trying to open &quot; + filename + &quot; to write data&quot;)
        with open(file=filename, mode=mode, newline='') as csvfile:
            fieldnames = ['iteration number', 'VMSize']
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            writer.writerow({'iteration number': i, 'VMSize': process_vm})
    except Exception as ex:
        logging.error(&quot;exception while writing data into&quot; + filename)
        csvfile.close()

def thread_manager(shells,ip, product_type, loops,time, username, password, private_key_path, certificate_path,fabric_health):
    logging.info(&quot;starting new thread: CPU/RAM Performance&quot;)
    t1 = threading.Thread(target=messurement_host_performance, args=(shells, loops))
    logging.info(&quot;Starting new thread: REST requests in loop&quot;)
    t2 = threading.Thread(target=run_rest_in_loop, args=(shells[2],ip, product_type, loops,time, username, password, private_key_path, certificate_path))
    logging.info(&quot;Measuring Processes virtual memory&quot;)
    #product_type = get_product_name_by_url(url)
    t3 = threading.Thread(target=virtual_memory_of_processes, args=(shells[3], loops, product_type))
    logging.info(&quot;Measuring Processes virtual memory&quot;)
    if str(fabric_health) == 'yes':
        t4 = threading.Thread(target=create_ufm_health_report, args=(ip, username, password))
        logging.info(&quot;Starting Fabric health Reports&quot;)
        t4.start()
    t5 = threading.Thread(target=graphs_scheduler, args=())
    logging.info(&quot;start Thread to for creating graphs every one hour&quot;)

    t1.start()
    t2.start()
    t3.start()
    t5.start()


    t1.join(timeout=300)
    t2.join(timeout=300)
    t3.join(timeout=300)
    if str(fabric_health) == 'yes':
        t4.join(timeout=300)
    logging.info(&quot;Threads are joined!&quot;)
def send_neo_ports_rest_api(neo_ip):
    url = r'http://ip/neo/resources/ports?_=1543846564166&amp;tz=Asia/Jerusalem'
    url = url.replace(&quot;ip&quot;, neo_ip)
    cookie = {&quot;session&quot;:&quot;.eJyrVopPK0otzlCyKikqTdVRis9MUbKqVlJIUrJS8guJyooMSTeJrEqv8HdJyY4Mycj2D3et9HfJNvILycnwC3c1jQqPrIrK8rVVqgXqLUgtyk3MS80rgZlWWpxaBDZRKTElNzNPqRYAE_clcg.DubaoQ.I0UVeS061HEHVhzFeOqLobiNhTk&quot;}
    payload = {&quot;_&quot;:&quot;1543846564166&quot;,&quot;tz&quot;:&quot;Asia/Jerusalem&quot;}
    logging.info(&quot;sending rest request for getting all ports #&quot;)
    try:
        r = requests.get(url= url, cookies=cookie, payload=payload)
    except Exception as e:
        logging.error(&quot;exception when sending rest API to NEO for getting all ports&quot;)
        return
    logging.info(&quot;Rest request for NEO succeeded.&quot;)
    return r

def create_graph(filepath ,title, ylabel, xlabel, current_graph_folder, process_name):
    style.use('ggplot')
    try:
        #filepath =
        #C:\Users\arielwe\PycharmProjects\SecurityProject\Rest_Loop_CPU_RAM\csv\RestAPI_loop_mysqld.csv
        #C:\Users\arielwe\PycharmProjects\SecurityProject\Rest_Loop_CPU_RAM\rest_loop_loading\csv\RestAPI_loop_mysqld.csv
        #C:\Users\arielwe\PycharmProjects\SecurityProject\Rest_Loop_CPU_RAM\rest_loop_loading\csv\RestAPI_loop_mysqld.csv'
        x,y = np.loadtxt(filepath, unpack=True, delimiter=',')
    except Exception as ex:
        print(ex)

    plt.title(title)
    plt.ylabel(ylabel)
    plt.xlabel(xlabel)
    plt.plot(x,y)
    full_graph_path =current_graph_folder + process_name + &quot;.png&quot;
    plt.savefig(full_graph_path)
    plt.close()

def graphs_scheduler():
    sleep(10)
    global counter
    global stop
    counter+=1
    if stop != False:
        return None
    else:
        threading.Timer(60,graphs_scheduler).start()
        logging.info(&quot;Creating Graphs #&quot; + str(counter) + &quot;:  time is &quot; +str(datetime.datetime.now()))
        create_graphs()

def get_payload_for_request(payload):
    with open(payload) as json_data:
        try:
            logging.info(&quot;Parsing json payload from file...&quot;)
            json_obj = json.load(json_data)
        except Exception as ex:
            logging.error(&quot;Couldn't parse file to json object&quot;)
            sys.exit(1)
        logging.info(&quot;json file parsed successfully&quot;)
        json_data.close()
        return json_obj

def DisplayOptions():
    #TODO- fix useage
    usage = r&quot;&quot;&quot;usage: python memory_tester.py [options] arg1 arg2\n&quot; 
            Example: python memory_tester.py 
            --product ufm
            -- ip 10.209.27.110
            --time 48
            --loops 500
            --pkey alice.key 
            --certificate alice.cert.pem
            &quot;&quot;&quot;
    parser = optparse.OptionParser(usage=usage)
    parser.add_option(&quot;--product&quot;, dest=&quot;type&quot;, help=&quot;product type [ufm/ufmapl/neo]&quot;)
    parser.add_option(&quot;--ip&quot;, dest=&quot;ip&quot;, help=&quot;ip address of the machine&quot;)
    parser.add_option(&quot;--time&quot;, dest=&quot;time&quot;, help=&quot;total time for script to run in hours &quot;)
    parser.add_option(&quot;--loops&quot;, dest=&quot;loops&quot;, help=&quot;number of REST calls in loop [Optional]&quot;)
    parser.add_option(&quot;--pkey&quot;, dest=&quot;private_key_path&quot;, help=&quot;private key path for SSL client certification [Optional]&quot;)
    parser.add_option(&quot;--certificate&quot;, dest=&quot;certificate_path&quot;, help=&quot;certificate path for SSL client certification [Optional]&quot;)
    parser.add_option(&quot;--fabric_health&quot;, dest=&quot;fabric_health&quot;, help=&quot;sending REST API calls to create UFM fabric health report [Optional]&quot;)

    (options, args) = parser.parse_args()
    if ((options.type is None)  or (options.ip is None) or (options.time is None)):
        logging.error(&quot;Missing parameters for script...exiting\n&quot;)
        sys.exit(1)
    return options

def getIPfromURL(url):
    regex_url=r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'
    ip = findRegex(output=url,regex_search=regex_url)
    if not ip:
        logging.error(&quot;Couldn't retreived ip from URL&quot;)
        sys.exit(1)
    else:
        logging.info(&quot;IP is: &quot; + str(ip))
        return ip[0]

def get_username_password(credentials):
    splited = str(credentials).split(':')
    username, password = splited[0], splited[1]
    password.replace(':','')

    return username, password

def isShellMode(shell):
    cmd = '\n'
    expected = ['&gt;']
    for cmd, expect in zip(cmd, expected):
        result, output = run_par_cmd(cmd=cmd, expect=expect, shell=shell)
        if ((int(result) == 0) and (len(output) &gt; 0)):
            logging.debug(cmd + &quot;working in Shell Mode equal true&quot;)
            return True
        else:
            logging.debug(cmd + &quot;working in Shell Mode equal false&quot;)
            return False

def get_credentials_from_product_type(type):
    logging.info(&quot;Checking product type and set correct credentails&quot;)
    if type == 'ufm':
        logging.info(&quot;Product is UFM-IB&quot;)
        return ('admin','****')
    elif type == 'neo':
        logging.info(&quot;Product is NEO&quot;)
        return ('admin','****')
    elif type == 'ufmapl':
        logging.info(&quot;Product is UFM-Appliance&quot;)
        return ('admin','*****')

def main():
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s %(levelname)-8s %(message)s',
                        datefmt='%m-%d %H:%M',
                        filemode='w')
    options = DisplayOptions()
    creating_directory(global_csv_path)
    creating_directory(global_graphs_path)
    #TODO - Add argparse for NEO/UFM/APL
    #ip = getIPfromURL(options.url)
    #username, password = get_username_password(options.credentials)
    type,ip, loops ,time, private_key_path,certificate_path, fabric_health= \
    options.type, options.ip ,options.loops, options.time, options.private_key_path, options.certificate_path, options.fabric_health

    username, password = get_credentials_from_product_type(type)
    #payload_obj = get_payload_for_request(payload)

    #TODO - Currently supports only appliance machine

    shells = []
    for i in range(5):
        if type == 'ufmapl':
            ssh = SSHConnect(ip=ip, username='admin', passowrd='admin')
        else:
            ssh = SSHConnect(ip=ip, username='root', passowrd='****')
        shells.append(createshell(ssh=ssh))
        if type == 'ufmapl':
            if isShellMode(shells[i]):
                ChangeToShellMode(shell=shells[i])
    thread_manager(shells,ip, type, loops,time, username, password, private_key_path, certificate_path,fabric_health)
    logging.info(&quot;Graphs are located under &quot; + global_graphs_path )
    logging.info(&quot;Script is completed&quot;)

if __name__ == '__main__':
    main()


**Actual outcome**

&lt;!--The output produced by the above code, which may be a screenshot, console output, etc.--&gt;
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">requests</span>
<span class="pl-k">import</span> <span class="pl-s1">logging</span>
<span class="pl-k">import</span> <span class="pl-s1">datetime</span>
<span class="pl-k">import</span> <span class="pl-s1">time</span>
<span class="pl-k">from</span> <span class="pl-s1">time</span> <span class="pl-k">import</span> <span class="pl-s1">sleep</span>
<span class="pl-k">import</span> <span class="pl-s1">sys</span>
<span class="pl-k">import</span> <span class="pl-s1">paramiko</span>
<span class="pl-k">import</span> <span class="pl-s1">csv</span>
<span class="pl-k">import</span> <span class="pl-s1">re</span>
<span class="pl-k">import</span> <span class="pl-s1">threading</span>
<span class="pl-k">import</span> <span class="pl-s1">optparse</span>
<span class="pl-k">import</span> <span class="pl-s1">json</span>
<span class="pl-k">import</span> <span class="pl-s1">os</span>
<span class="pl-k">import</span> <span class="pl-s1">shutil</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>
<span class="pl-s1">matplotlib</span>.<span class="pl-en">use</span>(<span class="pl-s">'agg'</span>)
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">style</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-c">#TODO -</span>
<span class="pl-s">'''</span>
<span class="pl-s">1. Creating graphs every hour</span>
<span class="pl-s">2. run script with NEO process + sending REST API in background+ generating reports. </span>
<span class="pl-s">3. sending the graphs via email </span>
<span class="pl-s">'''</span>



<span class="pl-c">#consts</span>
<span class="pl-s1">global_csv_path</span> <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-s1">os</span>.<span class="pl-s1">path</span>.<span class="pl-en">abspath</span>(<span class="pl-s1">__file__</span>)).<span class="pl-en">split</span>(<span class="pl-s">"script"</span>)[<span class="pl-c1">0</span>] <span class="pl-c1">+</span> <span class="pl-s">"csv"</span> <span class="pl-c1">+</span> <span class="pl-s1">os</span>.<span class="pl-s1">sep</span>
<span class="pl-s1">global_graphs_path</span> <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-s1">os</span>.<span class="pl-s1">path</span>.<span class="pl-en">abspath</span>(<span class="pl-s1">__file__</span>)).<span class="pl-en">split</span>(<span class="pl-s">"script"</span>)[<span class="pl-c1">0</span>] <span class="pl-c1">+</span> <span class="pl-s">"graphs"</span> <span class="pl-c1">+</span> <span class="pl-s1">os</span>.<span class="pl-s1">sep</span>
<span class="pl-s1">global_ram_path</span> <span class="pl-c1">=</span> <span class="pl-s1">os</span>.<span class="pl-s1">path</span>.<span class="pl-en">join</span>(<span class="pl-s1">global_csv_path</span>, <span class="pl-s">'RestAPI_loop_ram.csv'</span>)
<span class="pl-s1">global_cpu_path</span> <span class="pl-c1">=</span> <span class="pl-s1">os</span>.<span class="pl-s1">path</span>.<span class="pl-en">join</span>(<span class="pl-s1">global_csv_path</span>, <span class="pl-s">'RestAPI_loop_cpu.csv'</span>)
<span class="pl-s1">global_requests_path</span> <span class="pl-c1">=</span> <span class="pl-s1">os</span>.<span class="pl-s1">path</span>.<span class="pl-en">join</span>(<span class="pl-s1">global_csv_path</span>, <span class="pl-s">'RestAPI_loop_requests.csv'</span>)
<span class="pl-s1">counter</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
<span class="pl-s1">stop</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
<span class="pl-s1">total</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
<span class="pl-s1">ufm_processes_name_list</span> <span class="pl-c1">=</span> [<span class="pl-s">'mysqld'</span>,<span class="pl-s">'opensm'</span>,<span class="pl-s">'ModelMain'</span>,<span class="pl-s">'periodic_report_runner'</span>,<span class="pl-s">'unhealthy_ports_main'</span>,<span class="pl-s">'ibpm'</span>,<span class="pl-s">'UFMHealthConfiguration'</span>]

<span class="pl-k">def</span> <span class="pl-en">create_ufm_health_report</span>(<span class="pl-s1">ip</span>, <span class="pl-s1">username</span>, <span class="pl-s1">password</span>):
    <span class="pl-s1">counter</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>
    <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s">'http://$ip/ufmRest/reports/Fabric_Health'</span>
    <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s1">url</span>.<span class="pl-en">replace</span>(<span class="pl-s">'$ip'</span>,<span class="pl-s1">ip</span>)
    <span class="pl-s1">ufm_payload</span> <span class="pl-c1">=</span><span class="pl-s">r"""</span>
<span class="pl-s">    {</span>
<span class="pl-s">        "duplicate_nodes": true,</span>
<span class="pl-s">        "map_guids_desc": false,</span>
<span class="pl-s">        "ufm_alarms": true,</span>
<span class="pl-s">        "sm_state": true,</span>
<span class="pl-s">        "firmware": true,</span>
<span class="pl-s">        "cables": false,</span>
<span class="pl-s">        "non_opt_links": true,</span>
<span class="pl-s">        "non_opt_speed_width": true,</span>
<span class="pl-s">        "link_speed": "ALL",</span>
<span class="pl-s">        "link_width": "ALL",</span>
<span class="pl-s">        "eye_open": false,</span>
<span class="pl-s">        "duplicate_zero_and_lids": true</span>
<span class="pl-s">    }</span>
<span class="pl-s">    """</span>
    <span class="pl-k">while</span> <span class="pl-c1">not</span> <span class="pl-s1">stop</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>( <span class="pl-en">str</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">+</span> <span class="pl-s">"# Sending Fabric Health Report..."</span>)
        <span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-s1">requests</span>.<span class="pl-en">post</span>(<span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s1">url</span>, <span class="pl-s1">auth</span><span class="pl-c1">=</span>(<span class="pl-s1">username</span>, <span class="pl-s1">password</span>), <span class="pl-s1">data</span><span class="pl-c1">=</span><span class="pl-s1">ufm_payload</span>)
        <span class="pl-k">if</span> <span class="pl-en">str</span>(<span class="pl-s1">r</span>.<span class="pl-s1">status_code</span>) <span class="pl-c1">==</span> <span class="pl-s">'202'</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Fabric Health succeeded... "</span>)
        <span class="pl-k">else</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Fabric Health Failed... status code equals {}"</span>.<span class="pl-en">format</span>(<span class="pl-en">str</span>(<span class="pl-s1">r</span>.<span class="pl-s1">status_code</span>)))
        <span class="pl-s1">counter</span><span class="pl-c1">+=</span><span class="pl-c1">1</span>
        
        
<span class="pl-k">def</span> <span class="pl-en">creating_directory</span>(<span class="pl-s1">path</span>):
    <span class="pl-s1">logging</span>.<span class="pl-en">debug</span>(<span class="pl-s">"Start to create directory inside "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">path</span>))
    <span class="pl-c">#Try to remove backslash from the end:</span>
    <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-s1">path</span>.<span class="pl-en">rstrip</span>()
    <span class="pl-k">try</span>:
        <span class="pl-k">if</span> <span class="pl-s1">os</span>.<span class="pl-s1">path</span>.<span class="pl-en">exists</span>(<span class="pl-s1">path</span>):
            <span class="pl-s1">shutil</span>.<span class="pl-en">rmtree</span>(<span class="pl-s1">path</span>)
        <span class="pl-s1">os</span>.<span class="pl-en">mkdir</span>(<span class="pl-s1">path</span>)
    <span class="pl-k">except</span> <span class="pl-v">OSError</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Creation of the directory failed"</span> <span class="pl-c1">+</span><span class="pl-en">str</span>(<span class="pl-s1">ex</span>))
        <span class="pl-s1">sys</span>.<span class="pl-en">exit</span>(<span class="pl-c1">1</span>)
    <span class="pl-k">else</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Successfully created the directory %s "</span> <span class="pl-c1">%</span> <span class="pl-s1">path</span>)


<span class="pl-k">def</span> <span class="pl-en">findRegex</span>(<span class="pl-s1">output</span>, <span class="pl-s1">regex_search</span>):
    <span class="pl-s1">pattern</span> <span class="pl-c1">=</span><span class="pl-s1">re</span>.<span class="pl-en">compile</span>(<span class="pl-s1">pattern</span><span class="pl-c1">=</span><span class="pl-s1">regex_search</span>)
    <span class="pl-s1">matches_list</span> <span class="pl-c1">=</span> <span class="pl-s1">pattern</span>.<span class="pl-en">findall</span>(<span class="pl-s1">source</span><span class="pl-c1">=</span><span class="pl-s1">output</span>)
    <span class="pl-k">if</span> <span class="pl-en">len</span>(<span class="pl-s1">matches_list</span>) <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">debug</span>(<span class="pl-s">"Regex:"</span> <span class="pl-c1">+</span> <span class="pl-s1">regex_search</span> <span class="pl-c1">+</span> <span class="pl-s">" Was found!"</span>)
        <span class="pl-k">return</span> <span class="pl-s1">matches_list</span>
    <span class="pl-k">else</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">critical</span>(<span class="pl-s">"Regex was not found!:"</span> <span class="pl-c1">+</span> <span class="pl-s1">regex_search</span> )
        <span class="pl-k">return</span> []

<span class="pl-k">def</span> <span class="pl-en">createshell</span>(<span class="pl-s1">ssh</span>):
    <span class="pl-s1">shell</span> <span class="pl-c1">=</span> <span class="pl-s1">ssh</span>.<span class="pl-en">invoke_shell</span>()
    <span class="pl-s1">shell</span>.<span class="pl-en">settimeout</span>(<span class="pl-c1">0.5</span>)
    <span class="pl-s1">shell</span>.<span class="pl-en">recv</span>(<span class="pl-c1">1024</span>)
    <span class="pl-c">#time.sleep(10)</span>
    <span class="pl-k">return</span> <span class="pl-s1">shell</span>

<span class="pl-k">def</span> <span class="pl-en">run_par_cmd</span>(<span class="pl-s1">cmd</span>, <span class="pl-s1">expect</span>, <span class="pl-s1">shell</span>):
    <span class="pl-s">'''</span>
<span class="pl-s"></span>
<span class="pl-s">      :param shell:</span>
<span class="pl-s">      :param cmd: cmd command like ' show version'</span>
<span class="pl-s">      :param expect: string to look for like '</span>
<span class="pl-s">      :return: 0 if the expected string was found in output.</span>
<span class="pl-s">      '''</span>
    <span class="pl-c"># sleeping for 3 seconds to the command will be executed after shell prompt is printed.</span>
    <span class="pl-s1">shell</span>.<span class="pl-en">send</span>(<span class="pl-s1">cmd</span> <span class="pl-c1">+</span> <span class="pl-s">'<span class="pl-cce">\n</span>'</span>)
    <span class="pl-s1">out</span> <span class="pl-c1">=</span> <span class="pl-s">''</span>
    <span class="pl-k">while</span> <span class="pl-c1">True</span>:
        <span class="pl-k">try</span>:
            <span class="pl-s1">tmp</span> <span class="pl-c1">=</span> <span class="pl-s1">shell</span>.<span class="pl-en">recv</span>(<span class="pl-c1">1024</span>)
            <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">tmp</span>:
                <span class="pl-k">break</span>
        <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">e</span>:
            <span class="pl-k">break</span>
        <span class="pl-s1">out</span> <span class="pl-c1">+=</span> <span class="pl-s1">tmp</span>.<span class="pl-en">decode</span>(<span class="pl-s">"utf-8"</span>)
    <span class="pl-s1">ansi_escape</span> <span class="pl-c1">=</span> <span class="pl-s1">re</span>.<span class="pl-en">compile</span>(<span class="pl-s">r'\x1B\[[0-?]*[ -/]*[@-~]'</span>)
    <span class="pl-s1">out</span> <span class="pl-c1">=</span> <span class="pl-s1">ansi_escape</span>.<span class="pl-en">sub</span>(<span class="pl-s">''</span>, <span class="pl-s1">out</span>)
    <span class="pl-k">if</span> <span class="pl-s1">expect</span> <span class="pl-c1">not</span> <span class="pl-c1">in</span> <span class="pl-s1">out</span>:
        <span class="pl-k">return</span> (<span class="pl-c1">1</span>, <span class="pl-s1">out</span>)
    <span class="pl-k">return</span> (<span class="pl-c1">0</span>, <span class="pl-s1">out</span>)


<span class="pl-k">def</span> <span class="pl-v">SSHConnect</span>(<span class="pl-s1">ip</span>,<span class="pl-s1">username</span>, <span class="pl-s1">passowrd</span>):
    <span class="pl-s1">ssh</span> <span class="pl-c1">=</span> <span class="pl-s1">paramiko</span>.<span class="pl-v">SSHClient</span>()
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s1">msg</span><span class="pl-c1">=</span><span class="pl-s">"Open SSH Client to :"</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">ip</span>))
    <span class="pl-k">try</span>:
        <span class="pl-s1">ssh</span>.<span class="pl-en">set_missing_host_key_policy</span>(<span class="pl-s1">policy</span><span class="pl-c1">=</span><span class="pl-s1">paramiko</span>.<span class="pl-v">AutoAddPolicy</span>())
        <span class="pl-s1">ssh</span>.<span class="pl-en">connect</span>(<span class="pl-s1">ip</span>, <span class="pl-s1">port</span><span class="pl-c1">=</span><span class="pl-c1">22</span>, <span class="pl-s1">username</span><span class="pl-c1">=</span><span class="pl-s1">username</span>, <span class="pl-s1">password</span><span class="pl-c1">=</span><span class="pl-s1">passowrd</span>, <span class="pl-s1">allow_agent</span><span class="pl-c1">=</span><span class="pl-c1">False</span>, <span class="pl-s1">look_for_keys</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
    <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s1">msg</span><span class="pl-c1">=</span><span class="pl-s">"SSH Client wasn't established!"</span>)
        <span class="pl-s1">sys</span>.<span class="pl-en">exit</span>(<span class="pl-c1">0</span>)
    <span class="pl-k">return</span> <span class="pl-s1">ssh</span>

<span class="pl-k">def</span> <span class="pl-v">ChangeToShellMode</span>(<span class="pl-s1">shell</span>):
    <span class="pl-c">#result should be '0'</span>
    <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-en">run_enable_configure_terminal</span>(<span class="pl-s1">shell</span>)
    <span class="pl-k">if</span> <span class="pl-en">int</span>(<span class="pl-s1">result</span>) <span class="pl-c1">!=</span> <span class="pl-c1">0</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Can't run <span class="pl-cce">\'</span>_shell<span class="pl-cce">\'</span> command..<span class="pl-cce">\n</span>"</span> <span class="pl-c1">+</span> <span class="pl-s">"exiting"</span>)
        <span class="pl-en">exit</span>(<span class="pl-c1">1</span>)
    <span class="pl-k">else</span>:
        <span class="pl-s1">command</span> <span class="pl-c1">=</span> <span class="pl-s">"_shell"</span>
        <span class="pl-s1">expect</span> <span class="pl-c1">=</span> <span class="pl-s">'~]#'</span>
        <span class="pl-k">try</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Changing UFM APL from CLI Mode to SHELL mode"</span>)
            <span class="pl-s1">result</span>, <span class="pl-s1">output</span> <span class="pl-c1">=</span> <span class="pl-en">run_par_cmd</span>(<span class="pl-s1">cmd</span><span class="pl-c1">=</span><span class="pl-s1">command</span>, <span class="pl-s1">expect</span><span class="pl-c1">=</span><span class="pl-s1">expect</span>, <span class="pl-s1">shell</span><span class="pl-c1">=</span><span class="pl-s1">shell</span>)
        <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Got Exception while trying to change for SHELL mode"</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">ex</span>))
        <span class="pl-k">if</span> <span class="pl-en">int</span>(<span class="pl-s1">result</span>) <span class="pl-c1">==</span> <span class="pl-c1">0</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"_shell command was executed successfully!"</span>)
        <span class="pl-k">else</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"couldn't find expected output while running shell command..<span class="pl-cce">\n</span>Please make sure License is installed!"</span>)

<span class="pl-k">def</span> <span class="pl-en">get_ram_total_used</span>(<span class="pl-s1">output</span>, <span class="pl-s1">regex_ram</span>, <span class="pl-s1">counter</span>):
    <span class="pl-s1">matches</span> <span class="pl-c1">=</span> <span class="pl-en">findRegex</span>(<span class="pl-s1">output</span>, <span class="pl-s1">regex_ram</span>)
    <span class="pl-k">if</span> <span class="pl-s1">matches</span>:
        <span class="pl-s1">cpu_value_total</span>, <span class="pl-s1">cpu_value_used</span> <span class="pl-c1">=</span> <span class="pl-s1">matches</span>[<span class="pl-c1">0</span>][<span class="pl-c1">2</span>], <span class="pl-s1">matches</span>[<span class="pl-c1">0</span>][<span class="pl-c1">4</span>]
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-en">str</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">+</span> <span class="pl-s">"# RAM value is :<span class="pl-cce">\t</span>"</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>((<span class="pl-en">float</span>(<span class="pl-s1">cpu_value_used</span>)<span class="pl-c1">/</span><span class="pl-en">float</span>(<span class="pl-s1">cpu_value_total</span>))<span class="pl-c1">*</span><span class="pl-c1">100</span>)<span class="pl-c1">+</span><span class="pl-s">'%'</span>)
        <span class="pl-k">return</span> <span class="pl-en">float</span>(<span class="pl-s1">cpu_value_used</span>)<span class="pl-c1">/</span><span class="pl-en">float</span>(<span class="pl-s1">cpu_value_total</span>)
    <span class="pl-k">else</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Couldn't retrived RAM usage according to given regex!"</span>)
        <span class="pl-k">return</span> <span class="pl-c1">-</span><span class="pl-c1">1</span>

<span class="pl-k">def</span> <span class="pl-v">GetRAMUsage</span>(<span class="pl-s1">shell</span> ,<span class="pl-s1">counter</span>):
    <span class="pl-s1">command</span> <span class="pl-c1">=</span> <span class="pl-s">r"""free -t"""</span>
    <span class="pl-s1">expected</span> <span class="pl-c1">=</span> <span class="pl-s">'total'</span>
    <span class="pl-s1">mode</span> <span class="pl-c1">=</span><span class="pl-s">'a'</span>
    <span class="pl-s1">regex_ram</span> <span class="pl-c1">=</span> <span class="pl-s">r'([Total:]{6})(\s*)(\d*)(\s*)(\d*)'</span>
    <span class="pl-k">if</span> <span class="pl-s1">counter</span> <span class="pl-c1">==</span> <span class="pl-c1">0</span>:
        <span class="pl-s1">mode</span> <span class="pl-c1">=</span> <span class="pl-s">'w'</span>

    <span class="pl-c">#file = os.path.realpath(__file__) + os.sep + '..' + os.sep + os.path.join('csv' , 'RestAPI_loop_ram.csv')</span>
    <span class="pl-k">with</span> <span class="pl-en">open</span>(<span class="pl-s1">global_ram_path</span>, <span class="pl-s1">mode</span>, <span class="pl-s1">newline</span><span class="pl-c1">=</span><span class="pl-s">''</span>) <span class="pl-k">as</span> <span class="pl-s1">csvfile</span>:
        <span class="pl-s1">fieldnames</span> <span class="pl-c1">=</span> [<span class="pl-s">'iteration number'</span>, <span class="pl-s">'RAM'</span>]
        <span class="pl-s1">writer</span> <span class="pl-c1">=</span> <span class="pl-s1">csv</span>.<span class="pl-v">DictWriter</span>(<span class="pl-s1">csvfile</span>, <span class="pl-s1">fieldnames</span><span class="pl-c1">=</span><span class="pl-s1">fieldnames</span>)
        <span class="pl-s1">time_started</span> <span class="pl-c1">=</span> <span class="pl-s1">datetime</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()
        <span class="pl-k">try</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Measuring RAM USage..."</span>)
            <span class="pl-s1">result</span>, <span class="pl-s1">output</span> <span class="pl-c1">=</span> <span class="pl-en">run_par_cmd</span>(<span class="pl-s1">cmd</span><span class="pl-c1">=</span><span class="pl-s1">command</span>, <span class="pl-s1">expect</span><span class="pl-c1">=</span><span class="pl-s1">expected</span>, <span class="pl-s1">shell</span><span class="pl-c1">=</span><span class="pl-s1">shell</span>)
        <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Got Exception while trying to retrieve RAM utilization , "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">ex</span>))
            <span class="pl-en">print</span>(<span class="pl-s">'Error on line {}'</span>.<span class="pl-en">format</span>(<span class="pl-s1">sys</span>.<span class="pl-en">exc_info</span>()[<span class="pl-c1">-</span><span class="pl-c1">1</span>].<span class="pl-s1">tb_lineno</span>), <span class="pl-en">type</span>(<span class="pl-s1">ex</span>).<span class="pl-s1">__name__</span>, <span class="pl-s1">ex</span>)
        <span class="pl-k">else</span>:
            <span class="pl-k">if</span> <span class="pl-en">int</span>(<span class="pl-s1">result</span>) <span class="pl-c1">==</span> <span class="pl-c1">0</span>:
                <span class="pl-s1">logging</span>.<span class="pl-en">debug</span>( <span class="pl-en">str</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">+</span><span class="pl-s">"# get RAM command was executed successfully!"</span>)
            <span class="pl-k">else</span>:
                <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"couldn't find expected output while running <span class="pl-cce">\'</span>free -t<span class="pl-cce">\'</span> command..<span class="pl-cce">\n</span>"</span>)
                <span class="pl-en">print</span>(<span class="pl-s">"expected: "</span> <span class="pl-c1">+</span> <span class="pl-s1">expected</span> <span class="pl-c1">+</span> <span class="pl-s">'<span class="pl-cce">\n</span>'</span> <span class="pl-c1">+</span><span class="pl-s">"Output : <span class="pl-cce">\n</span>"</span> <span class="pl-c1">+</span> <span class="pl-s1">output</span><span class="pl-c1">+</span><span class="pl-s">'<span class="pl-cce">\n</span><span class="pl-cce">\n</span>'</span>)
                <span class="pl-k">return</span> <span class="pl-c1">None</span>
            <span class="pl-s1">ram_total</span> <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-en">get_ram_total_used</span>(<span class="pl-s1">output</span>, <span class="pl-s1">regex_ram</span>, <span class="pl-s1">counter</span>))
            <span class="pl-k">if</span>  <span class="pl-en">str</span>(<span class="pl-s1">ram_total</span>) <span class="pl-c1">==</span> <span class="pl-s">'-1'</span> :
                <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Couldn't calculate RAM usage"</span>)
                <span class="pl-k">return</span> <span class="pl-c1">None</span>
            <span class="pl-k">else</span>:
                <span class="pl-s1">writer</span>.<span class="pl-en">writerow</span>({<span class="pl-s">'iteration number'</span>: <span class="pl-s1">counter</span>, <span class="pl-s">'RAM'</span>: <span class="pl-en">str</span>(<span class="pl-en">float</span>(<span class="pl-s1">ram_total</span>)<span class="pl-c1">*</span><span class="pl-c1">100</span>)})
        <span class="pl-s1">csvfile</span>.<span class="pl-en">close</span>()

<span class="pl-k">def</span> <span class="pl-v">GetCPUUsage</span>(<span class="pl-s1">shell</span>, <span class="pl-s1">counter</span>):
    <span class="pl-s1">command</span> <span class="pl-c1">=</span> <span class="pl-s">r"""grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'"""</span>
    <span class="pl-s1">expected</span> <span class="pl-c1">=</span> <span class="pl-s">'%'</span>
    <span class="pl-s1">regex</span> <span class="pl-c1">=</span> <span class="pl-s">r'[0-1]{1}\.{1}[0-9]*'</span>
    <span class="pl-s1">mode</span> <span class="pl-c1">=</span><span class="pl-s">'a'</span>
    <span class="pl-k">if</span> <span class="pl-s1">counter</span> <span class="pl-c1">==</span> <span class="pl-c1">0</span>:
        <span class="pl-s1">mode</span> <span class="pl-c1">=</span> <span class="pl-s">'w'</span>
    <span class="pl-c">#file = os.path.realpath(__file__) + os.sep + '..' + os.sep +  os.path.join( 'csv', 'RestAPI_loop_cpu.csv')</span>
    <span class="pl-k">with</span> <span class="pl-en">open</span>(<span class="pl-s1">global_cpu_path</span> ,<span class="pl-s1">mode</span><span class="pl-c1">=</span><span class="pl-s1">mode</span>, <span class="pl-s1">newline</span><span class="pl-c1">=</span><span class="pl-s">''</span>) <span class="pl-k">as</span> <span class="pl-s1">csvfile</span>:
        <span class="pl-s1">fieldnames</span> <span class="pl-c1">=</span> [<span class="pl-s">'iteration number'</span>, <span class="pl-s">'CPU'</span>]
        <span class="pl-s1">writer</span> <span class="pl-c1">=</span> <span class="pl-s1">csv</span>.<span class="pl-v">DictWriter</span>(<span class="pl-s1">csvfile</span>, <span class="pl-s1">fieldnames</span><span class="pl-c1">=</span><span class="pl-s1">fieldnames</span>)
        <span class="pl-s1">time_started</span> <span class="pl-c1">=</span> <span class="pl-s1">datetime</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()
        <span class="pl-k">try</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Measuring CPU USage..."</span>)
            <span class="pl-s1">result</span>, <span class="pl-s1">output</span> <span class="pl-c1">=</span> <span class="pl-en">run_par_cmd</span>(<span class="pl-s1">cmd</span><span class="pl-c1">=</span><span class="pl-s1">command</span>, <span class="pl-s1">expect</span><span class="pl-c1">=</span><span class="pl-s1">expected</span>, <span class="pl-s1">shell</span><span class="pl-c1">=</span><span class="pl-s1">shell</span>)
        <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Got Exception while trying to retrieve CPU utilization , "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">ex</span>))
        <span class="pl-k">else</span>:
            <span class="pl-k">if</span> <span class="pl-en">int</span>(<span class="pl-s1">result</span>) <span class="pl-c1">==</span> <span class="pl-c1">0</span>:
                <span class="pl-s1">logging</span>.<span class="pl-en">debug</span>(<span class="pl-s">"CPU command was executed successfully!"</span>)
            <span class="pl-k">else</span>:
                <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"couldn't find expected output while running CPU command.."</span>)
                <span class="pl-k">return</span> <span class="pl-c1">None</span>
            <span class="pl-s1">cpu_value</span> <span class="pl-c1">=</span> <span class="pl-en">findRegex</span>(<span class="pl-s1">output</span> ,<span class="pl-s1">regex</span>)
            <span class="pl-k">if</span> <span class="pl-s1">cpu_value</span>:
                <span class="pl-s1">cpu_value_flt</span> <span class="pl-c1">=</span> <span class="pl-en">float</span>(<span class="pl-s1">cpu_value</span>[<span class="pl-c1">0</span>])
                <span class="pl-k">if</span> <span class="pl-c1">0.0</span> <span class="pl-c1">&lt;=</span> <span class="pl-s1">cpu_value_flt</span> <span class="pl-c1">&lt;=</span> <span class="pl-c1">100.0</span>:
                <span class="pl-c">#if cpu_value_str &lt;= 100.0 and cpu_value_str &gt;= 0.0:</span>
                    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>( <span class="pl-en">str</span>(<span class="pl-s1">counter</span>)<span class="pl-c1">+</span> <span class="pl-s">"# CPU usage is:<span class="pl-cce">\t</span> "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">cpu_value_flt</span>) <span class="pl-c1">+</span> <span class="pl-s">'%'</span>)
                    <span class="pl-s1">writer</span>.<span class="pl-en">writerow</span>({<span class="pl-s">'iteration number'</span>: <span class="pl-en">str</span>(<span class="pl-s1">counter</span>), <span class="pl-s">'CPU'</span>: <span class="pl-en">str</span>(<span class="pl-s1">cpu_value_flt</span><span class="pl-c1">*</span><span class="pl-c1">100</span>)})
                <span class="pl-k">else</span>:
                    <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Not Matched Regex!<span class="pl-cce">\n</span>Couldn't retrevied CPU usage according to given regex!"</span>)
            <span class="pl-k">else</span>:
                <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Couldn't retrieved CPU usage!"</span>)
        <span class="pl-s1">csvfile</span>.<span class="pl-en">close</span>()

<span class="pl-k">def</span> <span class="pl-en">messurement_host_performance</span>(<span class="pl-s1">shells</span>, <span class="pl-s1">loops</span>):

    <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
    <span class="pl-s1">lst</span> <span class="pl-c1">=</span> []

    <span class="pl-k">while</span> <span class="pl-s1">stop</span> <span class="pl-c1">==</span> <span class="pl-c1">False</span>:
        <span class="pl-k">try</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">debug</span>(<span class="pl-s">"Running CPU/RAM performance test #"</span><span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">i</span>))
            <span class="pl-s1">t1</span> <span class="pl-c1">=</span> <span class="pl-s1">threading</span>.<span class="pl-v">Thread</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-v">GetCPUUsage</span>,  <span class="pl-s1">args</span><span class="pl-c1">=</span>(<span class="pl-s1">shells</span>[<span class="pl-c1">0</span>],<span class="pl-s1">i</span>))
            <span class="pl-s1">t2</span> <span class="pl-c1">=</span> <span class="pl-s1">threading</span>.<span class="pl-v">Thread</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-v">GetRAMUsage</span>, <span class="pl-s1">args</span><span class="pl-c1">=</span>(<span class="pl-s1">shells</span>[<span class="pl-c1">1</span>],<span class="pl-s1">i</span>))
            <span class="pl-s1">t1</span>.<span class="pl-en">start</span>()
            <span class="pl-s1">t2</span>.<span class="pl-en">start</span>()
            <span class="pl-s1">t1</span>.<span class="pl-en">join</span>()
            <span class="pl-s1">t2</span>.<span class="pl-en">join</span>()
            <span class="pl-s1">i</span><span class="pl-c1">+=</span><span class="pl-c1">1</span>
        <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Exception on starting thread"</span> <span class="pl-c1">+</span> <span class="pl-s1">ex</span>)
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Performance measurement is completed!"</span>)

<span class="pl-k">def</span> <span class="pl-en">run_enable_configure_terminal</span>(<span class="pl-s1">shell</span>):
    <span class="pl-s1">commandsList</span> <span class="pl-c1">=</span> [<span class="pl-s">'enable'</span> , <span class="pl-s">'configure terminal'</span>]
    <span class="pl-s1">expectedList</span> <span class="pl-c1">=</span> [<span class="pl-s">'#'</span>, <span class="pl-s">'(config)'</span>]
    <span class="pl-k">for</span> <span class="pl-s1">cmd</span>,<span class="pl-s1">expect</span> <span class="pl-c1">in</span> <span class="pl-en">zip</span>(<span class="pl-s1">commandsList</span>,<span class="pl-s1">expectedList</span>):
        <span class="pl-s1">result</span>, <span class="pl-s1">output</span> <span class="pl-c1">=</span> <span class="pl-en">run_par_cmd</span>(<span class="pl-s1">cmd</span><span class="pl-c1">=</span><span class="pl-s1">cmd</span>, <span class="pl-s1">expect</span><span class="pl-c1">=</span><span class="pl-s1">expect</span>, <span class="pl-s1">shell</span><span class="pl-c1">=</span><span class="pl-s1">shell</span>)
        <span class="pl-k">if</span> ((<span class="pl-en">int</span>(<span class="pl-s1">result</span>) <span class="pl-c1">==</span> <span class="pl-c1">0</span> )<span class="pl-c1">and</span> (<span class="pl-en">len</span>(<span class="pl-s1">output</span>) <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span> )):
            <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s1">cmd</span><span class="pl-c1">+</span> <span class="pl-s">" command run successfully"</span>)
        <span class="pl-k">else</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"can't run "</span><span class="pl-c1">+</span><span class="pl-s1">cmd</span><span class="pl-c1">+</span><span class="pl-s">" command"</span>)
            <span class="pl-s1">sys</span>.<span class="pl-en">exit</span>(<span class="pl-c1">1</span>)
    <span class="pl-k">return</span> <span class="pl-c1">False</span>

<span class="pl-k">def</span> <span class="pl-en">get_vmsize_of_process_by_process_id</span>(<span class="pl-s1">shell</span>, <span class="pl-s1">process_vm</span>):
    <span class="pl-s1">cmd</span> <span class="pl-c1">=</span> <span class="pl-s">'cat /proc/x/status'</span>
    <span class="pl-s1">cmd</span> <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-s1">cmd</span>).<span class="pl-en">replace</span>(<span class="pl-s">'x'</span>,<span class="pl-s1">process_vm</span>)
    <span class="pl-s1">expected</span> <span class="pl-c1">=</span> <span class="pl-s">'VmSize'</span>
    <span class="pl-s1">regex_search</span><span class="pl-c1">=</span><span class="pl-s">'(VmSize:)(\s*)(\d*)(\s*)(kB)'</span>
    <span class="pl-s1">vm_size</span> <span class="pl-c1">=</span> <span class="pl-c1">None</span>

    <span class="pl-s1">result</span>, <span class="pl-s1">output</span> <span class="pl-c1">=</span> <span class="pl-en">run_par_cmd</span>(<span class="pl-s1">cmd</span>, <span class="pl-s1">expected</span>,<span class="pl-s1">shell</span>)
    <span class="pl-k">if</span> ((<span class="pl-en">int</span>(<span class="pl-s1">result</span>) <span class="pl-c1">==</span> <span class="pl-c1">0</span>) <span class="pl-c1">and</span> (<span class="pl-en">len</span>(<span class="pl-s1">output</span>) <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span>)):
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s1">cmd</span> <span class="pl-c1">+</span> <span class="pl-s">" command run successfully"</span>)
    <span class="pl-k">else</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"can't run "</span> <span class="pl-c1">+</span> <span class="pl-s1">cmd</span> <span class="pl-c1">+</span> <span class="pl-s">" command"</span>)
        <span class="pl-s1">sys</span>.<span class="pl-en">exit</span>(<span class="pl-c1">1</span>)
    <span class="pl-s1">matches</span> <span class="pl-c1">=</span> <span class="pl-en">findRegex</span>(<span class="pl-s1">output</span>, <span class="pl-s1">regex_search</span>)
    <span class="pl-k">if</span> <span class="pl-s1">matches</span>:
        <span class="pl-s1">vm_size</span> <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-s1">matches</span>[<span class="pl-c1">0</span>][<span class="pl-c1">2</span>])
    <span class="pl-k">else</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"No matches were found for vmsize"</span>)
    <span class="pl-k">return</span> <span class="pl-s1">vm_size</span>
<span class="pl-k">def</span> <span class="pl-en">continue_loop</span>(<span class="pl-s1">counter</span>,<span class="pl-s1">started_time</span>, <span class="pl-s1">loops</span>, <span class="pl-s1">time</span>):
    <span class="pl-k">if</span> <span class="pl-s1">time</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-c1">None</span>:
        <span class="pl-k">if</span> (<span class="pl-s1">started_time</span> <span class="pl-c1">+</span> <span class="pl-s1">datetime</span>.<span class="pl-en">timedelta</span>(<span class="pl-s1">hours</span><span class="pl-c1">=</span><span class="pl-en">int</span>(<span class="pl-s1">time</span>)) <span class="pl-c1">&gt;</span> <span class="pl-s1">datetime</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()):
            <span class="pl-k">return</span> <span class="pl-c1">True</span>
        <span class="pl-k">else</span>:
            <span class="pl-k">return</span> <span class="pl-c1">False</span>
    <span class="pl-k">else</span>:
        <span class="pl-k">if</span> <span class="pl-s1">loops</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-c1">None</span>:
            <span class="pl-k">if</span> (<span class="pl-en">int</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">&lt;</span> <span class="pl-en">int</span>(<span class="pl-s1">loops</span>)):
                <span class="pl-k">return</span> <span class="pl-c1">True</span>
            <span class="pl-k">else</span>:
                <span class="pl-k">return</span> <span class="pl-c1">False</span>
<span class="pl-k">def</span> <span class="pl-en">send_ufm_rest_get_pkey</span>(<span class="pl-s1">shell</span>, <span class="pl-s1">ip</span>, <span class="pl-s1">username</span>, <span class="pl-s1">password</span>, <span class="pl-s1">private_key_path</span>,<span class="pl-s1">certificate_path</span>):

    <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s">r'http://ip/ufmRest/resources/pkeys'</span>
    <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s1">url</span>.<span class="pl-en">replace</span>(<span class="pl-s">'ip'</span>,<span class="pl-s1">ip</span>)
    <span class="pl-s1">payload</span> <span class="pl-c1">=</span> <span class="pl-s">r'''{</span>
<span class="pl-s">          "pkey": "0x1",</span>
<span class="pl-s">          "index0": false,</span>
<span class="pl-s">          "ip_over_ib": true,</span>
<span class="pl-s">          "membership": "full",</span>
<span class="pl-s">          "guids": [</span>
<span class="pl-s">    "98039b0300671ec0"</span>
<span class="pl-s">  ]</span>
<span class="pl-s">}'''</span>
    <span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s1">requests</span>.<span class="pl-en">session</span>()
    <span class="pl-s1">s</span>.<span class="pl-s1">auth</span> <span class="pl-c1">=</span> (<span class="pl-s1">username</span>, <span class="pl-s1">password</span>)
    <span class="pl-k">if</span> ((<span class="pl-s1">private_key_path</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-c1">None</span>) <span class="pl-c1">and</span> (<span class="pl-s1">certificate_path</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-c1">None</span>)):
        <span class="pl-c"># Using SSL certification</span>
        <span class="pl-s1">s</span>.<span class="pl-s1">cert</span> <span class="pl-c1">=</span> (<span class="pl-s1">certificate_path</span>, <span class="pl-s1">private_key_path</span>)
    <span class="pl-k">else</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Using Basic Authentication"</span>)

    <span class="pl-k">try</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"creating new pkey with rest request "</span>)
        <span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-en">post</span>(<span class="pl-s1">url</span><span class="pl-c1">=</span><span class="pl-s1">url</span>, <span class="pl-s1">data</span><span class="pl-c1">=</span><span class="pl-s1">payload</span>)
    <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">e</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"exception in UFM rest request"</span>)
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"creating new pkey with rest request was send successfully."</span>)
    <span class="pl-k">return</span> <span class="pl-s1">r</span>

<span class="pl-k">def</span> <span class="pl-en">run_rest_in_loop</span>(<span class="pl-s1">shell</span>,<span class="pl-s1">ip</span>, <span class="pl-s1">prodcut_type</span>, <span class="pl-s1">loops</span>,<span class="pl-s1">time</span>, <span class="pl-s1">username</span>, <span class="pl-s1">password</span>, <span class="pl-s1">private_key_path</span>, <span class="pl-s1">certificate_path</span>):
    <span class="pl-s1">counter</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
    <span class="pl-s1">success</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
    <span class="pl-s1">time_started</span> <span class="pl-c1">=</span> <span class="pl-s1">datetime</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()

    <span class="pl-c">#file = os.path.realpath(__file__) + os.sep +'..' + os.sep + os.path.join('csv', 'RestAPI_loop_requests.csv')</span>
    <span class="pl-k">with</span> <span class="pl-en">open</span>(<span class="pl-s1">global_requests_path</span>, <span class="pl-s">'w'</span>, <span class="pl-s1">newline</span><span class="pl-c1">=</span><span class="pl-s">''</span>) <span class="pl-k">as</span> <span class="pl-s1">csvfile</span>:
        <span class="pl-s1">fieldnames</span> <span class="pl-c1">=</span> [<span class="pl-s">'iteration number'</span>, <span class="pl-s">'time'</span>, <span class="pl-s">'Response Code'</span>, <span class="pl-s">'Succeeded'</span>]
        <span class="pl-s1">writer</span> <span class="pl-c1">=</span> <span class="pl-s1">csv</span>.<span class="pl-v">DictWriter</span>(<span class="pl-s1">csvfile</span>, <span class="pl-s1">fieldnames</span><span class="pl-c1">=</span><span class="pl-s1">fieldnames</span>)
        <span class="pl-k">while</span> <span class="pl-en">continue_loop</span>(<span class="pl-s1">counter</span>,<span class="pl-s1">time_started</span>,<span class="pl-s1">loops</span>,<span class="pl-s1">time</span>):
            <span class="pl-s1">request_send_time</span> <span class="pl-c1">=</span> <span class="pl-s1">datetime</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()
            <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-en">str</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">+</span> <span class="pl-s">"# sending Rest request"</span>)
            <span class="pl-s1">counter</span> <span class="pl-c1">+=</span> <span class="pl-c1">1</span>
            <span class="pl-k">try</span>:
                <span class="pl-k">if</span> (<span class="pl-s1">prodcut_type</span> <span class="pl-c1">==</span> <span class="pl-s">'ufm'</span>):
                    <span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-en">send_ufm_rest_get_pkey</span>(<span class="pl-s1">shell</span>,<span class="pl-s1">ip</span>,<span class="pl-s1">username</span>,<span class="pl-s1">password</span>,<span class="pl-s1">private_key_path</span>,<span class="pl-s1">certificate_path</span>)
                <span class="pl-k">elif</span> (<span class="pl-s1">prodcut_type</span> <span class="pl-c1">==</span> <span class="pl-s">'neo'</span>):
                    <span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-en">send_neo_ports_rest_api</span>(<span class="pl-s1">ip</span>)
                    <span class="pl-c">#TODO - missing UFM Aplliance Rest</span>
            <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
                <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Exception on sending REST request"</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">+</span> <span class="pl-s">"<span class="pl-cce">\n</span>"</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">ex</span>))
                <span class="pl-s1">sys</span>.<span class="pl-en">exit</span>(<span class="pl-c1">1</span>)
            <span class="pl-s1">request_end_time</span> <span class="pl-c1">=</span> <span class="pl-s1">datetime</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()
            <span class="pl-s1">total_requst_time</span> <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-s1">request_end_time</span> <span class="pl-c1">-</span> <span class="pl-s1">request_send_time</span>)
            <span class="pl-s1">request_status_code</span> <span class="pl-c1">=</span> <span class="pl-s1">r</span>.<span class="pl-s1">status_code</span>
            <span class="pl-k">if</span> (<span class="pl-en">str</span>(<span class="pl-s1">r</span>.<span class="pl-s1">status_code</span>) <span class="pl-c1">==</span> <span class="pl-s">'200'</span>):
                <span class="pl-s1">success</span> <span class="pl-c1">+=</span> <span class="pl-c1">1</span>
                <span class="pl-s1">writer</span>.<span class="pl-en">writerow</span>(
                    {<span class="pl-s">'iteration number'</span>: <span class="pl-en">str</span>(<span class="pl-s1">counter</span>), <span class="pl-s">'time'</span>: <span class="pl-en">str</span>(<span class="pl-s1">time_started</span>), <span class="pl-s">'Response Code'</span>: <span class="pl-en">str</span>(<span class="pl-s1">request_status_code</span>),
                     <span class="pl-s">'Succeeded'</span>: <span class="pl-s">'Yes'</span>})
                <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Total time for request #"</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">+</span> <span class="pl-s">" is<span class="pl-cce">\t</span><span class="pl-cce">\t</span><span class="pl-cce">\t</span> "</span> <span class="pl-c1">+</span> <span class="pl-s1">total_requst_time</span>)
            <span class="pl-k">else</span>:
                <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Request # "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">+</span> <span class="pl-s">" Failed!"</span> <span class="pl-c1">+</span> <span class="pl-s">"Status Code is: "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">request_status_code</span>))
                <span class="pl-s1">writer</span>.<span class="pl-en">writerow</span>(
                    {<span class="pl-s">'iteration number'</span>: <span class="pl-s1">counter</span>, <span class="pl-s">'time'</span>: <span class="pl-s1">total_requst_time</span>, <span class="pl-s">'Response Code'</span>: <span class="pl-s1">request_status_code</span>,
                     <span class="pl-s">'Succeeded'</span>: <span class="pl-s">'No'</span>})
        <span class="pl-s1">csvfile</span>.<span class="pl-en">close</span>()
    <span class="pl-s1">end_time</span> <span class="pl-c1">=</span> <span class="pl-s1">datetime</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()
    <span class="pl-s1">total_time</span> <span class="pl-c1">=</span> <span class="pl-s1">end_time</span> <span class="pl-c1">-</span> <span class="pl-s1">time_started</span>
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Total time for "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">+</span> <span class="pl-s">' loops'</span> <span class="pl-c1">+</span> <span class="pl-s">" was<span class="pl-cce">\t</span><span class="pl-cce">\t</span><span class="pl-cce">\t</span>"</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">total_time</span>) <span class="pl-c1">+</span> <span class="pl-s">"<span class="pl-cce">\t</span><span class="pl-cce">\t</span>Number of Success Requests:<span class="pl-cce">\t</span> "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">success</span>) <span class="pl-c1">+</span> <span class="pl-s">"/"</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">counter</span>))
    <span class="pl-k">global</span> <span class="pl-s1">stop</span>
    <span class="pl-s1">stop</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>


<span class="pl-k">def</span> <span class="pl-en">virtual_memory_of_processes</span>(<span class="pl-s1">shell</span>, <span class="pl-s1">loops</span>, <span class="pl-s1">product_type</span>):
    <span class="pl-s1">base_regex</span> <span class="pl-c1">=</span> <span class="pl-s">r"""(\s{3,6})(\d{4,6})(\s{3,6})(\d*)(\s*)(\d*)(.*)(ufm/)(.*)"""</span>
    <span class="pl-k">global</span> <span class="pl-s1">ufm_processes_name_list</span>
    <span class="pl-s1">logging</span>.<span class="pl-en">debug</span>(<span class="pl-s">" Running ps -ef command to check running processes"</span>)
    <span class="pl-s1">expected</span> <span class="pl-c1">=</span> <span class="pl-s1">product_type</span>
    <span class="pl-s1">command</span> <span class="pl-c1">=</span> <span class="pl-s">'ps -ef | grep '</span><span class="pl-c1">+</span> <span class="pl-s1">product_type</span>
    <span class="pl-s1">i</span><span class="pl-c1">=</span><span class="pl-c1">0</span>

    <span class="pl-k">while</span> <span class="pl-s1">stop</span> <span class="pl-c1">==</span> <span class="pl-c1">False</span>:
        <span class="pl-k">try</span>:
            <span class="pl-s1">result</span>, <span class="pl-s1">output</span> <span class="pl-c1">=</span> <span class="pl-en">run_par_cmd</span>(<span class="pl-s1">cmd</span><span class="pl-c1">=</span><span class="pl-s1">command</span>, <span class="pl-s1">expect</span><span class="pl-c1">=</span><span class="pl-s1">expected</span>, <span class="pl-s1">shell</span><span class="pl-c1">=</span><span class="pl-s1">shell</span>)
        <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"exception in ps -ef command"</span>)
        <span class="pl-k">if</span> <span class="pl-en">int</span>(<span class="pl-s1">result</span>) <span class="pl-c1">!=</span> <span class="pl-c1">-</span><span class="pl-c1">1</span>:
            <span class="pl-k">for</span> <span class="pl-s1">process_name</span> <span class="pl-c1">in</span> <span class="pl-s1">ufm_processes_name_list</span>:
                <span class="pl-s1">regex_search</span> <span class="pl-c1">=</span> <span class="pl-s1">base_regex</span> <span class="pl-c1">+</span> <span class="pl-s">'('</span><span class="pl-c1">+</span><span class="pl-s1">process_name</span> <span class="pl-c1">+</span> <span class="pl-s">')'</span>
                <span class="pl-s1">matches</span> <span class="pl-c1">=</span> <span class="pl-en">findRegex</span>(<span class="pl-s1">output</span>, <span class="pl-s1">regex_search</span>)
                <span class="pl-k">if</span> <span class="pl-s1">matches</span>:
                    <span class="pl-s1">process_vm</span> <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-s1">matches</span>[<span class="pl-c1">0</span>][<span class="pl-c1">1</span>])
                    <span class="pl-s1">vm_size</span> <span class="pl-c1">=</span> <span class="pl-en">get_vmsize_of_process_by_process_id</span>(<span class="pl-s1">shell</span>, <span class="pl-s1">process_vm</span>)
                    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>( <span class="pl-en">str</span>(<span class="pl-s1">i</span>) <span class="pl-c1">+</span> <span class="pl-s">"# virtual memory of "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">process_name</span>) <span class="pl-c1">+</span> <span class="pl-s">" = "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">vm_size</span>))
                    <span class="pl-en">write_process_to_csv</span>(<span class="pl-s1">i</span>, <span class="pl-s1">process_name</span>,<span class="pl-s1">vm_size</span>)
                <span class="pl-k">else</span>:
                    <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"couldn't find process virtual memory according to given regex"</span>)
            <span class="pl-s1">i</span> <span class="pl-c1">+=</span> <span class="pl-c1">1</span>
        <span class="pl-k">else</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"couldn't find expected result in ps -ef command"</span>)
<span class="pl-k">def</span> <span class="pl-en">get_product_name_by_url</span>(<span class="pl-s1">url</span>):

    <span class="pl-k">if</span> <span class="pl-en">int</span>(<span class="pl-en">str</span>(<span class="pl-s1">url</span>).<span class="pl-en">find</span>(<span class="pl-s">'ufm'</span>)) <span class="pl-c1">!=</span> <span class="pl-c1">-</span><span class="pl-c1">1</span>:
        <span class="pl-k">return</span> <span class="pl-s">'ufm'</span>
    <span class="pl-k">elif</span> <span class="pl-en">int</span>(<span class="pl-en">str</span>(<span class="pl-s1">url</span>).<span class="pl-en">find</span>(<span class="pl-s">'neo'</span>)) <span class="pl-c1">!=</span> <span class="pl-c1">-</span><span class="pl-c1">1</span>:
        <span class="pl-k">return</span> <span class="pl-s">'neo'</span>
    <span class="pl-k">else</span>:
        <span class="pl-k">return</span> <span class="pl-c1">-</span><span class="pl-c1">1</span>

<span class="pl-k">def</span> <span class="pl-en">create_graphs</span>():
    <span class="pl-k">global</span> <span class="pl-s1">ufm_processes_name_list</span>
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Creating Graphs for processes"</span>)

    <span class="pl-s1">dt</span> <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-s1">datetime</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()).<span class="pl-en">split</span>(<span class="pl-s">"."</span>)[<span class="pl-c1">0</span>].<span class="pl-en">replace</span>(<span class="pl-s">" "</span>,<span class="pl-s">"_"</span>).<span class="pl-en">replace</span>(<span class="pl-s">":"</span>,<span class="pl-s">"-"</span>)
    <span class="pl-c">#Creating sub folder for graphs_time</span>
    <span class="pl-s1">current_graph_folder</span> <span class="pl-c1">=</span> <span class="pl-s1">global_graphs_path</span> <span class="pl-c1">+</span> <span class="pl-s1">dt</span> <span class="pl-c1">+</span> <span class="pl-s1">os</span>.<span class="pl-s1">sep</span>
    <span class="pl-en">creating_directory</span>(<span class="pl-s1">current_graph_folder</span>)

    <span class="pl-k">for</span> <span class="pl-s1">process_name</span> <span class="pl-c1">in</span> <span class="pl-s1">ufm_processes_name_list</span>:
        <span class="pl-s1">filename</span> <span class="pl-c1">=</span> <span class="pl-s1">global_csv_path</span> <span class="pl-c1">+</span> <span class="pl-s">'RestAPI_loop_'</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">process_name</span>) <span class="pl-c1">+</span> <span class="pl-s">'.csv'</span>
        <span class="pl-en">create_graph</span>(<span class="pl-s1">filename</span>, <span class="pl-en">str</span>(<span class="pl-s1">process_name</span>), <span class="pl-s">'VMSize(kb)'</span>,<span class="pl-s">'iterations'</span>,<span class="pl-s1">current_graph_folder</span>,<span class="pl-s1">process_name</span> )
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Creating Graphs for processes completed successfully"</span>)
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Creating Graphs for CPU/RAM usage"</span>)
    <span class="pl-k">for</span> <span class="pl-s1">name</span> <span class="pl-c1">in</span> (<span class="pl-s">'ram'</span>,<span class="pl-s">'cpu'</span>):
        <span class="pl-s1">filename</span> <span class="pl-c1">=</span> <span class="pl-s1">global_csv_path</span> <span class="pl-c1">+</span> <span class="pl-s">'RestAPI_loop_'</span> <span class="pl-c1">+</span> <span class="pl-s1">name</span> <span class="pl-c1">+</span> <span class="pl-s">'.csv'</span>
        <span class="pl-en">create_graph</span>(<span class="pl-s1">filename</span>, <span class="pl-en">str</span>(<span class="pl-s1">name</span>),  <span class="pl-s1">name</span> <span class="pl-c1">+</span><span class="pl-s">'(%)'</span>,<span class="pl-s">'iterations'</span>,<span class="pl-s1">current_graph_folder</span>,<span class="pl-s1">name</span>)

<span class="pl-k">def</span> <span class="pl-en">write_process_to_csv</span>(<span class="pl-s1">i</span>, <span class="pl-s1">process_name</span>,<span class="pl-s1">process_vm</span>):

    <span class="pl-c">#csv_path = os.path.realpath(__file__) + os.sep + '..' + os.sep + os.path.join('csv')</span>
    <span class="pl-s1">filename</span> <span class="pl-c1">=</span> <span class="pl-s1">global_csv_path</span> <span class="pl-c1">+</span> <span class="pl-s">'RestAPI_loop_'</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">process_name</span>)<span class="pl-c1">+</span> <span class="pl-s">'.csv'</span>
    <span class="pl-s1">mode</span> <span class="pl-c1">=</span> <span class="pl-s">'a'</span>
    <span class="pl-k">if</span> <span class="pl-s1">i</span> <span class="pl-c1">==</span> <span class="pl-c1">0</span>:
        <span class="pl-s1">mode</span> <span class="pl-c1">=</span> <span class="pl-s">'w'</span>
    <span class="pl-k">try</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">debug</span>(<span class="pl-s">"Trying to open "</span> <span class="pl-c1">+</span> <span class="pl-s1">filename</span> <span class="pl-c1">+</span> <span class="pl-s">" to write data"</span>)
        <span class="pl-k">with</span> <span class="pl-en">open</span>(<span class="pl-s1">file</span><span class="pl-c1">=</span><span class="pl-s1">filename</span>, <span class="pl-s1">mode</span><span class="pl-c1">=</span><span class="pl-s1">mode</span>, <span class="pl-s1">newline</span><span class="pl-c1">=</span><span class="pl-s">''</span>) <span class="pl-k">as</span> <span class="pl-s1">csvfile</span>:
            <span class="pl-s1">fieldnames</span> <span class="pl-c1">=</span> [<span class="pl-s">'iteration number'</span>, <span class="pl-s">'VMSize'</span>]
            <span class="pl-s1">writer</span> <span class="pl-c1">=</span> <span class="pl-s1">csv</span>.<span class="pl-v">DictWriter</span>(<span class="pl-s1">csvfile</span>, <span class="pl-s1">fieldnames</span><span class="pl-c1">=</span><span class="pl-s1">fieldnames</span>)
            <span class="pl-s1">writer</span>.<span class="pl-en">writerow</span>({<span class="pl-s">'iteration number'</span>: <span class="pl-s1">i</span>, <span class="pl-s">'VMSize'</span>: <span class="pl-s1">process_vm</span>})
    <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"exception while writing data into"</span> <span class="pl-c1">+</span> <span class="pl-s1">filename</span>)
        <span class="pl-s1">csvfile</span>.<span class="pl-en">close</span>()

<span class="pl-k">def</span> <span class="pl-en">thread_manager</span>(<span class="pl-s1">shells</span>,<span class="pl-s1">ip</span>, <span class="pl-s1">product_type</span>, <span class="pl-s1">loops</span>,<span class="pl-s1">time</span>, <span class="pl-s1">username</span>, <span class="pl-s1">password</span>, <span class="pl-s1">private_key_path</span>, <span class="pl-s1">certificate_path</span>,<span class="pl-s1">fabric_health</span>):
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"starting new thread: CPU/RAM Performance"</span>)
    <span class="pl-s1">t1</span> <span class="pl-c1">=</span> <span class="pl-s1">threading</span>.<span class="pl-v">Thread</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">messurement_host_performance</span>, <span class="pl-s1">args</span><span class="pl-c1">=</span>(<span class="pl-s1">shells</span>, <span class="pl-s1">loops</span>))
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Starting new thread: REST requests in loop"</span>)
    <span class="pl-s1">t2</span> <span class="pl-c1">=</span> <span class="pl-s1">threading</span>.<span class="pl-v">Thread</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">run_rest_in_loop</span>, <span class="pl-s1">args</span><span class="pl-c1">=</span>(<span class="pl-s1">shells</span>[<span class="pl-c1">2</span>],<span class="pl-s1">ip</span>, <span class="pl-s1">product_type</span>, <span class="pl-s1">loops</span>,<span class="pl-s1">time</span>, <span class="pl-s1">username</span>, <span class="pl-s1">password</span>, <span class="pl-s1">private_key_path</span>, <span class="pl-s1">certificate_path</span>))
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Measuring Processes virtual memory"</span>)
    <span class="pl-c">#product_type = get_product_name_by_url(url)</span>
    <span class="pl-s1">t3</span> <span class="pl-c1">=</span> <span class="pl-s1">threading</span>.<span class="pl-v">Thread</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">virtual_memory_of_processes</span>, <span class="pl-s1">args</span><span class="pl-c1">=</span>(<span class="pl-s1">shells</span>[<span class="pl-c1">3</span>], <span class="pl-s1">loops</span>, <span class="pl-s1">product_type</span>))
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Measuring Processes virtual memory"</span>)
    <span class="pl-k">if</span> <span class="pl-en">str</span>(<span class="pl-s1">fabric_health</span>) <span class="pl-c1">==</span> <span class="pl-s">'yes'</span>:
        <span class="pl-s1">t4</span> <span class="pl-c1">=</span> <span class="pl-s1">threading</span>.<span class="pl-v">Thread</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">create_ufm_health_report</span>, <span class="pl-s1">args</span><span class="pl-c1">=</span>(<span class="pl-s1">ip</span>, <span class="pl-s1">username</span>, <span class="pl-s1">password</span>))
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Starting Fabric health Reports"</span>)
        <span class="pl-s1">t4</span>.<span class="pl-en">start</span>()
    <span class="pl-s1">t5</span> <span class="pl-c1">=</span> <span class="pl-s1">threading</span>.<span class="pl-v">Thread</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">graphs_scheduler</span>, <span class="pl-s1">args</span><span class="pl-c1">=</span>())
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"start Thread to for creating graphs every one hour"</span>)

    <span class="pl-s1">t1</span>.<span class="pl-en">start</span>()
    <span class="pl-s1">t2</span>.<span class="pl-en">start</span>()
    <span class="pl-s1">t3</span>.<span class="pl-en">start</span>()
    <span class="pl-s1">t5</span>.<span class="pl-en">start</span>()


    <span class="pl-s1">t1</span>.<span class="pl-en">join</span>(<span class="pl-s1">timeout</span><span class="pl-c1">=</span><span class="pl-c1">300</span>)
    <span class="pl-s1">t2</span>.<span class="pl-en">join</span>(<span class="pl-s1">timeout</span><span class="pl-c1">=</span><span class="pl-c1">300</span>)
    <span class="pl-s1">t3</span>.<span class="pl-en">join</span>(<span class="pl-s1">timeout</span><span class="pl-c1">=</span><span class="pl-c1">300</span>)
    <span class="pl-k">if</span> <span class="pl-en">str</span>(<span class="pl-s1">fabric_health</span>) <span class="pl-c1">==</span> <span class="pl-s">'yes'</span>:
        <span class="pl-s1">t4</span>.<span class="pl-en">join</span>(<span class="pl-s1">timeout</span><span class="pl-c1">=</span><span class="pl-c1">300</span>)
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Threads are joined!"</span>)
<span class="pl-k">def</span> <span class="pl-en">send_neo_ports_rest_api</span>(<span class="pl-s1">neo_ip</span>):
    <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s">r'http://ip/neo/resources/ports?_=1543846564166&amp;tz=Asia/Jerusalem'</span>
    <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s1">url</span>.<span class="pl-en">replace</span>(<span class="pl-s">"ip"</span>, <span class="pl-s1">neo_ip</span>)
    <span class="pl-s1">cookie</span> <span class="pl-c1">=</span> {<span class="pl-s">"session"</span>:<span class="pl-s">".eJyrVopPK0otzlCyKikqTdVRis9MUbKqVlJIUrJS8guJyooMSTeJrEqv8HdJyY4Mycj2D3et9HfJNvILycnwC3c1jQqPrIrK8rVVqgXqLUgtyk3MS80rgZlWWpxaBDZRKTElNzNPqRYAE_clcg.DubaoQ.I0UVeS061HEHVhzFeOqLobiNhTk"</span>}
    <span class="pl-s1">payload</span> <span class="pl-c1">=</span> {<span class="pl-s">"_"</span>:<span class="pl-s">"1543846564166"</span>,<span class="pl-s">"tz"</span>:<span class="pl-s">"Asia/Jerusalem"</span>}
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"sending rest request for getting all ports #"</span>)
    <span class="pl-k">try</span>:
        <span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-s1">requests</span>.<span class="pl-en">get</span>(<span class="pl-s1">url</span><span class="pl-c1">=</span> <span class="pl-s1">url</span>, <span class="pl-s1">cookies</span><span class="pl-c1">=</span><span class="pl-s1">cookie</span>, <span class="pl-s1">payload</span><span class="pl-c1">=</span><span class="pl-s1">payload</span>)
    <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">e</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"exception when sending rest API to NEO for getting all ports"</span>)
        <span class="pl-k">return</span>
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Rest request for NEO succeeded."</span>)
    <span class="pl-k">return</span> <span class="pl-s1">r</span>

<span class="pl-k">def</span> <span class="pl-en">create_graph</span>(<span class="pl-s1">filepath</span> ,<span class="pl-s1">title</span>, <span class="pl-s1">ylabel</span>, <span class="pl-s1">xlabel</span>, <span class="pl-s1">current_graph_folder</span>, <span class="pl-s1">process_name</span>):
    <span class="pl-s1">style</span>.<span class="pl-en">use</span>(<span class="pl-s">'ggplot'</span>)
    <span class="pl-k">try</span>:
        <span class="pl-c">#filepath =</span>
        <span class="pl-c">#C:\Users\arielwe\PycharmProjects\SecurityProject\Rest_Loop_CPU_RAM\csv\RestAPI_loop_mysqld.csv</span>
        <span class="pl-c">#C:\Users\arielwe\PycharmProjects\SecurityProject\Rest_Loop_CPU_RAM\rest_loop_loading\csv\RestAPI_loop_mysqld.csv</span>
        <span class="pl-c">#C:\Users\arielwe\PycharmProjects\SecurityProject\Rest_Loop_CPU_RAM\rest_loop_loading\csv\RestAPI_loop_mysqld.csv'</span>
        <span class="pl-s1">x</span>,<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">loadtxt</span>(<span class="pl-s1">filepath</span>, <span class="pl-s1">unpack</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">delimiter</span><span class="pl-c1">=</span><span class="pl-s">','</span>)
    <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
        <span class="pl-en">print</span>(<span class="pl-s1">ex</span>)

    <span class="pl-s1">plt</span>.<span class="pl-en">title</span>(<span class="pl-s1">title</span>)
    <span class="pl-s1">plt</span>.<span class="pl-en">ylabel</span>(<span class="pl-s1">ylabel</span>)
    <span class="pl-s1">plt</span>.<span class="pl-en">xlabel</span>(<span class="pl-s1">xlabel</span>)
    <span class="pl-s1">plt</span>.<span class="pl-en">plot</span>(<span class="pl-s1">x</span>,<span class="pl-s1">y</span>)
    <span class="pl-s1">full_graph_path</span> <span class="pl-c1">=</span><span class="pl-s1">current_graph_folder</span> <span class="pl-c1">+</span> <span class="pl-s1">process_name</span> <span class="pl-c1">+</span> <span class="pl-s">".png"</span>
    <span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s1">full_graph_path</span>)
    <span class="pl-s1">plt</span>.<span class="pl-en">close</span>()

<span class="pl-k">def</span> <span class="pl-en">graphs_scheduler</span>():
    <span class="pl-en">sleep</span>(<span class="pl-c1">10</span>)
    <span class="pl-k">global</span> <span class="pl-s1">counter</span>
    <span class="pl-k">global</span> <span class="pl-s1">stop</span>
    <span class="pl-s1">counter</span><span class="pl-c1">+=</span><span class="pl-c1">1</span>
    <span class="pl-k">if</span> <span class="pl-s1">stop</span> <span class="pl-c1">!=</span> <span class="pl-c1">False</span>:
        <span class="pl-k">return</span> <span class="pl-c1">None</span>
    <span class="pl-k">else</span>:
        <span class="pl-s1">threading</span>.<span class="pl-v">Timer</span>(<span class="pl-c1">60</span>,<span class="pl-s1">graphs_scheduler</span>).<span class="pl-en">start</span>()
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Creating Graphs #"</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">counter</span>) <span class="pl-c1">+</span> <span class="pl-s">":  time is "</span> <span class="pl-c1">+</span><span class="pl-en">str</span>(<span class="pl-s1">datetime</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()))
        <span class="pl-en">create_graphs</span>()

<span class="pl-k">def</span> <span class="pl-en">get_payload_for_request</span>(<span class="pl-s1">payload</span>):
    <span class="pl-k">with</span> <span class="pl-en">open</span>(<span class="pl-s1">payload</span>) <span class="pl-k">as</span> <span class="pl-s1">json_data</span>:
        <span class="pl-k">try</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Parsing json payload from file..."</span>)
            <span class="pl-s1">json_obj</span> <span class="pl-c1">=</span> <span class="pl-s1">json</span>.<span class="pl-en">load</span>(<span class="pl-s1">json_data</span>)
        <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">ex</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Couldn't parse file to json object"</span>)
            <span class="pl-s1">sys</span>.<span class="pl-en">exit</span>(<span class="pl-c1">1</span>)
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"json file parsed successfully"</span>)
        <span class="pl-s1">json_data</span>.<span class="pl-en">close</span>()
        <span class="pl-k">return</span> <span class="pl-s1">json_obj</span>

<span class="pl-k">def</span> <span class="pl-v">DisplayOptions</span>():
    <span class="pl-c">#TODO- fix useage</span>
    <span class="pl-s1">usage</span> <span class="pl-c1">=</span> <span class="pl-s">r"""usage: python memory_tester.py [options] arg1 arg2\n" </span>
<span class="pl-s">            Example: python memory_tester.py </span>
<span class="pl-s">            --product ufm</span>
<span class="pl-s">            -- ip 10.209.27.110</span>
<span class="pl-s">            --time 48</span>
<span class="pl-s">            --loops 500</span>
<span class="pl-s">            --pkey alice.key </span>
<span class="pl-s">            --certificate alice.cert.pem</span>
<span class="pl-s">            """</span>
    <span class="pl-s1">parser</span> <span class="pl-c1">=</span> <span class="pl-s1">optparse</span>.<span class="pl-v">OptionParser</span>(<span class="pl-s1">usage</span><span class="pl-c1">=</span><span class="pl-s1">usage</span>)
    <span class="pl-s1">parser</span>.<span class="pl-en">add_option</span>(<span class="pl-s">"--product"</span>, <span class="pl-s1">dest</span><span class="pl-c1">=</span><span class="pl-s">"type"</span>, <span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">"product type [ufm/ufmapl/neo]"</span>)
    <span class="pl-s1">parser</span>.<span class="pl-en">add_option</span>(<span class="pl-s">"--ip"</span>, <span class="pl-s1">dest</span><span class="pl-c1">=</span><span class="pl-s">"ip"</span>, <span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">"ip address of the machine"</span>)
    <span class="pl-s1">parser</span>.<span class="pl-en">add_option</span>(<span class="pl-s">"--time"</span>, <span class="pl-s1">dest</span><span class="pl-c1">=</span><span class="pl-s">"time"</span>, <span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">"total time for script to run in hours "</span>)
    <span class="pl-s1">parser</span>.<span class="pl-en">add_option</span>(<span class="pl-s">"--loops"</span>, <span class="pl-s1">dest</span><span class="pl-c1">=</span><span class="pl-s">"loops"</span>, <span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">"number of REST calls in loop [Optional]"</span>)
    <span class="pl-s1">parser</span>.<span class="pl-en">add_option</span>(<span class="pl-s">"--pkey"</span>, <span class="pl-s1">dest</span><span class="pl-c1">=</span><span class="pl-s">"private_key_path"</span>, <span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">"private key path for SSL client certification [Optional]"</span>)
    <span class="pl-s1">parser</span>.<span class="pl-en">add_option</span>(<span class="pl-s">"--certificate"</span>, <span class="pl-s1">dest</span><span class="pl-c1">=</span><span class="pl-s">"certificate_path"</span>, <span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">"certificate path for SSL client certification [Optional]"</span>)
    <span class="pl-s1">parser</span>.<span class="pl-en">add_option</span>(<span class="pl-s">"--fabric_health"</span>, <span class="pl-s1">dest</span><span class="pl-c1">=</span><span class="pl-s">"fabric_health"</span>, <span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">"sending REST API calls to create UFM fabric health report [Optional]"</span>)

    (<span class="pl-s1">options</span>, <span class="pl-s1">args</span>) <span class="pl-c1">=</span> <span class="pl-s1">parser</span>.<span class="pl-en">parse_args</span>()
    <span class="pl-k">if</span> ((<span class="pl-s1">options</span>.<span class="pl-s1">type</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>)  <span class="pl-c1">or</span> (<span class="pl-s1">options</span>.<span class="pl-s1">ip</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>) <span class="pl-c1">or</span> (<span class="pl-s1">options</span>.<span class="pl-s1">time</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>)):
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Missing parameters for script...exiting<span class="pl-cce">\n</span>"</span>)
        <span class="pl-s1">sys</span>.<span class="pl-en">exit</span>(<span class="pl-c1">1</span>)
    <span class="pl-k">return</span> <span class="pl-s1">options</span>

<span class="pl-k">def</span> <span class="pl-en">getIPfromURL</span>(<span class="pl-s1">url</span>):
    <span class="pl-s1">regex_url</span><span class="pl-c1">=</span><span class="pl-s">r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'</span>
    <span class="pl-s1">ip</span> <span class="pl-c1">=</span> <span class="pl-en">findRegex</span>(<span class="pl-s1">output</span><span class="pl-c1">=</span><span class="pl-s1">url</span>,<span class="pl-s1">regex_search</span><span class="pl-c1">=</span><span class="pl-s1">regex_url</span>)
    <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">ip</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">error</span>(<span class="pl-s">"Couldn't retreived ip from URL"</span>)
        <span class="pl-s1">sys</span>.<span class="pl-en">exit</span>(<span class="pl-c1">1</span>)
    <span class="pl-k">else</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"IP is: "</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">ip</span>))
        <span class="pl-k">return</span> <span class="pl-s1">ip</span>[<span class="pl-c1">0</span>]

<span class="pl-k">def</span> <span class="pl-en">get_username_password</span>(<span class="pl-s1">credentials</span>):
    <span class="pl-s1">splited</span> <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-s1">credentials</span>).<span class="pl-en">split</span>(<span class="pl-s">':'</span>)
    <span class="pl-s1">username</span>, <span class="pl-s1">password</span> <span class="pl-c1">=</span> <span class="pl-s1">splited</span>[<span class="pl-c1">0</span>], <span class="pl-s1">splited</span>[<span class="pl-c1">1</span>]
    <span class="pl-s1">password</span>.<span class="pl-en">replace</span>(<span class="pl-s">':'</span>,<span class="pl-s">''</span>)

    <span class="pl-k">return</span> <span class="pl-s1">username</span>, <span class="pl-s1">password</span>

<span class="pl-k">def</span> <span class="pl-en">isShellMode</span>(<span class="pl-s1">shell</span>):
    <span class="pl-s1">cmd</span> <span class="pl-c1">=</span> <span class="pl-s">'<span class="pl-cce">\n</span>'</span>
    <span class="pl-s1">expected</span> <span class="pl-c1">=</span> [<span class="pl-s">'&gt;'</span>]
    <span class="pl-k">for</span> <span class="pl-s1">cmd</span>, <span class="pl-s1">expect</span> <span class="pl-c1">in</span> <span class="pl-en">zip</span>(<span class="pl-s1">cmd</span>, <span class="pl-s1">expected</span>):
        <span class="pl-s1">result</span>, <span class="pl-s1">output</span> <span class="pl-c1">=</span> <span class="pl-en">run_par_cmd</span>(<span class="pl-s1">cmd</span><span class="pl-c1">=</span><span class="pl-s1">cmd</span>, <span class="pl-s1">expect</span><span class="pl-c1">=</span><span class="pl-s1">expect</span>, <span class="pl-s1">shell</span><span class="pl-c1">=</span><span class="pl-s1">shell</span>)
        <span class="pl-k">if</span> ((<span class="pl-en">int</span>(<span class="pl-s1">result</span>) <span class="pl-c1">==</span> <span class="pl-c1">0</span>) <span class="pl-c1">and</span> (<span class="pl-en">len</span>(<span class="pl-s1">output</span>) <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span>)):
            <span class="pl-s1">logging</span>.<span class="pl-en">debug</span>(<span class="pl-s1">cmd</span> <span class="pl-c1">+</span> <span class="pl-s">"working in Shell Mode equal true"</span>)
            <span class="pl-k">return</span> <span class="pl-c1">True</span>
        <span class="pl-k">else</span>:
            <span class="pl-s1">logging</span>.<span class="pl-en">debug</span>(<span class="pl-s1">cmd</span> <span class="pl-c1">+</span> <span class="pl-s">"working in Shell Mode equal false"</span>)
            <span class="pl-k">return</span> <span class="pl-c1">False</span>

<span class="pl-k">def</span> <span class="pl-en">get_credentials_from_product_type</span>(<span class="pl-s1">type</span>):
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Checking product type and set correct credentails"</span>)
    <span class="pl-k">if</span> <span class="pl-s1">type</span> <span class="pl-c1">==</span> <span class="pl-s">'ufm'</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Product is UFM-IB"</span>)
        <span class="pl-k">return</span> (<span class="pl-s">'admin'</span>,<span class="pl-s">'****'</span>)
    <span class="pl-k">elif</span> <span class="pl-s1">type</span> <span class="pl-c1">==</span> <span class="pl-s">'neo'</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Product is NEO"</span>)
        <span class="pl-k">return</span> (<span class="pl-s">'admin'</span>,<span class="pl-s">'****'</span>)
    <span class="pl-k">elif</span> <span class="pl-s1">type</span> <span class="pl-c1">==</span> <span class="pl-s">'ufmapl'</span>:
        <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Product is UFM-Appliance"</span>)
        <span class="pl-k">return</span> (<span class="pl-s">'admin'</span>,<span class="pl-s">'*****'</span>)

<span class="pl-k">def</span> <span class="pl-en">main</span>():
    <span class="pl-s1">logging</span>.<span class="pl-en">basicConfig</span>(<span class="pl-s1">level</span><span class="pl-c1">=</span><span class="pl-s1">logging</span>.<span class="pl-v">INFO</span>,
                        <span class="pl-s1">format</span><span class="pl-c1">=</span><span class="pl-s">'%(asctime)s %(levelname)-8s %(message)s'</span>,
                        <span class="pl-s1">datefmt</span><span class="pl-c1">=</span><span class="pl-s">'%m-%d %H:%M'</span>,
                        <span class="pl-s1">filemode</span><span class="pl-c1">=</span><span class="pl-s">'w'</span>)
    <span class="pl-s1">options</span> <span class="pl-c1">=</span> <span class="pl-v">DisplayOptions</span>()
    <span class="pl-en">creating_directory</span>(<span class="pl-s1">global_csv_path</span>)
    <span class="pl-en">creating_directory</span>(<span class="pl-s1">global_graphs_path</span>)
    <span class="pl-c">#TODO - Add argparse for NEO/UFM/APL</span>
    <span class="pl-c">#ip = getIPfromURL(options.url)</span>
    <span class="pl-c">#username, password = get_username_password(options.credentials)</span>
    <span class="pl-s1">type</span>,<span class="pl-s1">ip</span>, <span class="pl-s1">loops</span> ,<span class="pl-s1">time</span>, <span class="pl-s1">private_key_path</span>,<span class="pl-s1">certificate_path</span>, <span class="pl-s1">fabric_health</span><span class="pl-c1">=</span> \
    <span class="pl-s1">options</span>.<span class="pl-s1">type</span>, <span class="pl-s1">options</span>.<span class="pl-s1">ip</span> ,<span class="pl-s1">options</span>.<span class="pl-s1">loops</span>, <span class="pl-s1">options</span>.<span class="pl-s1">time</span>, <span class="pl-s1">options</span>.<span class="pl-s1">private_key_path</span>, <span class="pl-s1">options</span>.<span class="pl-s1">certificate_path</span>, <span class="pl-s1">options</span>.<span class="pl-s1">fabric_health</span>

    <span class="pl-s1">username</span>, <span class="pl-s1">password</span> <span class="pl-c1">=</span> <span class="pl-en">get_credentials_from_product_type</span>(<span class="pl-s1">type</span>)
    <span class="pl-c">#payload_obj = get_payload_for_request(payload)</span>

    <span class="pl-c">#TODO - Currently supports only appliance machine</span>

    <span class="pl-s1">shells</span> <span class="pl-c1">=</span> []
    <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">5</span>):
        <span class="pl-k">if</span> <span class="pl-s1">type</span> <span class="pl-c1">==</span> <span class="pl-s">'ufmapl'</span>:
            <span class="pl-s1">ssh</span> <span class="pl-c1">=</span> <span class="pl-v">SSHConnect</span>(<span class="pl-s1">ip</span><span class="pl-c1">=</span><span class="pl-s1">ip</span>, <span class="pl-s1">username</span><span class="pl-c1">=</span><span class="pl-s">'admin'</span>, <span class="pl-s1">passowrd</span><span class="pl-c1">=</span><span class="pl-s">'admin'</span>)
        <span class="pl-k">else</span>:
            <span class="pl-s1">ssh</span> <span class="pl-c1">=</span> <span class="pl-v">SSHConnect</span>(<span class="pl-s1">ip</span><span class="pl-c1">=</span><span class="pl-s1">ip</span>, <span class="pl-s1">username</span><span class="pl-c1">=</span><span class="pl-s">'root'</span>, <span class="pl-s1">passowrd</span><span class="pl-c1">=</span><span class="pl-s">'****'</span>)
        <span class="pl-s1">shells</span>.<span class="pl-en">append</span>(<span class="pl-en">createshell</span>(<span class="pl-s1">ssh</span><span class="pl-c1">=</span><span class="pl-s1">ssh</span>))
        <span class="pl-k">if</span> <span class="pl-s1">type</span> <span class="pl-c1">==</span> <span class="pl-s">'ufmapl'</span>:
            <span class="pl-k">if</span> <span class="pl-en">isShellMode</span>(<span class="pl-s1">shells</span>[<span class="pl-s1">i</span>]):
                <span class="pl-v">ChangeToShellMode</span>(<span class="pl-s1">shell</span><span class="pl-c1">=</span><span class="pl-s1">shells</span>[<span class="pl-s1">i</span>])
    <span class="pl-en">thread_manager</span>(<span class="pl-s1">shells</span>,<span class="pl-s1">ip</span>, <span class="pl-s1">type</span>, <span class="pl-s1">loops</span>,<span class="pl-s1">time</span>, <span class="pl-s1">username</span>, <span class="pl-s1">password</span>, <span class="pl-s1">private_key_path</span>, <span class="pl-s1">certificate_path</span>,<span class="pl-s1">fabric_health</span>)
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Graphs are located under "</span> <span class="pl-c1">+</span> <span class="pl-s1">global_graphs_path</span> )
    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"Script is completed"</span>)

<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-en">main</span>()


<span class="pl-c1">**</span><span class="pl-v">Actual</span> <span class="pl-s1">outcome</span><span class="pl-c1">**</span>

<span class="pl-c1">&lt;</span>!<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-v">The</span> <span class="pl-s1">output</span> <span class="pl-s1">produced</span> <span class="pl-s1">by</span> <span class="pl-s1">the</span> <span class="pl-s1">above</span> <span class="pl-s1">code</span>, <span class="pl-s1">which</span> <span class="pl-s1">may</span> <span class="pl-s1">be</span> <span class="pl-s1">a</span> <span class="pl-s1">screenshot</span>, <span class="pl-s1">console</span> <span class="pl-s1">output</span>, <span class="pl-s1">etc</span>.<span class="pl-c1">-</span><span class="pl-c1">-&gt;</span></pre></div>
<h1 dir="auto">If applicable, paste the console output here</h1>
<p dir="auto">running command: memory_tester.py --fabric_health yes --product ufm --ip 10.209.27.119 --time 1 --pkey C:\Users\arielwe\Desktop\SecurityProject\RESTAPI_loop_files\alice.key --certificate C:\Users\arielwe\Desktop\SecurityProject\RESTAPI_loop_files\alice.cert.pem</p>
<p dir="auto">output:<br>
12-06 10:18 INFO     creating new pkey with rest request was send successfully.<br>
12-06 10:18 INFO     Fabric Health succeeded...<br>
12-06 10:18 INFO     1117# Sending Fabric Health Report...<br>
12-06 10:18 INFO     Total time for request <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="10164601" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/1692" data-hovercard-type="issue" data-hovercard-url="/matplotlib/matplotlib/issues/1692/hovercard" href="https://github.com/matplotlib/matplotlib/issues/1692">#1692</a> is			 0:00:00.176482<br>
12-06 10:18 INFO     1692# sending Rest request<br>
12-06 10:18 INFO     creating new pkey with rest request<br>
12-06 10:18 INFO     creating new pkey with rest request was send successfully.<br>
12-06 10:18 INFO     Fabric Health succeeded...<br>
12-06 10:18 INFO     1118# Sending Fabric Health Report...<br>
12-06 10:18 INFO     Total time for request <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="10165861" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/1693" data-hovercard-type="issue" data-hovercard-url="/matplotlib/matplotlib/issues/1693/hovercard" href="https://github.com/matplotlib/matplotlib/issues/1693">#1693</a> is			 0:00:00.120330<br>
12-06 10:18 INFO     1693# sending Rest request<br>
12-06 10:18 INFO     creating new pkey with rest request<br>
Exception ignored in: &lt;generator object _process_plot_var_args._getdefaults.. at 0x0EE81930&gt;<br>
Traceback (most recent call last):<br>
File "C:\Users\arielwe\PycharmProjects\SecurityProject\venv\lib\site-packages\matplotlib\axes_base.py", line 262, in <br>
for k in prop_keys):<br>
SystemError: error return without exception set<br>
12-06 10:18 INFO     creating new pkey with rest request was send successfully.<br>
Exception ignored in: &lt;generator object Transform._iter_break_from_left_to_right at 0x14E07840&gt;<br>
Traceback (most recent call last):<br>
File "C:\Users\arielwe\PycharmProjects\SecurityProject\venv\lib\site-packages\matplotlib\transforms.py", line 1302, in _iter_break_from_left_to_right<br>
12-06 10:18 INFO     Total time for request <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="10165947" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/1694" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/1694/hovercard" href="https://github.com/matplotlib/matplotlib/pull/1694">#1694</a> is			 0:00:00.096263<br>
12-06 10:18 INFO     1694# sending Rest request<br>
12-06 10:18 INFO     creating new pkey with rest request<br>
12-06 10:18 INFO     Fabric Health succeeded...<br>
12-06 10:18 INFO     1119# Sending Fabric Health Report...<br>
yield IdentityTransform(), self<br>
SystemError: error return without exception set<br>
Exception ignored in: &lt;generator object CompositeGenericTransform._iter_break_from_left_to_right at 0x0E68A750&gt;<br>
Traceback (most recent call last):<br>
File "C:\Users\arielwe\PycharmProjects\SecurityProject\venv\lib\site-packages\matplotlib\transforms.py", line 2409, in _iter_break_from_left_to_right<br>
yield left, right + self._b<br>
SystemError: error return without exception set<br>
12-06 10:18 INFO     creating new pkey with rest request was send successfully.<br>
12-06 10:18 INFO     Total time for request <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="10218592" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/1695" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/1695/hovercard" href="https://github.com/matplotlib/matplotlib/pull/1695">#1695</a> is			 0:00:00.096264<br>
12-06 10:18 INFO     1695# sending Rest request<br>
12-06 10:18 INFO     creating new pkey with rest request<br>
12-06 10:18 INFO     Fabric Health succeeded...<br>
12-06 10:18 INFO     1120# Sending Fabric Health Report...<br>
12-06 10:18 INFO     creating new pkey with rest request was send successfully.<br>
12-06 10:18 INFO     Total time for request <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="10244322" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/1696" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/1696/hovercard" href="https://github.com/matplotlib/matplotlib/pull/1696">#1696</a> is			 0:00:00.110302<br>
12-06 10:18 INFO     1696# sending Rest request<br>
12-06 10:18 INFO     creating new pkey with rest request<br>
12-06 10:18 INFO     Fabric Health succeeded...<br>
12-06 10:18 INFO     1121# Sending Fabric Health Report...<br>
12-06 10:18 INFO     264# CPU usage is:	 0.00725173%<br>
12-06 10:18 INFO     creating new pkey with rest request was send successfully.<br>
12-06 10:18 INFO     264# RAM value is :	7.162979808958611%<br>
12-06 10:18 INFO     Total time for request <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="10246367" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/1697" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/1697/hovercard" href="https://github.com/matplotlib/matplotlib/pull/1697">#1697</a> is			 0:00:00.126346<br>
12-06 10:18 INFO     1697# sending Rest request<br>
12-06 10:18 INFO     creating new pkey with rest request<br>
12-06 10:18 INFO     Measuring CPU USage...<br>
12-06 10:18 INFO     Measuring RAM USage...<br>
12-06 10:18 INFO     cat /proc/2767/status command run successfully<br>
12-06 10:18 INFO     34# virtual memory of mysqld = 12244<br>
12-06 10:18 INFO     Fabric Health succeeded...<br>
12-06 10:18 INFO     1122# Sending Fabric Health Report...<br>
12-06 10:18 INFO     creating new pkey with rest request was send successfully.<br>
12-06 10:18 INFO     Total time for request <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="10247172" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/1698" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/1698/hovercard" href="https://github.com/matplotlib/matplotlib/pull/1698">#1698</a> is			 0:00:00.113308<br>
12-06 10:18 INFO     1698# sending Rest request<br>
12-06 10:18 INFO     creating new pkey with rest request<br>
Exception ignored in: &lt;generator object broadcast_arrays.. at 0x0FE2E540&gt;<br>
Traceback (most recent call last):<br>
File "C:\Users\arielwe\PycharmProjects\SecurityProject\venv\lib\site-packages\numpy\lib\stride_tricks.py", line 254, in <br>
if all(array.shape == shape for array in args):<br>
SystemError: error return without exception set<br>
Exception ignored in: &lt;generator object broadcast_arrays.. at 0x0C992600&gt;<br>
Traceback (most recent call last):<br>
File "C:\Users\arielwe\PycharmProjects\SecurityProject\venv\lib\site-packages\numpy\lib\stride_tricks.py", line 254, in <br>
if all(array.shape == shape for array in args):<br>
SystemError: error return without exception set<br>
12-06 10:18 INFO     1703# sending Rest request<br>
12-06 10:18 INFO     creating new pkey with rest request<br>
File "C:\Users\arielwe\PycharmProjects\SecurityProject\venv\lib\site-packages\matplotlib\ticker.py", line 690, in <br>
if abs_min // 10 ** oom != abs_max // 10 ** oom)<br>
SystemError: error return without exception set<br>
12-06 10:18 INFO     Fabric Health succeeded...</p>