def remote(self, node_name=None, host=None, address_pool=None, username=None): """Get SSHClient by a node name or hostname. One of the following arguments should be specified: - host (str): IP address or hostname. If specified, 'node_name' is ignored. - node_name (str): Name of the node stored to config.underlay.ssh - address_pool (str): optional for node_name. If None, use the first matched node_name. """ ssh_data = self.__ssh_data(node_name=node_name, host=host, address_pool=address_pool) ssh_auth = ssh_client.SSHAuth( username=username or ssh_data['login'], password=ssh_data['password'], keys=[ rsakey.RSAKey(file_obj=StringIO.StringIO(key)) for key in ssh_data['keys'] ]) client = ssh_client.SSHClient(host=ssh_data['host'], port=ssh_data['port'] or 22, auth=ssh_auth) client._ssh.get_transport().set_keepalive( settings.SSH_SERVER_ALIVE_INTERVAL) return client
def find_node_remote(self, node_name, login=settings.SSH_SLAVE_CREDENTIALS['login'], password=settings.SSH_SLAVE_CREDENTIALS['password']): ip = self.find_node_ip(node_name) return ssh_client.SSHClient( ip, auth=ssh_client.SSHAuth( username=login, password=password))
def get_ssh_to_remote_by_key(ip, keyfile): warnings.warn('LEGACY, for fuel-qa compatibility', DeprecationWarning) try: with open(keyfile) as f: keys = [paramiko.RSAKey.from_private_key(f)] except IOError: logger.warning('Loading of SSH key from file failed. Trying to use' ' SSH agent ...') keys = paramiko.Agent().get_keys() return ssh_client.SSHClient(ip, auth=ssh_client.SSHAuth(keys=keys))
def __get_file(self, mode="r"): if self.host: remote = ssh_client.SSHClient(host=self.host, port=self.port, username=self.username, password=self.__password, private_keys=self.__private_keys) return remote.open(self.__file_path, mode=mode) else: return open(self.__file_path, mode=mode)
def wait_ssh_cmd(host, port, check_cmd, username=settings.SSH_CREDENTIALS['login'], password=settings.SSH_CREDENTIALS['password'], timeout=0): ssh = ssh_client.SSHClient(host=host, port=port, auth=ssh_client.SSHAuth(username=username, password=password)) wait(lambda: not ssh.execute(check_cmd)['exit_code'], timeout=timeout)
def get_admin_remote(self, login=settings.SSH_CREDENTIALS['login'], password=settings.SSH_CREDENTIALS['password']): admin_ip = self.get_admin_ip() admin_node = self.get_admin() helpers.wait_tcp( host=admin_ip, port=admin_node.ssh_port, timeout=180, timeout_msg=("Admin node {ip} is not accessible by SSH." "".format(ip=admin_ip))) return ssh_client.SSHClient( admin_ip, auth=ssh_client.SSHAuth(username=login, password=password))
def remote( self, network_name, login=None, password=None, private_keys=None, auth=None): """Create SSH-connection to the network NOTE: this method works only for master node :rtype : SSHClient """ return ssh_client.SSHClient( self.get_ip_address_by_network_name(network_name), username=login, password=password, private_keys=private_keys, auth=auth)
def __get_file(self, mode="r"): if self.host: keys = map(paramiko.RSAKey.from_private_key, map(StringIO.StringIO, self.__private_keys)) remote = ssh_client.SSHClient(host=self.host, port=self.port, username=self.username, password=self.__password, private_keys=keys) return remote.open(self.__file_path, mode=mode) else: return open(self.__file_path, mode=mode)
def get_node_remote(self, node_name, login=settings.SSH_SLAVE_CREDENTIALS['login'], password=settings.SSH_SLAVE_CREDENTIALS['password']): node = self.get_node(name=node_name) ip = self.get_node_ip(node_name) helpers.wait_tcp( host=ip, port=node.ssh_port, timeout=180, timeout_msg="Node {ip} is not accessible by SSH.".format(ip=ip)) return ssh_client.SSHClient( ip, auth=ssh_client.SSHAuth( username=login, password=password, keys=self.get_private_keys()))
def get_ssh_to_remote(self, ip, login=settings.SSH_SLAVE_CREDENTIALS['login'], password=settings.SSH_SLAVE_CREDENTIALS['password']): msg = ('get_ssh_to_remote has been deprecated in favor of ' 'DevopsEnvironment.get_node_remote') logger.warning(msg) warnings.warn(msg, DeprecationWarning) from devops import client env = client.DevopsClient().get_env(self.name) return ssh_client.SSHClient(ip, auth=ssh_client.SSHAuth( username=login, password=password, keys=env.get_private_keys()))
def remote(self, node_name=None, host=None, address_pool=None): """Get SSHClient by a node name or hostname. One of the following arguments should be specified: - host (str): IP address or hostname. If specified, 'node_name' is ignored. - node_name (str): Name of the node stored to config.underlay.ssh - address_pool (str): optional for node_name. If None, use the first matched node_name. """ ssh_data = self.__ssh_data(node_name=node_name, host=host, address_pool=address_pool) return ssh_client.SSHClient(host=ssh_data['host'], port=ssh_data['port'] or 22, username=ssh_data['login'], password=ssh_data['password'], private_keys=ssh_data['keys'])