Ask Your Question
0

how to associate floating_ip to a server

asked 2015-11-17 21:37:36 -0600

John Zhao gravatar image

I am using novaclient 2.0. After creating a server and floating IP, what is the syntax to associate the ip to the server?

Thanks,

John

edit retag flag offensive close merge delete

Comments

Would Neutron CLI satisfy you ? or you need API.

dbaxps gravatar imagedbaxps ( 2015-11-18 03:08:22 -0600 )edit

I am writing a python application, and need python API call syntax. Thanks.

John Zhao gravatar imageJohn Zhao ( 2015-11-18 08:27:28 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2015-11-18 09:32:48 -0600

dbaxps gravatar image

updated 2015-11-19 03:05:56 -0600

See https://albertomolina.wordpress.com/2...
Create in current dir and compile 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

Final draft

ubuntu@ubuntu-System:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from novaclient.v2  import client
>>> from credentials import get_nova_creds
>>> creds = get_nova_creds()
>>> nova = client.Client(**creds)
>>> nova.security_groups.list()
[<SecurityGroup description=Default security group, id=a371f267-4663-4c6a-9d98-ee10ee0d6578, name=default, rules=[{u'from_port': 22, u'group': {}, u'ip_protocol': u'tcp', u'to_port': 22, u'parent_group_id': u'a371f267-4663-4c6a-9d98-ee10ee0d6578', u'ip_range': {u'cidr': u'0.0.0.0/0'}, u'id': u'264a5a77-5171-4bc4-9247-e9b1a918160d'}, {u'from_port': None, u'group': {u'tenant_id': u'65f0f61efdf14137a62d0df0cc1358dd', u'name': u'default'}, u'ip_protocol': None, u'to_port': None, u'parent_group_id': u'a371f267-4663-4c6a-9d98-ee10ee0d6578', u'ip_range': {}, u'id': u'2b589891-7f70-4730-b7f0-56c2fc2fb639'}, {u'from_port': None, u'group': {u'tenant_id': u'65f0f61efdf14137a62d0df0cc1358dd', u'name': u'default'}, u'ip_protocol': None, u'to_port': None, u'parent_group_id': u'a371f267-4663-4c6a-9d98-ee10ee0d6578', u'ip_range': {}, u'id': u'4bfca1b5-ef73-448f-8dc9-f1691e47b319'}, {u'from_port': -1, u'group': {}, u'ip_protocol': u'icmp', u'to_port': -1, u'parent_group_id': u'a371f267-4663-4c6a-9d98-ee10ee0d6578', u'ip_range': {u'cidr': u'0.0.0.0/0'}, u'id': u'77f76909-106d-4615-a348-a823d8bd4e65'}], tenant_id=65f0f61efdf14137a62d0df0cc1358dd>]
>>> f = open('.ssh/id_rsa.pub','r')
>>> publickey = f.readline()[:-1]
>>> keypair = nova.keypairs.create('id_rsa',publickey)
>>> f.close()
>>> nova.floating_ip_pools.list()
[<FloatingIPPool: name=public>]
>>> floating_ip = nova.floating_ips.create(nova.floating_ip_pools.list()[0].name)
>>> floating_ip.ip
u'192.168.12.154'
>>> nova.images.list()
[<Image: VF22Cloud>, <Image: cirros-0.3.4-x86_64-uec>, <Image: cirros-0.3.4-x86_64-uec-ramdisk>, <Image: cirros-0.3.4-x86_64-uec-kernel>]
>>> image = nova.images.find(name="VF22Cloud")
>>> flavor = nova.flavors.find(name="m1.small")
>>> nova.networks.list()
[<Network: public>, <Network: private>]
>>> network = nova.networks.find(label="private")
>>> server = nova.servers.create(name = "vf22devs12",
... image = image.id,
... flavor = flavor.id, 
... network = network.id,
... key_name = keypair.name)
>>> server.status
u'ACTIVE'
>>> server.addresses
{u'private': [{u'OS-EXT-IPS-MAC:mac_addr': u'fa:16:3e:06:c0:8f', u'version': 6, u'addr': u'fde8:5a0d:9d30:0:f816:3eff:fe06:c08f', u'OS-EXT-IPS:type': u'fixed'}, {u'OS-EXT-IPS-MAC:mac_addr': u'fa:16:3e:06:c0:8f', u'version': 4, u'addr': u'10.254.1.6', u'OS-EXT-IPS:type': u'fixed'}]}
>>> server.add_floating_ip(floating_ip)
>>>

Via CLI :-

ubuntu@ubuntu-System:~$ nova list
+--------------------------------------+------------+---------+------------+-------------+--------------------------------------------------------------------------+
| ID                                   | Name       | Status  | Task State | Power State | Networks                                                                 |
+--------------------------------------+------------+---------+------------+-------------+--------------------------------------------------------------------------+
| f62be10f-9a4d-4dab-bd1a-90eb90b04713 | vf22devs12 | ACTIVE  | -          | Running     | private=fde8:5a0d:9d30:0:f816:3eff:fe06:c08f, 10.254.1.6, 192.168.12.154 |
+--------------------------------------+------------+---------+------------+-------------+--------------------------------------------------------------------------+
ubuntu@ubuntu-System:~$ ping 192.168.12.154
PING 192.168.12.154 (192.168.12.154) 56(84) bytes of data.
64 bytes from 192.168.12.154: icmp_seq=1 ttl=63 time=0.944 ms
64 bytes from 192.168.12.154: icmp_seq=2 ttl=63 time=0.187 ...
(more)
edit flag offensive delete link more
0

answered 2015-11-18 08:53:38 -0600

John Zhao gravatar image

found the syntax. It is myInstance.add_floating_ip(myIP)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2015-11-17 21:37:36 -0600

Seen: 181 times

Last updated: Nov 19 '15