Ask Your Question

Revision history [back]

Per http://lxer.com/module/newswire/view/225394/index.html

 [root@ip-192-169-142-127 api(keystone_admin)]# cat credentials.py
#!/usr/bin/env python
import os

def get_keystone_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['password'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['tenant_name'] = os.environ['OS_TENANT_NAME']
    return d

def get_nova_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['api_key'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['project_id'] = os.environ['OS_TENANT_NAME']
    return d

==================================================================

[root@ip-192-169-142-127 api(keystone_admin)]# cat assignFIP.py

#!/usr/bin/env python
import os
import time
from novaclient.v2.client import Client
from credentials import get_nova_creds

# Assign floating IP for active instance

creds = get_nova_creds()
nova = Client(**creds)
nova.floating_ip_pools.list()
floating_ip = nova.floating_ips.create(nova.floating_ip_pools.list()[0].name)
instance = nova.servers.find(name="Ubuntu1510Devs")
instance.add_floating_ip(floating_ip)