Skip to content

Commit

Permalink
SDK-38 Add APIs in edge modules for Ansible modules
Browse files Browse the repository at this point in the history
AIO - Add is_enabled
Backup - Add is_configured
Cache - Add is_enabled
Config - Fix doc strings
Directory Services - Add get_connected_domain
Drive - Add get_status
FTP - Add get_configuration, enable and modify
Licenses - Add get
NFS - Add get_configuration, enable and modify
RSync - Add get_configuration, enable and modify
Services - Add sso_enabled and disable_sso
SMB - Add get_configuration, enable and modify
Syslog - Add get_current_config and modify_current_config
Timezone - Add get timezone
Volumes - Add modify
Config - Add is_wizard_enabled and enable_wizard
Add new ENUM for Backup config status
  • Loading branch information
ygalblum committed Mar 19, 2020
1 parent b502e7a commit ea34e7d
Show file tree
Hide file tree
Showing 21 changed files with 416 additions and 35 deletions.
9 changes: 9 additions & 0 deletions cterasdk/edge/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ class AIO(BaseCommand):
"""
Gateway AIO APIs
"""
def is_enabled(self):
"""
Is AIO enabled
:return: True is AIO is enabled, else False
:rtype: bool
"""
cifs = self._gateway.get('/config/fileservices/cifs')
return cifs.robustMutexes and (cifs.aioReadThreshold > 0) and (cifs.aioWriteThreshold > 0)

def enable(self):
"""
Expand Down
10 changes: 10 additions & 0 deletions cterasdk/edge/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from . import taskmgr as TaskManager
from ..common import Object
from ..exception import CTERAException
from .enum import BackupConfStatusID
from .base_command import BaseCommand


Expand Down Expand Up @@ -65,6 +66,15 @@ def configure(self, passphrase=None):

logging.getLogger().info('Cloud backup configuration completed successfully.')

def is_configured(self):
"""
Is Backup configured
:return bool: True if backup is configured, else False
"""
backup_status = self._gateway.get('/proc/backup/backupStatus')
return backup_status.serviceStatus.id == BackupConfStatusID.Attached

def start(self):
""" Start backup """
logging.getLogger().info("Starting cloud backup.")
Expand Down
3 changes: 3 additions & 0 deletions cterasdk/edge/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def force_eviction(self):
self._gateway.execute("/config/cloudsync", "forceExecuteEvictor", None)
logging.getLogger().info("Eviction started.")

def is_enabled(self):
return self._gateway.get('/config/cloudsync/cloudExtender/operationMode') == OperationMode.CachingGateway

def _set_operation_mode(self, mode):
self._gateway.put('/config/cloudsync/cloudExtender/operationMode', mode)
logging.getLogger().info('Device opreation mode changed. %s', {'mode': mode})
25 changes: 22 additions & 3 deletions cterasdk/edge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def set_location(self, location):
"""
Set the location of the gateway
:return str: The command response
:param str location: New location to set
:return str: The new location
"""
logging.getLogger().info('Configuring device location. %s', {'location': location})
return self._gateway.put('/config/device/location', location)
Expand All @@ -35,14 +36,32 @@ def set_hostname(self, hostname):
"""
Set the hostname of the gateway
:return str: The command response
:param str hostname: New hostname to set
:return str: The new hostname
"""
logging.getLogger().info('Configuring device hostname. %s', {'hostname': hostname})
return self._gateway.put('/config/device/hostname', hostname)

def is_wizard_enabled(self):
"""
Get the current configuration of the first time wizard
:return bool: True if the first time wizard is enabled, else False
"""
return self._gateway.get('/config/gui/openFirstTimeWizard')

def enable_wizard(self):
"""
Enable the first time wizard
"""
return self._set_wizard(True)

def disable_wizard(self):
"""
Disable the first time wizard
"""
return self._set_wizard(False)

def _set_wizard(self, state):
logging.getLogger().info('Disabling first time wizard')
return self._gateway.put('/config/gui/openFirstTimeWizard', False)
return self._gateway.put('/config/gui/openFirstTimeWizard', state)
15 changes: 14 additions & 1 deletion cterasdk/edge/directoryservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,24 @@ def advanced_mapping(self, domain, start, end):
logging.getLogger().error('Could not find domain name. %s', {'domain': domain})
raise CTERAException('Could not find domain name', None, domain=domain, domains=self.domains())

def get_connected_domain(self):
"""
Get the connected domain information
:return cterasdk.common.object.Object:
"""
cifs = self._gateway.get('/config/fileservices/cifs')
obj = Object()
obj.type = cifs.type
obj.domain = cifs.domain
obj.workgroup = cifs.workgroup
return obj

def domains(self):
"""
Get all domains
:return list(str): List of names of all configured domains
:return list(str): List of names of all discovered domains
"""
return [domain.flatName for domain in self._gateway.execute('/status/fileservices/cifs', 'enumDiscoveredDomains')]

Expand Down
9 changes: 9 additions & 0 deletions cterasdk/edge/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ class Drive(BaseCommand):
def get(self, name=None):
"""
Get Drive. If a drive name was not passed as an argument, a list of all drives will be retrieved
:param str,optional name: Name of the drive
"""
return self._gateway.get('/config/storage/disks' + ('' if name is None else ('/' + name)))

def get_status(self, name=None):
"""
Get drive status. If a drive name was not passed as an argument, a list of all drives will be retrieved
:param str name: Name of the drive
"""
return self._gateway.get('/status/storage/disks' + ('' if name is None else ('/' + name)))

def format(self, name):
"""
Format a drive
Expand Down
29 changes: 29 additions & 0 deletions cterasdk/edge/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,32 @@ class RAIDLevel:
RAID_1 = "1"
RAID_5 = "5"
RAID_6 = "6"


class BackupConfStatusID:
"""
Status of backup configuration
:ivar str NotInitialized: Backup configuration was not initialized
:ivar str Configuring: Backup is being configured
:ivar str Attaching: Backup configuration is Attaching
:ivar str Attached: Backup configuration is Attached
:ivar str NoFolder: No Folder for backup
:ivar str WrongPassword: Wrong password used
:ivar str Failed: Backup configuration failed
:ivar str Unsubscribed: Unsubscribed to backup
:ivar str Unlicensed: Unlicensed" to backup
:ivar str ClocksOutOfSync: Clocks are out of sync
:ivar str GetFoldersList: Get folders list
"""
NotInitialized = "NotInitialized"
Configuring = "Configuring"
Attaching = "Attaching"
Attached = "Attached"
NoFolder = "NoFolder"
WrongPassword = "WrongPassword"
Failed = "Failed"
Unsubscribed = "Unsubscribed"
Unlicensed = "Unlicensed"
ClocksOutOfSync = "ClocksOutOfSync"
GetFoldersList = "GetFoldersList"
60 changes: 55 additions & 5 deletions cterasdk/edge/ftp.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,70 @@
import logging

from .enum import Mode
from ..exception import CTERAException
from .base_command import BaseCommand


class FTP(BaseCommand):
""" Gateway FTP configuration APIs """

def get_configuration(self):
"""
Get the current FTP configuration
:return cterasdk.common.object.Object:
"""
return self._gateway.get('/config/fileservices/ftp')

def enable(self):
""" Enable FTP """
self._set_mode(True)

def disable(self):
""" Disable FTP """
self._set_mode(False)

def is_disabled(self):
""" Check if the FTP server is disabled """
return self._gateway.get('/config/fileservices/ftp/mode') == Mode.Disabled

def disable(self):
""" Disable FTP """
logging.getLogger().info('Disabling FTP server.')
def _set_mode(self, enabled):
logging.getLogger().info('%s FTP server.', ('Enabling' if enabled else 'Disabling'))
self._gateway.put('/config/fileservices/ftp/mode', Mode.Enabled if enabled else Mode.Disabled)
logging.getLogger().info('FTP server %s.', ('enabled' if enabled else 'disabled'))

self._gateway.put('/config/fileservices/ftp/mode', Mode.Disabled)
def modify(
self,
allow_anonymous_ftp=None,
anonymous_download_limit=None,
anonymous_ftp_folder=None,
banner_message=None,
max_connections_per_ip=None,
require_ssl=None):
"""
Modify the FTP Configuration. Parameters that are not passed will not be affected
logging.getLogger().info('FTP server disabled.')
:param bool,optional allow_anonymous_ftp: Enable/Disable anonymous FTP downloads
:param int,optional anonymous_download_limit:
Limit download bandwidth of anonymous connection in KB/sec per connection. 0 for unlimited
:param str,optional anonymous_ftp_folder: Anonymous FTP Directory
:param str,optional banner_message: FTP Banner Message
:param int,optional max_connections_per_ip: Maximum Connections per Client
:param bool,optional require_ssl: If Ture, allow only SSL/TLS connections
"""
config = self.get_configuration()
if config.mode != Mode.Enabled:
raise CTERAException("FTP must be enabled in order to modify its configuration")
if anonymous_download_limit is not None:
config.AnonymousDownloadLimit = anonymous_download_limit
if anonymous_ftp_folder is not None:
config.AnonymousFTPFolder = anonymous_ftp_folder
if allow_anonymous_ftp is not None:
config.AllowAnonymousFTP = allow_anonymous_ftp
if banner_message is not None:
config.BannerMessage = banner_message
if max_connections_per_ip is not None:
config.MaxConnectionsPerIP = max_connections_per_ip
if require_ssl is not None:
config.RequireSSL = require_ssl
self._gateway.put('/config/fileservices/ftp', config)
11 changes: 11 additions & 0 deletions cterasdk/edge/licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ def apply(self, ctera_license):
self._gateway.put('/config/device/activeLicenseType', inferred_license)

logging.getLogger().info('License applied. %s', {'license': ctera_license})

def get(self):
"""
Get the current Gateway License
"""
inferred_license = self._gateway.get('/config/device/activeLicenseType')
if inferred_license == 'NA':
return inferred_license
if len(inferred_license) == 8:
inferred_license = inferred_license + '16'
return 'EV' + inferred_license[8:]
2 changes: 1 addition & 1 deletion cterasdk/edge/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Network(BaseCommand):
""" Gateway Network configuration APIs """

def status(self):
def get_status(self):
"""
Retrieve the network interface status
"""
Expand Down
46 changes: 39 additions & 7 deletions cterasdk/edge/nfs.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
import logging

from .enum import Mode
from ..exception import CTERAException
from .base_command import BaseCommand


class NFS(BaseCommand):
""" Gateway NFS configuration """

def is_disabled(self):
""" Check if the NFS server is disabled """
return self._gateway.get('/config/fileservices/nfs/mode') == Mode.Disabled
def get_configuration(self):
"""
Get the current NFS configuration
:return cterasdk.common.object.Object:
"""
return self._gateway.get('/config/fileservices/nfs')

def enable(self):
""" Enable NFS """
self._set_mode(True)

def disable(self):
""" Disable NFS """
self._set_mode(False)

logging.getLogger().info('Disabling NFS server.')

self._gateway.put('/config/fileservices/nfs/mode', Mode.Disabled)
def is_disabled(self):
""" Check if the NFS server is disabled """
return self._gateway.get('/config/fileservices/nfs/mode') == Mode.Disabled

logging.getLogger().info('NFS server disabled.')
def _set_mode(self, enabled):
logging.getLogger().info('%s NFS server.', ('Enabling' if enabled else 'Disabling'))
self._gateway.put('/config/fileservices/nfs/mode', Mode.Enabled if enabled else Mode.Disabled)
logging.getLogger().info('NFS server %s.', ('enabled' if enabled else 'disabled'))

def modify(
self,
async_write=None,
aggregate_writes=None):
"""
Modify the FTP Configuration. Parameters that are not passed will not be affected
:param bool,optional async_write: If Ture, use asynchronous writes
:param bool,optional aggregate_writes: If Ture, aggregate write requests
"""
config = self.get_configuration()
if config.mode != Mode.Enabled:
raise CTERAException("NFS must be enabled in order to modify its configuration")
if async_write is not None:
setattr(config, 'async', Mode.Enabled if async_write else Mode.Disabled)
if aggregate_writes is not None:
config.aggregateWrites = Mode.Enabled if aggregate_writes else Mode.Disabled
self._gateway.put('/config/fileservices/nfs', config)
44 changes: 40 additions & 4 deletions cterasdk/edge/rsync.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
import logging

from .enum import Mode
from ..exception import CTERAException
from .base_command import BaseCommand


class RSync(BaseCommand):
""" Gateway RSync configuration """

def get_configuration(self):
"""
Get the current RSync configuration
:return cterasdk.common.object.Object:
"""
return self._gateway.get('/config/fileservices/rsync')

def enable(self):
""" Enable FTP """
self._set_mode(True)

def disable(self):
""" Disable FTP """
self._set_mode(False)

def is_disabled(self):
""" Check if the Rsync server is disabled """
return self._gateway.get('/config/fileservices/rsync/server') == Mode.Disabled

def disable(self):
def _set_mode(self, enabled):
""" Disable RSync """
logging.getLogger().info('Disabling RSync server.')
self._gateway.put('/config/fileservices/rsync/server', Mode.Disabled)
logging.getLogger().info('RSync server disabled.')
logging.getLogger().info('%s RSync server.', ('Enabling' if enabled else 'Disabling'))
self._gateway.put('/config/fileservices/rsync/server', Mode.Enabled if enabled else Mode.Disabled)
logging.getLogger().info('RSync server %s.', ('enabled' if enabled else 'disabled'))

def modify(
self,
port=None,
max_connections=None):
"""
Modify the RSync Configuration. Parameters that are not passed will not be affected
:param int,optional port: RSync Port
:param int,optional max_connections: Maximum Connections
"""
config = self.get_configuration()
if config.server != Mode.Enabled:
raise CTERAException("RSync must be enabled in order to modify its configuration")
if port is not None:
config.port = port
if max_connections is not None:
config.maxConnections = max_connections
self._gateway.put('/config/fileservices/rsync', config)

0 comments on commit ea34e7d

Please sign in to comment.