Merge branch 'feature/reversedns/check-users-vm-against-opennebula' into 'master'
Feature/reversedns/check users vm against opennebula See merge request ungleich-public/dynamicweb!707
This commit is contained in:
commit
cb244e78a1
2 changed files with 27 additions and 12 deletions
|
@ -26,11 +26,11 @@ from django.views.generic import (
|
||||||
View, CreateView, FormView, ListView, DetailView, DeleteView,
|
View, CreateView, FormView, ListView, DetailView, DeleteView,
|
||||||
TemplateView, UpdateView
|
TemplateView, UpdateView
|
||||||
)
|
)
|
||||||
from rest_framework.views import APIView
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework.renderers import JSONRenderer
|
|
||||||
from guardian.mixins import PermissionRequiredMixin
|
from guardian.mixins import PermissionRequiredMixin
|
||||||
from oca.pool import WrongIdError
|
from oca.pool import WrongIdError
|
||||||
|
from rest_framework.renderers import JSONRenderer
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.views import APIView
|
||||||
from stored_messages.api import mark_read
|
from stored_messages.api import mark_read
|
||||||
from stored_messages.models import Message
|
from stored_messages.models import Message
|
||||||
from stored_messages.settings import stored_messages_settings
|
from stored_messages.settings import stored_messages_settings
|
||||||
|
@ -1778,13 +1778,22 @@ class CheckUserVM(APIView):
|
||||||
response = check_otp(user, realm, token)
|
response = check_otp(user, realm, token)
|
||||||
if response != 200:
|
if response != 200:
|
||||||
return Response('Invalid token', 403)
|
return Response('Invalid token', 403)
|
||||||
uservms = VMDetail.objects.filter(user__email=email)
|
manager = OpenNebulaManager()
|
||||||
if len(uservms) > 0:
|
# not the best way to lookup vms by ip
|
||||||
for i in range(len(uservms)):
|
# TODO: make this optimal
|
||||||
if uservms[i].ipv4 == ip or uservms[i].ipv6 == ip:
|
vms = manager.get_vms()
|
||||||
return Response('success', 200)
|
users_vms = [vm for vm in vms if vm.uname == email]
|
||||||
return Response('No VM found matching the ip address provided', 404)
|
if len(users_vms) == 0:
|
||||||
else:
|
return Response('No VM found with the given email address',
|
||||||
return Response('No VM found with the given email address', 404)
|
404)
|
||||||
|
for vm in users_vms:
|
||||||
|
for nic in vm.template.nics:
|
||||||
|
if hasattr(nic, 'ip6_global'):
|
||||||
|
if nic.ip6_global == ip:
|
||||||
|
return Response('success', 200)
|
||||||
|
elif hasattr(nic, 'ip'):
|
||||||
|
if nic.ip == ip:
|
||||||
|
return Response('success', 200)
|
||||||
|
return Response('No VM found matching the ip address provided', 404)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return Response('Not enough data provided', 400)
|
return Response('Not enough data provided', 400)
|
||||||
|
|
|
@ -212,7 +212,13 @@ class OpenNebulaManager():
|
||||||
'Could not connect via client, using oneadmin instead')
|
'Could not connect via client, using oneadmin instead')
|
||||||
try:
|
try:
|
||||||
vm_pool = oca.VirtualMachinePool(self.oneadmin_client)
|
vm_pool = oca.VirtualMachinePool(self.oneadmin_client)
|
||||||
vm_pool.info(filter=-2)
|
if infoextended:
|
||||||
|
vm_pool.infoextended(
|
||||||
|
filter=-1, # User's resources and any of his groups
|
||||||
|
vm_state=-1 # Look for VMs in any state, except DONE
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
vm_pool.info(filter=-2)
|
||||||
return vm_pool
|
return vm_pool
|
||||||
except:
|
except:
|
||||||
raise ConnectionRefusedError
|
raise ConnectionRefusedError
|
||||||
|
|
Loading…
Reference in a new issue