Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ 670e954a

History | View | Annotate | Download (63.5 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
QUERYD_USER = _autoconf.QUERYD_USER
108
QUERYD_GROUP = _autoconf.QUERYD_GROUP
109
NODED_USER = _autoconf.NODED_USER
110
NODED_GROUP = _autoconf.NODED_GROUP
111
MOND_USER = _autoconf.MOND_USER
112
MOND_GROUP = _autoconf.MOND_GROUP
113
SSH_LOGIN_USER = _autoconf.SSH_LOGIN_USER
114
SSH_CONSOLE_USER = _autoconf.SSH_CONSOLE_USER
115

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

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

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

    
139
# Wipe
140
DD_CMD = "dd"
141
MAX_WIPE_CHUNK = 1024 # 1GB
142
MIN_WIPE_CHUNK_PERCENT = 10
143

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

    
155
# SSH constants
156
SSH = "ssh"
157
SCP = "scp"
158

    
159
NODED = "ganeti-noded"
160
CONFD = "ganeti-confd"
161
QUERYD = "ganeti-queryd"
162
RAPI = "ganeti-rapi"
163
MASTERD = "ganeti-masterd"
164
MOND = "ganeti-mond"
165

    
166
DAEMONS = compat.UniqueFrozenset([
167
  NODED,
168
  CONFD,
169
  QUERYD,
170
  RAPI,
171
  MASTERD,
172
  MOND,
173
  ])
174

    
175
DAEMONS_PORTS = {
176
  # daemon-name: ("proto", "default-port")
177
  NODED: ("tcp", 1811),
178
  CONFD: ("udp", 1814),
179
  MOND: ("tcp", 1815),
180
  RAPI: ("tcp", 5080),
181
  SSH: ("tcp", 22),
182
}
183

    
184
DEFAULT_NODED_PORT = DAEMONS_PORTS[NODED][1]
185
DEFAULT_CONFD_PORT = DAEMONS_PORTS[CONFD][1]
186
DEFAULT_MOND_PORT = DAEMONS_PORTS[MOND][1]
187
DEFAULT_RAPI_PORT = DAEMONS_PORTS[RAPI][1]
188

    
189
FIRST_DRBD_PORT = 11000
190
LAST_DRBD_PORT = 14999
191

    
192
DAEMONS_LOGBASE = {
193
  NODED: "node-daemon",
194
  CONFD: "conf-daemon",
195
  QUERYD: "query-daemon",
196
  RAPI: "rapi-daemon",
197
  MASTERD: "master-daemon",
198
  MOND: "monitoring-daemon",
199
  }
200

    
201
DAEMONS_LOGFILES = \
202
    dict((daemon, pathutils.GetLogFilename(DAEMONS_LOGBASE[daemon]))
203
         for daemon in DAEMONS_LOGBASE)
204

    
205
# Some daemons might require more than one logfile.
206
# Specifically, right now only the Haskell http library "snap", used by the
207
# monitoring daemon, requires multiple log files.
208

    
209
# These are the only valid reasons for having an extra logfile
210
EXTRA_LOGREASON_ACCESS = "access"
211
EXTRA_LOGREASON_ERROR = "error"
212

    
213
VALID_EXTRA_LOGREASONS = compat.UniqueFrozenset([
214
  EXTRA_LOGREASON_ACCESS,
215
  EXTRA_LOGREASON_ERROR,
216
  ])
217

    
218
# These are the extra logfiles, grouped by daemon
219
DAEMONS_EXTRA_LOGBASE = {
220
  MOND: {
221
    EXTRA_LOGREASON_ACCESS: "monitoring-daemon-access",
222
    EXTRA_LOGREASON_ERROR: "monitoring-daemon-error",
223
    }
224
  }
225

    
226
DAEMONS_EXTRA_LOGFILES = \
227
  dict((daemon, dict((extra,
228
       pathutils.GetLogFilename(DAEMONS_EXTRA_LOGBASE[daemon][extra]))
229
       for extra in DAEMONS_EXTRA_LOGBASE[daemon]))
230
         for daemon in DAEMONS_EXTRA_LOGBASE)
231

    
232
DEV_CONSOLE = "/dev/console"
233

    
234
PROC_MOUNTS = "/proc/mounts"
235

    
236
# Local UniX Interface related constants
237
LUXI_EOM = "\3"
238
LUXI_VERSION = CONFIG_VERSION
239
#: Environment variable for the luxi override socket
240
LUXI_OVERRIDE = "FORCE_LUXI_SOCKET"
241
LUXI_OVERRIDE_MASTER = "master"
242
LUXI_OVERRIDE_QUERY = "query"
243

    
244
# one of "no", "yes", "only"
245
SYSLOG_USAGE = _autoconf.SYSLOG_USAGE
246
SYSLOG_NO = "no"
247
SYSLOG_YES = "yes"
248
SYSLOG_ONLY = "only"
249
SYSLOG_SOCKET = "/dev/log"
250

    
251
EXPORT_CONF_FILE = "config.ini"
252

    
253
XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER
254
XEN_KERNEL = _autoconf.XEN_KERNEL
255
XEN_INITRD = _autoconf.XEN_INITRD
256
XEN_CMD_XM = "xm"
257
XEN_CMD_XL = "xl"
258
# FIXME: This will be made configurable using hvparams in Ganeti 2.7
259
XEN_CMD = _autoconf.XEN_CMD
260

    
261
KNOWN_XEN_COMMANDS = compat.UniqueFrozenset([
262
  XEN_CMD_XM,
263
  XEN_CMD_XL,
264
  ])
265

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

    
277
KVM_PATH = _autoconf.KVM_PATH
278
KVM_KERNEL = _autoconf.KVM_KERNEL
279
SOCAT_PATH = _autoconf.SOCAT_PATH
280
SOCAT_USE_ESCAPE = _autoconf.SOCAT_USE_ESCAPE
281
SOCAT_USE_COMPRESS = _autoconf.SOCAT_USE_COMPRESS
282
SOCAT_ESCAPE_CODE = "0x1d"
283

    
284
#: Console as SSH command
285
CONS_SSH = "ssh"
286

    
287
#: Console as VNC server
288
CONS_VNC = "vnc"
289

    
290
#: Console as SPICE server
291
CONS_SPICE = "spice"
292

    
293
#: Display a message for console access
294
CONS_MESSAGE = "msg"
295

    
296
#: All console types
297
CONS_ALL = compat.UniqueFrozenset([
298
  CONS_SSH,
299
  CONS_VNC,
300
  CONS_SPICE,
301
  CONS_MESSAGE,
302
  ])
303

    
304
# For RSA keys more bits are better, but they also make operations more
305
# expensive. NIST SP 800-131 recommends a minimum of 2048 bits from the year
306
# 2010 on.
307
RSA_KEY_BITS = 2048
308

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

    
317
# Digest used to sign certificates ("openssl x509" uses SHA1 by default)
318
X509_CERT_SIGN_DIGEST = "SHA1"
319

    
320
# Default validity of certificates in days
321
X509_CERT_DEFAULT_VALIDITY = 365 * 5
322

    
323
# commonName (CN) used in certificates
324
X509_CERT_CN = "ganeti.example.com"
325

    
326
X509_CERT_SIGNATURE_HEADER = "X-Ganeti-Signature"
327

    
328
# Import/export daemon mode
329
IEM_IMPORT = "import"
330
IEM_EXPORT = "export"
331

    
332
# Import/export transport compression
333
IEC_NONE = "none"
334
IEC_GZIP = "gzip"
335
IEC_ALL = compat.UniqueFrozenset([
336
  IEC_NONE,
337
  IEC_GZIP,
338
  ])
339

    
340
IE_CUSTOM_SIZE = "fd"
341

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

    
344
# Import/export I/O
345
# Direct file I/O, equivalent to a shell's I/O redirection using '<' or '>'
346
IEIO_FILE = "file"
347
# Raw block device I/O using "dd"
348
IEIO_RAW_DISK = "raw"
349
# OS definition import/export script
350
IEIO_SCRIPT = "script"
351

    
352
VALUE_DEFAULT = "default"
353
VALUE_AUTO = "auto"
354
VALUE_GENERATE = "generate"
355
VALUE_NONE = "none"
356
VALUE_TRUE = "true"
357
VALUE_FALSE = "false"
358

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

    
362
# hooks-related constants
363
HOOKS_PHASE_PRE = "pre"
364
HOOKS_PHASE_POST = "post"
365
HOOKS_NAME_CFGUPDATE = "config-update"
366
HOOKS_NAME_WATCHER = "watcher"
367
HOOKS_VERSION = 2
368
HOOKS_PATH = "/sbin:/bin:/usr/sbin:/usr/bin"
369

    
370
# hooks subject type (what object type does the LU deal with)
371
HTYPE_CLUSTER = "CLUSTER"
372
HTYPE_NODE = "NODE"
373
HTYPE_GROUP = "GROUP"
374
HTYPE_INSTANCE = "INSTANCE"
375
HTYPE_NETWORK = "NETWORK"
376

    
377
HKR_SKIP = 0
378
HKR_FAIL = 1
379
HKR_SUCCESS = 2
380

    
381
# Storage types
382
ST_BLOCK = "blockdev"
383
ST_DISKLESS = "diskless"
384
ST_EXT = "ext"
385
ST_FILE = "file"
386
ST_LVM_PV = "lvm-pv"
387
ST_LVM_VG = "lvm-vg"
388
ST_RADOS = "rados"
389

    
390
VALID_STORAGE_TYPES = compat.UniqueFrozenset([
391
  ST_BLOCK,
392
  ST_DISKLESS,
393
  ST_EXT,
394
  ST_FILE,
395
  ST_LVM_PV,
396
  ST_LVM_VG,
397
  ST_RADOS,
398
  ])
399

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
542
# the set of disk templates that can be moved by copying
543
# Note: a requirement is that they're not accessed externally or shared between
544
# nodes; in particular, sharedfile is not suitable.
545
DTS_COPYABLE = compat.UniqueFrozenset([
546
  DT_FILE,
547
  DT_PLAIN,
548
  ])
549

    
550
# the set of disk templates that are supported by exclusive_storage
551
DTS_EXCL_STORAGE = compat.UniqueFrozenset([DT_PLAIN])
552

    
553
# templates for which we don't perform checks on free space
554
DTS_NO_FREE_SPACE_CHECK = compat.UniqueFrozenset([
555
  DT_FILE,
556
  DT_SHARED_FILE,
557
  DT_RBD,
558
  DT_EXT,
559
  ])
560

    
561
# logical disk types
562
LD_LV = "lvm"
563
LD_DRBD8 = "drbd8"
564
LD_FILE = "file"
565
LD_BLOCKDEV = "blockdev"
566
LD_RBD = "rbd"
567
LD_EXT = "ext"
568
LOGICAL_DISK_TYPES = compat.UniqueFrozenset([
569
  LD_LV,
570
  LD_DRBD8,
571
  LD_FILE,
572
  LD_BLOCKDEV,
573
  LD_RBD,
574
  LD_EXT,
575
  ])
576

    
577
LDS_BLOCK = compat.UniqueFrozenset([
578
  LD_LV,
579
  LD_DRBD8,
580
  LD_BLOCKDEV,
581
  LD_RBD,
582
  LD_EXT,
583
  ])
584

    
585
# drbd constants
586
DRBD_HMAC_ALG = "md5"
587
DRBD_NET_PROTOCOL = "C"
588
DRBD_STATUS_FILE = "/proc/drbd"
589

    
590
#: Size of DRBD meta block device
591
DRBD_META_SIZE = 128
592

    
593
# drbd barrier types
594
DRBD_B_NONE = "n"
595
DRBD_B_DISK_BARRIERS = "b"
596
DRBD_B_DISK_DRAIN = "d"
597
DRBD_B_DISK_FLUSH = "f"
598

    
599
# Valid barrier combinations: "n" or any non-null subset of "bfd"
600
DRBD_VALID_BARRIER_OPT = compat.UniqueFrozenset([
601
  frozenset([DRBD_B_NONE]),
602
  frozenset([DRBD_B_DISK_BARRIERS]),
603
  frozenset([DRBD_B_DISK_DRAIN]),
604
  frozenset([DRBD_B_DISK_FLUSH]),
605
  frozenset([DRBD_B_DISK_DRAIN, DRBD_B_DISK_FLUSH]),
606
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_DRAIN]),
607
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_FLUSH]),
608
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_FLUSH, DRBD_B_DISK_DRAIN]),
609
  ])
610

    
611
# rbd tool command
612
RBD_CMD = "rbd"
613

    
614
# file backend driver
615
FD_LOOP = "loop"
616
FD_BLKTAP = "blktap"
617

    
618
# the set of drbd-like disk types
619
LDS_DRBD = compat.UniqueFrozenset([LD_DRBD8])
620

    
621
# disk access mode
622
DISK_RDONLY = "ro"
623
DISK_RDWR = "rw"
624
DISK_ACCESS_SET = compat.UniqueFrozenset([DISK_RDONLY, DISK_RDWR])
625

    
626
# disk replacement mode
627
REPLACE_DISK_PRI = "replace_on_primary"    # replace disks on primary
628
REPLACE_DISK_SEC = "replace_on_secondary"  # replace disks on secondary
629
REPLACE_DISK_CHG = "replace_new_secondary" # change secondary node
630
REPLACE_DISK_AUTO = "replace_auto"
631
REPLACE_MODES = compat.UniqueFrozenset([
632
  REPLACE_DISK_PRI,
633
  REPLACE_DISK_SEC,
634
  REPLACE_DISK_CHG,
635
  REPLACE_DISK_AUTO,
636
  ])
637

    
638
# Instance export mode
639
EXPORT_MODE_LOCAL = "local"
640
EXPORT_MODE_REMOTE = "remote"
641
EXPORT_MODES = compat.UniqueFrozenset([
642
  EXPORT_MODE_LOCAL,
643
  EXPORT_MODE_REMOTE,
644
  ])
645

    
646
# instance creation modes
647
INSTANCE_CREATE = "create"
648
INSTANCE_IMPORT = "import"
649
INSTANCE_REMOTE_IMPORT = "remote-import"
650
INSTANCE_CREATE_MODES = compat.UniqueFrozenset([
651
  INSTANCE_CREATE,
652
  INSTANCE_IMPORT,
653
  INSTANCE_REMOTE_IMPORT,
654
  ])
655

    
656
# Remote import/export handshake message and version
657
RIE_VERSION = 0
658
RIE_HANDSHAKE = "Hi, I'm Ganeti"
659

    
660
# Remote import/export certificate validity in seconds
661
RIE_CERT_VALIDITY = 24 * 60 * 60
662

    
663
# Overall timeout for establishing connection
664
RIE_CONNECT_TIMEOUT = 180
665

    
666
# Export only: how long to wait per connection attempt (seconds)
667
RIE_CONNECT_ATTEMPT_TIMEOUT = 20
668

    
669
# Export only: number of attempts to connect
670
RIE_CONNECT_RETRIES = 10
671

    
672
#: Give child process up to 5 seconds to exit after sending a signal
673
CHILD_LINGER_TIMEOUT = 5.0
674

    
675
FILE_DRIVER = compat.UniqueFrozenset([FD_LOOP, FD_BLKTAP])
676

    
677
# import/export config options
678
INISECT_EXP = "export"
679
INISECT_INS = "instance"
680
INISECT_HYP = "hypervisor"
681
INISECT_BEP = "backend"
682
INISECT_OSP = "os"
683

    
684
# dynamic device modification
685
DDM_ADD = "add"
686
DDM_MODIFY = "modify"
687
DDM_REMOVE = "remove"
688
DDMS_VALUES = compat.UniqueFrozenset([DDM_ADD, DDM_REMOVE])
689
DDMS_VALUES_WITH_MODIFY = (DDMS_VALUES | frozenset([
690
  DDM_MODIFY,
691
  ]))
692
# TODO: DDM_SWAP, DDM_MOVE?
693

    
694
# common exit codes
695
EXIT_SUCCESS = 0
696
EXIT_FAILURE = 1
697
EXIT_NOTCLUSTER = 5
698
EXIT_NOTMASTER = 11
699
EXIT_NODESETUP_ERROR = 12
700
EXIT_CONFIRMATION = 13 # need user confirmation
701

    
702
#: Exit code for query operations with unknown fields
703
EXIT_UNKNOWN_FIELD = 14
704

    
705
# tags
706
TAG_CLUSTER = "cluster"
707
TAG_NODEGROUP = "nodegroup"
708
TAG_NODE = "node"
709
TAG_INSTANCE = "instance"
710
TAG_NETWORK = "network"
711
VALID_TAG_TYPES = compat.UniqueFrozenset([
712
  TAG_CLUSTER,
713
  TAG_NODEGROUP,
714
  TAG_NODE,
715
  TAG_INSTANCE,
716
  TAG_NETWORK,
717
  ])
718
MAX_TAG_LEN = 128
719
MAX_TAGS_PER_OBJ = 4096
720

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

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

    
749
#: Key for job IDs in opcode result
750
JOB_IDS_KEY = "jobs"
751

    
752
# runparts results
753
(RUNPARTS_SKIP,
754
 RUNPARTS_RUN,
755
 RUNPARTS_ERR) = range(3)
756

    
757
RUNPARTS_STATUS = compat.UniqueFrozenset([
758
  RUNPARTS_SKIP,
759
  RUNPARTS_RUN,
760
  RUNPARTS_ERR,
761
  ])
762

    
763
# RPC constants
764
(RPC_ENCODING_NONE,
765
 RPC_ENCODING_ZLIB_BASE64) = range(2)
766

    
767
# Various time constants for the timeout table
768
RPC_TMO_URGENT = 60 # one minute
769
RPC_TMO_FAST = 5 * 60 # five minutes
770
RPC_TMO_NORMAL = 15 * 60 # 15 minutes
771
RPC_TMO_SLOW = 3600 # one hour
772
RPC_TMO_4HRS = 4 * 3600
773
RPC_TMO_1DAY = 86400
774

    
775
# Timeout for connecting to nodes (seconds)
776
RPC_CONNECT_TIMEOUT = 5
777

    
778
# os related constants
779
OS_SCRIPT_CREATE = "create"
780
OS_SCRIPT_IMPORT = "import"
781
OS_SCRIPT_EXPORT = "export"
782
OS_SCRIPT_RENAME = "rename"
783
OS_SCRIPT_VERIFY = "verify"
784
OS_SCRIPTS = compat.UniqueFrozenset([
785
  OS_SCRIPT_CREATE,
786
  OS_SCRIPT_IMPORT,
787
  OS_SCRIPT_EXPORT,
788
  OS_SCRIPT_RENAME,
789
  OS_SCRIPT_VERIFY,
790
  ])
791

    
792
OS_API_FILE = "ganeti_api_version"
793
OS_VARIANTS_FILE = "variants.list"
794
OS_PARAMETERS_FILE = "parameters.list"
795

    
796
OS_VALIDATE_PARAMETERS = "parameters"
797
OS_VALIDATE_CALLS = compat.UniqueFrozenset([OS_VALIDATE_PARAMETERS])
798

    
799
# External Storage (ES) related constants
800
ES_ACTION_CREATE = "create"
801
ES_ACTION_REMOVE = "remove"
802
ES_ACTION_GROW = "grow"
803
ES_ACTION_ATTACH = "attach"
804
ES_ACTION_DETACH = "detach"
805
ES_ACTION_SETINFO = "setinfo"
806
ES_ACTION_VERIFY = "verify"
807

    
808
ES_SCRIPT_CREATE = ES_ACTION_CREATE
809
ES_SCRIPT_REMOVE = ES_ACTION_REMOVE
810
ES_SCRIPT_GROW = ES_ACTION_GROW
811
ES_SCRIPT_ATTACH = ES_ACTION_ATTACH
812
ES_SCRIPT_DETACH = ES_ACTION_DETACH
813
ES_SCRIPT_SETINFO = ES_ACTION_SETINFO
814
ES_SCRIPT_VERIFY = ES_ACTION_VERIFY
815
ES_SCRIPTS = frozenset([
816
  ES_SCRIPT_CREATE,
817
  ES_SCRIPT_REMOVE,
818
  ES_SCRIPT_GROW,
819
  ES_SCRIPT_ATTACH,
820
  ES_SCRIPT_DETACH,
821
  ES_SCRIPT_SETINFO,
822
  ES_SCRIPT_VERIFY
823
  ])
824

    
825
ES_PARAMETERS_FILE = "parameters.list"
826

    
827
# reboot types
828
INSTANCE_REBOOT_SOFT = "soft"
829
INSTANCE_REBOOT_HARD = "hard"
830
INSTANCE_REBOOT_FULL = "full"
831

    
832
REBOOT_TYPES = compat.UniqueFrozenset([
833
  INSTANCE_REBOOT_SOFT,
834
  INSTANCE_REBOOT_HARD,
835
  INSTANCE_REBOOT_FULL,
836
  ])
837

    
838
# instance reboot behaviors
839
INSTANCE_REBOOT_ALLOWED = "reboot"
840
INSTANCE_REBOOT_EXIT = "exit"
841

    
842
REBOOT_BEHAVIORS = compat.UniqueFrozenset([
843
  INSTANCE_REBOOT_ALLOWED,
844
  INSTANCE_REBOOT_EXIT,
845
  ])
846

    
847
VTYPE_STRING = "string"
848
VTYPE_MAYBE_STRING = "maybe-string"
849
VTYPE_BOOL = "bool"
850
VTYPE_SIZE = "size" # size, in MiBs
851
VTYPE_INT = "int"
852
ENFORCEABLE_TYPES = compat.UniqueFrozenset([
853
  VTYPE_STRING,
854
  VTYPE_MAYBE_STRING,
855
  VTYPE_BOOL,
856
  VTYPE_SIZE,
857
  VTYPE_INT,
858
  ])
859

    
860
# Constant representing that the user does not specify any IP version
861
IFACE_NO_IP_VERSION_SPECIFIED = 0
862

    
863
VALID_SERIAL_SPEEDS = compat.UniqueFrozenset([
864
  75,
865
  110,
866
  300,
867
  600,
868
  1200,
869
  1800,
870
  2400,
871
  4800,
872
  9600,
873
  14400,
874
  19200,
875
  28800,
876
  38400,
877
  57600,
878
  115200,
879
  230400,
880
  345600,
881
  460800,
882
  ])
883

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

    
953

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

    
1024
HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
1025

    
1026
HVS_PARAMETER_TITLES = {
1027
  HV_ACPI: "ACPI",
1028
  HV_BOOT_ORDER: "Boot_order",
1029
  HV_CDROM_IMAGE_PATH: "CDROM_image_path",
1030
  HV_DISK_TYPE: "Disk_type",
1031
  HV_INITRD_PATH: "Initrd_path",
1032
  HV_KERNEL_PATH: "Kernel_path",
1033
  HV_NIC_TYPE: "NIC_type",
1034
  HV_PAE: "PAE",
1035
  HV_VNC_BIND_ADDRESS: "VNC_bind_address",
1036
  HV_PASSTHROUGH: "pci_pass",
1037
  HV_CPU_TYPE: "cpu_type",
1038
  }
1039

    
1040
# Migration statuses
1041
HV_MIGRATION_COMPLETED = "completed"
1042
HV_MIGRATION_ACTIVE = "active"
1043
HV_MIGRATION_FAILED = "failed"
1044
HV_MIGRATION_CANCELLED = "cancelled"
1045

    
1046
HV_MIGRATION_VALID_STATUSES = compat.UniqueFrozenset([
1047
  HV_MIGRATION_COMPLETED,
1048
  HV_MIGRATION_ACTIVE,
1049
  HV_MIGRATION_FAILED,
1050
  HV_MIGRATION_CANCELLED,
1051
  ])
1052

    
1053
HV_MIGRATION_FAILED_STATUSES = compat.UniqueFrozenset([
1054
  HV_MIGRATION_FAILED,
1055
  HV_MIGRATION_CANCELLED,
1056
  ])
1057

    
1058
# KVM-specific statuses
1059
HV_KVM_MIGRATION_VALID_STATUSES = HV_MIGRATION_VALID_STATUSES
1060

    
1061
# Node info keys
1062
HV_NODEINFO_KEY_VERSION = "hv_version"
1063

    
1064
# Hypervisor state
1065
HVST_MEMORY_TOTAL = "mem_total"
1066
HVST_MEMORY_NODE = "mem_node"
1067
HVST_MEMORY_HV = "mem_hv"
1068
HVST_CPU_TOTAL = "cpu_total"
1069
HVST_CPU_NODE = "cpu_node"
1070

    
1071
HVST_DEFAULTS = {
1072
  HVST_MEMORY_TOTAL: 0,
1073
  HVST_MEMORY_NODE: 0,
1074
  HVST_MEMORY_HV: 0,
1075
  HVST_CPU_TOTAL: 1,
1076
  HVST_CPU_NODE: 1,
1077
  }
1078

    
1079
HVSTS_PARAMETER_TYPES = {
1080
  HVST_MEMORY_TOTAL: VTYPE_INT,
1081
  HVST_MEMORY_NODE: VTYPE_INT,
1082
  HVST_MEMORY_HV: VTYPE_INT,
1083
  HVST_CPU_TOTAL: VTYPE_INT,
1084
  HVST_CPU_NODE: VTYPE_INT,
1085
  }
1086

    
1087
HVSTS_PARAMETERS = frozenset(HVSTS_PARAMETER_TYPES.keys())
1088

    
1089
# Disk state
1090
DS_DISK_TOTAL = "disk_total"
1091
DS_DISK_RESERVED = "disk_reserved"
1092
DS_DISK_OVERHEAD = "disk_overhead"
1093

    
1094
DS_DEFAULTS = {
1095
  DS_DISK_TOTAL: 0,
1096
  DS_DISK_RESERVED: 0,
1097
  DS_DISK_OVERHEAD: 0,
1098
  }
1099

    
1100
DSS_PARAMETER_TYPES = {
1101
  DS_DISK_TOTAL: VTYPE_INT,
1102
  DS_DISK_RESERVED: VTYPE_INT,
1103
  DS_DISK_OVERHEAD: VTYPE_INT,
1104
  }
1105

    
1106
DSS_PARAMETERS = frozenset(DSS_PARAMETER_TYPES.keys())
1107
DS_VALID_TYPES = compat.UniqueFrozenset([LD_LV])
1108

    
1109
# Backend parameter names
1110
BE_MEMORY = "memory" # deprecated and replaced by max and min mem
1111
BE_MAXMEM = "maxmem"
1112
BE_MINMEM = "minmem"
1113
BE_VCPUS = "vcpus"
1114
BE_AUTO_BALANCE = "auto_balance"
1115
BE_ALWAYS_FAILOVER = "always_failover"
1116
BE_SPINDLE_USE = "spindle_use"
1117

    
1118
BES_PARAMETER_TYPES = {
1119
  BE_MAXMEM: VTYPE_SIZE,
1120
  BE_MINMEM: VTYPE_SIZE,
1121
  BE_VCPUS: VTYPE_INT,
1122
  BE_AUTO_BALANCE: VTYPE_BOOL,
1123
  BE_ALWAYS_FAILOVER: VTYPE_BOOL,
1124
  BE_SPINDLE_USE: VTYPE_INT,
1125
  }
1126

    
1127
BES_PARAMETER_TITLES = {
1128
  BE_AUTO_BALANCE: "Auto_balance",
1129
  BE_MAXMEM: "ConfigMaxMem",
1130
  BE_MINMEM: "ConfigMinMem",
1131
  BE_VCPUS: "ConfigVCPUs",
1132
  }
1133

    
1134
BES_PARAMETER_COMPAT = {
1135
  BE_MEMORY: VTYPE_SIZE,
1136
  }
1137
BES_PARAMETER_COMPAT.update(BES_PARAMETER_TYPES)
1138

    
1139
BES_PARAMETERS = frozenset(BES_PARAMETER_TYPES.keys())
1140

    
1141
# instance specs
1142
ISPEC_MEM_SIZE = "memory-size"
1143
ISPEC_CPU_COUNT = "cpu-count"
1144
ISPEC_DISK_COUNT = "disk-count"
1145
ISPEC_DISK_SIZE = "disk-size"
1146
ISPEC_NIC_COUNT = "nic-count"
1147
ISPEC_SPINDLE_USE = "spindle-use"
1148

    
1149
ISPECS_PARAMETER_TYPES = {
1150
  ISPEC_MEM_SIZE: VTYPE_INT,
1151
  ISPEC_CPU_COUNT: VTYPE_INT,
1152
  ISPEC_DISK_COUNT: VTYPE_INT,
1153
  ISPEC_DISK_SIZE: VTYPE_INT,
1154
  ISPEC_NIC_COUNT: VTYPE_INT,
1155
  ISPEC_SPINDLE_USE: VTYPE_INT,
1156
  }
1157

    
1158
ISPECS_PARAMETERS = frozenset(ISPECS_PARAMETER_TYPES.keys())
1159

    
1160
ISPECS_MINMAX = "minmax"
1161
ISPECS_MIN = "min"
1162
ISPECS_MAX = "max"
1163
ISPECS_STD = "std"
1164
IPOLICY_DTS = "disk-templates"
1165
IPOLICY_VCPU_RATIO = "vcpu-ratio"
1166
IPOLICY_SPINDLE_RATIO = "spindle-ratio"
1167

    
1168
ISPECS_MINMAX_KEYS = compat.UniqueFrozenset([
1169
  ISPECS_MIN,
1170
  ISPECS_MAX,
1171
  ])
1172

    
1173
IPOLICY_PARAMETERS = compat.UniqueFrozenset([
1174
  IPOLICY_VCPU_RATIO,
1175
  IPOLICY_SPINDLE_RATIO,
1176
  ])
1177

    
1178
IPOLICY_ALL_KEYS = (IPOLICY_PARAMETERS |
1179
                    frozenset([ISPECS_MINMAX, ISPECS_STD, IPOLICY_DTS]))
1180

    
1181
# Node parameter names
1182
ND_OOB_PROGRAM = "oob_program"
1183
ND_SPINDLE_COUNT = "spindle_count"
1184
ND_EXCLUSIVE_STORAGE = "exclusive_storage"
1185

    
1186
NDS_PARAMETER_TYPES = {
1187
  ND_OOB_PROGRAM: VTYPE_STRING,
1188
  ND_SPINDLE_COUNT: VTYPE_INT,
1189
  ND_EXCLUSIVE_STORAGE: VTYPE_BOOL,
1190
  }
1191

    
1192
NDS_PARAMETERS = frozenset(NDS_PARAMETER_TYPES.keys())
1193

    
1194
NDS_PARAMETER_TITLES = {
1195
  ND_OOB_PROGRAM: "OutOfBandProgram",
1196
  ND_SPINDLE_COUNT: "SpindleCount",
1197
  ND_EXCLUSIVE_STORAGE: "ExclusiveStorage",
1198
  }
1199

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

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

    
1270
DISK_DT_PARAMETERS = frozenset(DISK_DT_TYPES.keys())
1271

    
1272
# OOB supported commands
1273
OOB_POWER_ON = "power-on"
1274
OOB_POWER_OFF = "power-off"
1275
OOB_POWER_CYCLE = "power-cycle"
1276
OOB_POWER_STATUS = "power-status"
1277
OOB_HEALTH = "health"
1278

    
1279
OOB_COMMANDS = compat.UniqueFrozenset([
1280
  OOB_POWER_ON,
1281
  OOB_POWER_OFF,
1282
  OOB_POWER_CYCLE,
1283
  OOB_POWER_STATUS,
1284
  OOB_HEALTH,
1285
  ])
1286

    
1287
OOB_POWER_STATUS_POWERED = "powered"
1288

    
1289
OOB_TIMEOUT = 60 # 60 seconds
1290
OOB_POWER_DELAY = 2.0 # 2 seconds
1291

    
1292
OOB_STATUS_OK = "OK"
1293
OOB_STATUS_WARNING = "WARNING"
1294
OOB_STATUS_CRITICAL = "CRITICAL"
1295
OOB_STATUS_UNKNOWN = "UNKNOWN"
1296

    
1297
OOB_STATUSES = compat.UniqueFrozenset([
1298
  OOB_STATUS_OK,
1299
  OOB_STATUS_WARNING,
1300
  OOB_STATUS_CRITICAL,
1301
  OOB_STATUS_UNKNOWN,
1302
  ])
1303

    
1304
# Instance Parameters Profile
1305
PP_DEFAULT = "default"
1306

    
1307
# NIC_* constants are used inside the ganeti config
1308
NIC_MODE = "mode"
1309
NIC_LINK = "link"
1310

    
1311
NIC_MODE_BRIDGED = "bridged"
1312
NIC_MODE_ROUTED = "routed"
1313
NIC_MODE_OVS = "openvswitch"
1314
NIC_IP_POOL = "pool"
1315

    
1316
NIC_VALID_MODES = compat.UniqueFrozenset([
1317
  NIC_MODE_BRIDGED,
1318
  NIC_MODE_ROUTED,
1319
  NIC_MODE_OVS,
1320
  ])
1321

    
1322
RESERVE_ACTION = "reserve"
1323
RELEASE_ACTION = "release"
1324

    
1325
NICS_PARAMETER_TYPES = {
1326
  NIC_MODE: VTYPE_STRING,
1327
  NIC_LINK: VTYPE_STRING,
1328
  }
1329

    
1330
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
1331

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

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

    
1368
# Hypervisor constants
1369
HT_XEN_PVM = "xen-pvm"
1370
HT_FAKE = "fake"
1371
HT_XEN_HVM = "xen-hvm"
1372
HT_KVM = "kvm"
1373
HT_CHROOT = "chroot"
1374
HT_LXC = "lxc"
1375
HYPER_TYPES = compat.UniqueFrozenset([
1376
  HT_XEN_PVM,
1377
  HT_FAKE,
1378
  HT_XEN_HVM,
1379
  HT_KVM,
1380
  HT_CHROOT,
1381
  HT_LXC,
1382
  ])
1383
HTS_REQ_PORT = compat.UniqueFrozenset([HT_XEN_HVM, HT_KVM])
1384

    
1385
VNC_BASE_PORT = 5900
1386
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
1387

    
1388
# NIC types
1389
HT_NIC_RTL8139 = "rtl8139"
1390
HT_NIC_NE2K_PCI = "ne2k_pci"
1391
HT_NIC_NE2K_ISA = "ne2k_isa"
1392
HT_NIC_I82551 = "i82551"
1393
HT_NIC_I85557B = "i82557b"
1394
HT_NIC_I8259ER = "i82559er"
1395
HT_NIC_PCNET = "pcnet"
1396
HT_NIC_E1000 = "e1000"
1397
HT_NIC_PARAVIRTUAL = HT_DISK_PARAVIRTUAL = "paravirtual"
1398

    
1399
HT_HVM_VALID_NIC_TYPES = compat.UniqueFrozenset([
1400
  HT_NIC_RTL8139,
1401
  HT_NIC_NE2K_PCI,
1402
  HT_NIC_E1000,
1403
  HT_NIC_NE2K_ISA,
1404
  HT_NIC_PARAVIRTUAL,
1405
  ])
1406
HT_KVM_VALID_NIC_TYPES = compat.UniqueFrozenset([
1407
  HT_NIC_RTL8139,
1408
  HT_NIC_NE2K_PCI,
1409
  HT_NIC_NE2K_ISA,
1410
  HT_NIC_I82551,
1411
  HT_NIC_I85557B,
1412
  HT_NIC_I8259ER,
1413
  HT_NIC_PCNET,
1414
  HT_NIC_E1000,
1415
  HT_NIC_PARAVIRTUAL,
1416
  ])
1417

    
1418
# Vif types
1419
# default vif type in xen-hvm
1420
HT_HVM_VIF_IOEMU = "ioemu"
1421
HT_HVM_VIF_VIF = "vif"
1422
HT_HVM_VALID_VIF_TYPES = compat.UniqueFrozenset([
1423
  HT_HVM_VIF_IOEMU,
1424
  HT_HVM_VIF_VIF,
1425
  ])
1426

    
1427
# Disk types
1428
HT_DISK_IOEMU = "ioemu"
1429
HT_DISK_IDE = "ide"
1430
HT_DISK_SCSI = "scsi"
1431
HT_DISK_SD = "sd"
1432
HT_DISK_MTD = "mtd"
1433
HT_DISK_PFLASH = "pflash"
1434

    
1435
HT_CACHE_DEFAULT = "default"
1436
HT_CACHE_NONE = "none"
1437
HT_CACHE_WTHROUGH = "writethrough"
1438
HT_CACHE_WBACK = "writeback"
1439
HT_VALID_CACHE_TYPES = compat.UniqueFrozenset([
1440
  HT_CACHE_DEFAULT,
1441
  HT_CACHE_NONE,
1442
  HT_CACHE_WTHROUGH,
1443
  HT_CACHE_WBACK,
1444
  ])
1445

    
1446
HT_HVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1447
  HT_DISK_PARAVIRTUAL,
1448
  HT_DISK_IOEMU,
1449
  ])
1450
HT_KVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1451
  HT_DISK_PARAVIRTUAL,
1452
  HT_DISK_IDE,
1453
  HT_DISK_SCSI,
1454
  HT_DISK_SD,
1455
  HT_DISK_MTD,
1456
  HT_DISK_PFLASH,
1457
  ])
1458

    
1459
# Mouse types:
1460
HT_MOUSE_MOUSE = "mouse"
1461
HT_MOUSE_TABLET = "tablet"
1462

    
1463
HT_KVM_VALID_MOUSE_TYPES = compat.UniqueFrozenset([
1464
  HT_MOUSE_MOUSE,
1465
  HT_MOUSE_TABLET,
1466
  ])
1467

    
1468
# Boot order
1469
HT_BO_FLOPPY = "floppy"
1470
HT_BO_CDROM = "cdrom"
1471
HT_BO_DISK = "disk"
1472
HT_BO_NETWORK = "network"
1473

    
1474
HT_KVM_VALID_BO_TYPES = compat.UniqueFrozenset([
1475
  HT_BO_FLOPPY,
1476
  HT_BO_CDROM,
1477
  HT_BO_DISK,
1478
  HT_BO_NETWORK,
1479
  ])
1480

    
1481
# SPICE lossless image compression options
1482
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ = "auto_glz"
1483
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ = "auto_lz"
1484
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC = "quic"
1485
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ = "glz"
1486
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ = "lz"
1487
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF = "off"
1488

    
1489
HT_KVM_SPICE_VALID_LOSSLESS_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1490
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ,
1491
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ,
1492
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC,
1493
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ,
1494
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ,
1495
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF,
1496
  ])
1497

    
1498
# SPICE lossy image compression options (valid for both jpeg and zlib-glz)
1499
HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO = "auto"
1500
HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER = "never"
1501
HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS = "always"
1502

    
1503
HT_KVM_SPICE_VALID_LOSSY_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1504
  HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO,
1505
  HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER,
1506
  HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS,
1507
  ])
1508

    
1509
# SPICE video stream detection
1510
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF = "off"
1511
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL = "all"
1512
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER = "filter"
1513

    
1514
HT_KVM_SPICE_VALID_VIDEO_STREAM_DETECTION_OPTIONS = compat.UniqueFrozenset([
1515
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF,
1516
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL,
1517
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER,
1518
  ])
1519

    
1520
# Security models
1521
HT_SM_NONE = "none"
1522
HT_SM_USER = "user"
1523
HT_SM_POOL = "pool"
1524

    
1525
HT_KVM_VALID_SM_TYPES = compat.UniqueFrozenset([
1526
  HT_SM_NONE,
1527
  HT_SM_USER,
1528
  HT_SM_POOL,
1529
  ])
1530

    
1531
# Kvm flag values
1532
HT_KVM_ENABLED = "enabled"
1533
HT_KVM_DISABLED = "disabled"
1534

    
1535
HT_KVM_FLAG_VALUES = compat.UniqueFrozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
1536

    
1537
# Migration type
1538
HT_MIGRATION_LIVE = "live"
1539
HT_MIGRATION_NONLIVE = "non-live"
1540
HT_MIGRATION_MODES = compat.UniqueFrozenset([
1541
  HT_MIGRATION_LIVE,
1542
  HT_MIGRATION_NONLIVE,
1543
  ])
1544

    
1545
# Cluster Verify steps
1546
VERIFY_NPLUSONE_MEM = "nplusone_mem"
1547
VERIFY_OPTIONAL_CHECKS = compat.UniqueFrozenset([VERIFY_NPLUSONE_MEM])
1548

    
1549
# Cluster Verify error classes
1550
CV_TCLUSTER = "cluster"
1551
CV_TGROUP = "group"
1552
CV_TNODE = "node"
1553
CV_TINSTANCE = "instance"
1554

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

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

    
1672
CV_ALL_ECODES_STRINGS = \
1673
  compat.UniqueFrozenset(estr for (_, estr, _) in CV_ALL_ECODES)
1674

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

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

    
1720
# Admin states
1721
ADMINST_UP = "up"
1722
ADMINST_DOWN = "down"
1723
ADMINST_OFFLINE = "offline"
1724
ADMINST_ALL = compat.UniqueFrozenset([
1725
  ADMINST_UP,
1726
  ADMINST_DOWN,
1727
  ADMINST_OFFLINE,
1728
  ])
1729

    
1730
# Node roles
1731
NR_REGULAR = "R"
1732
NR_MASTER = "M"
1733
NR_MCANDIDATE = "C"
1734
NR_DRAINED = "D"
1735
NR_OFFLINE = "O"
1736
NR_ALL = compat.UniqueFrozenset([
1737
  NR_REGULAR,
1738
  NR_MASTER,
1739
  NR_MCANDIDATE,
1740
  NR_DRAINED,
1741
  NR_OFFLINE,
1742
  ])
1743

    
1744
# SSL certificate check constants (in days)
1745
SSL_CERT_EXPIRATION_WARN = 30
1746
SSL_CERT_EXPIRATION_ERROR = 7
1747

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

    
1771
IALLOCATOR_NEVAC_PRI = "primary-only"
1772
IALLOCATOR_NEVAC_SEC = "secondary-only"
1773
IALLOCATOR_NEVAC_ALL = "all"
1774
IALLOCATOR_NEVAC_MODES = compat.UniqueFrozenset([
1775
  IALLOCATOR_NEVAC_PRI,
1776
  IALLOCATOR_NEVAC_SEC,
1777
  IALLOCATOR_NEVAC_ALL,
1778
  ])
1779

    
1780
# Node evacuation
1781
NODE_EVAC_PRI = "primary-only"
1782
NODE_EVAC_SEC = "secondary-only"
1783
NODE_EVAC_ALL = "all"
1784
NODE_EVAC_MODES = compat.UniqueFrozenset([
1785
  NODE_EVAC_PRI,
1786
  NODE_EVAC_SEC,
1787
  NODE_EVAC_ALL,
1788
  ])
1789

    
1790
# Job queue
1791
JOB_QUEUE_VERSION = 1
1792
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
1793
JOB_QUEUE_FILES_PERMS = 0640
1794

    
1795
JOB_ID_TEMPLATE = r"\d+"
1796
JOB_FILE_RE = re.compile(r"^job-(%s)$" % JOB_ID_TEMPLATE)
1797

    
1798
# unchanged job return
1799
JOB_NOTCHANGED = "nochange"
1800

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

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

    
1839
# OpCode priority
1840
OP_PRIO_LOWEST = +19
1841
OP_PRIO_HIGHEST = -20
1842

    
1843
OP_PRIO_LOW = +10
1844
OP_PRIO_NORMAL = 0
1845
OP_PRIO_HIGH = -10
1846

    
1847
OP_PRIO_SUBMIT_VALID = compat.UniqueFrozenset([
1848
  OP_PRIO_LOW,
1849
  OP_PRIO_NORMAL,
1850
  OP_PRIO_HIGH,
1851
  ])
1852

    
1853
OP_PRIO_DEFAULT = OP_PRIO_NORMAL
1854

    
1855
# Lock recalculate mode
1856
LOCKS_REPLACE = "replace"
1857
LOCKS_APPEND = "append"
1858

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

    
1868
# Execution log types
1869
ELOG_MESSAGE = "message"
1870
ELOG_REMOTE_IMPORT = "remote-import"
1871
ELOG_JQUEUE_TEST = "jqueue-test"
1872

    
1873
# /etc/hosts modification
1874
ETC_HOSTS_ADD = "add"
1875
ETC_HOSTS_REMOVE = "remove"
1876

    
1877
# Job queue test
1878
JQT_MSGPREFIX = "TESTMSG="
1879
JQT_EXPANDNAMES = "expandnames"
1880
JQT_EXEC = "exec"
1881
JQT_LOGMSG = "logmsg"
1882
JQT_STARTMSG = "startmsg"
1883
JQT_ALL = compat.UniqueFrozenset([
1884
  JQT_EXPANDNAMES,
1885
  JQT_EXEC,
1886
  JQT_LOGMSG,
1887
  JQT_STARTMSG,
1888
  ])
1889

    
1890
# Query resources
1891
QR_CLUSTER = "cluster"
1892
QR_INSTANCE = "instance"
1893
QR_NODE = "node"
1894
QR_LOCK = "lock"
1895
QR_GROUP = "group"
1896
QR_OS = "os"
1897
QR_JOB = "job"
1898
QR_EXPORT = "export"
1899
QR_NETWORK = "network"
1900
QR_EXTSTORAGE = "extstorage"
1901

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

    
1914
#: List of resources which can be queried using Local UniX Interface
1915
QR_VIA_LUXI = QR_VIA_OP.union([
1916
  QR_LOCK,
1917
  QR_JOB,
1918
  ])
1919

    
1920
#: List of resources which can be queried using RAPI
1921
QR_VIA_RAPI = QR_VIA_LUXI
1922

    
1923
# Query field types
1924
QFT_UNKNOWN = "unknown"
1925
QFT_TEXT = "text"
1926
QFT_BOOL = "bool"
1927
QFT_NUMBER = "number"
1928
QFT_UNIT = "unit"
1929
QFT_TIMESTAMP = "timestamp"
1930
QFT_OTHER = "other"
1931

    
1932
#: All query field types
1933
QFT_ALL = compat.UniqueFrozenset([
1934
  QFT_UNKNOWN,
1935
  QFT_TEXT,
1936
  QFT_BOOL,
1937
  QFT_NUMBER,
1938
  QFT_UNIT,
1939
  QFT_TIMESTAMP,
1940
  QFT_OTHER,
1941
  ])
1942

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

    
1958
RS_ALL = compat.UniqueFrozenset([
1959
  RS_NORMAL,
1960
  RS_UNKNOWN,
1961
  RS_NODATA,
1962
  RS_UNAVAIL,
1963
  RS_OFFLINE,
1964
  ])
1965

    
1966
#: Dictionary with special field cases and their verbose/terse formatting
1967
RSS_DESCRIPTION = {
1968
  RS_UNKNOWN: ("(unknown)", "??"),
1969
  RS_NODATA: ("(nodata)", "?"),
1970
  RS_OFFLINE: ("(offline)", "*"),
1971
  RS_UNAVAIL: ("(unavail)", "-"),
1972
  }
1973

    
1974
# max dynamic devices
1975
MAX_NICS = 8
1976
MAX_DISKS = 16
1977

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

    
2005
SS_FILE_PERMS = 0444
2006

    
2007
# cluster wide default parameters
2008
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
2009

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

    
2116
HVC_GLOBALS = compat.UniqueFrozenset([
2117
  HV_MIGRATION_PORT,
2118
  HV_MIGRATION_BANDWIDTH,
2119
  HV_MIGRATION_MODE,
2120
  ])
2121

    
2122
BEC_DEFAULTS = {
2123
  BE_MINMEM: 128,
2124
  BE_MAXMEM: 128,
2125
  BE_VCPUS: 1,
2126
  BE_AUTO_BALANCE: True,
2127
  BE_ALWAYS_FAILOVER: False,
2128
  BE_SPINDLE_USE: 1,
2129
  }
2130

    
2131
NDC_DEFAULTS = {
2132
  ND_OOB_PROGRAM: "",
2133
  ND_SPINDLE_COUNT: 1,
2134
  ND_EXCLUSIVE_STORAGE: False,
2135
  }
2136

    
2137
NDC_GLOBALS = compat.UniqueFrozenset([
2138
  ND_EXCLUSIVE_STORAGE,
2139
  ])
2140

    
2141
DISK_LD_DEFAULTS = {
2142
  LD_DRBD8: {
2143
    LDP_RESYNC_RATE: CLASSIC_DRBD_SYNC_SPEED,
2144
    LDP_BARRIERS: _autoconf.DRBD_BARRIERS,
2145
    LDP_NO_META_FLUSH: _autoconf.DRBD_NO_META_FLUSH,
2146
    LDP_DEFAULT_METAVG: DEFAULT_VG,
2147
    LDP_DISK_CUSTOM: "",
2148
    LDP_NET_CUSTOM: "",
2149
    LDP_DYNAMIC_RESYNC: False,
2150

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

    
2173
# readability shortcuts
2174
_LV_DEFAULTS = DISK_LD_DEFAULTS[LD_LV]
2175
_DRBD_DEFAULTS = DISK_LD_DEFAULTS[LD_DRBD8]
2176

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

    
2207
# we don't want to export the shortcuts
2208
del _LV_DEFAULTS, _DRBD_DEFAULTS
2209

    
2210
NICC_DEFAULTS = {
2211
  NIC_MODE: NIC_MODE_BRIDGED,
2212
  NIC_LINK: DEFAULT_BRIDGE,
2213
  }
2214

    
2215
# All of the following values are quite arbitrarily - there are no
2216
# "good" defaults, these must be customised per-site
2217
ISPECS_MINMAX_DEFAULTS = {
2218
  ISPECS_MIN: {
2219
    ISPEC_MEM_SIZE: 128,
2220
    ISPEC_CPU_COUNT: 1,
2221
    ISPEC_DISK_COUNT: 1,
2222
    ISPEC_DISK_SIZE: 1024,
2223
    ISPEC_NIC_COUNT: 1,
2224
    ISPEC_SPINDLE_USE: 1,
2225
    },
2226
  ISPECS_MAX: {
2227
    ISPEC_MEM_SIZE: 32768,
2228
    ISPEC_CPU_COUNT: 8,
2229
    ISPEC_DISK_COUNT: MAX_DISKS,
2230
    ISPEC_DISK_SIZE: 1024 * 1024,
2231
    ISPEC_NIC_COUNT: MAX_NICS,
2232
    ISPEC_SPINDLE_USE: 12,
2233
    },
2234
  }
2235
IPOLICY_DEFAULTS = {
2236
  ISPECS_MINMAX: [ISPECS_MINMAX_DEFAULTS],
2237
  ISPECS_STD: {
2238
    ISPEC_MEM_SIZE: 128,
2239
    ISPEC_CPU_COUNT: 1,
2240
    ISPEC_DISK_COUNT: 1,
2241
    ISPEC_DISK_SIZE: 1024,
2242
    ISPEC_NIC_COUNT: 1,
2243
    ISPEC_SPINDLE_USE: 1,
2244
    },
2245
  IPOLICY_DTS: list(DISK_TEMPLATES),
2246
  IPOLICY_VCPU_RATIO: 4.0,
2247
  IPOLICY_SPINDLE_RATIO: 32.0,
2248
  }
2249

    
2250
MASTER_POOL_SIZE_DEFAULT = 10
2251

    
2252
# Exclusive storage:
2253
# Error margin used to compare physical disks
2254
PART_MARGIN = .01
2255
# Space reserved when creating instance disks
2256
PART_RESERVED = .02
2257

    
2258
CONFD_PROTOCOL_VERSION = 1
2259

    
2260
CONFD_REQ_PING = 0
2261
CONFD_REQ_NODE_ROLE_BYNAME = 1
2262
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
2263
CONFD_REQ_CLUSTER_MASTER = 3
2264
CONFD_REQ_NODE_PIP_LIST = 4
2265
CONFD_REQ_MC_PIP_LIST = 5
2266
CONFD_REQ_INSTANCES_IPS_LIST = 6
2267
CONFD_REQ_NODE_DRBD = 7
2268
CONFD_REQ_NODE_INSTANCES = 8
2269

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

    
2278
CONFD_REQFIELD_NAME = "0"
2279
CONFD_REQFIELD_IP = "1"
2280
CONFD_REQFIELD_MNODE_PIP = "2"
2281

    
2282
CONFD_REQS = compat.UniqueFrozenset([
2283
  CONFD_REQ_PING,
2284
  CONFD_REQ_NODE_ROLE_BYNAME,
2285
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
2286
  CONFD_REQ_CLUSTER_MASTER,
2287
  CONFD_REQ_NODE_PIP_LIST,
2288
  CONFD_REQ_MC_PIP_LIST,
2289
  CONFD_REQ_INSTANCES_IPS_LIST,
2290
  CONFD_REQ_NODE_DRBD,
2291
  ])
2292

    
2293
CONFD_REPL_STATUS_OK = 0
2294
CONFD_REPL_STATUS_ERROR = 1
2295
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
2296

    
2297
CONFD_REPL_STATUSES = compat.UniqueFrozenset([
2298
  CONFD_REPL_STATUS_OK,
2299
  CONFD_REPL_STATUS_ERROR,
2300
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
2301
  ])
2302

    
2303
(CONFD_NODE_ROLE_MASTER,
2304
 CONFD_NODE_ROLE_CANDIDATE,
2305
 CONFD_NODE_ROLE_OFFLINE,
2306
 CONFD_NODE_ROLE_DRAINED,
2307
 CONFD_NODE_ROLE_REGULAR,
2308
 ) = range(5)
2309

    
2310
# A few common errors for confd
2311
CONFD_ERROR_UNKNOWN_ENTRY = 1
2312
CONFD_ERROR_INTERNAL = 2
2313
CONFD_ERROR_ARGUMENT = 3
2314

    
2315
# Each request is "salted" by the current timestamp.
2316
# This constants decides how many seconds of skew to accept.
2317
# TODO: make this a default and allow the value to be more configurable
2318
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
2319

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

    
2326
# If we receive more than one update in this amount of microseconds,
2327
# we move to polling every RATELIMIT seconds, rather than relying on
2328
# inotify, to be able to serve more requests.
2329
CONFD_CONFIG_RELOAD_RATELIMIT = 250000
2330

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

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

    
2342
# Timeout in seconds to expire pending query request in the confd client
2343
# library. We don't actually expect any answer more than 10 seconds after we
2344
# sent a request.
2345
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
2346

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

    
2354
# User-id pool minimum/maximum acceptable user-ids.
2355
UIDPOOL_UID_MIN = 0
2356
UIDPOOL_UID_MAX = 2 ** 32 - 1 # Assuming 32 bit user-ids
2357

    
2358
# Name or path of the pgrep command
2359
PGREP = "pgrep"
2360

    
2361
# Name of the node group that gets created at cluster init or upgrade
2362
INITIAL_NODE_GROUP_NAME = "default"
2363

    
2364
# Possible values for NodeGroup.alloc_policy
2365
ALLOC_POLICY_PREFERRED = "preferred"
2366
ALLOC_POLICY_LAST_RESORT = "last_resort"
2367
ALLOC_POLICY_UNALLOCABLE = "unallocable"
2368
VALID_ALLOC_POLICIES = [
2369
  ALLOC_POLICY_PREFERRED,
2370
  ALLOC_POLICY_LAST_RESORT,
2371
  ALLOC_POLICY_UNALLOCABLE,
2372
  ]
2373

    
2374
# Temporary external/shared storage parameters
2375
BLOCKDEV_DRIVER_MANUAL = "manual"
2376

    
2377
# qemu-img path, required for ovfconverter
2378
QEMUIMG_PATH = _autoconf.QEMUIMG_PATH
2379

    
2380
# Whether htools was enabled at compilation time
2381
HTOOLS = _autoconf.HTOOLS
2382
# The hail iallocator
2383
IALLOC_HAIL = "hail"
2384

    
2385
# Fake opcodes for functions that have hooks attached to them via
2386
# backend.RunLocalHooks
2387
FAKE_OP_MASTER_TURNUP = "OP_CLUSTER_IP_TURNUP"
2388
FAKE_OP_MASTER_TURNDOWN = "OP_CLUSTER_IP_TURNDOWN"
2389

    
2390
# SSH key types
2391
SSHK_RSA = "rsa"
2392
SSHK_DSA = "dsa"
2393
SSHK_ALL = compat.UniqueFrozenset([SSHK_RSA, SSHK_DSA])
2394

    
2395
# SSH authorized key types
2396
SSHAK_RSA = "ssh-rsa"
2397
SSHAK_DSS = "ssh-dss"
2398
SSHAK_ALL = compat.UniqueFrozenset([SSHAK_RSA, SSHAK_DSS])
2399

    
2400
# SSH setup
2401
SSHS_CLUSTER_NAME = "cluster_name"
2402
SSHS_SSH_HOST_KEY = "ssh_host_key"
2403
SSHS_SSH_ROOT_KEY = "ssh_root_key"
2404
SSHS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2405

    
2406
#: Key files for SSH daemon
2407
SSH_DAEMON_KEYFILES = {
2408
  SSHK_RSA: (pathutils.SSH_HOST_RSA_PRIV, pathutils.SSH_HOST_RSA_PUB),
2409
  SSHK_DSA: (pathutils.SSH_HOST_DSA_PRIV, pathutils.SSH_HOST_DSA_PUB),
2410
  }
2411

    
2412
# Node daemon setup
2413
NDS_CLUSTER_NAME = "cluster_name"
2414
NDS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2415
NDS_SSCONF = "ssconf"
2416
NDS_START_NODE_DAEMON = "start_node_daemon"
2417

    
2418
# Path generating random UUID
2419
RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
2420

    
2421
# Regex string for verifying a UUID
2422
UUID_REGEX = "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
2423

    
2424
# Auto-repair tag prefixes
2425
AUTO_REPAIR_TAG_PREFIX = "ganeti:watcher:autorepair:"
2426
AUTO_REPAIR_TAG_ENABLED = AUTO_REPAIR_TAG_PREFIX
2427
AUTO_REPAIR_TAG_SUSPENDED = AUTO_REPAIR_TAG_ENABLED + "suspend:"
2428
AUTO_REPAIR_TAG_PENDING = AUTO_REPAIR_TAG_PREFIX + "pending:"
2429
AUTO_REPAIR_TAG_RESULT = AUTO_REPAIR_TAG_PREFIX + "result:"
2430

    
2431
# Auto-repair levels
2432
AUTO_REPAIR_FIX_STORAGE = "fix-storage"
2433
AUTO_REPAIR_MIGRATE = "migrate"
2434
AUTO_REPAIR_FAILOVER = "failover"
2435
AUTO_REPAIR_REINSTALL = "reinstall"
2436
AUTO_REPAIR_ALL_TYPES = [
2437
  AUTO_REPAIR_FIX_STORAGE,
2438
  AUTO_REPAIR_MIGRATE,
2439
  AUTO_REPAIR_FAILOVER,
2440
  AUTO_REPAIR_REINSTALL,
2441
]
2442

    
2443
# Auto-repair results
2444
AUTO_REPAIR_SUCCESS = "success"
2445
AUTO_REPAIR_FAILURE = "failure"
2446
AUTO_REPAIR_ENOPERM = "enoperm"
2447
AUTO_REPAIR_ALL_RESULTS = frozenset([
2448
    AUTO_REPAIR_SUCCESS,
2449
    AUTO_REPAIR_FAILURE,
2450
    AUTO_REPAIR_ENOPERM,
2451
])
2452

    
2453
# The version identifier for builtin data collectors
2454
BUILTIN_DATA_COLLECTOR_VERSION = "B"
2455

    
2456
# The reason trail opcode parameter name
2457
OPCODE_REASON = "reason"
2458

    
2459
# The source reasons for the execution of an OpCode
2460
OPCODE_REASON_SRC_CLIENT = "gnt:client"
2461
OPCODE_REASON_SRC_NODED = "gnt:daemon:noded"
2462
OPCODE_REASON_SRC_OPCODE = "gnt:opcode"
2463
OPCODE_REASON_SRC_RLIB2 = "gnt:library:rlib2"
2464
OPCODE_REASON_SRC_USER = "gnt:user"
2465

    
2466
OPCODE_REASON_SOURCES = compat.UniqueFrozenset([
2467
  OPCODE_REASON_SRC_CLIENT,
2468
  OPCODE_REASON_SRC_NODED,
2469
  OPCODE_REASON_SRC_OPCODE,
2470
  OPCODE_REASON_SRC_RLIB2,
2471
  OPCODE_REASON_SRC_USER,
2472
  ])
2473

    
2474
# Do not re-export imported modules
2475
del re, _vcsversion, _autoconf, socket, pathutils, compat