Skip to main content

A flask based vm booking app.

Project description

vm-booking-app

A RESTful API application where I can store data about VMs used by customers.

Installation

Install using pip:

$ pipenv install
$ flask run

API Usage Examples

Get all users.

$ curl -X GET http://localhost:5000/api/users
{
  "users": [
    {
      "id": 1,
      "email: "user1@gmail.com",
      "username": "user1"
    },
    {
      "id": 2,
      "email: "user2@gmail.com",
      "username": "user2"
    }
  ]
}

Get a user.

Gets a user username.

$ curl -X GET http://localhost:5000/api/users/<slug>
{
  "user": {
    "id": 1,
    "email: "user1@gmail.com",
    "username": "user1"
  }
}

Create a user.

Email and username are required fields.

$ curl -X POST http://localhost:5000/api/users -d '{"email":"user3@gmail.com", "username": "user3"}'
{
  "user": {
    "id": 1,
    "email": "user3@gmail.com",
    "username": "user3"
  }
}

Update a user.

Only email and username can be changed.

$ curl -X PATCH http://localhost:5000/api/users/<slug> -d '{"email":"user4@gmail.com"}'
{
  "user": {
    "id": 1,
    "email": "user4@gmail.com",
    "username": "user4"
  }
}

Delete a user.

$ curl -X DELETE http://localhost:5000/api/users/<slug>
{
  "user": {
    "id": 1,
    "email": "user1@gmail.com",
    "username": "user1"
  }
}

Get all vms.

$ curl -X GET http://localhost:5000/api/vms
{
  "vms": [
    {
      "id": 1,
      "name": "VM1",
      "ip": "10.0.2.3",
      "description": "general purpose vm",
      "status": "running",
      "reservation_start": "21/11/2026",
      "reservation_end": "21/11/2026",
      "user_id": 1
    }
  ]
}

Get a vm.

$ curl -X GET http://localhost:5000/api/vms/<id>
{
  "vm": {
    "id": 1,
    "name": "VM1",
    "ip": "10.0.2.3",
    "description": "general purpose vm",
    "status": "running",
    "reservation_start": "21/11/2026",
    "reservation_end": "21/11/2026",
    "user_id": 1
  }
}

Create a vm.

Name, ip, user_id are required.

$ curl -H "Content-Type: application/json" -X POST http://localhost:5000/api/vms
-d '{"ip":"10.0.2.4", "name": "VM1", "reservation_start": "21/11/2026", "reservation_end": "21/11/2026", "userId": 2}'
{
  "vm": {
    "id": 1,
    "name": "VM1",
    "ip": "10.0.2.3"
    "description": "general purpose vm",
    "status": "running",
    "reservation_start": "21/11/2026",
    "reservation_end": "21/11/2026",
    "user_id": 1
  }
}

Update vm.

Only name, description and status can be chanded currently.

$ curl -H "Content-Type: application/json" -X PATCH http://localhost:5000/api/vms/<id>
-d '{"description":"standart vm"}'
{
  "vm": {
    "id": 1,
    "name": "VM1",
    "ip": "10.0.2.3",
    "description": "standard vm",
    "status": "running",
    "reservation_start": "21/11/2026",
    "reservation_end": "21/11/2026",
    "user_id": 1
  }
}

Delete vm.

$ curl -H "Content-Type: application/json" -X DELETE http://localhost:5000/api/vms/<id>
{
  "vm": {
    "id": 1,
    "ip": "10.0.2.3",
    "name": "VM1",
    "description": "standard vm",
    "status": "running",
    "reservation_start": "21/11/2026",
    "reservation_end": "21/11/2026",
    "user_id": 1
  }
}

Get vm usage by username

$ curl -X GET http://localhost:5000/api/users/<slug>/vm-use
{
  "user": {
    "id": 1,
    "email": "user1@gmail.com",
    "username": "user1",
    "vms": [{}, {}]
  }
}

Development

For working on vm-booking-app, you'll need to have Python >= 3.7 and pipenv installed. With those installed, run the following command to create a virtualenv for the project and fetch the dependencies:

$ pipenv install --dev
...

Next, activate the virtualenv and get to work:

$ pipenv shell
...
(vm-booking-app) $

Linting

For linting we use flake8 tool. We should keep code clean. To run linter use the following command:

$ flake8 api
...

Models

User

id: number
email: string
username: string

VM

id: number
name: string
ip: string
description: string?
status: string
reservation_start: DateTime
reservation_end: DateTime
user_id: User.id

Deploying

cd ~
git clone git@gitlab-1914910442.us-west-2.elb.amazonaws.com:oonyshchenko/vm-booking-app.git
git checkout master
source .env_prod
docker-compose up --build -d

Testing

Open in browser http://localhost:5000 to get API status and version.

Open in browser http://localhost:5000/healthy to get DB connection status.

Automatic tests

(vm-booking-app) $ pytest
(vm-booking-app) $ pytest --cov=api   

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vm-booking-app-0.1.44.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vm_booking_app-0.1.44-py2.py3-none-any.whl (5.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file vm-booking-app-0.1.44.tar.gz.

File metadata

  • Download URL: vm-booking-app-0.1.44.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for vm-booking-app-0.1.44.tar.gz
Algorithm Hash digest
SHA256 ec333b278a5b4580ff3639d3b4453c0218eeab7a2e5c9911f319f40c5771e56e
MD5 8811a8faddc9ce8dd4d7fb40c0904d9b
BLAKE2b-256 7f2b33a387edc7acd1953517edbb1fc365846bd153395d0f0263a7dc8e8a3318

See more details on using hashes here.

File details

Details for the file vm_booking_app-0.1.44-py2.py3-none-any.whl.

File metadata

  • Download URL: vm_booking_app-0.1.44-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for vm_booking_app-0.1.44-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 38fb1d251165e37514a51e5d07dab19cb64b0bbd3d14c87accdb6105b13012e1
MD5 8b6aec9a8892f65a3540e43b6e1f1ff1
BLAKE2b-256 9a0b89f579058b662790a8ecd2e07ef03669be2634989cb881d4e6faf868b999

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page