libra/doc/pool_mgm/code.rst
Andrew Hutchings ed21fa1748 Accept names for flavor and image
If a name is specified for flavor or image this is used to search for the
relevant IDs

Also fix type on Nova delete handler

Fixes bug #1076912

Change-Id: Ia891e20a1a7a09715fb69df64246e339c1145d3c
2012-11-14 12:29:42 +00:00

3.8 KiB

Code Walkthrough

Here we'll highlight some of the more important code aspects.

Server Class

This class is the main server activity once it has started in either daemon on non-daemon mode.

param logger

An instance of :pylogging.logger

param args

An instance of :pylibra.common.options.Options

Sets the signal handler and then called :pycheck_nodes

Runs a check to see if new nodes are needed. Called once by :pymain at start and then called by the scheduler. It also restarts the scheduler at the end of execution

Uses :pythreading.Timer to set the next scheduled execution of :pycheck_nodes

Builds the required number of nodes determined by :pycheck_nodes.

param count

The number of nodes to build

param api

A driver derived from the :pyMgmDriver parent class

The signal handler function. Clears the signal handler and calls :pyshutdown

param signum

The signal number

param frame

The stack frame

Causes the application to exit

param error

set to True if an error caused shutdown

type error

boolean

Node Class

This class uses :pynovaclient.client to manipulate Nova nodes

param username

The Nova username

param password

The Nova password

param tenant

The Nova tenant

param auth_url

The Nova authentication URL

param region

The Nova region

param keyaname

The Nova key name for new nodes

param secgroup

The Nova security group for new nodes

param image

The Nova image ID or name for new nodes

param node_type

The flavor ID or name for new nodes

Creates a new Nova node and tests that it is running. It will poll every 3 seconds for 2 minutes to check if the node is running.

return

True and status dictionary for success, False and error for fail

MgmDriver Class

The defines the API for interacting with various API servers. Drivers for these API servers should inherit from this class and implement the relevant API methods that it can support. This is an abstract class and is not meant to be instantiated directly.

Gets the number of free nodes. This is used to calculate if more nodes are needed

return

the number of free nodes

Adds the node details for a new device to the API server.

param name

the new name for the node

param address

the new public IP address for the node

return

True or False and the JSON response (if any)

Check to see if the driver has access to a valid API server

return

True or False

Gets the URL for the current API server

return

the URL for the current API server

Known Drivers Dictionary

This is the dictionary that maps values for the --driver <libra_pool_mgm.py --driver> option to a class implementing the driver :py~MgmDriver API for that API server. After implementing a new driver class, you simply add a new entry to this dictionary to plug in the new driver.