コード例 #1
0
ファイル: whitebox.py プロジェクト: mindpool/tempest
 def get_ssh_connection(self, host, username, password):
     """Create an SSH connection object to a host"""
     ssh_timeout = self.config.compute.ssh_timeout
     ssh_client = Client(host, username, password, ssh_timeout)
     if not ssh_client.test_connection_auth():
         raise exceptions.SSHTimeout()
     else:
         return ssh_client
コード例 #2
0
    def __init__(self, server, username, password):
        ssh_timeout = TempestConfig().compute.ssh_timeout
        network = TempestConfig().compute.network_for_ssh
        ip_version = TempestConfig().compute.ip_version_for_ssh
        addresses = server['addresses'][network]

        for address in addresses:
            if address['version'] == ip_version:
                ip_address = address['addr']
                break

        if ip_address is None:
            raise ServerUnreachable()

        self.ssh_client = Client(ip_address, username, password, ssh_timeout)
        if not self.ssh_client.test_connection_auth():
            raise SSHTimeout()
コード例 #3
0
class RemoteClient():

    def __init__(self, server, username, password):
        ssh_timeout = TempestConfig().compute.ssh_timeout
        network = TempestConfig().compute.network_for_ssh
        ip_version = TempestConfig().compute.ip_version_for_ssh
        addresses = server['addresses'][network]

        for address in addresses:
            if address['version'] == ip_version:
                ip_address = address['addr']
                break

        if ip_address is None:
            raise ServerUnreachable()

        self.ssh_client = Client(ip_address, username, password, ssh_timeout)
        if not self.ssh_client.test_connection_auth():
            raise SSHTimeout()

    def can_authenticate(self):
        # Re-authenticate
        return self.ssh_client.test_connection_auth()

    def hostname_equals_servername(self, expected_hostname):
        # Get hostname using command "hostname"
        actual_hostname = self.ssh_client.exec_command("hostname").rstrip()
        return expected_hostname == actual_hostname

    def get_files(self, path):
        # Return a list of comma seperated files
        command = "ls -m " + path
        return self.ssh_client.exec_command(command).rstrip('\n').split(', ')

    def get_ram_size_in_mb(self):
        output = self.ssh_client.exec_command('free -m | grep Mem')
        if output:
            return output.split()[1]

    def get_number_of_vcpus(self):
        command = 'cat /proc/cpuinfo | grep processor | wc -l'
        output = self.ssh_client.exec_command(command)
        return int(output)

    def get_partitions(self):
        # Return the contents of /proc/partitions
        command = 'cat /proc/partitions'
        output = self.ssh_client.exec_command(command)
        return output

    def get_boot_time(self):
        cmd = 'date -d "`cut -f1 -d. /proc/uptime` seconds ago" \
            "+%Y-%m-%d %H:%M:%S"'
        boot_time_string = self.ssh_client.exec_command(cmd)
        boot_time_string = boot_time_string.replace('\n', '')
        return time.strptime(boot_time_string, utils.LAST_REBOOT_TIME_FORMAT)
コード例 #4
0
ファイル: remote_client.py プロジェクト: mindpool/tempest
class RemoteClient():
    def __init__(self, server, username, password):
        ssh_timeout = TempestConfig().compute.ssh_timeout
        network = TempestConfig().compute.network_for_ssh
        ip_version = TempestConfig().compute.ip_version_for_ssh
        addresses = server['addresses'][network]

        for address in addresses:
            if address['version'] == ip_version:
                ip_address = address['addr']
                break

        if ip_address is None:
            raise ServerUnreachable()

        self.ssh_client = Client(ip_address, username, password, ssh_timeout)
        if not self.ssh_client.test_connection_auth():
            raise SSHTimeout()

    def can_authenticate(self):
        # Re-authenticate
        return self.ssh_client.test_connection_auth()

    def hostname_equals_servername(self, expected_hostname):
        # Get hostname using command "hostname"
        actual_hostname = self.ssh_client.exec_command("hostname").rstrip()
        return expected_hostname == actual_hostname

    def get_files(self, path):
        # Return a list of comma seperated files
        command = "ls -m " + path
        return self.ssh_client.exec_command(command).rstrip('\n').split(', ')

    def get_ram_size_in_mb(self):
        output = self.ssh_client.exec_command('free -m | grep Mem')
        if output:
            return output.split()[1]

    def get_number_of_vcpus(self):
        command = 'cat /proc/cpuinfo | grep processor | wc -l'
        output = self.ssh_client.exec_command(command)
        return int(output)

    def get_partitions(self):
        # Return the contents of /proc/partitions
        command = 'cat /proc/partitions'
        output = self.ssh_client.exec_command(command)
        return output

    def get_boot_time(self):
        cmd = 'date -d "`cut -f1 -d. /proc/uptime` seconds ago" \
            "+%Y-%m-%d %H:%M:%S"'

        boot_time_string = self.ssh_client.exec_command(cmd)
        boot_time_string = boot_time_string.replace('\n', '')
        return time.strptime(boot_time_string, utils.LAST_REBOOT_TIME_FORMAT)
コード例 #5
0
    def __init__(self, server, username, password=None, pkey=None):
        ssh_timeout = TempestConfig().compute.ssh_timeout
        network = TempestConfig().compute.network_for_ssh
        ip_version = TempestConfig().compute.ip_version_for_ssh
        ssh_channel_timeout = TempestConfig().compute.ssh_channel_timeout
        if isinstance(server, basestring):
            ip_address = server
        else:
            addresses = server['addresses'][network]
            for address in addresses:
                if address['version'] == ip_version:
                    ip_address = address['addr']
                    break
            else:
                raise ServerUnreachable()

        self.ssh_client = Client(ip_address, username, password, ssh_timeout,
                                 pkey=pkey,
                                 channel_timeout=ssh_channel_timeout)
        if not self.ssh_client.test_connection_auth():
            raise SSHTimeout()
コード例 #6
0
ファイル: remote_client.py プロジェクト: AsylumCorp/tempest
    def __init__(self, server, username, password):
        ssh_timeout = TempestConfig().compute.ssh_timeout
        network = TempestConfig().compute.network_for_ssh
        ip_version = TempestConfig().compute.ip_version_for_ssh
        addresses = server['addresses'][network]

        for address in addresses:
            if address['version'] == ip_version:
                ip_address = address['addr']
                break

        if ip_address is None:
            raise ServerUnreachable()

        self.ssh_client = Client(ip_address, username, password, ssh_timeout)
        if not self.ssh_client.test_connection_auth():
            raise SSHTimeout()
コード例 #7
0
ファイル: remote_client.py プロジェクト: LIS/LIS-Tempest
 def __init__(self, server, username, password=None, pkey=None):
     ssh_timeout = CONF.compute.ssh_timeout
     network = CONF.compute.network_for_ssh
     ip_version = CONF.compute.ip_version_for_ssh
     ssh_channel_timeout = CONF.compute.ssh_channel_timeout
     if isinstance(server, basestring):
         ip_address = server
     else:
         addresses = server['addresses'][network]
         for address in addresses:
             if address['version'] == ip_version:
                 ip_address = address['addr']
                 break
         else:
             raise ServerUnreachable()
     self.ssh_client = Client(ip_address, username, password, ssh_timeout,
                              pkey=pkey,
                              channel_timeout=ssh_channel_timeout)
コード例 #8
0
ファイル: remote_client.py プロジェクト: AsylumCorp/tempest
class RemoteClient():

    def __init__(self, server, username, password):
        ssh_timeout = TempestConfig().compute.ssh_timeout
        network = TempestConfig().compute.network_for_ssh
        ip_version = TempestConfig().compute.ip_version_for_ssh
        addresses = server['addresses'][network]

        for address in addresses:
            if address['version'] == ip_version:
                ip_address = address['addr']
                break

        if ip_address is None:
            raise ServerUnreachable()

        self.ssh_client = Client(ip_address, username, password, ssh_timeout)
        if not self.ssh_client.test_connection_auth():
            raise SSHTimeout()

    def can_authenticate(self):
        # Re-authenticate
        return self.ssh_client.test_connection_auth()

    def hostname_equals_servername(self, expected_hostname):
        # Get hostname using command "hostname"
        actual_hostname = self.ssh_client.exec_command("hostname").rstrip()
        return expected_hostname == actual_hostname

    def get_files(self, path):
        # Return a list of comma seperated files
        command = "ls -m " + path
        return self.ssh_client.exec_command(command).rstrip('\n').split(', ')

    def get_ram_size_in_mb(self):
        output = self.ssh_client.exec_command('free -m | grep Mem')
        if output:
            return output.split()[1]

    def get_number_of_vcpus(self):
        command = 'cat /proc/cpuinfo | grep processor | wc -l'
        output = self.ssh_client.exec_command(command)
        return int(output)
コード例 #9
0
ファイル: remote_client.py プロジェクト: LIS/LIS-Tempest
class RemoteClient():

    # NOTE(afazekas): It should always get an address instead of server
    def __init__(self, server, username, password=None, pkey=None):
        ssh_timeout = CONF.compute.ssh_timeout
        network = CONF.compute.network_for_ssh
        ip_version = CONF.compute.ip_version_for_ssh
        ssh_channel_timeout = CONF.compute.ssh_channel_timeout
        if isinstance(server, basestring):
            ip_address = server
        else:
            addresses = server['addresses'][network]
            for address in addresses:
                if address['version'] == ip_version:
                    ip_address = address['addr']
                    break
            else:
                raise ServerUnreachable()
        self.ssh_client = Client(ip_address, username, password, ssh_timeout,
                                 pkey=pkey,
                                 channel_timeout=ssh_channel_timeout)

    def validate_authentication(self):
        """Validate ssh connection and authentication
           This method raises an Exception when the validation fails.
        """
        self.ssh_client.test_connection_auth()

    def hostname_equals_servername(self, expected_hostname):
        # Get host name using command "hostname"
        actual_hostname = self.ssh_client.exec_command("hostname").rstrip()
        return expected_hostname == actual_hostname

    def get_files(self, path):
        # Return a list of comma separated files
        command = "ls -m " + path
        return self.ssh_client.exec_command(command).rstrip('\n').split(', ')

    def get_ram_size_in_mb(self):
        output = self.ssh_client.exec_command('free -m | grep Mem')
        if output:
            return output.split()[1]

    def get_number_of_vcpus(self):
        command = 'cat /proc/cpuinfo | grep processor | wc -l'
        output = self.ssh_client.exec_command(command)
        return int(output)

    def get_partitions(self):
        # Return the contents of /proc/partitions
        command = 'cat /proc/partitions'
        output = self.ssh_client.exec_command(command)
        return output

    def get_boot_time(self):
        cmd = 'cut -f1 -d. /proc/uptime'
        boot_secs = self.ssh_client.exec_command(cmd)
        boot_time = time.time() - int(boot_secs)
        return time.localtime(boot_time)

    def write_to_console(self, message):
        message = re.sub("([$\\`])", "\\\\\\\\\\1", message)
        # usually to /dev/ttyS0
        cmd = 'sudo sh -c "echo \\"%s\\" >/dev/console"' % message
        return self.ssh_client.exec_command(cmd)

    def ping_host(self, host):
        cmd = 'ping -c1 -w1 %s' % host
        return self.ssh_client.exec_command(cmd)

    def get_mac_address(self):
        cmd = "/sbin/ifconfig | awk '/HWaddr/ {print $5}'"
        return self.ssh_client.exec_command(cmd)
コード例 #10
0
ファイル: remote_client.py プロジェクト: eghobo/tempest
class RemoteClient():

    #Note(afazekas): It should always get an address instead of server
    def __init__(self, server, username, password=None, pkey=None):
        ssh_timeout = TempestConfig().compute.ssh_timeout
        network = TempestConfig().compute.network_for_ssh
        ip_version = TempestConfig().compute.ip_version_for_ssh
        if isinstance(server, basestring):
            ip_address = server
        else:
            addresses = server['addresses'][network]
            for address in addresses:
                if address['version'] == ip_version:
                    ip_address = address['addr']
                    break
            else:
                raise ServerUnreachable()

        self.ssh_client = Client(ip_address, username, password, ssh_timeout,
                                 pkey=pkey)
        if not self.ssh_client.test_connection_auth():
            raise SSHTimeout()

    def can_authenticate(self):
        # Re-authenticate
        return self.ssh_client.test_connection_auth()

    def hostname_equals_servername(self, expected_hostname):
        # Get hostname using command "hostname"
        actual_hostname = self.ssh_client.exec_command("hostname").rstrip()
        return expected_hostname == actual_hostname

    def get_files(self, path):
        # Return a list of comma seperated files
        command = "ls -m " + path
        return self.ssh_client.exec_command(command).rstrip('\n').split(', ')

    def get_ram_size_in_mb(self):
        output = self.ssh_client.exec_command('free -m | grep Mem')
        if output:
            return output.split()[1]

    def get_number_of_vcpus(self):
        command = 'cat /proc/cpuinfo | grep processor | wc -l'
        output = self.ssh_client.exec_command(command)
        return int(output)

    def get_partitions(self):
        # Return the contents of /proc/partitions
        command = 'cat /proc/partitions'
        output = self.ssh_client.exec_command(command)
        return output

    def get_boot_time(self):
        cmd = 'date -d "`cut -f1 -d. /proc/uptime` seconds ago" \
            "+%Y-%m-%d %H:%M:%S"'
        boot_time_string = self.ssh_client.exec_command(cmd)
        boot_time_string = boot_time_string.replace('\n', '')
        return time.strptime(boot_time_string, utils.LAST_REBOOT_TIME_FORMAT)

    def write_to_console(self, message):
        message = re.sub("([$\\`])", "\\\\\\\\\\1", message)
        # usually to /dev/ttyS0
        cmd = 'sudo sh -c "echo \\"%s\\" >/dev/console"' % message
        return self.ssh_client.exec_command(cmd)
コード例 #11
0
class RemoteClient():

    #Note(afazekas): It should always get an address instead of server
    def __init__(self, server, username, password=None, pkey=None):
        ssh_timeout = TempestConfig().compute.ssh_timeout
        network = TempestConfig().compute.network_for_ssh
        ip_version = TempestConfig().compute.ip_version_for_ssh
        if isinstance(server, basestring):
            ip_address = server
        else:
            addresses = server['addresses'][network]
            for address in addresses:
                if address['version'] == ip_version:
                    ip_address = address['addr']
                    break
            else:
                raise ServerUnreachable()

        self.ssh_client = Client(ip_address,
                                 username,
                                 password,
                                 ssh_timeout,
                                 pkey=pkey)
        if not self.ssh_client.test_connection_auth():
            raise SSHTimeout()

    def can_authenticate(self):
        # Re-authenticate
        return self.ssh_client.test_connection_auth()

    def hostname_equals_servername(self, expected_hostname):
        # Get hostname using command "hostname"
        actual_hostname = self.ssh_client.exec_command("hostname").rstrip()
        return expected_hostname == actual_hostname

    def get_files(self, path):
        # Return a list of comma seperated files
        command = "ls -m " + path
        return self.ssh_client.exec_command(command).rstrip('\n').split(', ')

    def get_ram_size_in_mb(self):
        output = self.ssh_client.exec_command('free -m | grep Mem')
        if output:
            return output.split()[1]

    def get_number_of_vcpus(self):
        command = 'cat /proc/cpuinfo | grep processor | wc -l'
        output = self.ssh_client.exec_command(command)
        return int(output)

    def get_partitions(self):
        # Return the contents of /proc/partitions
        command = 'cat /proc/partitions'
        output = self.ssh_client.exec_command(command)
        return output

    def get_boot_time(self):
        cmd = 'date -d "`cut -f1 -d. /proc/uptime` seconds ago" \
            "+%Y-%m-%d %H:%M:%S"'

        boot_time_string = self.ssh_client.exec_command(cmd)
        boot_time_string = boot_time_string.replace('\n', '')
        return time.strptime(boot_time_string, utils.LAST_REBOOT_TIME_FORMAT)

    def write_to_console(self, message):
        message = re.sub("([$\\`])", "\\\\\\\\\\1", message)
        # usually to /dev/ttyS0
        cmd = 'sudo sh -c "echo \\"%s\\" >/dev/console"' % message
        return self.ssh_client.exec_command(cmd)
コード例 #12
0
class RemoteClient():

    # NOTE(afazekas): It should always get an address instead of server
    def __init__(self, server, username, password=None, pkey=None):
        ssh_timeout = CONF.compute.ssh_timeout
        network = CONF.compute.network_for_ssh
        ip_version = CONF.compute.ip_version_for_ssh
        ssh_channel_timeout = CONF.compute.ssh_channel_timeout
        if isinstance(server, basestring):
            ip_address = server
        else:
            addresses = server['addresses'][network]
            for address in addresses:
                if address['version'] == ip_version:
                    ip_address = address['addr']
                    break
            else:
                raise ServerUnreachable()
        self.ssh_client = Client(ip_address,
                                 username,
                                 password,
                                 ssh_timeout,
                                 pkey=pkey,
                                 channel_timeout=ssh_channel_timeout)

    def validate_authentication(self):
        """Validate ssh connection and authentication
           This method raises an Exception when the validation fails.
        """
        self.ssh_client.test_connection_auth()

    def hostname_equals_servername(self, expected_hostname):
        # Get host name using command "hostname"
        actual_hostname = self.ssh_client.exec_command("hostname").rstrip()
        return expected_hostname == actual_hostname

    def get_files(self, path):
        # Return a list of comma separated files
        command = "ls -m " + path
        return self.ssh_client.exec_command(command).rstrip('\n').split(', ')

    def get_ram_size_in_mb(self):
        output = self.ssh_client.exec_command('free -m | grep Mem')
        if output:
            return output.split()[1]

    def get_number_of_vcpus(self):
        command = 'cat /proc/cpuinfo | grep processor | wc -l'
        output = self.ssh_client.exec_command(command)
        return int(output)

    def get_partitions(self):
        # Return the contents of /proc/partitions
        command = 'cat /proc/partitions'
        output = self.ssh_client.exec_command(command)
        return output

    def get_boot_time(self):
        cmd = 'cut -f1 -d. /proc/uptime'
        boot_secs = self.ssh_client.exec_command(cmd)
        boot_time = time.time() - int(boot_secs)
        return time.localtime(boot_time)

    def write_to_console(self, message):
        message = re.sub("([$\\`])", "\\\\\\\\\\1", message)
        # usually to /dev/ttyS0
        cmd = 'sudo sh -c "echo \\"%s\\" >/dev/console"' % message
        return self.ssh_client.exec_command(cmd)

    def ping_host(self, host):
        cmd = 'ping -c1 -w1 %s' % host
        return self.ssh_client.exec_command(cmd)

    def get_mac_address(self):
        cmd = "/sbin/ifconfig | awk '/HWaddr/ {print $5}'"
        return self.ssh_client.exec_command(cmd)