lease_it apps

lease_it.backend

lease_it.backendExceptions

This module contains all exception triggered by Backend

exception lease_it.backend.Exceptions.PermissionDenied(user_id, instance_id)[source]

PermissionDenied exception is triggered when a user (logged or not) try to make an invalid command

lease_it.backend.OpenstackConnection

This module manage interaction between application and OpenStack cloud infrastructure

class lease_it.backend.OpenstackConnection.OpenstackConnection[source]

This class manage interface between OpenStack Cloud infrastructure and views.

flavors()[source]

Return a list of flavor and a detail about

  • Their properties (CPU / Disk / RAM)
  • The actual Cloud state (number of VM we can start, maximum VM we can start if empty)
Returns:dict()
instances(request, filtered=False)[source]

List all instances started on cluster and owned by user

Parameters:
  • request – Web request, used to retrieve user id
  • filtered – True if we only return user_id instances
Returns:

dict()

static lease_instance(request, instance_id)[source]

If instance_id is owned by user_id, then update lease information, if not, raise PermissionDenied exception. A Openstack administrator can also update a lease for a user

Parameters:
  • instance_id – id of instance
  • request – Web request
Returns:

void

projects()[source]

Return a list of project w/ there id and name

Returns:dict()
spy_instances()[source]

spy_instances is started by instance_spy module and check all running VM + notify user if a VM is close to its lease time

Returns:dict()
users()[source]

Return a list of users w/ attributes id, first_name, last_name and email

Returns:dict of users

lease_it.backend.TestConnection

TestConnection is a fake backend to return some fake value for testing. It will return value in the same format that OpenstackConnection must do.

TestConnection inherits from OpenstackConnection and overwrite the private methods

  • _instances()
  • _flavors()
  • _hypervisors()
  • _domains()
  • _users()
  • _projects()

lease_it.client

instance-spy should be put on a crontab to check running instance, notify user if lease is close to expire and destroy instance when lease is over

lease_it.client.run.admin_cli()[source]

Admin Command Line Interface

Returns:void
lease_it.client.run.instance_spy()[source]

Function used to run the script

Returns:void

lease_it.datastore

lease_it.datastore.Exceptions

This module contains all exception triggered by Backend

exception lease_it.datastore.Exceptions.StillRunning(instance_id, heartbeat)[source]

PermissionDenied exception is triggered when a user (logged or not) try to make an invalid command

lease_it.datastore.ModelAccess

ModelAccess module is a interface between Django model and view

class lease_it.datastore.ModelAccess.InstancesAccess[source]

ModelAccess is a class will abstract model access for application. It will get / save / ... informations in a format expected by views

static delete(instance_id)[source]

Remove instance entry on database. If the VM is still running, the VM will be recreated on next spy instance running

Parameters:instance_id – instance to delete
Returns:None
static get(instance)[source]

Get or Create instance on model backend

Parameters:instance – instance to get
Returns:Instance model
static get_all()[source]

Return all data on database

Returns:dict of data
static heartbeat(instance)[source]

get a instance and update the heartbeat value. This method is called by instance-spy when it find a instance running. Heartbeat can be use to retrieve old Virtual Machine

Parameters:instance – instance to update
Returns:None
static lease(instance)[source]

get a instance and update the leased_at value.

Parameters:instance – instance to lease
Returns:None
static show(instances)[source]

Return a list of instances store on database

Returns:dict of instances

lease_it.notification

Mail notification system

class lease_it.notification.MailNotification.MailNotification(users)[source]

A class to abstract e-mail notification

format_mail(user, notification_type, instances)[source]

Format the mail content :param user: user we currently notify :param notification_type: notification type (delete or notify) :param instances: list of instance for the user :return: string

static format_user_instances(user)[source]

Create a string w/ the list of instance formatted to be mailed :param user: user we currently notify :return: string

send(notifications)[source]

The all notifications give in parameter, each notifications type (delete or notify) are a dictionnary of users with a list of instance to notify per user :param notifications: dict of users and instances :return: void

lease_it.models

model for django database. Use for 2 differents cases:

  • Cache some data to avoid useless overload on OpenStack infrastructure
    • instances informations
    • user informations
    • ...
  • Store data that is not available on OpenStack
    • lease time
    • ...
class lease_it.models.Instances(*args, **kwargs)[source]

Instance model will be use to store instances informations as id / name / launch time / lease time / ...

lease_it.views

Views module manage interface between user and openstack-lease-it.

lease_it.views provide interaction based on REST good practice.

lease_it.views.dashboard(request, *args, **kwargs)[source]

The default dashboard

Parameters:request – Web request
Returns:HTML Rendering
lease_it.views.database(request, *args, **kwargs)[source]

This view is used to delete instance from database

Parameters:
  • request – Web request
  • instance_id – instance id
Returns:

JSonResponse w/ status of deletion

lease_it.views.databases(request, *args, **kwargs)[source]

View for all entries on database, used to delete old instances data

Parameters:request – Web request
Returns:JSonResponse w/ list of database entries
lease_it.views.flavors(request, *args, **kwargs)[source]

View for flavors request

Parameters:request – Web request
Returns:JsonResponse w/ list of flavor and details values
lease_it.views.instance(request, *args, **kwargs)[source]

This is view used to for a new lease on a specific instance (http://url/instances/instance_id) a PermissionDenied exception is raised decided by backend. Mainly if instance is not owned by user but see Backend comment.

Parameters:
  • request – Web request
  • instance_id – retrieve from url
Returns:

JsonResponse

lease_it.views.instances(request, *args, **kwargs)[source]

View for instances list

Parameters:request – Web request
Returns:JsonResponse w/ list of instances and details
lease_it.views.users(request, *args, **kwargs)[source]

View for users

Parameters:request – Web request
Returns:JsonResponse w/ list of users and details