Code Monkey home page Code Monkey logo

openstackgpuservice's Introduction

OpenstackGPUService

Overview

This service provides a REST-API to retrieve information about OpenStack GPU flavors (total and available). It is written for de.NBI cloud OpenStack setups especially in Bielefeld, but can easily be adapted to any OpenStack installation providing GPU (or other) resources.

Prerequisites

The OpenstackGPUService needs some additional configuration of aggregates and flavors to work properly.

Aggregates

GPU hypervisors have to be grouped into different aggregates based on their GPU type (gpu_type) and on the number of GPUs they provide (gpu_count). Every aggregate has to make some extra metadata available:

  • gpu='' Whether this aggregate provides GPU resources.
  • gpu_count='' Number of GPUs provided.
  • gpu_type='' Type (alias name) of GPU provided.
Example
$ openstack aggregate show 'Delta GPU V100'
+-------------------+--------------------------------------------------------------------------------+
| Field             | Value                                                                          |
+-------------------+--------------------------------------------------------------------------------+
| availability_zone | default                                                                        |
| created_at        | 2018-10-13T19:08:59.000000                                                     |
| deleted_at        | None                                                                           |
| hosts             | host1,host2,...                                                                |
| id                | 10                                                                             |
| is_deleted        | False                                                                          |
| name              | Delta GPU V100                                                                 |
| properties        | cores='28', gpu='True', gpu_count='2', gpu_type='V100', hyperthreading='false' |
| updated_at        | 2022-03-23T14:31:00.000000                                                     |
| uuid              | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx                                           |
+-------------------+--------------------------------------------------------------------------------+

Flavors

Currently GPU are supported using the PCI-passthrough feature of Openstack. Flavors must be configured setting the pci_passthrough:alias property=':. The service matches the alias name with aggregates gpu_type (aggregates metadata) to calculate the total count and current available number of each flavor.

There is of course more configuration work to do to support GPU(PCI) devices properly.

Example
$ openstack flavor show 'de.NBI GPU V100 medium'                                                                                                                                                                                                                                    
+-------------------------------------------------------------------------------------------------+
| Field                      | Value                                                              |
+----------------------------+--------------------------------------------------------------------+
| OS-FLV-DISABLED:disabled   | False                                                              |
| OS-FLV-EXT-DATA:ephemeral  | 0                                                                  |
| access_project_ids         | ['xxx', 'xxx', 'xxx', 'xxx', ... ]                                |
| description                | None                                                               |
| disk                       | 50                                                                 |
| id                         | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx                               |
| name                       | de.NBI GPU V100 medium                                             |
| os-flavor-access:is_public | False                                                              |
| properties                 | pci_passthrough:alias='V100:1'                                     |
| ram                        | 65535                                                              |
| rxtx_factor                | 1.0                                                                |
| swap                       | 1024                                                               |
| vcpus                      | 14                                                                 |
+----------------------------+--------------------------------------------------------------------+

This server was generated by the OpenAPI Generator project. By using the OpenAPI-Spec from a remote server, you can easily generate a server stub.

Requirements

Python 3.6+

Usage

It recommend to install dependencies in a separate virtual environment.

$ python3 -m venv venv
$ source venv/bin/activate
(venv)$ pip3 install -r requirements.txt

When connecting to a "real" Openstack Setup, you have to source your RC file beforehand. The Openstack user should be has the admin role or at least the capability to list all servers, flavors, hypervisor and aggregates.

(venv)$ source my_project-openrc.sh

Client

To run the client, please execute the following from the root directory:

(venv)$ python3 OpenStackGPUClient.py --help

Server

For performance reasons (and better user feelings) the server returns only cached data. The cache (only memcached is supported) is updated continuously.

  1. A user/client requests for data.
  2. The server ask the cache if the requested resources are available.
  3. Depending on the cache status, the result is returned immediately or calculated (long running task!).
  4. Independent of the REST API, the cache is updated continuously (every 150 seconds by default).

To run the server, please execute the following from the root directory:

(venv)$ python3 OpenStackGPUServer.py 

When running OpenstackGPUServer without further arguments a memcached service listening on 127.0.0.1:11211 is expected and REST is bind to http://127.0.0.1:8080.

A graphical UI (for testing) is available at:

http://localhost:8080/ui/

Your OpenAPI definition lives here:

http://localhost:8080/openapi.json

(Units-)Test

OpenstackGPUService comes with a full set of units test. All external dependencies concerning the Openstack API are mocked using unittest.mock functionality.

Mock Test Setup

The Mock test setup "simulates" the following setup.

  • two aggregates (for GPU and non GPU based hypervisors)
  • three hypervisors available (28 cores, 384 cores, 4 TB local disc space), two of them having two GPUs on board
  • two instances running (de.NBI large, de.NBI GPU V100 medium)

Calling the gpu_flavors_get methods should return a list of three GPU flavors.

  • de.NBI GPU V100 medium (4 total, 3 available)
  • de.NBI GPU V100 large (4 total, 3 available)
  • de.NBI 2 GPU V100 large (2 total, 1 available)

Integration test

To launch the integration tests, use tox from the root directory:

(venv)$ pip install tox
(venv)$ tox

Running with Docker

To run the server inside a Docker container, please execute the following from the root directory:

# building the image
docker build -t openapi_server .

# start up a container in the host network
docker run --network host --env-file ./env.file denbi/openstackgpuservice

where env.file contains the Openstack environment :

OS_REGION_NAME=Bielefeld
OS_PROJECT_DOMAIN_ID=default
OS_INTERFACE=public
OS_AUTH_URL=https://openstack.cebitec.uni-bielefeld.de:5000/v3/
OS_USERNAME=XXXX
OS_PROJECT_ID=XXXXX
OS_USER_DOMAIN_NAME=Default
OS_PROJECT_NAME=XXXXX
OS_PASSWORD=XXXXXX

Running with Docker Compose

Run a OpenstackGPUService together with a memcached service container with docker compose is also supported.

docker run -p 8080:8080 openapi_server
docker run --network host --env-file ./env.file denbi/openstackgpuservice

openstackgpuservice's People

Contributors

jkrue avatar dweinholz avatar maitai avatar ekatchko avatar awalende avatar pbelmann avatar

Watchers

 avatar James Cloos avatar  avatar Nils Hoffmann avatar  avatar  avatar

openstackgpuservice's Issues

Service crash when using with Openstack Wallaby

The Update from Openstack Train to Openstack Wallaby bumps the microversion of the Compute API from
2.79 to 2.88.

(taken from https://docs.openstack.org/nova/latest/reference/api-microversion-history.html)

2.88 (Maximum in Wallaby)
The following fields are no longer included in responses for the GET /os-hypervisors/detail and GET /os-hypervisors/{hypervisor_id} APIs:

  • current_workload
  • cpu_info
  • current_workload
  • cpu_info
  • vcpus
  • vcpus_used
  • free_disk_gb
  • local_gb
  • local_gb_used
  • disk_available_least
  • free_ram_mb
  • memory_mb
  • memory_mb_used
  • running_vms
  • vcpus
  • vcpus_used
  • free_disk_gb
  • local_gb
  • local_gb_used
  • disk_available_least
  • free_ram_mb
  • memory_mb
  • memory_mb_used
  • running_vms

These fields were removed as the information they provided were frequently misleading or outright wrong, and many can be better queried from placement.

add ci workflow

The current version comes with a full mocked test suite. We should consider adding a ci workflow.

Question concerning the API response value ?

How can I understand the specification?
It is of course possible to calculate the available count and the absolute number of instances based on this flavor, but what is the idea behind the absolute number of instances? In my opinion, this information is worth nothing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.