Skip to content

Commit c454407

Browse files
authored
Saimon/portal settings (#231)
1 parent 7102c79 commit c454407

File tree

5 files changed

+115
-9
lines changed

5 files changed

+115
-9
lines changed

cterasdk/core/enum.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,34 @@ class PlanItem:
312312
Storage = 'Storage'
313313

314314

315+
class PlanService:
316+
"""
317+
Plan Service
318+
319+
:ivar str CloudDrive: Cloud Drive
320+
:ivar str CloudBackup: Cloud Backup
321+
:ivar str Seeding: Seeding
322+
:ivar str Remote: Remote Access
323+
"""
324+
CloudDrive = 'Cloud folders'
325+
CloudBackup = 'Cloud Backup'
326+
Seeding = 'Seeding'
327+
Remote = 'Remote Access'
328+
329+
330+
class PlanServiceState:
331+
"""
332+
Plan Service State
333+
334+
:ivar str Enabled: Enabled
335+
:ivar str Disabled: Disabled
336+
:ivar str Connect: Cloud Drive Connect
337+
"""
338+
Enabled = 'OK'
339+
Disabled = 'Disabled'
340+
Connect = 'Lite'
341+
342+
315343
class ListFilter:
316344
"""
317345
Cloud Drive Folder List Filter

cterasdk/core/plans.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,17 @@ def get(self, name, include=None):
7878
raise ObjectNotFoundException('Could not find subscription plan', f'/plans/{name}', name=name)
7979
return plan
8080

81-
def add(self, name, retention=None, quotas=None):
81+
def add(self, name, services=None, retention=None, quotas=None):
8282
"""
8383
Add a subscription plan
8484
85+
:param dict,optional services: Services to enable or disable
8586
:param dict,optional retention: The data retention policy
8687
:param dict,optional quotas: The items included in the plan and their respective quota
8788
"""
8889
plan = self._core.api.defaults('Plan')
8990
plan.name = name
91+
Plans._assign_services(plan, services)
9092
Plans._assign_retention(plan, retention)
9193
Plans._assign_quotas(plan, quotas)
9294
try:
@@ -97,15 +99,17 @@ def add(self, name, retention=None, quotas=None):
9799
logging.getLogger('cterasdk.core').error("Plan creation failed.")
98100
raise CTERAException('Plan creation failed', error)
99101

100-
def modify(self, name, retention=None, quotas=None, apply_changes=True):
102+
def modify(self, name, services=None, retention=None, quotas=None, apply_changes=True):
101103
"""
102104
Modify a subscription plan
103105
106+
:param dict,optional services: Services to enable or disable
104107
:param dict,optional retention: The data retention policy
105108
:param dict,optional quotas: The items included in the plan and their respective quota
106109
:param bool,optional apply_changes: Apply provisioning changes immediately
107110
"""
108111
plan = self._get_entire_object(name)
112+
Plans._assign_services(plan, services)
109113
Plans._assign_retention(plan, retention)
110114
Plans._assign_quotas(plan, quotas)
111115
try:
@@ -121,6 +125,14 @@ def modify(self, name, retention=None, quotas=None, apply_changes=True):
121125
logging.getLogger('cterasdk.core').error("Could not modify subscription plan.")
122126
raise CTERAException('Could not modify subscription plan', error)
123127

128+
@staticmethod
129+
def _assign_services(plan, services):
130+
if services is not None:
131+
for service in plan.services:
132+
service_state = services.get(service.serviceName, None)
133+
if service_state:
134+
service.serviceState = service_state
135+
124136
@staticmethod
125137
def _assign_retention(plan, retention):
126138
if retention is not None:

cterasdk/core/settings.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,61 @@
11
import logging
22

3+
from ..common import Object
34
from .base_command import BaseCommand
45

56

67
class Settings(BaseCommand):
78
"""
8-
Portal Settings APIs
9+
CTERA Portal Settings APIs
910
1011
:ivar cterasdk.core.settings.GlobalSettings global_settings: Object holding the Portal Global Settings APIs
1112
"""
1213

13-
def __init__(self, portal):
14-
super().__init__(portal)
15-
self.global_settings = GlobalSettings(self._core)
14+
def __init__(self, core):
15+
super().__init__(core)
16+
self.global_settings = GlobalSettings(core)
17+
self.portal = PortalSettings(core)
18+
19+
20+
class PortalSettings(BaseCommand):
21+
"""
22+
Virtual Portal Settings APIs
23+
"""
24+
def get(self):
25+
if self.session().in_tenant_context():
26+
return self._core.api.execute('', 'getSettings').settings
27+
return self._core.api.get('/settings/defaultPortalSettings')
28+
29+
def use_global_settings(self):
30+
return self.update()
31+
32+
def update(self, settings=None):
33+
"""
34+
Update Portal Settings
35+
36+
:param cterasdk.common.object.Objcet settings: Settings, defaults to using the global settings.
37+
"""
38+
if not self.session().in_tenant_context():
39+
self._core.api.put('/settings/defaultPortalSettings', settings)
40+
else:
41+
param = PortalSettings._create_settings_parameter()
42+
if settings:
43+
param.fromSystem = False
44+
param.settings = settings
45+
self._core.api.execute('', 'setSettings', param)
46+
47+
@staticmethod
48+
def _create_settings_parameter():
49+
param = Object()
50+
param._classname = 'SettingsParam' # pylint: disable=protected-access
51+
param.fromSystem = True
52+
return param
1653

1754

1855
class GlobalSettings(BaseCommand):
56+
"""
57+
Global Settings APIs
58+
"""
1959

2060
def get_timezone(self):
2161
"""

docs/source/UserGuides/Portal/Administration.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,10 @@ Subscription Plans
310310
"""
311311
312312
name = 'good_plan'
313+
services = {core_enum.PlanService.CloudBackup: core_enum.PlanServiceState.Disabled, core_enum.PlanService.CloudDrive: core_enum.PlanServiceState.Disabled}
313314
retention = {core_enum.PlanRetention.Daily: 7, core_enum.PlanRetention.Monthly: 12}
314315
quotas = {core_enum.PlanItem.EV16: 10, core_enum.PlanItem.EV32: 5, core_enum.PlanItem.Share: 100}
315-
admin.plans.add(name, retention, quotas)
316+
admin.plans.add(name, services, retention, quotas)
316317
317318
.. automethod:: cterasdk.core.plans.Plans.modify
318319
:noindex:
@@ -326,9 +327,10 @@ Subscription Plans
326327
"""
327328
328329
name = 'good_plan'
330+
services = {core_enum.PlanService.CloudBackup: core_enum.PlanServiceState.Disabled, core_enum.PlanService.CloudDrive: core_enum.PlanServiceState.Disabled}
329331
retention = {core_enum.PlanRetention.Daily: 30, core_enum.PlanRetention.Monthly: 36}
330332
quotas = {core_enum.PlanItem.EV16: 20, core_enum.PlanItem.EV32: 10, core_enum.PlanItem.Share: 200}
331-
admin.plans.modify(name, retention, quotas)
333+
admin.plans.modify(name, services, retention, quotas)
332334
333335
.. automethod:: cterasdk.core.plans.Plans.delete
334336
:noindex:
@@ -1561,6 +1563,30 @@ Timezone
15611563
15621564
admin.settings.global_settings.set_timzeone('(GMT-05:00) Eastern Time (US , Canada)')
15631565
1566+
1567+
Virtual Portal Settings
1568+
=======================
1569+
1570+
.. automethod:: cterasdk.core.settings.PortalSettings.get
1571+
:noindex:
1572+
1573+
.. code:: python
1574+
1575+
admin.settings.portal.get()
1576+
1577+
.. automethod:: cterasdk.core.settings.PortalSettings.use_global_settings
1578+
:noindex:
1579+
1580+
.. automethod:: cterasdk.core.settings.PortalSettings.update
1581+
:noindex:
1582+
1583+
.. code:: python
1584+
1585+
settings = admin.settings.portal.get()
1586+
settings.defaultMail = 'support@acme.com' # assign default email to domain users without an email address
1587+
admin.settings.portal.update(settings) # apply settings changes
1588+
1589+
15641590
TLS Certificate
15651591
===============
15661592

tests/ut/test_core_plans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_modify_success_without_apply_changes(self):
155155
Connect=5,
156156
Storage=4096
157157
)
158-
plans.Plans(self._global_admin).modify(self._plan_name, retention, quotas, False)
158+
plans.Plans(self._global_admin).modify(self._plan_name, retention=retention, quotas=quotas, apply_changes=False)
159159
self._global_admin.api.get.assert_called_once_with(f'/plans/{self._plan_name}')
160160
self._global_admin.api.put.assert_called_once_with(f'/plans/{self._plan_name}', mock.ANY)
161161
expected_param = self._get_plan_object(retention, licenses)

0 commit comments

Comments
 (0)