Ask Your Question
0

Openstack instance ip_address

asked 2019-01-12 06:33:49 -0500

najeh gravatar image

How can i get the fixed ip_address of an openstcak instance using python sdk ?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2019-01-12 08:07:09 -0500

updated 2019-01-15 07:52:51 -0500

find_server as documented in the openstacksdk API reference.

EDIT: find_server() returns a server object that only has the links populated. After this, you use get_server() to get all the details.

import openstack;

conn = openstack.connect(
    CONNECTION DETAILS
)

server = conn.compute.find_server(YOUR SERVER NAME)
server = conn.compute.get_server(server)
print(str(server))

for addrinfo in server.addresses['private']:
     print("{} ipv{} address {}\n".format(addrinfo['OS-EXT-IPS:type'],addrinfo['version'],addrinfo['addr']))

I get the following result, which includes both static and floating IPs:

openstack.compute.v2.server.Server(OS-EXT-STS:task_state=None, addresses={u'private': [{u'OS-EXT-IPS-MAC:mac_addr': u'fa:16:3e:47:41:56', u'version': 4, u'addr': u'10.0.0.25', u'OS-EXT-IPS:type': u'fixed'}, {u'OS-EXT-IPS-MAC:mac_addr': u'fa:16:3e:47:41:56', u'version': 4, u'addr': u'172.24.4.2', u'OS-EXT-IPS:type': u'floating'}]}, ....
fixed ipv4 address 10.0.0.25

floating ipv4 address 172.24.4.2
edit flag offensive delete link more

Comments

find_server display all information about the server but i need exactly the hostname of the instance "192.168.x.x".

how can i get it?

najeh gravatar imagenajeh ( 2019-01-13 06:06:59 -0500 )edit
1

As far as I understand it, it's a field in the Server object.

Bernd Bausch gravatar imageBernd Bausch ( 2019-01-13 07:58:17 -0500 )edit
1

Instructions how to set that field when launching an instance. Reading the field should not be harder.

Bernd Bausch gravatar imageBernd Bausch ( 2019-01-13 08:01:54 -0500 )edit

"opensttack server list" display like the table that contain all server details.I need the ip_address associated to networks for each instance. How can i get it ?

+------+-------+--------+----------+--------+

ID |Name |Status| Networks| Image

+------+-------+--------+-----------+-----

najeh gravatar imagenajeh ( 2019-01-14 05:35:36 -0500 )edit
1

I have never tried it, but why don’t you just print the server object returned by find_server() to find out?

Bernd Bausch gravatar imageBernd Bausch ( 2019-01-14 08:09:59 -0500 )edit

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: 2019-01-12 06:33:49 -0500

Seen: 45 times

Last updated: Jan 15