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