Module Expr Str ImportFrom alias Import alias Import alias Import alias Import alias Import alias identifier Import alias Assign NameStore NameLoad TryExcept body Import alias Assign NameStore NameLoad handlers ExceptHandler type NameLoad body Pass Assign NameStore Call AttributeLoad NameLoad attr NameLoad FunctionDef arguments args defaults body Expr Str Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad vararg kwarg body Expr Str If UnaryOpNot Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad Return Dict If BoolOpAnd NameLoad CompareIsNot NameLoad NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body For NameStore Call AttributeLoad NameLoad attr NameLoad body If UnaryOpNot Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad Return Dict Expr Call AttributeLoad AttributeLoad NameLoad attr attr Num Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Index Num Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad If CompareIsNot NameLoad NameLoad body Import alias Assign NameStore Dict Assign NameStore Call AttributeLoad NameLoad attr ListLoad Str Str Str keyword AttributeLoad NameLoad attr For NameStore AttributeLoad NameLoad attr body Assign TupleStore NameStore NameStore NameStore Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad attr Str Assign SubscriptStore NameLoad Index NameLoad NameLoad Assign NameStore ListLoad Str Str Call AttributeLoad Str attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword AttributeLoad NameLoad attr For NameStore AttributeLoad NameLoad attr body Assign TupleStore NameStore NameStore NameStore Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad attr Str If BoolOpOr CompareNotIn NameLoad NameLoad CompareNotEq SubscriptLoad NameLoad Index NameLoad NameLoad body Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad Call AttributeLoad NameLoad attr Str TryExcept body ImportFrom alias Assign NameStore Dict For TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad body Assign TupleStore NameStore NameStore NameStore Call AttributeLoad NameLoad attr Str Assign SubscriptStore NameLoad Index NameLoad Dict For TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad body Assign NameStore Call NameLoad NameLoad NameLoad If CompareIs NameLoad NameLoad body Raise Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad Str attr NameLoad NameLoad Assign NameStore SubscriptStore SubscriptLoad NameLoad Index NameLoad Index AttributeLoad NameLoad attr Dict Assign NameStore SubscriptLoad NameLoad Index Str Assign NameStore SubscriptLoad NameLoad Index Str If CompareIn Str NameLoad body Assign NameStore Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad NameLoad Index Str attr NameLoad orelse Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad For NameStore NameLoad body If CompareNotIn NameLoad NameLoad body Raise Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad Str attr NameLoad If CompareIn SubscriptLoad NameLoad Index NameLoad NameLoad body Raise Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad Str attr SubscriptLoad NameLoad Index NameLoad Assign SubscriptStore NameLoad Index SubscriptLoad NameLoad Index NameLoad NameLoad Return Dict NameLoad NameLoad handlers ExceptHandler type NameLoad name NameStore body Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr Call NameLoad NameLoad Return Dict ExceptHandler type NameLoad name NameStore body Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Str keyword NameLoad Return Dict decorator_list
N/A N/A 
Generate Pillar data from Django models through the Django ORM

:maintainer: Micah Hausler <micah.hausler@gmail.com>
:maturity: new


Configuring the django_orm ext_pillar
=====================================

To use this module, your Django project must be on the salt master server with
database access. This assumes you are using virtualenv with all the project's
requirements installed.

.. code-block:: yaml

    ext_pillar:
      - django_orm:
          pillar_name: my_application
          project_path: /path/to/project/
          settings_module: my_application.settings
          env_file: /path/to/env/file.sh
          # Optional: If your project is not using the system python,
          # add your virtualenv path below.
          env: /path/to/virtualenv/

          django_app:

            # Required: the app that is included in INSTALLED_APPS
            my_application.clients:

              # Required: the model name
              Client:

                # Required: model field to use as the key in the rendered
                # Pillar. Must be unique; must also be included in the
                # ``fields`` list below.
                name: shortname

                # Optional:
                # See Django's QuerySet documentation for how to use .filter()
                filter:  {'kw': 'args'}

                # Required: a list of field names
                # List items will be used as arguments to the .values() method.
                # See Django's QuerySet documentation for how to use .values()
                fields:
                  - field_1
                  - field_2


This would return pillar data that would look like

.. code-block:: yaml

    my_application:
      my_application.clients:
        Client:
          client_1:
            field_1: data_from_field_1
            field_2: data_from_field_2
          client_2:
            field_1: data_from_field_1
            field_2: data_from_field_2

As another example, data from multiple database tables can be fetched using
Django's regular lookup syntax. Note, using ManyToManyFields will not currently
work since the return from values() changes if a ManyToMany is present.

.. code-block:: yaml

    ext_pillar:
      - django_orm:
          pillar_name: djangotutorial
          project_path: /path/to/mysite
          settings_module: mysite.settings

          django_app:
            mysite.polls:
              Choices:
                name: poll__question
                fields:
                  - poll__question
                  - poll__id
                  - choice_text
                  - votes

Module Documentation
====================
 __future__ absolute_import N/A logging N/A os N/A sys N/A salt.exceptions N/A salt.ext.six six N/A salt.utils N/A HAS_VIRTUALENV False N/A N/A N/A virtualenv N/A HAS_VIRTUALENV True N/A N/A N/A ImportError N/A N/A N/A log N/A N/A logging getLogger __name__ __virtual__ N/A N/A N/A N/A N/A 
    Always load
     N/A True N/A ext_pillar N/A N/A minion_id pillar pillar_name project_path settings_module django_app env env_file N/A None None args kwargs N/A N/A 
    Connect to a Django database through the ORM and retrieve model fields

    :type pillar_name: str
    :param pillar_name: The name of the pillar to be returned

    :type project_path: str
    :param project_path: The full path to your Django project (the directory
        manage.py is in)

    :type settings_module: str
    :param settings_module: The settings module for your project. This can be
        found in your manage.py file

    :type django_app: str
    :param django_app: A dictionary containing your apps, models, and fields

    :type env: str
    :param env: The full path to the virtualenv for your Django project

    :type env_file: str
    :param env_file: An optional bash file that sets up your environment. The
        file is run in a subprocess and the changed variables are then added
     N/A N/A N/A N/A N/A os path isdir project_path N/A N/A N/A N/A log error N/A N/A Django project dir: '{0}' not a directory! format project_path N/A N/A N/A N/A HAS_VIRTUALENV N/A env None N/A N/A N/A os path isdir env N/A N/A path N/A N/A virtualenv path_locations env N/A N/A N/A N/A N/A N/A os path isdir path N/A N/A N/A N/A log error N/A N/A Virtualenv {0} not a directory! format path N/A N/A N/A N/A N/A N/A sys path insert 0 N/A N/A N/A os path join N/A N/A N/A virtualenv path_locations env N/A 1 site-packages N/A N/A N/A N/A sys path append project_path N/A N/A N/A os environ N/A DJANGO_SETTINGS_MODULE settings_module N/A N/A env_file None N/A N/A subprocess N/A base_env N/A N/A proc N/A N/A subprocess Popen N/A bash -c env stdout N/A subprocess PIPE N/A line N/A proc stdout N/A N/A N/A key _ value N/A N/A N/A N/A N/A salt utils to_str line partition = N/A N/A base_env N/A key value N/A command N/A bash -c N/A N/A source {0} && env format env_file N/A proc N/A N/A subprocess Popen command stdout N/A subprocess PIPE N/A line N/A proc stdout N/A N/A N/A key _ value N/A N/A N/A N/A N/A salt utils to_str line partition = N/A N/A N/A key base_env N/A N/A base_env N/A key value N/A N/A N/A N/A os environ N/A key N/A N/A value rstrip N/A N/A N/A log debug N/A N/A Adding {0} = {1} to Django environment format key N/A N/A value rstrip N/A N/A django.db.models.loading get_model N/A django_pillar N/A N/A N/A proj_app models N/A N/A six iteritems django_app N/A N/A N/A _ _ app N/A N/A proj_app rpartition . N/A N/A django_pillar N/A app N/A N/A N/A model_name model_meta N/A N/A six iteritems models N/A N/A model_orm N/A get_model app model_name N/A N/A model_orm None N/A N/A N/A N/A N/A salt exceptions SaltException N/A N/A Django model '{0}' not found in app '{1}'. format app model_name N/A pillar_for_model N/A N/A django_pillar N/A app N/A N/A model_orm __name__ N/A N/A name_field N/A model_meta N/A name N/A fields N/A model_meta N/A fields N/A N/A filter model_meta N/A N/A qs N/A N/A N/A N/A N/A model_orm objects filter N/A model_meta N/A filter values fields N/A N/A qs N/A N/A N/A model_orm objects values fields N/A model qs N/A N/A N/A name_field model N/A N/A N/A N/A N/A salt exceptions SaltException N/A N/A Name '{0}' not found in returned fields. format name_field N/A N/A N/A model N/A name_field pillar_for_model N/A N/A N/A N/A N/A salt exceptions SaltException N/A N/A Value for '{0}' is not unique: {0} format N/A model N/A name_field N/A N/A pillar_for_model N/A N/A model N/A name_field model N/A N/A pillar_name django_pillar N/A N/A N/A ImportError N/A e N/A N/A N/A N/A log error N/A N/A Failed to import library: {0} format N/A str e N/A N/A N/A N/A Exception N/A e N/A N/A N/A N/A log error N/A N/A Failed on Error: {0} format N/A str e N/A N/A N/A log debug django_orm traceback exc_info True N/A N/A N/A