Revision 0bb376ce ganeti/snf-ganeti-hook.py
b/ganeti/snf-ganeti-hook.py | ||
---|---|---|
14 | 14 |
|
15 | 15 |
""" |
16 | 16 |
import logging |
17 |
from django.core.management import setup_environ |
|
18 | 17 |
|
19 | 18 |
import sys |
20 | 19 |
import os |
21 | 20 |
|
22 |
# Discover the path for the Synnefo project. |
|
23 |
# |
|
24 |
# IMPORTANT: |
|
25 |
# This assumes this script has been *linked* into the /etc/ganeti/hooks |
|
26 |
# directory on the master and nodes, and that it lives in a ganeti/ directory |
|
27 |
# under the Synnefo project root. |
|
28 |
|
|
21 |
# IMPORTANT: PYTHONPATH must contain the parent of the Synnefo project root. |
|
29 | 22 |
try: |
30 |
target = os.readlink(sys.argv[0]) |
|
31 |
except OSError: |
|
32 |
target = sys.argv[0] |
|
33 |
target_script = os.path.abspath(target) |
|
34 |
target_dirname = os.path.dirname(target_script) |
|
35 |
|
|
36 |
if os.path.split(target_dirname)[1] != "ganeti": |
|
37 |
raise Exception, "Unexpected location for the Synnefo Ganeti hook, " \ |
|
38 |
"cannot determine Synnefo project root.\n" \ |
|
39 |
"This script run as: %s\nLocation determined to be at: %s\n" \ |
|
40 |
"Script in %s, not under ganeti/ directory." % \ |
|
41 |
(sys.argv[0], target_script, target_dirname) |
|
42 |
|
|
43 |
# Add the parent of the project root to sys.path (for Python imports), |
|
44 |
# then load Django settings. |
|
45 |
# FIXME: Why do import references start at synnefo.* ? |
|
46 |
synnefo_project_root = os.path.split(target_dirname)[0] |
|
47 |
sys.path.append(os.path.join(synnefo_project_root, '..')) |
|
48 |
|
|
49 |
import synnefo.settings as settings |
|
50 |
setup_environ(settings) |
|
23 |
import synnefo.settings as settings |
|
24 |
except ImportError: |
|
25 |
raise Exception("Cannot import settings, make sure PYTHONPATH contains " |
|
26 |
"the parent directory of the Synnefo Django project.") |
|
51 | 27 |
|
52 | 28 |
# A hook runs either in the "pre" or "post" phase of a Ganeti operation. |
53 | 29 |
# Possible values for the Ganeti operation are "instance-start", |
Also available in: Unified diff