Commit bb54accb authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Merge branch 'feature-helpdesk-ips' into develop

parents ceb8087e d3957519
......@@ -274,3 +274,11 @@ class MacPrefixPoolTableFactory(factory.DjangoModelFactory):
class QuotaHolderSerialFactory(factory.DjangoModelFactory):
FACTORY_FOR = models.QuotaHolderSerial
serial = factory.Sequence(lambda x: x, type=int)
class IPAddressLogFactory(factory.DjangoModelFactory):
FACTORY_FOR = models.IPAddressLog
address = "192.168.2.1"
server_id = 1
network_id = 1
active = True
......@@ -192,3 +192,12 @@ h3.info { cursor:default; color:#2956B2; text-align:center; font-size:16px
.vm-action form { margin-bottom: 0px; }
.vm-action.inactive form input { background-color: #2956B2; color: #ffffff;}
.vm-action form input { background-color: #F81A23; color: #ffffff;}
.table-sorted th:hover { color:#2956B2; cursor:pointer; }
.table-sorted th span { padding-right:20px; }
.table-sorted th:hover span { background:url(../img/arrow-down.png) no-repeat right center; }
.table-sorted th.headerSortDown span,
.table-sorted th.headerSortDown:hover span { background:url(../img/arrow-up.png) no-repeat right center; }
.table-sorted th.headerSortUp span,
.table-sorted th.headerSortUp:hover span { background:url(../img/arrow-down.png) no-repeat right center; }
......@@ -2,7 +2,14 @@ $(document).ready(function(){ $("input").focus(); })
$(document).ready(function(){
// table sorting
$('.table-sorted').tablesorter({
sortList : [[2,0]],
});
// fix sub nav on scroll
var $win = $(window)
, $nav = $('.subnav')
......
......@@ -19,7 +19,7 @@
</div>
<div class="span5">
<form class="form-horizontal account-form" method="get" action=".">
<input type="text" class="input-medium search-query" name="account" autocomplete="off">
<input type="text" class="input-medium search-query" name="account">
<button type="submit" class="btn">View account</button>
</form>
</div>
......@@ -41,7 +41,7 @@
</div>
<script src="{{ MEDIA_URL }}helpdesk/js/jquery.js"></script>
<script src="{{ MEDIA_URL }}helpdesk/js/bootstrap.js"></script>
<script src="{{ MEDIA_URL }}helpdesk/js/common.js"></script>
<script src="{{ MEDIA_URL }}helpdesk/js/jquery.tablesorter.js"></script>
<script src="{{ MEDIA_URL }}helpdesk/js/common.js"></script>
</body>
</html>
{% extends "helpdesk/base.html" %}
{% block extraheader %}
<small>/ {{ search_query }}</small>
{% endblock %}
{% block content %}
{% if ip_exists %}
<h3>IP Address {{ search_query }}</h3>
<table class="table table-striped table-sorted table-ip">
<thead>
<tr>
<th><span> Server</span></th>
<th><span> Network </span></th>
<th><span> Allocated </span></th>
<th><span> Released </span></th>
<th><span> Account </span></th>
</tr>
</thead>
<tbody>
{% for ip in ips %}
<tr>
<td>
{% if ip.released_at %}
Server {{ ip.server_id }}
{% else %}
<a href="vm-{{ ip.server_id }}">Server {{ ip.server_id }}</a>
{% endif %}
</td>
<td> Network {{ ip.network_id }} </td>
<td> {{ ip.allocated_at|date:"r" }} </td>
<td>
{% if ip.released_at %}
{{ ip.released_at|date:"r" }}
{% else %}
-
{% endif %}
</td>
<td><a href="{{ ip.account }}">{{ ip.account }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p> IP Address <em>{{ search_query }}</em> has never been allocated to any server. </p>
{% endif %}
{% endblock %}
......@@ -150,6 +150,10 @@ class HelpdeskTests(TestCase):
network__public=True,
network__userid=None,
address="195.251.222.211")
mfactory.IPAddressLogFactory(address=ip2.address,
server_id=vm1u1.id,
network_id=ip2.network.id,
active=True)
def test_enabled_setting(self):
settings.HELPDESK_ENABLED = False
......@@ -166,12 +170,16 @@ class HelpdeskTests(TestCase):
# ip does not exist, proper message gets displayed
r = self.client.get(reverse('helpdesk-details',
args=["195.251.221.122"]), user_token='0001')
self.assertContains(r, 'User with IP')
self.assertFalse(r.context["ip_exists"])
self.assertEqual(list(r.context["ips"]), [])
# ip exists, 'test' account discovered
# ip exists
r = self.client.get(reverse('helpdesk-details',
args=["195.251.222.211"]), user_token='0001')
self.assertEqual(r.context['account'], USER1)
self.assertTrue(r.context["ip_exists"])
ips = r.context["ips"]
for ip in ips:
self.assertEqual(ip.address, "195.251.222.211")
def test_vm_lookup(self):
# vm id does not exist
......
......@@ -46,7 +46,7 @@ from urllib import unquote
import astakosclient
from snf_django.lib import astakos
from synnefo.db.models import VirtualMachine, IPAddress, Network
from synnefo.db.models import VirtualMachine, Network, IPAddressLog
# server actions specific imports
from synnefo.api import util
......@@ -190,14 +190,8 @@ def account(request, search_query):
auth_token = request.user['access']['token']['id']
if is_ip:
try:
ip = IPAddress.objects.filter(address=search_query, deleted=False)\
.get()
search_query = ip.userid
is_uuid = True
except IPAddress.DoesNotExist:
account_exists = False
account = None
# Search the IPAddressLog for the full use history of this IP
return search_by_ip(request, search_query)
if is_vm:
vmid = is_vm.groupdict().get('vmid')
......@@ -274,6 +268,41 @@ def account(request, search_query):
extra_context=user_context)
def search_by_ip(request, search_query):
"""Search IP history for all uses of an IP address."""
auth_token = request.user['access']['token']['id']
astakos_client = astakosclient.AstakosClient(auth_token,
settings.ASTAKOS_AUTH_URL,
retry=2, use_pool=True,
logger=logger)
ips = IPAddressLog.objects.filter(address=search_query)\
.order_by("allocated_at")
for ip in ips:
# Annotate IPs with the VM, Network and account attributes
ip.vm = VirtualMachine.objects.get(id=ip.server_id)
ip.network = Network.objects.get(id=ip.network_id)
userid = ip.vm.userid
try:
ip.account = astakos_client.get_username(userid)
except:
ip.account = userid
logger.info("Failed to resolve '%s' into account" % userid)
user_context = {
'ip_exists': bool(ips),
'ips': ips,
'search_query': search_query,
'token': auth_token,
'HELPDESK_MEDIA_URL': HELPDESK_MEDIA_URL,
'UI_MEDIA_URL': UI_MEDIA_URL
}
return direct_to_template(request, "helpdesk/ip.html",
extra_context=user_context)
@helpdesk_user_required
@token_check
def vm_suspend(request, vm_id):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment