1 from flask
import Flask
, request
2 from flask_restful
import Api
, Resource
6 class BaseOpenstackDummy(Resource
):
8 This class is the base class for all openstack entrypoints of son-emu.
11 def __init__(self
, listenip
, port
):
16 self
.playbook_file
= '/tmp/son-emu-requests.log'
17 with
open(self
.playbook_file
, 'w'):
21 self
.app
= Flask(__name__
)
22 self
.api
= Api(self
.app
)
24 def _start_flask(self
):
25 logging
.info("Starting %s endpoint @ http://%s:%d" % (__name__
, self
.ip
, self
.port
))
26 if self
.app
is not None:
27 self
.app
.before_request(self
.dump_playbook
)
28 self
.app
.run(self
.ip
, self
.port
, debug
=True, use_reloader
=False)
30 def dump_playbook(self
):
31 with self
.manage
.lock
:
32 with
open(self
.playbook_file
, 'a') as logfile
:
33 if len(request
.data
) > 0:
34 data
= "# %s API\n" % str(self
.__class
__).split('.')[-1].rstrip('\'>')
35 data
+= "curl -X {type} -H \"Content-type: application/json\" -d '{data}' {url}".format(type=request
.method
,
38 logfile
.write(data
+ "\n")