def _is_instance_reachable(ip_address, retry_interval, timeout): """Verify the server can be pinged.""" start = int(time.time()) reachable = False while not reachable: reachable = PingClient.ping(ip_address) if reachable: return True time.sleep(retry_interval) if int(time.time()) - start >= timeout: return False
def verify_server_reachable(cls, ip=None): """ @summary: Verify server connectivity with a basic ping check. @param ip: IP address to ping. Defaults to SSH IPv4 address if no IP is provided @type ip: string """ if not ip: ip = cls.server.addresses.get_by_name( cls.servers_config.network_for_ssh).ipv4 if not PingClient.ping(ip): raise ServerUnreachable( "Server {id} was not pingable at {ip}".format( id=cls.server.id, ip=ip))
def verify_server_reachable(cls, ip=None): """ @summary: Verify server connectivity with a basic ping check. @param ip: IP address to ping. Defaults to SSH IPv4 address if no IP is provided @type ip: string """ if not ip: ip = cls.server.addresses.get_by_name( cls.servers_config.network_for_ssh).ipv4 if not PingClient.ping(ip): raise ServerUnreachable( "Server {id} was not pingable at {ip}".format(id=cls.server.id, ip=ip))
def __init__(self, ip_address=None, username='******', password=None, key=None, connection_timeout=600, retry_interval=10): self.client_log = cclogging.getLogger( cclogging.get_object_namespace(self.__class__)) if ip_address is None: raise ServerUnreachable("None") self.ip_address = ip_address self.username = username self.password = password # Verify the server can be pinged before attempting to connect start = int(time.time()) reachable = False while not reachable: reachable = PingClient.ping(ip_address) if reachable: break time.sleep(retry_interval) if int(time.time()) - start >= connection_timeout: raise ServerUnreachable(ip_address) if key is not None: auth_strategy = SSHAuthStrategy.KEY_STRING else: auth_strategy = SSHAuthStrategy.PASSWORD self.ssh_client = SSHBehaviors(username=self.username, password=self.password, host=self.ip_address, tcp_timeout=20, auth_strategy=auth_strategy, look_for_keys=False, key=key) self.ssh_client.connect_with_timeout(cooldown=20, timeout=connection_timeout) if not self.ssh_client.is_connected(): message = ('SSH timeout after {timeout} seconds: ' 'Could not connect to {ip_address}.') raise SshConnectionException( message.format(timeout=connection_timeout, ip_address=ip_address))
def __init__(self, ip_address=None, username='******', password=None, key=None, connection_timeout=600, retry_interval=10): self.client_log = cclogging.getLogger( cclogging.get_object_namespace(self.__class__)) if ip_address is None: raise ServerUnreachable("None") self.ip_address = ip_address self.username = username self.password = password self.connection_timeout = connection_timeout # Verify the server can be pinged before attempting to connect start = int(time.time()) reachable = False while not reachable: reachable = PingClient.ping(ip_address) if reachable: break time.sleep(retry_interval) if int(time.time()) - start >= connection_timeout: raise ServerUnreachable( 'Could not reach the server at {ip_address}'.format( ip_address=ip_address)) if key is not None: auth_strategy = SSHAuthStrategy.KEY_STRING else: auth_strategy = SSHAuthStrategy.PASSWORD self.ssh_client = SSHClient( username=self.username, password=self.password, host=self.ip_address, tcp_timeout=20, auth_strategy=auth_strategy, look_for_keys=False, key=key) self.ssh_client.connect_with_timeout( cooldown=20, timeout=connection_timeout) if not self.ssh_client.is_connected(): message = ('SSH timeout after {timeout} seconds: ' 'Could not connect to {ip_address}.') raise SshConnectionException(message.format( timeout=connection_timeout, ip_address=ip_address))