简体   繁体   中英

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.

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.

AttributeError: 'Client' object has no attribute 'floating_ips'

Most modern OpenStack deployments no longer use the legacy Nova network implementation, and instead use Neutron to manage networks and addresses. This means the Nova server does not provide the necessary API endpoints, so the floating_ips resource and methods are no longer available.

You would need to interact with Neutron in order to create a new floating ip address.

If you are writing your own OpenStack client you may want to investigate the shade module. This wraps around many of the OpenStack APIs to provide a more convenient programming interface. 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])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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