-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The configuration management database (CMDB) is a system that stores server information.
In order to use this tool, there are a few things you need to install.
- Make sure all the requirements from the prior section are installed.
- Clone this repo.
- Create a new virtual environment and enter it. Run:
$ virtualenv venv
$ source venv/bin/activate- Install the requirements. Run:
(venv)$ pip install -r requirements.txtThese parts of the project contain the core functionality of CMDB. These include:
- A database that stores server information along with an API
- Using the database API directly does not provide authentication and authorization, so it is recommended to use the HTTP API to interact with the database
- An HTTP API for interacting with the database
- A Python client library for the HTTP API
The database is the most important part of CMDB. It organizes and stores all metadata about servers. We expose an API to directly communicate with the database.
There are three types of information that the CMDB stores.
- Fields: these are the fields that the database is configured with, which currently are: the application, environment, and tier.
- Tags: these are arbitrary key-value pairs that servers can be attributed with.
- VIPs: VIPs, or Virtual IP addresses, have their own endpoint. They can also be tagged with arbitrary key-value pairs, servers can be associated with the VIPs, and there can be names associated with the VIPs.
In addition, there is a filtering system in place so you can search for servers that match the particular field, tag or VIP. However, this best used through the web and client APIs.
In order to use any of the other components, you need to configure the database. Make sure that a "cmdb" database is created in mysql. To do so, just run (as root mysql user)
mysql> CREATE USER '<username>'@'localhost' IDENTIFIED BY '<password>';
mysql> CREATE DATABASE cmdb;
mysql> GRANT ALL on cmdb.* to '<username>'@'localhost';Visit the CMDB API page to learn about how to use the cmdb API and what methods are available.
The Web API Server is a Flask application that communicates with the database.
- Authentication: There is a user/ password system in place for security. Once a user has authenticated, they will be given a session ID which they can then use for authentication for subsequent requests to the server.
-
- Authorization: There are three permissions for users.
-
- Read: A user with read permission can only view data.
- Write: A user with write permission can read and write to the database.
- Admin: A user with admin permission can read and write to the database in addition to adding/deleting users and setting user permissions.
Once a server database has been created, you can start up the Flask server (make sure you are in the virtualenv).
Run:
$ source bin/activate
(venv)$ cd src
(venv)$ python server.py -u <username> -p <password>You can specify what hostname or port of the server by using the optional arguments -H, --host or -P, --port.
For example:
(venv)$ python server.py -u <username> -p <password> --host localhost --port 80The default host is 127.0.0.1 and the default port is 5000.
The first POST request to the /user endpoint will create an administrative user that will be able to create other users,
so make sure do this first:
$ curl -X POST -H "Content-Type: application/json" 127.0.0.1:5000/user --data '{"username": "<admin username here>", "password": "<admin password here>"}'Once the server is established, you can make HTTP requests to the Web API. Look at the documentation located server.
The Python client library sends HTTP requests to a given web API server.
The Python client library properly formats the requests to a given web API server, according to the API defined in the web API server, and handles passing in session tokens.
For an application to use the client library, you only need to include the cmdb_client.py file in your $PYTHONPATH
and say:
import cmdb_client
in your application to get full access to it.
Visit the client API page to learn about how to use the cmdb_client API and what methods are provided.
In order to properly generate the documentation, make sure you have the requirements installed from the installation section above. To view documentation, run (in the virtualenv):
(venv)$ cd docs
(venv)$ make htmlIn addition to the core features which focus on interacting with and serving server information, we also have a set of scripts that allow for easy importing of already existing server configurations.
You can add them to your $PATH or just use the scripts in the repository.
One source of server configuration is the SoftLayer JSON files. The populate_db script takes in a json file and populates the database with information
from that json file.
To run the script, you should have a server running along with a username and password in the database. This line of code will run the script:
$ populate_db.py [--html HTML] username password server jsonRequired arguments:
username Username for authentication for the cmdb password Password for the corresponding username server URL of the server json Full path of the file that contains the metadata in JSON
Optional arguments:
--html HTML Full path of the file that contains the tier configuration
Another source of server information can come from existing Puppet config files. The parse_vip_puppet script takes a recipe and populates the database with
vip information.
To run the script, you should have a server running along with a username and password in the database. This line of code will run the script:
$ parse_vip_puppet.py username password server file_pathRequired arguments:
username Username for authentication for the cmdb password Password for the corresponding username server URL of the server file_path Full path of the file that contains the tier configuration information