Esempio n. 1
0
 def test_http_connection(self):
     url = 'http://www.test.com'
     _junk, conn = c.http_connection(url)
     self.assertTrue(isinstance(conn, c.HTTPConnection))
     url = 'https://www.test.com'
     _junk, conn = c.http_connection(url)
     self.assertTrue(isinstance(conn, c.HTTPSConnection))
     url = 'ftp://www.test.com'
     self.assertRaises(c.ClientException, c.http_connection, url)
Esempio n. 2
0
 def test_http_connection(self):
     url = 'http://www.test.com'
     _junk, conn = c.http_connection(url)
     self.assertTrue(isinstance(conn, c.HTTPConnection))
     url = 'https://www.test.com'
     _junk, conn = c.http_connection(url)
     self.assertTrue(isinstance(conn, c.HTTPSConnection))
     url = 'ftp://www.test.com'
     self.assertRaises(c.ClientException, c.http_connection, url)
Esempio n. 3
0
 def get_diskusage_total(self, account):
     object_nodes = set()
     for dev in self.__object_ring.devs:
         url = "http://%s:%d/recon/diskusage" % (dev['ip'], dev['port'])
         object_nodes.add(url)
     
     total_space = 0
     used_space = 0
     avail_space = 0
     for url in object_nodes:
         ##self.logger.critical("url = %s" % url)
         (parsed, conn) = http_connection(url)
         conn.request('GET', parsed.path, '', {})
         resp = conn.getresponse()
         resp_data = resp.read()
         #self.logger.critical("resp = %s" % resp_data)
         device_list = json.loads(resp_data)
         
         for device in device_list:
             if (device['size'] != ""):
                 total_space += int(device['size'])
             if (device['used'] != ""):
                 used_space += int(device['used'])
             if (device['avail'] != ""):
                 avail_space += int(device['avail'])
             #self.logger.critical("[get_diskusage_by_account] %s:%s - %s" % (url,device['device'], str(device['size'])))
             
     ret = dict()
     ret['account'] = account
     ret['total'] = total_space
     ret['used'] = used_space
     ret['avail'] = avail_space
     return ret
Esempio n. 4
0
def retry(func, *args, **kwargs):
    """
    You can use the kwargs to override the 'retries' (default: 5) and
    'use_account' (default: 1).
    """
    global url, token, parsed, conn
    retries = kwargs.get('retries', 5)
    use_account = 1
    if 'use_account' in kwargs:
        use_account = kwargs['use_account']
        del kwargs['use_account']
    use_account -= 1
    attempts = 0
    backoff = 1
    while attempts <= retries:
        attempts += 1
        try:
            if not url[use_account] or not token[use_account]:
                url[use_account], token[use_account] = \
                    get_auth(swift_test_auth, swift_test_user[use_account],
                             swift_test_key[use_account])
                parsed[use_account] = conn[use_account] = None
            if not parsed[use_account] or not conn[use_account]:
                parsed[use_account], conn[use_account] = \
                    http_connection(url[use_account])
            return func(url[use_account], token[use_account],
                        parsed[use_account], conn[use_account], *args,
                        **kwargs)
        except (socket.error, HTTPException):
            if attempts > retries:
                raise
            parsed[use_account] = conn[use_account] = None
        except AuthError, err:
            url[use_account] = token[use_account] = None
            continue
        except InternalServerError, err:
            pass
Esempio n. 5
0
def retry(func, *args, **kwargs):
    """
    You can use the kwargs to override the 'retries' (default: 5) and
    'use_account' (default: 1).
    """
    global url, token, parsed, conn
    retries = kwargs.get('retries', 5)
    use_account = 1
    if 'use_account' in kwargs:
        use_account = kwargs['use_account']
        del kwargs['use_account']
    use_account -= 1
    attempts = 0
    backoff = 1
    while attempts <= retries:
        attempts += 1
        try:
            if not url[use_account] or not token[use_account]:
                url[use_account], token[use_account] = \
                    get_auth(swift_test_auth, swift_test_user[use_account],
                             swift_test_key[use_account])
                parsed[use_account] = conn[use_account] = None
            if not parsed[use_account] or not conn[use_account]:
                parsed[use_account], conn[use_account] = \
                    http_connection(url[use_account])
            return func(url[use_account], token[use_account],
                       parsed[use_account], conn[use_account], *args, **kwargs)
        except (socket.error, HTTPException):
            if attempts > retries:
                raise
            parsed[use_account] = conn[use_account] = None
        except AuthError, err:
            url[use_account] = token[use_account] = None
            continue
        except InternalServerError, err:
            pass
Esempio n. 6
0
 def create(self):
     return client.http_connection(self.url)
Esempio n. 7
0
 def create(self):
     return client.http_connection(self.url)