Locking: add ssynchronized decorator
[ganeti-local] / lib / constants.py
1 #
2 #
3
4 # Copyright (C) 2006, 2007 Google Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21
22 """Module holding different constants."""
23
24 from ganeti import _autoconf
25
26 # various versions
27 PROTOCOL_VERSION = 13
28 RELEASE_VERSION = _autoconf.PACKAGE_VERSION
29 OS_API_VERSION = 5
30 EXPORT_VERSION = 0
31
32
33 # Format for CONFIG_VERSION:
34 #   01 03 0123 = 01030123
35 #   ^^ ^^ ^^^^
36 #   |  |  + Configuration version/revision
37 #   |  + Minor version
38 #   + Major version
39 #
40 # It stored as an integer. Make sure not to write an octal number.
41
42 # BuildVersion and SplitVersion must be in here because we can't import other
43 # modules. The cfgupgrade tool must be able to read and write version numbers
44 # and thus requires these functions. To avoid code duplication, they're kept in
45 # here.
46
47 def BuildVersion(major, minor, revision):
48   """Calculates int version number from major, minor and revision numbers.
49
50   Returns: int representing version number
51
52   """
53   assert isinstance(major, int)
54   assert isinstance(minor, int)
55   assert isinstance(revision, int)
56   return (1000000 * major +
57             10000 * minor +
58                 1 * revision)
59
60
61 def SplitVersion(version):
62   """Splits version number stored in an int.
63
64   Returns: tuple; (major, minor, revision)
65
66   """
67   assert isinstance(version, int)
68
69   (major, remainder) = divmod(version, 1000000)
70   (minor, revision) = divmod(remainder, 10000)
71
72   return (major, minor, revision)
73
74
75 CONFIG_MAJOR = int(_autoconf.VERSION_MAJOR)
76 CONFIG_MINOR = int(_autoconf.VERSION_MINOR)
77 CONFIG_REVISION = 0
78 CONFIG_VERSION = BuildVersion(CONFIG_MAJOR, CONFIG_MINOR, CONFIG_REVISION)
79
80 # file paths
81 DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti"
82 RUN_DIR = _autoconf.LOCALSTATEDIR + "/run"
83 BDEV_CACHE_DIR = RUN_DIR + "/ganeti"
84 LOCK_DIR = _autoconf.LOCALSTATEDIR + "/lock"
85 CLUSTER_CONF_FILE = DATA_DIR + "/config.data"
86 SSL_CERT_FILE = DATA_DIR + "/server.pem"
87 WATCHER_STATEFILE = DATA_DIR + "/watcher.data"
88 SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
89 ETC_HOSTS = "/etc/hosts"
90 DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
91 MASTER_SOCKET = RUN_DIR + "/ganeti-master.sock"
92
93 NODE_INITD_SCRIPT = _autoconf.SYSCONFDIR + "/init.d/ganeti"
94 DEFAULT_NODED_PORT = 1811
95 FIRST_DRBD_PORT = 11000
96 LAST_DRBD_PORT = 14999
97 MASTER_SCRIPT = "ganeti-master"
98
99 LOG_DIR = _autoconf.LOCALSTATEDIR + "/log/ganeti"
100 LOG_OS_DIR = LOG_DIR + "/os"
101 LOG_NODESERVER = LOG_DIR + "/node-daemon.log"
102 LOG_WATCHER = LOG_DIR + "/watcher.log"
103 LOG_MASTERDAEMON = LOG_DIR + "/master-daemon.log"
104
105 OS_SEARCH_PATH = _autoconf.OS_SEARCH_PATH
106 EXPORT_DIR = _autoconf.EXPORT_DIR
107
108 EXPORT_CONF_FILE = "config.ini"
109
110 XEN_KERNEL = _autoconf.XEN_KERNEL
111 XEN_INITRD = _autoconf.XEN_INITRD
112
113 VALUE_DEFAULT = "default"
114 VALUE_NONE = "none"
115
116 # hooks-related constants
117 HOOKS_BASE_DIR = _autoconf.SYSCONFDIR + "/ganeti/hooks"
118 HOOKS_PHASE_PRE = "pre"
119 HOOKS_PHASE_POST = "post"
120 HOOKS_NAME_CFGUPDATE = "config-update"
121 HOOKS_VERSION = 1
122
123 # hooks subject type (what object type does the LU deal with)
124 HTYPE_CLUSTER = "CLUSTER"
125 HTYPE_NODE = "NODE"
126 HTYPE_INSTANCE = "INSTANCE"
127
128 HKR_SKIP = 0
129 HKR_FAIL = 1
130 HKR_SUCCESS = 2
131
132 # disk template types
133 DT_DISKLESS = "diskless"
134 DT_PLAIN = "plain"
135 DT_DRBD8 = "drbd"
136 DT_FILE = "file"
137
138 # the set of network-mirrored disk templates
139 DTS_NET_MIRROR = frozenset([DT_DRBD8])
140
141 # the set of non-lvm-based disk templates
142 DTS_NOT_LVM = frozenset([DT_DISKLESS, DT_FILE])
143
144 # logical disk types
145 LD_LV = "lvm"
146 LD_DRBD8 = "drbd8"
147 LD_FILE = "file"
148
149 # file backend driver
150 FD_LOOP = "loop"
151 FD_BLKTAP = "blktap"
152
153 # the set of drbd-like disk types
154 LDS_DRBD = frozenset([LD_DRBD8])
155
156 # disk replacement mode
157 REPLACE_DISK_PRI = "replace_primary"
158 REPLACE_DISK_SEC = "replace_secondary"
159 REPLACE_DISK_ALL = "replace_all"
160
161 # instance creation modes
162 INSTANCE_CREATE = "create"
163 INSTANCE_IMPORT = "import"
164
165 DISK_TEMPLATES = frozenset([DT_DISKLESS, DT_PLAIN,
166                             DT_DRBD8, DT_FILE])
167
168 FILE_DRIVER = frozenset([FD_LOOP, FD_BLKTAP])
169
170 # import/export config options
171 INISECT_EXP = "export"
172 INISECT_INS = "instance"
173
174 # common exit codes
175 EXIT_SUCCESS = 0
176 EXIT_FAILURE = 1
177 EXIT_NOTMASTER = 11
178 EXIT_NODESETUP_ERROR = 12
179 EXIT_CONFIRMATION = 13 # need user confirmation
180
181 # tags
182 TAG_CLUSTER = "cluster"
183 TAG_NODE = "node"
184 TAG_INSTANCE = "instance"
185 MAX_TAG_LEN = 128
186 MAX_TAGS_PER_OBJ = 4096
187
188 # others
189 DEFAULT_BRIDGE = "xen-br0"
190 SYNC_SPEED = 30 * 1024
191 LOCALHOST_IP_ADDRESS = "127.0.0.1"
192 TCP_PING_TIMEOUT = 10
193 GANETI_RUNAS = "root"
194 DEFAULT_VG = "xenvg"
195 BIND_ADDRESS_GLOBAL = "0.0.0.0"
196 MIN_VG_SIZE = 20480
197
198 # valid os status
199 OS_VALID_STATUS = "VALID"
200
201 # ssh constants
202 SSH_INITD_SCRIPT = _autoconf.SSH_INITD_SCRIPT
203 SSH_CONFIG_DIR = "/etc/ssh/"
204 SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "ssh_host_dsa_key"
205 SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
206 SSH_HOST_RSA_PRIV = SSH_CONFIG_DIR + "ssh_host_rsa_key"
207 SSH_HOST_RSA_PUB = SSH_HOST_RSA_PRIV + ".pub"
208 SSH = "ssh"
209 SCP = "scp"
210
211 # reboot types
212 INSTANCE_REBOOT_SOFT = "soft"
213 INSTANCE_REBOOT_HARD = "hard"
214 INSTANCE_REBOOT_FULL = "full"
215
216 # Hypervisor constants
217 HT_XEN_PVM30 = "xen-3.0"
218 HT_FAKE = "fake"
219 HT_XEN_HVM31 = "xen-hvm-3.1"
220 HYPER_TYPES = frozenset([HT_XEN_PVM30, HT_FAKE, HT_XEN_HVM31])
221 HTS_REQ_PORT = frozenset([HT_XEN_HVM31])
222
223 HT_HVM_VNC_BASE_PORT = 5900
224 HT_HVM_DEFAULT_BOOT_ORDER = 'dc'
225 VNC_PASSWORD_FILE = _autoconf.SYSCONFDIR + "/ganeti/vnc-cluster-password"
226 VNC_DEFAULT_BIND_ADDRESS = '0.0.0.0'
227
228 # Cluster Verify steps
229 VERIFY_NPLUSONE_MEM = 'nplusone_mem'
230 VERIFY_OPTIONAL_CHECKS = frozenset([VERIFY_NPLUSONE_MEM])
231
232 # Allocator framework constants
233 IALLOCATOR_DIR_IN = "in"
234 IALLOCATOR_DIR_OUT = "out"
235 IALLOCATOR_MODE_ALLOC = "allocate"
236 IALLOCATOR_MODE_RELOC = "relocate"
237 IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
238 IARUN_NOTFOUND = 1
239 IARUN_FAILURE = 2
240 IARUN_SUCCESS = 3