Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ 14013e5d

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

    
161
DAEMONS_PORTS = {
162
  # daemon-name: ("proto", "default-port")
163
  NODED: ("tcp", 1811),
164
  CONFD: ("udp", 1814),
165
  RAPI: ("tcp", 5080),
166
  SSH: ("tcp", 22),
167
}
168
DEFAULT_NODED_PORT = DAEMONS_PORTS[NODED][1]
169
DEFAULT_CONFD_PORT = DAEMONS_PORTS[CONFD][1]
170
DEFAULT_RAPI_PORT = DAEMONS_PORTS[RAPI][1]
171

    
172
FIRST_DRBD_PORT = 11000
173
LAST_DRBD_PORT = 14999
174

    
175
DAEMONS_LOGBASE = {
176
  NODED: "node-daemon",
177
  CONFD: "conf-daemon",
178
  RAPI: "rapi-daemon",
179
  MASTERD: "master-daemon",
180
  }
181

    
182
DAEMONS_LOGFILES = \
183
    dict((daemon, pathutils.GetLogFilename(DAEMONS_LOGBASE[daemon]))
184
         for daemon in DAEMONS_LOGBASE)
185

    
186
DEV_CONSOLE = "/dev/console"
187

    
188
PROC_MOUNTS = "/proc/mounts"
189

    
190
# Local UniX Interface related constants
191
LUXI_EOM = "\3"
192
LUXI_VERSION = CONFIG_VERSION
193
#: Environment variable for the luxi override socket
194
LUXI_OVERRIDE = "FORCE_LUXI_SOCKET"
195
LUXI_OVERRIDE_MASTER = "master"
196
LUXI_OVERRIDE_QUERY = "query"
197

    
198
# one of "no", "yes", "only"
199
SYSLOG_USAGE = _autoconf.SYSLOG_USAGE
200
SYSLOG_NO = "no"
201
SYSLOG_YES = "yes"
202
SYSLOG_ONLY = "only"
203
SYSLOG_SOCKET = "/dev/log"
204

    
205
EXPORT_CONF_FILE = "config.ini"
206

    
207
XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER
208
XEN_KERNEL = _autoconf.XEN_KERNEL
209
XEN_INITRD = _autoconf.XEN_INITRD
210
XEN_CMD_XM = "xm"
211
XEN_CMD_XL = "xl"
212
# FIXME: This will be made configurable using hvparams in Ganeti 2.7
213
XEN_CMD = _autoconf.XEN_CMD
214

    
215
KNOWN_XEN_COMMANDS = compat.UniqueFrozenset([
216
  XEN_CMD_XM,
217
  XEN_CMD_XL,
218
  ])
219

    
220
# When the Xen toolstack used is "xl", live migration requires the source host
221
# to connect to the target host via ssh (xl runs this command). We need to pass
222
# the command xl runs some extra info so that it can use Ganeti's key
223
# verification and not fail. Note that this string is incomplete: it must be
224
# filled with the cluster name before being used.
225
XL_SSH_CMD = ("ssh -l %s -oGlobalKnownHostsFile=%s"
226
              " -oUserKnownHostsFile=/dev/null"
227
              " -oCheckHostIp=no -oStrictHostKeyChecking=yes"
228
              " -oHostKeyAlias=%%s") % (SSH_LOGIN_USER,
229
                                        pathutils.SSH_KNOWN_HOSTS_FILE)
230

    
231
KVM_PATH = _autoconf.KVM_PATH
232
KVM_KERNEL = _autoconf.KVM_KERNEL
233
SOCAT_PATH = _autoconf.SOCAT_PATH
234
SOCAT_USE_ESCAPE = _autoconf.SOCAT_USE_ESCAPE
235
SOCAT_USE_COMPRESS = _autoconf.SOCAT_USE_COMPRESS
236
SOCAT_ESCAPE_CODE = "0x1d"
237

    
238
#: Console as SSH command
239
CONS_SSH = "ssh"
240

    
241
#: Console as VNC server
242
CONS_VNC = "vnc"
243

    
244
#: Console as SPICE server
245
CONS_SPICE = "spice"
246

    
247
#: Display a message for console access
248
CONS_MESSAGE = "msg"
249

    
250
#: All console types
251
CONS_ALL = compat.UniqueFrozenset([
252
  CONS_SSH,
253
  CONS_VNC,
254
  CONS_SPICE,
255
  CONS_MESSAGE,
256
  ])
257

    
258
# For RSA keys more bits are better, but they also make operations more
259
# expensive. NIST SP 800-131 recommends a minimum of 2048 bits from the year
260
# 2010 on.
261
RSA_KEY_BITS = 2048
262

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

    
271
# Digest used to sign certificates ("openssl x509" uses SHA1 by default)
272
X509_CERT_SIGN_DIGEST = "SHA1"
273

    
274
# Default validity of certificates in days
275
X509_CERT_DEFAULT_VALIDITY = 365 * 5
276

    
277
# commonName (CN) used in certificates
278
X509_CERT_CN = "ganeti.example.com"
279

    
280
X509_CERT_SIGNATURE_HEADER = "X-Ganeti-Signature"
281

    
282
# Import/export daemon mode
283
IEM_IMPORT = "import"
284
IEM_EXPORT = "export"
285

    
286
# Import/export transport compression
287
IEC_NONE = "none"
288
IEC_GZIP = "gzip"
289
IEC_ALL = compat.UniqueFrozenset([
290
  IEC_NONE,
291
  IEC_GZIP,
292
  ])
293

    
294
IE_CUSTOM_SIZE = "fd"
295

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

    
298
# Import/export I/O
299
# Direct file I/O, equivalent to a shell's I/O redirection using '<' or '>'
300
IEIO_FILE = "file"
301
# Raw block device I/O using "dd"
302
IEIO_RAW_DISK = "raw"
303
# OS definition import/export script
304
IEIO_SCRIPT = "script"
305

    
306
VALUE_DEFAULT = "default"
307
VALUE_AUTO = "auto"
308
VALUE_GENERATE = "generate"
309
VALUE_NONE = "none"
310
VALUE_TRUE = "true"
311
VALUE_FALSE = "false"
312

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

    
316
# hooks-related constants
317
HOOKS_PHASE_PRE = "pre"
318
HOOKS_PHASE_POST = "post"
319
HOOKS_NAME_CFGUPDATE = "config-update"
320
HOOKS_NAME_WATCHER = "watcher"
321
HOOKS_VERSION = 2
322
HOOKS_PATH = "/sbin:/bin:/usr/sbin:/usr/bin"
323

    
324
# hooks subject type (what object type does the LU deal with)
325
HTYPE_CLUSTER = "CLUSTER"
326
HTYPE_NODE = "NODE"
327
HTYPE_GROUP = "GROUP"
328
HTYPE_INSTANCE = "INSTANCE"
329
HTYPE_NETWORK = "NETWORK"
330

    
331
HKR_SKIP = 0
332
HKR_FAIL = 1
333
HKR_SUCCESS = 2
334

    
335
# Storage types
336
ST_FILE = "file"
337
ST_LVM_PV = "lvm-pv"
338
ST_LVM_VG = "lvm-vg"
339

    
340
# Storage fields
341
# first two are valid in LU context only, not passed to backend
342
SF_NODE = "node"
343
SF_TYPE = "type"
344
# and the rest are valid in backend
345
SF_NAME = "name"
346
SF_SIZE = "size"
347
SF_FREE = "free"
348
SF_USED = "used"
349
SF_ALLOCATABLE = "allocatable"
350

    
351
# Storage operations
352
SO_FIX_CONSISTENCY = "fix-consistency"
353

    
354
# Available fields per storage type
355
VALID_STORAGE_FIELDS = compat.UniqueFrozenset([
356
  SF_NAME,
357
  SF_TYPE,
358
  SF_SIZE,
359
  SF_USED,
360
  SF_FREE,
361
  SF_ALLOCATABLE,
362
  ])
363

    
364
VALID_STORAGE_TYPES = compat.UniqueFrozenset([
365
  ST_FILE,
366
  ST_LVM_PV,
367
  ST_LVM_VG,
368
  ])
369

    
370
MODIFIABLE_STORAGE_FIELDS = {
371
  ST_LVM_PV: frozenset([SF_ALLOCATABLE]),
372
  }
373

    
374
VALID_STORAGE_OPERATIONS = {
375
  ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
376
  }
377

    
378
# Local disk status
379
# Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
380
(LDS_OKAY,
381
 LDS_UNKNOWN,
382
 LDS_FAULTY) = range(1, 4)
383

    
384
# disk template types
385
DT_DISKLESS = "diskless"
386
DT_PLAIN = "plain"
387
DT_DRBD8 = "drbd"
388
DT_FILE = "file"
389
DT_SHARED_FILE = "sharedfile"
390
DT_BLOCK = "blockdev"
391
DT_RBD = "rbd"
392
DT_EXT = "ext"
393

    
394
# the set of network-mirrored disk templates
395
DTS_INT_MIRROR = compat.UniqueFrozenset([DT_DRBD8])
396

    
397
# the set of externally-mirrored disk templates (e.g. SAN, NAS)
398
DTS_EXT_MIRROR = compat.UniqueFrozenset([
399
  DT_SHARED_FILE,
400
  DT_BLOCK,
401
  DT_RBD,
402
  DT_EXT,
403
  ])
404

    
405
# the set of non-lvm-based disk templates
406
DTS_NOT_LVM = compat.UniqueFrozenset([
407
  DT_DISKLESS,
408
  DT_FILE,
409
  DT_SHARED_FILE,
410
  DT_BLOCK,
411
  DT_RBD,
412
  DT_EXT,
413
  ])
414

    
415
# the set of disk templates which can be grown
416
DTS_GROWABLE = compat.UniqueFrozenset([
417
  DT_PLAIN,
418
  DT_DRBD8,
419
  DT_FILE,
420
  DT_SHARED_FILE,
421
  DT_RBD,
422
  DT_EXT,
423
  ])
424

    
425
# the set of disk templates that allow adoption
426
DTS_MAY_ADOPT = compat.UniqueFrozenset([
427
  DT_PLAIN,
428
  DT_BLOCK,
429
  ])
430

    
431
# the set of disk templates that *must* use adoption
432
DTS_MUST_ADOPT = compat.UniqueFrozenset([DT_BLOCK])
433

    
434
# the set of disk templates that allow migrations
435
DTS_MIRRORED = frozenset.union(DTS_INT_MIRROR, DTS_EXT_MIRROR)
436

    
437
# the set of file based disk templates
438
DTS_FILEBASED = compat.UniqueFrozenset([
439
  DT_FILE,
440
  DT_SHARED_FILE,
441
  ])
442

    
443
# the set of disk templates that are supported by exclusive_storage
444
DTS_EXCL_STORAGE = compat.UniqueFrozenset([DT_PLAIN])
445

    
446
# templates for which we don't perform checks on free space
447
DTS_NO_FREE_SPACE_CHECK = compat.UniqueFrozenset([
448
  DT_FILE,
449
  DT_SHARED_FILE,
450
  DT_RBD,
451
  DT_EXT,
452
  ])
453

    
454
# logical disk types
455
LD_LV = "lvm"
456
LD_DRBD8 = "drbd8"
457
LD_FILE = "file"
458
LD_BLOCKDEV = "blockdev"
459
LD_RBD = "rbd"
460
LD_EXT = "ext"
461
LOGICAL_DISK_TYPES = compat.UniqueFrozenset([
462
  LD_LV,
463
  LD_DRBD8,
464
  LD_FILE,
465
  LD_BLOCKDEV,
466
  LD_RBD,
467
  LD_EXT,
468
  ])
469

    
470
LDS_BLOCK = compat.UniqueFrozenset([
471
  LD_LV,
472
  LD_DRBD8,
473
  LD_BLOCKDEV,
474
  LD_RBD,
475
  LD_EXT,
476
  ])
477

    
478
# drbd constants
479
DRBD_HMAC_ALG = "md5"
480
DRBD_NET_PROTOCOL = "C"
481
DRBD_STATUS_FILE = "/proc/drbd"
482

    
483
#: Size of DRBD meta block device
484
DRBD_META_SIZE = 128
485

    
486
# drbd barrier types
487
DRBD_B_NONE = "n"
488
DRBD_B_DISK_BARRIERS = "b"
489
DRBD_B_DISK_DRAIN = "d"
490
DRBD_B_DISK_FLUSH = "f"
491

    
492
# Valid barrier combinations: "n" or any non-null subset of "bfd"
493
DRBD_VALID_BARRIER_OPT = compat.UniqueFrozenset([
494
  frozenset([DRBD_B_NONE]),
495
  frozenset([DRBD_B_DISK_BARRIERS]),
496
  frozenset([DRBD_B_DISK_DRAIN]),
497
  frozenset([DRBD_B_DISK_FLUSH]),
498
  frozenset([DRBD_B_DISK_DRAIN, DRBD_B_DISK_FLUSH]),
499
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_DRAIN]),
500
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_FLUSH]),
501
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_FLUSH, DRBD_B_DISK_DRAIN]),
502
  ])
503

    
504
# rbd tool command
505
RBD_CMD = "rbd"
506

    
507
# file backend driver
508
FD_LOOP = "loop"
509
FD_BLKTAP = "blktap"
510

    
511
# the set of drbd-like disk types
512
LDS_DRBD = compat.UniqueFrozenset([LD_DRBD8])
513

    
514
# disk access mode
515
DISK_RDONLY = "ro"
516
DISK_RDWR = "rw"
517
DISK_ACCESS_SET = compat.UniqueFrozenset([DISK_RDONLY, DISK_RDWR])
518

    
519
# disk replacement mode
520
REPLACE_DISK_PRI = "replace_on_primary"    # replace disks on primary
521
REPLACE_DISK_SEC = "replace_on_secondary"  # replace disks on secondary
522
REPLACE_DISK_CHG = "replace_new_secondary" # change secondary node
523
REPLACE_DISK_AUTO = "replace_auto"
524
REPLACE_MODES = compat.UniqueFrozenset([
525
  REPLACE_DISK_PRI,
526
  REPLACE_DISK_SEC,
527
  REPLACE_DISK_CHG,
528
  REPLACE_DISK_AUTO,
529
  ])
530

    
531
# Instance export mode
532
EXPORT_MODE_LOCAL = "local"
533
EXPORT_MODE_REMOTE = "remote"
534
EXPORT_MODES = compat.UniqueFrozenset([
535
  EXPORT_MODE_LOCAL,
536
  EXPORT_MODE_REMOTE,
537
  ])
538

    
539
# instance creation modes
540
INSTANCE_CREATE = "create"
541
INSTANCE_IMPORT = "import"
542
INSTANCE_REMOTE_IMPORT = "remote-import"
543
INSTANCE_CREATE_MODES = compat.UniqueFrozenset([
544
  INSTANCE_CREATE,
545
  INSTANCE_IMPORT,
546
  INSTANCE_REMOTE_IMPORT,
547
  ])
548

    
549
# Remote import/export handshake message and version
550
RIE_VERSION = 0
551
RIE_HANDSHAKE = "Hi, I'm Ganeti"
552

    
553
# Remote import/export certificate validity in seconds
554
RIE_CERT_VALIDITY = 24 * 60 * 60
555

    
556
# Overall timeout for establishing connection
557
RIE_CONNECT_TIMEOUT = 180
558

    
559
# Export only: how long to wait per connection attempt (seconds)
560
RIE_CONNECT_ATTEMPT_TIMEOUT = 20
561

    
562
# Export only: number of attempts to connect
563
RIE_CONNECT_RETRIES = 10
564

    
565
#: Give child process up to 5 seconds to exit after sending a signal
566
CHILD_LINGER_TIMEOUT = 5.0
567

    
568
DISK_TEMPLATES = compat.UniqueFrozenset([
569
  DT_DISKLESS,
570
  DT_PLAIN,
571
  DT_DRBD8,
572
  DT_FILE,
573
  DT_SHARED_FILE,
574
  DT_BLOCK,
575
  DT_RBD,
576
  DT_EXT
577
  ])
578

    
579
FILE_DRIVER = compat.UniqueFrozenset([FD_LOOP, FD_BLKTAP])
580

    
581
# import/export config options
582
INISECT_EXP = "export"
583
INISECT_INS = "instance"
584
INISECT_HYP = "hypervisor"
585
INISECT_BEP = "backend"
586
INISECT_OSP = "os"
587

    
588
# dynamic device modification
589
DDM_ADD = "add"
590
DDM_MODIFY = "modify"
591
DDM_REMOVE = "remove"
592
DDMS_VALUES = compat.UniqueFrozenset([DDM_ADD, DDM_REMOVE])
593
DDMS_VALUES_WITH_MODIFY = (DDMS_VALUES | frozenset([
594
  DDM_MODIFY,
595
  ]))
596
# TODO: DDM_SWAP, DDM_MOVE?
597

    
598
# common exit codes
599
EXIT_SUCCESS = 0
600
EXIT_FAILURE = 1
601
EXIT_NOTCLUSTER = 5
602
EXIT_NOTMASTER = 11
603
EXIT_NODESETUP_ERROR = 12
604
EXIT_CONFIRMATION = 13 # need user confirmation
605

    
606
#: Exit code for query operations with unknown fields
607
EXIT_UNKNOWN_FIELD = 14
608

    
609
# tags
610
TAG_CLUSTER = "cluster"
611
TAG_NODEGROUP = "nodegroup"
612
TAG_NODE = "node"
613
TAG_INSTANCE = "instance"
614
TAG_NETWORK = "network"
615
VALID_TAG_TYPES = compat.UniqueFrozenset([
616
  TAG_CLUSTER,
617
  TAG_NODEGROUP,
618
  TAG_NODE,
619
  TAG_INSTANCE,
620
  TAG_NETWORK,
621
  ])
622
MAX_TAG_LEN = 128
623
MAX_TAGS_PER_OBJ = 4096
624

    
625
# others
626
DEFAULT_BRIDGE = "xen-br0"
627
CLASSIC_DRBD_SYNC_SPEED = 60 * 1024  # 60 MiB, expressed in KiB
628
IP4_ADDRESS_LOCALHOST = "127.0.0.1"
629
IP4_ADDRESS_ANY = "0.0.0.0"
630
IP6_ADDRESS_LOCALHOST = "::1"
631
IP6_ADDRESS_ANY = "::"
632
IP4_VERSION = 4
633
IP6_VERSION = 6
634
VALID_IP_VERSIONS = compat.UniqueFrozenset([IP4_VERSION, IP6_VERSION])
635
# for export to htools
636
IP4_FAMILY = socket.AF_INET
637
IP6_FAMILY = socket.AF_INET6
638

    
639
TCP_PING_TIMEOUT = 10
640
DEFAULT_VG = "xenvg"
641
DEFAULT_DRBD_HELPER = "/bin/true"
642
MIN_VG_SIZE = 20480
643
DEFAULT_MAC_PREFIX = "aa:00:00"
644
# default maximum instance wait time, in seconds.
645
DEFAULT_SHUTDOWN_TIMEOUT = 120
646
NODE_MAX_CLOCK_SKEW = 150
647
# Time for an intra-cluster disk transfer to wait for a connection
648
DISK_TRANSFER_CONNECT_TIMEOUT = 60
649
# Disk index separator
650
DISK_SEPARATOR = _autoconf.DISK_SEPARATOR
651
IP_COMMAND_PATH = _autoconf.IP_PATH
652

    
653
#: Key for job IDs in opcode result
654
JOB_IDS_KEY = "jobs"
655

    
656
# runparts results
657
(RUNPARTS_SKIP,
658
 RUNPARTS_RUN,
659
 RUNPARTS_ERR) = range(3)
660

    
661
RUNPARTS_STATUS = compat.UniqueFrozenset([
662
  RUNPARTS_SKIP,
663
  RUNPARTS_RUN,
664
  RUNPARTS_ERR,
665
  ])
666

    
667
# RPC constants
668
(RPC_ENCODING_NONE,
669
 RPC_ENCODING_ZLIB_BASE64) = range(2)
670

    
671
# Various time constants for the timeout table
672
RPC_TMO_URGENT = 60 # one minute
673
RPC_TMO_FAST = 5 * 60 # five minutes
674
RPC_TMO_NORMAL = 15 * 60 # 15 minutes
675
RPC_TMO_SLOW = 3600 # one hour
676
RPC_TMO_4HRS = 4 * 3600
677
RPC_TMO_1DAY = 86400
678

    
679
# Timeout for connecting to nodes (seconds)
680
RPC_CONNECT_TIMEOUT = 5
681

    
682
# os related constants
683
OS_SCRIPT_CREATE = "create"
684
OS_SCRIPT_IMPORT = "import"
685
OS_SCRIPT_EXPORT = "export"
686
OS_SCRIPT_RENAME = "rename"
687
OS_SCRIPT_VERIFY = "verify"
688
OS_SCRIPTS = compat.UniqueFrozenset([
689
  OS_SCRIPT_CREATE,
690
  OS_SCRIPT_IMPORT,
691
  OS_SCRIPT_EXPORT,
692
  OS_SCRIPT_RENAME,
693
  OS_SCRIPT_VERIFY,
694
  ])
695

    
696
OS_API_FILE = "ganeti_api_version"
697
OS_VARIANTS_FILE = "variants.list"
698
OS_PARAMETERS_FILE = "parameters.list"
699

    
700
OS_VALIDATE_PARAMETERS = "parameters"
701
OS_VALIDATE_CALLS = compat.UniqueFrozenset([OS_VALIDATE_PARAMETERS])
702

    
703
# External Storage (ES) related constants
704
ES_ACTION_CREATE = "create"
705
ES_ACTION_REMOVE = "remove"
706
ES_ACTION_GROW = "grow"
707
ES_ACTION_ATTACH = "attach"
708
ES_ACTION_DETACH = "detach"
709
ES_ACTION_SETINFO = "setinfo"
710
ES_ACTION_VERIFY = "verify"
711

    
712
ES_SCRIPT_CREATE = ES_ACTION_CREATE
713
ES_SCRIPT_REMOVE = ES_ACTION_REMOVE
714
ES_SCRIPT_GROW = ES_ACTION_GROW
715
ES_SCRIPT_ATTACH = ES_ACTION_ATTACH
716
ES_SCRIPT_DETACH = ES_ACTION_DETACH
717
ES_SCRIPT_SETINFO = ES_ACTION_SETINFO
718
ES_SCRIPT_VERIFY = ES_ACTION_VERIFY
719
ES_SCRIPTS = frozenset([
720
  ES_SCRIPT_CREATE,
721
  ES_SCRIPT_REMOVE,
722
  ES_SCRIPT_GROW,
723
  ES_SCRIPT_ATTACH,
724
  ES_SCRIPT_DETACH,
725
  ES_SCRIPT_SETINFO,
726
  ES_SCRIPT_VERIFY
727
  ])
728

    
729
ES_PARAMETERS_FILE = "parameters.list"
730

    
731
# reboot types
732
INSTANCE_REBOOT_SOFT = "soft"
733
INSTANCE_REBOOT_HARD = "hard"
734
INSTANCE_REBOOT_FULL = "full"
735

    
736
REBOOT_TYPES = compat.UniqueFrozenset([
737
  INSTANCE_REBOOT_SOFT,
738
  INSTANCE_REBOOT_HARD,
739
  INSTANCE_REBOOT_FULL,
740
  ])
741

    
742
# instance reboot behaviors
743
INSTANCE_REBOOT_ALLOWED = "reboot"
744
INSTANCE_REBOOT_EXIT = "exit"
745

    
746
REBOOT_BEHAVIORS = compat.UniqueFrozenset([
747
  INSTANCE_REBOOT_ALLOWED,
748
  INSTANCE_REBOOT_EXIT,
749
  ])
750

    
751
VTYPE_STRING = "string"
752
VTYPE_MAYBE_STRING = "maybe-string"
753
VTYPE_BOOL = "bool"
754
VTYPE_SIZE = "size" # size, in MiBs
755
VTYPE_INT = "int"
756
ENFORCEABLE_TYPES = compat.UniqueFrozenset([
757
  VTYPE_STRING,
758
  VTYPE_MAYBE_STRING,
759
  VTYPE_BOOL,
760
  VTYPE_SIZE,
761
  VTYPE_INT,
762
  ])
763

    
764
# Constant representing that the user does not specify any IP version
765
IFACE_NO_IP_VERSION_SPECIFIED = 0
766

    
767
VALID_SERIAL_SPEEDS = compat.UniqueFrozenset([
768
  75,
769
  110,
770
  300,
771
  600,
772
  1200,
773
  1800,
774
  2400,
775
  4800,
776
  9600,
777
  14400,
778
  19200,
779
  28800,
780
  38400,
781
  57600,
782
  115200,
783
  230400,
784
  345600,
785
  460800,
786
  ])
787

    
788
# HV parameter names (global namespace)
789
HV_BOOT_ORDER = "boot_order"
790
HV_CDROM_IMAGE_PATH = "cdrom_image_path"
791
HV_KVM_CDROM2_IMAGE_PATH = "cdrom2_image_path"
792
HV_KVM_FLOPPY_IMAGE_PATH = "floppy_image_path"
793
HV_NIC_TYPE = "nic_type"
794
HV_DISK_TYPE = "disk_type"
795
HV_KVM_CDROM_DISK_TYPE = "cdrom_disk_type"
796
HV_VNC_BIND_ADDRESS = "vnc_bind_address"
797
HV_VNC_PASSWORD_FILE = "vnc_password_file"
798
HV_VNC_TLS = "vnc_tls"
799
HV_VNC_X509 = "vnc_x509_path"
800
HV_VNC_X509_VERIFY = "vnc_x509_verify"
801
HV_KVM_SPICE_BIND = "spice_bind"
802
HV_KVM_SPICE_IP_VERSION = "spice_ip_version"
803
HV_KVM_SPICE_PASSWORD_FILE = "spice_password_file"
804
HV_KVM_SPICE_LOSSLESS_IMG_COMPR = "spice_image_compression"
805
HV_KVM_SPICE_JPEG_IMG_COMPR = "spice_jpeg_wan_compression"
806
HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR = "spice_zlib_glz_wan_compression"
807
HV_KVM_SPICE_STREAMING_VIDEO_DETECTION = "spice_streaming_video"
808
HV_KVM_SPICE_AUDIO_COMPR = "spice_playback_compression"
809
HV_KVM_SPICE_USE_TLS = "spice_use_tls"
810
HV_KVM_SPICE_TLS_CIPHERS = "spice_tls_ciphers"
811
HV_KVM_SPICE_USE_VDAGENT = "spice_use_vdagent"
812
HV_ACPI = "acpi"
813
HV_PAE = "pae"
814
HV_USE_BOOTLOADER = "use_bootloader"
815
HV_BOOTLOADER_ARGS = "bootloader_args"
816
HV_BOOTLOADER_PATH = "bootloader_path"
817
HV_KERNEL_ARGS = "kernel_args"
818
HV_KERNEL_PATH = "kernel_path"
819
HV_INITRD_PATH = "initrd_path"
820
HV_ROOT_PATH = "root_path"
821
HV_SERIAL_CONSOLE = "serial_console"
822
HV_SERIAL_SPEED = "serial_speed"
823
HV_USB_MOUSE = "usb_mouse"
824
HV_KEYMAP = "keymap"
825
HV_DEVICE_MODEL = "device_model"
826
HV_INIT_SCRIPT = "init_script"
827
HV_MIGRATION_PORT = "migration_port"
828
HV_MIGRATION_BANDWIDTH = "migration_bandwidth"
829
HV_MIGRATION_DOWNTIME = "migration_downtime"
830
HV_MIGRATION_MODE = "migration_mode"
831
HV_USE_LOCALTIME = "use_localtime"
832
HV_DISK_CACHE = "disk_cache"
833
HV_SECURITY_MODEL = "security_model"
834
HV_SECURITY_DOMAIN = "security_domain"
835
HV_KVM_FLAG = "kvm_flag"
836
HV_VHOST_NET = "vhost_net"
837
HV_KVM_USE_CHROOT = "use_chroot"
838
HV_CPU_MASK = "cpu_mask"
839
HV_MEM_PATH = "mem_path"
840
HV_PASSTHROUGH = "pci_pass"
841
HV_BLOCKDEV_PREFIX = "blockdev_prefix"
842
HV_REBOOT_BEHAVIOR = "reboot_behavior"
843
HV_CPU_TYPE = "cpu_type"
844
HV_CPU_CAP = "cpu_cap"
845
HV_CPU_WEIGHT = "cpu_weight"
846
HV_CPU_CORES = "cpu_cores"
847
HV_CPU_THREADS = "cpu_threads"
848
HV_CPU_SOCKETS = "cpu_sockets"
849
HV_SOUNDHW = "soundhw"
850
HV_USB_DEVICES = "usb_devices"
851
HV_VGA = "vga"
852
HV_KVM_EXTRA = "kvm_extra"
853
HV_KVM_MACHINE_VERSION = "machine_version"
854
HV_KVM_PATH = "kvm_path"
855

    
856

    
857
HVS_PARAMETER_TYPES = {
858
  HV_KVM_PATH: VTYPE_STRING,
859
  HV_BOOT_ORDER: VTYPE_STRING,
860
  HV_KVM_FLOPPY_IMAGE_PATH: VTYPE_STRING,
861
  HV_CDROM_IMAGE_PATH: VTYPE_STRING,
862
  HV_KVM_CDROM2_IMAGE_PATH: VTYPE_STRING,
863
  HV_NIC_TYPE: VTYPE_STRING,
864
  HV_DISK_TYPE: VTYPE_STRING,
865
  HV_KVM_CDROM_DISK_TYPE: VTYPE_STRING,
866
  HV_VNC_PASSWORD_FILE: VTYPE_STRING,
867
  HV_VNC_BIND_ADDRESS: VTYPE_STRING,
868
  HV_VNC_TLS: VTYPE_BOOL,
869
  HV_VNC_X509: VTYPE_STRING,
870
  HV_VNC_X509_VERIFY: VTYPE_BOOL,
871
  HV_KVM_SPICE_BIND: VTYPE_STRING,
872
  HV_KVM_SPICE_IP_VERSION: VTYPE_INT,
873
  HV_KVM_SPICE_PASSWORD_FILE: VTYPE_STRING,
874
  HV_KVM_SPICE_LOSSLESS_IMG_COMPR: VTYPE_STRING,
875
  HV_KVM_SPICE_JPEG_IMG_COMPR: VTYPE_STRING,
876
  HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR: VTYPE_STRING,
877
  HV_KVM_SPICE_STREAMING_VIDEO_DETECTION: VTYPE_STRING,
878
  HV_KVM_SPICE_AUDIO_COMPR: VTYPE_BOOL,
879
  HV_KVM_SPICE_USE_TLS: VTYPE_BOOL,
880
  HV_KVM_SPICE_TLS_CIPHERS: VTYPE_STRING,
881
  HV_KVM_SPICE_USE_VDAGENT: VTYPE_BOOL,
882
  HV_ACPI: VTYPE_BOOL,
883
  HV_PAE: VTYPE_BOOL,
884
  HV_USE_BOOTLOADER: VTYPE_BOOL,
885
  HV_BOOTLOADER_PATH: VTYPE_STRING,
886
  HV_BOOTLOADER_ARGS: VTYPE_STRING,
887
  HV_KERNEL_PATH: VTYPE_STRING,
888
  HV_KERNEL_ARGS: VTYPE_STRING,
889
  HV_INITRD_PATH: VTYPE_STRING,
890
  HV_ROOT_PATH: VTYPE_MAYBE_STRING,
891
  HV_SERIAL_CONSOLE: VTYPE_BOOL,
892
  HV_SERIAL_SPEED: VTYPE_INT,
893
  HV_USB_MOUSE: VTYPE_STRING,
894
  HV_KEYMAP: VTYPE_STRING,
895
  HV_DEVICE_MODEL: VTYPE_STRING,
896
  HV_INIT_SCRIPT: VTYPE_STRING,
897
  HV_MIGRATION_PORT: VTYPE_INT,
898
  HV_MIGRATION_BANDWIDTH: VTYPE_INT,
899
  HV_MIGRATION_DOWNTIME: VTYPE_INT,
900
  HV_MIGRATION_MODE: VTYPE_STRING,
901
  HV_USE_LOCALTIME: VTYPE_BOOL,
902
  HV_DISK_CACHE: VTYPE_STRING,
903
  HV_SECURITY_MODEL: VTYPE_STRING,
904
  HV_SECURITY_DOMAIN: VTYPE_STRING,
905
  HV_KVM_FLAG: VTYPE_STRING,
906
  HV_VHOST_NET: VTYPE_BOOL,
907
  HV_KVM_USE_CHROOT: VTYPE_BOOL,
908
  HV_CPU_MASK: VTYPE_STRING,
909
  HV_MEM_PATH: VTYPE_STRING,
910
  HV_PASSTHROUGH: VTYPE_STRING,
911
  HV_BLOCKDEV_PREFIX: VTYPE_STRING,
912
  HV_REBOOT_BEHAVIOR: VTYPE_STRING,
913
  HV_CPU_TYPE: VTYPE_STRING,
914
  HV_CPU_CAP: VTYPE_INT,
915
  HV_CPU_WEIGHT: VTYPE_INT,
916
  HV_CPU_CORES: VTYPE_INT,
917
  HV_CPU_THREADS: VTYPE_INT,
918
  HV_CPU_SOCKETS: VTYPE_INT,
919
  HV_SOUNDHW: VTYPE_STRING,
920
  HV_USB_DEVICES: VTYPE_STRING,
921
  HV_VGA: VTYPE_STRING,
922
  HV_KVM_EXTRA: VTYPE_STRING,
923
  HV_KVM_MACHINE_VERSION: VTYPE_STRING,
924
  }
925

    
926
HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
927

    
928
HVS_PARAMETER_TITLES = {
929
  HV_ACPI: "ACPI",
930
  HV_BOOT_ORDER: "Boot_order",
931
  HV_CDROM_IMAGE_PATH: "CDROM_image_path",
932
  HV_DISK_TYPE: "Disk_type",
933
  HV_INITRD_PATH: "Initrd_path",
934
  HV_KERNEL_PATH: "Kernel_path",
935
  HV_NIC_TYPE: "NIC_type",
936
  HV_PAE: "PAE",
937
  HV_VNC_BIND_ADDRESS: "VNC_bind_address",
938
  HV_PASSTHROUGH: "pci_pass",
939
  HV_CPU_TYPE: "cpu_type",
940
  }
941

    
942
# Migration statuses
943
HV_MIGRATION_COMPLETED = "completed"
944
HV_MIGRATION_ACTIVE = "active"
945
HV_MIGRATION_FAILED = "failed"
946
HV_MIGRATION_CANCELLED = "cancelled"
947

    
948
HV_MIGRATION_VALID_STATUSES = compat.UniqueFrozenset([
949
  HV_MIGRATION_COMPLETED,
950
  HV_MIGRATION_ACTIVE,
951
  HV_MIGRATION_FAILED,
952
  HV_MIGRATION_CANCELLED,
953
  ])
954

    
955
HV_MIGRATION_FAILED_STATUSES = compat.UniqueFrozenset([
956
  HV_MIGRATION_FAILED,
957
  HV_MIGRATION_CANCELLED,
958
  ])
959

    
960
# KVM-specific statuses
961
HV_KVM_MIGRATION_VALID_STATUSES = HV_MIGRATION_VALID_STATUSES
962

    
963
# Node info keys
964
HV_NODEINFO_KEY_VERSION = "hv_version"
965

    
966
# Hypervisor state
967
HVST_MEMORY_TOTAL = "mem_total"
968
HVST_MEMORY_NODE = "mem_node"
969
HVST_MEMORY_HV = "mem_hv"
970
HVST_CPU_TOTAL = "cpu_total"
971
HVST_CPU_NODE = "cpu_node"
972

    
973
HVST_DEFAULTS = {
974
  HVST_MEMORY_TOTAL: 0,
975
  HVST_MEMORY_NODE: 0,
976
  HVST_MEMORY_HV: 0,
977
  HVST_CPU_TOTAL: 1,
978
  HVST_CPU_NODE: 1,
979
  }
980

    
981
HVSTS_PARAMETER_TYPES = {
982
  HVST_MEMORY_TOTAL: VTYPE_INT,
983
  HVST_MEMORY_NODE: VTYPE_INT,
984
  HVST_MEMORY_HV: VTYPE_INT,
985
  HVST_CPU_TOTAL: VTYPE_INT,
986
  HVST_CPU_NODE: VTYPE_INT,
987
  }
988

    
989
HVSTS_PARAMETERS = frozenset(HVSTS_PARAMETER_TYPES.keys())
990

    
991
# Disk state
992
DS_DISK_TOTAL = "disk_total"
993
DS_DISK_RESERVED = "disk_reserved"
994
DS_DISK_OVERHEAD = "disk_overhead"
995

    
996
DS_DEFAULTS = {
997
  DS_DISK_TOTAL: 0,
998
  DS_DISK_RESERVED: 0,
999
  DS_DISK_OVERHEAD: 0,
1000
  }
1001

    
1002
DSS_PARAMETER_TYPES = {
1003
  DS_DISK_TOTAL: VTYPE_INT,
1004
  DS_DISK_RESERVED: VTYPE_INT,
1005
  DS_DISK_OVERHEAD: VTYPE_INT,
1006
  }
1007

    
1008
DSS_PARAMETERS = frozenset(DSS_PARAMETER_TYPES.keys())
1009
DS_VALID_TYPES = compat.UniqueFrozenset([LD_LV])
1010

    
1011
# Backend parameter names
1012
BE_MEMORY = "memory" # deprecated and replaced by max and min mem
1013
BE_MAXMEM = "maxmem"
1014
BE_MINMEM = "minmem"
1015
BE_VCPUS = "vcpus"
1016
BE_AUTO_BALANCE = "auto_balance"
1017
BE_ALWAYS_FAILOVER = "always_failover"
1018
BE_SPINDLE_USE = "spindle_use"
1019

    
1020
BES_PARAMETER_TYPES = {
1021
  BE_MAXMEM: VTYPE_SIZE,
1022
  BE_MINMEM: VTYPE_SIZE,
1023
  BE_VCPUS: VTYPE_INT,
1024
  BE_AUTO_BALANCE: VTYPE_BOOL,
1025
  BE_ALWAYS_FAILOVER: VTYPE_BOOL,
1026
  BE_SPINDLE_USE: VTYPE_INT,
1027
  }
1028

    
1029
BES_PARAMETER_TITLES = {
1030
  BE_AUTO_BALANCE: "Auto_balance",
1031
  BE_MAXMEM: "ConfigMaxMem",
1032
  BE_MINMEM: "ConfigMinMem",
1033
  BE_VCPUS: "ConfigVCPUs",
1034
  }
1035

    
1036
BES_PARAMETER_COMPAT = {
1037
  BE_MEMORY: VTYPE_SIZE,
1038
  }
1039
BES_PARAMETER_COMPAT.update(BES_PARAMETER_TYPES)
1040

    
1041
BES_PARAMETERS = frozenset(BES_PARAMETER_TYPES.keys())
1042

    
1043
# instance specs
1044
ISPEC_MEM_SIZE = "memory-size"
1045
ISPEC_CPU_COUNT = "cpu-count"
1046
ISPEC_DISK_COUNT = "disk-count"
1047
ISPEC_DISK_SIZE = "disk-size"
1048
ISPEC_NIC_COUNT = "nic-count"
1049
ISPEC_SPINDLE_USE = "spindle-use"
1050

    
1051
ISPECS_PARAMETER_TYPES = {
1052
  ISPEC_MEM_SIZE: VTYPE_INT,
1053
  ISPEC_CPU_COUNT: VTYPE_INT,
1054
  ISPEC_DISK_COUNT: VTYPE_INT,
1055
  ISPEC_DISK_SIZE: VTYPE_INT,
1056
  ISPEC_NIC_COUNT: VTYPE_INT,
1057
  ISPEC_SPINDLE_USE: VTYPE_INT,
1058
  }
1059

    
1060
ISPECS_PARAMETERS = frozenset(ISPECS_PARAMETER_TYPES.keys())
1061

    
1062
ISPECS_MIN = "min"
1063
ISPECS_MAX = "max"
1064
ISPECS_STD = "std"
1065
IPOLICY_DTS = "disk-templates"
1066
IPOLICY_VCPU_RATIO = "vcpu-ratio"
1067
IPOLICY_SPINDLE_RATIO = "spindle-ratio"
1068

    
1069
IPOLICY_ISPECS = compat.UniqueFrozenset([
1070
  ISPECS_MIN,
1071
  ISPECS_MAX,
1072
  ISPECS_STD,
1073
  ])
1074

    
1075
IPOLICY_PARAMETERS = compat.UniqueFrozenset([
1076
  IPOLICY_VCPU_RATIO,
1077
  IPOLICY_SPINDLE_RATIO,
1078
  ])
1079

    
1080
IPOLICY_ALL_KEYS = (IPOLICY_ISPECS |
1081
                    IPOLICY_PARAMETERS |
1082
                    frozenset([IPOLICY_DTS]))
1083

    
1084
# Node parameter names
1085
ND_OOB_PROGRAM = "oob_program"
1086
ND_SPINDLE_COUNT = "spindle_count"
1087
ND_EXCLUSIVE_STORAGE = "exclusive_storage"
1088

    
1089
NDS_PARAMETER_TYPES = {
1090
  ND_OOB_PROGRAM: VTYPE_STRING,
1091
  ND_SPINDLE_COUNT: VTYPE_INT,
1092
  ND_EXCLUSIVE_STORAGE: VTYPE_BOOL,
1093
  }
1094

    
1095
NDS_PARAMETERS = frozenset(NDS_PARAMETER_TYPES.keys())
1096

    
1097
NDS_PARAMETER_TITLES = {
1098
  ND_OOB_PROGRAM: "OutOfBandProgram",
1099
  ND_SPINDLE_COUNT: "SpindleCount",
1100
  ND_EXCLUSIVE_STORAGE: "ExclusiveStorage",
1101
  }
1102

    
1103
# Logical Disks parameters
1104
LDP_RESYNC_RATE = "resync-rate"
1105
LDP_STRIPES = "stripes"
1106
LDP_BARRIERS = "disabled-barriers"
1107
LDP_NO_META_FLUSH = "disable-meta-flush"
1108
LDP_DEFAULT_METAVG = "default-metavg"
1109
LDP_DISK_CUSTOM = "disk-custom"
1110
LDP_NET_CUSTOM = "net-custom"
1111
LDP_DYNAMIC_RESYNC = "dynamic-resync"
1112
LDP_PLAN_AHEAD = "c-plan-ahead"
1113
LDP_FILL_TARGET = "c-fill-target"
1114
LDP_DELAY_TARGET = "c-delay-target"
1115
LDP_MAX_RATE = "c-max-rate"
1116
LDP_MIN_RATE = "c-min-rate"
1117
LDP_POOL = "pool"
1118
DISK_LD_TYPES = {
1119
  LDP_RESYNC_RATE: VTYPE_INT,
1120
  LDP_STRIPES: VTYPE_INT,
1121
  LDP_BARRIERS: VTYPE_STRING,
1122
  LDP_NO_META_FLUSH: VTYPE_BOOL,
1123
  LDP_DEFAULT_METAVG: VTYPE_STRING,
1124
  LDP_DISK_CUSTOM: VTYPE_STRING,
1125
  LDP_NET_CUSTOM: VTYPE_STRING,
1126
  LDP_DYNAMIC_RESYNC: VTYPE_BOOL,
1127
  LDP_PLAN_AHEAD: VTYPE_INT,
1128
  LDP_FILL_TARGET: VTYPE_INT,
1129
  LDP_DELAY_TARGET: VTYPE_INT,
1130
  LDP_MAX_RATE: VTYPE_INT,
1131
  LDP_MIN_RATE: VTYPE_INT,
1132
  LDP_POOL: VTYPE_STRING,
1133
  }
1134
DISK_LD_PARAMETERS = frozenset(DISK_LD_TYPES.keys())
1135

    
1136
# Disk template parameters (can be set/changed by the user via gnt-cluster and
1137
# gnt-group)
1138
DRBD_RESYNC_RATE = "resync-rate"
1139
DRBD_DATA_STRIPES = "data-stripes"
1140
DRBD_META_STRIPES = "meta-stripes"
1141
DRBD_DISK_BARRIERS = "disk-barriers"
1142
DRBD_META_BARRIERS = "meta-barriers"
1143
DRBD_DEFAULT_METAVG = "metavg"
1144
DRBD_DISK_CUSTOM = "disk-custom"
1145
DRBD_NET_CUSTOM = "net-custom"
1146
DRBD_DYNAMIC_RESYNC = "dynamic-resync"
1147
DRBD_PLAN_AHEAD = "c-plan-ahead"
1148
DRBD_FILL_TARGET = "c-fill-target"
1149
DRBD_DELAY_TARGET = "c-delay-target"
1150
DRBD_MAX_RATE = "c-max-rate"
1151
DRBD_MIN_RATE = "c-min-rate"
1152
LV_STRIPES = "stripes"
1153
RBD_POOL = "pool"
1154
DISK_DT_TYPES = {
1155
  DRBD_RESYNC_RATE: VTYPE_INT,
1156
  DRBD_DATA_STRIPES: VTYPE_INT,
1157
  DRBD_META_STRIPES: VTYPE_INT,
1158
  DRBD_DISK_BARRIERS: VTYPE_STRING,
1159
  DRBD_META_BARRIERS: VTYPE_BOOL,
1160
  DRBD_DEFAULT_METAVG: VTYPE_STRING,
1161
  DRBD_DISK_CUSTOM: VTYPE_STRING,
1162
  DRBD_NET_CUSTOM: VTYPE_STRING,
1163
  DRBD_DYNAMIC_RESYNC: VTYPE_BOOL,
1164
  DRBD_PLAN_AHEAD: VTYPE_INT,
1165
  DRBD_FILL_TARGET: VTYPE_INT,
1166
  DRBD_DELAY_TARGET: VTYPE_INT,
1167
  DRBD_MAX_RATE: VTYPE_INT,
1168
  DRBD_MIN_RATE: VTYPE_INT,
1169
  LV_STRIPES: VTYPE_INT,
1170
  RBD_POOL: VTYPE_STRING,
1171
  }
1172

    
1173
DISK_DT_PARAMETERS = frozenset(DISK_DT_TYPES.keys())
1174

    
1175
# OOB supported commands
1176
OOB_POWER_ON = "power-on"
1177
OOB_POWER_OFF = "power-off"
1178
OOB_POWER_CYCLE = "power-cycle"
1179
OOB_POWER_STATUS = "power-status"
1180
OOB_HEALTH = "health"
1181

    
1182
OOB_COMMANDS = compat.UniqueFrozenset([
1183
  OOB_POWER_ON,
1184
  OOB_POWER_OFF,
1185
  OOB_POWER_CYCLE,
1186
  OOB_POWER_STATUS,
1187
  OOB_HEALTH,
1188
  ])
1189

    
1190
OOB_POWER_STATUS_POWERED = "powered"
1191

    
1192
OOB_TIMEOUT = 60 # 60 seconds
1193
OOB_POWER_DELAY = 2.0 # 2 seconds
1194

    
1195
OOB_STATUS_OK = "OK"
1196
OOB_STATUS_WARNING = "WARNING"
1197
OOB_STATUS_CRITICAL = "CRITICAL"
1198
OOB_STATUS_UNKNOWN = "UNKNOWN"
1199

    
1200
OOB_STATUSES = compat.UniqueFrozenset([
1201
  OOB_STATUS_OK,
1202
  OOB_STATUS_WARNING,
1203
  OOB_STATUS_CRITICAL,
1204
  OOB_STATUS_UNKNOWN,
1205
  ])
1206

    
1207
# Instance Parameters Profile
1208
PP_DEFAULT = "default"
1209

    
1210
# NIC_* constants are used inside the ganeti config
1211
NIC_MODE = "mode"
1212
NIC_LINK = "link"
1213

    
1214
NIC_MODE_BRIDGED = "bridged"
1215
NIC_MODE_ROUTED = "routed"
1216
NIC_MODE_OVS = "openvswitch"
1217
NIC_IP_POOL = "pool"
1218

    
1219
NIC_VALID_MODES = compat.UniqueFrozenset([
1220
  NIC_MODE_BRIDGED,
1221
  NIC_MODE_ROUTED,
1222
  NIC_MODE_OVS,
1223
  ])
1224

    
1225
RESERVE_ACTION = "reserve"
1226
RELEASE_ACTION = "release"
1227

    
1228
NICS_PARAMETER_TYPES = {
1229
  NIC_MODE: VTYPE_STRING,
1230
  NIC_LINK: VTYPE_STRING,
1231
  }
1232

    
1233
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
1234

    
1235
# IDISK_* constants are used in opcodes, to create/change disks
1236
IDISK_SIZE = "size"
1237
IDISK_MODE = "mode"
1238
IDISK_ADOPT = "adopt"
1239
IDISK_VG = "vg"
1240
IDISK_METAVG = "metavg"
1241
IDISK_PROVIDER = "provider"
1242
IDISK_PARAMS_TYPES = {
1243
  IDISK_SIZE: VTYPE_SIZE,
1244
  IDISK_MODE: VTYPE_STRING,
1245
  IDISK_ADOPT: VTYPE_STRING,
1246
  IDISK_VG: VTYPE_STRING,
1247
  IDISK_METAVG: VTYPE_STRING,
1248
  IDISK_PROVIDER: VTYPE_STRING,
1249
  }
1250
IDISK_PARAMS = frozenset(IDISK_PARAMS_TYPES.keys())
1251

    
1252
# INIC_* constants are used in opcodes, to create/change nics
1253
INIC_MAC = "mac"
1254
INIC_IP = "ip"
1255
INIC_MODE = "mode"
1256
INIC_LINK = "link"
1257
INIC_NETWORK = "network"
1258
INIC_PARAMS_TYPES = {
1259
  INIC_IP: VTYPE_MAYBE_STRING,
1260
  INIC_LINK: VTYPE_STRING,
1261
  INIC_MAC: VTYPE_STRING,
1262
  INIC_MODE: VTYPE_STRING,
1263
  INIC_NETWORK: VTYPE_MAYBE_STRING,
1264
  }
1265
INIC_PARAMS = frozenset(INIC_PARAMS_TYPES.keys())
1266

    
1267
# Hypervisor constants
1268
HT_XEN_PVM = "xen-pvm"
1269
HT_FAKE = "fake"
1270
HT_XEN_HVM = "xen-hvm"
1271
HT_KVM = "kvm"
1272
HT_CHROOT = "chroot"
1273
HT_LXC = "lxc"
1274
HYPER_TYPES = compat.UniqueFrozenset([
1275
  HT_XEN_PVM,
1276
  HT_FAKE,
1277
  HT_XEN_HVM,
1278
  HT_KVM,
1279
  HT_CHROOT,
1280
  HT_LXC,
1281
  ])
1282
HTS_REQ_PORT = compat.UniqueFrozenset([HT_XEN_HVM, HT_KVM])
1283

    
1284
VNC_BASE_PORT = 5900
1285
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
1286

    
1287
# NIC types
1288
HT_NIC_RTL8139 = "rtl8139"
1289
HT_NIC_NE2K_PCI = "ne2k_pci"
1290
HT_NIC_NE2K_ISA = "ne2k_isa"
1291
HT_NIC_I82551 = "i82551"
1292
HT_NIC_I85557B = "i82557b"
1293
HT_NIC_I8259ER = "i82559er"
1294
HT_NIC_PCNET = "pcnet"
1295
HT_NIC_E1000 = "e1000"
1296
HT_NIC_PARAVIRTUAL = HT_DISK_PARAVIRTUAL = "paravirtual"
1297

    
1298
HT_HVM_VALID_NIC_TYPES = compat.UniqueFrozenset([
1299
  HT_NIC_RTL8139,
1300
  HT_NIC_NE2K_PCI,
1301
  HT_NIC_E1000,
1302
  HT_NIC_NE2K_ISA,
1303
  HT_NIC_PARAVIRTUAL,
1304
  ])
1305
HT_KVM_VALID_NIC_TYPES = compat.UniqueFrozenset([
1306
  HT_NIC_RTL8139,
1307
  HT_NIC_NE2K_PCI,
1308
  HT_NIC_NE2K_ISA,
1309
  HT_NIC_I82551,
1310
  HT_NIC_I85557B,
1311
  HT_NIC_I8259ER,
1312
  HT_NIC_PCNET,
1313
  HT_NIC_E1000,
1314
  HT_NIC_PARAVIRTUAL,
1315
  ])
1316

    
1317
# Disk types
1318
HT_DISK_IOEMU = "ioemu"
1319
HT_DISK_IDE = "ide"
1320
HT_DISK_SCSI = "scsi"
1321
HT_DISK_SD = "sd"
1322
HT_DISK_MTD = "mtd"
1323
HT_DISK_PFLASH = "pflash"
1324

    
1325
HT_CACHE_DEFAULT = "default"
1326
HT_CACHE_NONE = "none"
1327
HT_CACHE_WTHROUGH = "writethrough"
1328
HT_CACHE_WBACK = "writeback"
1329
HT_VALID_CACHE_TYPES = compat.UniqueFrozenset([
1330
  HT_CACHE_DEFAULT,
1331
  HT_CACHE_NONE,
1332
  HT_CACHE_WTHROUGH,
1333
  HT_CACHE_WBACK,
1334
  ])
1335

    
1336
HT_HVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1337
  HT_DISK_PARAVIRTUAL,
1338
  HT_DISK_IOEMU,
1339
  ])
1340
HT_KVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1341
  HT_DISK_PARAVIRTUAL,
1342
  HT_DISK_IDE,
1343
  HT_DISK_SCSI,
1344
  HT_DISK_SD,
1345
  HT_DISK_MTD,
1346
  HT_DISK_PFLASH,
1347
  ])
1348

    
1349
# Mouse types:
1350
HT_MOUSE_MOUSE = "mouse"
1351
HT_MOUSE_TABLET = "tablet"
1352

    
1353
HT_KVM_VALID_MOUSE_TYPES = compat.UniqueFrozenset([
1354
  HT_MOUSE_MOUSE,
1355
  HT_MOUSE_TABLET,
1356
  ])
1357

    
1358
# Boot order
1359
HT_BO_FLOPPY = "floppy"
1360
HT_BO_CDROM = "cdrom"
1361
HT_BO_DISK = "disk"
1362
HT_BO_NETWORK = "network"
1363

    
1364
HT_KVM_VALID_BO_TYPES = compat.UniqueFrozenset([
1365
  HT_BO_FLOPPY,
1366
  HT_BO_CDROM,
1367
  HT_BO_DISK,
1368
  HT_BO_NETWORK,
1369
  ])
1370

    
1371
# SPICE lossless image compression options
1372
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ = "auto_glz"
1373
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ = "auto_lz"
1374
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC = "quic"
1375
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ = "glz"
1376
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ = "lz"
1377
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF = "off"
1378

    
1379
HT_KVM_SPICE_VALID_LOSSLESS_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1380
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ,
1381
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ,
1382
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC,
1383
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ,
1384
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ,
1385
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF,
1386
  ])
1387

    
1388
# SPICE lossy image compression options (valid for both jpeg and zlib-glz)
1389
HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO = "auto"
1390
HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER = "never"
1391
HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS = "always"
1392

    
1393
HT_KVM_SPICE_VALID_LOSSY_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1394
  HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO,
1395
  HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER,
1396
  HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS,
1397
  ])
1398

    
1399
# SPICE video stream detection
1400
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF = "off"
1401
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL = "all"
1402
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER = "filter"
1403

    
1404
HT_KVM_SPICE_VALID_VIDEO_STREAM_DETECTION_OPTIONS = compat.UniqueFrozenset([
1405
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF,
1406
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL,
1407
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER,
1408
  ])
1409

    
1410
# Security models
1411
HT_SM_NONE = "none"
1412
HT_SM_USER = "user"
1413
HT_SM_POOL = "pool"
1414

    
1415
HT_KVM_VALID_SM_TYPES = compat.UniqueFrozenset([
1416
  HT_SM_NONE,
1417
  HT_SM_USER,
1418
  HT_SM_POOL,
1419
  ])
1420

    
1421
# Kvm flag values
1422
HT_KVM_ENABLED = "enabled"
1423
HT_KVM_DISABLED = "disabled"
1424

    
1425
HT_KVM_FLAG_VALUES = compat.UniqueFrozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
1426

    
1427
# Migration type
1428
HT_MIGRATION_LIVE = "live"
1429
HT_MIGRATION_NONLIVE = "non-live"
1430
HT_MIGRATION_MODES = compat.UniqueFrozenset([
1431
  HT_MIGRATION_LIVE,
1432
  HT_MIGRATION_NONLIVE,
1433
  ])
1434

    
1435
# Cluster Verify steps
1436
VERIFY_NPLUSONE_MEM = "nplusone_mem"
1437
VERIFY_OPTIONAL_CHECKS = compat.UniqueFrozenset([VERIFY_NPLUSONE_MEM])
1438

    
1439
# Cluster Verify error classes
1440
CV_TCLUSTER = "cluster"
1441
CV_TGROUP = "group"
1442
CV_TNODE = "node"
1443
CV_TINSTANCE = "instance"
1444

    
1445
# Cluster Verify error codes and documentation
1446
CV_ECLUSTERCFG = \
1447
  (CV_TCLUSTER, "ECLUSTERCFG", "Cluster configuration verification failure")
1448
CV_ECLUSTERCERT = \
1449
  (CV_TCLUSTER, "ECLUSTERCERT",
1450
   "Cluster certificate files verification failure")
1451
CV_ECLUSTERFILECHECK = \
1452
  (CV_TCLUSTER, "ECLUSTERFILECHECK",
1453
   "Cluster configuration verification failure")
1454
CV_ECLUSTERDANGLINGNODES = \
1455
  (CV_TNODE, "ECLUSTERDANGLINGNODES",
1456
   "Some nodes belong to non-existing groups")
1457
CV_ECLUSTERDANGLINGINST = \
1458
  (CV_TNODE, "ECLUSTERDANGLINGINST",
1459
   "Some instances have a non-existing primary node")
1460
CV_EGROUPDIFFERENTPVSIZE = \
1461
  (CV_TGROUP, "EGROUPDIFFERENTPVSIZE", "PVs in the group have different sizes")
1462
CV_EINSTANCEBADNODE = \
1463
  (CV_TINSTANCE, "EINSTANCEBADNODE",
1464
   "Instance marked as running lives on an offline node")
1465
CV_EINSTANCEDOWN = \
1466
  (CV_TINSTANCE, "EINSTANCEDOWN", "Instance not running on its primary node")
1467
CV_EINSTANCELAYOUT = \
1468
  (CV_TINSTANCE, "EINSTANCELAYOUT", "Instance has multiple secondary nodes")
1469
CV_EINSTANCEMISSINGDISK = \
1470
  (CV_TINSTANCE, "EINSTANCEMISSINGDISK", "Missing volume on an instance")
1471
CV_EINSTANCEFAULTYDISK = \
1472
  (CV_TINSTANCE, "EINSTANCEFAULTYDISK",
1473
   "Impossible to retrieve status for a disk")
1474
CV_EINSTANCEWRONGNODE = \
1475
  (CV_TINSTANCE, "EINSTANCEWRONGNODE", "Instance running on the wrong node")
1476
CV_EINSTANCESPLITGROUPS = \
1477
  (CV_TINSTANCE, "EINSTANCESPLITGROUPS",
1478
   "Instance with primary and secondary nodes in different groups")
1479
CV_EINSTANCEPOLICY = \
1480
  (CV_TINSTANCE, "EINSTANCEPOLICY",
1481
   "Instance does not meet policy")
1482
CV_EINSTANCEUNSUITABLENODE = \
1483
  (CV_TINSTANCE, "EINSTANCEUNSUITABLENODE",
1484
   "Instance running on nodes that are not suitable for it")
1485
CV_ENODEDRBD = \
1486
  (CV_TNODE, "ENODEDRBD", "Error parsing the DRBD status file")
1487
CV_ENODEDRBDHELPER = \
1488
  (CV_TNODE, "ENODEDRBDHELPER", "Error caused by the DRBD helper")
1489
CV_ENODEFILECHECK = \
1490
  (CV_TNODE, "ENODEFILECHECK",
1491
   "Error retrieving the checksum of the node files")
1492
CV_ENODEHOOKS = \
1493
  (CV_TNODE, "ENODEHOOKS", "Communication failure in hooks execution")
1494
CV_ENODEHV = \
1495
  (CV_TNODE, "ENODEHV", "Hypervisor parameters verification failure")
1496
CV_ENODELVM = \
1497
  (CV_TNODE, "ENODELVM", "LVM-related node error")
1498
CV_ENODEN1 = \
1499
  (CV_TNODE, "ENODEN1", "Not enough memory to accommodate instance failovers")
1500
CV_ENODENET = \
1501
  (CV_TNODE, "ENODENET", "Network-related node error")
1502
CV_ENODEOS = \
1503
  (CV_TNODE, "ENODEOS", "OS-related node error")
1504
CV_ENODEORPHANINSTANCE = \
1505
  (CV_TNODE, "ENODEORPHANINSTANCE", "Unknown intance running on a node")
1506
CV_ENODEORPHANLV = \
1507
  (CV_TNODE, "ENODEORPHANLV", "Unknown LVM logical volume")
1508
CV_ENODERPC = \
1509
  (CV_TNODE, "ENODERPC",
1510
   "Error during connection to the primary node of an instance")
1511
CV_ENODESSH = \
1512
  (CV_TNODE, "ENODESSH", "SSH-related node error")
1513
CV_ENODEVERSION = \
1514
  (CV_TNODE, "ENODEVERSION",
1515
   "Protocol version mismatch or Ganeti version mismatch")
1516
CV_ENODESETUP = \
1517
  (CV_TNODE, "ENODESETUP", "Node setup error")
1518
CV_ENODETIME = \
1519
  (CV_TNODE, "ENODETIME", "Node returned invalid time")
1520
CV_ENODEOOBPATH = \
1521
  (CV_TNODE, "ENODEOOBPATH", "Invalid Out Of Band path")
1522
CV_ENODEUSERSCRIPTS = \
1523
  (CV_TNODE, "ENODEUSERSCRIPTS", "User scripts not present or not executable")
1524
CV_ENODEFILESTORAGEPATHS = \
1525
  (CV_TNODE, "ENODEFILESTORAGEPATHS", "Detected bad file storage paths")
1526

    
1527
CV_ALL_ECODES = compat.UniqueFrozenset([
1528
  CV_ECLUSTERCFG,
1529
  CV_ECLUSTERCERT,
1530
  CV_ECLUSTERFILECHECK,
1531
  CV_ECLUSTERDANGLINGNODES,
1532
  CV_ECLUSTERDANGLINGINST,
1533
  CV_EINSTANCEBADNODE,
1534
  CV_EINSTANCEDOWN,
1535
  CV_EINSTANCELAYOUT,
1536
  CV_EINSTANCEMISSINGDISK,
1537
  CV_EINSTANCEFAULTYDISK,
1538
  CV_EINSTANCEWRONGNODE,
1539
  CV_EINSTANCESPLITGROUPS,
1540
  CV_EINSTANCEPOLICY,
1541
  CV_ENODEDRBD,
1542
  CV_ENODEDRBDHELPER,
1543
  CV_ENODEFILECHECK,
1544
  CV_ENODEHOOKS,
1545
  CV_ENODEHV,
1546
  CV_ENODELVM,
1547
  CV_ENODEN1,
1548
  CV_ENODENET,
1549
  CV_ENODEOS,
1550
  CV_ENODEORPHANINSTANCE,
1551
  CV_ENODEORPHANLV,
1552
  CV_ENODERPC,
1553
  CV_ENODESSH,
1554
  CV_ENODEVERSION,
1555
  CV_ENODESETUP,
1556
  CV_ENODETIME,
1557
  CV_ENODEOOBPATH,
1558
  CV_ENODEUSERSCRIPTS,
1559
  CV_ENODEFILESTORAGEPATHS,
1560
  ])
1561

    
1562
CV_ALL_ECODES_STRINGS = \
1563
  compat.UniqueFrozenset(estr for (_, estr, _) in CV_ALL_ECODES)
1564

    
1565
# Node verify constants
1566
NV_BRIDGES = "bridges"
1567
NV_DRBDHELPER = "drbd-helper"
1568
NV_DRBDLIST = "drbd-list"
1569
NV_EXCLUSIVEPVS = "exclusive-pvs"
1570
NV_FILELIST = "filelist"
1571
NV_FILE_STORAGE_PATHS = "file-storage-paths"
1572
NV_HVINFO = "hvinfo"
1573
NV_HVPARAMS = "hvparms"
1574
NV_HYPERVISOR = "hypervisor"
1575
NV_INSTANCELIST = "instancelist"
1576
NV_LVLIST = "lvlist"
1577
NV_MASTERIP = "master-ip"
1578
NV_NODELIST = "nodelist"
1579
NV_NODENETTEST = "node-net-test"
1580
NV_NODESETUP = "nodesetup"
1581
NV_OOB_PATHS = "oob-paths"
1582
NV_OSLIST = "oslist"
1583
NV_PVLIST = "pvlist"
1584
NV_TIME = "time"
1585
NV_USERSCRIPTS = "user-scripts"
1586
NV_VERSION = "version"
1587
NV_VGLIST = "vglist"
1588
NV_VMNODES = "vmnodes"
1589

    
1590
# Instance status
1591
INSTST_RUNNING = "running"
1592
INSTST_ADMINDOWN = "ADMIN_down"
1593
INSTST_ADMINOFFLINE = "ADMIN_offline"
1594
INSTST_NODEOFFLINE = "ERROR_nodeoffline"
1595
INSTST_NODEDOWN = "ERROR_nodedown"
1596
INSTST_WRONGNODE = "ERROR_wrongnode"
1597
INSTST_ERRORUP = "ERROR_up"
1598
INSTST_ERRORDOWN = "ERROR_down"
1599
INSTST_ALL = compat.UniqueFrozenset([
1600
  INSTST_RUNNING,
1601
  INSTST_ADMINDOWN,
1602
  INSTST_ADMINOFFLINE,
1603
  INSTST_NODEOFFLINE,
1604
  INSTST_NODEDOWN,
1605
  INSTST_WRONGNODE,
1606
  INSTST_ERRORUP,
1607
  INSTST_ERRORDOWN,
1608
  ])
1609

    
1610
# Admin states
1611
ADMINST_UP = "up"
1612
ADMINST_DOWN = "down"
1613
ADMINST_OFFLINE = "offline"
1614
ADMINST_ALL = compat.UniqueFrozenset([
1615
  ADMINST_UP,
1616
  ADMINST_DOWN,
1617
  ADMINST_OFFLINE,
1618
  ])
1619

    
1620
# Node roles
1621
NR_REGULAR = "R"
1622
NR_MASTER = "M"
1623
NR_MCANDIDATE = "C"
1624
NR_DRAINED = "D"
1625
NR_OFFLINE = "O"
1626
NR_ALL = compat.UniqueFrozenset([
1627
  NR_REGULAR,
1628
  NR_MASTER,
1629
  NR_MCANDIDATE,
1630
  NR_DRAINED,
1631
  NR_OFFLINE,
1632
  ])
1633

    
1634
# SSL certificate check constants (in days)
1635
SSL_CERT_EXPIRATION_WARN = 30
1636
SSL_CERT_EXPIRATION_ERROR = 7
1637

    
1638
# Allocator framework constants
1639
IALLOCATOR_VERSION = 2
1640
IALLOCATOR_DIR_IN = "in"
1641
IALLOCATOR_DIR_OUT = "out"
1642
VALID_IALLOCATOR_DIRECTIONS = compat.UniqueFrozenset([
1643
  IALLOCATOR_DIR_IN,
1644
  IALLOCATOR_DIR_OUT,
1645
  ])
1646
IALLOCATOR_MODE_ALLOC = "allocate"
1647
IALLOCATOR_MODE_RELOC = "relocate"
1648
IALLOCATOR_MODE_CHG_GROUP = "change-group"
1649
IALLOCATOR_MODE_NODE_EVAC = "node-evacuate"
1650
IALLOCATOR_MODE_MULTI_ALLOC = "multi-allocate"
1651
VALID_IALLOCATOR_MODES = compat.UniqueFrozenset([
1652
  IALLOCATOR_MODE_ALLOC,
1653
  IALLOCATOR_MODE_RELOC,
1654
  IALLOCATOR_MODE_CHG_GROUP,
1655
  IALLOCATOR_MODE_NODE_EVAC,
1656
  IALLOCATOR_MODE_MULTI_ALLOC,
1657
  ])
1658
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
1659
DEFAULT_IALLOCATOR_SHORTCUT = "."
1660

    
1661
IALLOCATOR_NEVAC_PRI = "primary-only"
1662
IALLOCATOR_NEVAC_SEC = "secondary-only"
1663
IALLOCATOR_NEVAC_ALL = "all"
1664
IALLOCATOR_NEVAC_MODES = compat.UniqueFrozenset([
1665
  IALLOCATOR_NEVAC_PRI,
1666
  IALLOCATOR_NEVAC_SEC,
1667
  IALLOCATOR_NEVAC_ALL,
1668
  ])
1669

    
1670
# Node evacuation
1671
NODE_EVAC_PRI = "primary-only"
1672
NODE_EVAC_SEC = "secondary-only"
1673
NODE_EVAC_ALL = "all"
1674
NODE_EVAC_MODES = compat.UniqueFrozenset([
1675
  NODE_EVAC_PRI,
1676
  NODE_EVAC_SEC,
1677
  NODE_EVAC_ALL,
1678
  ])
1679

    
1680
# Job queue
1681
JOB_QUEUE_VERSION = 1
1682
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
1683

    
1684
JOB_ID_TEMPLATE = r"\d+"
1685
JOB_FILE_RE = re.compile(r"^job-(%s)$" % JOB_ID_TEMPLATE)
1686

    
1687
# unchanged job return
1688
JOB_NOTCHANGED = "nochange"
1689

    
1690
# Job status
1691
JOB_STATUS_QUEUED = "queued"
1692
JOB_STATUS_WAITING = "waiting"
1693
JOB_STATUS_CANCELING = "canceling"
1694
JOB_STATUS_RUNNING = "running"
1695
JOB_STATUS_CANCELED = "canceled"
1696
JOB_STATUS_SUCCESS = "success"
1697
JOB_STATUS_ERROR = "error"
1698
JOBS_PENDING = compat.UniqueFrozenset([
1699
  JOB_STATUS_QUEUED,
1700
  JOB_STATUS_WAITING,
1701
  JOB_STATUS_CANCELING,
1702
  ])
1703
JOBS_FINALIZED = compat.UniqueFrozenset([
1704
  JOB_STATUS_CANCELED,
1705
  JOB_STATUS_SUCCESS,
1706
  JOB_STATUS_ERROR,
1707
  ])
1708
JOB_STATUS_ALL = compat.UniqueFrozenset([
1709
  JOB_STATUS_RUNNING,
1710
  ]) | JOBS_PENDING | JOBS_FINALIZED
1711

    
1712
# OpCode status
1713
# not yet finalized
1714
OP_STATUS_QUEUED = "queued"
1715
OP_STATUS_WAITING = "waiting"
1716
OP_STATUS_CANCELING = "canceling"
1717
OP_STATUS_RUNNING = "running"
1718
# finalized
1719
OP_STATUS_CANCELED = "canceled"
1720
OP_STATUS_SUCCESS = "success"
1721
OP_STATUS_ERROR = "error"
1722
OPS_FINALIZED = compat.UniqueFrozenset([
1723
  OP_STATUS_CANCELED,
1724
  OP_STATUS_SUCCESS,
1725
  OP_STATUS_ERROR,
1726
  ])
1727

    
1728
# OpCode priority
1729
OP_PRIO_LOWEST = +19
1730
OP_PRIO_HIGHEST = -20
1731

    
1732
OP_PRIO_LOW = +10
1733
OP_PRIO_NORMAL = 0
1734
OP_PRIO_HIGH = -10
1735

    
1736
OP_PRIO_SUBMIT_VALID = compat.UniqueFrozenset([
1737
  OP_PRIO_LOW,
1738
  OP_PRIO_NORMAL,
1739
  OP_PRIO_HIGH,
1740
  ])
1741

    
1742
OP_PRIO_DEFAULT = OP_PRIO_NORMAL
1743

    
1744
# Lock recalculate mode
1745
LOCKS_REPLACE = "replace"
1746
LOCKS_APPEND = "append"
1747

    
1748
# Lock timeout (sum) before we should go into blocking acquire (still
1749
# can be reset by priority change); computed as max time (10 hours)
1750
# before we should actually go into blocking acquire given that we
1751
# start from default priority level; in seconds
1752
# TODO
1753
LOCK_ATTEMPTS_TIMEOUT = 10 * 3600 / (OP_PRIO_DEFAULT - OP_PRIO_HIGHEST)
1754
LOCK_ATTEMPTS_MAXWAIT = 15.0
1755
LOCK_ATTEMPTS_MINWAIT = 1.0
1756

    
1757
# Execution log types
1758
ELOG_MESSAGE = "message"
1759
ELOG_REMOTE_IMPORT = "remote-import"
1760
ELOG_JQUEUE_TEST = "jqueue-test"
1761

    
1762
# /etc/hosts modification
1763
ETC_HOSTS_ADD = "add"
1764
ETC_HOSTS_REMOVE = "remove"
1765

    
1766
# Job queue test
1767
JQT_MSGPREFIX = "TESTMSG="
1768
JQT_EXPANDNAMES = "expandnames"
1769
JQT_EXEC = "exec"
1770
JQT_LOGMSG = "logmsg"
1771
JQT_STARTMSG = "startmsg"
1772
JQT_ALL = compat.UniqueFrozenset([
1773
  JQT_EXPANDNAMES,
1774
  JQT_EXEC,
1775
  JQT_LOGMSG,
1776
  JQT_STARTMSG,
1777
  ])
1778

    
1779
# Query resources
1780
QR_CLUSTER = "cluster"
1781
QR_INSTANCE = "instance"
1782
QR_NODE = "node"
1783
QR_LOCK = "lock"
1784
QR_GROUP = "group"
1785
QR_OS = "os"
1786
QR_JOB = "job"
1787
QR_EXPORT = "export"
1788
QR_NETWORK = "network"
1789
QR_EXTSTORAGE = "extstorage"
1790

    
1791
#: List of resources which can be queried using L{opcodes.OpQuery}
1792
QR_VIA_OP = compat.UniqueFrozenset([
1793
  QR_CLUSTER,
1794
  QR_INSTANCE,
1795
  QR_NODE,
1796
  QR_GROUP,
1797
  QR_OS,
1798
  QR_EXPORT,
1799
  QR_NETWORK,
1800
  QR_EXTSTORAGE,
1801
  ])
1802

    
1803
#: List of resources which can be queried using Local UniX Interface
1804
QR_VIA_LUXI = QR_VIA_OP.union([
1805
  QR_LOCK,
1806
  QR_JOB,
1807
  ])
1808

    
1809
#: List of resources which can be queried using RAPI
1810
QR_VIA_RAPI = QR_VIA_LUXI
1811

    
1812
# Query field types
1813
QFT_UNKNOWN = "unknown"
1814
QFT_TEXT = "text"
1815
QFT_BOOL = "bool"
1816
QFT_NUMBER = "number"
1817
QFT_UNIT = "unit"
1818
QFT_TIMESTAMP = "timestamp"
1819
QFT_OTHER = "other"
1820

    
1821
#: All query field types
1822
QFT_ALL = compat.UniqueFrozenset([
1823
  QFT_UNKNOWN,
1824
  QFT_TEXT,
1825
  QFT_BOOL,
1826
  QFT_NUMBER,
1827
  QFT_UNIT,
1828
  QFT_TIMESTAMP,
1829
  QFT_OTHER,
1830
  ])
1831

    
1832
# Query result field status (don't change or reuse values as they're used by
1833
# clients)
1834
#: Normal field status
1835
RS_NORMAL = 0
1836
#: Unknown field
1837
RS_UNKNOWN = 1
1838
#: No data (e.g. RPC error), can be used instead of L{RS_OFFLINE}
1839
RS_NODATA = 2
1840
#: Value unavailable/unsupported for item; if this field is supported
1841
#: but we cannot get the data for the moment, RS_NODATA or
1842
#: RS_OFFLINE should be used
1843
RS_UNAVAIL = 3
1844
#: Resource marked offline
1845
RS_OFFLINE = 4
1846

    
1847
RS_ALL = compat.UniqueFrozenset([
1848
  RS_NORMAL,
1849
  RS_UNKNOWN,
1850
  RS_NODATA,
1851
  RS_UNAVAIL,
1852
  RS_OFFLINE,
1853
  ])
1854

    
1855
#: Dictionary with special field cases and their verbose/terse formatting
1856
RSS_DESCRIPTION = {
1857
  RS_UNKNOWN: ("(unknown)", "??"),
1858
  RS_NODATA: ("(nodata)", "?"),
1859
  RS_OFFLINE: ("(offline)", "*"),
1860
  RS_UNAVAIL: ("(unavail)", "-"),
1861
  }
1862

    
1863
# max dynamic devices
1864
MAX_NICS = 8
1865
MAX_DISKS = 16
1866

    
1867
# SSCONF file prefix
1868
SSCONF_FILEPREFIX = "ssconf_"
1869
# SSCONF keys
1870
SS_CLUSTER_NAME = "cluster_name"
1871
SS_CLUSTER_TAGS = "cluster_tags"
1872
SS_FILE_STORAGE_DIR = "file_storage_dir"
1873
SS_SHARED_FILE_STORAGE_DIR = "shared_file_storage_dir"
1874
SS_MASTER_CANDIDATES = "master_candidates"
1875
SS_MASTER_CANDIDATES_IPS = "master_candidates_ips"
1876
SS_MASTER_IP = "master_ip"
1877
SS_MASTER_NETDEV = "master_netdev"
1878
SS_MASTER_NETMASK = "master_netmask"
1879
SS_MASTER_NODE = "master_node"
1880
SS_NODE_LIST = "node_list"
1881
SS_NODE_PRIMARY_IPS = "node_primary_ips"
1882
SS_NODE_SECONDARY_IPS = "node_secondary_ips"
1883
SS_OFFLINE_NODES = "offline_nodes"
1884
SS_ONLINE_NODES = "online_nodes"
1885
SS_PRIMARY_IP_FAMILY = "primary_ip_family"
1886
SS_INSTANCE_LIST = "instance_list"
1887
SS_RELEASE_VERSION = "release_version"
1888
SS_HYPERVISOR_LIST = "hypervisor_list"
1889
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
1890
SS_UID_POOL = "uid_pool"
1891
SS_NODEGROUPS = "nodegroups"
1892
SS_NETWORKS = "networks"
1893

    
1894
SS_FILE_PERMS = 0444
1895

    
1896
# cluster wide default parameters
1897
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
1898

    
1899
HVC_DEFAULTS = {
1900
  HT_XEN_PVM: {
1901
    HV_USE_BOOTLOADER: False,
1902
    HV_BOOTLOADER_PATH: XEN_BOOTLOADER,
1903
    HV_BOOTLOADER_ARGS: "",
1904
    HV_KERNEL_PATH: XEN_KERNEL,
1905
    HV_INITRD_PATH: "",
1906
    HV_ROOT_PATH: "/dev/xvda1",
1907
    HV_KERNEL_ARGS: "ro",
1908
    HV_MIGRATION_PORT: 8002,
1909
    HV_MIGRATION_MODE: HT_MIGRATION_LIVE,
1910
    HV_BLOCKDEV_PREFIX: "sd",
1911
    HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED,
1912
    HV_CPU_MASK: CPU_PINNING_ALL,
1913
    HV_CPU_CAP: 0,
1914
    HV_CPU_WEIGHT: 256,
1915
    },
1916
  HT_XEN_HVM: {
1917
    HV_BOOT_ORDER: "cd",
1918
    HV_CDROM_IMAGE_PATH: "",
1919
    HV_NIC_TYPE: HT_NIC_RTL8139,
1920
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
1921
    HV_VNC_BIND_ADDRESS: IP4_ADDRESS_ANY,
1922
    HV_VNC_PASSWORD_FILE: pathutils.VNC_PASSWORD_FILE,
1923
    HV_ACPI: True,
1924
    HV_PAE: True,
1925
    HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
1926
    HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
1927
    HV_MIGRATION_PORT: 8002,
1928
    HV_MIGRATION_MODE: HT_MIGRATION_NONLIVE,
1929
    HV_USE_LOCALTIME: False,
1930
    HV_BLOCKDEV_PREFIX: "hd",
1931
    HV_PASSTHROUGH: "",
1932
    HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED,
1933
    HV_CPU_MASK: CPU_PINNING_ALL,
1934
    HV_CPU_CAP: 0,
1935
    HV_CPU_WEIGHT: 256,
1936
    },
1937
  HT_KVM: {
1938
    HV_KVM_PATH: KVM_PATH,
1939
    HV_KERNEL_PATH: KVM_KERNEL,
1940
    HV_INITRD_PATH: "",
1941
    HV_KERNEL_ARGS: "ro",
1942
    HV_ROOT_PATH: "/dev/vda1",
1943
    HV_ACPI: True,
1944
    HV_SERIAL_CONSOLE: True,
1945
    HV_SERIAL_SPEED: 38400,
1946
    HV_VNC_BIND_ADDRESS: "",
1947
    HV_VNC_TLS: False,
1948
    HV_VNC_X509: "",
1949
    HV_VNC_X509_VERIFY: False,
1950
    HV_VNC_PASSWORD_FILE: "",
1951
    HV_KVM_SPICE_BIND: "",
1952
    HV_KVM_SPICE_IP_VERSION: IFACE_NO_IP_VERSION_SPECIFIED,
1953
    HV_KVM_SPICE_PASSWORD_FILE: "",
1954
    HV_KVM_SPICE_LOSSLESS_IMG_COMPR: "",
1955
    HV_KVM_SPICE_JPEG_IMG_COMPR: "",
1956
    HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR: "",
1957
    HV_KVM_SPICE_STREAMING_VIDEO_DETECTION: "",
1958
    HV_KVM_SPICE_AUDIO_COMPR: True,
1959
    HV_KVM_SPICE_USE_TLS: False,
1960
    HV_KVM_SPICE_TLS_CIPHERS: OPENSSL_CIPHERS,
1961
    HV_KVM_SPICE_USE_VDAGENT: True,
1962
    HV_KVM_FLOPPY_IMAGE_PATH: "",
1963
    HV_CDROM_IMAGE_PATH: "",
1964
    HV_KVM_CDROM2_IMAGE_PATH: "",
1965
    HV_BOOT_ORDER: HT_BO_DISK,
1966
    HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
1967
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
1968
    HV_KVM_CDROM_DISK_TYPE: "",
1969
    HV_USB_MOUSE: "",
1970
    HV_KEYMAP: "",
1971
    HV_MIGRATION_PORT: 8102,
1972
    HV_MIGRATION_BANDWIDTH: 32, # MiB/s
1973
    HV_MIGRATION_DOWNTIME: 30,  # ms
1974
    HV_MIGRATION_MODE: HT_MIGRATION_LIVE,
1975
    HV_USE_LOCALTIME: False,
1976
    HV_DISK_CACHE: HT_CACHE_DEFAULT,
1977
    HV_SECURITY_MODEL: HT_SM_NONE,
1978
    HV_SECURITY_DOMAIN: "",
1979
    HV_KVM_FLAG: "",
1980
    HV_VHOST_NET: False,
1981
    HV_KVM_USE_CHROOT: False,
1982
    HV_MEM_PATH: "",
1983
    HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED,
1984
    HV_CPU_MASK: CPU_PINNING_ALL,
1985
    HV_CPU_TYPE: "",
1986
    HV_CPU_CORES: 0,
1987
    HV_CPU_THREADS: 0,
1988
    HV_CPU_SOCKETS: 0,
1989
    HV_SOUNDHW: "",
1990
    HV_USB_DEVICES: "",
1991
    HV_VGA: "",
1992
    HV_KVM_EXTRA: "",
1993
    HV_KVM_MACHINE_VERSION: "",
1994
    },
1995
  HT_FAKE: {},
1996
  HT_CHROOT: {
1997
    HV_INIT_SCRIPT: "/ganeti-chroot",
1998
    },
1999
  HT_LXC: {
2000
    HV_CPU_MASK: "",
2001
    },
2002
  }
2003

    
2004
HVC_GLOBALS = compat.UniqueFrozenset([
2005
  HV_MIGRATION_PORT,
2006
  HV_MIGRATION_BANDWIDTH,
2007
  HV_MIGRATION_MODE,
2008
  ])
2009

    
2010
BEC_DEFAULTS = {
2011
  BE_MINMEM: 128,
2012
  BE_MAXMEM: 128,
2013
  BE_VCPUS: 1,
2014
  BE_AUTO_BALANCE: True,
2015
  BE_ALWAYS_FAILOVER: False,
2016
  BE_SPINDLE_USE: 1,
2017
  }
2018

    
2019
NDC_DEFAULTS = {
2020
  ND_OOB_PROGRAM: "",
2021
  ND_SPINDLE_COUNT: 1,
2022
  ND_EXCLUSIVE_STORAGE: False,
2023
  }
2024

    
2025
NDC_GLOBALS = compat.UniqueFrozenset([
2026
  ND_EXCLUSIVE_STORAGE,
2027
  ])
2028

    
2029
DISK_LD_DEFAULTS = {
2030
  LD_DRBD8: {
2031
    LDP_RESYNC_RATE: CLASSIC_DRBD_SYNC_SPEED,
2032
    LDP_BARRIERS: _autoconf.DRBD_BARRIERS,
2033
    LDP_NO_META_FLUSH: _autoconf.DRBD_NO_META_FLUSH,
2034
    LDP_DEFAULT_METAVG: DEFAULT_VG,
2035
    LDP_DISK_CUSTOM: "",
2036
    LDP_NET_CUSTOM: "",
2037
    LDP_DYNAMIC_RESYNC: False,
2038

    
2039
    # The default values for the DRBD dynamic resync speed algorithm
2040
    # are taken from the drbsetup 8.3.11 man page, except for
2041
    # c-plan-ahead (that we don't need to set to 0, because we have a
2042
    # separate option to enable it) and for c-max-rate, that we cap to
2043
    # the default value for the static resync rate.
2044
    LDP_PLAN_AHEAD: 20, # ds
2045
    LDP_FILL_TARGET: 0, # sectors
2046
    LDP_DELAY_TARGET: 1, # ds
2047
    LDP_MAX_RATE: CLASSIC_DRBD_SYNC_SPEED, # KiB/s
2048
    LDP_MIN_RATE: 4 * 1024, # KiB/s
2049
    },
2050
  LD_LV: {
2051
    LDP_STRIPES: _autoconf.LVM_STRIPECOUNT
2052
    },
2053
  LD_FILE: {},
2054
  LD_BLOCKDEV: {},
2055
  LD_RBD: {
2056
    LDP_POOL: "rbd"
2057
    },
2058
  LD_EXT: {},
2059
  }
2060

    
2061
# readability shortcuts
2062
_LV_DEFAULTS = DISK_LD_DEFAULTS[LD_LV]
2063
_DRBD_DEFAULTS = DISK_LD_DEFAULTS[LD_DRBD8]
2064

    
2065
DISK_DT_DEFAULTS = {
2066
  DT_PLAIN: {
2067
    LV_STRIPES: DISK_LD_DEFAULTS[LD_LV][LDP_STRIPES],
2068
    },
2069
  DT_DRBD8: {
2070
    DRBD_RESYNC_RATE: _DRBD_DEFAULTS[LDP_RESYNC_RATE],
2071
    DRBD_DATA_STRIPES: _LV_DEFAULTS[LDP_STRIPES],
2072
    DRBD_META_STRIPES: _LV_DEFAULTS[LDP_STRIPES],
2073
    DRBD_DISK_BARRIERS: _DRBD_DEFAULTS[LDP_BARRIERS],
2074
    DRBD_META_BARRIERS: _DRBD_DEFAULTS[LDP_NO_META_FLUSH],
2075
    DRBD_DEFAULT_METAVG: _DRBD_DEFAULTS[LDP_DEFAULT_METAVG],
2076
    DRBD_DISK_CUSTOM: _DRBD_DEFAULTS[LDP_DISK_CUSTOM],
2077
    DRBD_NET_CUSTOM: _DRBD_DEFAULTS[LDP_NET_CUSTOM],
2078
    DRBD_DYNAMIC_RESYNC: _DRBD_DEFAULTS[LDP_DYNAMIC_RESYNC],
2079
    DRBD_PLAN_AHEAD: _DRBD_DEFAULTS[LDP_PLAN_AHEAD],
2080
    DRBD_FILL_TARGET: _DRBD_DEFAULTS[LDP_FILL_TARGET],
2081
    DRBD_DELAY_TARGET: _DRBD_DEFAULTS[LDP_DELAY_TARGET],
2082
    DRBD_MAX_RATE: _DRBD_DEFAULTS[LDP_MAX_RATE],
2083
    DRBD_MIN_RATE: _DRBD_DEFAULTS[LDP_MIN_RATE],
2084
    },
2085
  DT_DISKLESS: {},
2086
  DT_FILE: {},
2087
  DT_SHARED_FILE: {},
2088
  DT_BLOCK: {},
2089
  DT_RBD: {
2090
    RBD_POOL: DISK_LD_DEFAULTS[LD_RBD][LDP_POOL]
2091
    },
2092
  DT_EXT: {},
2093
  }
2094

    
2095
# we don't want to export the shortcuts
2096
del _LV_DEFAULTS, _DRBD_DEFAULTS
2097

    
2098
NICC_DEFAULTS = {
2099
  NIC_MODE: NIC_MODE_BRIDGED,
2100
  NIC_LINK: DEFAULT_BRIDGE,
2101
  }
2102

    
2103
# All of the following values are quite arbitrarily - there are no
2104
# "good" defaults, these must be customised per-site
2105
IPOLICY_DEFAULTS = {
2106
  ISPECS_MIN: {
2107
    ISPEC_MEM_SIZE: 128,
2108
    ISPEC_CPU_COUNT: 1,
2109
    ISPEC_DISK_COUNT: 1,
2110
    ISPEC_DISK_SIZE: 1024,
2111
    ISPEC_NIC_COUNT: 1,
2112
    ISPEC_SPINDLE_USE: 1,
2113
    },
2114
  ISPECS_MAX: {
2115
    ISPEC_MEM_SIZE: 32768,
2116
    ISPEC_CPU_COUNT: 8,
2117
    ISPEC_DISK_COUNT: MAX_DISKS,
2118
    ISPEC_DISK_SIZE: 1024 * 1024,
2119
    ISPEC_NIC_COUNT: MAX_NICS,
2120
    ISPEC_SPINDLE_USE: 12,
2121
    },
2122
  ISPECS_STD: {
2123
    ISPEC_MEM_SIZE: 128,
2124
    ISPEC_CPU_COUNT: 1,
2125
    ISPEC_DISK_COUNT: 1,
2126
    ISPEC_DISK_SIZE: 1024,
2127
    ISPEC_NIC_COUNT: 1,
2128
    ISPEC_SPINDLE_USE: 1,
2129
    },
2130
  IPOLICY_DTS: list(DISK_TEMPLATES),
2131
  IPOLICY_VCPU_RATIO: 4.0,
2132
  IPOLICY_SPINDLE_RATIO: 32.0,
2133
  }
2134

    
2135
MASTER_POOL_SIZE_DEFAULT = 10
2136

    
2137
# Exclusive storage:
2138
# Error margin used to compare physical disks
2139
PART_MARGIN = .01
2140
# Space reserved when creating instance disks
2141
PART_RESERVED = .02
2142

    
2143
CONFD_PROTOCOL_VERSION = 1
2144

    
2145
CONFD_REQ_PING = 0
2146
CONFD_REQ_NODE_ROLE_BYNAME = 1
2147
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
2148
CONFD_REQ_CLUSTER_MASTER = 3
2149
CONFD_REQ_NODE_PIP_LIST = 4
2150
CONFD_REQ_MC_PIP_LIST = 5
2151
CONFD_REQ_INSTANCES_IPS_LIST = 6
2152
CONFD_REQ_NODE_DRBD = 7
2153
CONFD_REQ_NODE_INSTANCES = 8
2154

    
2155
# Confd request query fields. These are used to narrow down queries.
2156
# These must be strings rather than integers, because json-encoding
2157
# converts them to strings anyway, as they're used as dict-keys.
2158
CONFD_REQQ_LINK = "0"
2159
CONFD_REQQ_IP = "1"
2160
CONFD_REQQ_IPLIST = "2"
2161
CONFD_REQQ_FIELDS = "3"
2162

    
2163
CONFD_REQFIELD_NAME = "0"
2164
CONFD_REQFIELD_IP = "1"
2165
CONFD_REQFIELD_MNODE_PIP = "2"
2166

    
2167
CONFD_REQS = compat.UniqueFrozenset([
2168
  CONFD_REQ_PING,
2169
  CONFD_REQ_NODE_ROLE_BYNAME,
2170
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
2171
  CONFD_REQ_CLUSTER_MASTER,
2172
  CONFD_REQ_NODE_PIP_LIST,
2173
  CONFD_REQ_MC_PIP_LIST,
2174
  CONFD_REQ_INSTANCES_IPS_LIST,
2175
  CONFD_REQ_NODE_DRBD,
2176
  ])
2177

    
2178
CONFD_REPL_STATUS_OK = 0
2179
CONFD_REPL_STATUS_ERROR = 1
2180
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
2181

    
2182
CONFD_REPL_STATUSES = compat.UniqueFrozenset([
2183
  CONFD_REPL_STATUS_OK,
2184
  CONFD_REPL_STATUS_ERROR,
2185
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
2186
  ])
2187

    
2188
(CONFD_NODE_ROLE_MASTER,
2189
 CONFD_NODE_ROLE_CANDIDATE,
2190
 CONFD_NODE_ROLE_OFFLINE,
2191
 CONFD_NODE_ROLE_DRAINED,
2192
 CONFD_NODE_ROLE_REGULAR,
2193
 ) = range(5)
2194

    
2195
# A few common errors for confd
2196
CONFD_ERROR_UNKNOWN_ENTRY = 1
2197
CONFD_ERROR_INTERNAL = 2
2198
CONFD_ERROR_ARGUMENT = 3
2199

    
2200
# Each request is "salted" by the current timestamp.
2201
# This constants decides how many seconds of skew to accept.
2202
# TODO: make this a default and allow the value to be more configurable
2203
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
2204

    
2205
# When we haven't reloaded the config for more than this amount of
2206
# seconds, we force a test to see if inotify is betraying us. Using a
2207
# prime number to ensure we get less chance of 'same wakeup' with
2208
# other processes.
2209
CONFD_CONFIG_RELOAD_TIMEOUT = 17
2210

    
2211
# If we receive more than one update in this amount of microseconds,
2212
# we move to polling every RATELIMIT seconds, rather than relying on
2213
# inotify, to be able to serve more requests.
2214
CONFD_CONFIG_RELOAD_RATELIMIT = 250000
2215

    
2216
# Magic number prepended to all confd queries.
2217
# This allows us to distinguish different types of confd protocols and handle
2218
# them. For example by changing this we can move the whole payload to be
2219
# compressed, or move away from json.
2220
CONFD_MAGIC_FOURCC = "plj0"
2221

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

    
2227
# Timeout in seconds to expire pending query request in the confd client
2228
# library. We don't actually expect any answer more than 10 seconds after we
2229
# sent a request.
2230
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
2231

    
2232
# Maximum UDP datagram size.
2233
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
2234
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
2235
#   (assuming we can't use jumbo frames)
2236
# We just set this to 60K, which should be enough
2237
MAX_UDP_DATA_SIZE = 61440
2238

    
2239
# User-id pool minimum/maximum acceptable user-ids.
2240
UIDPOOL_UID_MIN = 0
2241
UIDPOOL_UID_MAX = 2 ** 32 - 1 # Assuming 32 bit user-ids
2242

    
2243
# Name or path of the pgrep command
2244
PGREP = "pgrep"
2245

    
2246
# Name of the node group that gets created at cluster init or upgrade
2247
INITIAL_NODE_GROUP_NAME = "default"
2248

    
2249
# Possible values for NodeGroup.alloc_policy
2250
ALLOC_POLICY_PREFERRED = "preferred"
2251
ALLOC_POLICY_LAST_RESORT = "last_resort"
2252
ALLOC_POLICY_UNALLOCABLE = "unallocable"
2253
VALID_ALLOC_POLICIES = [
2254
  ALLOC_POLICY_PREFERRED,
2255
  ALLOC_POLICY_LAST_RESORT,
2256
  ALLOC_POLICY_UNALLOCABLE,
2257
  ]
2258

    
2259
# Temporary external/shared storage parameters
2260
BLOCKDEV_DRIVER_MANUAL = "manual"
2261

    
2262
# qemu-img path, required for ovfconverter
2263
QEMUIMG_PATH = _autoconf.QEMUIMG_PATH
2264

    
2265
# Whether htools was enabled at compilation time
2266
HTOOLS = _autoconf.HTOOLS
2267
# The hail iallocator
2268
IALLOC_HAIL = "hail"
2269

    
2270
# Fake opcodes for functions that have hooks attached to them via
2271
# backend.RunLocalHooks
2272
FAKE_OP_MASTER_TURNUP = "OP_CLUSTER_IP_TURNUP"
2273
FAKE_OP_MASTER_TURNDOWN = "OP_CLUSTER_IP_TURNDOWN"
2274

    
2275
# SSH key types
2276
SSHK_RSA = "rsa"
2277
SSHK_DSA = "dsa"
2278
SSHK_ALL = compat.UniqueFrozenset([SSHK_RSA, SSHK_DSA])
2279

    
2280
# SSH authorized key types
2281
SSHAK_RSA = "ssh-rsa"
2282
SSHAK_DSS = "ssh-dss"
2283
SSHAK_ALL = compat.UniqueFrozenset([SSHAK_RSA, SSHAK_DSS])
2284

    
2285
# SSH setup
2286
SSHS_CLUSTER_NAME = "cluster_name"
2287
SSHS_SSH_HOST_KEY = "ssh_host_key"
2288
SSHS_SSH_ROOT_KEY = "ssh_root_key"
2289
SSHS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2290

    
2291
#: Key files for SSH daemon
2292
SSH_DAEMON_KEYFILES = {
2293
  SSHK_RSA: (pathutils.SSH_HOST_RSA_PRIV, pathutils.SSH_HOST_RSA_PUB),
2294
  SSHK_DSA: (pathutils.SSH_HOST_DSA_PRIV, pathutils.SSH_HOST_DSA_PUB),
2295
  }
2296

    
2297
# Node daemon setup
2298
NDS_CLUSTER_NAME = "cluster_name"
2299
NDS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2300
NDS_SSCONF = "ssconf"
2301
NDS_START_NODE_DAEMON = "start_node_daemon"
2302

    
2303
# Path generating random UUID
2304
RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
2305

    
2306
# Regex string for verifying a UUID
2307
UUID_REGEX = "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
2308

    
2309
# Auto-repair tag prefixes
2310
AUTO_REPAIR_TAG_PREFIX = "ganeti:watcher:autorepair:"
2311
AUTO_REPAIR_TAG_ENABLED = AUTO_REPAIR_TAG_PREFIX
2312
AUTO_REPAIR_TAG_SUSPENDED = AUTO_REPAIR_TAG_ENABLED + "suspend:"
2313
AUTO_REPAIR_TAG_PENDING = AUTO_REPAIR_TAG_PREFIX + "pending:"
2314
AUTO_REPAIR_TAG_RESULT = AUTO_REPAIR_TAG_PREFIX + "result:"
2315

    
2316
# Auto-repair levels
2317
AUTO_REPAIR_FIX_STORAGE = "fix-storage"
2318
AUTO_REPAIR_MIGRATE = "migrate"
2319
AUTO_REPAIR_FAILOVER = "failover"
2320
AUTO_REPAIR_REINSTALL = "reinstall"
2321
AUTO_REPAIR_ALL_TYPES = [
2322
  AUTO_REPAIR_FIX_STORAGE,
2323
  AUTO_REPAIR_MIGRATE,
2324
  AUTO_REPAIR_FAILOVER,
2325
  AUTO_REPAIR_REINSTALL,
2326
]
2327

    
2328
# Auto-repair results
2329
AUTO_REPAIR_SUCCESS = "success"
2330
AUTO_REPAIR_FAILURE = "failure"
2331
AUTO_REPAIR_ENOPERM = "enoperm"
2332
AUTO_REPAIR_ALL_RESULTS = frozenset([
2333
    AUTO_REPAIR_SUCCESS,
2334
    AUTO_REPAIR_FAILURE,
2335
    AUTO_REPAIR_ENOPERM,
2336
])
2337

    
2338
# The version identifier for builtin data collectors
2339
BUILTIN_DATA_COLLECTOR_VERSION = "B"
2340

    
2341
# The source reasons for the change of state of an instance
2342
INSTANCE_REASON_SOURCE_CLI = "cli"
2343
INSTANCE_REASON_SOURCE_RAPI = "rapi"
2344
INSTANCE_REASON_SOURCE_UNKNOWN = "unknown"
2345

    
2346
INSTANCE_REASON_SOURCES = compat.UniqueFrozenset([
2347
  INSTANCE_REASON_SOURCE_CLI,
2348
  INSTANCE_REASON_SOURCE_RAPI,
2349
  INSTANCE_REASON_SOURCE_UNKNOWN,
2350
  ])
2351

    
2352
# The default reasons for the change of state of an instance
2353
INSTANCE_REASON_REBOOT = "reboot"
2354

    
2355
# Do not re-export imported modules
2356
del re, _vcsversion, _autoconf, socket, pathutils, compat