19
19
Created on Feb 25, 2011
20
20
21
21
@author: Houssem Medhioub
22
+ @author: Daniel Turull (DELETE and PUT of OperationResource class)
22
23
23
24
@organization: Institut Telecom - Telecom SudParis
24
- @version: 0.1
25
+ @version: 0.3
25
26
@license: LGPL - Lesser General Public License
26
27
"""
27
28
68
69
from pyocni .backend .opennebula_backend import opennebula_backend
69
70
from pyocni .backend .openstack_backend import openstack_backend
70
71
72
+ from pyocni .pyocni_tools import ask_user_details as shell_ask
71
73
72
74
# getting the Logger
73
75
logger = config .logger
93
95
'Not Implemented' : 501 ,
94
96
'Service Unavailable' : 503 }
95
97
98
+ # ======================================================================================
99
+ # Reinialization of the locations registry and objects registry (clear ZODB)
100
+ # ======================================================================================
101
+ result = shell_ask .query_yes_no_quit (" \n _______________________________________________________________\n "
102
+ " Do you want to purge 'locations' and 'objects' Databases (DB reinialization)?" , "no" )
103
+ if result == 'yes' :
104
+ location_registry ().purge_locations_db ()
105
+ location_registry ().purge_objects_db ()
106
+
96
107
97
108
# ======================================================================================
98
109
# the category registry
171
182
location_registry ().register_location ("/OpenFlowCloNeNetworkInterface/" , OpenFlowCloNeNetworkInterface ())
172
183
location_registry ().register_location ("/l3vpn/" , l3vpn ())
173
184
174
- # register backends
175
- backend_registry ().register_backend (dummy_backend ())
176
- backend_registry ().register_backend (openflow_backend ())
177
- backend_registry ().register_backend (l3vpn_backend ())
178
- backend_registry ().register_backend (opennebula_backend ())
179
- backend_registry ().register_backend (openstack_backend ())
185
+ # ======================================================================================
186
+ # the Backend registry
187
+ # ======================================================================================
188
+
189
+ result = shell_ask .query_yes_no_quit (" \n _______________________________________________________________\n "
190
+ " Do you want to register the dummy backend ?" , "yes" )
191
+ if result == 'yes' :
192
+ backend_registry ().register_backend (dummy_backend ())
193
+ result = shell_ask .query_yes_no_quit (" \n _______________________________________________________________\n "
194
+ " Do you want to register the OpenFlow backend ?" , "no" )
195
+ if result == 'yes' :
196
+ backend_registry ().register_backend (openflow_backend ())
197
+ result = shell_ask .query_yes_no_quit (" \n _______________________________________________________________\n "
198
+ " Do you want to register the L3VPN backend ?" , "no" )
199
+ if result == 'yes' :
200
+ backend_registry ().register_backend (l3vpn_backend ())
201
+ result = shell_ask .query_yes_no_quit (" \n _______________________________________________________________\n "
202
+ " Do you want to register the OpenNebula backend ?" , "no" )
203
+ if result == 'yes' :
204
+ backend_registry ().register_backend (opennebula_backend ())
205
+ result = shell_ask .query_yes_no_quit (" \n _______________________________________________________________\n "
206
+ " Do you want to register the OpenStack backend ?" , "no" )
207
+ if result == 'yes' :
208
+ backend_registry ().register_backend (openstack_backend ())
180
209
181
210
182
211
class QueryInterface (object ):
@@ -240,7 +269,7 @@ def delete(self):
240
269
# Operation on Paths in the Name-space
241
270
# ======================================================================================
242
271
#
243
- # Retrieving All resource instances Below a Path
272
+ # Retrieving All resource instances Below a Path (DONE)
244
273
#
245
274
# Deletion of all resource instances below a path
246
275
class OperationPath (object ):
@@ -308,13 +337,13 @@ def delete(self):
308
337
# Operations on Resource Instances
309
338
# ======================================================================================
310
339
#
311
- # Creating a resource instance
340
+ # Creating a resource instance (DONE)
312
341
#
313
- # Retrieving a resource instance
342
+ # Retrieving a resource instance (DONE)
314
343
#
315
- # Updating a resource instance
344
+ # Updating a resource instance (DONE)
316
345
#
317
- # Deleting a resource instance
346
+ # Deleting a resource instance (DONE)
318
347
#
319
348
# Triggering an Action on a resource instance
320
349
class OperationResource (object ):
@@ -389,19 +418,48 @@ def post(self):
389
418
def put (self ):
390
419
"""
391
420
392
- Creating a resource instance by providing the path in the name-space hierarchy
421
+ Creating a resource instance by providing the path in the name-space hierarchy (To do)
393
422
Or
394
- Updating a resource instance
423
+ Updating a resource instance (Done)
395
424
396
425
"""
426
+ # =1= get old resources
427
+ _old_resource = location_registry ().get_object (self .req .path )
428
+ # =2= get new resources
429
+ resource_json_serializer = json_serializer .resource_serializer ()
430
+ _resource = resource_json_serializer .from_json (self .req .body )
431
+
432
+ # =3= unregister old and register new
433
+ location_registry ().unregister_location (self .req .path )
434
+ location_registry ().register_location (self .req .path , _resource )
435
+
436
+ # =4= execute the backend command by sending the resource object
437
+ for _backend in backend_registry ().get_backends ().values ():
438
+ _backend .update (_old_resource , _resource )
439
+
440
+ self .res .body = 'Resource ' + self .req .path + ' has been updated'
441
+
397
442
return self .res
398
443
399
444
def delete (self ):
400
445
"""
401
446
402
- Removing a Mixin definition
447
+ Deleting a resource instance
403
448
404
449
"""
450
+ # =1= get resources
451
+ _resource = location_registry ().get_object (self .req .path )
452
+
453
+ # =2= remove resources
454
+ location_registry ().unregister_location (self .req .path )
455
+
456
+ # =3= execute the backend command by sending the resource object
457
+ for _backend in backend_registry ().get_backends ().values ():
458
+ _backend .delete (_resource )
459
+
460
+ # =4= return OK with the Location of the created resource
461
+ self .res .body = 'Resource with this PATH has been removed'
462
+
405
463
return self .res
406
464
407
465
# ======================================================================================
@@ -440,8 +498,14 @@ def run_server(self):
440
498
to run the server
441
499
442
500
"""
501
+ print ("\n ______________________________________________________________________________________\n "
502
+ "The OCNI server is running at: " )
443
503
wsgi .server (eventlet .listen ((config .OCNI_IP , int (config .OCNI_PORT ))), self .app )
444
504
505
+ print ("\n ______________________________________________________________________________________\n "
506
+ "Closing correctly 'locations' and 'objects' Databases: " )
507
+ location_registry (). close_locations_db ()
508
+ location_registry ().close_objects_db ()
445
509
446
510
if __name__ == '__main__' :
447
511
logger .debug ('############ BEGIN OCCI Category rendering ###############' )
@@ -455,7 +519,7 @@ def run_server(self):
455
519
location_registry ().register_location ("/network/123" , network_instance )
456
520
457
521
networkinterface_instance = NetworkInterface ('456' , 'source' , '/network/123' , '192.168.1.2' , '00:00:10:20:30:40' ,
458
- 'active' )
522
+ 'active' )
459
523
location_registry ().register_location ("/link/networkinterface/456" , networkinterface_instance )
460
524
461
525
l = link_renderer ()
0 commit comments