Ask Your Question
0

how to get spice or vnc connect_port in openstack/ocata

asked 2017-04-15 11:03:42 -0500

luke@ocata gravatar image

updated 2017-04-19 01:41:44 -0500

Hi, I am trying to use remote-viewer to access an instance running in ocata. My neutron is dhcp-flat type, and i can see that the qemu-kvm is listening on 5901 from compute1.

I want to use python api to get instance connect_info. In nova/api.py,

def get_spice_console(self, context, instance, console_type):
    """Get a url to an instance Console."""
    connect_info = self.compute_rpcapi.get_spice_console(context,
            instance=instance, console_type=console_type)
    self.consoleauth_rpcapi.authorize_console(context,
            connect_info['token'], console_type,
            connect_info['host'], connect_info['port'],
            connect_info['internal_access_path'], instance.uuid,
            access_url=connect_info['access_url'])

    return {'url': connect_info['access_url']}

get_spice_console gets connect_info from self.compute_rpcapi.get_spice_console, and nova-compute would return connection info getting from libvirt xml, authorize_console be called so nova-spiceproxy can get connect_info from nova-consoleauth. api.get_spice_console returns a url, but how can i get the connect_info(ip, port) from my nova client?

from keystoneauth1 import loading
from keystoneauth1 import session 
from novaclient import client
loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(auth_url='http://controller:35357/v3', username='admin', password='11111111', project_name='admin', user_domain_name='Default', project_domain_name='Default')
sess = session.Session(auth=auth)
nova = client.Client(2, session=sess)
nova.servers.get_spice_console('4de610f2-37f4-4b29-958a-2bc2c50aaeb8', 'spice-html5')
# OUT: {u'console': {u'url': u'http://controller:6082/spice_auto.html?token=bb949780-b5de-4424-9ea2-728d6157c496', u'type': u'spice-html5'}}
cirros_console = nova.servers.get_spice_console('4de610f2-37f4-4b29-958a-2bc2c50aaeb8', 'spice-html5')
cirros_console
# OUT: {u'console': {u'url': u'http://controller:6082/spice_auto.html?token=c0e3ae92-d44a-4d82-be43-641854004043', u'type': u'spice-html5'}}
edit retag flag offensive close merge delete

Comments

the question is how to get spice connect_info(ip, port) from a instance id using nova client? then my nova client can instruct remote-viewer to connect the instance.

luke@ocata gravatar imageluke@ocata ( 2017-04-15 11:29:02 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-04-19 23:37:37 -0500

luke@ocata gravatar image

updated 2017-04-20 00:37:58 -0500

i changed api.py:

url_connect_info = connect_info['access_url'] + '&spice_host=' + connect_info['host'] + '&spice_port=' + connect_info['port']
return {'url': url_connect_info}

get the result:

>>> nova.servers.get_spice_console('4de610f2-37f4-4b29-958a-2bc2c50aaeb8', 'spice-html5')
{u'console': {u'url': u'http://controller:6082/spice_auto.html?token=63f3ab81-b745-42ba-ba05-623a1d5666b9&spice_host=192.168.120.160&s
pice_port=5900', u'type': u'spice-html5'}}
>>>

it can satisfy my need, but i still do not know whether i should write a new service instead of changing api.py?

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

Stats

Asked: 2017-04-15 11:03:42 -0500

Seen: 31 times

Last updated: Apr 20