예제 #1
0
def driver_restart(host_obj):
    msg = ''
    if hostSetData.driver_action(host_obj, 'restart') is None:
        msg += ' fail to restart the driver in host: ' + host_obj.get_hostname(
        )
    if msg:
        utilities.reporter(msg, 'red')
        return False
    return True
예제 #2
0
 def connect(self, ip):
     if self.recCounter == 2:
         utilities.reporter("No connection to host: " + ip + "!", 'red')
         return None
     try:
         conn = rpyc.classic.connect(ip)
         return conn
     except Exception as err:
         self.recCounter += 1
         utilities.reporter("No connection to host: " + ip + " via RPyC service.\n" +
                            "starting to install the ver_tools: " + VER_TOOLS_PATH, 'yellow')
         sshParamiko.ssh_command(str(ip), VER_TOOLS_PATH)
         return self.connect(ip)  # recursion, it is a good day to die
예제 #3
0
def update_setup(host_obj):
    msg = ''
    dic_versions = hostGetData.get_versions_from_json()

    try:
        if not hostSetData.install_driver(
                host_obj, dic_versions["ofed_install_command"]):
            msg = 'fail to update setup: ' + host_obj.get_hostname()
        if hostSetData.driver_action(host_obj, 'restart') is None:
            msg = msg + '\n fail to restart driver'
    except:
        utilities.reporter(
            "OFED installation failed: " +
            dic_versions["ofed_install_command"] + "\n", 'red')
        return False
    if msg:
        utilities.reporter(msg, 'red')
        return False
    return True
예제 #4
0
def run_ping(client, server_int, client_nt, ipv, count=3):
    if ipv is "ipv4":
        server_ip = server_int.get_ipv4()
        ping = "ping"
    elif ipv is "ipv6":
        server_ip = server_int.get_ipv6()
        ping = "ping6"

    cmd = ping + " -c " + str(
        count) + " -I " + client_nt.get_interface_name() + " " + server_ip
    try:
        out = client.run_cmd(
            cmd, r'.*\d+\spackets\stransmitted\,\s\d+\sreceived\,\s(\d+).*', 1,
            1)
        if out is '0':
            return True
        else:
            return False
    except:
        utilities.reporter("Ping fail: " + cmd + "\n", 'red')
        return False
예제 #5
0
 def run_cmd(self,
             cmd,
             reg=0,
             return_value=0,
             output_to_screen=0,
             write_to_file=0):
     if hasattr(self, 'hostname'): host = self.get_hostname()
     else: host = "No Name Yet"
     if write_to_file: cmd = cmd + " > " + write_to_file
     if output_to_screen:
         utilities.reporter(
             "Function: HostLinux.run_cmd, Object: HostLinux: " + host +
             "\nCommand: " + cmd + "\n", 'green')
     proc = self.conn.modules.subprocess.Popen(cmd,
                                               shell=True,
                                               stdout=subprocess.PIPE,
                                               stderr=subprocess.PIPE,
                                               universal_newlines=True)
     stdout, stderr = proc.communicate()
     if output_to_screen:
         utilities.reporter("Output of command is:\n" + stdout, 'blue')
         if stderr:
             utilities.reporter("Error output of command is:\n" + stderr,
                                'blue')
     if write_to_file: return
     if stderr:
         utilities.reporter("Something went wrong: " + stderr, 'red')
         self.last_output = stderr
         raise Exception("failed in command: " + cmd)
         return None
     self.set_last_output(stdout)
     if reg:
         try:
             stdout = re.findall(reg, stdout)[0]
         except:
             utilities.reporter(
                 "Host: " + self.get_hostname() + "Command Fail: " + cmd +
                 "\n" + stdout, 'red')
             return None
     if return_value: return stdout