Skip to content

Commit 1274c41

Browse files
committed
10-01-2012
1 parent eb2c6bc commit 1274c41

File tree

6 files changed

+235
-43
lines changed

6 files changed

+235
-43
lines changed

README

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pyocni Readme
1+
pyocni README
22
-------------
33

44
Copyright (C) Houssem Medhioub <[email protected]>
@@ -70,6 +70,7 @@ python start.py
7070
-----------------------------------------------------------------------------
7171
Retrieval of all registered Kinds and Mixins:
7272
curl -X GET -H 'accept: application/json:occi' -v http://localhost:8090/-/
73+
__________________________________________________________________________________________________________________
7374

7475
Creation of Resource instance (compute)
7576
curl -X POST -d@post_compute.json -H 'content-type: application/json:occi' -v http://localhost:8090/compute/
@@ -85,6 +86,7 @@ curl -X POST -d@post_clonenode_openflow.json -H 'content-type: application/json:
8586

8687
Creation of Resource instance (CloNeLink) with l3vpn Mixin
8788
curl -X POST -d@post_clonelink_l3vpn.json -H 'content-type: application/json:occi' -v http://localhost:8090/CloNeLink/
89+
__________________________________________________________________________________________________________________
8890

8991
Retrieval of Resource instance (Compute)
9092
curl -X GET -H 'accept: application/json:occi' -v http://localhost:8090/compute/user1/compute1
@@ -97,7 +99,14 @@ curl -X GET -H 'accept: application/json:occi' -v http://localhost:8090/CloNeLin
9799

98100
Retrieval of all resource instance below a path
99101
curl -X GET -H 'accept: application/json:occi' -v http://localhost:8090/CloNeNode/user1/
102+
__________________________________________________________________________________________________________________
100103

104+
UPDATE of Resource instance (CloNeLink) with l3vpn Mixin
105+
curl -X PUT -d@post_clonelink_l3vpn.json -H 'accept: application/json:occi' -v http://localhost:8090/CloNeLink/user1/CloNeLink1
106+
__________________________________________________________________________________________________________________
107+
108+
Delete of Resource instance (CloNeLink) with l3vpn Mixin
109+
curl -X DELETE -H 'accept: application/json:occi' -v http://localhost:8090/CloNeLink/user1/CloNeLink1
101110

102111
-----------------------------------------------------------------------------
103112
5. For developers

pyocni/backend/opennebula_backend.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,26 @@ def create(self, entity):
4242

4343
logger.debug('The create operation of the opennebula_backend')
4444

45-
f = open('/tmp/template', 'w')
46-
f.write('Name = ' + str(entity.occi_compute_hostname) + '\n')
47-
f.write('CPU = ' + str(entity.occi_compute_cores) + '\n')
48-
f.write('MEMORY = ' + str(entity.occi_compute_memory) + '\n')
49-
f.write('DISK = [ IMAGE_ID = 1,\n')
50-
f.write(' target = "hda",\n')
51-
f.write(' readonly = "no"]\n')
52-
f.write('OS = [ ARCH = ' + str(entity.occi_compute_architecture) + ' ]\n')
53-
f.write('FEATURE = [ acpi = "yes"]\n')
54-
f.write('NIC = [ NETWORK_ID = 3 ]\n')
55-
f.write('GRAPHICS = [ type = "vnc", listen="127.0.0.1", port="-1"]\n')
56-
57-
#print f.read()
58-
59-
templateID=commands.getstatusoutput('onetemplate create /tmp/template')
60-
print templateID
61-
rt=commands.getstatusoutput('onetemplate instanciate ' + str(templateID))
62-
print rt
63-
f.close()
64-
print '###########################################################################'
45+
# f = open('/tmp/template', 'w')
46+
# f.write('Name = ' + str(entity.occi_compute_hostname) + '\n')
47+
# f.write('CPU = ' + str(entity.occi_compute_cores) + '\n')
48+
# f.write('MEMORY = ' + str(entity.occi_compute_memory) + '\n')
49+
# f.write('DISK = [ IMAGE_ID = 1,\n')
50+
# f.write(' target = "hda",\n')
51+
# f.write(' readonly = "no"]\n')
52+
# f.write('OS = [ ARCH = ' + str(entity.occi_compute_architecture) + ' ]\n')
53+
# f.write('FEATURE = [ acpi = "yes"]\n')
54+
# f.write('NIC = [ NETWORK_ID = 3 ]\n')
55+
# f.write('GRAPHICS = [ type = "vnc", listen="127.0.0.1", port="-1"]\n')
56+
#
57+
# #print f.read()
58+
#
59+
# templateID=commands.getstatusoutput('onetemplate create /tmp/template')
60+
# print templateID
61+
# rt=commands.getstatusoutput('onetemplate instanciate ' + str(templateID))
62+
# print rt
63+
# f.close()
64+
# print '###########################################################################'
6565

6666

6767
def read(self, entity):

pyocni/ocni_server.py

+80-16
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
Created on Feb 25, 2011
2020
2121
@author: Houssem Medhioub
22+
@author: Daniel Turull (DELETE and PUT of OperationResource class)
2223
2324
@organization: Institut Telecom - Telecom SudParis
24-
@version: 0.1
25+
@version: 0.3
2526
@license: LGPL - Lesser General Public License
2627
"""
2728

@@ -68,6 +69,7 @@
6869
from pyocni.backend.opennebula_backend import opennebula_backend
6970
from pyocni.backend.openstack_backend import openstack_backend
7071

72+
from pyocni.pyocni_tools import ask_user_details as shell_ask
7173

7274
# getting the Logger
7375
logger = config.logger
@@ -93,6 +95,15 @@
9395
'Not Implemented': 501,
9496
'Service Unavailable': 503}
9597

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+
96107

97108
# ======================================================================================
98109
# the category registry
@@ -171,12 +182,30 @@
171182
location_registry().register_location("/OpenFlowCloNeNetworkInterface/", OpenFlowCloNeNetworkInterface())
172183
location_registry().register_location("/l3vpn/", l3vpn())
173184

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())
180209

181210

182211
class QueryInterface(object):
@@ -240,7 +269,7 @@ def delete(self):
240269
# Operation on Paths in the Name-space
241270
# ======================================================================================
242271
#
243-
# Retrieving All resource instances Below a Path
272+
# Retrieving All resource instances Below a Path (DONE)
244273
#
245274
# Deletion of all resource instances below a path
246275
class OperationPath(object):
@@ -308,13 +337,13 @@ def delete(self):
308337
# Operations on Resource Instances
309338
# ======================================================================================
310339
#
311-
# Creating a resource instance
340+
# Creating a resource instance (DONE)
312341
#
313-
# Retrieving a resource instance
342+
# Retrieving a resource instance (DONE)
314343
#
315-
# Updating a resource instance
344+
# Updating a resource instance (DONE)
316345
#
317-
# Deleting a resource instance
346+
# Deleting a resource instance (DONE)
318347
#
319348
# Triggering an Action on a resource instance
320349
class OperationResource(object):
@@ -389,19 +418,48 @@ def post(self):
389418
def put(self):
390419
"""
391420
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)
393422
Or
394-
Updating a resource instance
423+
Updating a resource instance (Done)
395424
396425
"""
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+
397442
return self.res
398443

399444
def delete(self):
400445
"""
401446
402-
Removing a Mixin definition
447+
Deleting a resource instance
403448
404449
"""
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+
405463
return self.res
406464

407465
# ======================================================================================
@@ -440,8 +498,14 @@ def run_server(self):
440498
to run the server
441499
442500
"""
501+
print ("\n______________________________________________________________________________________\n"
502+
"The OCNI server is running at: ")
443503
wsgi.server(eventlet.listen((config.OCNI_IP, int(config.OCNI_PORT))), self.app)
444504

505+
print ("\n______________________________________________________________________________________\n"
506+
"Closing correctly 'locations' and 'objects' Databases: ")
507+
location_registry(). close_locations_db()
508+
location_registry().close_objects_db()
445509

446510
if __name__ == '__main__':
447511
logger.debug('############ BEGIN OCCI Category rendering ###############')
@@ -455,7 +519,7 @@ def run_server(self):
455519
location_registry().register_location("/network/123", network_instance)
456520

457521
networkinterface_instance = NetworkInterface('456', 'source', '/network/123', '192.168.1.2', '00:00:10:20:30:40',
458-
'active')
522+
'active')
459523
location_registry().register_location("/link/networkinterface/456", networkinterface_instance)
460524

461525
l = link_renderer()

0 commit comments

Comments
 (0)