Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ 3636400f

History | View | Annotate | Download (26.9 kB)

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
import re
25

    
26
from ganeti import _autoconf
27

    
28
# various versions
29
PROTOCOL_VERSION = 40
30
RELEASE_VERSION = _autoconf.PACKAGE_VERSION
31
OS_API_V10 = 10
32
OS_API_V15 = 15
33
OS_API_V20 = 20
34
OS_API_VERSIONS = frozenset([OS_API_V10, OS_API_V15, OS_API_V20])
35
EXPORT_VERSION = 0
36
RAPI_VERSION = 2
37

    
38

    
39
# Format for CONFIG_VERSION:
40
#   01 03 0123 = 01030123
41
#   ^^ ^^ ^^^^
42
#   |  |  + Configuration version/revision
43
#   |  + Minor version
44
#   + Major version
45
#
46
# It stored as an integer. Make sure not to write an octal number.
47

    
48
# BuildVersion and SplitVersion must be in here because we can't import other
49
# modules. The cfgupgrade tool must be able to read and write version numbers
50
# and thus requires these functions. To avoid code duplication, they're kept in
51
# here.
52

    
53
def BuildVersion(major, minor, revision):
54
  """Calculates int version number from major, minor and revision numbers.
55

56
  Returns: int representing version number
57

58
  """
59
  assert isinstance(major, int)
60
  assert isinstance(minor, int)
61
  assert isinstance(revision, int)
62
  return (1000000 * major +
63
            10000 * minor +
64
                1 * revision)
65

    
66

    
67
def SplitVersion(version):
68
  """Splits version number stored in an int.
69

70
  Returns: tuple; (major, minor, revision)
71

72
  """
73
  assert isinstance(version, int)
74

    
75
  (major, remainder) = divmod(version, 1000000)
76
  (minor, revision) = divmod(remainder, 10000)
77

    
78
  return (major, minor, revision)
79

    
80

    
81
CONFIG_MAJOR = int(_autoconf.VERSION_MAJOR)
82
CONFIG_MINOR = int(_autoconf.VERSION_MINOR)
83
CONFIG_REVISION = 0
84
CONFIG_VERSION = BuildVersion(CONFIG_MAJOR, CONFIG_MINOR, CONFIG_REVISION)
85

    
86
# user separation
87
DAEMONS_GROUP = _autoconf.DAEMONS_GROUP
88
MASTERD_USER = _autoconf.MASTERD_USER
89
RAPI_USER = _autoconf.RAPI_USER
90

    
91
# file paths
92
DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti"
93
RUN_DIR = _autoconf.LOCALSTATEDIR + "/run"
94
RUN_GANETI_DIR = RUN_DIR + "/ganeti"
95
BDEV_CACHE_DIR = RUN_GANETI_DIR + "/bdev-cache"
96
DISK_LINKS_DIR = RUN_GANETI_DIR + "/instance-disks"
97
RUN_DIRS_MODE = 0775
98
SOCKET_DIR = RUN_GANETI_DIR + "/socket"
99
SECURE_DIR_MODE = 0700
100
SOCKET_DIR_MODE = 0750
101
CRYPTO_KEYS_DIR = RUN_GANETI_DIR + "/crypto"
102
CRYPTO_KEYS_DIR_MODE = SECURE_DIR_MODE
103
IMPORT_EXPORT_DIR = RUN_GANETI_DIR + "/import-export"
104
IMPORT_EXPORT_DIR_MODE = 0755
105
# keep RUN_GANETI_DIR first here, to make sure all get created when the node
106
# daemon is started (this takes care of RUN_DIR being tmpfs)
107
SUB_RUN_DIRS = [ RUN_GANETI_DIR, BDEV_CACHE_DIR, DISK_LINKS_DIR ]
108
LOCK_DIR = _autoconf.LOCALSTATEDIR + "/lock"
109
SSCONF_LOCK_FILE = LOCK_DIR + "/ganeti-ssconf.lock"
110
# User-id pool lock directory
111
# The user-ids that are in use have a corresponding lock file in this directory
112
UIDPOOL_LOCKDIR = RUN_GANETI_DIR + "/uid-pool"
113
CLUSTER_CONF_FILE = DATA_DIR + "/config.data"
114
NODED_CERT_FILE = DATA_DIR + "/server.pem"
115
RAPI_CERT_FILE = DATA_DIR + "/rapi.pem"
116
CONFD_HMAC_KEY = DATA_DIR + "/hmac.key"
117
CLUSTER_DOMAIN_SECRET_FILE = DATA_DIR + "/cluster-domain-secret"
118
WATCHER_STATEFILE = DATA_DIR + "/watcher.data"
119
WATCHER_PAUSEFILE = DATA_DIR + "/watcher.pause"
120
INSTANCE_UPFILE = RUN_GANETI_DIR + "/instance-status"
121
SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
122
RAPI_USERS_FILE = DATA_DIR + "/rapi_users"
123
QUEUE_DIR = DATA_DIR + "/queue"
124
DAEMON_UTIL = _autoconf.PKGLIBDIR + "/daemon-util"
125
ETC_HOSTS = "/etc/hosts"
126
DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
127
ENABLE_FILE_STORAGE = _autoconf.ENABLE_FILE_STORAGE
128
SYSCONFDIR = _autoconf.SYSCONFDIR
129
TOOLSDIR = _autoconf.TOOLSDIR
130
CONF_DIR = SYSCONFDIR + "/ganeti"
131

    
132
ALL_CERT_FILES = frozenset([NODED_CERT_FILE, RAPI_CERT_FILE])
133

    
134
MASTER_SOCKET = SOCKET_DIR + "/ganeti-master"
135

    
136
NODED = "ganeti-noded"
137
CONFD = "ganeti-confd"
138
RAPI = "ganeti-rapi"
139
MASTERD = "ganeti-masterd"
140
# used in the ganeti-nbma project
141
NLD = "ganeti-nld"
142

    
143
DAEMONS_PORTS = {
144
  # daemon-name: ("proto", "default-port")
145
  NODED: ("tcp", 1811),
146
  CONFD: ("udp", 1814),
147
  RAPI: ("tcp", 5080),
148
  # used in the ganeti-nbma project
149
  NLD: ("udp", 1816),
150
}
151
DEFAULT_NODED_PORT = DAEMONS_PORTS[NODED][1]
152
DEFAULT_CONFD_PORT = DAEMONS_PORTS[CONFD][1]
153
DEFAULT_RAPI_PORT = DAEMONS_PORTS[RAPI][1]
154
# used in the ganeti-nbma project
155
DEFAULT_NLD_PORT = DAEMONS_PORTS[NLD][1]
156

    
157
FIRST_DRBD_PORT = 11000
158
LAST_DRBD_PORT = 14999
159
MASTER_SCRIPT = "ganeti-master"
160

    
161
LOG_DIR = _autoconf.LOCALSTATEDIR + "/log/ganeti/"
162
DAEMONS_LOGFILES = {
163
  # "daemon-name": "logfile"
164
  NODED: LOG_DIR + "node-daemon.log",
165
  CONFD: LOG_DIR + "conf-daemon.log",
166
  RAPI: LOG_DIR + "rapi-daemon.log",
167
  MASTERD: LOG_DIR + "master-daemon.log",
168
  # used in the ganeti-nbma project
169
  NLD: LOG_DIR + "nl-daemon.log",
170
  }
171

    
172
LOG_OS_DIR = LOG_DIR + "os"
173
LOG_WATCHER = LOG_DIR + "watcher.log"
174
LOG_COMMANDS = LOG_DIR + "commands.log"
175
LOG_BURNIN = LOG_DIR + "burnin.log"
176

    
177
DEV_CONSOLE = "/dev/console"
178

    
179
# luxi related constants
180
LUXI_EOM = "\3"
181

    
182
# one of 'no', 'yes', 'only'
183
SYSLOG_USAGE = _autoconf.SYSLOG_USAGE
184
SYSLOG_NO = "no"
185
SYSLOG_YES = "yes"
186
SYSLOG_ONLY = "only"
187
SYSLOG_SOCKET = "/dev/log"
188

    
189
OS_SEARCH_PATH = _autoconf.OS_SEARCH_PATH
190
EXPORT_DIR = _autoconf.EXPORT_DIR
191

    
192
EXPORT_CONF_FILE = "config.ini"
193

    
194
XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER
195
XEN_KERNEL = _autoconf.XEN_KERNEL
196
XEN_INITRD = _autoconf.XEN_INITRD
197

    
198
KVM_PATH = _autoconf.KVM_PATH
199
SOCAT_PATH = _autoconf.SOCAT_PATH
200
SOCAT_USE_ESCAPE = _autoconf.SOCAT_USE_ESCAPE
201
SOCAT_ESCAPE_CODE = "0x1d"
202

    
203
# For RSA keys more bits are better, but they also make operations more
204
# expensive. NIST SP 800-131 recommends a minimum of 2048 bits from the year
205
# 2010 on.
206
RSA_KEY_BITS = 2048
207

    
208
# Ciphers allowed for SSL connections. For the format, see ciphers(1). A better
209
# way to disable ciphers would be to use the exclamation mark (!), but socat
210
# versions below 1.5 can't parse exclamation marks in options properly. When
211
# modifying the ciphers, ensure to not accidentially add something after it's
212
# been removed. Use the "openssl" utility to check the allowed ciphers, e.g.
213
# "openssl ciphers -v HIGH:-DES".
214
OPENSSL_CIPHERS = "HIGH:-DES:-3DES:-EXPORT:-ADH"
215

    
216
# Digest used to sign certificates ("openssl x509" uses SHA1 by default)
217
X509_CERT_SIGN_DIGEST = "SHA1"
218

    
219
X509_CERT_SIGNATURE_HEADER = "X-Ganeti-Signature"
220

    
221
IMPORT_EXPORT_DAEMON = _autoconf.PKGLIBDIR + "/import-export"
222

    
223
# Import/export daemon mode
224
IEM_IMPORT = "import"
225
IEM_EXPORT = "export"
226

    
227
# Import/export transport compression
228
IEC_NONE = "none"
229
IEC_GZIP = "gzip"
230
IEC_ALL = frozenset([
231
  IEC_NONE,
232
  IEC_GZIP,
233
  ])
234

    
235
IE_CUSTOM_SIZE = "fd"
236

    
237
IE_MAGIC_RE = re.compile(r"^[-_.a-zA-Z0-9]{5,100}$")
238

    
239
# Import/export I/O
240
# Direct file I/O, equivalent to a shell's I/O redirection using '<' or '>'
241
IEIO_FILE = "file"
242
# Raw block device I/O using "dd"
243
IEIO_RAW_DISK = "raw"
244
# OS definition import/export script
245
IEIO_SCRIPT = "script"
246

    
247
VALUE_DEFAULT = "default"
248
VALUE_AUTO = "auto"
249
VALUE_GENERATE = "generate"
250
VALUE_NONE = "none"
251
VALUE_TRUE = "true"
252
VALUE_FALSE = "false"
253

    
254
# External script validation mask
255
EXT_PLUGIN_MASK = re.compile("^[a-zA-Z0-9_-]+$")
256

    
257
# hooks-related constants
258
HOOKS_BASE_DIR = CONF_DIR + "/hooks"
259
HOOKS_PHASE_PRE = "pre"
260
HOOKS_PHASE_POST = "post"
261
HOOKS_NAME_CFGUPDATE = "config-update"
262
HOOKS_NAME_WATCHER = "watcher"
263
HOOKS_VERSION = 2
264

    
265
# hooks subject type (what object type does the LU deal with)
266
HTYPE_CLUSTER = "CLUSTER"
267
HTYPE_NODE = "NODE"
268
HTYPE_INSTANCE = "INSTANCE"
269

    
270
HKR_SKIP = 0
271
HKR_FAIL = 1
272
HKR_SUCCESS = 2
273

    
274
# Storage types
275
ST_FILE = "file"
276
ST_LVM_PV = "lvm-pv"
277
ST_LVM_VG = "lvm-vg"
278

    
279
# Storage fields
280
# first two are valid in LU context only, not passed to backend
281
SF_NODE = "node"
282
SF_TYPE = "type"
283
# and the rest are valid in backend
284
SF_NAME = "name"
285
SF_SIZE = "size"
286
SF_FREE = "free"
287
SF_USED = "used"
288
SF_ALLOCATABLE = "allocatable"
289

    
290
# Storage operations
291
SO_FIX_CONSISTENCY = "fix-consistency"
292

    
293
# Available fields per storage type
294
VALID_STORAGE_FIELDS = frozenset([SF_NAME, SF_TYPE, SF_SIZE,
295
                                  SF_USED, SF_FREE, SF_ALLOCATABLE])
296

    
297
VALID_STORAGE_TYPES = frozenset([ST_FILE, ST_LVM_PV, ST_LVM_VG])
298

    
299
MODIFIABLE_STORAGE_FIELDS = {
300
  ST_LVM_PV: frozenset([SF_ALLOCATABLE]),
301
  }
302

    
303
VALID_STORAGE_OPERATIONS = {
304
  ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
305
  }
306

    
307
# Local disk status
308
# Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
309
(LDS_OKAY,
310
 LDS_UNKNOWN,
311
 LDS_FAULTY) = range(1, 4)
312

    
313
# disk template types
314
DT_DISKLESS = "diskless"
315
DT_PLAIN = "plain"
316
DT_DRBD8 = "drbd"
317
DT_FILE = "file"
318

    
319
# the set of network-mirrored disk templates
320
DTS_NET_MIRROR = frozenset([DT_DRBD8])
321

    
322
# the set of non-lvm-based disk templates
323
DTS_NOT_LVM = frozenset([DT_DISKLESS, DT_FILE])
324

    
325
# the set of disk templates which can be grown
326
DTS_GROWABLE = frozenset([DT_PLAIN, DT_DRBD8, DT_FILE])
327

    
328
# logical disk types
329
LD_LV = "lvm"
330
LD_DRBD8 = "drbd8"
331
LD_FILE = "file"
332
LDS_BLOCK = frozenset([LD_LV, LD_DRBD8])
333

    
334
# drbd constants
335
DRBD_HMAC_ALG = "md5"
336
DRBD_NET_PROTOCOL = "C"
337
DRBD_BARRIERS = _autoconf.DRBD_BARRIERS
338

    
339
# file backend driver
340
FD_LOOP = "loop"
341
FD_BLKTAP = "blktap"
342

    
343
# the set of drbd-like disk types
344
LDS_DRBD = frozenset([LD_DRBD8])
345

    
346
# disk access mode
347
DISK_RDONLY = "ro"
348
DISK_RDWR = "rw"
349
DISK_ACCESS_SET = frozenset([DISK_RDONLY, DISK_RDWR])
350

    
351
# disk replacement mode
352
REPLACE_DISK_PRI = "replace_on_primary"    # replace disks on primary
353
REPLACE_DISK_SEC = "replace_on_secondary"  # replace disks on secondary
354
REPLACE_DISK_CHG = "replace_new_secondary" # change secondary node
355
REPLACE_DISK_AUTO = "replace_auto"
356
REPLACE_MODES = frozenset([
357
  REPLACE_DISK_PRI,
358
  REPLACE_DISK_SEC,
359
  REPLACE_DISK_CHG,
360
  REPLACE_DISK_AUTO,
361
  ])
362

    
363
# Instance export mode
364
EXPORT_MODE_LOCAL = "local"
365
EXPORT_MODE_REMOTE = "remote"
366
EXPORT_MODES = frozenset([
367
  EXPORT_MODE_LOCAL,
368
  EXPORT_MODE_REMOTE,
369
  ])
370

    
371
# lock recalculate mode
372
LOCKS_REPLACE = 'replace'
373
LOCKS_APPEND = 'append'
374

    
375
# instance creation modes
376
INSTANCE_CREATE = "create"
377
INSTANCE_IMPORT = "import"
378
INSTANCE_REMOTE_IMPORT = "remote-import"
379
INSTANCE_CREATE_MODES = frozenset([
380
  INSTANCE_CREATE,
381
  INSTANCE_IMPORT,
382
  INSTANCE_REMOTE_IMPORT,
383
  ])
384

    
385
# Remote import/export handshake message and version
386
RIE_VERSION = 0
387
RIE_HANDSHAKE = "Hi, I'm Ganeti"
388

    
389
# Remote import/export certificate validity in seconds
390
RIE_CERT_VALIDITY = 24 * 60 * 60
391

    
392
# Remote import/export connect timeout for socat
393
RIE_CONNECT_TIMEOUT = 60
394

    
395
DISK_TEMPLATES = frozenset([DT_DISKLESS, DT_PLAIN,
396
                            DT_DRBD8, DT_FILE])
397

    
398
FILE_DRIVER = frozenset([FD_LOOP, FD_BLKTAP])
399

    
400
# import/export config options
401
INISECT_EXP = "export"
402
INISECT_INS = "instance"
403
INISECT_HYP = "hypervisor"
404
INISECT_BEP = "backend"
405
INISECT_OSP = "os"
406

    
407
# dynamic device modification
408
DDM_ADD = 'add'
409
DDM_REMOVE = 'remove'
410

    
411
# common exit codes
412
EXIT_SUCCESS = 0
413
EXIT_FAILURE = 1
414
EXIT_NOTCLUSTER = 5
415
EXIT_NOTMASTER = 11
416
EXIT_NODESETUP_ERROR = 12
417
EXIT_CONFIRMATION = 13 # need user confirmation
418

    
419
# tags
420
TAG_CLUSTER = "cluster"
421
TAG_NODE = "node"
422
TAG_INSTANCE = "instance"
423
VALID_TAG_TYPES = frozenset([
424
  TAG_CLUSTER,
425
  TAG_NODE,
426
  TAG_INSTANCE,
427
  ])
428
MAX_TAG_LEN = 128
429
MAX_TAGS_PER_OBJ = 4096
430

    
431
# others
432
DEFAULT_BRIDGE = "xen-br0"
433
SYNC_SPEED = 60 * 1024
434
LOCALHOST_IP_ADDRESS = "127.0.0.1"
435
TCP_PING_TIMEOUT = 10
436
GANETI_RUNAS = "root"
437
DEFAULT_VG = "xenvg"
438
BIND_ADDRESS_GLOBAL = "0.0.0.0"
439
MIN_VG_SIZE = 20480
440
DEFAULT_MAC_PREFIX = "aa:00:00"
441
LVM_STRIPECOUNT = _autoconf.LVM_STRIPECOUNT
442
# default maximum instance wait time, in seconds.
443
DEFAULT_SHUTDOWN_TIMEOUT = 120
444
NODE_MAX_CLOCK_SKEW = 150
445
# Time for an intra-cluster disk transfer to wait for a connection
446
DISK_TRANSFER_CONNECT_TIMEOUT = 30
447

    
448
# runparts results
449
(RUNPARTS_SKIP,
450
 RUNPARTS_RUN,
451
 RUNPARTS_ERR) = range(3)
452

    
453
RUNPARTS_STATUS = frozenset([RUNPARTS_SKIP, RUNPARTS_RUN, RUNPARTS_ERR])
454

    
455
# RPC constants
456
(RPC_ENCODING_NONE,
457
 RPC_ENCODING_ZLIB_BASE64) = range(2)
458

    
459
# os related constants
460
OS_SCRIPT_CREATE = 'create'
461
OS_SCRIPT_IMPORT = 'import'
462
OS_SCRIPT_EXPORT = 'export'
463
OS_SCRIPT_RENAME = 'rename'
464
OS_SCRIPT_VERIFY = 'verify'
465
OS_SCRIPTS = frozenset([OS_SCRIPT_CREATE, OS_SCRIPT_IMPORT,
466
                        OS_SCRIPT_EXPORT, OS_SCRIPT_RENAME,
467
                        OS_SCRIPT_VERIFY])
468

    
469
OS_API_FILE = 'ganeti_api_version'
470
OS_VARIANTS_FILE = 'variants.list'
471
OS_PARAMETERS_FILE = 'parameters.list'
472

    
473
OS_VALIDATE_PARAMETERS = 'parameters'
474
OS_VALIDATE_CALLS = frozenset([OS_VALIDATE_PARAMETERS])
475

    
476
# ssh constants
477
SSH_CONFIG_DIR = _autoconf.SSH_CONFIG_DIR
478
SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_dsa_key"
479
SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
480
SSH_HOST_RSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_rsa_key"
481
SSH_HOST_RSA_PUB = SSH_HOST_RSA_PRIV + ".pub"
482
SSH = "ssh"
483
SCP = "scp"
484

    
485
# reboot types
486
INSTANCE_REBOOT_SOFT = "soft"
487
INSTANCE_REBOOT_HARD = "hard"
488
INSTANCE_REBOOT_FULL = "full"
489

    
490
REBOOT_TYPES = frozenset([INSTANCE_REBOOT_SOFT,
491
                          INSTANCE_REBOOT_HARD,
492
                          INSTANCE_REBOOT_FULL])
493

    
494
VTYPE_STRING = 'string'
495
VTYPE_BOOL = 'bool'
496
VTYPE_SIZE = 'size' # size, in MiBs
497
VTYPE_INT = 'int'
498
ENFORCEABLE_TYPES = frozenset([
499
                      VTYPE_STRING,
500
                      VTYPE_BOOL,
501
                      VTYPE_SIZE,
502
                      VTYPE_INT,
503
                      ])
504

    
505
# HV parameter names (global namespace)
506
HV_BOOT_ORDER = "boot_order"
507
HV_CDROM_IMAGE_PATH = "cdrom_image_path"
508
HV_NIC_TYPE = "nic_type"
509
HV_DISK_TYPE = "disk_type"
510
HV_VNC_BIND_ADDRESS = "vnc_bind_address"
511
HV_VNC_PASSWORD_FILE = "vnc_password_file"
512
HV_VNC_TLS = "vnc_tls"
513
HV_VNC_X509 = "vnc_x509_path"
514
HV_VNC_X509_VERIFY = "vnc_x509_verify"
515
HV_ACPI = "acpi"
516
HV_PAE = "pae"
517
HV_USE_BOOTLOADER = "use_bootloader"
518
HV_BOOTLOADER_ARGS = "bootloader_args"
519
HV_BOOTLOADER_PATH = "bootloader_path"
520
HV_KERNEL_ARGS = "kernel_args"
521
HV_KERNEL_PATH = "kernel_path"
522
HV_INITRD_PATH = "initrd_path"
523
HV_ROOT_PATH = "root_path"
524
HV_SERIAL_CONSOLE = "serial_console"
525
HV_USB_MOUSE = "usb_mouse"
526
HV_DEVICE_MODEL = "device_model"
527
HV_INIT_SCRIPT = "init_script"
528
HV_MIGRATION_PORT = "migration_port"
529
HV_MIGRATION_BANDWIDTH = "migration_bandwidth"
530
HV_MIGRATION_DOWNTIME = "migration_downtime"
531
HV_USE_LOCALTIME = "use_localtime"
532
HV_DISK_CACHE = "disk_cache"
533
HV_SECURITY_MODEL = "security_model"
534
HV_SECURITY_DOMAIN = "security_domain"
535
HV_KVM_FLAG = "kvm_flag"
536
HV_VHOST_NET = "vhost_net"
537
HV_KVM_USE_CHROOT = "use_chroot"
538

    
539
HVS_PARAMETER_TYPES = {
540
  HV_BOOT_ORDER: VTYPE_STRING,
541
  HV_CDROM_IMAGE_PATH: VTYPE_STRING,
542
  HV_NIC_TYPE: VTYPE_STRING,
543
  HV_DISK_TYPE: VTYPE_STRING,
544
  HV_VNC_PASSWORD_FILE: VTYPE_STRING,
545
  HV_VNC_BIND_ADDRESS: VTYPE_STRING,
546
  HV_VNC_TLS: VTYPE_BOOL,
547
  HV_VNC_X509: VTYPE_STRING,
548
  HV_VNC_X509_VERIFY: VTYPE_BOOL,
549
  HV_ACPI: VTYPE_BOOL,
550
  HV_PAE: VTYPE_BOOL,
551
  HV_USE_BOOTLOADER: VTYPE_BOOL,
552
  HV_BOOTLOADER_PATH: VTYPE_STRING,
553
  HV_BOOTLOADER_ARGS: VTYPE_STRING,
554
  HV_KERNEL_PATH: VTYPE_STRING,
555
  HV_KERNEL_ARGS: VTYPE_STRING,
556
  HV_INITRD_PATH: VTYPE_STRING,
557
  HV_ROOT_PATH: VTYPE_STRING,
558
  HV_SERIAL_CONSOLE: VTYPE_BOOL,
559
  HV_USB_MOUSE: VTYPE_STRING,
560
  HV_DEVICE_MODEL: VTYPE_STRING,
561
  HV_INIT_SCRIPT: VTYPE_STRING,
562
  HV_MIGRATION_PORT: VTYPE_INT,
563
  HV_MIGRATION_BANDWIDTH: VTYPE_INT,
564
  HV_MIGRATION_DOWNTIME: VTYPE_INT,
565
  HV_USE_LOCALTIME: VTYPE_BOOL,
566
  HV_DISK_CACHE: VTYPE_STRING,
567
  HV_SECURITY_MODEL: VTYPE_STRING,
568
  HV_SECURITY_DOMAIN: VTYPE_STRING,
569
  HV_KVM_FLAG: VTYPE_STRING,
570
  HV_VHOST_NET: VTYPE_BOOL,
571
  HV_KVM_USE_CHROOT: VTYPE_BOOL,
572
  }
573

    
574
HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
575

    
576
# BE parameter names
577
BE_MEMORY = "memory"
578
BE_VCPUS = "vcpus"
579
BE_AUTO_BALANCE = "auto_balance"
580

    
581
BES_PARAMETER_TYPES = {
582
    BE_MEMORY: VTYPE_SIZE,
583
    BE_VCPUS: VTYPE_INT,
584
    BE_AUTO_BALANCE: VTYPE_BOOL,
585
    }
586

    
587
BES_PARAMETERS = frozenset(BES_PARAMETER_TYPES.keys())
588

    
589
# Instance Parameters Profile
590
PP_DEFAULT = "default"
591

    
592
NIC_MODE = "mode"
593
NIC_LINK = "link"
594

    
595
NIC_MODE_BRIDGED = "bridged"
596
NIC_MODE_ROUTED = "routed"
597

    
598
NIC_VALID_MODES = frozenset([NIC_MODE_BRIDGED, NIC_MODE_ROUTED])
599

    
600
NICS_PARAMETER_TYPES = {
601
    NIC_MODE: VTYPE_STRING,
602
    NIC_LINK: VTYPE_STRING,
603
    }
604

    
605
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
606

    
607
IDISK_SIZE = "size"
608
IDISK_MODE = "mode"
609
IDISK_ADOPT = "adopt"
610
IDISK_PARAMS = frozenset([IDISK_SIZE, IDISK_MODE, IDISK_ADOPT])
611
IDISK_PARAMS_TYPES = {
612
  IDISK_SIZE: VTYPE_SIZE,
613
  IDISK_MODE: VTYPE_STRING,
614
  IDISK_ADOPT: VTYPE_STRING,
615
  }
616
INIC_MAC = "mac"
617
INIC_IP = "ip"
618
INIC_MODE = "mode"
619
INIC_LINK = "link"
620
INIC_BRIDGE = "bridge"
621
INIC_PARAMS = frozenset([INIC_MAC, INIC_IP, INIC_MODE, INIC_LINK, INIC_BRIDGE])
622
INIC_PARAMS_TYPES = dict([(name, VTYPE_STRING) for name in INIC_PARAMS])
623

    
624
# Hypervisor constants
625
HT_XEN_PVM = "xen-pvm"
626
HT_FAKE = "fake"
627
HT_XEN_HVM = "xen-hvm"
628
HT_KVM = "kvm"
629
HT_CHROOT = "chroot"
630
HYPER_TYPES = frozenset([HT_XEN_PVM, HT_FAKE, HT_XEN_HVM, HT_KVM, HT_CHROOT])
631
HTS_REQ_PORT = frozenset([HT_XEN_HVM, HT_KVM])
632

    
633
VNC_BASE_PORT = 5900
634
VNC_PASSWORD_FILE = CONF_DIR + "/vnc-cluster-password"
635
VNC_DEFAULT_BIND_ADDRESS = '0.0.0.0'
636

    
637
# NIC types
638
HT_NIC_RTL8139 = "rtl8139"
639
HT_NIC_NE2K_PCI = "ne2k_pci"
640
HT_NIC_NE2K_ISA = "ne2k_isa"
641
HT_NIC_I82551 = "i82551"
642
HT_NIC_I85557B = "i82557b"
643
HT_NIC_I8259ER = "i82559er"
644
HT_NIC_PCNET = "pcnet"
645
HT_NIC_E1000 = "e1000"
646
HT_NIC_PARAVIRTUAL = HT_DISK_PARAVIRTUAL = "paravirtual"
647

    
648
HT_HVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
649
                                    HT_NIC_NE2K_ISA, HT_NIC_PARAVIRTUAL])
650
HT_KVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
651
                                    HT_NIC_NE2K_ISA, HT_NIC_I82551,
652
                                    HT_NIC_I85557B, HT_NIC_I8259ER,
653
                                    HT_NIC_PCNET, HT_NIC_E1000,
654
                                    HT_NIC_PARAVIRTUAL])
655
# Disk types
656
HT_DISK_IOEMU = "ioemu"
657
HT_DISK_IDE = "ide"
658
HT_DISK_SCSI = "scsi"
659
HT_DISK_SD = "sd"
660
HT_DISK_MTD = "mtd"
661
HT_DISK_PFLASH = "pflash"
662

    
663
HT_CACHE_DEFAULT = "default"
664
HT_CACHE_NONE = "none"
665
HT_CACHE_WTHROUGH = "writethrough"
666
HT_CACHE_WBACK = "writeback"
667
HT_VALID_CACHE_TYPES = frozenset([HT_CACHE_DEFAULT,
668
                                  HT_CACHE_NONE,
669
                                  HT_CACHE_WTHROUGH,
670
                                  HT_CACHE_WBACK])
671

    
672
HT_HVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IOEMU])
673
HT_KVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IDE,
674
                                     HT_DISK_SCSI, HT_DISK_SD, HT_DISK_MTD,
675
                                     HT_DISK_PFLASH])
676

    
677
# Mouse types:
678
HT_MOUSE_MOUSE = "mouse"
679
HT_MOUSE_TABLET = "tablet"
680

    
681
HT_KVM_VALID_MOUSE_TYPES = frozenset([HT_MOUSE_MOUSE, HT_MOUSE_TABLET])
682

    
683
# Boot order
684
HT_BO_CDROM = "cdrom"
685
HT_BO_DISK = "disk"
686
HT_BO_NETWORK = "network"
687

    
688
HT_KVM_VALID_BO_TYPES = frozenset([HT_BO_CDROM, HT_BO_DISK, HT_BO_NETWORK])
689

    
690
# Security models
691
HT_SM_NONE = "none"
692
HT_SM_USER = "user"
693
HT_SM_POOL = "pool"
694

    
695
HT_KVM_VALID_SM_TYPES = frozenset([HT_SM_NONE, HT_SM_USER, HT_SM_POOL])
696

    
697
# Kvm flag values
698
HT_KVM_ENABLED = "enabled"
699
HT_KVM_DISABLED = "disabled"
700

    
701
HT_KVM_FLAG_VALUES = frozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
702

    
703
# Cluster Verify steps
704
VERIFY_NPLUSONE_MEM = 'nplusone_mem'
705
VERIFY_OPTIONAL_CHECKS = frozenset([VERIFY_NPLUSONE_MEM])
706

    
707
# Node verify constants
708
NV_DRBDLIST = "drbd-list"
709
NV_FILELIST = "filelist"
710
NV_HVINFO = "hvinfo"
711
NV_HYPERVISOR = "hypervisor"
712
NV_INSTANCELIST = "instancelist"
713
NV_LVLIST = "lvlist"
714
NV_MASTERIP = "master-ip"
715
NV_NODELIST = "nodelist"
716
NV_NODENETTEST = "node-net-test"
717
NV_NODESETUP = "nodesetup"
718
NV_OSLIST = "oslist"
719
NV_PVLIST = "pvlist"
720
NV_TIME = "time"
721
NV_VERSION = "version"
722
NV_VGLIST = "vglist"
723

    
724
# SSL certificate check constants (in days)
725
SSL_CERT_EXPIRATION_WARN = 30
726
SSL_CERT_EXPIRATION_ERROR = 7
727

    
728
# Allocator framework constants
729
IALLOCATOR_VERSION = 2
730
IALLOCATOR_DIR_IN = "in"
731
IALLOCATOR_DIR_OUT = "out"
732
VALID_IALLOCATOR_DIRECTIONS = frozenset([
733
  IALLOCATOR_DIR_IN,
734
  IALLOCATOR_DIR_OUT,
735
  ])
736
IALLOCATOR_MODE_ALLOC = "allocate"
737
IALLOCATOR_MODE_RELOC = "relocate"
738
IALLOCATOR_MODE_MEVAC = "multi-evacuate"
739
VALID_IALLOCATOR_MODES = frozenset([
740
  IALLOCATOR_MODE_ALLOC,
741
  IALLOCATOR_MODE_RELOC,
742
  IALLOCATOR_MODE_MEVAC,
743
  ])
744
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
745

    
746
# Job queue
747
JOB_QUEUE_VERSION = 1
748
JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock"
749
JOB_QUEUE_VERSION_FILE = QUEUE_DIR + "/version"
750
JOB_QUEUE_SERIAL_FILE = QUEUE_DIR + "/serial"
751
JOB_QUEUE_ARCHIVE_DIR = QUEUE_DIR + "/archive"
752
JOB_QUEUE_DRAIN_FILE = QUEUE_DIR + "/drain"
753
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
754
JOB_QUEUE_DIRS = [QUEUE_DIR, JOB_QUEUE_ARCHIVE_DIR]
755
JOB_QUEUE_DIRS_MODE = SECURE_DIR_MODE
756

    
757
JOB_ID_TEMPLATE = r"\d+"
758

    
759
# unchanged job return
760
JOB_NOTCHANGED = "nochange"
761

    
762
# Job status
763
JOB_STATUS_QUEUED = "queued"
764
JOB_STATUS_WAITLOCK = "waiting"
765
JOB_STATUS_CANCELING = "canceling"
766
JOB_STATUS_RUNNING = "running"
767
JOB_STATUS_CANCELED = "canceled"
768
JOB_STATUS_SUCCESS = "success"
769
JOB_STATUS_ERROR = "error"
770

    
771
# OpCode status
772
# not yet finalized
773
OP_STATUS_QUEUED = "queued"
774
OP_STATUS_WAITLOCK = "waiting"
775
OP_STATUS_CANCELING = "canceling"
776
OP_STATUS_RUNNING = "running"
777
# finalized
778
OP_STATUS_CANCELED = "canceled"
779
OP_STATUS_SUCCESS = "success"
780
OP_STATUS_ERROR = "error"
781
OPS_FINALIZED = frozenset([OP_STATUS_CANCELED,
782
                           OP_STATUS_SUCCESS,
783
                           OP_STATUS_ERROR])
784

    
785
# Execution log types
786
ELOG_MESSAGE = "message"
787
ELOG_PROGRESS = "progress"
788
ELOG_REMOTE_IMPORT = "remote-import"
789

    
790
# max dynamic devices
791
MAX_NICS = 8
792
MAX_DISKS = 16
793

    
794
# SSCONF keys
795
SS_CLUSTER_NAME = "cluster_name"
796
SS_CLUSTER_TAGS = "cluster_tags"
797
SS_FILE_STORAGE_DIR = "file_storage_dir"
798
SS_MASTER_CANDIDATES = "master_candidates"
799
SS_MASTER_CANDIDATES_IPS = "master_candidates_ips"
800
SS_MASTER_IP = "master_ip"
801
SS_MASTER_NETDEV = "master_netdev"
802
SS_MASTER_NODE = "master_node"
803
SS_NODE_LIST = "node_list"
804
SS_NODE_PRIMARY_IPS = "node_primary_ips"
805
SS_NODE_SECONDARY_IPS = "node_secondary_ips"
806
SS_OFFLINE_NODES = "offline_nodes"
807
SS_ONLINE_NODES = "online_nodes"
808
SS_INSTANCE_LIST = "instance_list"
809
SS_RELEASE_VERSION = "release_version"
810
SS_HYPERVISOR_LIST = "hypervisor_list"
811
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
812
SS_UID_POOL = "uid_pool"
813

    
814
# cluster wide default parameters
815
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
816

    
817
HVC_DEFAULTS = {
818
  HT_XEN_PVM: {
819
    HV_USE_BOOTLOADER: False,
820
    HV_BOOTLOADER_PATH: XEN_BOOTLOADER,
821
    HV_BOOTLOADER_ARGS: '',
822
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-xenU",
823
    HV_INITRD_PATH: '',
824
    HV_ROOT_PATH: '/dev/sda1',
825
    HV_KERNEL_ARGS: 'ro',
826
    HV_MIGRATION_PORT: 8002,
827
    },
828
  HT_XEN_HVM: {
829
    HV_BOOT_ORDER: "cd",
830
    HV_CDROM_IMAGE_PATH: '',
831
    HV_NIC_TYPE: HT_NIC_RTL8139,
832
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
833
    HV_VNC_BIND_ADDRESS: '0.0.0.0',
834
    HV_VNC_PASSWORD_FILE: VNC_PASSWORD_FILE,
835
    HV_ACPI: True,
836
    HV_PAE: True,
837
    HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
838
    HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
839
    HV_MIGRATION_PORT: 8002,
840
    HV_USE_LOCALTIME: False,
841
    },
842
  HT_KVM: {
843
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
844
    HV_INITRD_PATH: '',
845
    HV_KERNEL_ARGS: 'ro',
846
    HV_ROOT_PATH: '/dev/vda1',
847
    HV_ACPI: True,
848
    HV_SERIAL_CONSOLE: True,
849
    HV_VNC_BIND_ADDRESS: '',
850
    HV_VNC_TLS: False,
851
    HV_VNC_X509: '',
852
    HV_VNC_X509_VERIFY: False,
853
    HV_VNC_PASSWORD_FILE: '',
854
    HV_CDROM_IMAGE_PATH: '',
855
    HV_BOOT_ORDER: HT_BO_DISK,
856
    HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
857
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
858
    HV_USB_MOUSE: '',
859
    HV_MIGRATION_PORT: 8102,
860
    HV_MIGRATION_BANDWIDTH: 32, # MiB/s
861
    HV_MIGRATION_DOWNTIME: 30,  # ms
862
    HV_USE_LOCALTIME: False,
863
    HV_DISK_CACHE: HT_CACHE_DEFAULT,
864
    HV_SECURITY_MODEL: HT_SM_NONE,
865
    HV_SECURITY_DOMAIN: '',
866
    HV_KVM_FLAG: "",
867
    HV_VHOST_NET: False,
868
    HV_KVM_USE_CHROOT: False,
869
    },
870
  HT_FAKE: {
871
    },
872
  HT_CHROOT: {
873
    HV_INIT_SCRIPT: "/ganeti-chroot",
874
    },
875
  }
876

    
877
HVC_GLOBALS = frozenset([
878
  HV_MIGRATION_PORT,
879
  HV_MIGRATION_BANDWIDTH,
880
  ])
881

    
882
BEC_DEFAULTS = {
883
  BE_MEMORY: 128,
884
  BE_VCPUS: 1,
885
  BE_AUTO_BALANCE: True,
886
  }
887

    
888
NICC_DEFAULTS = {
889
  NIC_MODE: NIC_MODE_BRIDGED,
890
  NIC_LINK: DEFAULT_BRIDGE,
891
  }
892

    
893
MASTER_POOL_SIZE_DEFAULT = 10
894

    
895
CONFD_PROTOCOL_VERSION = 1
896

    
897
CONFD_REQ_PING = 0
898
CONFD_REQ_NODE_ROLE_BYNAME = 1
899
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
900
CONFD_REQ_CLUSTER_MASTER = 3
901
CONFD_REQ_NODE_PIP_LIST = 4
902
CONFD_REQ_MC_PIP_LIST = 5
903
CONFD_REQ_INSTANCES_IPS_LIST = 6
904

    
905
# Confd request query fields. These are used to narrow down queries.
906
# These must be strings rather than integers, because json-encoding
907
# converts them to strings anyway, as they're used as dict-keys.
908
CONFD_REQQ_LINK = "0"
909
CONFD_REQQ_IP = "1"
910
CONFD_REQQ_IPLIST = "2"
911
CONFD_REQQ_FIELDS = "3"
912

    
913
CONFD_REQFIELD_NAME = "0"
914
CONFD_REQFIELD_IP = "1"
915
CONFD_REQFIELD_MNODE_PIP = "2"
916

    
917
CONFD_REQS = frozenset([
918
  CONFD_REQ_PING,
919
  CONFD_REQ_NODE_ROLE_BYNAME,
920
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
921
  CONFD_REQ_CLUSTER_MASTER,
922
  CONFD_REQ_NODE_PIP_LIST,
923
  CONFD_REQ_MC_PIP_LIST,
924
  CONFD_REQ_INSTANCES_IPS_LIST,
925
  ])
926

    
927
CONFD_REPL_STATUS_OK = 0
928
CONFD_REPL_STATUS_ERROR = 1
929
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
930

    
931
CONFD_REPL_STATUSES = frozenset([
932
  CONFD_REPL_STATUS_OK,
933
  CONFD_REPL_STATUS_ERROR,
934
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
935
  ])
936

    
937
(CONFD_NODE_ROLE_MASTER,
938
 CONFD_NODE_ROLE_CANDIDATE,
939
 CONFD_NODE_ROLE_OFFLINE,
940
 CONFD_NODE_ROLE_DRAINED,
941
 CONFD_NODE_ROLE_REGULAR,
942
 ) = range(5)
943

    
944
# A few common errors for confd
945
CONFD_ERROR_UNKNOWN_ENTRY = 1
946
CONFD_ERROR_INTERNAL = 2
947
CONFD_ERROR_ARGUMENT = 3
948

    
949
# Each request is "salted" by the current timestamp.
950
# This constants decides how many seconds of skew to accept.
951
# TODO: make this a default and allow the value to be more configurable
952
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
953

    
954
# When we haven't reloaded the config for more than this amount of seconds, we
955
# force a test to see if inotify is betraying us.
956
CONFD_CONFIG_RELOAD_TIMEOUT = 60
957

    
958
# If we receive more than one update in this amount of seconds, we move to
959
# polling every RATELIMIT seconds, rather than relying on inotify, to be able
960
# to serve more requests.
961
CONFD_CONFIG_RELOAD_RATELIMIT = 2
962

    
963
# Magic number prepended to all confd queries.
964
# This allows us to distinguish different types of confd protocols and handle
965
# them. For example by changing this we can move the whole payload to be
966
# compressed, or move away from json.
967
CONFD_MAGIC_FOURCC = 'plj0'
968

    
969
# By default a confd request is sent to the minimum between this number and all
970
# MCs. 6 was chosen because even in the case of a disastrous 50% response rate,
971
# we should have enough answers to be able to compare more than one.
972
CONFD_DEFAULT_REQ_COVERAGE = 6
973

    
974
# Timeout in seconds to expire pending query request in the confd client
975
# library. We don't actually expect any answer more than 10 seconds after we
976
# sent a request.
977
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
978

    
979
# Maximum UDP datagram size.
980
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
981
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
982
#   (assuming we can't use jumbo frames)
983
# We just set this to 60K, which should be enough
984
MAX_UDP_DATA_SIZE = 61440
985

    
986
# User-id pool minimum/maximum acceptable user-ids.
987
UIDPOOL_UID_MIN = 0
988
UIDPOOL_UID_MAX = 2**32-1 # Assuming 32 bit user-ids
989

    
990
# Name or path of the pgrep command
991
PGREP = "pgrep"