简体   繁体   English

nova客户端上的OpenStack Nova float_ips不存在

[英]OpenStack Nova floating_ips on nova client doesn't exist

A call to a setup and functional nova client using nova version "2" has no floating_ips attribute. 使用nova版本“ 2”对设置和功能nova客户端的调用没有float_ips属性。

from novaclient import client as NovaClient
class FloatingIpProvisioner():
    def __init__(self, os_session):
        self.nova = NovaClient.Client(version="2", session=os_session)

    def AddFloatingIpToInstance(self, instance):
        self.nova.floating_ip_pools
        floating_ip = self.nova.floating_ips.create()
        instance = self.nova.servers.find(name="test")
        instance.add_floating_ip(floating_ip)
        return floating_ip

instance = NovaClient.Client(version="2", session=session).servers.find(name="ansiblemaster")
floatingIp = FloatingIpProvisioner(session).AddFloatingIpToInstance(instance)

When calling above file we have Error: 调用上述文件时,出现错误:

File "provision.py", line 68, in AddFloatingIpToInstance
    floating_ip = self.nova.floating_ips.create()
AttributeError: 'Client' object has no attribute 'floating_ips'

This is the way Openstack and many 3rd party tutorials add floating ips to instances. 这是Openstack和许多第三方教程向实例添加浮动ip的方式。

AttributeError: 'Client' object has no attribute 'floating_ips' AttributeError:“客户端”对象没有属性“ floating_ips”

Most modern OpenStack deployments no longer use the legacy Nova network implementation, and instead use Neutron to manage networks and addresses. 大多数现代OpenStack部署不再使用传统的Nova网络实施,而是使用Neutron来管理网络和地址。 This means the Nova server does not provide the necessary API endpoints, so the floating_ips resource and methods are no longer available. 这意味着Nova服务器没有提供必要的API端点,因此floating_ips资源和方法不再可用。

You would need to interact with Neutron in order to create a new floating ip address. 您需要与Neutron进行交互才能创建一个新的浮动IP地址。

If you are writing your own OpenStack client you may want to investigate the shade module. 如果您正在编写自己的OpenStack客户端,则可能需要研究shade模块。 This wraps around many of the OpenStack APIs to provide a more convenient programming interface. 这包装了许多OpenStack API,以提供更方便的编程接口。 For example, your code becomes: 例如,您的代码变为:

import shade

cloud = shade.openstack_cloud()    

def AddFloatingIpToInstance(self, server_name, external_network='public'):
    server = cloud.get_server(server_name)
    ip = cloud.create_floating_ip(external_network)
    cloud.add_ips_to_server(server, ips=[ip])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM