The app.py file

 

Each extension of CoreCluster must contain file with definition of module contents

The app.py contains the list of:

This is main point to define contents of your extension. CoreCluster and CoreNode uses this definition to obtain necessary resources and to configure cloud.

Sample file looks like this:


MODULE = {
    'models': ['myextension.models.myextension_model'],
    'api': [
        'myextension.views.api',
        'corecluster.views.admin',
    ],
    'ci': [
        'myextension.views.ci',
    ],
    'configs': {
        'myextension': '/etc/corecluster/config.py',
    },
    'hooks': {
        'agent.vm.create': ['myextension.hooks.vm'],
        'agent.vm.remove_vm': ['myextension.hooks.vm'],
        'cron.minute': ['myextension.hooks.check_something', 'myextension.hooks.check_another_thing'],
    },
    'agents': [
        {'type': 'important_task_queue', 'module': 'myextension.agents.importantagent', 'count': 4},
    ],
    'drivers': {
        'MYEXTENSION_VM_DRIVER': 'myextension.drivers.vm',
    },
    'algorithms': {
        'MYEXTENSION_SOMETHING_SELECT': 'myextension.algorithms.select',
    },
}

app.py file contents

The name of app.py file is unrestricted, however convention is to name it app.py. Other names will cause different import path in config.py for CoreCluster and CoreNode. This file should be directly pointed in above configs to enable particular extension. In whole documentation this file is called as app.py.

The mandatory part of each app.py is MODULE dictionary, which contains all provided by extension parts.

models section

This section is a list of python modules required to load when module is enabled. This modules should contain additional database models (Django ORM) to handle extension's data. For example:


MODULE = {
    'models': [
        'myextension.models.vm_accounting_tables',
        'myextension.models.image_accounting_tables',
    ],
...

Read more about database model in Database model reference

api and ci sections

This section contains import to python's module with additional API functions. Usually this is present in all extensions and it is the only way to expose new functionality to the user.

Similar section to the api in app.py is ci. It defines list of additional functions present in Cluster Interface (CI), which is used for internal communication between Compute Nodes and Management Node.


MODULE = {
    'api': [
        'myextension.views.api',
        'corecluster.views.admin',
    ],
    'ci': [
        'myextension.views.ci',
    ],
...

With new API or CI modules you can add new functions or replace existing by overriding them. Order of functions is defined by order in APPS list, in config.py files for CoreNode and CoreCluster. You can also add new Admin site modules by api list.

configs section

With MODULE you can define own config files to access them with config.get function from corenetwork package. This should easier reading config contents in any place of your code.


MODULE = {
    'configs': {
        'myextension': '/etc/corecluster/config.py',
    },
...

Then you can use following code to obtain variable from your config:


from corenetwork.utils import config
...
variable = config.get('myextension', 'MY_VARIABLE', 'default_value')

agents section

This section was moved in version 16.12 from /etc/corecluster/agent.py config file to the app.py file. It defines what kind of tasks are supported by agents provided by extension and how should this taasks be handled. Also this section describes amount of each agent type to be executed at host.


MODULE = {
    'agents': [
        {'type': 'important_task_queue', 'module': 'myextension.agents.importantagent', 'count': 4},
    ],
...

Of corse, it is not mandatory to provide any agent with your extension, but if you need it, the app.py file is right place to declare it. Moreover, such configuration is much easier to enable your extension, instead defining agents in agent.py file.

The type subfield of agents section in MODULE dictionary defines which queue (what is equivalent to task type) is supported by this extension. Beware, that overriding any existing type of tasks will cause fully removal of previous agent with all its actions.

The module points to the Python's module with agent thread. This module should contain the AgentThread class, which inherits from BaseAgent. Read more in Agent reference .

The count field defines how many instances of this agent type should be executed at each host.

Remaining sections

All remaining sections point to the python modules, described in proper reference guides.

< Go back     Author: Maciej Nabozny Published: Jan. 13, 2017, 6:20 p.m.