@@ -191,29 +191,28 @@ def save(self):
191
191
Save the controller configuration on disk
192
192
"""
193
193
194
- if self ._config_loaded is False :
195
- return
196
-
197
- controller_settings = {"computes" : [],
198
- "templates" : [],
199
- "gns3vm" : self .gns3vm .__json__ (),
200
- "iou_license" : self ._iou_license_settings ,
201
- "appliances_etag" : self ._appliance_manager .appliances_etag ,
202
- "version" : __version__ }
203
-
204
- for template in self ._template_manager .templates .values ():
205
- if not template .builtin :
206
- controller_settings ["templates" ].append (template .__json__ ())
194
+ controller_settings = dict ()
195
+ if self ._config_loaded :
196
+ controller_settings = {"computes" : [],
197
+ "templates" : [],
198
+ "gns3vm" : self .gns3vm .__json__ (),
199
+ "iou_license" : self ._iou_license_settings ,
200
+ "appliances_etag" : self ._appliance_manager .appliances_etag ,
201
+ "version" : __version__ }
202
+
203
+ for template in self ._template_manager .templates .values ():
204
+ if not template .builtin :
205
+ controller_settings ["templates" ].append (template .__json__ ())
207
206
208
- for compute in self ._computes .values ():
209
- if compute .id != "local" and compute .id != "vm" :
210
- controller_settings ["computes" ].append ({"host" : compute .host ,
211
- "name" : compute .name ,
212
- "port" : compute .port ,
213
- "protocol" : compute .protocol ,
214
- "user" : compute .user ,
215
- "password" : compute .password ,
216
- "compute_id" : compute .id })
207
+ for compute in self ._computes .values ():
208
+ if compute .id != "local" and compute .id != "vm" :
209
+ controller_settings ["computes" ].append ({"host" : compute .host ,
210
+ "name" : compute .name ,
211
+ "port" : compute .port ,
212
+ "protocol" : compute .protocol ,
213
+ "user" : compute .user ,
214
+ "password" : compute .password ,
215
+ "compute_id" : compute .id })
217
216
218
217
try :
219
218
os .makedirs (os .path .dirname (self ._config_file ), exist_ok = True )
@@ -229,8 +228,7 @@ def _load_controller_settings(self):
229
228
230
229
try :
231
230
if not os .path .exists (self ._config_file ):
232
- self ._config_loaded = True
233
- self .save ()
231
+ self .save () # this will create the config file
234
232
with open (self ._config_file ) as f :
235
233
controller_settings = json .load (f )
236
234
except (OSError , ValueError ) as e :
@@ -255,6 +253,8 @@ def _load_controller_settings(self):
255
253
if not previous_version or \
256
254
parse_version (__version__ .split ("+" )[0 ]) > parse_version (previous_version .split ("+" )[0 ]):
257
255
self ._appliance_manager .install_builtin_appliances ()
256
+ elif not os .listdir (self ._appliance_manager .builtin_appliances_path ()):
257
+ self ._appliance_manager .install_builtin_appliances ()
258
258
259
259
self ._appliance_manager .appliances_etag = controller_settings .get ("appliances_etag" )
260
260
self ._appliance_manager .load_appliances ()
0 commit comments