Remote REST API for trace point introspection and control

Requires corresponding patch to OSv core for API:s used.

Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Merge remote-tracking branch 'upstream/master'
Http Server: A singleton class for starting the httpserver

The osvinit needs access to the httpserver internal logic before it
starts to serve external clients. It also needs the ability to delay its
operation until the initilization process completed.

global server is a singleton class that holds an httpserver and
responsible for its initialization.

To access the httpserver, it expose the server routes object that can be
used directly by the OSv Init.
The server itself needs to be started explicitely to start serving
external clients.

The logic in the global_server replaces the code that used to be in
main.

Instead of starting an httpserver by its own, main now calls the
global_server to run the server.

The route initilization is done by the global_server class.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http server: Make file create a stub library

The osvinit in its stand alon mode needs to linkage with the stub files
of the httpserver, for a makefile target creates a lib from the stub
files.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: rename httpserver.so to libhttpserver.so

The osvinit depends on the httpserver as a library. Nameing the
httpserver with the lib prefix allows using with -L in the compilation.
The lib will be placed on the load path so it can be found by the
osvinit.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: http client

The http client is loosely based on the boost http client example.
The original example can be found here:
http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/example/cpp03/http/client/sync_client.cpp

The client class redirect its output to an output stream so if the c is
a client the following can be done:
std::cout << c;

The client is used to retrieve init files from a remote server. It can
be replaced by a library client if need arises.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: the osvinit class

The osvinit object uses command from a yaml parser to either call an API
command or to perform internal command.
The supported options are:
Each command contains: GET, PUT, POST or DELETE with a url of the
command. Path parameters comes as part of the url.
Query parameteres follow as a yaml parameters.

The osvinit can be set to stop on errors or ignore them.

When opening the api, the osv init creates a new thread for that, it
would wait for that thread to terminate.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: the main

The main starts an osvinit task. It should get in the command line
either a file name or a server name and path on the server as the init
file.

It uses a parser for passing the configuration to the osvinit

It call the osvinit wait, it would return imidiatialy if the httpserver
was not run.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: A basic configuration file

The default configuration file is empty. When the osvinit will be in use
it should replace the httpserver and the osvinit would start the api
server when the configuration is done.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: Makefile

Adding the make file. It create the osvinit.so for use with the image
and the osvinit for standalon testing.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: add the module.py

Package the yaml-cpp lib, the osvinit.so and the osvinit.yaml init file.
By default the osvinit will not be started, but the httpserver will.

To change that, the starting line can be uncommentted or the osvinit can
be started with a -e directly.

The osvinit and httpserver should not be both started.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>

module.py need merge
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mgmt packagin add the osvinit

The mgmt needs to package the osvinit in the image.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: The global server header file

The global server is a singleton class that uses to access the API.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSvInit: add directory of the yaml-cpp library

Add the directory of the yaml-cpp library to the path

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mgmt: compile osvinit after httpserver

Explicitly specify to the build system that the osvinit module needs
to be compiled after the httpserver module. Otherwise, we may randomly
get opposite order, and the compilation will fail.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mgmt/httpserver: Add more include directories

httpserver's Makefile lists some OSv include directories so we can use OSv
APIs in our implementation of some of the requests. However, we did not
add enough include directories to allow including some OSv headers, such
as <osv/sched.hh>.

This patch adds to the include path ../../arch/$(arch), which is needed
for <arch.hh>, and ../.., needed for <drivers/clockevent.hh>. Both are
needed to be able to include <osv/sched.hh>.

To be honest, OSv's C++ API situation is a bit of a mess - there are too
many different directories of header files, and the API headers like
sched.hh include a huge number of other headers to define all the class
fields which are unfortunately all exposed. It's also not clear what is
the official policy of mixing Linux and OSv header files. But before we
solve these problems, this patch is an interim fix.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
rest_api: expose set/get hostname api

This patch is for mgmt.

This allows to get or set the hostname via the rest api.
Example:
Get the hostname:
curl http://localhost:8000/os/hostname
Set the hostname to 'osv_rocks'
curl -X POST http://localhost:8000/os/hostname?name=osv_rocks

Fixes #60

Signed-off-by: Jaspal Singh Dhillon <jaspal.iiith@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
httpserver: do not override response code in request post-processing phase

Fixes issue with response code set from a lambda handler getting
overriden with '200 OK'.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
httpserver: cleanup: remove unused parameter from reply400/reply500

This parameter has no effect and only gives a false ilusion that error
code can be controlled with it.

Fixes #58.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
httpserver: cleanup: make handle() return void

The return value of handler_base::handle() is not used for anything.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>