quota nextcloud
This commit is contained in:
parent
e2dd8a90ae
commit
8eae8e624f
|
@ -10,6 +10,8 @@ from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from orchestra.contrib.orchestration import ServiceController
|
from orchestra.contrib.orchestration import ServiceController
|
||||||
from orchestra.contrib.resources import ServiceMonitor
|
from orchestra.contrib.resources import ServiceMonitor
|
||||||
|
from orchestra.contrib.resources.models import ResourceData
|
||||||
|
from orchestra.contrib.saas.models import SaaS
|
||||||
|
|
||||||
from . import ApacheTrafficByName
|
from . import ApacheTrafficByName
|
||||||
from .. import settings
|
from .. import settings
|
||||||
|
@ -52,11 +54,31 @@ class NextCloudAPIMixin(object):
|
||||||
def create(self, saas):
|
def create(self, saas):
|
||||||
data = {
|
data = {
|
||||||
'userid': saas.name,
|
'userid': saas.name,
|
||||||
'password': saas.password
|
'password': saas.password,
|
||||||
}
|
}
|
||||||
self.api_post('users', data)
|
self.api_post('users', data)
|
||||||
|
|
||||||
|
def update_group(self, saas):
|
||||||
|
data = {
|
||||||
|
'groupid': saas.account.username
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
self.api_get('groups/%s' % saas.account.username)
|
||||||
|
except RuntimeError:
|
||||||
|
self.api_post('groups', data)
|
||||||
|
self.api_post(f'users/{saas.name}/groups', data)
|
||||||
|
|
||||||
def update(self, saas):
|
def update_quota(self, saas):
|
||||||
|
if hasattr(saas, 'resources') and hasattr(saas.resources, 'nextcloud-disk'):
|
||||||
|
resource = getattr(saas.resources, 'nextcloud-disk')
|
||||||
|
quotaValue = f"{resource.allocated}G" if resource.allocated > 0 else "default"
|
||||||
|
data = {
|
||||||
|
'key': "quota",
|
||||||
|
'value': quotaValue
|
||||||
|
}
|
||||||
|
self.api_put(f'users/{saas.name}', data)
|
||||||
|
|
||||||
|
def update_password(self, saas):
|
||||||
"""
|
"""
|
||||||
key: email|quota|display|password
|
key: email|quota|display|password
|
||||||
value: el valor a modificar.
|
value: el valor a modificar.
|
||||||
|
@ -70,6 +92,7 @@ class NextCloudAPIMixin(object):
|
||||||
}
|
}
|
||||||
self.api_put('users/%s' % saas.name, data)
|
self.api_put('users/%s' % saas.name, data)
|
||||||
|
|
||||||
|
|
||||||
def get_user(self, saas):
|
def get_user(self, saas):
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
|
@ -112,13 +135,18 @@ class NextCloudController(NextCloudAPIMixin, ServiceController):
|
||||||
try:
|
try:
|
||||||
self.api_get('users/%s' % saas.name)
|
self.api_get('users/%s' % saas.name)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
if getattr(saas, 'password'):
|
if getattr(saas, 'password', None):
|
||||||
self.create(saas)
|
self.create(saas)
|
||||||
|
self.update_group(saas)
|
||||||
|
self.update_quota(saas)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
if getattr(saas, 'password'):
|
if getattr(saas, 'password', None):
|
||||||
self.update(saas)
|
self.update_password(saas)
|
||||||
|
else:
|
||||||
|
self.update_group(saas)
|
||||||
|
self.update_quota(saas)
|
||||||
|
|
||||||
def remove(self, saas, server):
|
def remove(self, saas, server):
|
||||||
self.api_delete('users/%s' % saas.name)
|
self.api_delete('users/%s' % saas.name)
|
||||||
|
@ -126,7 +154,7 @@ class NextCloudController(NextCloudAPIMixin, ServiceController):
|
||||||
def save(self, saas):
|
def save(self, saas):
|
||||||
# TODO disable user https://github.com/owncloud/core/issues/12601
|
# TODO disable user https://github.com/owncloud/core/issues/12601
|
||||||
self.append(self.update_or_create, saas)
|
self.append(self.update_or_create, saas)
|
||||||
|
|
||||||
def delete(self, saas):
|
def delete(self, saas):
|
||||||
self.append(self.remove, saas)
|
self.append(self.remove, saas)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue