update ldap, update syncvm

This commit is contained in:
Nico Schottelius 2020-02-23 17:11:05 +01:00
parent edbfb7964e
commit 46921c43ad
3 changed files with 9 additions and 9 deletions

View file

@ -26,11 +26,14 @@ class Command(BaseCommand):
vms = json.loads(json.dumps(parse(response)))['VM_POOL']['VM']
for i, vm in enumerate(vms):
vm_id = vm['ID']
vm_owner = vm['UNAME']
vm_owner_email = vm['UNAME']
try:
user = get_user_model().objects.get(username=vm_owner)
user = get_user_model().objects.get(email=vm_owner_email)
except get_user_model().DoesNotExist:
user = get_user_model().objects.create_user(username=vm_owner)
print("Skipping VM import for unknown user with email: {}".format(vm_owner_email))
continue
# user = get_user_model().objects.create_user(username=vm_owner)
VMModel.objects.update_or_create(
defaults= { 'data': vm,
@ -40,3 +43,4 @@ class Command(BaseCommand):
else:
print(response)
print(uncloud.secrets.OPENNEBULA_USER_PASS)

View file

@ -17,7 +17,7 @@ class VMViewSet(viewsets.ModelViewSet):
def list(self, request):
queryset = VM.objects.filter(owner=request.user)
serializer = OpenNebulaVMSerializer(queryset, many=True)
serializer = OpenNebulaVMSerializer(queryset, many=True, context={'request': request})
return Response(serializer.data)
def retrieve(self, request, pk=None):

View file

@ -102,7 +102,7 @@ AUTH_PASSWORD_VALIDATORS = [
# AUTH/LDAP
import ldap
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion
from django_auth_ldap.config import LDAPSearch
AUTH_LDAP_SERVER_URI = uncloud.secrets.LDAP_SERVER_URI
@ -118,10 +118,6 @@ AUTH_LDAP_USER_SEARCH = LDAPSearch(
"dc=ungleich,dc=ch", ldap.SCOPE_SUBTREE, "(uid=%(user)s)"
)
#AUTH_LDAP_BIND_AS_AUTHENTICATING_USER=True
#AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=customer,dc=ungleich,dc=ch"
################################################################################
# AUTH/Django