55from ..exceptions import CTERAException
66from ..convert import fromxmlstr , toxmlstr
77from ..common import Device , delete_attrs
8- from ..lib import FileSystem , TempfileServices
8+ from ..lib import TempfileServices
9+ from ..lib .storage import commonfs , synfs
910from .base_command import BaseCommand
1011
1112
13+ logger = logging .getLogger ('cterasdk.edge' )
14+
15+
1216class Config (BaseCommand ):
1317 """ Edge Filer General Configuration APIs """
1418
1519 def __init__ (self , edge ):
1620 super ().__init__ (edge )
17- self ._filesystem = FileSystem .instance ()
1821
1922 def get_location (self ):
2023 """
@@ -31,7 +34,7 @@ def set_location(self, location):
3134 :param str location: New location to set
3235 :return str: The new location
3336 """
34- logging . getLogger ( 'cterasdk.edge' ) .info ('Configuring device location. %s' , {'location' : location })
37+ logger .info ('Configuring device location. %s' , {'location' : location })
3538 return self ._edge .api .put ('/config/device/location' , location )
3639
3740 def get_hostname (self ):
@@ -49,7 +52,7 @@ def set_hostname(self, hostname):
4952 :param str hostname: New hostname to set
5053 :return str: The new hostname
5154 """
52- logging . getLogger ( 'cterasdk.edge' ) .info ('Configuring device hostname. %s' , {'hostname' : hostname })
55+ logger .info ('Configuring device hostname. %s' , {'hostname' : hostname })
5356 return self ._edge .api .put ('/config/device/hostname' , hostname )
5457
5558 def import_config (self , config , exclude = None ):
@@ -69,14 +72,14 @@ def import_config(self, config, exclude=None):
6972 if exclude :
7073 delete_attrs (database , exclude )
7174
72- path = self . _filesystem .join (TempfileServices .mkdir (), f'{ self ._edge .session ().address } .xml' )
73- self . _filesystem . write (path , toxmlstr (database , True ).encode ('utf-8' ))
75+ path = commonfs .join (TempfileServices .mkdir (), f'{ self ._edge .session ().address } .xml' )
76+ synfs . overwrite (path , toxmlstr (database , True ).encode ('utf-8' ))
7477
7578 return self ._import_configuration (path )
7679
7780 def _import_configuration (self , path ):
78- self . _filesystem .properties (path )
79- logging . getLogger ( 'cterasdk.edge' ) .info ('Importing Edge Filer configuration.' )
81+ commonfs .properties (path )
82+ logger .info ('Importing Edge Filer configuration.' )
8083 with open (path , 'rb' ) as fd :
8184 response = self ._edge .api .form_data (
8285 '/config' ,
@@ -86,7 +89,7 @@ def _import_configuration(self, path):
8689 config = fd
8790 )
8891 )
89- logging . getLogger ( 'cterasdk.edge' ) .info ('Imported Edge Filer configuration.' )
92+ logger .info ('Imported Edge Filer configuration.' )
9093 return response
9194
9295 def load_config (self , config ):
@@ -96,18 +99,18 @@ def load_config(self, config):
9699 :param str config: A string or a path to the Edge Filer configuration file
97100 """
98101 data = None
99- if self . _filesystem .exists (config ):
100- logging . getLogger ( 'cterasdk.edge' ) .info ('Reading the Edge Filer configuration from file. %s' , {'path' : config })
102+ if commonfs .exists (config ):
103+ logger .info ('Reading the Edge Filer configuration from file. %s' , {'path' : config })
101104 with open (config , 'r' , encoding = 'utf-8' ) as f :
102105 data = f .read ()
103106 else :
104107 data = config
105108
106109 database = fromxmlstr (data )
107110 if database :
108- logging . getLogger ( 'cterasdk.edge' ) .info ('Completed parsing the Edge Filer configuration. %s' , {'firmware' : database .firmware })
111+ logger .info ('Completed parsing the Edge Filer configuration. %s' , {'firmware' : database .firmware })
109112 return database
110- logging . getLogger ( 'cterasdk.edge' ) .error ("Failed parsing the Edge Filer's configuration." )
113+ logger .error ("Failed parsing the Edge Filer's configuration." )
111114 raise CTERAException ("Failed parsing the Edge Filer's configuration" )
112115
113116 def export (self , destination = None ):
@@ -118,11 +121,11 @@ def export(self, destination=None):
118121 File destination, defaults to the default directory
119122 """
120123 default_filename = self ._edge .host () + datetime .now ().strftime ('_%Y-%m-%dT%H_%M_%S' ) + '.xml'
121- directory , filename = self . _filesystem . generate_file_location (destination , default_filename )
122- logging . getLogger ( 'cterasdk.edge' ) .info ('Exporting configuration. %s' , {'host' : self ._edge .host ()})
124+ directory , filename = commonfs . generate_file_destination (destination , default_filename )
125+ logger .info ('Exporting configuration. %s' , {'host' : self ._edge .host ()})
123126 handle = self ._edge .api .handle ('/export' )
124- filepath = FileSystem . instance (). save (directory , filename , handle )
125- logging . getLogger ( 'cterasdk.edge' ) .info ('Exported configuration. %s' , {'filepath' : filepath })
127+ filepath = synfs . write (directory , filename , handle )
128+ logger .info ('Exported configuration. %s' , {'filepath' : filepath })
126129
127130 def is_wizard_enabled (self ):
128131 """
@@ -145,5 +148,5 @@ def disable_wizard(self):
145148 return self ._set_wizard (False )
146149
147150 def _set_wizard (self , state ):
148- logging . getLogger ( 'cterasdk.edge' ) .info ('Disabling first time wizard' )
151+ logger .info ('Disabling first time wizard' )
149152 return self ._edge .api .put ('/config/gui/openFirstTimeWizard' , state )
0 commit comments