我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用fabric.api.env.timeout()。
def block_until_http_ready(urlstring, wait_time=10, timeout=240): "Blocks until server at urlstring can respond to http requests" server_ready = False t_elapsed = 0 while not server_ready and t_elapsed < timeout: try: sys.stdout.write('.') sys.stdout.flush() req = urllib2.Request(urlstring) response = urllib2.urlopen(req) #if response.code == 200: server_ready = True except urllib2.URLError: pass time.sleep(wait_time) t_elapsed += wait_time
def connect_to_instance_in_ssh(address, keypair_path, user='root'): """ Run the command LS on a given instance :param address: ip or dns name of a machine :type address: str :param keypair_path: keypair path :type keypair_path: str """ env.host_string = address env.user = user env.parallel = False env.key_filename = keypair_path env.disable_known_hosts = True env.connection_attempts = 10 env.timeout = 120 ocb.log(run('ls -la /root'), level='INFO')
def block_until_ssh_open(ipstring, wait_time=10, timeout=120): "Blocks until server at ipstring has an open port 22" reached = False t_elapsed = 0 while not reached and t_elapsed < timeout: try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((ipstring, 22)) reached = True except socket.error as err: time.sleep(wait_time) t_elapsed += wait_time sock.close()
def _init_fabric(self): env.warn_only = True env.connection_attempts = 10 env.timeout = 10 env.user = self.user env.key_filename = self.key_filename env.hosts = self.hosts env.password = self.password