diff --git a/hooks/nova_compute_context.py b/hooks/nova_compute_context.py index d6518032..011f48b3 100644 --- a/hooks/nova_compute_context.py +++ b/hooks/nova_compute_context.py @@ -310,7 +310,42 @@ class CloudComputeContext(context.OSContextGenerator): if self.restart_trigger(): ctxt['restart_trigger'] = self.restart_trigger() + return ctxt + +class InstanceConsoleContext(context.OSContextGenerator): + interfaces = [] + + def get_console_info(self, proto, **kwargs): + console_settings = { + proto + '_proxy_address': + relation_get('console_proxy_%s_address' % (proto), **kwargs), + proto + '_proxy_host': + relation_get('console_proxy_%s_host' % (proto), **kwargs), + proto + '_proxy_port': + relation_get('console_proxy_%s_port' % (proto), **kwargs), + } + return console_settings + + def __call__(self): + ctxt = {} + for rid in relation_ids('cloud-compute'): + for unit in related_units(rid): + rel = {'rid': rid, 'unit': unit} + proto = relation_get('console_access_protocol', **rel) + if not proto: + # only bother with units that have a proto set. + continue + ctxt['console_keymap'] = relation_get('console_keymap', **rel) + ctxt['console_access_protocol'] = proto + ctxt['console_vnc_type'] = True if 'vnc' in proto else False + if proto == 'vnc': + ctxt = dict(ctxt, **self.get_console_info('xvpvnc', **rel)) + ctxt = dict(ctxt, **self.get_console_info('novnc', **rel)) + else: + ctxt = dict(ctxt, **self.get_console_info(proto, **rel)) + break + ctxt['console_listen_addr'] = get_host_ip(unit_get('private-address')) return ctxt diff --git a/hooks/nova_compute_utils.py b/hooks/nova_compute_utils.py index 601b916a..1f941407 100644 --- a/hooks/nova_compute_utils.py +++ b/hooks/nova_compute_utils.py @@ -32,6 +32,7 @@ from nova_compute_context import ( NovaComputeLibvirtContext, NovaComputeCephContext, NeutronComputeContext, + InstanceConsoleContext, ) CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' @@ -77,7 +78,8 @@ BASE_RESOURCE_MAP = { context.SubordinateConfigContext( interface='nova-ceilometer', service='nova', - config_file=NOVA_CONF)], + config_file=NOVA_CONF), + InstanceConsoleContext(), ], }, } diff --git a/templates/havana/nova.conf b/templates/havana/nova.conf index 0b16ad34..c2e461f6 100644 --- a/templates/havana/nova.conf +++ b/templates/havana/nova.conf @@ -36,6 +36,25 @@ rbd_user = {{ rbd_user }} rbd_secret_uuid = {{ rbd_secret_uuid }} {% endif -%} +{% if console_vnc_type -%} +vnc_enabled = True +novnc_enabled = True +vnc_keymap = {{ console_keymap }} +vncserver_listen = 0.0.0.0 +vncserver_proxyclient_address = {{ console_listen_addr }} +{% if console_access_protocol == 'novnc' or console_access_protocol == 'vnc' -%} +novncproxy_base_url = {{ novnc_proxy_address }} +{% endif -%} +{% if console_access_protocol == 'xvpvnc' or console_access_protocol == 'vnc' -%} +xvpvncproxy_port = {{ xvpvnc_proxy_port }} +xvpvncproxy_host = {{ xvpvnc_proxy_host }} +xvpvncproxy_base_url = {{ xvpvnc_proxy_address }} +{% endif -%} +{% else -%} +vnc_enabled = False +novnc_enabled = False +{% endif -%} + {% if neutron_plugin and neutron_plugin == 'ovs' -%} libvirt_vif_driver = nova.virt.libvirt.vif.LibvirtGenericVIFDriver {% if neutron_security_groups -%} @@ -85,3 +104,13 @@ instances_path = {{ instances_path }} {{ key }} = {{ value }} {% endfor -%} {% endif -%} + +{% if console_access_protocol == 'spice' -%} +[spice] +agent_enabled = True +enabled = True +html5proxy_base_url = {{ spice_proxy_address }} +keymap = {{ console_keymap }} +server_listen = 0.0.0.0 +server_proxyclient_address = {{ console_listen_addr }} +{% endif -%}