Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ ae860154

History | View | Annotate | Download (63 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 = compat.UniqueFrozenset([
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

    
946

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

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

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

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

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

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

    
1050
# KVM-specific statuses
1051
HV_KVM_MIGRATION_VALID_STATUSES = HV_MIGRATION_VALID_STATUSES
1052

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1279
OOB_POWER_STATUS_POWERED = "powered"
1280

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1377
VNC_BASE_PORT = 5900
1378
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
1379

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

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

    
1410
# Disk types
1411
HT_DISK_IOEMU = "ioemu"
1412
HT_DISK_IDE = "ide"
1413
HT_DISK_SCSI = "scsi"
1414
HT_DISK_SD = "sd"
1415
HT_DISK_MTD = "mtd"
1416
HT_DISK_PFLASH = "pflash"
1417

    
1418
HT_CACHE_DEFAULT = "default"
1419
HT_CACHE_NONE = "none"
1420
HT_CACHE_WTHROUGH = "writethrough"
1421
HT_CACHE_WBACK = "writeback"
1422
HT_VALID_CACHE_TYPES = compat.UniqueFrozenset([
1423
  HT_CACHE_DEFAULT,
1424
  HT_CACHE_NONE,
1425
  HT_CACHE_WTHROUGH,
1426
  HT_CACHE_WBACK,
1427
  ])
1428

    
1429
HT_HVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1430
  HT_DISK_PARAVIRTUAL,
1431
  HT_DISK_IOEMU,
1432
  ])
1433
HT_KVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1434
  HT_DISK_PARAVIRTUAL,
1435
  HT_DISK_IDE,
1436
  HT_DISK_SCSI,
1437
  HT_DISK_SD,
1438
  HT_DISK_MTD,
1439
  HT_DISK_PFLASH,
1440
  ])
1441

    
1442
# Mouse types:
1443
HT_MOUSE_MOUSE = "mouse"
1444
HT_MOUSE_TABLET = "tablet"
1445

    
1446
HT_KVM_VALID_MOUSE_TYPES = compat.UniqueFrozenset([
1447
  HT_MOUSE_MOUSE,
1448
  HT_MOUSE_TABLET,
1449
  ])
1450

    
1451
# Boot order
1452
HT_BO_FLOPPY = "floppy"
1453
HT_BO_CDROM = "cdrom"
1454
HT_BO_DISK = "disk"
1455
HT_BO_NETWORK = "network"
1456

    
1457
HT_KVM_VALID_BO_TYPES = compat.UniqueFrozenset([
1458
  HT_BO_FLOPPY,
1459
  HT_BO_CDROM,
1460
  HT_BO_DISK,
1461
  HT_BO_NETWORK,
1462
  ])
1463

    
1464
# SPICE lossless image compression options
1465
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ = "auto_glz"
1466
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ = "auto_lz"
1467
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC = "quic"
1468
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ = "glz"
1469
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ = "lz"
1470
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF = "off"
1471

    
1472
HT_KVM_SPICE_VALID_LOSSLESS_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1473
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ,
1474
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ,
1475
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC,
1476
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ,
1477
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ,
1478
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF,
1479
  ])
1480

    
1481
# SPICE lossy image compression options (valid for both jpeg and zlib-glz)
1482
HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO = "auto"
1483
HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER = "never"
1484
HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS = "always"
1485

    
1486
HT_KVM_SPICE_VALID_LOSSY_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1487
  HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO,
1488
  HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER,
1489
  HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS,
1490
  ])
1491

    
1492
# SPICE video stream detection
1493
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF = "off"
1494
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL = "all"
1495
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER = "filter"
1496

    
1497
HT_KVM_SPICE_VALID_VIDEO_STREAM_DETECTION_OPTIONS = compat.UniqueFrozenset([
1498
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF,
1499
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL,
1500
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER,
1501
  ])
1502

    
1503
# Security models
1504
HT_SM_NONE = "none"
1505
HT_SM_USER = "user"
1506
HT_SM_POOL = "pool"
1507

    
1508
HT_KVM_VALID_SM_TYPES = compat.UniqueFrozenset([
1509
  HT_SM_NONE,
1510
  HT_SM_USER,
1511
  HT_SM_POOL,
1512
  ])
1513

    
1514
# Kvm flag values
1515
HT_KVM_ENABLED = "enabled"
1516
HT_KVM_DISABLED = "disabled"
1517

    
1518
HT_KVM_FLAG_VALUES = compat.UniqueFrozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
1519

    
1520
# Migration type
1521
HT_MIGRATION_LIVE = "live"
1522
HT_MIGRATION_NONLIVE = "non-live"
1523
HT_MIGRATION_MODES = compat.UniqueFrozenset([
1524
  HT_MIGRATION_LIVE,
1525
  HT_MIGRATION_NONLIVE,
1526
  ])
1527

    
1528
# Cluster Verify steps
1529
VERIFY_NPLUSONE_MEM = "nplusone_mem"
1530
VERIFY_OPTIONAL_CHECKS = compat.UniqueFrozenset([VERIFY_NPLUSONE_MEM])
1531

    
1532
# Cluster Verify error classes
1533
CV_TCLUSTER = "cluster"
1534
CV_TGROUP = "group"
1535
CV_TNODE = "node"
1536
CV_TINSTANCE = "instance"
1537

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

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

    
1655
CV_ALL_ECODES_STRINGS = \
1656
  compat.UniqueFrozenset(estr for (_, estr, _) in CV_ALL_ECODES)
1657

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

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

    
1703
# Admin states
1704
ADMINST_UP = "up"
1705
ADMINST_DOWN = "down"
1706
ADMINST_OFFLINE = "offline"
1707
ADMINST_ALL = compat.UniqueFrozenset([
1708
  ADMINST_UP,
1709
  ADMINST_DOWN,
1710
  ADMINST_OFFLINE,
1711
  ])
1712

    
1713
# Node roles
1714
NR_REGULAR = "R"
1715
NR_MASTER = "M"
1716
NR_MCANDIDATE = "C"
1717
NR_DRAINED = "D"
1718
NR_OFFLINE = "O"
1719
NR_ALL = compat.UniqueFrozenset([
1720
  NR_REGULAR,
1721
  NR_MASTER,
1722
  NR_MCANDIDATE,
1723
  NR_DRAINED,
1724
  NR_OFFLINE,
1725
  ])
1726

    
1727
# SSL certificate check constants (in days)
1728
SSL_CERT_EXPIRATION_WARN = 30
1729
SSL_CERT_EXPIRATION_ERROR = 7
1730

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

    
1754
IALLOCATOR_NEVAC_PRI = "primary-only"
1755
IALLOCATOR_NEVAC_SEC = "secondary-only"
1756
IALLOCATOR_NEVAC_ALL = "all"
1757
IALLOCATOR_NEVAC_MODES = compat.UniqueFrozenset([
1758
  IALLOCATOR_NEVAC_PRI,
1759
  IALLOCATOR_NEVAC_SEC,
1760
  IALLOCATOR_NEVAC_ALL,
1761
  ])
1762

    
1763
# Node evacuation
1764
NODE_EVAC_PRI = "primary-only"
1765
NODE_EVAC_SEC = "secondary-only"
1766
NODE_EVAC_ALL = "all"
1767
NODE_EVAC_MODES = compat.UniqueFrozenset([
1768
  NODE_EVAC_PRI,
1769
  NODE_EVAC_SEC,
1770
  NODE_EVAC_ALL,
1771
  ])
1772

    
1773
# Job queue
1774
JOB_QUEUE_VERSION = 1
1775
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
1776
JOB_QUEUE_FILES_PERMS = 0640
1777

    
1778
JOB_ID_TEMPLATE = r"\d+"
1779
JOB_FILE_RE = re.compile(r"^job-(%s)$" % JOB_ID_TEMPLATE)
1780

    
1781
# unchanged job return
1782
JOB_NOTCHANGED = "nochange"
1783

    
1784
# Job status
1785
JOB_STATUS_QUEUED = "queued"
1786
JOB_STATUS_WAITING = "waiting"
1787
JOB_STATUS_CANCELING = "canceling"
1788
JOB_STATUS_RUNNING = "running"
1789
JOB_STATUS_CANCELED = "canceled"
1790
JOB_STATUS_SUCCESS = "success"
1791
JOB_STATUS_ERROR = "error"
1792
JOBS_PENDING = compat.UniqueFrozenset([
1793
  JOB_STATUS_QUEUED,
1794
  JOB_STATUS_WAITING,
1795
  JOB_STATUS_CANCELING,
1796
  ])
1797
JOBS_FINALIZED = compat.UniqueFrozenset([
1798
  JOB_STATUS_CANCELED,
1799
  JOB_STATUS_SUCCESS,
1800
  JOB_STATUS_ERROR,
1801
  ])
1802
JOB_STATUS_ALL = compat.UniqueFrozenset([
1803
  JOB_STATUS_RUNNING,
1804
  ]) | JOBS_PENDING | JOBS_FINALIZED
1805

    
1806
# OpCode status
1807
# not yet finalized
1808
OP_STATUS_QUEUED = "queued"
1809
OP_STATUS_WAITING = "waiting"
1810
OP_STATUS_CANCELING = "canceling"
1811
OP_STATUS_RUNNING = "running"
1812
# finalized
1813
OP_STATUS_CANCELED = "canceled"
1814
OP_STATUS_SUCCESS = "success"
1815
OP_STATUS_ERROR = "error"
1816
OPS_FINALIZED = compat.UniqueFrozenset([
1817
  OP_STATUS_CANCELED,
1818
  OP_STATUS_SUCCESS,
1819
  OP_STATUS_ERROR,
1820
  ])
1821

    
1822
# OpCode priority
1823
OP_PRIO_LOWEST = +19
1824
OP_PRIO_HIGHEST = -20
1825

    
1826
OP_PRIO_LOW = +10
1827
OP_PRIO_NORMAL = 0
1828
OP_PRIO_HIGH = -10
1829

    
1830
OP_PRIO_SUBMIT_VALID = compat.UniqueFrozenset([
1831
  OP_PRIO_LOW,
1832
  OP_PRIO_NORMAL,
1833
  OP_PRIO_HIGH,
1834
  ])
1835

    
1836
OP_PRIO_DEFAULT = OP_PRIO_NORMAL
1837

    
1838
# Lock recalculate mode
1839
LOCKS_REPLACE = "replace"
1840
LOCKS_APPEND = "append"
1841

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

    
1851
# Execution log types
1852
ELOG_MESSAGE = "message"
1853
ELOG_REMOTE_IMPORT = "remote-import"
1854
ELOG_JQUEUE_TEST = "jqueue-test"
1855

    
1856
# /etc/hosts modification
1857
ETC_HOSTS_ADD = "add"
1858
ETC_HOSTS_REMOVE = "remove"
1859

    
1860
# Job queue test
1861
JQT_MSGPREFIX = "TESTMSG="
1862
JQT_EXPANDNAMES = "expandnames"
1863
JQT_EXEC = "exec"
1864
JQT_LOGMSG = "logmsg"
1865
JQT_STARTMSG = "startmsg"
1866
JQT_ALL = compat.UniqueFrozenset([
1867
  JQT_EXPANDNAMES,
1868
  JQT_EXEC,
1869
  JQT_LOGMSG,
1870
  JQT_STARTMSG,
1871
  ])
1872

    
1873
# Query resources
1874
QR_CLUSTER = "cluster"
1875
QR_INSTANCE = "instance"
1876
QR_NODE = "node"
1877
QR_LOCK = "lock"
1878
QR_GROUP = "group"
1879
QR_OS = "os"
1880
QR_JOB = "job"
1881
QR_EXPORT = "export"
1882
QR_NETWORK = "network"
1883
QR_EXTSTORAGE = "extstorage"
1884

    
1885
#: List of resources which can be queried using L{opcodes.OpQuery}
1886
QR_VIA_OP = compat.UniqueFrozenset([
1887
  QR_CLUSTER,
1888
  QR_INSTANCE,
1889
  QR_NODE,
1890
  QR_GROUP,
1891
  QR_OS,
1892
  QR_EXPORT,
1893
  QR_NETWORK,
1894
  QR_EXTSTORAGE,
1895
  ])
1896

    
1897
#: List of resources which can be queried using Local UniX Interface
1898
QR_VIA_LUXI = QR_VIA_OP.union([
1899
  QR_LOCK,
1900
  QR_JOB,
1901
  ])
1902

    
1903
#: List of resources which can be queried using RAPI
1904
QR_VIA_RAPI = QR_VIA_LUXI
1905

    
1906
# Query field types
1907
QFT_UNKNOWN = "unknown"
1908
QFT_TEXT = "text"
1909
QFT_BOOL = "bool"
1910
QFT_NUMBER = "number"
1911
QFT_UNIT = "unit"
1912
QFT_TIMESTAMP = "timestamp"
1913
QFT_OTHER = "other"
1914

    
1915
#: All query field types
1916
QFT_ALL = compat.UniqueFrozenset([
1917
  QFT_UNKNOWN,
1918
  QFT_TEXT,
1919
  QFT_BOOL,
1920
  QFT_NUMBER,
1921
  QFT_UNIT,
1922
  QFT_TIMESTAMP,
1923
  QFT_OTHER,
1924
  ])
1925

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

    
1941
RS_ALL = compat.UniqueFrozenset([
1942
  RS_NORMAL,
1943
  RS_UNKNOWN,
1944
  RS_NODATA,
1945
  RS_UNAVAIL,
1946
  RS_OFFLINE,
1947
  ])
1948

    
1949
#: Dictionary with special field cases and their verbose/terse formatting
1950
RSS_DESCRIPTION = {
1951
  RS_UNKNOWN: ("(unknown)", "??"),
1952
  RS_NODATA: ("(nodata)", "?"),
1953
  RS_OFFLINE: ("(offline)", "*"),
1954
  RS_UNAVAIL: ("(unavail)", "-"),
1955
  }
1956

    
1957
# max dynamic devices
1958
MAX_NICS = 8
1959
MAX_DISKS = 16
1960

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

    
1988
SS_FILE_PERMS = 0444
1989

    
1990
# cluster wide default parameters
1991
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
1992

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

    
2098
HVC_GLOBALS = compat.UniqueFrozenset([
2099
  HV_MIGRATION_PORT,
2100
  HV_MIGRATION_BANDWIDTH,
2101
  HV_MIGRATION_MODE,
2102
  ])
2103

    
2104
BEC_DEFAULTS = {
2105
  BE_MINMEM: 128,
2106
  BE_MAXMEM: 128,
2107
  BE_VCPUS: 1,
2108
  BE_AUTO_BALANCE: True,
2109
  BE_ALWAYS_FAILOVER: False,
2110
  BE_SPINDLE_USE: 1,
2111
  }
2112

    
2113
NDC_DEFAULTS = {
2114
  ND_OOB_PROGRAM: "",
2115
  ND_SPINDLE_COUNT: 1,
2116
  ND_EXCLUSIVE_STORAGE: False,
2117
  }
2118

    
2119
NDC_GLOBALS = compat.UniqueFrozenset([
2120
  ND_EXCLUSIVE_STORAGE,
2121
  ])
2122

    
2123
DISK_LD_DEFAULTS = {
2124
  LD_DRBD8: {
2125
    LDP_RESYNC_RATE: CLASSIC_DRBD_SYNC_SPEED,
2126
    LDP_BARRIERS: _autoconf.DRBD_BARRIERS,
2127
    LDP_NO_META_FLUSH: _autoconf.DRBD_NO_META_FLUSH,
2128
    LDP_DEFAULT_METAVG: DEFAULT_VG,
2129
    LDP_DISK_CUSTOM: "",
2130
    LDP_NET_CUSTOM: "",
2131
    LDP_DYNAMIC_RESYNC: False,
2132

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

    
2155
# readability shortcuts
2156
_LV_DEFAULTS = DISK_LD_DEFAULTS[LD_LV]
2157
_DRBD_DEFAULTS = DISK_LD_DEFAULTS[LD_DRBD8]
2158

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

    
2189
# we don't want to export the shortcuts
2190
del _LV_DEFAULTS, _DRBD_DEFAULTS
2191

    
2192
NICC_DEFAULTS = {
2193
  NIC_MODE: NIC_MODE_BRIDGED,
2194
  NIC_LINK: DEFAULT_BRIDGE,
2195
  }
2196

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

    
2232
MASTER_POOL_SIZE_DEFAULT = 10
2233

    
2234
# Exclusive storage:
2235
# Error margin used to compare physical disks
2236
PART_MARGIN = .01
2237
# Space reserved when creating instance disks
2238
PART_RESERVED = .02
2239

    
2240
CONFD_PROTOCOL_VERSION = 1
2241

    
2242
CONFD_REQ_PING = 0
2243
CONFD_REQ_NODE_ROLE_BYNAME = 1
2244
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
2245
CONFD_REQ_CLUSTER_MASTER = 3
2246
CONFD_REQ_NODE_PIP_LIST = 4
2247
CONFD_REQ_MC_PIP_LIST = 5
2248
CONFD_REQ_INSTANCES_IPS_LIST = 6
2249
CONFD_REQ_NODE_DRBD = 7
2250
CONFD_REQ_NODE_INSTANCES = 8
2251

    
2252
# Confd request query fields. These are used to narrow down queries.
2253
# These must be strings rather than integers, because json-encoding
2254
# converts them to strings anyway, as they're used as dict-keys.
2255
CONFD_REQQ_LINK = "0"
2256
CONFD_REQQ_IP = "1"
2257
CONFD_REQQ_IPLIST = "2"
2258
CONFD_REQQ_FIELDS = "3"
2259

    
2260
CONFD_REQFIELD_NAME = "0"
2261
CONFD_REQFIELD_IP = "1"
2262
CONFD_REQFIELD_MNODE_PIP = "2"
2263

    
2264
CONFD_REQS = compat.UniqueFrozenset([
2265
  CONFD_REQ_PING,
2266
  CONFD_REQ_NODE_ROLE_BYNAME,
2267
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
2268
  CONFD_REQ_CLUSTER_MASTER,
2269
  CONFD_REQ_NODE_PIP_LIST,
2270
  CONFD_REQ_MC_PIP_LIST,
2271
  CONFD_REQ_INSTANCES_IPS_LIST,
2272
  CONFD_REQ_NODE_DRBD,
2273
  ])
2274

    
2275
CONFD_REPL_STATUS_OK = 0
2276
CONFD_REPL_STATUS_ERROR = 1
2277
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
2278

    
2279
CONFD_REPL_STATUSES = compat.UniqueFrozenset([
2280
  CONFD_REPL_STATUS_OK,
2281
  CONFD_REPL_STATUS_ERROR,
2282
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
2283
  ])
2284

    
2285
(CONFD_NODE_ROLE_MASTER,
2286
 CONFD_NODE_ROLE_CANDIDATE,
2287
 CONFD_NODE_ROLE_OFFLINE,
2288
 CONFD_NODE_ROLE_DRAINED,
2289
 CONFD_NODE_ROLE_REGULAR,
2290
 ) = range(5)
2291

    
2292
# A few common errors for confd
2293
CONFD_ERROR_UNKNOWN_ENTRY = 1
2294
CONFD_ERROR_INTERNAL = 2
2295
CONFD_ERROR_ARGUMENT = 3
2296

    
2297
# Each request is "salted" by the current timestamp.
2298
# This constants decides how many seconds of skew to accept.
2299
# TODO: make this a default and allow the value to be more configurable
2300
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
2301

    
2302
# When we haven't reloaded the config for more than this amount of
2303
# seconds, we force a test to see if inotify is betraying us. Using a
2304
# prime number to ensure we get less chance of 'same wakeup' with
2305
# other processes.
2306
CONFD_CONFIG_RELOAD_TIMEOUT = 17
2307

    
2308
# If we receive more than one update in this amount of microseconds,
2309
# we move to polling every RATELIMIT seconds, rather than relying on
2310
# inotify, to be able to serve more requests.
2311
CONFD_CONFIG_RELOAD_RATELIMIT = 250000
2312

    
2313
# Magic number prepended to all confd queries.
2314
# This allows us to distinguish different types of confd protocols and handle
2315
# them. For example by changing this we can move the whole payload to be
2316
# compressed, or move away from json.
2317
CONFD_MAGIC_FOURCC = "plj0"
2318

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

    
2324
# Timeout in seconds to expire pending query request in the confd client
2325
# library. We don't actually expect any answer more than 10 seconds after we
2326
# sent a request.
2327
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
2328

    
2329
# Maximum UDP datagram size.
2330
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
2331
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
2332
#   (assuming we can't use jumbo frames)
2333
# We just set this to 60K, which should be enough
2334
MAX_UDP_DATA_SIZE = 61440
2335

    
2336
# User-id pool minimum/maximum acceptable user-ids.
2337
UIDPOOL_UID_MIN = 0
2338
UIDPOOL_UID_MAX = 2 ** 32 - 1 # Assuming 32 bit user-ids
2339

    
2340
# Name or path of the pgrep command
2341
PGREP = "pgrep"
2342

    
2343
# Name of the node group that gets created at cluster init or upgrade
2344
INITIAL_NODE_GROUP_NAME = "default"
2345

    
2346
# Possible values for NodeGroup.alloc_policy
2347
ALLOC_POLICY_PREFERRED = "preferred"
2348
ALLOC_POLICY_LAST_RESORT = "last_resort"
2349
ALLOC_POLICY_UNALLOCABLE = "unallocable"
2350
VALID_ALLOC_POLICIES = [
2351
  ALLOC_POLICY_PREFERRED,
2352
  ALLOC_POLICY_LAST_RESORT,
2353
  ALLOC_POLICY_UNALLOCABLE,
2354
  ]
2355

    
2356
# Temporary external/shared storage parameters
2357
BLOCKDEV_DRIVER_MANUAL = "manual"
2358

    
2359
# qemu-img path, required for ovfconverter
2360
QEMUIMG_PATH = _autoconf.QEMUIMG_PATH
2361

    
2362
# Whether htools was enabled at compilation time
2363
HTOOLS = _autoconf.HTOOLS
2364
# The hail iallocator
2365
IALLOC_HAIL = "hail"
2366

    
2367
# Fake opcodes for functions that have hooks attached to them via
2368
# backend.RunLocalHooks
2369
FAKE_OP_MASTER_TURNUP = "OP_CLUSTER_IP_TURNUP"
2370
FAKE_OP_MASTER_TURNDOWN = "OP_CLUSTER_IP_TURNDOWN"
2371

    
2372
# SSH key types
2373
SSHK_RSA = "rsa"
2374
SSHK_DSA = "dsa"
2375
SSHK_ALL = compat.UniqueFrozenset([SSHK_RSA, SSHK_DSA])
2376

    
2377
# SSH authorized key types
2378
SSHAK_RSA = "ssh-rsa"
2379
SSHAK_DSS = "ssh-dss"
2380
SSHAK_ALL = compat.UniqueFrozenset([SSHAK_RSA, SSHAK_DSS])
2381

    
2382
# SSH setup
2383
SSHS_CLUSTER_NAME = "cluster_name"
2384
SSHS_SSH_HOST_KEY = "ssh_host_key"
2385
SSHS_SSH_ROOT_KEY = "ssh_root_key"
2386
SSHS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2387

    
2388
#: Key files for SSH daemon
2389
SSH_DAEMON_KEYFILES = {
2390
  SSHK_RSA: (pathutils.SSH_HOST_RSA_PRIV, pathutils.SSH_HOST_RSA_PUB),
2391
  SSHK_DSA: (pathutils.SSH_HOST_DSA_PRIV, pathutils.SSH_HOST_DSA_PUB),
2392
  }
2393

    
2394
# Node daemon setup
2395
NDS_CLUSTER_NAME = "cluster_name"
2396
NDS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2397
NDS_SSCONF = "ssconf"
2398
NDS_START_NODE_DAEMON = "start_node_daemon"
2399

    
2400
# Path generating random UUID
2401
RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
2402

    
2403
# Regex string for verifying a UUID
2404
UUID_REGEX = "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
2405

    
2406
# Auto-repair tag prefixes
2407
AUTO_REPAIR_TAG_PREFIX = "ganeti:watcher:autorepair:"
2408
AUTO_REPAIR_TAG_ENABLED = AUTO_REPAIR_TAG_PREFIX
2409
AUTO_REPAIR_TAG_SUSPENDED = AUTO_REPAIR_TAG_ENABLED + "suspend:"
2410
AUTO_REPAIR_TAG_PENDING = AUTO_REPAIR_TAG_PREFIX + "pending:"
2411
AUTO_REPAIR_TAG_RESULT = AUTO_REPAIR_TAG_PREFIX + "result:"
2412

    
2413
# Auto-repair levels
2414
AUTO_REPAIR_FIX_STORAGE = "fix-storage"
2415
AUTO_REPAIR_MIGRATE = "migrate"
2416
AUTO_REPAIR_FAILOVER = "failover"
2417
AUTO_REPAIR_REINSTALL = "reinstall"
2418
AUTO_REPAIR_ALL_TYPES = [
2419
  AUTO_REPAIR_FIX_STORAGE,
2420
  AUTO_REPAIR_MIGRATE,
2421
  AUTO_REPAIR_FAILOVER,
2422
  AUTO_REPAIR_REINSTALL,
2423
]
2424

    
2425
# Auto-repair results
2426
AUTO_REPAIR_SUCCESS = "success"
2427
AUTO_REPAIR_FAILURE = "failure"
2428
AUTO_REPAIR_ENOPERM = "enoperm"
2429
AUTO_REPAIR_ALL_RESULTS = frozenset([
2430
    AUTO_REPAIR_SUCCESS,
2431
    AUTO_REPAIR_FAILURE,
2432
    AUTO_REPAIR_ENOPERM,
2433
])
2434

    
2435
# The version identifier for builtin data collectors
2436
BUILTIN_DATA_COLLECTOR_VERSION = "B"
2437

    
2438
# The source reasons for the change of state of an instance
2439
INSTANCE_REASON_SOURCE_CLI = "cli"
2440
INSTANCE_REASON_SOURCE_RAPI = "rapi"
2441
INSTANCE_REASON_SOURCE_UNKNOWN = "unknown"
2442

    
2443
INSTANCE_REASON_SOURCES = compat.UniqueFrozenset([
2444
  INSTANCE_REASON_SOURCE_CLI,
2445
  INSTANCE_REASON_SOURCE_RAPI,
2446
  INSTANCE_REASON_SOURCE_UNKNOWN,
2447
  ])
2448

    
2449
# The default reasons for the change of state of an instance
2450
INSTANCE_REASON_REBOOT = "reboot"
2451

    
2452
# Do not re-export imported modules
2453
del re, _vcsversion, _autoconf, socket, pathutils, compat