【问题标题】:not able to connect using api openstack无法使用 api openstack 连接
【发布时间】:2018-04-28 10:59:41
【问题描述】:

我正在尝试使用 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"}}

我知道我提供的网址格式错误,但我无法弄清楚该网址应该是什么。

【问题讨论】:

    标签: python python-3.x rest django-rest-framework openstack


    【解决方案1】:

    我使用libcloudex_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 端口用于novav2 是 nova 版本。你应该检查你正在使用的 nova 版本。一个简单的检查方法是使用 CLI 或 OpenStack Dashboard。

    HTH。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-10
      • 1970-01-01
      • 2014-05-29
      相关资源
      最近更新 更多