[英]not able to connect using api openstack
我正在嘗試使用lib雲庫連接到我的本地openstack安裝。
以下是我嘗試執行的代碼:
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
# Authentication information so you can authenticate to DreamCompute
# copy the details from the OpenStack RC file
# https://dashboard.dreamcompute.com/project/access_and_security/api_access/openrc/
auth_username = 'admin'
auth_password = 'f882e2f4eaad434c'
TENANT_NAME = 'admin'
project_name = 'admin'
auth_url = 'http://192.168.56.101:5000'
#auth_url = 'http://192.168.56.101:5000'
region_name = 'RegionOne'
OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack('auth_username',
'auth_password',
ex_force_auth_url=auth_url,
ex_force_base_url='http://192.168.56.101',
ex_force_auth_version='2.0_password',
ex_tenant_name='admin',
ex_force_service_name='nova',
ex_force_service_region=region_name)
print(dir(driver.list_nodes))
print(driver.api_name)
print(driver.VOLUME_STATE_MAP)
#print(driver.connection.auth_user_info)
images = driver.name
print(driver.list_volumes())
"""for image in images:
print(image)
"""
但是我一直得到找不到錯誤消息資源:
C:\Python dev\website\music\openstack>python openstack.py
['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__func__', '__ge__', '__get__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
openstack
{'creating': 'creating', 'available': 'available', 'attaching': 'attaching', 'in-use': 'inuse', 'deleting': 'deleting', 'error': 'error', 'error_deleting': 'error', 'backing-up': 'backup', 'restoring-backup': 'backup', 'error_restoring': 'error', 'error_extending': 'error'}
Traceback (most recent call last):
File "openstack.py", line 31, in <module>
print(driver.list_volumes())
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\compute\drivers\openstack.py", line 265, in list_volumes
self.connection.request('/os-volumes').object)
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\common\openstack.py", line 223, in request
raw=raw)
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\common\base.py", line 536, in request
action = self.morph_action_hook(action)
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\common\openstack.py", line 290, in morph_action_hook
self._populate_hosts_and_request_paths()
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\common\openstack.py", line 324, in _populate_hosts_and_request_paths
osa = osa.authenticate(**kwargs) # may throw InvalidCreds
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\common\openstack_identity.py", line 855, in authenticate
return self._authenticate_2_0_with_password()
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\common\openstack_identity.py", line 880, in _authenticate_2_0_with_password
return self._authenticate_2_0_with_body(reqbody)
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\common\openstack_identity.py", line 885, in _authenticate_2_0_with_body
method='POST')
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\common\base.py", line 637, in request
response = responseCls(**kwargs)
File "C:\Users\C5265680\AppData\Local\Programs\Python\Python36\lib\site-packages\libcloud\common\base.py", line 157, in __init__
message=self.parse_error())
libcloud.common.exceptions.BaseHTTPError: {"error": {"message": "The resource could not be found.", "code": 404, "title": "Not Found"}}
我知道我提供的網址格式錯誤,但是我無法弄清楚該網址應該是什么。
我將libcloud
與ex_force_auth_token
一起ex_force_auth_token
。 但根據此頁面: http : //libcloud.readthedocs.io/en/latest/compute/drivers/openstack.html
我相信您想要的是:
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
import libcloud.security
# This assumes you don't have SSL set up.
# Note: Code like this poses a security risk (MITM attack) and
# that's the reason why you should never use it for anything else
# besides testing. You have been warned.
libcloud.security.VERIFY_SSL_CERT = False
OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack('your_auth_username', 'your_auth_password',
ex_force_auth_url='http://192.168.1.101:5000',
ex_force_auth_version='2.0_password',
ex_force_service_type='compute',
ex_force_service_name='novaCompute',
ex_force_service_region='MyRegion')
我注意到您也將ex_force_base_url
放在了那里。 那應該可以,但是您的ex_force_base_url
應該是http://192.168.56.101:8774/v2
這里的端口8774用於nova
而v2
是nova版本。 您應該檢查使用的nova版本。 一種簡單的檢查方法是使用CLI或OpenStack儀表板。
HTH。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.