Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ 1b02d7ef

History | View | Annotate | Download (62.8 kB)

1
#
2
#
3

    
4
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 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
import socket
26

    
27
from ganeti import _autoconf
28
from ganeti import _vcsversion
29
from ganeti import compat
30
from ganeti import pathutils
31

    
32

    
33
# various versions
34
RELEASE_VERSION = _autoconf.PACKAGE_VERSION
35
OS_API_V10 = 10
36
OS_API_V15 = 15
37
OS_API_V20 = 20
38
OS_API_VERSIONS = compat.UniqueFrozenset([
39
  OS_API_V10,
40
  OS_API_V15,
41
  OS_API_V20,
42
  ])
43
VCS_VERSION = _vcsversion.VCS_VERSION
44
EXPORT_VERSION = 0
45
RAPI_VERSION = 2
46

    
47

    
48
# Format for CONFIG_VERSION:
49
#   01 03 0123 = 01030123
50
#   ^^ ^^ ^^^^
51
#   |  |  + Configuration version/revision
52
#   |  + Minor version
53
#   + Major version
54
#
55
# It is stored as an integer. Make sure not to write an octal number.
56

    
57
# BuildVersion and SplitVersion must be in here because we can't import other
58
# modules. The cfgupgrade tool must be able to read and write version numbers
59
# and thus requires these functions. To avoid code duplication, they're kept in
60
# here.
61

    
62
def BuildVersion(major, minor, revision):
63
  """Calculates int version number from major, minor and revision numbers.
64

65
  Returns: int representing version number
66

67
  """
68
  assert isinstance(major, int)
69
  assert isinstance(minor, int)
70
  assert isinstance(revision, int)
71
  return (1000000 * major +
72
            10000 * minor +
73
                1 * revision)
74

    
75

    
76
def SplitVersion(version):
77
  """Splits version number stored in an int.
78

79
  Returns: tuple; (major, minor, revision)
80

81
  """
82
  assert isinstance(version, int)
83

    
84
  (major, remainder) = divmod(version, 1000000)
85
  (minor, revision) = divmod(remainder, 10000)
86

    
87
  return (major, minor, revision)
88

    
89

    
90
CONFIG_MAJOR = int(_autoconf.VERSION_MAJOR)
91
CONFIG_MINOR = int(_autoconf.VERSION_MINOR)
92
CONFIG_REVISION = 0
93
CONFIG_VERSION = BuildVersion(CONFIG_MAJOR, CONFIG_MINOR, CONFIG_REVISION)
94

    
95
#: RPC protocol version
96
PROTOCOL_VERSION = BuildVersion(CONFIG_MAJOR, CONFIG_MINOR, 0)
97

    
98
# user separation
99
DAEMONS_GROUP = _autoconf.DAEMONS_GROUP
100
ADMIN_GROUP = _autoconf.ADMIN_GROUP
101
MASTERD_USER = _autoconf.MASTERD_USER
102
MASTERD_GROUP = _autoconf.MASTERD_GROUP
103
RAPI_USER = _autoconf.RAPI_USER
104
RAPI_GROUP = _autoconf.RAPI_GROUP
105
CONFD_USER = _autoconf.CONFD_USER
106
CONFD_GROUP = _autoconf.CONFD_GROUP
107
NODED_USER = _autoconf.NODED_USER
108
NODED_GROUP = _autoconf.NODED_GROUP
109
MOND_USER = _autoconf.MOND_USER
110
MOND_GROUP = _autoconf.MOND_GROUP
111
SSH_LOGIN_USER = _autoconf.SSH_LOGIN_USER
112
SSH_CONSOLE_USER = _autoconf.SSH_CONSOLE_USER
113

    
114
# cpu pinning separators and constants
115
CPU_PINNING_SEP = ":"
116
CPU_PINNING_ALL = "all"
117
# internal representation of "all"
118
CPU_PINNING_ALL_VAL = -1
119
# one "all" entry in a CPU list means CPU pinning is off
120
CPU_PINNING_OFF = [CPU_PINNING_ALL_VAL]
121

    
122
# A Xen-specific implementation detail - there is no way to actually say
123
# "use any cpu for pinning" in a Xen configuration file, as opposed to the
124
# command line, where you can say "xm vcpu-pin <domain> <vcpu> all".
125
# The workaround used in Xen is "0-63" (see source code function
126
# xm_vcpu_pin in <xen-source>/tools/python/xen/xm/main.py).
127
# To support future changes, the following constant is treated as a
128
# blackbox string that simply means use-any-cpu-for-pinning-under-xen.
129
CPU_PINNING_ALL_XEN = "0-63"
130

    
131
# A KVM-specific implementation detail - the following value is used
132
# to set CPU affinity to all processors (#0 through #31), per taskset
133
# man page.
134
# FIXME: This only works for machines with up to 32 CPU cores
135
CPU_PINNING_ALL_KVM = 0xFFFFFFFF
136

    
137
# Wipe
138
DD_CMD = "dd"
139
MAX_WIPE_CHUNK = 1024 # 1GB
140
MIN_WIPE_CHUNK_PERCENT = 10
141

    
142
RUN_DIRS_MODE = 0775
143
SECURE_DIR_MODE = 0700
144
SECURE_FILE_MODE = 0600
145
ADOPTABLE_BLOCKDEV_ROOT = "/dev/disk/"
146
ENABLE_FILE_STORAGE = _autoconf.ENABLE_FILE_STORAGE
147
ENABLE_SHARED_FILE_STORAGE = _autoconf.ENABLE_SHARED_FILE_STORAGE
148
ENABLE_CONFD = _autoconf.ENABLE_CONFD
149
ENABLE_SPLIT_QUERY = _autoconf.ENABLE_SPLIT_QUERY
150
ENABLE_RESTRICTED_COMMANDS = _autoconf.ENABLE_RESTRICTED_COMMANDS
151

    
152
# SSH constants
153
SSH = "ssh"
154
SCP = "scp"
155

    
156
NODED = "ganeti-noded"
157
CONFD = "ganeti-confd"
158
RAPI = "ganeti-rapi"
159
MASTERD = "ganeti-masterd"
160
MOND = "ganeti-mond"
161

    
162
DAEMONS = compat.UniqueFrozenset([
163
  NODED,
164
  CONFD,
165
  RAPI,
166
  MASTERD,
167
  MOND,
168
  ])
169

    
170
DAEMONS_PORTS = {
171
  # daemon-name: ("proto", "default-port")
172
  NODED: ("tcp", 1811),
173
  CONFD: ("udp", 1814),
174
  MOND: ("tcp", 1815),
175
  RAPI: ("tcp", 5080),
176
  SSH: ("tcp", 22),
177
}
178

    
179
DEFAULT_NODED_PORT = DAEMONS_PORTS[NODED][1]
180
DEFAULT_CONFD_PORT = DAEMONS_PORTS[CONFD][1]
181
DEFAULT_MOND_PORT = DAEMONS_PORTS[MOND][1]
182
DEFAULT_RAPI_PORT = DAEMONS_PORTS[RAPI][1]
183

    
184
FIRST_DRBD_PORT = 11000
185
LAST_DRBD_PORT = 14999
186

    
187
DAEMONS_LOGBASE = {
188
  NODED: "node-daemon",
189
  CONFD: "conf-daemon",
190
  RAPI: "rapi-daemon",
191
  MASTERD: "master-daemon",
192
  MOND: "monitoring-daemon",
193
  }
194

    
195
DAEMONS_LOGFILES = \
196
    dict((daemon, pathutils.GetLogFilename(DAEMONS_LOGBASE[daemon]))
197
         for daemon in DAEMONS_LOGBASE)
198

    
199
# Some daemons might require more than one logfile.
200
# Specifically, right now only the Haskell http library "snap", used by the
201
# monitoring daemon, requires multiple log files.
202

    
203
# These are the only valid reasons for having an extra logfile
204
EXTRA_LOGREASON_ACCESS = "access"
205
EXTRA_LOGREASON_ERROR = "error"
206

    
207
VALID_EXTRA_LOGREASONS = compat.UniqueFrozenset([
208
  EXTRA_LOGREASON_ACCESS,
209
  EXTRA_LOGREASON_ERROR,
210
  ])
211

    
212
# These are the extra logfiles, grouped by daemon
213
DAEMONS_EXTRA_LOGBASE = {
214
  MOND: {
215
    EXTRA_LOGREASON_ACCESS: "monitoring-daemon-access",
216
    EXTRA_LOGREASON_ERROR: "monitoring-daemon-error",
217
    }
218
  }
219

    
220
DAEMONS_EXTRA_LOGFILES = \
221
  dict((daemon, dict((extra,
222
       pathutils.GetLogFilename(DAEMONS_EXTRA_LOGBASE[daemon][extra]))
223
       for extra in DAEMONS_EXTRA_LOGBASE[daemon]))
224
         for daemon in DAEMONS_EXTRA_LOGBASE)
225

    
226
DEV_CONSOLE = "/dev/console"
227

    
228
PROC_MOUNTS = "/proc/mounts"
229

    
230
# Local UniX Interface related constants
231
LUXI_EOM = "\3"
232
LUXI_VERSION = CONFIG_VERSION
233
#: Environment variable for the luxi override socket
234
LUXI_OVERRIDE = "FORCE_LUXI_SOCKET"
235
LUXI_OVERRIDE_MASTER = "master"
236
LUXI_OVERRIDE_QUERY = "query"
237

    
238
# one of "no", "yes", "only"
239
SYSLOG_USAGE = _autoconf.SYSLOG_USAGE
240
SYSLOG_NO = "no"
241
SYSLOG_YES = "yes"
242
SYSLOG_ONLY = "only"
243
SYSLOG_SOCKET = "/dev/log"
244

    
245
EXPORT_CONF_FILE = "config.ini"
246

    
247
XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER
248
XEN_KERNEL = _autoconf.XEN_KERNEL
249
XEN_INITRD = _autoconf.XEN_INITRD
250
XEN_CMD_XM = "xm"
251
XEN_CMD_XL = "xl"
252
# FIXME: This will be made configurable using hvparams in Ganeti 2.7
253
XEN_CMD = _autoconf.XEN_CMD
254

    
255
KNOWN_XEN_COMMANDS = compat.UniqueFrozenset([
256
  XEN_CMD_XM,
257
  XEN_CMD_XL,
258
  ])
259

    
260
# When the Xen toolstack used is "xl", live migration requires the source host
261
# to connect to the target host via ssh (xl runs this command). We need to pass
262
# the command xl runs some extra info so that it can use Ganeti's key
263
# verification and not fail. Note that this string is incomplete: it must be
264
# filled with the cluster name before being used.
265
XL_SSH_CMD = ("ssh -l %s -oGlobalKnownHostsFile=%s"
266
              " -oUserKnownHostsFile=/dev/null"
267
              " -oCheckHostIp=no -oStrictHostKeyChecking=yes"
268
              " -oHostKeyAlias=%%s") % (SSH_LOGIN_USER,
269
                                        pathutils.SSH_KNOWN_HOSTS_FILE)
270

    
271
KVM_PATH = _autoconf.KVM_PATH
272
KVM_KERNEL = _autoconf.KVM_KERNEL
273
SOCAT_PATH = _autoconf.SOCAT_PATH
274
SOCAT_USE_ESCAPE = _autoconf.SOCAT_USE_ESCAPE
275
SOCAT_USE_COMPRESS = _autoconf.SOCAT_USE_COMPRESS
276
SOCAT_ESCAPE_CODE = "0x1d"
277

    
278
#: Console as SSH command
279
CONS_SSH = "ssh"
280

    
281
#: Console as VNC server
282
CONS_VNC = "vnc"
283

    
284
#: Console as SPICE server
285
CONS_SPICE = "spice"
286

    
287
#: Display a message for console access
288
CONS_MESSAGE = "msg"
289

    
290
#: All console types
291
CONS_ALL = compat.UniqueFrozenset([
292
  CONS_SSH,
293
  CONS_VNC,
294
  CONS_SPICE,
295
  CONS_MESSAGE,
296
  ])
297

    
298
# For RSA keys more bits are better, but they also make operations more
299
# expensive. NIST SP 800-131 recommends a minimum of 2048 bits from the year
300
# 2010 on.
301
RSA_KEY_BITS = 2048
302

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

    
311
# Digest used to sign certificates ("openssl x509" uses SHA1 by default)
312
X509_CERT_SIGN_DIGEST = "SHA1"
313

    
314
# Default validity of certificates in days
315
X509_CERT_DEFAULT_VALIDITY = 365 * 5
316

    
317
# commonName (CN) used in certificates
318
X509_CERT_CN = "ganeti.example.com"
319

    
320
X509_CERT_SIGNATURE_HEADER = "X-Ganeti-Signature"
321

    
322
# Import/export daemon mode
323
IEM_IMPORT = "import"
324
IEM_EXPORT = "export"
325

    
326
# Import/export transport compression
327
IEC_NONE = "none"
328
IEC_GZIP = "gzip"
329
IEC_ALL = compat.UniqueFrozenset([
330
  IEC_NONE,
331
  IEC_GZIP,
332
  ])
333

    
334
IE_CUSTOM_SIZE = "fd"
335

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

    
338
# Import/export I/O
339
# Direct file I/O, equivalent to a shell's I/O redirection using '<' or '>'
340
IEIO_FILE = "file"
341
# Raw block device I/O using "dd"
342
IEIO_RAW_DISK = "raw"
343
# OS definition import/export script
344
IEIO_SCRIPT = "script"
345

    
346
VALUE_DEFAULT = "default"
347
VALUE_AUTO = "auto"
348
VALUE_GENERATE = "generate"
349
VALUE_NONE = "none"
350
VALUE_TRUE = "true"
351
VALUE_FALSE = "false"
352

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

    
356
# hooks-related constants
357
HOOKS_PHASE_PRE = "pre"
358
HOOKS_PHASE_POST = "post"
359
HOOKS_NAME_CFGUPDATE = "config-update"
360
HOOKS_NAME_WATCHER = "watcher"
361
HOOKS_VERSION = 2
362
HOOKS_PATH = "/sbin:/bin:/usr/sbin:/usr/bin"
363

    
364
# hooks subject type (what object type does the LU deal with)
365
HTYPE_CLUSTER = "CLUSTER"
366
HTYPE_NODE = "NODE"
367
HTYPE_GROUP = "GROUP"
368
HTYPE_INSTANCE = "INSTANCE"
369
HTYPE_NETWORK = "NETWORK"
370

    
371
HKR_SKIP = 0
372
HKR_FAIL = 1
373
HKR_SUCCESS = 2
374

    
375
# Storage types
376
ST_BLOCK = "blockdev"
377
ST_DISKLESS = "diskless"
378
ST_EXT = "ext"
379
ST_FILE = "file"
380
ST_LVM_PV = "lvm-pv"
381
ST_LVM_VG = "lvm-vg"
382
ST_RADOS = "rados"
383
ST_SHARED_FILE = "sharedfile"
384

    
385
VALID_STORAGE_TYPES = compat.UniqueFrozenset([
386
  ST_BLOCK,
387
  ST_DISKLESS,
388
  ST_EXT,
389
  ST_FILE,
390
  ST_LVM_PV,
391
  ST_LVM_VG,
392
  ST_RADOS,
393
  ST_SHARED_FILE,
394
  ])
395

    
396
# Per default, only lvm is enabled.
397
DEFAULT_ENABLED_STORAGE_TYPES = compat.UniqueFrozenset([
398
  ST_LVM_VG,
399
  ])
400

    
401
# Storage fields
402
# first two are valid in LU context only, not passed to backend
403
SF_NODE = "node"
404
SF_TYPE = "type"
405
# and the rest are valid in backend
406
SF_NAME = "name"
407
SF_SIZE = "size"
408
SF_FREE = "free"
409
SF_USED = "used"
410
SF_ALLOCATABLE = "allocatable"
411

    
412
# Storage operations
413
SO_FIX_CONSISTENCY = "fix-consistency"
414

    
415
# Available fields per storage type
416
VALID_STORAGE_FIELDS = compat.UniqueFrozenset([
417
  SF_NAME,
418
  SF_TYPE,
419
  SF_SIZE,
420
  SF_USED,
421
  SF_FREE,
422
  SF_ALLOCATABLE,
423
  ])
424

    
425
MODIFIABLE_STORAGE_FIELDS = {
426
  ST_LVM_PV: frozenset([SF_ALLOCATABLE]),
427
  }
428

    
429
VALID_STORAGE_OPERATIONS = {
430
  ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
431
  }
432

    
433
# Local disk status
434
# Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
435
(LDS_OKAY,
436
 LDS_UNKNOWN,
437
 LDS_FAULTY) = range(1, 4)
438

    
439
# disk template types
440
DT_BLOCK = "blockdev"
441
DT_DISKLESS = "diskless"
442
DT_DRBD8 = "drbd"
443
DT_EXT = "ext"
444
DT_FILE = "file"
445
DT_PLAIN = "plain"
446
DT_RBD = "rbd"
447
DT_SHARED_FILE = "sharedfile"
448

    
449
# This is used to order determine the default disk template when the list
450
# of enabled disk templates is inferred from the current state of the cluster.
451
# This only happens on an upgrade from a version of Ganeti that did not
452
# support the 'enabled_disk_templates' so far.
453
DISK_TEMPLATE_PREFERENCE = [
454
  DT_DRBD8,
455
  DT_PLAIN,
456
  DT_FILE,
457
  DT_SHARED_FILE,
458
  DT_RBD,
459
  DT_BLOCK,
460
  DT_DISKLESS,
461
  DT_EXT
462
  ]
463

    
464
DISK_TEMPLATES = compat.UniqueFrozenset([
465
  DT_DISKLESS,
466
  DT_PLAIN,
467
  DT_DRBD8,
468
  DT_FILE,
469
  DT_SHARED_FILE,
470
  DT_BLOCK,
471
  DT_RBD,
472
  DT_EXT
473
  ])
474

    
475
# disk templates that are enabled by default
476
DEFAULT_ENABLED_DISK_TEMPLATES = compat.UniqueFrozenset([
477
  DT_DRBD8,
478
  DT_PLAIN,
479
  ])
480

    
481
# mapping of disk templates to storage types
482
DISK_TEMPLATES_STORAGE_TYPE = {
483
  DT_BLOCK: ST_BLOCK,
484
  DT_DISKLESS: ST_DISKLESS,
485
  DT_DRBD8: ST_LVM_VG,
486
  DT_EXT: ST_EXT,
487
  DT_FILE: ST_FILE,
488
  DT_PLAIN: ST_LVM_VG,
489
  DT_RBD: ST_RADOS,
490
  DT_SHARED_FILE: ST_SHARED_FILE,
491
  }
492

    
493
# the set of network-mirrored disk templates
494
DTS_INT_MIRROR = compat.UniqueFrozenset([DT_DRBD8])
495

    
496
# the set of externally-mirrored disk templates (e.g. SAN, NAS)
497
DTS_EXT_MIRROR = compat.UniqueFrozenset([
498
  DT_DISKLESS, # 'trivially' externally mirrored
499
  DT_SHARED_FILE,
500
  DT_BLOCK,
501
  DT_RBD,
502
  DT_EXT,
503
  ])
504

    
505
# the set of non-lvm-based disk templates
506
DTS_NOT_LVM = compat.UniqueFrozenset([
507
  DT_DISKLESS,
508
  DT_FILE,
509
  DT_SHARED_FILE,
510
  DT_BLOCK,
511
  DT_RBD,
512
  DT_EXT,
513
  ])
514

    
515
# the set of disk templates which can be grown
516
DTS_GROWABLE = compat.UniqueFrozenset([
517
  DT_PLAIN,
518
  DT_DRBD8,
519
  DT_FILE,
520
  DT_SHARED_FILE,
521
  DT_RBD,
522
  DT_EXT,
523
  ])
524

    
525
# the set of disk templates that allow adoption
526
DTS_MAY_ADOPT = compat.UniqueFrozenset([
527
  DT_PLAIN,
528
  DT_BLOCK,
529
  ])
530

    
531
# the set of disk templates that *must* use adoption
532
DTS_MUST_ADOPT = compat.UniqueFrozenset([DT_BLOCK])
533

    
534
# the set of disk templates that allow migrations
535
DTS_MIRRORED = frozenset.union(DTS_INT_MIRROR, DTS_EXT_MIRROR)
536

    
537
# the set of file based disk templates
538
DTS_FILEBASED = compat.UniqueFrozenset([
539
  DT_FILE,
540
  DT_SHARED_FILE,
541
  ])
542

    
543
# the set of disk templates that are supported by exclusive_storage
544
DTS_EXCL_STORAGE = compat.UniqueFrozenset([DT_PLAIN])
545

    
546
# templates for which we don't perform checks on free space
547
DTS_NO_FREE_SPACE_CHECK = compat.UniqueFrozenset([
548
  DT_FILE,
549
  DT_SHARED_FILE,
550
  DT_RBD,
551
  DT_EXT,
552
  ])
553

    
554
# logical disk types
555
LD_LV = "lvm"
556
LD_DRBD8 = "drbd8"
557
LD_FILE = "file"
558
LD_BLOCKDEV = "blockdev"
559
LD_RBD = "rbd"
560
LD_EXT = "ext"
561
LOGICAL_DISK_TYPES = compat.UniqueFrozenset([
562
  LD_LV,
563
  LD_DRBD8,
564
  LD_FILE,
565
  LD_BLOCKDEV,
566
  LD_RBD,
567
  LD_EXT,
568
  ])
569

    
570
LDS_BLOCK = compat.UniqueFrozenset([
571
  LD_LV,
572
  LD_DRBD8,
573
  LD_BLOCKDEV,
574
  LD_RBD,
575
  LD_EXT,
576
  ])
577

    
578
# drbd constants
579
DRBD_HMAC_ALG = "md5"
580
DRBD_NET_PROTOCOL = "C"
581
DRBD_STATUS_FILE = "/proc/drbd"
582

    
583
#: Size of DRBD meta block device
584
DRBD_META_SIZE = 128
585

    
586
# drbd barrier types
587
DRBD_B_NONE = "n"
588
DRBD_B_DISK_BARRIERS = "b"
589
DRBD_B_DISK_DRAIN = "d"
590
DRBD_B_DISK_FLUSH = "f"
591

    
592
# Valid barrier combinations: "n" or any non-null subset of "bfd"
593
DRBD_VALID_BARRIER_OPT = compat.UniqueFrozenset([
594
  frozenset([DRBD_B_NONE]),
595
  frozenset([DRBD_B_DISK_BARRIERS]),
596
  frozenset([DRBD_B_DISK_DRAIN]),
597
  frozenset([DRBD_B_DISK_FLUSH]),
598
  frozenset([DRBD_B_DISK_DRAIN, DRBD_B_DISK_FLUSH]),
599
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_DRAIN]),
600
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_FLUSH]),
601
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_FLUSH, DRBD_B_DISK_DRAIN]),
602
  ])
603

    
604
# rbd tool command
605
RBD_CMD = "rbd"
606

    
607
# file backend driver
608
FD_LOOP = "loop"
609
FD_BLKTAP = "blktap"
610

    
611
# the set of drbd-like disk types
612
LDS_DRBD = compat.UniqueFrozenset([LD_DRBD8])
613

    
614
# disk access mode
615
DISK_RDONLY = "ro"
616
DISK_RDWR = "rw"
617
DISK_ACCESS_SET = compat.UniqueFrozenset([DISK_RDONLY, DISK_RDWR])
618

    
619
# disk replacement mode
620
REPLACE_DISK_PRI = "replace_on_primary"    # replace disks on primary
621
REPLACE_DISK_SEC = "replace_on_secondary"  # replace disks on secondary
622
REPLACE_DISK_CHG = "replace_new_secondary" # change secondary node
623
REPLACE_DISK_AUTO = "replace_auto"
624
REPLACE_MODES = compat.UniqueFrozenset([
625
  REPLACE_DISK_PRI,
626
  REPLACE_DISK_SEC,
627
  REPLACE_DISK_CHG,
628
  REPLACE_DISK_AUTO,
629
  ])
630

    
631
# Instance export mode
632
EXPORT_MODE_LOCAL = "local"
633
EXPORT_MODE_REMOTE = "remote"
634
EXPORT_MODES = compat.UniqueFrozenset([
635
  EXPORT_MODE_LOCAL,
636
  EXPORT_MODE_REMOTE,
637
  ])
638

    
639
# instance creation modes
640
INSTANCE_CREATE = "create"
641
INSTANCE_IMPORT = "import"
642
INSTANCE_REMOTE_IMPORT = "remote-import"
643
INSTANCE_CREATE_MODES = compat.UniqueFrozenset([
644
  INSTANCE_CREATE,
645
  INSTANCE_IMPORT,
646
  INSTANCE_REMOTE_IMPORT,
647
  ])
648

    
649
# Remote import/export handshake message and version
650
RIE_VERSION = 0
651
RIE_HANDSHAKE = "Hi, I'm Ganeti"
652

    
653
# Remote import/export certificate validity in seconds
654
RIE_CERT_VALIDITY = 24 * 60 * 60
655

    
656
# Overall timeout for establishing connection
657
RIE_CONNECT_TIMEOUT = 180
658

    
659
# Export only: how long to wait per connection attempt (seconds)
660
RIE_CONNECT_ATTEMPT_TIMEOUT = 20
661

    
662
# Export only: number of attempts to connect
663
RIE_CONNECT_RETRIES = 10
664

    
665
#: Give child process up to 5 seconds to exit after sending a signal
666
CHILD_LINGER_TIMEOUT = 5.0
667

    
668
FILE_DRIVER = compat.UniqueFrozenset([FD_LOOP, FD_BLKTAP])
669

    
670
# import/export config options
671
INISECT_EXP = "export"
672
INISECT_INS = "instance"
673
INISECT_HYP = "hypervisor"
674
INISECT_BEP = "backend"
675
INISECT_OSP = "os"
676

    
677
# dynamic device modification
678
DDM_ADD = "add"
679
DDM_MODIFY = "modify"
680
DDM_REMOVE = "remove"
681
DDMS_VALUES = compat.UniqueFrozenset([DDM_ADD, DDM_REMOVE])
682
DDMS_VALUES_WITH_MODIFY = (DDMS_VALUES | frozenset([
683
  DDM_MODIFY,
684
  ]))
685
# TODO: DDM_SWAP, DDM_MOVE?
686

    
687
# common exit codes
688
EXIT_SUCCESS = 0
689
EXIT_FAILURE = 1
690
EXIT_NOTCLUSTER = 5
691
EXIT_NOTMASTER = 11
692
EXIT_NODESETUP_ERROR = 12
693
EXIT_CONFIRMATION = 13 # need user confirmation
694

    
695
#: Exit code for query operations with unknown fields
696
EXIT_UNKNOWN_FIELD = 14
697

    
698
# tags
699
TAG_CLUSTER = "cluster"
700
TAG_NODEGROUP = "nodegroup"
701
TAG_NODE = "node"
702
TAG_INSTANCE = "instance"
703
TAG_NETWORK = "network"
704
VALID_TAG_TYPES = compat.UniqueFrozenset([
705
  TAG_CLUSTER,
706
  TAG_NODEGROUP,
707
  TAG_NODE,
708
  TAG_INSTANCE,
709
  TAG_NETWORK,
710
  ])
711
MAX_TAG_LEN = 128
712
MAX_TAGS_PER_OBJ = 4096
713

    
714
# others
715
DEFAULT_BRIDGE = "xen-br0"
716
CLASSIC_DRBD_SYNC_SPEED = 60 * 1024  # 60 MiB, expressed in KiB
717
IP4_ADDRESS_LOCALHOST = "127.0.0.1"
718
IP4_ADDRESS_ANY = "0.0.0.0"
719
IP6_ADDRESS_LOCALHOST = "::1"
720
IP6_ADDRESS_ANY = "::"
721
IP4_VERSION = 4
722
IP6_VERSION = 6
723
VALID_IP_VERSIONS = compat.UniqueFrozenset([IP4_VERSION, IP6_VERSION])
724
# for export to htools
725
IP4_FAMILY = socket.AF_INET
726
IP6_FAMILY = socket.AF_INET6
727

    
728
TCP_PING_TIMEOUT = 10
729
DEFAULT_VG = "xenvg"
730
DEFAULT_DRBD_HELPER = "/bin/true"
731
MIN_VG_SIZE = 20480
732
DEFAULT_MAC_PREFIX = "aa:00:00"
733
# default maximum instance wait time, in seconds.
734
DEFAULT_SHUTDOWN_TIMEOUT = 120
735
NODE_MAX_CLOCK_SKEW = 150
736
# Time for an intra-cluster disk transfer to wait for a connection
737
DISK_TRANSFER_CONNECT_TIMEOUT = 60
738
# Disk index separator
739
DISK_SEPARATOR = _autoconf.DISK_SEPARATOR
740
IP_COMMAND_PATH = _autoconf.IP_PATH
741

    
742
#: Key for job IDs in opcode result
743
JOB_IDS_KEY = "jobs"
744

    
745
# runparts results
746
(RUNPARTS_SKIP,
747
 RUNPARTS_RUN,
748
 RUNPARTS_ERR) = range(3)
749

    
750
RUNPARTS_STATUS = compat.UniqueFrozenset([
751
  RUNPARTS_SKIP,
752
  RUNPARTS_RUN,
753
  RUNPARTS_ERR,
754
  ])
755

    
756
# RPC constants
757
(RPC_ENCODING_NONE,
758
 RPC_ENCODING_ZLIB_BASE64) = range(2)
759

    
760
# Various time constants for the timeout table
761
RPC_TMO_URGENT = 60 # one minute
762
RPC_TMO_FAST = 5 * 60 # five minutes
763
RPC_TMO_NORMAL = 15 * 60 # 15 minutes
764
RPC_TMO_SLOW = 3600 # one hour
765
RPC_TMO_4HRS = 4 * 3600
766
RPC_TMO_1DAY = 86400
767

    
768
# Timeout for connecting to nodes (seconds)
769
RPC_CONNECT_TIMEOUT = 5
770

    
771
# os related constants
772
OS_SCRIPT_CREATE = "create"
773
OS_SCRIPT_IMPORT = "import"
774
OS_SCRIPT_EXPORT = "export"
775
OS_SCRIPT_RENAME = "rename"
776
OS_SCRIPT_VERIFY = "verify"
777
OS_SCRIPTS = compat.UniqueFrozenset([
778
  OS_SCRIPT_CREATE,
779
  OS_SCRIPT_IMPORT,
780
  OS_SCRIPT_EXPORT,
781
  OS_SCRIPT_RENAME,
782
  OS_SCRIPT_VERIFY,
783
  ])
784

    
785
OS_API_FILE = "ganeti_api_version"
786
OS_VARIANTS_FILE = "variants.list"
787
OS_PARAMETERS_FILE = "parameters.list"
788

    
789
OS_VALIDATE_PARAMETERS = "parameters"
790
OS_VALIDATE_CALLS = compat.UniqueFrozenset([OS_VALIDATE_PARAMETERS])
791

    
792
# External Storage (ES) related constants
793
ES_ACTION_CREATE = "create"
794
ES_ACTION_REMOVE = "remove"
795
ES_ACTION_GROW = "grow"
796
ES_ACTION_ATTACH = "attach"
797
ES_ACTION_DETACH = "detach"
798
ES_ACTION_SETINFO = "setinfo"
799
ES_ACTION_VERIFY = "verify"
800

    
801
ES_SCRIPT_CREATE = ES_ACTION_CREATE
802
ES_SCRIPT_REMOVE = ES_ACTION_REMOVE
803
ES_SCRIPT_GROW = ES_ACTION_GROW
804
ES_SCRIPT_ATTACH = ES_ACTION_ATTACH
805
ES_SCRIPT_DETACH = ES_ACTION_DETACH
806
ES_SCRIPT_SETINFO = ES_ACTION_SETINFO
807
ES_SCRIPT_VERIFY = ES_ACTION_VERIFY
808
ES_SCRIPTS = frozenset([
809
  ES_SCRIPT_CREATE,
810
  ES_SCRIPT_REMOVE,
811
  ES_SCRIPT_GROW,
812
  ES_SCRIPT_ATTACH,
813
  ES_SCRIPT_DETACH,
814
  ES_SCRIPT_SETINFO,
815
  ES_SCRIPT_VERIFY
816
  ])
817

    
818
ES_PARAMETERS_FILE = "parameters.list"
819

    
820
# reboot types
821
INSTANCE_REBOOT_SOFT = "soft"
822
INSTANCE_REBOOT_HARD = "hard"
823
INSTANCE_REBOOT_FULL = "full"
824

    
825
REBOOT_TYPES = compat.UniqueFrozenset([
826
  INSTANCE_REBOOT_SOFT,
827
  INSTANCE_REBOOT_HARD,
828
  INSTANCE_REBOOT_FULL,
829
  ])
830

    
831
# instance reboot behaviors
832
INSTANCE_REBOOT_ALLOWED = "reboot"
833
INSTANCE_REBOOT_EXIT = "exit"
834

    
835
REBOOT_BEHAVIORS = compat.UniqueFrozenset([
836
  INSTANCE_REBOOT_ALLOWED,
837
  INSTANCE_REBOOT_EXIT,
838
  ])
839

    
840
VTYPE_STRING = "string"
841
VTYPE_MAYBE_STRING = "maybe-string"
842
VTYPE_BOOL = "bool"
843
VTYPE_SIZE = "size" # size, in MiBs
844
VTYPE_INT = "int"
845
ENFORCEABLE_TYPES = compat.UniqueFrozenset([
846
  VTYPE_STRING,
847
  VTYPE_MAYBE_STRING,
848
  VTYPE_BOOL,
849
  VTYPE_SIZE,
850
  VTYPE_INT,
851
  ])
852

    
853
# Constant representing that the user does not specify any IP version
854
IFACE_NO_IP_VERSION_SPECIFIED = 0
855

    
856
VALID_SERIAL_SPEEDS = compat.UniqueFrozenset([
857
  75,
858
  110,
859
  300,
860
  600,
861
  1200,
862
  1800,
863
  2400,
864
  4800,
865
  9600,
866
  14400,
867
  19200,
868
  28800,
869
  38400,
870
  57600,
871
  115200,
872
  230400,
873
  345600,
874
  460800,
875
  ])
876

    
877
# HV parameter names (global namespace)
878
HV_BOOT_ORDER = "boot_order"
879
HV_CDROM_IMAGE_PATH = "cdrom_image_path"
880
HV_KVM_CDROM2_IMAGE_PATH = "cdrom2_image_path"
881
HV_KVM_FLOPPY_IMAGE_PATH = "floppy_image_path"
882
HV_NIC_TYPE = "nic_type"
883
HV_DISK_TYPE = "disk_type"
884
HV_KVM_CDROM_DISK_TYPE = "cdrom_disk_type"
885
HV_VNC_BIND_ADDRESS = "vnc_bind_address"
886
HV_VNC_PASSWORD_FILE = "vnc_password_file"
887
HV_VNC_TLS = "vnc_tls"
888
HV_VNC_X509 = "vnc_x509_path"
889
HV_VNC_X509_VERIFY = "vnc_x509_verify"
890
HV_KVM_SPICE_BIND = "spice_bind"
891
HV_KVM_SPICE_IP_VERSION = "spice_ip_version"
892
HV_KVM_SPICE_PASSWORD_FILE = "spice_password_file"
893
HV_KVM_SPICE_LOSSLESS_IMG_COMPR = "spice_image_compression"
894
HV_KVM_SPICE_JPEG_IMG_COMPR = "spice_jpeg_wan_compression"
895
HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR = "spice_zlib_glz_wan_compression"
896
HV_KVM_SPICE_STREAMING_VIDEO_DETECTION = "spice_streaming_video"
897
HV_KVM_SPICE_AUDIO_COMPR = "spice_playback_compression"
898
HV_KVM_SPICE_USE_TLS = "spice_use_tls"
899
HV_KVM_SPICE_TLS_CIPHERS = "spice_tls_ciphers"
900
HV_KVM_SPICE_USE_VDAGENT = "spice_use_vdagent"
901
HV_ACPI = "acpi"
902
HV_PAE = "pae"
903
HV_USE_BOOTLOADER = "use_bootloader"
904
HV_BOOTLOADER_ARGS = "bootloader_args"
905
HV_BOOTLOADER_PATH = "bootloader_path"
906
HV_KERNEL_ARGS = "kernel_args"
907
HV_KERNEL_PATH = "kernel_path"
908
HV_INITRD_PATH = "initrd_path"
909
HV_ROOT_PATH = "root_path"
910
HV_SERIAL_CONSOLE = "serial_console"
911
HV_SERIAL_SPEED = "serial_speed"
912
HV_USB_MOUSE = "usb_mouse"
913
HV_KEYMAP = "keymap"
914
HV_DEVICE_MODEL = "device_model"
915
HV_INIT_SCRIPT = "init_script"
916
HV_MIGRATION_PORT = "migration_port"
917
HV_MIGRATION_BANDWIDTH = "migration_bandwidth"
918
HV_MIGRATION_DOWNTIME = "migration_downtime"
919
HV_MIGRATION_MODE = "migration_mode"
920
HV_USE_LOCALTIME = "use_localtime"
921
HV_DISK_CACHE = "disk_cache"
922
HV_SECURITY_MODEL = "security_model"
923
HV_SECURITY_DOMAIN = "security_domain"
924
HV_KVM_FLAG = "kvm_flag"
925
HV_VHOST_NET = "vhost_net"
926
HV_KVM_USE_CHROOT = "use_chroot"
927
HV_CPU_MASK = "cpu_mask"
928
HV_MEM_PATH = "mem_path"
929
HV_PASSTHROUGH = "pci_pass"
930
HV_BLOCKDEV_PREFIX = "blockdev_prefix"
931
HV_REBOOT_BEHAVIOR = "reboot_behavior"
932
HV_CPU_TYPE = "cpu_type"
933
HV_CPU_CAP = "cpu_cap"
934
HV_CPU_WEIGHT = "cpu_weight"
935
HV_CPU_CORES = "cpu_cores"
936
HV_CPU_THREADS = "cpu_threads"
937
HV_CPU_SOCKETS = "cpu_sockets"
938
HV_SOUNDHW = "soundhw"
939
HV_USB_DEVICES = "usb_devices"
940
HV_VGA = "vga"
941
HV_KVM_EXTRA = "kvm_extra"
942
HV_KVM_MACHINE_VERSION = "machine_version"
943
HV_KVM_PATH = "kvm_path"
944

    
945

    
946
HVS_PARAMETER_TYPES = {
947
  HV_KVM_PATH: VTYPE_STRING,
948
  HV_BOOT_ORDER: VTYPE_STRING,
949
  HV_KVM_FLOPPY_IMAGE_PATH: VTYPE_STRING,
950
  HV_CDROM_IMAGE_PATH: VTYPE_STRING,
951
  HV_KVM_CDROM2_IMAGE_PATH: VTYPE_STRING,
952
  HV_NIC_TYPE: VTYPE_STRING,
953
  HV_DISK_TYPE: VTYPE_STRING,
954
  HV_KVM_CDROM_DISK_TYPE: VTYPE_STRING,
955
  HV_VNC_PASSWORD_FILE: VTYPE_STRING,
956
  HV_VNC_BIND_ADDRESS: VTYPE_STRING,
957
  HV_VNC_TLS: VTYPE_BOOL,
958
  HV_VNC_X509: VTYPE_STRING,
959
  HV_VNC_X509_VERIFY: VTYPE_BOOL,
960
  HV_KVM_SPICE_BIND: VTYPE_STRING,
961
  HV_KVM_SPICE_IP_VERSION: VTYPE_INT,
962
  HV_KVM_SPICE_PASSWORD_FILE: VTYPE_STRING,
963
  HV_KVM_SPICE_LOSSLESS_IMG_COMPR: VTYPE_STRING,
964
  HV_KVM_SPICE_JPEG_IMG_COMPR: VTYPE_STRING,
965
  HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR: VTYPE_STRING,
966
  HV_KVM_SPICE_STREAMING_VIDEO_DETECTION: VTYPE_STRING,
967
  HV_KVM_SPICE_AUDIO_COMPR: VTYPE_BOOL,
968
  HV_KVM_SPICE_USE_TLS: VTYPE_BOOL,
969
  HV_KVM_SPICE_TLS_CIPHERS: VTYPE_STRING,
970
  HV_KVM_SPICE_USE_VDAGENT: VTYPE_BOOL,
971
  HV_ACPI: VTYPE_BOOL,
972
  HV_PAE: VTYPE_BOOL,
973
  HV_USE_BOOTLOADER: VTYPE_BOOL,
974
  HV_BOOTLOADER_PATH: VTYPE_STRING,
975
  HV_BOOTLOADER_ARGS: VTYPE_STRING,
976
  HV_KERNEL_PATH: VTYPE_STRING,
977
  HV_KERNEL_ARGS: VTYPE_STRING,
978
  HV_INITRD_PATH: VTYPE_STRING,
979
  HV_ROOT_PATH: VTYPE_MAYBE_STRING,
980
  HV_SERIAL_CONSOLE: VTYPE_BOOL,
981
  HV_SERIAL_SPEED: VTYPE_INT,
982
  HV_USB_MOUSE: VTYPE_STRING,
983
  HV_KEYMAP: VTYPE_STRING,
984
  HV_DEVICE_MODEL: VTYPE_STRING,
985
  HV_INIT_SCRIPT: VTYPE_STRING,
986
  HV_MIGRATION_PORT: VTYPE_INT,
987
  HV_MIGRATION_BANDWIDTH: VTYPE_INT,
988
  HV_MIGRATION_DOWNTIME: VTYPE_INT,
989
  HV_MIGRATION_MODE: VTYPE_STRING,
990
  HV_USE_LOCALTIME: VTYPE_BOOL,
991
  HV_DISK_CACHE: VTYPE_STRING,
992
  HV_SECURITY_MODEL: VTYPE_STRING,
993
  HV_SECURITY_DOMAIN: VTYPE_STRING,
994
  HV_KVM_FLAG: VTYPE_STRING,
995
  HV_VHOST_NET: VTYPE_BOOL,
996
  HV_KVM_USE_CHROOT: VTYPE_BOOL,
997
  HV_CPU_MASK: VTYPE_STRING,
998
  HV_MEM_PATH: VTYPE_STRING,
999
  HV_PASSTHROUGH: VTYPE_STRING,
1000
  HV_BLOCKDEV_PREFIX: VTYPE_STRING,
1001
  HV_REBOOT_BEHAVIOR: VTYPE_STRING,
1002
  HV_CPU_TYPE: VTYPE_STRING,
1003
  HV_CPU_CAP: VTYPE_INT,
1004
  HV_CPU_WEIGHT: VTYPE_INT,
1005
  HV_CPU_CORES: VTYPE_INT,
1006
  HV_CPU_THREADS: VTYPE_INT,
1007
  HV_CPU_SOCKETS: VTYPE_INT,
1008
  HV_SOUNDHW: VTYPE_STRING,
1009
  HV_USB_DEVICES: VTYPE_STRING,
1010
  HV_VGA: VTYPE_STRING,
1011
  HV_KVM_EXTRA: VTYPE_STRING,
1012
  HV_KVM_MACHINE_VERSION: VTYPE_STRING,
1013
  }
1014

    
1015
HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
1016

    
1017
HVS_PARAMETER_TITLES = {
1018
  HV_ACPI: "ACPI",
1019
  HV_BOOT_ORDER: "Boot_order",
1020
  HV_CDROM_IMAGE_PATH: "CDROM_image_path",
1021
  HV_DISK_TYPE: "Disk_type",
1022
  HV_INITRD_PATH: "Initrd_path",
1023
  HV_KERNEL_PATH: "Kernel_path",
1024
  HV_NIC_TYPE: "NIC_type",
1025
  HV_PAE: "PAE",
1026
  HV_VNC_BIND_ADDRESS: "VNC_bind_address",
1027
  HV_PASSTHROUGH: "pci_pass",
1028
  HV_CPU_TYPE: "cpu_type",
1029
  }
1030

    
1031
# Migration statuses
1032
HV_MIGRATION_COMPLETED = "completed"
1033
HV_MIGRATION_ACTIVE = "active"
1034
HV_MIGRATION_FAILED = "failed"
1035
HV_MIGRATION_CANCELLED = "cancelled"
1036

    
1037
HV_MIGRATION_VALID_STATUSES = compat.UniqueFrozenset([
1038
  HV_MIGRATION_COMPLETED,
1039
  HV_MIGRATION_ACTIVE,
1040
  HV_MIGRATION_FAILED,
1041
  HV_MIGRATION_CANCELLED,
1042
  ])
1043

    
1044
HV_MIGRATION_FAILED_STATUSES = compat.UniqueFrozenset([
1045
  HV_MIGRATION_FAILED,
1046
  HV_MIGRATION_CANCELLED,
1047
  ])
1048

    
1049
# KVM-specific statuses
1050
HV_KVM_MIGRATION_VALID_STATUSES = HV_MIGRATION_VALID_STATUSES
1051

    
1052
# Node info keys
1053
HV_NODEINFO_KEY_VERSION = "hv_version"
1054

    
1055
# Hypervisor state
1056
HVST_MEMORY_TOTAL = "mem_total"
1057
HVST_MEMORY_NODE = "mem_node"
1058
HVST_MEMORY_HV = "mem_hv"
1059
HVST_CPU_TOTAL = "cpu_total"
1060
HVST_CPU_NODE = "cpu_node"
1061

    
1062
HVST_DEFAULTS = {
1063
  HVST_MEMORY_TOTAL: 0,
1064
  HVST_MEMORY_NODE: 0,
1065
  HVST_MEMORY_HV: 0,
1066
  HVST_CPU_TOTAL: 1,
1067
  HVST_CPU_NODE: 1,
1068
  }
1069

    
1070
HVSTS_PARAMETER_TYPES = {
1071
  HVST_MEMORY_TOTAL: VTYPE_INT,
1072
  HVST_MEMORY_NODE: VTYPE_INT,
1073
  HVST_MEMORY_HV: VTYPE_INT,
1074
  HVST_CPU_TOTAL: VTYPE_INT,
1075
  HVST_CPU_NODE: VTYPE_INT,
1076
  }
1077

    
1078
HVSTS_PARAMETERS = frozenset(HVSTS_PARAMETER_TYPES.keys())
1079

    
1080
# Disk state
1081
DS_DISK_TOTAL = "disk_total"
1082
DS_DISK_RESERVED = "disk_reserved"
1083
DS_DISK_OVERHEAD = "disk_overhead"
1084

    
1085
DS_DEFAULTS = {
1086
  DS_DISK_TOTAL: 0,
1087
  DS_DISK_RESERVED: 0,
1088
  DS_DISK_OVERHEAD: 0,
1089
  }
1090

    
1091
DSS_PARAMETER_TYPES = {
1092
  DS_DISK_TOTAL: VTYPE_INT,
1093
  DS_DISK_RESERVED: VTYPE_INT,
1094
  DS_DISK_OVERHEAD: VTYPE_INT,
1095
  }
1096

    
1097
DSS_PARAMETERS = frozenset(DSS_PARAMETER_TYPES.keys())
1098
DS_VALID_TYPES = compat.UniqueFrozenset([LD_LV])
1099

    
1100
# Backend parameter names
1101
BE_MEMORY = "memory" # deprecated and replaced by max and min mem
1102
BE_MAXMEM = "maxmem"
1103
BE_MINMEM = "minmem"
1104
BE_VCPUS = "vcpus"
1105
BE_AUTO_BALANCE = "auto_balance"
1106
BE_ALWAYS_FAILOVER = "always_failover"
1107
BE_SPINDLE_USE = "spindle_use"
1108

    
1109
BES_PARAMETER_TYPES = {
1110
  BE_MAXMEM: VTYPE_SIZE,
1111
  BE_MINMEM: VTYPE_SIZE,
1112
  BE_VCPUS: VTYPE_INT,
1113
  BE_AUTO_BALANCE: VTYPE_BOOL,
1114
  BE_ALWAYS_FAILOVER: VTYPE_BOOL,
1115
  BE_SPINDLE_USE: VTYPE_INT,
1116
  }
1117

    
1118
BES_PARAMETER_TITLES = {
1119
  BE_AUTO_BALANCE: "Auto_balance",
1120
  BE_MAXMEM: "ConfigMaxMem",
1121
  BE_MINMEM: "ConfigMinMem",
1122
  BE_VCPUS: "ConfigVCPUs",
1123
  }
1124

    
1125
BES_PARAMETER_COMPAT = {
1126
  BE_MEMORY: VTYPE_SIZE,
1127
  }
1128
BES_PARAMETER_COMPAT.update(BES_PARAMETER_TYPES)
1129

    
1130
BES_PARAMETERS = frozenset(BES_PARAMETER_TYPES.keys())
1131

    
1132
# instance specs
1133
ISPEC_MEM_SIZE = "memory-size"
1134
ISPEC_CPU_COUNT = "cpu-count"
1135
ISPEC_DISK_COUNT = "disk-count"
1136
ISPEC_DISK_SIZE = "disk-size"
1137
ISPEC_NIC_COUNT = "nic-count"
1138
ISPEC_SPINDLE_USE = "spindle-use"
1139

    
1140
ISPECS_PARAMETER_TYPES = {
1141
  ISPEC_MEM_SIZE: VTYPE_INT,
1142
  ISPEC_CPU_COUNT: VTYPE_INT,
1143
  ISPEC_DISK_COUNT: VTYPE_INT,
1144
  ISPEC_DISK_SIZE: VTYPE_INT,
1145
  ISPEC_NIC_COUNT: VTYPE_INT,
1146
  ISPEC_SPINDLE_USE: VTYPE_INT,
1147
  }
1148

    
1149
ISPECS_PARAMETERS = frozenset(ISPECS_PARAMETER_TYPES.keys())
1150

    
1151
ISPECS_MINMAX = "minmax"
1152
ISPECS_MIN = "min"
1153
ISPECS_MAX = "max"
1154
ISPECS_STD = "std"
1155
IPOLICY_DTS = "disk-templates"
1156
IPOLICY_VCPU_RATIO = "vcpu-ratio"
1157
IPOLICY_SPINDLE_RATIO = "spindle-ratio"
1158

    
1159
ISPECS_MINMAX_KEYS = compat.UniqueFrozenset([
1160
  ISPECS_MIN,
1161
  ISPECS_MAX,
1162
  ])
1163

    
1164
IPOLICY_PARAMETERS = compat.UniqueFrozenset([
1165
  IPOLICY_VCPU_RATIO,
1166
  IPOLICY_SPINDLE_RATIO,
1167
  ])
1168

    
1169
IPOLICY_ALL_KEYS = (IPOLICY_PARAMETERS |
1170
                    frozenset([ISPECS_MINMAX, ISPECS_STD, IPOLICY_DTS]))
1171

    
1172
# Node parameter names
1173
ND_OOB_PROGRAM = "oob_program"
1174
ND_SPINDLE_COUNT = "spindle_count"
1175
ND_EXCLUSIVE_STORAGE = "exclusive_storage"
1176

    
1177
NDS_PARAMETER_TYPES = {
1178
  ND_OOB_PROGRAM: VTYPE_STRING,
1179
  ND_SPINDLE_COUNT: VTYPE_INT,
1180
  ND_EXCLUSIVE_STORAGE: VTYPE_BOOL,
1181
  }
1182

    
1183
NDS_PARAMETERS = frozenset(NDS_PARAMETER_TYPES.keys())
1184

    
1185
NDS_PARAMETER_TITLES = {
1186
  ND_OOB_PROGRAM: "OutOfBandProgram",
1187
  ND_SPINDLE_COUNT: "SpindleCount",
1188
  ND_EXCLUSIVE_STORAGE: "ExclusiveStorage",
1189
  }
1190

    
1191
# Logical Disks parameters
1192
LDP_RESYNC_RATE = "resync-rate"
1193
LDP_STRIPES = "stripes"
1194
LDP_BARRIERS = "disabled-barriers"
1195
LDP_NO_META_FLUSH = "disable-meta-flush"
1196
LDP_DEFAULT_METAVG = "default-metavg"
1197
LDP_DISK_CUSTOM = "disk-custom"
1198
LDP_NET_CUSTOM = "net-custom"
1199
LDP_DYNAMIC_RESYNC = "dynamic-resync"
1200
LDP_PLAN_AHEAD = "c-plan-ahead"
1201
LDP_FILL_TARGET = "c-fill-target"
1202
LDP_DELAY_TARGET = "c-delay-target"
1203
LDP_MAX_RATE = "c-max-rate"
1204
LDP_MIN_RATE = "c-min-rate"
1205
LDP_POOL = "pool"
1206
DISK_LD_TYPES = {
1207
  LDP_RESYNC_RATE: VTYPE_INT,
1208
  LDP_STRIPES: VTYPE_INT,
1209
  LDP_BARRIERS: VTYPE_STRING,
1210
  LDP_NO_META_FLUSH: VTYPE_BOOL,
1211
  LDP_DEFAULT_METAVG: VTYPE_STRING,
1212
  LDP_DISK_CUSTOM: VTYPE_STRING,
1213
  LDP_NET_CUSTOM: VTYPE_STRING,
1214
  LDP_DYNAMIC_RESYNC: VTYPE_BOOL,
1215
  LDP_PLAN_AHEAD: VTYPE_INT,
1216
  LDP_FILL_TARGET: VTYPE_INT,
1217
  LDP_DELAY_TARGET: VTYPE_INT,
1218
  LDP_MAX_RATE: VTYPE_INT,
1219
  LDP_MIN_RATE: VTYPE_INT,
1220
  LDP_POOL: VTYPE_STRING,
1221
  }
1222
DISK_LD_PARAMETERS = frozenset(DISK_LD_TYPES.keys())
1223

    
1224
# Disk template parameters (can be set/changed by the user via gnt-cluster and
1225
# gnt-group)
1226
DRBD_RESYNC_RATE = "resync-rate"
1227
DRBD_DATA_STRIPES = "data-stripes"
1228
DRBD_META_STRIPES = "meta-stripes"
1229
DRBD_DISK_BARRIERS = "disk-barriers"
1230
DRBD_META_BARRIERS = "meta-barriers"
1231
DRBD_DEFAULT_METAVG = "metavg"
1232
DRBD_DISK_CUSTOM = "disk-custom"
1233
DRBD_NET_CUSTOM = "net-custom"
1234
DRBD_DYNAMIC_RESYNC = "dynamic-resync"
1235
DRBD_PLAN_AHEAD = "c-plan-ahead"
1236
DRBD_FILL_TARGET = "c-fill-target"
1237
DRBD_DELAY_TARGET = "c-delay-target"
1238
DRBD_MAX_RATE = "c-max-rate"
1239
DRBD_MIN_RATE = "c-min-rate"
1240
LV_STRIPES = "stripes"
1241
RBD_POOL = "pool"
1242
DISK_DT_TYPES = {
1243
  DRBD_RESYNC_RATE: VTYPE_INT,
1244
  DRBD_DATA_STRIPES: VTYPE_INT,
1245
  DRBD_META_STRIPES: VTYPE_INT,
1246
  DRBD_DISK_BARRIERS: VTYPE_STRING,
1247
  DRBD_META_BARRIERS: VTYPE_BOOL,
1248
  DRBD_DEFAULT_METAVG: VTYPE_STRING,
1249
  DRBD_DISK_CUSTOM: VTYPE_STRING,
1250
  DRBD_NET_CUSTOM: VTYPE_STRING,
1251
  DRBD_DYNAMIC_RESYNC: VTYPE_BOOL,
1252
  DRBD_PLAN_AHEAD: VTYPE_INT,
1253
  DRBD_FILL_TARGET: VTYPE_INT,
1254
  DRBD_DELAY_TARGET: VTYPE_INT,
1255
  DRBD_MAX_RATE: VTYPE_INT,
1256
  DRBD_MIN_RATE: VTYPE_INT,
1257
  LV_STRIPES: VTYPE_INT,
1258
  RBD_POOL: VTYPE_STRING,
1259
  }
1260

    
1261
DISK_DT_PARAMETERS = frozenset(DISK_DT_TYPES.keys())
1262

    
1263
# OOB supported commands
1264
OOB_POWER_ON = "power-on"
1265
OOB_POWER_OFF = "power-off"
1266
OOB_POWER_CYCLE = "power-cycle"
1267
OOB_POWER_STATUS = "power-status"
1268
OOB_HEALTH = "health"
1269

    
1270
OOB_COMMANDS = compat.UniqueFrozenset([
1271
  OOB_POWER_ON,
1272
  OOB_POWER_OFF,
1273
  OOB_POWER_CYCLE,
1274
  OOB_POWER_STATUS,
1275
  OOB_HEALTH,
1276
  ])
1277

    
1278
OOB_POWER_STATUS_POWERED = "powered"
1279

    
1280
OOB_TIMEOUT = 60 # 60 seconds
1281
OOB_POWER_DELAY = 2.0 # 2 seconds
1282

    
1283
OOB_STATUS_OK = "OK"
1284
OOB_STATUS_WARNING = "WARNING"
1285
OOB_STATUS_CRITICAL = "CRITICAL"
1286
OOB_STATUS_UNKNOWN = "UNKNOWN"
1287

    
1288
OOB_STATUSES = compat.UniqueFrozenset([
1289
  OOB_STATUS_OK,
1290
  OOB_STATUS_WARNING,
1291
  OOB_STATUS_CRITICAL,
1292
  OOB_STATUS_UNKNOWN,
1293
  ])
1294

    
1295
# Instance Parameters Profile
1296
PP_DEFAULT = "default"
1297

    
1298
# NIC_* constants are used inside the ganeti config
1299
NIC_MODE = "mode"
1300
NIC_LINK = "link"
1301

    
1302
NIC_MODE_BRIDGED = "bridged"
1303
NIC_MODE_ROUTED = "routed"
1304
NIC_MODE_OVS = "openvswitch"
1305
NIC_IP_POOL = "pool"
1306

    
1307
NIC_VALID_MODES = compat.UniqueFrozenset([
1308
  NIC_MODE_BRIDGED,
1309
  NIC_MODE_ROUTED,
1310
  NIC_MODE_OVS,
1311
  ])
1312

    
1313
RESERVE_ACTION = "reserve"
1314
RELEASE_ACTION = "release"
1315

    
1316
NICS_PARAMETER_TYPES = {
1317
  NIC_MODE: VTYPE_STRING,
1318
  NIC_LINK: VTYPE_STRING,
1319
  }
1320

    
1321
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
1322

    
1323
# IDISK_* constants are used in opcodes, to create/change disks
1324
IDISK_SIZE = "size"
1325
IDISK_MODE = "mode"
1326
IDISK_ADOPT = "adopt"
1327
IDISK_VG = "vg"
1328
IDISK_METAVG = "metavg"
1329
IDISK_PROVIDER = "provider"
1330
IDISK_PARAMS_TYPES = {
1331
  IDISK_SIZE: VTYPE_SIZE,
1332
  IDISK_MODE: VTYPE_STRING,
1333
  IDISK_ADOPT: VTYPE_STRING,
1334
  IDISK_VG: VTYPE_STRING,
1335
  IDISK_METAVG: VTYPE_STRING,
1336
  IDISK_PROVIDER: VTYPE_STRING,
1337
  }
1338
IDISK_PARAMS = frozenset(IDISK_PARAMS_TYPES.keys())
1339

    
1340
# INIC_* constants are used in opcodes, to create/change nics
1341
INIC_MAC = "mac"
1342
INIC_IP = "ip"
1343
INIC_MODE = "mode"
1344
INIC_LINK = "link"
1345
INIC_NETWORK = "network"
1346
INIC_PARAMS_TYPES = {
1347
  INIC_IP: VTYPE_MAYBE_STRING,
1348
  INIC_LINK: VTYPE_STRING,
1349
  INIC_MAC: VTYPE_STRING,
1350
  INIC_MODE: VTYPE_STRING,
1351
  INIC_NETWORK: VTYPE_MAYBE_STRING,
1352
  }
1353
INIC_PARAMS = frozenset(INIC_PARAMS_TYPES.keys())
1354

    
1355
# Hypervisor constants
1356
HT_XEN_PVM = "xen-pvm"
1357
HT_FAKE = "fake"
1358
HT_XEN_HVM = "xen-hvm"
1359
HT_KVM = "kvm"
1360
HT_CHROOT = "chroot"
1361
HT_LXC = "lxc"
1362
HYPER_TYPES = compat.UniqueFrozenset([
1363
  HT_XEN_PVM,
1364
  HT_FAKE,
1365
  HT_XEN_HVM,
1366
  HT_KVM,
1367
  HT_CHROOT,
1368
  HT_LXC,
1369
  ])
1370
HTS_REQ_PORT = compat.UniqueFrozenset([HT_XEN_HVM, HT_KVM])
1371

    
1372
VNC_BASE_PORT = 5900
1373
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
1374

    
1375
# NIC types
1376
HT_NIC_RTL8139 = "rtl8139"
1377
HT_NIC_NE2K_PCI = "ne2k_pci"
1378
HT_NIC_NE2K_ISA = "ne2k_isa"
1379
HT_NIC_I82551 = "i82551"
1380
HT_NIC_I85557B = "i82557b"
1381
HT_NIC_I8259ER = "i82559er"
1382
HT_NIC_PCNET = "pcnet"
1383
HT_NIC_E1000 = "e1000"
1384
HT_NIC_PARAVIRTUAL = HT_DISK_PARAVIRTUAL = "paravirtual"
1385

    
1386
HT_HVM_VALID_NIC_TYPES = compat.UniqueFrozenset([
1387
  HT_NIC_RTL8139,
1388
  HT_NIC_NE2K_PCI,
1389
  HT_NIC_E1000,
1390
  HT_NIC_NE2K_ISA,
1391
  HT_NIC_PARAVIRTUAL,
1392
  ])
1393
HT_KVM_VALID_NIC_TYPES = compat.UniqueFrozenset([
1394
  HT_NIC_RTL8139,
1395
  HT_NIC_NE2K_PCI,
1396
  HT_NIC_NE2K_ISA,
1397
  HT_NIC_I82551,
1398
  HT_NIC_I85557B,
1399
  HT_NIC_I8259ER,
1400
  HT_NIC_PCNET,
1401
  HT_NIC_E1000,
1402
  HT_NIC_PARAVIRTUAL,
1403
  ])
1404

    
1405
# Disk types
1406
HT_DISK_IOEMU = "ioemu"
1407
HT_DISK_IDE = "ide"
1408
HT_DISK_SCSI = "scsi"
1409
HT_DISK_SD = "sd"
1410
HT_DISK_MTD = "mtd"
1411
HT_DISK_PFLASH = "pflash"
1412

    
1413
HT_CACHE_DEFAULT = "default"
1414
HT_CACHE_NONE = "none"
1415
HT_CACHE_WTHROUGH = "writethrough"
1416
HT_CACHE_WBACK = "writeback"
1417
HT_VALID_CACHE_TYPES = compat.UniqueFrozenset([
1418
  HT_CACHE_DEFAULT,
1419
  HT_CACHE_NONE,
1420
  HT_CACHE_WTHROUGH,
1421
  HT_CACHE_WBACK,
1422
  ])
1423

    
1424
HT_HVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1425
  HT_DISK_PARAVIRTUAL,
1426
  HT_DISK_IOEMU,
1427
  ])
1428
HT_KVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1429
  HT_DISK_PARAVIRTUAL,
1430
  HT_DISK_IDE,
1431
  HT_DISK_SCSI,
1432
  HT_DISK_SD,
1433
  HT_DISK_MTD,
1434
  HT_DISK_PFLASH,
1435
  ])
1436

    
1437
# Mouse types:
1438
HT_MOUSE_MOUSE = "mouse"
1439
HT_MOUSE_TABLET = "tablet"
1440

    
1441
HT_KVM_VALID_MOUSE_TYPES = compat.UniqueFrozenset([
1442
  HT_MOUSE_MOUSE,
1443
  HT_MOUSE_TABLET,
1444
  ])
1445

    
1446
# Boot order
1447
HT_BO_FLOPPY = "floppy"
1448
HT_BO_CDROM = "cdrom"
1449
HT_BO_DISK = "disk"
1450
HT_BO_NETWORK = "network"
1451

    
1452
HT_KVM_VALID_BO_TYPES = compat.UniqueFrozenset([
1453
  HT_BO_FLOPPY,
1454
  HT_BO_CDROM,
1455
  HT_BO_DISK,
1456
  HT_BO_NETWORK,
1457
  ])
1458

    
1459
# SPICE lossless image compression options
1460
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ = "auto_glz"
1461
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ = "auto_lz"
1462
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC = "quic"
1463
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ = "glz"
1464
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ = "lz"
1465
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF = "off"
1466

    
1467
HT_KVM_SPICE_VALID_LOSSLESS_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1468
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ,
1469
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ,
1470
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC,
1471
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ,
1472
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ,
1473
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF,
1474
  ])
1475

    
1476
# SPICE lossy image compression options (valid for both jpeg and zlib-glz)
1477
HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO = "auto"
1478
HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER = "never"
1479
HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS = "always"
1480

    
1481
HT_KVM_SPICE_VALID_LOSSY_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1482
  HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO,
1483
  HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER,
1484
  HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS,
1485
  ])
1486

    
1487
# SPICE video stream detection
1488
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF = "off"
1489
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL = "all"
1490
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER = "filter"
1491

    
1492
HT_KVM_SPICE_VALID_VIDEO_STREAM_DETECTION_OPTIONS = compat.UniqueFrozenset([
1493
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF,
1494
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL,
1495
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER,
1496
  ])
1497

    
1498
# Security models
1499
HT_SM_NONE = "none"
1500
HT_SM_USER = "user"
1501
HT_SM_POOL = "pool"
1502

    
1503
HT_KVM_VALID_SM_TYPES = compat.UniqueFrozenset([
1504
  HT_SM_NONE,
1505
  HT_SM_USER,
1506
  HT_SM_POOL,
1507
  ])
1508

    
1509
# Kvm flag values
1510
HT_KVM_ENABLED = "enabled"
1511
HT_KVM_DISABLED = "disabled"
1512

    
1513
HT_KVM_FLAG_VALUES = compat.UniqueFrozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
1514

    
1515
# Migration type
1516
HT_MIGRATION_LIVE = "live"
1517
HT_MIGRATION_NONLIVE = "non-live"
1518
HT_MIGRATION_MODES = compat.UniqueFrozenset([
1519
  HT_MIGRATION_LIVE,
1520
  HT_MIGRATION_NONLIVE,
1521
  ])
1522

    
1523
# Cluster Verify steps
1524
VERIFY_NPLUSONE_MEM = "nplusone_mem"
1525
VERIFY_OPTIONAL_CHECKS = compat.UniqueFrozenset([VERIFY_NPLUSONE_MEM])
1526

    
1527
# Cluster Verify error classes
1528
CV_TCLUSTER = "cluster"
1529
CV_TGROUP = "group"
1530
CV_TNODE = "node"
1531
CV_TINSTANCE = "instance"
1532

    
1533
# Cluster Verify error codes and documentation
1534
CV_ECLUSTERCFG = \
1535
  (CV_TCLUSTER, "ECLUSTERCFG", "Cluster configuration verification failure")
1536
CV_ECLUSTERCERT = \
1537
  (CV_TCLUSTER, "ECLUSTERCERT",
1538
   "Cluster certificate files verification failure")
1539
CV_ECLUSTERFILECHECK = \
1540
  (CV_TCLUSTER, "ECLUSTERFILECHECK",
1541
   "Cluster configuration verification failure")
1542
CV_ECLUSTERDANGLINGNODES = \
1543
  (CV_TNODE, "ECLUSTERDANGLINGNODES",
1544
   "Some nodes belong to non-existing groups")
1545
CV_ECLUSTERDANGLINGINST = \
1546
  (CV_TNODE, "ECLUSTERDANGLINGINST",
1547
   "Some instances have a non-existing primary node")
1548
CV_EGROUPDIFFERENTPVSIZE = \
1549
  (CV_TGROUP, "EGROUPDIFFERENTPVSIZE", "PVs in the group have different sizes")
1550
CV_EINSTANCEBADNODE = \
1551
  (CV_TINSTANCE, "EINSTANCEBADNODE",
1552
   "Instance marked as running lives on an offline node")
1553
CV_EINSTANCEDOWN = \
1554
  (CV_TINSTANCE, "EINSTANCEDOWN", "Instance not running on its primary node")
1555
CV_EINSTANCELAYOUT = \
1556
  (CV_TINSTANCE, "EINSTANCELAYOUT", "Instance has multiple secondary nodes")
1557
CV_EINSTANCEMISSINGDISK = \
1558
  (CV_TINSTANCE, "EINSTANCEMISSINGDISK", "Missing volume on an instance")
1559
CV_EINSTANCEFAULTYDISK = \
1560
  (CV_TINSTANCE, "EINSTANCEFAULTYDISK",
1561
   "Impossible to retrieve status for a disk")
1562
CV_EINSTANCEWRONGNODE = \
1563
  (CV_TINSTANCE, "EINSTANCEWRONGNODE", "Instance running on the wrong node")
1564
CV_EINSTANCESPLITGROUPS = \
1565
  (CV_TINSTANCE, "EINSTANCESPLITGROUPS",
1566
   "Instance with primary and secondary nodes in different groups")
1567
CV_EINSTANCEPOLICY = \
1568
  (CV_TINSTANCE, "EINSTANCEPOLICY",
1569
   "Instance does not meet policy")
1570
CV_EINSTANCEUNSUITABLENODE = \
1571
  (CV_TINSTANCE, "EINSTANCEUNSUITABLENODE",
1572
   "Instance running on nodes that are not suitable for it")
1573
CV_ENODEDRBD = \
1574
  (CV_TNODE, "ENODEDRBD", "Error parsing the DRBD status file")
1575
CV_ENODEDRBDHELPER = \
1576
  (CV_TNODE, "ENODEDRBDHELPER", "Error caused by the DRBD helper")
1577
CV_ENODEFILECHECK = \
1578
  (CV_TNODE, "ENODEFILECHECK",
1579
   "Error retrieving the checksum of the node files")
1580
CV_ENODEHOOKS = \
1581
  (CV_TNODE, "ENODEHOOKS", "Communication failure in hooks execution")
1582
CV_ENODEHV = \
1583
  (CV_TNODE, "ENODEHV", "Hypervisor parameters verification failure")
1584
CV_ENODELVM = \
1585
  (CV_TNODE, "ENODELVM", "LVM-related node error")
1586
CV_ENODEN1 = \
1587
  (CV_TNODE, "ENODEN1", "Not enough memory to accommodate instance failovers")
1588
CV_ENODENET = \
1589
  (CV_TNODE, "ENODENET", "Network-related node error")
1590
CV_ENODEOS = \
1591
  (CV_TNODE, "ENODEOS", "OS-related node error")
1592
CV_ENODEORPHANINSTANCE = \
1593
  (CV_TNODE, "ENODEORPHANINSTANCE", "Unknown intance running on a node")
1594
CV_ENODEORPHANLV = \
1595
  (CV_TNODE, "ENODEORPHANLV", "Unknown LVM logical volume")
1596
CV_ENODERPC = \
1597
  (CV_TNODE, "ENODERPC",
1598
   "Error during connection to the primary node of an instance")
1599
CV_ENODESSH = \
1600
  (CV_TNODE, "ENODESSH", "SSH-related node error")
1601
CV_ENODEVERSION = \
1602
  (CV_TNODE, "ENODEVERSION",
1603
   "Protocol version mismatch or Ganeti version mismatch")
1604
CV_ENODESETUP = \
1605
  (CV_TNODE, "ENODESETUP", "Node setup error")
1606
CV_ENODETIME = \
1607
  (CV_TNODE, "ENODETIME", "Node returned invalid time")
1608
CV_ENODEOOBPATH = \
1609
  (CV_TNODE, "ENODEOOBPATH", "Invalid Out Of Band path")
1610
CV_ENODEUSERSCRIPTS = \
1611
  (CV_TNODE, "ENODEUSERSCRIPTS", "User scripts not present or not executable")
1612
CV_ENODEFILESTORAGEPATHS = \
1613
  (CV_TNODE, "ENODEFILESTORAGEPATHS", "Detected bad file storage paths")
1614

    
1615
CV_ALL_ECODES = compat.UniqueFrozenset([
1616
  CV_ECLUSTERCFG,
1617
  CV_ECLUSTERCERT,
1618
  CV_ECLUSTERFILECHECK,
1619
  CV_ECLUSTERDANGLINGNODES,
1620
  CV_ECLUSTERDANGLINGINST,
1621
  CV_EINSTANCEBADNODE,
1622
  CV_EINSTANCEDOWN,
1623
  CV_EINSTANCELAYOUT,
1624
  CV_EINSTANCEMISSINGDISK,
1625
  CV_EINSTANCEFAULTYDISK,
1626
  CV_EINSTANCEWRONGNODE,
1627
  CV_EINSTANCESPLITGROUPS,
1628
  CV_EINSTANCEPOLICY,
1629
  CV_ENODEDRBD,
1630
  CV_ENODEDRBDHELPER,
1631
  CV_ENODEFILECHECK,
1632
  CV_ENODEHOOKS,
1633
  CV_ENODEHV,
1634
  CV_ENODELVM,
1635
  CV_ENODEN1,
1636
  CV_ENODENET,
1637
  CV_ENODEOS,
1638
  CV_ENODEORPHANINSTANCE,
1639
  CV_ENODEORPHANLV,
1640
  CV_ENODERPC,
1641
  CV_ENODESSH,
1642
  CV_ENODEVERSION,
1643
  CV_ENODESETUP,
1644
  CV_ENODETIME,
1645
  CV_ENODEOOBPATH,
1646
  CV_ENODEUSERSCRIPTS,
1647
  CV_ENODEFILESTORAGEPATHS,
1648
  ])
1649

    
1650
CV_ALL_ECODES_STRINGS = \
1651
  compat.UniqueFrozenset(estr for (_, estr, _) in CV_ALL_ECODES)
1652

    
1653
# Node verify constants
1654
NV_BRIDGES = "bridges"
1655
NV_DRBDHELPER = "drbd-helper"
1656
NV_DRBDLIST = "drbd-list"
1657
NV_EXCLUSIVEPVS = "exclusive-pvs"
1658
NV_FILELIST = "filelist"
1659
NV_FILE_STORAGE_PATHS = "file-storage-paths"
1660
NV_HVINFO = "hvinfo"
1661
NV_HVPARAMS = "hvparms"
1662
NV_HYPERVISOR = "hypervisor"
1663
NV_INSTANCELIST = "instancelist"
1664
NV_LVLIST = "lvlist"
1665
NV_MASTERIP = "master-ip"
1666
NV_NODELIST = "nodelist"
1667
NV_NODENETTEST = "node-net-test"
1668
NV_NODESETUP = "nodesetup"
1669
NV_OOB_PATHS = "oob-paths"
1670
NV_OSLIST = "oslist"
1671
NV_PVLIST = "pvlist"
1672
NV_TIME = "time"
1673
NV_USERSCRIPTS = "user-scripts"
1674
NV_VERSION = "version"
1675
NV_VGLIST = "vglist"
1676
NV_VMNODES = "vmnodes"
1677

    
1678
# Instance status
1679
INSTST_RUNNING = "running"
1680
INSTST_ADMINDOWN = "ADMIN_down"
1681
INSTST_ADMINOFFLINE = "ADMIN_offline"
1682
INSTST_NODEOFFLINE = "ERROR_nodeoffline"
1683
INSTST_NODEDOWN = "ERROR_nodedown"
1684
INSTST_WRONGNODE = "ERROR_wrongnode"
1685
INSTST_ERRORUP = "ERROR_up"
1686
INSTST_ERRORDOWN = "ERROR_down"
1687
INSTST_ALL = compat.UniqueFrozenset([
1688
  INSTST_RUNNING,
1689
  INSTST_ADMINDOWN,
1690
  INSTST_ADMINOFFLINE,
1691
  INSTST_NODEOFFLINE,
1692
  INSTST_NODEDOWN,
1693
  INSTST_WRONGNODE,
1694
  INSTST_ERRORUP,
1695
  INSTST_ERRORDOWN,
1696
  ])
1697

    
1698
# Admin states
1699
ADMINST_UP = "up"
1700
ADMINST_DOWN = "down"
1701
ADMINST_OFFLINE = "offline"
1702
ADMINST_ALL = compat.UniqueFrozenset([
1703
  ADMINST_UP,
1704
  ADMINST_DOWN,
1705
  ADMINST_OFFLINE,
1706
  ])
1707

    
1708
# Node roles
1709
NR_REGULAR = "R"
1710
NR_MASTER = "M"
1711
NR_MCANDIDATE = "C"
1712
NR_DRAINED = "D"
1713
NR_OFFLINE = "O"
1714
NR_ALL = compat.UniqueFrozenset([
1715
  NR_REGULAR,
1716
  NR_MASTER,
1717
  NR_MCANDIDATE,
1718
  NR_DRAINED,
1719
  NR_OFFLINE,
1720
  ])
1721

    
1722
# SSL certificate check constants (in days)
1723
SSL_CERT_EXPIRATION_WARN = 30
1724
SSL_CERT_EXPIRATION_ERROR = 7
1725

    
1726
# Allocator framework constants
1727
IALLOCATOR_VERSION = 2
1728
IALLOCATOR_DIR_IN = "in"
1729
IALLOCATOR_DIR_OUT = "out"
1730
VALID_IALLOCATOR_DIRECTIONS = compat.UniqueFrozenset([
1731
  IALLOCATOR_DIR_IN,
1732
  IALLOCATOR_DIR_OUT,
1733
  ])
1734
IALLOCATOR_MODE_ALLOC = "allocate"
1735
IALLOCATOR_MODE_RELOC = "relocate"
1736
IALLOCATOR_MODE_CHG_GROUP = "change-group"
1737
IALLOCATOR_MODE_NODE_EVAC = "node-evacuate"
1738
IALLOCATOR_MODE_MULTI_ALLOC = "multi-allocate"
1739
VALID_IALLOCATOR_MODES = compat.UniqueFrozenset([
1740
  IALLOCATOR_MODE_ALLOC,
1741
  IALLOCATOR_MODE_RELOC,
1742
  IALLOCATOR_MODE_CHG_GROUP,
1743
  IALLOCATOR_MODE_NODE_EVAC,
1744
  IALLOCATOR_MODE_MULTI_ALLOC,
1745
  ])
1746
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
1747
DEFAULT_IALLOCATOR_SHORTCUT = "."
1748

    
1749
IALLOCATOR_NEVAC_PRI = "primary-only"
1750
IALLOCATOR_NEVAC_SEC = "secondary-only"
1751
IALLOCATOR_NEVAC_ALL = "all"
1752
IALLOCATOR_NEVAC_MODES = compat.UniqueFrozenset([
1753
  IALLOCATOR_NEVAC_PRI,
1754
  IALLOCATOR_NEVAC_SEC,
1755
  IALLOCATOR_NEVAC_ALL,
1756
  ])
1757

    
1758
# Node evacuation
1759
NODE_EVAC_PRI = "primary-only"
1760
NODE_EVAC_SEC = "secondary-only"
1761
NODE_EVAC_ALL = "all"
1762
NODE_EVAC_MODES = compat.UniqueFrozenset([
1763
  NODE_EVAC_PRI,
1764
  NODE_EVAC_SEC,
1765
  NODE_EVAC_ALL,
1766
  ])
1767

    
1768
# Job queue
1769
JOB_QUEUE_VERSION = 1
1770
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
1771

    
1772
JOB_ID_TEMPLATE = r"\d+"
1773
JOB_FILE_RE = re.compile(r"^job-(%s)$" % JOB_ID_TEMPLATE)
1774

    
1775
# unchanged job return
1776
JOB_NOTCHANGED = "nochange"
1777

    
1778
# Job status
1779
JOB_STATUS_QUEUED = "queued"
1780
JOB_STATUS_WAITING = "waiting"
1781
JOB_STATUS_CANCELING = "canceling"
1782
JOB_STATUS_RUNNING = "running"
1783
JOB_STATUS_CANCELED = "canceled"
1784
JOB_STATUS_SUCCESS = "success"
1785
JOB_STATUS_ERROR = "error"
1786
JOBS_PENDING = compat.UniqueFrozenset([
1787
  JOB_STATUS_QUEUED,
1788
  JOB_STATUS_WAITING,
1789
  JOB_STATUS_CANCELING,
1790
  ])
1791
JOBS_FINALIZED = compat.UniqueFrozenset([
1792
  JOB_STATUS_CANCELED,
1793
  JOB_STATUS_SUCCESS,
1794
  JOB_STATUS_ERROR,
1795
  ])
1796
JOB_STATUS_ALL = compat.UniqueFrozenset([
1797
  JOB_STATUS_RUNNING,
1798
  ]) | JOBS_PENDING | JOBS_FINALIZED
1799

    
1800
# OpCode status
1801
# not yet finalized
1802
OP_STATUS_QUEUED = "queued"
1803
OP_STATUS_WAITING = "waiting"
1804
OP_STATUS_CANCELING = "canceling"
1805
OP_STATUS_RUNNING = "running"
1806
# finalized
1807
OP_STATUS_CANCELED = "canceled"
1808
OP_STATUS_SUCCESS = "success"
1809
OP_STATUS_ERROR = "error"
1810
OPS_FINALIZED = compat.UniqueFrozenset([
1811
  OP_STATUS_CANCELED,
1812
  OP_STATUS_SUCCESS,
1813
  OP_STATUS_ERROR,
1814
  ])
1815

    
1816
# OpCode priority
1817
OP_PRIO_LOWEST = +19
1818
OP_PRIO_HIGHEST = -20
1819

    
1820
OP_PRIO_LOW = +10
1821
OP_PRIO_NORMAL = 0
1822
OP_PRIO_HIGH = -10
1823

    
1824
OP_PRIO_SUBMIT_VALID = compat.UniqueFrozenset([
1825
  OP_PRIO_LOW,
1826
  OP_PRIO_NORMAL,
1827
  OP_PRIO_HIGH,
1828
  ])
1829

    
1830
OP_PRIO_DEFAULT = OP_PRIO_NORMAL
1831

    
1832
# Lock recalculate mode
1833
LOCKS_REPLACE = "replace"
1834
LOCKS_APPEND = "append"
1835

    
1836
# Lock timeout (sum) before we should go into blocking acquire (still
1837
# can be reset by priority change); computed as max time (10 hours)
1838
# before we should actually go into blocking acquire given that we
1839
# start from default priority level; in seconds
1840
# TODO
1841
LOCK_ATTEMPTS_TIMEOUT = 10 * 3600 / (OP_PRIO_DEFAULT - OP_PRIO_HIGHEST)
1842
LOCK_ATTEMPTS_MAXWAIT = 15.0
1843
LOCK_ATTEMPTS_MINWAIT = 1.0
1844

    
1845
# Execution log types
1846
ELOG_MESSAGE = "message"
1847
ELOG_REMOTE_IMPORT = "remote-import"
1848
ELOG_JQUEUE_TEST = "jqueue-test"
1849

    
1850
# /etc/hosts modification
1851
ETC_HOSTS_ADD = "add"
1852
ETC_HOSTS_REMOVE = "remove"
1853

    
1854
# Job queue test
1855
JQT_MSGPREFIX = "TESTMSG="
1856
JQT_EXPANDNAMES = "expandnames"
1857
JQT_EXEC = "exec"
1858
JQT_LOGMSG = "logmsg"
1859
JQT_STARTMSG = "startmsg"
1860
JQT_ALL = compat.UniqueFrozenset([
1861
  JQT_EXPANDNAMES,
1862
  JQT_EXEC,
1863
  JQT_LOGMSG,
1864
  JQT_STARTMSG,
1865
  ])
1866

    
1867
# Query resources
1868
QR_CLUSTER = "cluster"
1869
QR_INSTANCE = "instance"
1870
QR_NODE = "node"
1871
QR_LOCK = "lock"
1872
QR_GROUP = "group"
1873
QR_OS = "os"
1874
QR_JOB = "job"
1875
QR_EXPORT = "export"
1876
QR_NETWORK = "network"
1877
QR_EXTSTORAGE = "extstorage"
1878

    
1879
#: List of resources which can be queried using L{opcodes.OpQuery}
1880
QR_VIA_OP = compat.UniqueFrozenset([
1881
  QR_CLUSTER,
1882
  QR_INSTANCE,
1883
  QR_NODE,
1884
  QR_GROUP,
1885
  QR_OS,
1886
  QR_EXPORT,
1887
  QR_NETWORK,
1888
  QR_EXTSTORAGE,
1889
  ])
1890

    
1891
#: List of resources which can be queried using Local UniX Interface
1892
QR_VIA_LUXI = QR_VIA_OP.union([
1893
  QR_LOCK,
1894
  QR_JOB,
1895
  ])
1896

    
1897
#: List of resources which can be queried using RAPI
1898
QR_VIA_RAPI = QR_VIA_LUXI
1899

    
1900
# Query field types
1901
QFT_UNKNOWN = "unknown"
1902
QFT_TEXT = "text"
1903
QFT_BOOL = "bool"
1904
QFT_NUMBER = "number"
1905
QFT_UNIT = "unit"
1906
QFT_TIMESTAMP = "timestamp"
1907
QFT_OTHER = "other"
1908

    
1909
#: All query field types
1910
QFT_ALL = compat.UniqueFrozenset([
1911
  QFT_UNKNOWN,
1912
  QFT_TEXT,
1913
  QFT_BOOL,
1914
  QFT_NUMBER,
1915
  QFT_UNIT,
1916
  QFT_TIMESTAMP,
1917
  QFT_OTHER,
1918
  ])
1919

    
1920
# Query result field status (don't change or reuse values as they're used by
1921
# clients)
1922
#: Normal field status
1923
RS_NORMAL = 0
1924
#: Unknown field
1925
RS_UNKNOWN = 1
1926
#: No data (e.g. RPC error), can be used instead of L{RS_OFFLINE}
1927
RS_NODATA = 2
1928
#: Value unavailable/unsupported for item; if this field is supported
1929
#: but we cannot get the data for the moment, RS_NODATA or
1930
#: RS_OFFLINE should be used
1931
RS_UNAVAIL = 3
1932
#: Resource marked offline
1933
RS_OFFLINE = 4
1934

    
1935
RS_ALL = compat.UniqueFrozenset([
1936
  RS_NORMAL,
1937
  RS_UNKNOWN,
1938
  RS_NODATA,
1939
  RS_UNAVAIL,
1940
  RS_OFFLINE,
1941
  ])
1942

    
1943
#: Dictionary with special field cases and their verbose/terse formatting
1944
RSS_DESCRIPTION = {
1945
  RS_UNKNOWN: ("(unknown)", "??"),
1946
  RS_NODATA: ("(nodata)", "?"),
1947
  RS_OFFLINE: ("(offline)", "*"),
1948
  RS_UNAVAIL: ("(unavail)", "-"),
1949
  }
1950

    
1951
# max dynamic devices
1952
MAX_NICS = 8
1953
MAX_DISKS = 16
1954

    
1955
# SSCONF file prefix
1956
SSCONF_FILEPREFIX = "ssconf_"
1957
# SSCONF keys
1958
SS_CLUSTER_NAME = "cluster_name"
1959
SS_CLUSTER_TAGS = "cluster_tags"
1960
SS_FILE_STORAGE_DIR = "file_storage_dir"
1961
SS_SHARED_FILE_STORAGE_DIR = "shared_file_storage_dir"
1962
SS_MASTER_CANDIDATES = "master_candidates"
1963
SS_MASTER_CANDIDATES_IPS = "master_candidates_ips"
1964
SS_MASTER_IP = "master_ip"
1965
SS_MASTER_NETDEV = "master_netdev"
1966
SS_MASTER_NETMASK = "master_netmask"
1967
SS_MASTER_NODE = "master_node"
1968
SS_NODE_LIST = "node_list"
1969
SS_NODE_PRIMARY_IPS = "node_primary_ips"
1970
SS_NODE_SECONDARY_IPS = "node_secondary_ips"
1971
SS_OFFLINE_NODES = "offline_nodes"
1972
SS_ONLINE_NODES = "online_nodes"
1973
SS_PRIMARY_IP_FAMILY = "primary_ip_family"
1974
SS_INSTANCE_LIST = "instance_list"
1975
SS_RELEASE_VERSION = "release_version"
1976
SS_HYPERVISOR_LIST = "hypervisor_list"
1977
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
1978
SS_UID_POOL = "uid_pool"
1979
SS_NODEGROUPS = "nodegroups"
1980
SS_NETWORKS = "networks"
1981

    
1982
SS_FILE_PERMS = 0444
1983

    
1984
# cluster wide default parameters
1985
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
1986

    
1987
HVC_DEFAULTS = {
1988
  HT_XEN_PVM: {
1989
    HV_USE_BOOTLOADER: False,
1990
    HV_BOOTLOADER_PATH: XEN_BOOTLOADER,
1991
    HV_BOOTLOADER_ARGS: "",
1992
    HV_KERNEL_PATH: XEN_KERNEL,
1993
    HV_INITRD_PATH: "",
1994
    HV_ROOT_PATH: "/dev/xvda1",
1995
    HV_KERNEL_ARGS: "ro",
1996
    HV_MIGRATION_PORT: 8002,
1997
    HV_MIGRATION_MODE: HT_MIGRATION_LIVE,
1998
    HV_BLOCKDEV_PREFIX: "sd",
1999
    HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED,
2000
    HV_CPU_MASK: CPU_PINNING_ALL,
2001
    HV_CPU_CAP: 0,
2002
    HV_CPU_WEIGHT: 256,
2003
    },
2004
  HT_XEN_HVM: {
2005
    HV_BOOT_ORDER: "cd",
2006
    HV_CDROM_IMAGE_PATH: "",
2007
    HV_NIC_TYPE: HT_NIC_RTL8139,
2008
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
2009
    HV_VNC_BIND_ADDRESS: IP4_ADDRESS_ANY,
2010
    HV_VNC_PASSWORD_FILE: pathutils.VNC_PASSWORD_FILE,
2011
    HV_ACPI: True,
2012
    HV_PAE: True,
2013
    HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
2014
    HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
2015
    HV_MIGRATION_PORT: 8002,
2016
    HV_MIGRATION_MODE: HT_MIGRATION_NONLIVE,
2017
    HV_USE_LOCALTIME: False,
2018
    HV_BLOCKDEV_PREFIX: "hd",
2019
    HV_PASSTHROUGH: "",
2020
    HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED,
2021
    HV_CPU_MASK: CPU_PINNING_ALL,
2022
    HV_CPU_CAP: 0,
2023
    HV_CPU_WEIGHT: 256,
2024
    },
2025
  HT_KVM: {
2026
    HV_KVM_PATH: KVM_PATH,
2027
    HV_KERNEL_PATH: KVM_KERNEL,
2028
    HV_INITRD_PATH: "",
2029
    HV_KERNEL_ARGS: "ro",
2030
    HV_ROOT_PATH: "/dev/vda1",
2031
    HV_ACPI: True,
2032
    HV_SERIAL_CONSOLE: True,
2033
    HV_SERIAL_SPEED: 38400,
2034
    HV_VNC_BIND_ADDRESS: "",
2035
    HV_VNC_TLS: False,
2036
    HV_VNC_X509: "",
2037
    HV_VNC_X509_VERIFY: False,
2038
    HV_VNC_PASSWORD_FILE: "",
2039
    HV_KVM_SPICE_BIND: "",
2040
    HV_KVM_SPICE_IP_VERSION: IFACE_NO_IP_VERSION_SPECIFIED,
2041
    HV_KVM_SPICE_PASSWORD_FILE: "",
2042
    HV_KVM_SPICE_LOSSLESS_IMG_COMPR: "",
2043
    HV_KVM_SPICE_JPEG_IMG_COMPR: "",
2044
    HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR: "",
2045
    HV_KVM_SPICE_STREAMING_VIDEO_DETECTION: "",
2046
    HV_KVM_SPICE_AUDIO_COMPR: True,
2047
    HV_KVM_SPICE_USE_TLS: False,
2048
    HV_KVM_SPICE_TLS_CIPHERS: OPENSSL_CIPHERS,
2049
    HV_KVM_SPICE_USE_VDAGENT: True,
2050
    HV_KVM_FLOPPY_IMAGE_PATH: "",
2051
    HV_CDROM_IMAGE_PATH: "",
2052
    HV_KVM_CDROM2_IMAGE_PATH: "",
2053
    HV_BOOT_ORDER: HT_BO_DISK,
2054
    HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
2055
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
2056
    HV_KVM_CDROM_DISK_TYPE: "",
2057
    HV_USB_MOUSE: "",
2058
    HV_KEYMAP: "",
2059
    HV_MIGRATION_PORT: 8102,
2060
    HV_MIGRATION_BANDWIDTH: 32, # MiB/s
2061
    HV_MIGRATION_DOWNTIME: 30,  # ms
2062
    HV_MIGRATION_MODE: HT_MIGRATION_LIVE,
2063
    HV_USE_LOCALTIME: False,
2064
    HV_DISK_CACHE: HT_CACHE_DEFAULT,
2065
    HV_SECURITY_MODEL: HT_SM_NONE,
2066
    HV_SECURITY_DOMAIN: "",
2067
    HV_KVM_FLAG: "",
2068
    HV_VHOST_NET: False,
2069
    HV_KVM_USE_CHROOT: False,
2070
    HV_MEM_PATH: "",
2071
    HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED,
2072
    HV_CPU_MASK: CPU_PINNING_ALL,
2073
    HV_CPU_TYPE: "",
2074
    HV_CPU_CORES: 0,
2075
    HV_CPU_THREADS: 0,
2076
    HV_CPU_SOCKETS: 0,
2077
    HV_SOUNDHW: "",
2078
    HV_USB_DEVICES: "",
2079
    HV_VGA: "",
2080
    HV_KVM_EXTRA: "",
2081
    HV_KVM_MACHINE_VERSION: "",
2082
    },
2083
  HT_FAKE: {},
2084
  HT_CHROOT: {
2085
    HV_INIT_SCRIPT: "/ganeti-chroot",
2086
    },
2087
  HT_LXC: {
2088
    HV_CPU_MASK: "",
2089
    },
2090
  }
2091

    
2092
HVC_GLOBALS = compat.UniqueFrozenset([
2093
  HV_MIGRATION_PORT,
2094
  HV_MIGRATION_BANDWIDTH,
2095
  HV_MIGRATION_MODE,
2096
  ])
2097

    
2098
BEC_DEFAULTS = {
2099
  BE_MINMEM: 128,
2100
  BE_MAXMEM: 128,
2101
  BE_VCPUS: 1,
2102
  BE_AUTO_BALANCE: True,
2103
  BE_ALWAYS_FAILOVER: False,
2104
  BE_SPINDLE_USE: 1,
2105
  }
2106

    
2107
NDC_DEFAULTS = {
2108
  ND_OOB_PROGRAM: "",
2109
  ND_SPINDLE_COUNT: 1,
2110
  ND_EXCLUSIVE_STORAGE: False,
2111
  }
2112

    
2113
NDC_GLOBALS = compat.UniqueFrozenset([
2114
  ND_EXCLUSIVE_STORAGE,
2115
  ])
2116

    
2117
DISK_LD_DEFAULTS = {
2118
  LD_DRBD8: {
2119
    LDP_RESYNC_RATE: CLASSIC_DRBD_SYNC_SPEED,
2120
    LDP_BARRIERS: _autoconf.DRBD_BARRIERS,
2121
    LDP_NO_META_FLUSH: _autoconf.DRBD_NO_META_FLUSH,
2122
    LDP_DEFAULT_METAVG: DEFAULT_VG,
2123
    LDP_DISK_CUSTOM: "",
2124
    LDP_NET_CUSTOM: "",
2125
    LDP_DYNAMIC_RESYNC: False,
2126

    
2127
    # The default values for the DRBD dynamic resync speed algorithm
2128
    # are taken from the drbsetup 8.3.11 man page, except for
2129
    # c-plan-ahead (that we don't need to set to 0, because we have a
2130
    # separate option to enable it) and for c-max-rate, that we cap to
2131
    # the default value for the static resync rate.
2132
    LDP_PLAN_AHEAD: 20, # ds
2133
    LDP_FILL_TARGET: 0, # sectors
2134
    LDP_DELAY_TARGET: 1, # ds
2135
    LDP_MAX_RATE: CLASSIC_DRBD_SYNC_SPEED, # KiB/s
2136
    LDP_MIN_RATE: 4 * 1024, # KiB/s
2137
    },
2138
  LD_LV: {
2139
    LDP_STRIPES: _autoconf.LVM_STRIPECOUNT
2140
    },
2141
  LD_FILE: {},
2142
  LD_BLOCKDEV: {},
2143
  LD_RBD: {
2144
    LDP_POOL: "rbd"
2145
    },
2146
  LD_EXT: {},
2147
  }
2148

    
2149
# readability shortcuts
2150
_LV_DEFAULTS = DISK_LD_DEFAULTS[LD_LV]
2151
_DRBD_DEFAULTS = DISK_LD_DEFAULTS[LD_DRBD8]
2152

    
2153
DISK_DT_DEFAULTS = {
2154
  DT_PLAIN: {
2155
    LV_STRIPES: DISK_LD_DEFAULTS[LD_LV][LDP_STRIPES],
2156
    },
2157
  DT_DRBD8: {
2158
    DRBD_RESYNC_RATE: _DRBD_DEFAULTS[LDP_RESYNC_RATE],
2159
    DRBD_DATA_STRIPES: _LV_DEFAULTS[LDP_STRIPES],
2160
    DRBD_META_STRIPES: _LV_DEFAULTS[LDP_STRIPES],
2161
    DRBD_DISK_BARRIERS: _DRBD_DEFAULTS[LDP_BARRIERS],
2162
    DRBD_META_BARRIERS: _DRBD_DEFAULTS[LDP_NO_META_FLUSH],
2163
    DRBD_DEFAULT_METAVG: _DRBD_DEFAULTS[LDP_DEFAULT_METAVG],
2164
    DRBD_DISK_CUSTOM: _DRBD_DEFAULTS[LDP_DISK_CUSTOM],
2165
    DRBD_NET_CUSTOM: _DRBD_DEFAULTS[LDP_NET_CUSTOM],
2166
    DRBD_DYNAMIC_RESYNC: _DRBD_DEFAULTS[LDP_DYNAMIC_RESYNC],
2167
    DRBD_PLAN_AHEAD: _DRBD_DEFAULTS[LDP_PLAN_AHEAD],
2168
    DRBD_FILL_TARGET: _DRBD_DEFAULTS[LDP_FILL_TARGET],
2169
    DRBD_DELAY_TARGET: _DRBD_DEFAULTS[LDP_DELAY_TARGET],
2170
    DRBD_MAX_RATE: _DRBD_DEFAULTS[LDP_MAX_RATE],
2171
    DRBD_MIN_RATE: _DRBD_DEFAULTS[LDP_MIN_RATE],
2172
    },
2173
  DT_DISKLESS: {},
2174
  DT_FILE: {},
2175
  DT_SHARED_FILE: {},
2176
  DT_BLOCK: {},
2177
  DT_RBD: {
2178
    RBD_POOL: DISK_LD_DEFAULTS[LD_RBD][LDP_POOL]
2179
    },
2180
  DT_EXT: {},
2181
  }
2182

    
2183
# we don't want to export the shortcuts
2184
del _LV_DEFAULTS, _DRBD_DEFAULTS
2185

    
2186
NICC_DEFAULTS = {
2187
  NIC_MODE: NIC_MODE_BRIDGED,
2188
  NIC_LINK: DEFAULT_BRIDGE,
2189
  }
2190

    
2191
# All of the following values are quite arbitrarily - there are no
2192
# "good" defaults, these must be customised per-site
2193
ISPECS_MINMAX_DEFAULTS = {
2194
  ISPECS_MIN: {
2195
    ISPEC_MEM_SIZE: 128,
2196
    ISPEC_CPU_COUNT: 1,
2197
    ISPEC_DISK_COUNT: 1,
2198
    ISPEC_DISK_SIZE: 1024,
2199
    ISPEC_NIC_COUNT: 1,
2200
    ISPEC_SPINDLE_USE: 1,
2201
    },
2202
  ISPECS_MAX: {
2203
    ISPEC_MEM_SIZE: 32768,
2204
    ISPEC_CPU_COUNT: 8,
2205
    ISPEC_DISK_COUNT: MAX_DISKS,
2206
    ISPEC_DISK_SIZE: 1024 * 1024,
2207
    ISPEC_NIC_COUNT: MAX_NICS,
2208
    ISPEC_SPINDLE_USE: 12,
2209
    },
2210
  }
2211
IPOLICY_DEFAULTS = {
2212
  ISPECS_MINMAX: ISPECS_MINMAX_DEFAULTS,
2213
  ISPECS_STD: {
2214
    ISPEC_MEM_SIZE: 128,
2215
    ISPEC_CPU_COUNT: 1,
2216
    ISPEC_DISK_COUNT: 1,
2217
    ISPEC_DISK_SIZE: 1024,
2218
    ISPEC_NIC_COUNT: 1,
2219
    ISPEC_SPINDLE_USE: 1,
2220
    },
2221
  IPOLICY_DTS: list(DISK_TEMPLATES),
2222
  IPOLICY_VCPU_RATIO: 4.0,
2223
  IPOLICY_SPINDLE_RATIO: 32.0,
2224
  }
2225

    
2226
MASTER_POOL_SIZE_DEFAULT = 10
2227

    
2228
# Exclusive storage:
2229
# Error margin used to compare physical disks
2230
PART_MARGIN = .01
2231
# Space reserved when creating instance disks
2232
PART_RESERVED = .02
2233

    
2234
CONFD_PROTOCOL_VERSION = 1
2235

    
2236
CONFD_REQ_PING = 0
2237
CONFD_REQ_NODE_ROLE_BYNAME = 1
2238
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
2239
CONFD_REQ_CLUSTER_MASTER = 3
2240
CONFD_REQ_NODE_PIP_LIST = 4
2241
CONFD_REQ_MC_PIP_LIST = 5
2242
CONFD_REQ_INSTANCES_IPS_LIST = 6
2243
CONFD_REQ_NODE_DRBD = 7
2244
CONFD_REQ_NODE_INSTANCES = 8
2245

    
2246
# Confd request query fields. These are used to narrow down queries.
2247
# These must be strings rather than integers, because json-encoding
2248
# converts them to strings anyway, as they're used as dict-keys.
2249
CONFD_REQQ_LINK = "0"
2250
CONFD_REQQ_IP = "1"
2251
CONFD_REQQ_IPLIST = "2"
2252
CONFD_REQQ_FIELDS = "3"
2253

    
2254
CONFD_REQFIELD_NAME = "0"
2255
CONFD_REQFIELD_IP = "1"
2256
CONFD_REQFIELD_MNODE_PIP = "2"
2257

    
2258
CONFD_REQS = compat.UniqueFrozenset([
2259
  CONFD_REQ_PING,
2260
  CONFD_REQ_NODE_ROLE_BYNAME,
2261
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
2262
  CONFD_REQ_CLUSTER_MASTER,
2263
  CONFD_REQ_NODE_PIP_LIST,
2264
  CONFD_REQ_MC_PIP_LIST,
2265
  CONFD_REQ_INSTANCES_IPS_LIST,
2266
  CONFD_REQ_NODE_DRBD,
2267
  ])
2268

    
2269
CONFD_REPL_STATUS_OK = 0
2270
CONFD_REPL_STATUS_ERROR = 1
2271
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
2272

    
2273
CONFD_REPL_STATUSES = compat.UniqueFrozenset([
2274
  CONFD_REPL_STATUS_OK,
2275
  CONFD_REPL_STATUS_ERROR,
2276
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
2277
  ])
2278

    
2279
(CONFD_NODE_ROLE_MASTER,
2280
 CONFD_NODE_ROLE_CANDIDATE,
2281
 CONFD_NODE_ROLE_OFFLINE,
2282
 CONFD_NODE_ROLE_DRAINED,
2283
 CONFD_NODE_ROLE_REGULAR,
2284
 ) = range(5)
2285

    
2286
# A few common errors for confd
2287
CONFD_ERROR_UNKNOWN_ENTRY = 1
2288
CONFD_ERROR_INTERNAL = 2
2289
CONFD_ERROR_ARGUMENT = 3
2290

    
2291
# Each request is "salted" by the current timestamp.
2292
# This constants decides how many seconds of skew to accept.
2293
# TODO: make this a default and allow the value to be more configurable
2294
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
2295

    
2296
# When we haven't reloaded the config for more than this amount of
2297
# seconds, we force a test to see if inotify is betraying us. Using a
2298
# prime number to ensure we get less chance of 'same wakeup' with
2299
# other processes.
2300
CONFD_CONFIG_RELOAD_TIMEOUT = 17
2301

    
2302
# If we receive more than one update in this amount of microseconds,
2303
# we move to polling every RATELIMIT seconds, rather than relying on
2304
# inotify, to be able to serve more requests.
2305
CONFD_CONFIG_RELOAD_RATELIMIT = 250000
2306

    
2307
# Magic number prepended to all confd queries.
2308
# This allows us to distinguish different types of confd protocols and handle
2309
# them. For example by changing this we can move the whole payload to be
2310
# compressed, or move away from json.
2311
CONFD_MAGIC_FOURCC = "plj0"
2312

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

    
2318
# Timeout in seconds to expire pending query request in the confd client
2319
# library. We don't actually expect any answer more than 10 seconds after we
2320
# sent a request.
2321
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
2322

    
2323
# Maximum UDP datagram size.
2324
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
2325
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
2326
#   (assuming we can't use jumbo frames)
2327
# We just set this to 60K, which should be enough
2328
MAX_UDP_DATA_SIZE = 61440
2329

    
2330
# User-id pool minimum/maximum acceptable user-ids.
2331
UIDPOOL_UID_MIN = 0
2332
UIDPOOL_UID_MAX = 2 ** 32 - 1 # Assuming 32 bit user-ids
2333

    
2334
# Name or path of the pgrep command
2335
PGREP = "pgrep"
2336

    
2337
# Name of the node group that gets created at cluster init or upgrade
2338
INITIAL_NODE_GROUP_NAME = "default"
2339

    
2340
# Possible values for NodeGroup.alloc_policy
2341
ALLOC_POLICY_PREFERRED = "preferred"
2342
ALLOC_POLICY_LAST_RESORT = "last_resort"
2343
ALLOC_POLICY_UNALLOCABLE = "unallocable"
2344
VALID_ALLOC_POLICIES = [
2345
  ALLOC_POLICY_PREFERRED,
2346
  ALLOC_POLICY_LAST_RESORT,
2347
  ALLOC_POLICY_UNALLOCABLE,
2348
  ]
2349

    
2350
# Temporary external/shared storage parameters
2351
BLOCKDEV_DRIVER_MANUAL = "manual"
2352

    
2353
# qemu-img path, required for ovfconverter
2354
QEMUIMG_PATH = _autoconf.QEMUIMG_PATH
2355

    
2356
# Whether htools was enabled at compilation time
2357
HTOOLS = _autoconf.HTOOLS
2358
# The hail iallocator
2359
IALLOC_HAIL = "hail"
2360

    
2361
# Fake opcodes for functions that have hooks attached to them via
2362
# backend.RunLocalHooks
2363
FAKE_OP_MASTER_TURNUP = "OP_CLUSTER_IP_TURNUP"
2364
FAKE_OP_MASTER_TURNDOWN = "OP_CLUSTER_IP_TURNDOWN"
2365

    
2366
# SSH key types
2367
SSHK_RSA = "rsa"
2368
SSHK_DSA = "dsa"
2369
SSHK_ALL = compat.UniqueFrozenset([SSHK_RSA, SSHK_DSA])
2370

    
2371
# SSH authorized key types
2372
SSHAK_RSA = "ssh-rsa"
2373
SSHAK_DSS = "ssh-dss"
2374
SSHAK_ALL = compat.UniqueFrozenset([SSHAK_RSA, SSHAK_DSS])
2375

    
2376
# SSH setup
2377
SSHS_CLUSTER_NAME = "cluster_name"
2378
SSHS_SSH_HOST_KEY = "ssh_host_key"
2379
SSHS_SSH_ROOT_KEY = "ssh_root_key"
2380
SSHS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2381

    
2382
#: Key files for SSH daemon
2383
SSH_DAEMON_KEYFILES = {
2384
  SSHK_RSA: (pathutils.SSH_HOST_RSA_PRIV, pathutils.SSH_HOST_RSA_PUB),
2385
  SSHK_DSA: (pathutils.SSH_HOST_DSA_PRIV, pathutils.SSH_HOST_DSA_PUB),
2386
  }
2387

    
2388
# Node daemon setup
2389
NDS_CLUSTER_NAME = "cluster_name"
2390
NDS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2391
NDS_SSCONF = "ssconf"
2392
NDS_START_NODE_DAEMON = "start_node_daemon"
2393

    
2394
# Path generating random UUID
2395
RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
2396

    
2397
# Regex string for verifying a UUID
2398
UUID_REGEX = "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
2399

    
2400
# Auto-repair tag prefixes
2401
AUTO_REPAIR_TAG_PREFIX = "ganeti:watcher:autorepair:"
2402
AUTO_REPAIR_TAG_ENABLED = AUTO_REPAIR_TAG_PREFIX
2403
AUTO_REPAIR_TAG_SUSPENDED = AUTO_REPAIR_TAG_ENABLED + "suspend:"
2404
AUTO_REPAIR_TAG_PENDING = AUTO_REPAIR_TAG_PREFIX + "pending:"
2405
AUTO_REPAIR_TAG_RESULT = AUTO_REPAIR_TAG_PREFIX + "result:"
2406

    
2407
# Auto-repair levels
2408
AUTO_REPAIR_FIX_STORAGE = "fix-storage"
2409
AUTO_REPAIR_MIGRATE = "migrate"
2410
AUTO_REPAIR_FAILOVER = "failover"
2411
AUTO_REPAIR_REINSTALL = "reinstall"
2412
AUTO_REPAIR_ALL_TYPES = [
2413
  AUTO_REPAIR_FIX_STORAGE,
2414
  AUTO_REPAIR_MIGRATE,
2415
  AUTO_REPAIR_FAILOVER,
2416
  AUTO_REPAIR_REINSTALL,
2417
]
2418

    
2419
# Auto-repair results
2420
AUTO_REPAIR_SUCCESS = "success"
2421
AUTO_REPAIR_FAILURE = "failure"
2422
AUTO_REPAIR_ENOPERM = "enoperm"
2423
AUTO_REPAIR_ALL_RESULTS = frozenset([
2424
    AUTO_REPAIR_SUCCESS,
2425
    AUTO_REPAIR_FAILURE,
2426
    AUTO_REPAIR_ENOPERM,
2427
])
2428

    
2429
# The version identifier for builtin data collectors
2430
BUILTIN_DATA_COLLECTOR_VERSION = "B"
2431

    
2432
# The source reasons for the change of state of an instance
2433
INSTANCE_REASON_SOURCE_CLI = "cli"
2434
INSTANCE_REASON_SOURCE_RAPI = "rapi"
2435
INSTANCE_REASON_SOURCE_UNKNOWN = "unknown"
2436

    
2437
INSTANCE_REASON_SOURCES = compat.UniqueFrozenset([
2438
  INSTANCE_REASON_SOURCE_CLI,
2439
  INSTANCE_REASON_SOURCE_RAPI,
2440
  INSTANCE_REASON_SOURCE_UNKNOWN,
2441
  ])
2442

    
2443
# The default reasons for the change of state of an instance
2444
INSTANCE_REASON_REBOOT = "reboot"
2445

    
2446
# Do not re-export imported modules
2447
del re, _vcsversion, _autoconf, socket, pathutils, compat