doc/book/admin/pyro.rst
author Christophe de Vienne <christophe@unlish.com>
Thu, 08 Jan 2015 22:11:06 +0100
changeset 10491 c67bcee93248
permissions -rw-r--r--
[doc] Restructure the documentation * Create a new index file * Move the sphinx configuration files do the documentation root * Move book/README to dev/documenting.rst * Move book/mode_plan.py to tools/ * Move book/en/images to images * Move book/en/* to book/ * Move changelogs to changes/* * Adapt the Makefile * Add a title to the javascript api index Related to #4832808
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10491
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     1
.. _UsingPyro:
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     2
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     3
Working with a distributed client (using Pyro)
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     4
==============================================
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     5
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     6
In some circumstances, it is practical to split the repository and
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     7
web-client parts of the application for load-balancing reasons. Or
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     8
one wants to access the repository from independant scripts to consult
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     9
or update the database.
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    10
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    11
Prerequisites
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    12
-------------
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    13
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    14
For this to work, several steps have to be taken in order.
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    15
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    16
You must first ensure that the appropriate software is installed and
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    17
running (see :ref:`ConfigEnv`)::
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    18
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    19
  pyro-nsd -x -p 6969
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    20
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    21
Then you have to set appropriate options in your configuration. For
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    22
instance::
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    23
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    24
  pyro-server=yes
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    25
  pyro-ns-host=localhost:6969
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    26
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    27
  pyro-instance-id=myinstancename
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    28
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    29
Connect to the CubicWeb repository from a python script
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    30
-------------------------------------------------------
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    31
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    32
Assuming pyro-nsd is running and your instance is configured with ``pyro-server=yes``,
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    33
you will be able to use :mod:`cubicweb.dbapi` api to initiate the connection.
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    34
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    35
.. note::
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    36
    Regardless of whether your instance is pyro activated or not, you can still
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    37
    achieve this by using cubicweb-ctl shell scripts in a simpler way, as by default
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    38
    it creates a repository 'in-memory' instead of connecting through pyro. That
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    39
    also means you've to be on the host where the instance is running.
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    40
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    41
Finally, the client (for instance a python script) must connect specifically
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    42
as in the following example code:
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    43
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    44
.. sourcecode:: python
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    45
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    46
    from cubicweb import dbapi
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    47
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    48
    cnx = dbapi.connect(database='instance-id', user='admin', password='admin')
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    49
    cnx.load_appobjects()
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    50
    cur = cnx.cursor()
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    51
    for name in (u'Personal', u'Professional', u'Computers'):
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    52
        cur.execute('INSERT Tag T: T name %(n)s', {'n': name})
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    53
    cnx.commit()
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    54
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    55
Calling :meth:`cubicweb.dbapi.load_appobjects`, will populate the
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    56
cubicweb registries (see :ref:`VRegistryIntro`) with the application
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    57
objects installed on the host where the script runs. You'll then be
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    58
allowed to use the ORM goodies and custom entity methods and views. Of
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    59
course this is optional, without it you can still get the repository
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    60
data through the connection but in a roughly way: only RQL cursors
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    61
will be available, e.g. you can't even build entity objects from the
c67bcee93248 [doc] Restructure the documentation
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    62
result set.