def _wait_for_server(cs, s, with_url_ping=False):
    while s.status != 'ACTIVE':
        sleep(60)
        s = cs.servers.get(s.id)
        print '%s: %s (%s%%)' % (s.id, s.status, s.progress)

    if with_url_ping:
        # Wait for a response
        url = 'http://%s/index.html' % s.public_ip
        tries = 0
        while True:
            try:
                print 'Attempting to connect to %s' % url
                urllib2.urlopen(url)
                print 'ping success, returning'
                break
            except urllib2.HTTPError, e:
                print e
                if e.code == 401:
                    print '401 not authorized'
                elif e.code == 404:
                    print '404 not found... waiting...'
                elif e.code == 503:
                    print '503 service unavailable'
                else:
                    print 'unknown error: %s' % e
                sleep(30)
            except urllib2.URLError, u:
                print u
                print 'Connection refused for now...'
                sleep(30)

            tries += 1
            if tries > 20:  # 10 minutes
                raise Exception('URL ping timed out')
dataset/ETHPy150Open nicholaskuechler/autoscale-rackspacecloud-fabric-celery/fabfile.py/_wait_for_server/original