diff --git a/horizon/api/nova.py b/horizon/api/nova.py index c90d75ef2..ea1806ed8 100644 --- a/horizon/api/nova.py +++ b/horizon/api/nova.py @@ -26,6 +26,7 @@ import logging from novaclient.v1_1 import client as nova_client from novaclient.v1_1 import security_group_rules as nova_rules +from novaclient.v1_1.security_groups import SecurityGroup as NovaSecurityGroup from novaclient.v1_1.servers import REBOOT_HARD from horizon.api.base import APIResourceWrapper, APIDictWrapper, url_for @@ -303,6 +304,28 @@ def server_console_output(request, instance_id, tail_length=None): length=tail_length) +def server_security_groups(request, instance_id): + """Gets security groups of an instance.""" + # TODO(gabriel): This needs to be moved up to novaclient, and should + # be removed once novaclient supports this call. + security_groups = [] + nclient = novaclient(request) + resp, body = nclient.client.get('/servers/%s/os-security-groups' + % instance_id) + if body: + # Wrap data in SG objects as novaclient would. + sg_objects = [NovaSecurityGroup(nclient.security_groups, sg) for + sg in body.get('security_groups', [])] + # Then wrap novaclient's object with our own. Yes, sadly wrapping + # with two layers of objects is necessary. + security_groups = [SecurityGroup(sg) for sg in sg_objects] + # Package up the rules, as well. + for sg in security_groups: + rule_objects = [SecurityGroupRule(rule) for rule in sg.rules] + sg.rules = rule_objects + return security_groups + + def server_pause(request, instance_id): novaclient(request).servers.pause(instance_id) diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/views.py b/horizon/dashboards/nova/instances_and_volumes/instances/views.py index 001e98e63..21856d1fc 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/views.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/views.py @@ -109,6 +109,8 @@ class DetailView(tabs.TabView): full_flavors = SortedDict([(str(flavor.id), flavor) for \ flavor in flavors]) instance.full_flavor = full_flavors[instance.flavor["id"]] + instance.security_groups = api.server_security_groups( + self.request, instance_id) except: redirect = reverse('horizon:nova:instances_and_volumes:index') exceptions.handle(self.request, diff --git a/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_overview.html b/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_overview.html index 57f1aefbc..1a67793b3 100644 --- a/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_overview.html +++ b/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_overview.html @@ -36,6 +36,25 @@ +
+

{% trans "Security Groups" %}

+
+ {% for group in instance.security_groups %} + + {% endfor %} +
+

{% trans "Meta" %}