Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ 5bb0a1cb

History | View | Annotate | Download (63.4 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

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

    
394
# Storage fields
395
# first two are valid in LU context only, not passed to backend
396
SF_NODE = "node"
397
SF_TYPE = "type"
398
# and the rest are valid in backend
399
SF_NAME = "name"
400
SF_SIZE = "size"
401
SF_FREE = "free"
402
SF_USED = "used"
403
SF_ALLOCATABLE = "allocatable"
404

    
405
# Storage operations
406
SO_FIX_CONSISTENCY = "fix-consistency"
407

    
408
# Available fields per storage type
409
VALID_STORAGE_FIELDS = compat.UniqueFrozenset([
410
  SF_NAME,
411
  SF_TYPE,
412
  SF_SIZE,
413
  SF_USED,
414
  SF_FREE,
415
  SF_ALLOCATABLE,
416
  ])
417

    
418
MODIFIABLE_STORAGE_FIELDS = {
419
  ST_LVM_PV: frozenset([SF_ALLOCATABLE]),
420
  }
421

    
422
VALID_STORAGE_OPERATIONS = {
423
  ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
424
  }
425

    
426
# Local disk status
427
# Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
428
(LDS_OKAY,
429
 LDS_UNKNOWN,
430
 LDS_FAULTY) = range(1, 4)
431

    
432
# disk template types
433
DT_BLOCK = "blockdev"
434
DT_DISKLESS = "diskless"
435
DT_DRBD8 = "drbd"
436
DT_EXT = "ext"
437
DT_FILE = "file"
438
DT_PLAIN = "plain"
439
DT_RBD = "rbd"
440
DT_SHARED_FILE = "sharedfile"
441

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

    
457
DISK_TEMPLATES = compat.UniqueFrozenset([
458
  DT_DISKLESS,
459
  DT_PLAIN,
460
  DT_DRBD8,
461
  DT_FILE,
462
  DT_SHARED_FILE,
463
  DT_BLOCK,
464
  DT_RBD,
465
  DT_EXT
466
  ])
467

    
468
# disk templates that are enabled by default
469
DEFAULT_ENABLED_DISK_TEMPLATES = [
470
  DT_DRBD8,
471
  DT_PLAIN,
472
  ]
473

    
474
# mapping of disk templates to storage types
475
DISK_TEMPLATES_STORAGE_TYPE = {
476
  DT_BLOCK: ST_BLOCK,
477
  DT_DISKLESS: ST_DISKLESS,
478
  DT_DRBD8: ST_LVM_VG,
479
  DT_EXT: ST_EXT,
480
  DT_FILE: ST_FILE,
481
  DT_PLAIN: ST_LVM_VG,
482
  DT_RBD: ST_RADOS,
483
  DT_SHARED_FILE: ST_FILE,
484
  }
485

    
486
# the set of network-mirrored disk templates
487
DTS_INT_MIRROR = compat.UniqueFrozenset([DT_DRBD8])
488

    
489
# the set of externally-mirrored disk templates (e.g. SAN, NAS)
490
DTS_EXT_MIRROR = compat.UniqueFrozenset([
491
  DT_DISKLESS, # 'trivially' externally mirrored
492
  DT_SHARED_FILE,
493
  DT_BLOCK,
494
  DT_RBD,
495
  DT_EXT,
496
  ])
497

    
498
# the set of non-lvm-based disk templates
499
DTS_NOT_LVM = compat.UniqueFrozenset([
500
  DT_DISKLESS,
501
  DT_FILE,
502
  DT_SHARED_FILE,
503
  DT_BLOCK,
504
  DT_RBD,
505
  DT_EXT,
506
  ])
507

    
508
# the set of disk templates which can be grown
509
DTS_GROWABLE = compat.UniqueFrozenset([
510
  DT_PLAIN,
511
  DT_DRBD8,
512
  DT_FILE,
513
  DT_SHARED_FILE,
514
  DT_RBD,
515
  DT_EXT,
516
  ])
517

    
518
# the set of disk templates that allow adoption
519
DTS_MAY_ADOPT = compat.UniqueFrozenset([
520
  DT_PLAIN,
521
  DT_BLOCK,
522
  ])
523

    
524
# the set of disk templates that *must* use adoption
525
DTS_MUST_ADOPT = compat.UniqueFrozenset([DT_BLOCK])
526

    
527
# the set of disk templates that allow migrations
528
DTS_MIRRORED = frozenset.union(DTS_INT_MIRROR, DTS_EXT_MIRROR)
529

    
530
# the set of file based disk templates
531
DTS_FILEBASED = compat.UniqueFrozenset([
532
  DT_FILE,
533
  DT_SHARED_FILE,
534
  ])
535

    
536
# the set of disk templates that can be moved by copying
537
# Note: a requirement is that they're not accessed externally or shared between
538
# nodes; in particular, sharedfile is not suitable.
539
DTS_COPYABLE = compat.UniqueFrozenset([
540
  DT_FILE,
541
  DT_PLAIN,
542
  ])
543

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
819
ES_PARAMETERS_FILE = "parameters.list"
820

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

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

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

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

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

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

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

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

    
947

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

    
1018
HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
1019

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

    
1034
# Migration statuses
1035
HV_MIGRATION_COMPLETED = "completed"
1036
HV_MIGRATION_ACTIVE = "active"
1037
HV_MIGRATION_FAILED = "failed"
1038
HV_MIGRATION_CANCELLED = "cancelled"
1039

    
1040
HV_MIGRATION_VALID_STATUSES = compat.UniqueFrozenset([
1041
  HV_MIGRATION_COMPLETED,
1042
  HV_MIGRATION_ACTIVE,
1043
  HV_MIGRATION_FAILED,
1044
  HV_MIGRATION_CANCELLED,
1045
  ])
1046

    
1047
HV_MIGRATION_FAILED_STATUSES = compat.UniqueFrozenset([
1048
  HV_MIGRATION_FAILED,
1049
  HV_MIGRATION_CANCELLED,
1050
  ])
1051

    
1052
# KVM-specific statuses
1053
HV_KVM_MIGRATION_VALID_STATUSES = HV_MIGRATION_VALID_STATUSES
1054

    
1055
# Node info keys
1056
HV_NODEINFO_KEY_VERSION = "hv_version"
1057

    
1058
# Hypervisor state
1059
HVST_MEMORY_TOTAL = "mem_total"
1060
HVST_MEMORY_NODE = "mem_node"
1061
HVST_MEMORY_HV = "mem_hv"
1062
HVST_CPU_TOTAL = "cpu_total"
1063
HVST_CPU_NODE = "cpu_node"
1064

    
1065
HVST_DEFAULTS = {
1066
  HVST_MEMORY_TOTAL: 0,
1067
  HVST_MEMORY_NODE: 0,
1068
  HVST_MEMORY_HV: 0,
1069
  HVST_CPU_TOTAL: 1,
1070
  HVST_CPU_NODE: 1,
1071
  }
1072

    
1073
HVSTS_PARAMETER_TYPES = {
1074
  HVST_MEMORY_TOTAL: VTYPE_INT,
1075
  HVST_MEMORY_NODE: VTYPE_INT,
1076
  HVST_MEMORY_HV: VTYPE_INT,
1077
  HVST_CPU_TOTAL: VTYPE_INT,
1078
  HVST_CPU_NODE: VTYPE_INT,
1079
  }
1080

    
1081
HVSTS_PARAMETERS = frozenset(HVSTS_PARAMETER_TYPES.keys())
1082

    
1083
# Disk state
1084
DS_DISK_TOTAL = "disk_total"
1085
DS_DISK_RESERVED = "disk_reserved"
1086
DS_DISK_OVERHEAD = "disk_overhead"
1087

    
1088
DS_DEFAULTS = {
1089
  DS_DISK_TOTAL: 0,
1090
  DS_DISK_RESERVED: 0,
1091
  DS_DISK_OVERHEAD: 0,
1092
  }
1093

    
1094
DSS_PARAMETER_TYPES = {
1095
  DS_DISK_TOTAL: VTYPE_INT,
1096
  DS_DISK_RESERVED: VTYPE_INT,
1097
  DS_DISK_OVERHEAD: VTYPE_INT,
1098
  }
1099

    
1100
DSS_PARAMETERS = frozenset(DSS_PARAMETER_TYPES.keys())
1101
DS_VALID_TYPES = compat.UniqueFrozenset([LD_LV])
1102

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

    
1112
BES_PARAMETER_TYPES = {
1113
  BE_MAXMEM: VTYPE_SIZE,
1114
  BE_MINMEM: VTYPE_SIZE,
1115
  BE_VCPUS: VTYPE_INT,
1116
  BE_AUTO_BALANCE: VTYPE_BOOL,
1117
  BE_ALWAYS_FAILOVER: VTYPE_BOOL,
1118
  BE_SPINDLE_USE: VTYPE_INT,
1119
  }
1120

    
1121
BES_PARAMETER_TITLES = {
1122
  BE_AUTO_BALANCE: "Auto_balance",
1123
  BE_MAXMEM: "ConfigMaxMem",
1124
  BE_MINMEM: "ConfigMinMem",
1125
  BE_VCPUS: "ConfigVCPUs",
1126
  }
1127

    
1128
BES_PARAMETER_COMPAT = {
1129
  BE_MEMORY: VTYPE_SIZE,
1130
  }
1131
BES_PARAMETER_COMPAT.update(BES_PARAMETER_TYPES)
1132

    
1133
BES_PARAMETERS = frozenset(BES_PARAMETER_TYPES.keys())
1134

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

    
1143
ISPECS_PARAMETER_TYPES = {
1144
  ISPEC_MEM_SIZE: VTYPE_INT,
1145
  ISPEC_CPU_COUNT: VTYPE_INT,
1146
  ISPEC_DISK_COUNT: VTYPE_INT,
1147
  ISPEC_DISK_SIZE: VTYPE_INT,
1148
  ISPEC_NIC_COUNT: VTYPE_INT,
1149
  ISPEC_SPINDLE_USE: VTYPE_INT,
1150
  }
1151

    
1152
ISPECS_PARAMETERS = frozenset(ISPECS_PARAMETER_TYPES.keys())
1153

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

    
1162
ISPECS_MINMAX_KEYS = compat.UniqueFrozenset([
1163
  ISPECS_MIN,
1164
  ISPECS_MAX,
1165
  ])
1166

    
1167
IPOLICY_PARAMETERS = compat.UniqueFrozenset([
1168
  IPOLICY_VCPU_RATIO,
1169
  IPOLICY_SPINDLE_RATIO,
1170
  ])
1171

    
1172
IPOLICY_ALL_KEYS = (IPOLICY_PARAMETERS |
1173
                    frozenset([ISPECS_MINMAX, ISPECS_STD, IPOLICY_DTS]))
1174

    
1175
# Node parameter names
1176
ND_OOB_PROGRAM = "oob_program"
1177
ND_SPINDLE_COUNT = "spindle_count"
1178
ND_EXCLUSIVE_STORAGE = "exclusive_storage"
1179

    
1180
NDS_PARAMETER_TYPES = {
1181
  ND_OOB_PROGRAM: VTYPE_STRING,
1182
  ND_SPINDLE_COUNT: VTYPE_INT,
1183
  ND_EXCLUSIVE_STORAGE: VTYPE_BOOL,
1184
  }
1185

    
1186
NDS_PARAMETERS = frozenset(NDS_PARAMETER_TYPES.keys())
1187

    
1188
NDS_PARAMETER_TITLES = {
1189
  ND_OOB_PROGRAM: "OutOfBandProgram",
1190
  ND_SPINDLE_COUNT: "SpindleCount",
1191
  ND_EXCLUSIVE_STORAGE: "ExclusiveStorage",
1192
  }
1193

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

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

    
1264
DISK_DT_PARAMETERS = frozenset(DISK_DT_TYPES.keys())
1265

    
1266
# OOB supported commands
1267
OOB_POWER_ON = "power-on"
1268
OOB_POWER_OFF = "power-off"
1269
OOB_POWER_CYCLE = "power-cycle"
1270
OOB_POWER_STATUS = "power-status"
1271
OOB_HEALTH = "health"
1272

    
1273
OOB_COMMANDS = compat.UniqueFrozenset([
1274
  OOB_POWER_ON,
1275
  OOB_POWER_OFF,
1276
  OOB_POWER_CYCLE,
1277
  OOB_POWER_STATUS,
1278
  OOB_HEALTH,
1279
  ])
1280

    
1281
OOB_POWER_STATUS_POWERED = "powered"
1282

    
1283
OOB_TIMEOUT = 60 # 60 seconds
1284
OOB_POWER_DELAY = 2.0 # 2 seconds
1285

    
1286
OOB_STATUS_OK = "OK"
1287
OOB_STATUS_WARNING = "WARNING"
1288
OOB_STATUS_CRITICAL = "CRITICAL"
1289
OOB_STATUS_UNKNOWN = "UNKNOWN"
1290

    
1291
OOB_STATUSES = compat.UniqueFrozenset([
1292
  OOB_STATUS_OK,
1293
  OOB_STATUS_WARNING,
1294
  OOB_STATUS_CRITICAL,
1295
  OOB_STATUS_UNKNOWN,
1296
  ])
1297

    
1298
# Instance Parameters Profile
1299
PP_DEFAULT = "default"
1300

    
1301
# NIC_* constants are used inside the ganeti config
1302
NIC_MODE = "mode"
1303
NIC_LINK = "link"
1304

    
1305
NIC_MODE_BRIDGED = "bridged"
1306
NIC_MODE_ROUTED = "routed"
1307
NIC_MODE_OVS = "openvswitch"
1308
NIC_IP_POOL = "pool"
1309

    
1310
NIC_VALID_MODES = compat.UniqueFrozenset([
1311
  NIC_MODE_BRIDGED,
1312
  NIC_MODE_ROUTED,
1313
  NIC_MODE_OVS,
1314
  ])
1315

    
1316
RESERVE_ACTION = "reserve"
1317
RELEASE_ACTION = "release"
1318

    
1319
NICS_PARAMETER_TYPES = {
1320
  NIC_MODE: VTYPE_STRING,
1321
  NIC_LINK: VTYPE_STRING,
1322
  }
1323

    
1324
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
1325

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

    
1345
# INIC_* constants are used in opcodes, to create/change nics
1346
INIC_MAC = "mac"
1347
INIC_IP = "ip"
1348
INIC_MODE = "mode"
1349
INIC_LINK = "link"
1350
INIC_NETWORK = "network"
1351
INIC_NAME = "name"
1352
INIC_PARAMS_TYPES = {
1353
  INIC_IP: VTYPE_MAYBE_STRING,
1354
  INIC_LINK: VTYPE_STRING,
1355
  INIC_MAC: VTYPE_STRING,
1356
  INIC_MODE: VTYPE_STRING,
1357
  INIC_NETWORK: VTYPE_MAYBE_STRING,
1358
  INIC_NAME: VTYPE_MAYBE_STRING,
1359
  }
1360
INIC_PARAMS = frozenset(INIC_PARAMS_TYPES.keys())
1361

    
1362
# Hypervisor constants
1363
HT_XEN_PVM = "xen-pvm"
1364
HT_FAKE = "fake"
1365
HT_XEN_HVM = "xen-hvm"
1366
HT_KVM = "kvm"
1367
HT_CHROOT = "chroot"
1368
HT_LXC = "lxc"
1369
HYPER_TYPES = compat.UniqueFrozenset([
1370
  HT_XEN_PVM,
1371
  HT_FAKE,
1372
  HT_XEN_HVM,
1373
  HT_KVM,
1374
  HT_CHROOT,
1375
  HT_LXC,
1376
  ])
1377
HTS_REQ_PORT = compat.UniqueFrozenset([HT_XEN_HVM, HT_KVM])
1378

    
1379
VNC_BASE_PORT = 5900
1380
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
1381

    
1382
# NIC types
1383
HT_NIC_RTL8139 = "rtl8139"
1384
HT_NIC_NE2K_PCI = "ne2k_pci"
1385
HT_NIC_NE2K_ISA = "ne2k_isa"
1386
HT_NIC_I82551 = "i82551"
1387
HT_NIC_I85557B = "i82557b"
1388
HT_NIC_I8259ER = "i82559er"
1389
HT_NIC_PCNET = "pcnet"
1390
HT_NIC_E1000 = "e1000"
1391
HT_NIC_PARAVIRTUAL = HT_DISK_PARAVIRTUAL = "paravirtual"
1392

    
1393
HT_HVM_VALID_NIC_TYPES = compat.UniqueFrozenset([
1394
  HT_NIC_RTL8139,
1395
  HT_NIC_NE2K_PCI,
1396
  HT_NIC_E1000,
1397
  HT_NIC_NE2K_ISA,
1398
  HT_NIC_PARAVIRTUAL,
1399
  ])
1400
HT_KVM_VALID_NIC_TYPES = compat.UniqueFrozenset([
1401
  HT_NIC_RTL8139,
1402
  HT_NIC_NE2K_PCI,
1403
  HT_NIC_NE2K_ISA,
1404
  HT_NIC_I82551,
1405
  HT_NIC_I85557B,
1406
  HT_NIC_I8259ER,
1407
  HT_NIC_PCNET,
1408
  HT_NIC_E1000,
1409
  HT_NIC_PARAVIRTUAL,
1410
  ])
1411

    
1412
# Vif types
1413
# default vif type in xen-hvm
1414
HT_HVM_VIF_IOEMU = "ioemu"
1415
HT_HVM_VIF_VIF = "vif"
1416
HT_HVM_VALID_VIF_TYPES = compat.UniqueFrozenset([
1417
  HT_HVM_VIF_IOEMU,
1418
  HT_HVM_VIF_VIF,
1419
  ])
1420

    
1421
# Disk types
1422
HT_DISK_IOEMU = "ioemu"
1423
HT_DISK_IDE = "ide"
1424
HT_DISK_SCSI = "scsi"
1425
HT_DISK_SD = "sd"
1426
HT_DISK_MTD = "mtd"
1427
HT_DISK_PFLASH = "pflash"
1428

    
1429
HT_CACHE_DEFAULT = "default"
1430
HT_CACHE_NONE = "none"
1431
HT_CACHE_WTHROUGH = "writethrough"
1432
HT_CACHE_WBACK = "writeback"
1433
HT_VALID_CACHE_TYPES = compat.UniqueFrozenset([
1434
  HT_CACHE_DEFAULT,
1435
  HT_CACHE_NONE,
1436
  HT_CACHE_WTHROUGH,
1437
  HT_CACHE_WBACK,
1438
  ])
1439

    
1440
HT_HVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1441
  HT_DISK_PARAVIRTUAL,
1442
  HT_DISK_IOEMU,
1443
  ])
1444
HT_KVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1445
  HT_DISK_PARAVIRTUAL,
1446
  HT_DISK_IDE,
1447
  HT_DISK_SCSI,
1448
  HT_DISK_SD,
1449
  HT_DISK_MTD,
1450
  HT_DISK_PFLASH,
1451
  ])
1452

    
1453
# Mouse types:
1454
HT_MOUSE_MOUSE = "mouse"
1455
HT_MOUSE_TABLET = "tablet"
1456

    
1457
HT_KVM_VALID_MOUSE_TYPES = compat.UniqueFrozenset([
1458
  HT_MOUSE_MOUSE,
1459
  HT_MOUSE_TABLET,
1460
  ])
1461

    
1462
# Boot order
1463
HT_BO_FLOPPY = "floppy"
1464
HT_BO_CDROM = "cdrom"
1465
HT_BO_DISK = "disk"
1466
HT_BO_NETWORK = "network"
1467

    
1468
HT_KVM_VALID_BO_TYPES = compat.UniqueFrozenset([
1469
  HT_BO_FLOPPY,
1470
  HT_BO_CDROM,
1471
  HT_BO_DISK,
1472
  HT_BO_NETWORK,
1473
  ])
1474

    
1475
# SPICE lossless image compression options
1476
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ = "auto_glz"
1477
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ = "auto_lz"
1478
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC = "quic"
1479
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ = "glz"
1480
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ = "lz"
1481
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF = "off"
1482

    
1483
HT_KVM_SPICE_VALID_LOSSLESS_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1484
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ,
1485
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ,
1486
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC,
1487
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ,
1488
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ,
1489
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF,
1490
  ])
1491

    
1492
# SPICE lossy image compression options (valid for both jpeg and zlib-glz)
1493
HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO = "auto"
1494
HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER = "never"
1495
HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS = "always"
1496

    
1497
HT_KVM_SPICE_VALID_LOSSY_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1498
  HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO,
1499
  HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER,
1500
  HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS,
1501
  ])
1502

    
1503
# SPICE video stream detection
1504
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF = "off"
1505
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL = "all"
1506
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER = "filter"
1507

    
1508
HT_KVM_SPICE_VALID_VIDEO_STREAM_DETECTION_OPTIONS = compat.UniqueFrozenset([
1509
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF,
1510
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL,
1511
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER,
1512
  ])
1513

    
1514
# Security models
1515
HT_SM_NONE = "none"
1516
HT_SM_USER = "user"
1517
HT_SM_POOL = "pool"
1518

    
1519
HT_KVM_VALID_SM_TYPES = compat.UniqueFrozenset([
1520
  HT_SM_NONE,
1521
  HT_SM_USER,
1522
  HT_SM_POOL,
1523
  ])
1524

    
1525
# Kvm flag values
1526
HT_KVM_ENABLED = "enabled"
1527
HT_KVM_DISABLED = "disabled"
1528

    
1529
HT_KVM_FLAG_VALUES = compat.UniqueFrozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
1530

    
1531
# Migration type
1532
HT_MIGRATION_LIVE = "live"
1533
HT_MIGRATION_NONLIVE = "non-live"
1534
HT_MIGRATION_MODES = compat.UniqueFrozenset([
1535
  HT_MIGRATION_LIVE,
1536
  HT_MIGRATION_NONLIVE,
1537
  ])
1538

    
1539
# Cluster Verify steps
1540
VERIFY_NPLUSONE_MEM = "nplusone_mem"
1541
VERIFY_OPTIONAL_CHECKS = compat.UniqueFrozenset([VERIFY_NPLUSONE_MEM])
1542

    
1543
# Cluster Verify error classes
1544
CV_TCLUSTER = "cluster"
1545
CV_TGROUP = "group"
1546
CV_TNODE = "node"
1547
CV_TINSTANCE = "instance"
1548

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

    
1631
CV_ALL_ECODES = compat.UniqueFrozenset([
1632
  CV_ECLUSTERCFG,
1633
  CV_ECLUSTERCERT,
1634
  CV_ECLUSTERFILECHECK,
1635
  CV_ECLUSTERDANGLINGNODES,
1636
  CV_ECLUSTERDANGLINGINST,
1637
  CV_EINSTANCEBADNODE,
1638
  CV_EINSTANCEDOWN,
1639
  CV_EINSTANCELAYOUT,
1640
  CV_EINSTANCEMISSINGDISK,
1641
  CV_EINSTANCEFAULTYDISK,
1642
  CV_EINSTANCEWRONGNODE,
1643
  CV_EINSTANCESPLITGROUPS,
1644
  CV_EINSTANCEPOLICY,
1645
  CV_ENODEDRBD,
1646
  CV_ENODEDRBDHELPER,
1647
  CV_ENODEFILECHECK,
1648
  CV_ENODEHOOKS,
1649
  CV_ENODEHV,
1650
  CV_ENODELVM,
1651
  CV_ENODEN1,
1652
  CV_ENODENET,
1653
  CV_ENODEOS,
1654
  CV_ENODEORPHANINSTANCE,
1655
  CV_ENODEORPHANLV,
1656
  CV_ENODERPC,
1657
  CV_ENODESSH,
1658
  CV_ENODEVERSION,
1659
  CV_ENODESETUP,
1660
  CV_ENODETIME,
1661
  CV_ENODEOOBPATH,
1662
  CV_ENODEUSERSCRIPTS,
1663
  CV_ENODEFILESTORAGEPATHS,
1664
  ])
1665

    
1666
CV_ALL_ECODES_STRINGS = \
1667
  compat.UniqueFrozenset(estr for (_, estr, _) in CV_ALL_ECODES)
1668

    
1669
# Node verify constants
1670
NV_BRIDGES = "bridges"
1671
NV_DRBDHELPER = "drbd-helper"
1672
NV_DRBDVERSION = "drbd-version"
1673
NV_DRBDLIST = "drbd-list"
1674
NV_EXCLUSIVEPVS = "exclusive-pvs"
1675
NV_FILELIST = "filelist"
1676
NV_FILE_STORAGE_PATHS = "file-storage-paths"
1677
NV_HVINFO = "hvinfo"
1678
NV_HVPARAMS = "hvparms"
1679
NV_HYPERVISOR = "hypervisor"
1680
NV_INSTANCELIST = "instancelist"
1681
NV_LVLIST = "lvlist"
1682
NV_MASTERIP = "master-ip"
1683
NV_NODELIST = "nodelist"
1684
NV_NODENETTEST = "node-net-test"
1685
NV_NODESETUP = "nodesetup"
1686
NV_OOB_PATHS = "oob-paths"
1687
NV_OSLIST = "oslist"
1688
NV_PVLIST = "pvlist"
1689
NV_TIME = "time"
1690
NV_USERSCRIPTS = "user-scripts"
1691
NV_VERSION = "version"
1692
NV_VGLIST = "vglist"
1693
NV_VMNODES = "vmnodes"
1694

    
1695
# Instance status
1696
INSTST_RUNNING = "running"
1697
INSTST_ADMINDOWN = "ADMIN_down"
1698
INSTST_ADMINOFFLINE = "ADMIN_offline"
1699
INSTST_NODEOFFLINE = "ERROR_nodeoffline"
1700
INSTST_NODEDOWN = "ERROR_nodedown"
1701
INSTST_WRONGNODE = "ERROR_wrongnode"
1702
INSTST_ERRORUP = "ERROR_up"
1703
INSTST_ERRORDOWN = "ERROR_down"
1704
INSTST_ALL = compat.UniqueFrozenset([
1705
  INSTST_RUNNING,
1706
  INSTST_ADMINDOWN,
1707
  INSTST_ADMINOFFLINE,
1708
  INSTST_NODEOFFLINE,
1709
  INSTST_NODEDOWN,
1710
  INSTST_WRONGNODE,
1711
  INSTST_ERRORUP,
1712
  INSTST_ERRORDOWN,
1713
  ])
1714

    
1715
# Admin states
1716
ADMINST_UP = "up"
1717
ADMINST_DOWN = "down"
1718
ADMINST_OFFLINE = "offline"
1719
ADMINST_ALL = compat.UniqueFrozenset([
1720
  ADMINST_UP,
1721
  ADMINST_DOWN,
1722
  ADMINST_OFFLINE,
1723
  ])
1724

    
1725
# Node roles
1726
NR_REGULAR = "R"
1727
NR_MASTER = "M"
1728
NR_MCANDIDATE = "C"
1729
NR_DRAINED = "D"
1730
NR_OFFLINE = "O"
1731
NR_ALL = compat.UniqueFrozenset([
1732
  NR_REGULAR,
1733
  NR_MASTER,
1734
  NR_MCANDIDATE,
1735
  NR_DRAINED,
1736
  NR_OFFLINE,
1737
  ])
1738

    
1739
# SSL certificate check constants (in days)
1740
SSL_CERT_EXPIRATION_WARN = 30
1741
SSL_CERT_EXPIRATION_ERROR = 7
1742

    
1743
# Allocator framework constants
1744
IALLOCATOR_VERSION = 2
1745
IALLOCATOR_DIR_IN = "in"
1746
IALLOCATOR_DIR_OUT = "out"
1747
VALID_IALLOCATOR_DIRECTIONS = compat.UniqueFrozenset([
1748
  IALLOCATOR_DIR_IN,
1749
  IALLOCATOR_DIR_OUT,
1750
  ])
1751
IALLOCATOR_MODE_ALLOC = "allocate"
1752
IALLOCATOR_MODE_RELOC = "relocate"
1753
IALLOCATOR_MODE_CHG_GROUP = "change-group"
1754
IALLOCATOR_MODE_NODE_EVAC = "node-evacuate"
1755
IALLOCATOR_MODE_MULTI_ALLOC = "multi-allocate"
1756
VALID_IALLOCATOR_MODES = compat.UniqueFrozenset([
1757
  IALLOCATOR_MODE_ALLOC,
1758
  IALLOCATOR_MODE_RELOC,
1759
  IALLOCATOR_MODE_CHG_GROUP,
1760
  IALLOCATOR_MODE_NODE_EVAC,
1761
  IALLOCATOR_MODE_MULTI_ALLOC,
1762
  ])
1763
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
1764
DEFAULT_IALLOCATOR_SHORTCUT = "."
1765

    
1766
IALLOCATOR_NEVAC_PRI = "primary-only"
1767
IALLOCATOR_NEVAC_SEC = "secondary-only"
1768
IALLOCATOR_NEVAC_ALL = "all"
1769
IALLOCATOR_NEVAC_MODES = compat.UniqueFrozenset([
1770
  IALLOCATOR_NEVAC_PRI,
1771
  IALLOCATOR_NEVAC_SEC,
1772
  IALLOCATOR_NEVAC_ALL,
1773
  ])
1774

    
1775
# Node evacuation
1776
NODE_EVAC_PRI = "primary-only"
1777
NODE_EVAC_SEC = "secondary-only"
1778
NODE_EVAC_ALL = "all"
1779
NODE_EVAC_MODES = compat.UniqueFrozenset([
1780
  NODE_EVAC_PRI,
1781
  NODE_EVAC_SEC,
1782
  NODE_EVAC_ALL,
1783
  ])
1784

    
1785
# Job queue
1786
JOB_QUEUE_VERSION = 1
1787
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
1788
JOB_QUEUE_FILES_PERMS = 0640
1789

    
1790
JOB_ID_TEMPLATE = r"\d+"
1791
JOB_FILE_RE = re.compile(r"^job-(%s)$" % JOB_ID_TEMPLATE)
1792

    
1793
# unchanged job return
1794
JOB_NOTCHANGED = "nochange"
1795

    
1796
# Job status
1797
JOB_STATUS_QUEUED = "queued"
1798
JOB_STATUS_WAITING = "waiting"
1799
JOB_STATUS_CANCELING = "canceling"
1800
JOB_STATUS_RUNNING = "running"
1801
JOB_STATUS_CANCELED = "canceled"
1802
JOB_STATUS_SUCCESS = "success"
1803
JOB_STATUS_ERROR = "error"
1804
JOBS_PENDING = compat.UniqueFrozenset([
1805
  JOB_STATUS_QUEUED,
1806
  JOB_STATUS_WAITING,
1807
  JOB_STATUS_CANCELING,
1808
  ])
1809
JOBS_FINALIZED = compat.UniqueFrozenset([
1810
  JOB_STATUS_CANCELED,
1811
  JOB_STATUS_SUCCESS,
1812
  JOB_STATUS_ERROR,
1813
  ])
1814
JOB_STATUS_ALL = compat.UniqueFrozenset([
1815
  JOB_STATUS_RUNNING,
1816
  ]) | JOBS_PENDING | JOBS_FINALIZED
1817

    
1818
# OpCode status
1819
# not yet finalized
1820
OP_STATUS_QUEUED = "queued"
1821
OP_STATUS_WAITING = "waiting"
1822
OP_STATUS_CANCELING = "canceling"
1823
OP_STATUS_RUNNING = "running"
1824
# finalized
1825
OP_STATUS_CANCELED = "canceled"
1826
OP_STATUS_SUCCESS = "success"
1827
OP_STATUS_ERROR = "error"
1828
OPS_FINALIZED = compat.UniqueFrozenset([
1829
  OP_STATUS_CANCELED,
1830
  OP_STATUS_SUCCESS,
1831
  OP_STATUS_ERROR,
1832
  ])
1833

    
1834
# OpCode priority
1835
OP_PRIO_LOWEST = +19
1836
OP_PRIO_HIGHEST = -20
1837

    
1838
OP_PRIO_LOW = +10
1839
OP_PRIO_NORMAL = 0
1840
OP_PRIO_HIGH = -10
1841

    
1842
OP_PRIO_SUBMIT_VALID = compat.UniqueFrozenset([
1843
  OP_PRIO_LOW,
1844
  OP_PRIO_NORMAL,
1845
  OP_PRIO_HIGH,
1846
  ])
1847

    
1848
OP_PRIO_DEFAULT = OP_PRIO_NORMAL
1849

    
1850
# Lock recalculate mode
1851
LOCKS_REPLACE = "replace"
1852
LOCKS_APPEND = "append"
1853

    
1854
# Lock timeout (sum) before we should go into blocking acquire (still
1855
# can be reset by priority change); computed as max time (10 hours)
1856
# before we should actually go into blocking acquire given that we
1857
# start from default priority level; in seconds
1858
# TODO
1859
LOCK_ATTEMPTS_TIMEOUT = 10 * 3600 / (OP_PRIO_DEFAULT - OP_PRIO_HIGHEST)
1860
LOCK_ATTEMPTS_MAXWAIT = 15.0
1861
LOCK_ATTEMPTS_MINWAIT = 1.0
1862

    
1863
# Execution log types
1864
ELOG_MESSAGE = "message"
1865
ELOG_REMOTE_IMPORT = "remote-import"
1866
ELOG_JQUEUE_TEST = "jqueue-test"
1867

    
1868
# /etc/hosts modification
1869
ETC_HOSTS_ADD = "add"
1870
ETC_HOSTS_REMOVE = "remove"
1871

    
1872
# Job queue test
1873
JQT_MSGPREFIX = "TESTMSG="
1874
JQT_EXPANDNAMES = "expandnames"
1875
JQT_EXEC = "exec"
1876
JQT_LOGMSG = "logmsg"
1877
JQT_STARTMSG = "startmsg"
1878
JQT_ALL = compat.UniqueFrozenset([
1879
  JQT_EXPANDNAMES,
1880
  JQT_EXEC,
1881
  JQT_LOGMSG,
1882
  JQT_STARTMSG,
1883
  ])
1884

    
1885
# Query resources
1886
QR_CLUSTER = "cluster"
1887
QR_INSTANCE = "instance"
1888
QR_NODE = "node"
1889
QR_LOCK = "lock"
1890
QR_GROUP = "group"
1891
QR_OS = "os"
1892
QR_JOB = "job"
1893
QR_EXPORT = "export"
1894
QR_NETWORK = "network"
1895
QR_EXTSTORAGE = "extstorage"
1896

    
1897
#: List of resources which can be queried using L{opcodes.OpQuery}
1898
QR_VIA_OP = compat.UniqueFrozenset([
1899
  QR_CLUSTER,
1900
  QR_INSTANCE,
1901
  QR_NODE,
1902
  QR_GROUP,
1903
  QR_OS,
1904
  QR_EXPORT,
1905
  QR_NETWORK,
1906
  QR_EXTSTORAGE,
1907
  ])
1908

    
1909
#: List of resources which can be queried using Local UniX Interface
1910
QR_VIA_LUXI = QR_VIA_OP.union([
1911
  QR_LOCK,
1912
  QR_JOB,
1913
  ])
1914

    
1915
#: List of resources which can be queried using RAPI
1916
QR_VIA_RAPI = QR_VIA_LUXI
1917

    
1918
# Query field types
1919
QFT_UNKNOWN = "unknown"
1920
QFT_TEXT = "text"
1921
QFT_BOOL = "bool"
1922
QFT_NUMBER = "number"
1923
QFT_UNIT = "unit"
1924
QFT_TIMESTAMP = "timestamp"
1925
QFT_OTHER = "other"
1926

    
1927
#: All query field types
1928
QFT_ALL = compat.UniqueFrozenset([
1929
  QFT_UNKNOWN,
1930
  QFT_TEXT,
1931
  QFT_BOOL,
1932
  QFT_NUMBER,
1933
  QFT_UNIT,
1934
  QFT_TIMESTAMP,
1935
  QFT_OTHER,
1936
  ])
1937

    
1938
# Query result field status (don't change or reuse values as they're used by
1939
# clients)
1940
#: Normal field status
1941
RS_NORMAL = 0
1942
#: Unknown field
1943
RS_UNKNOWN = 1
1944
#: No data (e.g. RPC error), can be used instead of L{RS_OFFLINE}
1945
RS_NODATA = 2
1946
#: Value unavailable/unsupported for item; if this field is supported
1947
#: but we cannot get the data for the moment, RS_NODATA or
1948
#: RS_OFFLINE should be used
1949
RS_UNAVAIL = 3
1950
#: Resource marked offline
1951
RS_OFFLINE = 4
1952

    
1953
RS_ALL = compat.UniqueFrozenset([
1954
  RS_NORMAL,
1955
  RS_UNKNOWN,
1956
  RS_NODATA,
1957
  RS_UNAVAIL,
1958
  RS_OFFLINE,
1959
  ])
1960

    
1961
#: Dictionary with special field cases and their verbose/terse formatting
1962
RSS_DESCRIPTION = {
1963
  RS_UNKNOWN: ("(unknown)", "??"),
1964
  RS_NODATA: ("(nodata)", "?"),
1965
  RS_OFFLINE: ("(offline)", "*"),
1966
  RS_UNAVAIL: ("(unavail)", "-"),
1967
  }
1968

    
1969
# max dynamic devices
1970
MAX_NICS = 8
1971
MAX_DISKS = 16
1972

    
1973
# SSCONF file prefix
1974
SSCONF_FILEPREFIX = "ssconf_"
1975
# SSCONF keys
1976
SS_CLUSTER_NAME = "cluster_name"
1977
SS_CLUSTER_TAGS = "cluster_tags"
1978
SS_FILE_STORAGE_DIR = "file_storage_dir"
1979
SS_SHARED_FILE_STORAGE_DIR = "shared_file_storage_dir"
1980
SS_MASTER_CANDIDATES = "master_candidates"
1981
SS_MASTER_CANDIDATES_IPS = "master_candidates_ips"
1982
SS_MASTER_IP = "master_ip"
1983
SS_MASTER_NETDEV = "master_netdev"
1984
SS_MASTER_NETMASK = "master_netmask"
1985
SS_MASTER_NODE = "master_node"
1986
SS_NODE_LIST = "node_list"
1987
SS_NODE_PRIMARY_IPS = "node_primary_ips"
1988
SS_NODE_SECONDARY_IPS = "node_secondary_ips"
1989
SS_OFFLINE_NODES = "offline_nodes"
1990
SS_ONLINE_NODES = "online_nodes"
1991
SS_PRIMARY_IP_FAMILY = "primary_ip_family"
1992
SS_INSTANCE_LIST = "instance_list"
1993
SS_RELEASE_VERSION = "release_version"
1994
SS_HYPERVISOR_LIST = "hypervisor_list"
1995
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
1996
SS_UID_POOL = "uid_pool"
1997
SS_NODEGROUPS = "nodegroups"
1998
SS_NETWORKS = "networks"
1999

    
2000
SS_FILE_PERMS = 0444
2001

    
2002
# cluster wide default parameters
2003
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
2004

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

    
2111
HVC_GLOBALS = compat.UniqueFrozenset([
2112
  HV_MIGRATION_PORT,
2113
  HV_MIGRATION_BANDWIDTH,
2114
  HV_MIGRATION_MODE,
2115
  ])
2116

    
2117
BEC_DEFAULTS = {
2118
  BE_MINMEM: 128,
2119
  BE_MAXMEM: 128,
2120
  BE_VCPUS: 1,
2121
  BE_AUTO_BALANCE: True,
2122
  BE_ALWAYS_FAILOVER: False,
2123
  BE_SPINDLE_USE: 1,
2124
  }
2125

    
2126
NDC_DEFAULTS = {
2127
  ND_OOB_PROGRAM: "",
2128
  ND_SPINDLE_COUNT: 1,
2129
  ND_EXCLUSIVE_STORAGE: False,
2130
  }
2131

    
2132
NDC_GLOBALS = compat.UniqueFrozenset([
2133
  ND_EXCLUSIVE_STORAGE,
2134
  ])
2135

    
2136
DISK_LD_DEFAULTS = {
2137
  LD_DRBD8: {
2138
    LDP_RESYNC_RATE: CLASSIC_DRBD_SYNC_SPEED,
2139
    LDP_BARRIERS: _autoconf.DRBD_BARRIERS,
2140
    LDP_NO_META_FLUSH: _autoconf.DRBD_NO_META_FLUSH,
2141
    LDP_DEFAULT_METAVG: DEFAULT_VG,
2142
    LDP_DISK_CUSTOM: "",
2143
    LDP_NET_CUSTOM: "",
2144
    LDP_DYNAMIC_RESYNC: False,
2145

    
2146
    # The default values for the DRBD dynamic resync speed algorithm
2147
    # are taken from the drbsetup 8.3.11 man page, except for
2148
    # c-plan-ahead (that we don't need to set to 0, because we have a
2149
    # separate option to enable it) and for c-max-rate, that we cap to
2150
    # the default value for the static resync rate.
2151
    LDP_PLAN_AHEAD: 20, # ds
2152
    LDP_FILL_TARGET: 0, # sectors
2153
    LDP_DELAY_TARGET: 1, # ds
2154
    LDP_MAX_RATE: CLASSIC_DRBD_SYNC_SPEED, # KiB/s
2155
    LDP_MIN_RATE: 4 * 1024, # KiB/s
2156
    },
2157
  LD_LV: {
2158
    LDP_STRIPES: _autoconf.LVM_STRIPECOUNT
2159
    },
2160
  LD_FILE: {},
2161
  LD_BLOCKDEV: {},
2162
  LD_RBD: {
2163
    LDP_POOL: "rbd"
2164
    },
2165
  LD_EXT: {},
2166
  }
2167

    
2168
# readability shortcuts
2169
_LV_DEFAULTS = DISK_LD_DEFAULTS[LD_LV]
2170
_DRBD_DEFAULTS = DISK_LD_DEFAULTS[LD_DRBD8]
2171

    
2172
DISK_DT_DEFAULTS = {
2173
  DT_PLAIN: {
2174
    LV_STRIPES: DISK_LD_DEFAULTS[LD_LV][LDP_STRIPES],
2175
    },
2176
  DT_DRBD8: {
2177
    DRBD_RESYNC_RATE: _DRBD_DEFAULTS[LDP_RESYNC_RATE],
2178
    DRBD_DATA_STRIPES: _LV_DEFAULTS[LDP_STRIPES],
2179
    DRBD_META_STRIPES: _LV_DEFAULTS[LDP_STRIPES],
2180
    DRBD_DISK_BARRIERS: _DRBD_DEFAULTS[LDP_BARRIERS],
2181
    DRBD_META_BARRIERS: _DRBD_DEFAULTS[LDP_NO_META_FLUSH],
2182
    DRBD_DEFAULT_METAVG: _DRBD_DEFAULTS[LDP_DEFAULT_METAVG],
2183
    DRBD_DISK_CUSTOM: _DRBD_DEFAULTS[LDP_DISK_CUSTOM],
2184
    DRBD_NET_CUSTOM: _DRBD_DEFAULTS[LDP_NET_CUSTOM],
2185
    DRBD_DYNAMIC_RESYNC: _DRBD_DEFAULTS[LDP_DYNAMIC_RESYNC],
2186
    DRBD_PLAN_AHEAD: _DRBD_DEFAULTS[LDP_PLAN_AHEAD],
2187
    DRBD_FILL_TARGET: _DRBD_DEFAULTS[LDP_FILL_TARGET],
2188
    DRBD_DELAY_TARGET: _DRBD_DEFAULTS[LDP_DELAY_TARGET],
2189
    DRBD_MAX_RATE: _DRBD_DEFAULTS[LDP_MAX_RATE],
2190
    DRBD_MIN_RATE: _DRBD_DEFAULTS[LDP_MIN_RATE],
2191
    },
2192
  DT_DISKLESS: {},
2193
  DT_FILE: {},
2194
  DT_SHARED_FILE: {},
2195
  DT_BLOCK: {},
2196
  DT_RBD: {
2197
    RBD_POOL: DISK_LD_DEFAULTS[LD_RBD][LDP_POOL]
2198
    },
2199
  DT_EXT: {},
2200
  }
2201

    
2202
# we don't want to export the shortcuts
2203
del _LV_DEFAULTS, _DRBD_DEFAULTS
2204

    
2205
NICC_DEFAULTS = {
2206
  NIC_MODE: NIC_MODE_BRIDGED,
2207
  NIC_LINK: DEFAULT_BRIDGE,
2208
  }
2209

    
2210
# All of the following values are quite arbitrarily - there are no
2211
# "good" defaults, these must be customised per-site
2212
ISPECS_MINMAX_DEFAULTS = {
2213
  ISPECS_MIN: {
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
  ISPECS_MAX: {
2222
    ISPEC_MEM_SIZE: 32768,
2223
    ISPEC_CPU_COUNT: 8,
2224
    ISPEC_DISK_COUNT: MAX_DISKS,
2225
    ISPEC_DISK_SIZE: 1024 * 1024,
2226
    ISPEC_NIC_COUNT: MAX_NICS,
2227
    ISPEC_SPINDLE_USE: 12,
2228
    },
2229
  }
2230
IPOLICY_DEFAULTS = {
2231
  ISPECS_MINMAX: [ISPECS_MINMAX_DEFAULTS],
2232
  ISPECS_STD: {
2233
    ISPEC_MEM_SIZE: 128,
2234
    ISPEC_CPU_COUNT: 1,
2235
    ISPEC_DISK_COUNT: 1,
2236
    ISPEC_DISK_SIZE: 1024,
2237
    ISPEC_NIC_COUNT: 1,
2238
    ISPEC_SPINDLE_USE: 1,
2239
    },
2240
  IPOLICY_DTS: list(DISK_TEMPLATES),
2241
  IPOLICY_VCPU_RATIO: 4.0,
2242
  IPOLICY_SPINDLE_RATIO: 32.0,
2243
  }
2244

    
2245
MASTER_POOL_SIZE_DEFAULT = 10
2246

    
2247
# Exclusive storage:
2248
# Error margin used to compare physical disks
2249
PART_MARGIN = .01
2250
# Space reserved when creating instance disks
2251
PART_RESERVED = .02
2252

    
2253
CONFD_PROTOCOL_VERSION = 1
2254

    
2255
CONFD_REQ_PING = 0
2256
CONFD_REQ_NODE_ROLE_BYNAME = 1
2257
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
2258
CONFD_REQ_CLUSTER_MASTER = 3
2259
CONFD_REQ_NODE_PIP_LIST = 4
2260
CONFD_REQ_MC_PIP_LIST = 5
2261
CONFD_REQ_INSTANCES_IPS_LIST = 6
2262
CONFD_REQ_NODE_DRBD = 7
2263
CONFD_REQ_NODE_INSTANCES = 8
2264

    
2265
# Confd request query fields. These are used to narrow down queries.
2266
# These must be strings rather than integers, because json-encoding
2267
# converts them to strings anyway, as they're used as dict-keys.
2268
CONFD_REQQ_LINK = "0"
2269
CONFD_REQQ_IP = "1"
2270
CONFD_REQQ_IPLIST = "2"
2271
CONFD_REQQ_FIELDS = "3"
2272

    
2273
CONFD_REQFIELD_NAME = "0"
2274
CONFD_REQFIELD_IP = "1"
2275
CONFD_REQFIELD_MNODE_PIP = "2"
2276

    
2277
CONFD_REQS = compat.UniqueFrozenset([
2278
  CONFD_REQ_PING,
2279
  CONFD_REQ_NODE_ROLE_BYNAME,
2280
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
2281
  CONFD_REQ_CLUSTER_MASTER,
2282
  CONFD_REQ_NODE_PIP_LIST,
2283
  CONFD_REQ_MC_PIP_LIST,
2284
  CONFD_REQ_INSTANCES_IPS_LIST,
2285
  CONFD_REQ_NODE_DRBD,
2286
  ])
2287

    
2288
CONFD_REPL_STATUS_OK = 0
2289
CONFD_REPL_STATUS_ERROR = 1
2290
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
2291

    
2292
CONFD_REPL_STATUSES = compat.UniqueFrozenset([
2293
  CONFD_REPL_STATUS_OK,
2294
  CONFD_REPL_STATUS_ERROR,
2295
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
2296
  ])
2297

    
2298
(CONFD_NODE_ROLE_MASTER,
2299
 CONFD_NODE_ROLE_CANDIDATE,
2300
 CONFD_NODE_ROLE_OFFLINE,
2301
 CONFD_NODE_ROLE_DRAINED,
2302
 CONFD_NODE_ROLE_REGULAR,
2303
 ) = range(5)
2304

    
2305
# A few common errors for confd
2306
CONFD_ERROR_UNKNOWN_ENTRY = 1
2307
CONFD_ERROR_INTERNAL = 2
2308
CONFD_ERROR_ARGUMENT = 3
2309

    
2310
# Each request is "salted" by the current timestamp.
2311
# This constants decides how many seconds of skew to accept.
2312
# TODO: make this a default and allow the value to be more configurable
2313
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
2314

    
2315
# When we haven't reloaded the config for more than this amount of
2316
# seconds, we force a test to see if inotify is betraying us. Using a
2317
# prime number to ensure we get less chance of 'same wakeup' with
2318
# other processes.
2319
CONFD_CONFIG_RELOAD_TIMEOUT = 17
2320

    
2321
# If we receive more than one update in this amount of microseconds,
2322
# we move to polling every RATELIMIT seconds, rather than relying on
2323
# inotify, to be able to serve more requests.
2324
CONFD_CONFIG_RELOAD_RATELIMIT = 250000
2325

    
2326
# Magic number prepended to all confd queries.
2327
# This allows us to distinguish different types of confd protocols and handle
2328
# them. For example by changing this we can move the whole payload to be
2329
# compressed, or move away from json.
2330
CONFD_MAGIC_FOURCC = "plj0"
2331

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

    
2337
# Timeout in seconds to expire pending query request in the confd client
2338
# library. We don't actually expect any answer more than 10 seconds after we
2339
# sent a request.
2340
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
2341

    
2342
# Maximum UDP datagram size.
2343
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
2344
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
2345
#   (assuming we can't use jumbo frames)
2346
# We just set this to 60K, which should be enough
2347
MAX_UDP_DATA_SIZE = 61440
2348

    
2349
# User-id pool minimum/maximum acceptable user-ids.
2350
UIDPOOL_UID_MIN = 0
2351
UIDPOOL_UID_MAX = 2 ** 32 - 1 # Assuming 32 bit user-ids
2352

    
2353
# Name or path of the pgrep command
2354
PGREP = "pgrep"
2355

    
2356
# Name of the node group that gets created at cluster init or upgrade
2357
INITIAL_NODE_GROUP_NAME = "default"
2358

    
2359
# Possible values for NodeGroup.alloc_policy
2360
ALLOC_POLICY_PREFERRED = "preferred"
2361
ALLOC_POLICY_LAST_RESORT = "last_resort"
2362
ALLOC_POLICY_UNALLOCABLE = "unallocable"
2363
VALID_ALLOC_POLICIES = [
2364
  ALLOC_POLICY_PREFERRED,
2365
  ALLOC_POLICY_LAST_RESORT,
2366
  ALLOC_POLICY_UNALLOCABLE,
2367
  ]
2368

    
2369
# Temporary external/shared storage parameters
2370
BLOCKDEV_DRIVER_MANUAL = "manual"
2371

    
2372
# qemu-img path, required for ovfconverter
2373
QEMUIMG_PATH = _autoconf.QEMUIMG_PATH
2374

    
2375
# Whether htools was enabled at compilation time
2376
HTOOLS = _autoconf.HTOOLS
2377
# The hail iallocator
2378
IALLOC_HAIL = "hail"
2379

    
2380
# Fake opcodes for functions that have hooks attached to them via
2381
# backend.RunLocalHooks
2382
FAKE_OP_MASTER_TURNUP = "OP_CLUSTER_IP_TURNUP"
2383
FAKE_OP_MASTER_TURNDOWN = "OP_CLUSTER_IP_TURNDOWN"
2384

    
2385
# SSH key types
2386
SSHK_RSA = "rsa"
2387
SSHK_DSA = "dsa"
2388
SSHK_ALL = compat.UniqueFrozenset([SSHK_RSA, SSHK_DSA])
2389

    
2390
# SSH authorized key types
2391
SSHAK_RSA = "ssh-rsa"
2392
SSHAK_DSS = "ssh-dss"
2393
SSHAK_ALL = compat.UniqueFrozenset([SSHAK_RSA, SSHAK_DSS])
2394

    
2395
# SSH setup
2396
SSHS_CLUSTER_NAME = "cluster_name"
2397
SSHS_SSH_HOST_KEY = "ssh_host_key"
2398
SSHS_SSH_ROOT_KEY = "ssh_root_key"
2399
SSHS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2400

    
2401
#: Key files for SSH daemon
2402
SSH_DAEMON_KEYFILES = {
2403
  SSHK_RSA: (pathutils.SSH_HOST_RSA_PRIV, pathutils.SSH_HOST_RSA_PUB),
2404
  SSHK_DSA: (pathutils.SSH_HOST_DSA_PRIV, pathutils.SSH_HOST_DSA_PUB),
2405
  }
2406

    
2407
# Node daemon setup
2408
NDS_CLUSTER_NAME = "cluster_name"
2409
NDS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2410
NDS_SSCONF = "ssconf"
2411
NDS_START_NODE_DAEMON = "start_node_daemon"
2412

    
2413
# Path generating random UUID
2414
RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
2415

    
2416
# Regex string for verifying a UUID
2417
UUID_REGEX = "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
2418

    
2419
# Auto-repair tag prefixes
2420
AUTO_REPAIR_TAG_PREFIX = "ganeti:watcher:autorepair:"
2421
AUTO_REPAIR_TAG_ENABLED = AUTO_REPAIR_TAG_PREFIX
2422
AUTO_REPAIR_TAG_SUSPENDED = AUTO_REPAIR_TAG_ENABLED + "suspend:"
2423
AUTO_REPAIR_TAG_PENDING = AUTO_REPAIR_TAG_PREFIX + "pending:"
2424
AUTO_REPAIR_TAG_RESULT = AUTO_REPAIR_TAG_PREFIX + "result:"
2425

    
2426
# Auto-repair levels
2427
AUTO_REPAIR_FIX_STORAGE = "fix-storage"
2428
AUTO_REPAIR_MIGRATE = "migrate"
2429
AUTO_REPAIR_FAILOVER = "failover"
2430
AUTO_REPAIR_REINSTALL = "reinstall"
2431
AUTO_REPAIR_ALL_TYPES = [
2432
  AUTO_REPAIR_FIX_STORAGE,
2433
  AUTO_REPAIR_MIGRATE,
2434
  AUTO_REPAIR_FAILOVER,
2435
  AUTO_REPAIR_REINSTALL,
2436
]
2437

    
2438
# Auto-repair results
2439
AUTO_REPAIR_SUCCESS = "success"
2440
AUTO_REPAIR_FAILURE = "failure"
2441
AUTO_REPAIR_ENOPERM = "enoperm"
2442
AUTO_REPAIR_ALL_RESULTS = frozenset([
2443
    AUTO_REPAIR_SUCCESS,
2444
    AUTO_REPAIR_FAILURE,
2445
    AUTO_REPAIR_ENOPERM,
2446
])
2447

    
2448
# The version identifier for builtin data collectors
2449
BUILTIN_DATA_COLLECTOR_VERSION = "B"
2450

    
2451
# The reason trail opcode parameter name
2452
OPCODE_REASON = "reason"
2453

    
2454
# The source reasons for the execution of an OpCode
2455
OPCODE_REASON_SRC_CLIENT = "gnt:client"
2456
OPCODE_REASON_SRC_NODED = "gnt:daemon:noded"
2457
OPCODE_REASON_SRC_OPCODE = "gnt:opcode"
2458
OPCODE_REASON_SRC_RLIB2 = "gnt:library:rlib2"
2459
OPCODE_REASON_SRC_USER = "gnt:user"
2460

    
2461
OPCODE_REASON_SOURCES = compat.UniqueFrozenset([
2462
  OPCODE_REASON_SRC_CLIENT,
2463
  OPCODE_REASON_SRC_NODED,
2464
  OPCODE_REASON_SRC_OPCODE,
2465
  OPCODE_REASON_SRC_RLIB2,
2466
  OPCODE_REASON_SRC_USER,
2467
  ])
2468

    
2469
# Do not re-export imported modules
2470
del re, _vcsversion, _autoconf, socket, pathutils, compat