Example #1
0
    def get_other_interfaces(self):
        """
        Get other interfaces
        :return:
        """
        ignore_interfaces = ['^lo', '^v', 'docker', 'br', 'bond']
        cmd = "ip route show default | awk '/default/ {print $5}'"
        com = Command(cmd)
        management_interface = com.read()
        if management_interface:
            ignore_interfaces.append(management_interface)
            # print(cmd)
            # print("Management interface: %s" % management_interface)

        ignore_pattern = '|'.join(ignore_interfaces)
        # print(ignore_pattern)
        cmd = "ls /sys/class/net/ | grep -vE '%s'" % ignore_pattern
        # print(cmd)
        com = Command(cmd)
        try:
            com.run()
            return com.output
        except Exception as concrete_error:
            print(concrete_error)
            return []
Example #2
0
 def find_path(self, parent_dir, target_name):
     """
     Find the target path from the specified directory
     :param parent_dir:
     :param target_name:
     :return:
     """
     cmd = Command("find %s -name %s" % (parent_dir, target_name))
     try:
         cmd.run()
         return cmd.returncode
     except Exception as concrete_error:
         print(concrete_error)
         return False
Example #3
0
 def set_freq(self, freq, cpu='all'):
     """
     Set CPU frequency
     :param freq:
     :param cpu:
     :return:
     """
     cmd = Command("cpupower -c %s frequency-set --freq %s" % (cpu, freq))
     try:
         cmd.run()
         return cmd.returncode
     except Exception as concrete_error:
         print(concrete_error)
         return False
Example #4
0
 def set_governor(self, governor, cpu='all'):
     """
     Set the frequency governor mode of CPU
     :param governor:
     :param cpu:
     :return:
     """
     cmd = Command("cpupower -c %s frequency-set --governor %s" %
                   (cpu, governor))
     try:
         cmd.run()
         return cmd.returncode
     except Exception as concrete_error:
         print(concrete_error)
         return False