Show security groups for instance in overview detail.
Fixes bug 897090, since IP information is displayed as nova returns it. Change-Id: If64ec14ba4cf6b081a7a99aa7ccee0aef70efa35
This commit is contained in:
parent
d3f2552547
commit
ceed483843
@ -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)
|
||||
|
||||
|
@ -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,
|
||||
|
@ -36,6 +36,25 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="security_groups row-fluid">
|
||||
<h4>{% trans "Security Groups" %}</h4>
|
||||
<hr class="header_rule">
|
||||
{% for group in instance.security_groups %}
|
||||
<ul>
|
||||
<li>
|
||||
<strong>{{ group.name }}</strong>
|
||||
<ul>
|
||||
{% for rule in group.rules %}
|
||||
<li>{{ rule }}</li>
|
||||
{% empty %}
|
||||
<li><em>{% trans "No rules defined." %}</em></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="meta row-fluid">
|
||||
<h4>{% trans "Meta" %}</h4>
|
||||
<hr class="header_rule">
|
||||
|
Loading…
Reference in New Issue
Block a user