尝试为项目测试 libcloud 的 ECS 驱动程序。
我写了一个简单的测试:
with open("conf.json") as f:
data = json.loads(f.read())
driver = get_driver(getattr(Provider,'ECS'))
with open('.cloud_credentials/'+data['provider']+'/access_id', 'r') as myfile:
ACCESS_KEY_ID = myfile.read().replace('\n', '')
print ACCESS_KEY_ID
with open('.cloud_credentials/'+data['provider']+'/secret_key', 'r') as myfile:
SECRET_KEY = myfile.read().replace('\n', '')
print SECRET_KEY
timer.start()
conn = driver(access_id = ACCESS_KEY_ID,
secret = SECRET_KEY,
region = 'us-east-1')
timer.stop()
cluster = conn.create_cluster('pippo','us-east-1')
但是运行它会产生这个错误:
Traceback (most recent call last):
File "launch.py", line 32, in <module>
cluster = conn.create_cluster('pippo',data['region'])
File "/home/sergio/anaconda2/lib/python2.7/site-packages/libcloud/container/drivers/ecs.py", line 151, in create_cluster
headers=self._get_headers('CreateCluster')
File "/home/sergio/anaconda2/lib/python2.7/site-packages/libcloud/common/base.py", line 604, in request
headers=headers, stream=stream)
File "/home/sergio/anaconda2/lib/python2.7/site-packages/libcloud/http.py", line 212, in request
verify=self.verification
File "/home/sergio/anaconda2/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/home/sergio/anaconda2/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/home/sergio/anaconda2/lib/python2.7/site-packages/requests/adapters.py", line 437, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='ecs.%s.amazonaws.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f5f16dca950>: Failed to establish a new connection: [Errno -2] Name or service not known',))
我认为问题在于包含该 %s 的主机字符串。在库中挖掘看起来该字符串是在文件中初始化的虚拟字符串:
/libcloud/container/drivers/ecs.py
我想这些文件中应该有一个函数应该覆盖基本字符串,由于某些原因可能不会被调用,但是作为 libcloud 库的新手,很难找到罪魁祸首。
奇怪的是,检查正在发送的标头,看起来它们包含正确的(?)地址:
headers: {'Host': u'ecs.us-east-1.amazonaws.com', 'User-Agent': 'libcloud/2.2.1 (Amazon Elastic Container Service) ', 'Content-Type': 'application/x-amz-json-1.1', 'Accept-Encoding': 'gzip,deflate', 'x-amz-target': 'AmazonEC2ContainerServiceV20141113.CreateCluster'}
有更多经验的人可以指出我正确的方向吗?将不胜感激。