Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ 05440845

History | View | Annotate | Download (60.4 kB)

1
#
2
#
3

    
4
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21

    
22
"""Module holding different constants."""
23

    
24
import re
25
import socket
26

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

    
32

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

    
47

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

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

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

65
  Returns: int representing version number
66

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

    
75

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

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

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

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

    
87
  return (major, minor, revision)
88

    
89

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

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

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

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

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

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

    
135
# Wipe
136
DD_CMD = "dd"
137
MAX_WIPE_CHUNK = 1024 # 1GB
138
MIN_WIPE_CHUNK_PERCENT = 10
139

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

    
150
NODED = "ganeti-noded"
151
CONFD = "ganeti-confd"
152
RAPI = "ganeti-rapi"
153
MASTERD = "ganeti-masterd"
154

    
155
DAEMONS_PORTS = {
156
  # daemon-name: ("proto", "default-port")
157
  NODED: ("tcp", 1811),
158
  CONFD: ("udp", 1814),
159
  RAPI: ("tcp", 5080),
160
  "ssh": ("tcp", 22),
161
}
162
DEFAULT_NODED_PORT = DAEMONS_PORTS[NODED][1]
163
DEFAULT_CONFD_PORT = DAEMONS_PORTS[CONFD][1]
164
DEFAULT_RAPI_PORT = DAEMONS_PORTS[RAPI][1]
165

    
166
FIRST_DRBD_PORT = 11000
167
LAST_DRBD_PORT = 14999
168

    
169
DAEMONS_LOGBASE = {
170
  NODED: "node-daemon",
171
  CONFD: "conf-daemon",
172
  RAPI: "rapi-daemon",
173
  MASTERD: "master-daemon",
174
  }
175

    
176
DAEMONS_LOGFILES = \
177
    dict((daemon, pathutils.GetLogFilename(DAEMONS_LOGBASE[daemon]))
178
         for daemon in DAEMONS_LOGBASE)
179

    
180
DEV_CONSOLE = "/dev/console"
181

    
182
PROC_MOUNTS = "/proc/mounts"
183

    
184
# Local UniX Interface related constants
185
LUXI_EOM = "\3"
186
LUXI_VERSION = CONFIG_VERSION
187

    
188
# one of "no", "yes", "only"
189
SYSLOG_USAGE = _autoconf.SYSLOG_USAGE
190
SYSLOG_NO = "no"
191
SYSLOG_YES = "yes"
192
SYSLOG_ONLY = "only"
193
SYSLOG_SOCKET = "/dev/log"
194

    
195
EXPORT_CONF_FILE = "config.ini"
196

    
197
XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER
198
XEN_KERNEL = _autoconf.XEN_KERNEL
199
XEN_INITRD = _autoconf.XEN_INITRD
200
XEN_CMD_XM = "xm"
201
XEN_CMD_XL = "xl"
202
# FIXME: This will be made configurable using hvparams in Ganeti 2.7
203
XEN_CMD = _autoconf.XEN_CMD
204
# When the Xen toolstack used is "xl", live migration requires the source host
205
# to connect to the target host via ssh (xl runs this command). We need to pass
206
# the command xl runs some extra info so that it can use Ganeti's key
207
# verification and not fail. Note that this string is incomplete: it must be
208
# filled with the cluster name before being used.
209
XL_SSH_CMD = ("ssh -l %s -oGlobalKnownHostsFile=%s"
210
              " -oUserKnownHostsFile=/dev/null"
211
              " -oCheckHostIp=no -oStrictHostKeyChecking=yes"
212
              " -oHostKeyAlias=%%s") % (SSH_LOGIN_USER,
213
                                        pathutils.SSH_KNOWN_HOSTS_FILE)
214

    
215
KVM_PATH = _autoconf.KVM_PATH
216
KVM_KERNEL = _autoconf.KVM_KERNEL
217
SOCAT_PATH = _autoconf.SOCAT_PATH
218
SOCAT_USE_ESCAPE = _autoconf.SOCAT_USE_ESCAPE
219
SOCAT_USE_COMPRESS = _autoconf.SOCAT_USE_COMPRESS
220
SOCAT_ESCAPE_CODE = "0x1d"
221

    
222
#: Console as SSH command
223
CONS_SSH = "ssh"
224

    
225
#: Console as VNC server
226
CONS_VNC = "vnc"
227

    
228
#: Console as SPICE server
229
CONS_SPICE = "spice"
230

    
231
#: Display a message for console access
232
CONS_MESSAGE = "msg"
233

    
234
#: All console types
235
CONS_ALL = compat.UniqueFrozenset([
236
  CONS_SSH,
237
  CONS_VNC,
238
  CONS_SPICE,
239
  CONS_MESSAGE,
240
  ])
241

    
242
# For RSA keys more bits are better, but they also make operations more
243
# expensive. NIST SP 800-131 recommends a minimum of 2048 bits from the year
244
# 2010 on.
245
RSA_KEY_BITS = 2048
246

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

    
255
# Digest used to sign certificates ("openssl x509" uses SHA1 by default)
256
X509_CERT_SIGN_DIGEST = "SHA1"
257

    
258
# Default validity of certificates in days
259
X509_CERT_DEFAULT_VALIDITY = 365 * 5
260

    
261
# commonName (CN) used in certificates
262
X509_CERT_CN = "ganeti.example.com"
263

    
264
X509_CERT_SIGNATURE_HEADER = "X-Ganeti-Signature"
265

    
266
# Import/export daemon mode
267
IEM_IMPORT = "import"
268
IEM_EXPORT = "export"
269

    
270
# Import/export transport compression
271
IEC_NONE = "none"
272
IEC_GZIP = "gzip"
273
IEC_ALL = compat.UniqueFrozenset([
274
  IEC_NONE,
275
  IEC_GZIP,
276
  ])
277

    
278
IE_CUSTOM_SIZE = "fd"
279

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

    
282
# Import/export I/O
283
# Direct file I/O, equivalent to a shell's I/O redirection using '<' or '>'
284
IEIO_FILE = "file"
285
# Raw block device I/O using "dd"
286
IEIO_RAW_DISK = "raw"
287
# OS definition import/export script
288
IEIO_SCRIPT = "script"
289

    
290
VALUE_DEFAULT = "default"
291
VALUE_AUTO = "auto"
292
VALUE_GENERATE = "generate"
293
VALUE_NONE = "none"
294
VALUE_TRUE = "true"
295
VALUE_FALSE = "false"
296

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

    
300
# hooks-related constants
301
HOOKS_PHASE_PRE = "pre"
302
HOOKS_PHASE_POST = "post"
303
HOOKS_NAME_CFGUPDATE = "config-update"
304
HOOKS_NAME_WATCHER = "watcher"
305
HOOKS_VERSION = 2
306
HOOKS_PATH = "/sbin:/bin:/usr/sbin:/usr/bin"
307

    
308
# hooks subject type (what object type does the LU deal with)
309
HTYPE_CLUSTER = "CLUSTER"
310
HTYPE_NODE = "NODE"
311
HTYPE_GROUP = "GROUP"
312
HTYPE_INSTANCE = "INSTANCE"
313
HTYPE_NETWORK = "NETWORK"
314

    
315
HKR_SKIP = 0
316
HKR_FAIL = 1
317
HKR_SUCCESS = 2
318

    
319
# Storage types
320
ST_FILE = "file"
321
ST_LVM_PV = "lvm-pv"
322
ST_LVM_VG = "lvm-vg"
323

    
324
# Storage fields
325
# first two are valid in LU context only, not passed to backend
326
SF_NODE = "node"
327
SF_TYPE = "type"
328
# and the rest are valid in backend
329
SF_NAME = "name"
330
SF_SIZE = "size"
331
SF_FREE = "free"
332
SF_USED = "used"
333
SF_ALLOCATABLE = "allocatable"
334

    
335
# Storage operations
336
SO_FIX_CONSISTENCY = "fix-consistency"
337

    
338
# Available fields per storage type
339
VALID_STORAGE_FIELDS = compat.UniqueFrozenset([
340
  SF_NAME,
341
  SF_TYPE,
342
  SF_SIZE,
343
  SF_USED,
344
  SF_FREE,
345
  SF_ALLOCATABLE,
346
  ])
347

    
348
VALID_STORAGE_TYPES = compat.UniqueFrozenset([
349
  ST_FILE,
350
  ST_LVM_PV,
351
  ST_LVM_VG,
352
  ])
353

    
354
MODIFIABLE_STORAGE_FIELDS = {
355
  ST_LVM_PV: frozenset([SF_ALLOCATABLE]),
356
  }
357

    
358
VALID_STORAGE_OPERATIONS = {
359
  ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
360
  }
361

    
362
# Local disk status
363
# Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
364
(LDS_OKAY,
365
 LDS_UNKNOWN,
366
 LDS_FAULTY) = range(1, 4)
367

    
368
# disk template types
369
DT_DISKLESS = "diskless"
370
DT_PLAIN = "plain"
371
DT_DRBD8 = "drbd"
372
DT_FILE = "file"
373
DT_SHARED_FILE = "sharedfile"
374
DT_BLOCK = "blockdev"
375
DT_RBD = "rbd"
376
DT_EXT = "ext"
377

    
378
# the set of network-mirrored disk templates
379
DTS_INT_MIRROR = compat.UniqueFrozenset([DT_DRBD8])
380

    
381
# the set of externally-mirrored disk templates (e.g. SAN, NAS)
382
DTS_EXT_MIRROR = compat.UniqueFrozenset([
383
  DT_DISKLESS, # 'trivially' externally mirrored
384
  DT_SHARED_FILE,
385
  DT_BLOCK,
386
  DT_RBD,
387
  DT_EXT,
388
  ])
389

    
390
# the set of non-lvm-based disk templates
391
DTS_NOT_LVM = compat.UniqueFrozenset([
392
  DT_DISKLESS,
393
  DT_FILE,
394
  DT_SHARED_FILE,
395
  DT_BLOCK,
396
  DT_RBD,
397
  DT_EXT,
398
  ])
399

    
400
# the set of disk templates which can be grown
401
DTS_GROWABLE = compat.UniqueFrozenset([
402
  DT_PLAIN,
403
  DT_DRBD8,
404
  DT_FILE,
405
  DT_SHARED_FILE,
406
  DT_RBD,
407
  DT_EXT,
408
  ])
409

    
410
# the set of disk templates that allow adoption
411
DTS_MAY_ADOPT = compat.UniqueFrozenset([
412
  DT_PLAIN,
413
  DT_BLOCK,
414
  ])
415

    
416
# the set of disk templates that *must* use adoption
417
DTS_MUST_ADOPT = compat.UniqueFrozenset([DT_BLOCK])
418

    
419
# the set of disk templates that allow migrations
420
DTS_MIRRORED = frozenset.union(DTS_INT_MIRROR, DTS_EXT_MIRROR)
421

    
422
# the set of file based disk templates
423
DTS_FILEBASED = compat.UniqueFrozenset([
424
  DT_FILE,
425
  DT_SHARED_FILE,
426
  ])
427

    
428
# the set of disk templates that can be moved by copying
429
# Note: a requirement is that they're not accessed externally or shared between
430
# nodes; in particular, sharedfile is not suitable.
431
DTS_COPYABLE = compat.UniqueFrozenset([
432
  DT_FILE,
433
  DT_PLAIN,
434
  ])
435

    
436
# the set of disk templates that are supported by exclusive_storage
437
DTS_EXCL_STORAGE = compat.UniqueFrozenset([DT_PLAIN])
438

    
439
# templates for which we don't perform checks on free space
440
DTS_NO_FREE_SPACE_CHECK = compat.UniqueFrozenset([
441
  DT_FILE,
442
  DT_SHARED_FILE,
443
  DT_RBD,
444
  DT_EXT,
445
  ])
446

    
447
# logical disk types
448
LD_LV = "lvm"
449
LD_DRBD8 = "drbd8"
450
LD_FILE = "file"
451
LD_BLOCKDEV = "blockdev"
452
LD_RBD = "rbd"
453
LD_EXT = "ext"
454
LOGICAL_DISK_TYPES = compat.UniqueFrozenset([
455
  LD_LV,
456
  LD_DRBD8,
457
  LD_FILE,
458
  LD_BLOCKDEV,
459
  LD_RBD,
460
  LD_EXT,
461
  ])
462

    
463
LDS_BLOCK = compat.UniqueFrozenset([
464
  LD_LV,
465
  LD_DRBD8,
466
  LD_BLOCKDEV,
467
  LD_RBD,
468
  LD_EXT,
469
  ])
470

    
471
# drbd constants
472
DRBD_HMAC_ALG = "md5"
473
DRBD_NET_PROTOCOL = "C"
474
DRBD_STATUS_FILE = "/proc/drbd"
475

    
476
#: Size of DRBD meta block device
477
DRBD_META_SIZE = 128
478

    
479
# drbd barrier types
480
DRBD_B_NONE = "n"
481
DRBD_B_DISK_BARRIERS = "b"
482
DRBD_B_DISK_DRAIN = "d"
483
DRBD_B_DISK_FLUSH = "f"
484

    
485
# Valid barrier combinations: "n" or any non-null subset of "bfd"
486
DRBD_VALID_BARRIER_OPT = compat.UniqueFrozenset([
487
  frozenset([DRBD_B_NONE]),
488
  frozenset([DRBD_B_DISK_BARRIERS]),
489
  frozenset([DRBD_B_DISK_DRAIN]),
490
  frozenset([DRBD_B_DISK_FLUSH]),
491
  frozenset([DRBD_B_DISK_DRAIN, DRBD_B_DISK_FLUSH]),
492
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_DRAIN]),
493
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_FLUSH]),
494
  frozenset([DRBD_B_DISK_BARRIERS, DRBD_B_DISK_FLUSH, DRBD_B_DISK_DRAIN]),
495
  ])
496

    
497
# rbd tool command
498
RBD_CMD = "rbd"
499

    
500
# file backend driver
501
FD_LOOP = "loop"
502
FD_BLKTAP = "blktap"
503

    
504
# the set of drbd-like disk types
505
LDS_DRBD = compat.UniqueFrozenset([LD_DRBD8])
506

    
507
# disk access mode
508
DISK_RDONLY = "ro"
509
DISK_RDWR = "rw"
510
DISK_ACCESS_SET = compat.UniqueFrozenset([DISK_RDONLY, DISK_RDWR])
511

    
512
# disk replacement mode
513
REPLACE_DISK_PRI = "replace_on_primary"    # replace disks on primary
514
REPLACE_DISK_SEC = "replace_on_secondary"  # replace disks on secondary
515
REPLACE_DISK_CHG = "replace_new_secondary" # change secondary node
516
REPLACE_DISK_AUTO = "replace_auto"
517
REPLACE_MODES = compat.UniqueFrozenset([
518
  REPLACE_DISK_PRI,
519
  REPLACE_DISK_SEC,
520
  REPLACE_DISK_CHG,
521
  REPLACE_DISK_AUTO,
522
  ])
523

    
524
# Instance export mode
525
EXPORT_MODE_LOCAL = "local"
526
EXPORT_MODE_REMOTE = "remote"
527
EXPORT_MODES = compat.UniqueFrozenset([
528
  EXPORT_MODE_LOCAL,
529
  EXPORT_MODE_REMOTE,
530
  ])
531

    
532
# instance creation modes
533
INSTANCE_CREATE = "create"
534
INSTANCE_IMPORT = "import"
535
INSTANCE_REMOTE_IMPORT = "remote-import"
536
INSTANCE_CREATE_MODES = compat.UniqueFrozenset([
537
  INSTANCE_CREATE,
538
  INSTANCE_IMPORT,
539
  INSTANCE_REMOTE_IMPORT,
540
  ])
541

    
542
# Remote import/export handshake message and version
543
RIE_VERSION = 0
544
RIE_HANDSHAKE = "Hi, I'm Ganeti"
545

    
546
# Remote import/export certificate validity in seconds
547
RIE_CERT_VALIDITY = 24 * 60 * 60
548

    
549
# Overall timeout for establishing connection
550
RIE_CONNECT_TIMEOUT = 180
551

    
552
# Export only: how long to wait per connection attempt (seconds)
553
RIE_CONNECT_ATTEMPT_TIMEOUT = 20
554

    
555
# Export only: number of attempts to connect
556
RIE_CONNECT_RETRIES = 10
557

    
558
#: Give child process up to 5 seconds to exit after sending a signal
559
CHILD_LINGER_TIMEOUT = 5.0
560

    
561
DISK_TEMPLATES = compat.UniqueFrozenset([
562
  DT_DISKLESS,
563
  DT_PLAIN,
564
  DT_DRBD8,
565
  DT_FILE,
566
  DT_SHARED_FILE,
567
  DT_BLOCK,
568
  DT_RBD,
569
  DT_EXT
570
  ])
571

    
572
FILE_DRIVER = compat.UniqueFrozenset([FD_LOOP, FD_BLKTAP])
573

    
574
# import/export config options
575
INISECT_EXP = "export"
576
INISECT_INS = "instance"
577
INISECT_HYP = "hypervisor"
578
INISECT_BEP = "backend"
579
INISECT_OSP = "os"
580

    
581
# dynamic device modification
582
DDM_ADD = "add"
583
DDM_MODIFY = "modify"
584
DDM_REMOVE = "remove"
585
DDMS_VALUES = compat.UniqueFrozenset([DDM_ADD, DDM_REMOVE])
586
DDMS_VALUES_WITH_MODIFY = (DDMS_VALUES | frozenset([
587
  DDM_MODIFY,
588
  ]))
589
# TODO: DDM_SWAP, DDM_MOVE?
590

    
591
# common exit codes
592
EXIT_SUCCESS = 0
593
EXIT_FAILURE = 1
594
EXIT_NOTCLUSTER = 5
595
EXIT_NOTMASTER = 11
596
EXIT_NODESETUP_ERROR = 12
597
EXIT_CONFIRMATION = 13 # need user confirmation
598

    
599
#: Exit code for query operations with unknown fields
600
EXIT_UNKNOWN_FIELD = 14
601

    
602
# tags
603
TAG_CLUSTER = "cluster"
604
TAG_NODEGROUP = "nodegroup"
605
TAG_NODE = "node"
606
TAG_INSTANCE = "instance"
607
TAG_NETWORK = "network"
608
VALID_TAG_TYPES = compat.UniqueFrozenset([
609
  TAG_CLUSTER,
610
  TAG_NODEGROUP,
611
  TAG_NODE,
612
  TAG_INSTANCE,
613
  TAG_NETWORK,
614
  ])
615
MAX_TAG_LEN = 128
616
MAX_TAGS_PER_OBJ = 4096
617

    
618
# others
619
DEFAULT_BRIDGE = "xen-br0"
620
CLASSIC_DRBD_SYNC_SPEED = 60 * 1024  # 60 MiB, expressed in KiB
621
IP4_ADDRESS_LOCALHOST = "127.0.0.1"
622
IP4_ADDRESS_ANY = "0.0.0.0"
623
IP6_ADDRESS_LOCALHOST = "::1"
624
IP6_ADDRESS_ANY = "::"
625
IP4_VERSION = 4
626
IP6_VERSION = 6
627
VALID_IP_VERSIONS = compat.UniqueFrozenset([IP4_VERSION, IP6_VERSION])
628
# for export to htools
629
IP4_FAMILY = socket.AF_INET
630
IP6_FAMILY = socket.AF_INET6
631

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

    
646
#: Key for job IDs in opcode result
647
JOB_IDS_KEY = "jobs"
648

    
649
# runparts results
650
(RUNPARTS_SKIP,
651
 RUNPARTS_RUN,
652
 RUNPARTS_ERR) = range(3)
653

    
654
RUNPARTS_STATUS = compat.UniqueFrozenset([
655
  RUNPARTS_SKIP,
656
  RUNPARTS_RUN,
657
  RUNPARTS_ERR,
658
  ])
659

    
660
# RPC constants
661
(RPC_ENCODING_NONE,
662
 RPC_ENCODING_ZLIB_BASE64) = range(2)
663

    
664
# Various time constants for the timeout table
665
RPC_TMO_URGENT = 60 # one minute
666
RPC_TMO_FAST = 5 * 60 # five minutes
667
RPC_TMO_NORMAL = 15 * 60 # 15 minutes
668
RPC_TMO_SLOW = 3600 # one hour
669
RPC_TMO_4HRS = 4 * 3600
670
RPC_TMO_1DAY = 86400
671

    
672
# Timeout for connecting to nodes (seconds)
673
RPC_CONNECT_TIMEOUT = 5
674

    
675
# os related constants
676
OS_SCRIPT_CREATE = "create"
677
OS_SCRIPT_IMPORT = "import"
678
OS_SCRIPT_EXPORT = "export"
679
OS_SCRIPT_RENAME = "rename"
680
OS_SCRIPT_VERIFY = "verify"
681
OS_SCRIPTS = compat.UniqueFrozenset([
682
  OS_SCRIPT_CREATE,
683
  OS_SCRIPT_IMPORT,
684
  OS_SCRIPT_EXPORT,
685
  OS_SCRIPT_RENAME,
686
  OS_SCRIPT_VERIFY,
687
  ])
688

    
689
OS_API_FILE = "ganeti_api_version"
690
OS_VARIANTS_FILE = "variants.list"
691
OS_PARAMETERS_FILE = "parameters.list"
692

    
693
OS_VALIDATE_PARAMETERS = "parameters"
694
OS_VALIDATE_CALLS = compat.UniqueFrozenset([OS_VALIDATE_PARAMETERS])
695

    
696
# External Storage (ES) related constants
697
ES_ACTION_CREATE = "create"
698
ES_ACTION_REMOVE = "remove"
699
ES_ACTION_GROW = "grow"
700
ES_ACTION_ATTACH = "attach"
701
ES_ACTION_DETACH = "detach"
702
ES_ACTION_SETINFO = "setinfo"
703
ES_ACTION_VERIFY = "verify"
704

    
705
ES_SCRIPT_CREATE = ES_ACTION_CREATE
706
ES_SCRIPT_REMOVE = ES_ACTION_REMOVE
707
ES_SCRIPT_GROW = ES_ACTION_GROW
708
ES_SCRIPT_ATTACH = ES_ACTION_ATTACH
709
ES_SCRIPT_DETACH = ES_ACTION_DETACH
710
ES_SCRIPT_SETINFO = ES_ACTION_SETINFO
711
ES_SCRIPT_VERIFY = ES_ACTION_VERIFY
712
ES_SCRIPTS = frozenset([
713
  ES_SCRIPT_CREATE,
714
  ES_SCRIPT_REMOVE,
715
  ES_SCRIPT_GROW,
716
  ES_SCRIPT_ATTACH,
717
  ES_SCRIPT_DETACH,
718
  ES_SCRIPT_SETINFO,
719
  ES_SCRIPT_VERIFY
720
  ])
721

    
722
ES_PARAMETERS_FILE = "parameters.list"
723

    
724
# ssh constants
725
SSH = "ssh"
726
SCP = "scp"
727

    
728
# reboot types
729
INSTANCE_REBOOT_SOFT = "soft"
730
INSTANCE_REBOOT_HARD = "hard"
731
INSTANCE_REBOOT_FULL = "full"
732

    
733
REBOOT_TYPES = compat.UniqueFrozenset([
734
  INSTANCE_REBOOT_SOFT,
735
  INSTANCE_REBOOT_HARD,
736
  INSTANCE_REBOOT_FULL,
737
  ])
738

    
739
# instance reboot behaviors
740
INSTANCE_REBOOT_ALLOWED = "reboot"
741
INSTANCE_REBOOT_EXIT = "exit"
742

    
743
REBOOT_BEHAVIORS = compat.UniqueFrozenset([
744
  INSTANCE_REBOOT_ALLOWED,
745
  INSTANCE_REBOOT_EXIT,
746
  ])
747

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

    
761
# Constant representing that the user does not specify any IP version
762
IFACE_NO_IP_VERSION_SPECIFIED = 0
763

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

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

    
854

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

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

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

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

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

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

    
959
# KVM-specific statuses
960
HV_KVM_MIGRATION_VALID_STATUSES = HV_MIGRATION_VALID_STATUSES
961

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1189
OOB_POWER_STATUS_POWERED = "powered"
1190

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1283
VNC_BASE_PORT = 5900
1284
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
1285

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

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

    
1316
# Vif types
1317
# default vif type in xen-hvm
1318
HT_HVM_VIF_IOEMU = "ioemu"
1319
HT_HVM_VIF_VIF = "vif"
1320
HT_HVM_VALID_VIF_TYPES = compat.UniqueFrozenset([
1321
  HT_HVM_VIF_IOEMU,
1322
  HT_HVM_VIF_VIF,
1323
  ])
1324

    
1325
# Disk types
1326
HT_DISK_IOEMU = "ioemu"
1327
HT_DISK_IDE = "ide"
1328
HT_DISK_SCSI = "scsi"
1329
HT_DISK_SD = "sd"
1330
HT_DISK_MTD = "mtd"
1331
HT_DISK_PFLASH = "pflash"
1332

    
1333
HT_CACHE_DEFAULT = "default"
1334
HT_CACHE_NONE = "none"
1335
HT_CACHE_WTHROUGH = "writethrough"
1336
HT_CACHE_WBACK = "writeback"
1337
HT_VALID_CACHE_TYPES = compat.UniqueFrozenset([
1338
  HT_CACHE_DEFAULT,
1339
  HT_CACHE_NONE,
1340
  HT_CACHE_WTHROUGH,
1341
  HT_CACHE_WBACK,
1342
  ])
1343

    
1344
HT_HVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1345
  HT_DISK_PARAVIRTUAL,
1346
  HT_DISK_IOEMU,
1347
  ])
1348
HT_KVM_VALID_DISK_TYPES = compat.UniqueFrozenset([
1349
  HT_DISK_PARAVIRTUAL,
1350
  HT_DISK_IDE,
1351
  HT_DISK_SCSI,
1352
  HT_DISK_SD,
1353
  HT_DISK_MTD,
1354
  HT_DISK_PFLASH,
1355
  ])
1356

    
1357
# Mouse types:
1358
HT_MOUSE_MOUSE = "mouse"
1359
HT_MOUSE_TABLET = "tablet"
1360

    
1361
HT_KVM_VALID_MOUSE_TYPES = compat.UniqueFrozenset([
1362
  HT_MOUSE_MOUSE,
1363
  HT_MOUSE_TABLET,
1364
  ])
1365

    
1366
# Boot order
1367
HT_BO_FLOPPY = "floppy"
1368
HT_BO_CDROM = "cdrom"
1369
HT_BO_DISK = "disk"
1370
HT_BO_NETWORK = "network"
1371

    
1372
HT_KVM_VALID_BO_TYPES = compat.UniqueFrozenset([
1373
  HT_BO_FLOPPY,
1374
  HT_BO_CDROM,
1375
  HT_BO_DISK,
1376
  HT_BO_NETWORK,
1377
  ])
1378

    
1379
# SPICE lossless image compression options
1380
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ = "auto_glz"
1381
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ = "auto_lz"
1382
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC = "quic"
1383
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ = "glz"
1384
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ = "lz"
1385
HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF = "off"
1386

    
1387
HT_KVM_SPICE_VALID_LOSSLESS_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1388
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ,
1389
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ,
1390
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC,
1391
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ,
1392
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ,
1393
  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF,
1394
  ])
1395

    
1396
# SPICE lossy image compression options (valid for both jpeg and zlib-glz)
1397
HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO = "auto"
1398
HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER = "never"
1399
HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS = "always"
1400

    
1401
HT_KVM_SPICE_VALID_LOSSY_IMG_COMPR_OPTIONS = compat.UniqueFrozenset([
1402
  HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO,
1403
  HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER,
1404
  HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS,
1405
  ])
1406

    
1407
# SPICE video stream detection
1408
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF = "off"
1409
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL = "all"
1410
HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER = "filter"
1411

    
1412
HT_KVM_SPICE_VALID_VIDEO_STREAM_DETECTION_OPTIONS = compat.UniqueFrozenset([
1413
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF,
1414
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL,
1415
  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER,
1416
  ])
1417

    
1418
# Security models
1419
HT_SM_NONE = "none"
1420
HT_SM_USER = "user"
1421
HT_SM_POOL = "pool"
1422

    
1423
HT_KVM_VALID_SM_TYPES = compat.UniqueFrozenset([
1424
  HT_SM_NONE,
1425
  HT_SM_USER,
1426
  HT_SM_POOL,
1427
  ])
1428

    
1429
# Kvm flag values
1430
HT_KVM_ENABLED = "enabled"
1431
HT_KVM_DISABLED = "disabled"
1432

    
1433
HT_KVM_FLAG_VALUES = compat.UniqueFrozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
1434

    
1435
# Migration type
1436
HT_MIGRATION_LIVE = "live"
1437
HT_MIGRATION_NONLIVE = "non-live"
1438
HT_MIGRATION_MODES = compat.UniqueFrozenset([
1439
  HT_MIGRATION_LIVE,
1440
  HT_MIGRATION_NONLIVE,
1441
  ])
1442

    
1443
# Cluster Verify steps
1444
VERIFY_NPLUSONE_MEM = "nplusone_mem"
1445
VERIFY_OPTIONAL_CHECKS = compat.UniqueFrozenset([VERIFY_NPLUSONE_MEM])
1446

    
1447
# Cluster Verify error classes
1448
CV_TCLUSTER = "cluster"
1449
CV_TGROUP = "group"
1450
CV_TNODE = "node"
1451
CV_TINSTANCE = "instance"
1452

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

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

    
1570
CV_ALL_ECODES_STRINGS = \
1571
  compat.UniqueFrozenset(estr for (_, estr, _) in CV_ALL_ECODES)
1572

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

    
1598
# Instance status
1599
INSTST_RUNNING = "running"
1600
INSTST_ADMINDOWN = "ADMIN_down"
1601
INSTST_ADMINOFFLINE = "ADMIN_offline"
1602
INSTST_NODEOFFLINE = "ERROR_nodeoffline"
1603
INSTST_NODEDOWN = "ERROR_nodedown"
1604
INSTST_WRONGNODE = "ERROR_wrongnode"
1605
INSTST_ERRORUP = "ERROR_up"
1606
INSTST_ERRORDOWN = "ERROR_down"
1607
INSTST_ALL = compat.UniqueFrozenset([
1608
  INSTST_RUNNING,
1609
  INSTST_ADMINDOWN,
1610
  INSTST_ADMINOFFLINE,
1611
  INSTST_NODEOFFLINE,
1612
  INSTST_NODEDOWN,
1613
  INSTST_WRONGNODE,
1614
  INSTST_ERRORUP,
1615
  INSTST_ERRORDOWN,
1616
  ])
1617

    
1618
# Admin states
1619
ADMINST_UP = "up"
1620
ADMINST_DOWN = "down"
1621
ADMINST_OFFLINE = "offline"
1622
ADMINST_ALL = compat.UniqueFrozenset([
1623
  ADMINST_UP,
1624
  ADMINST_DOWN,
1625
  ADMINST_OFFLINE,
1626
  ])
1627

    
1628
# Node roles
1629
NR_REGULAR = "R"
1630
NR_MASTER = "M"
1631
NR_MCANDIDATE = "C"
1632
NR_DRAINED = "D"
1633
NR_OFFLINE = "O"
1634
NR_ALL = compat.UniqueFrozenset([
1635
  NR_REGULAR,
1636
  NR_MASTER,
1637
  NR_MCANDIDATE,
1638
  NR_DRAINED,
1639
  NR_OFFLINE,
1640
  ])
1641

    
1642
# SSL certificate check constants (in days)
1643
SSL_CERT_EXPIRATION_WARN = 30
1644
SSL_CERT_EXPIRATION_ERROR = 7
1645

    
1646
# Allocator framework constants
1647
IALLOCATOR_VERSION = 2
1648
IALLOCATOR_DIR_IN = "in"
1649
IALLOCATOR_DIR_OUT = "out"
1650
VALID_IALLOCATOR_DIRECTIONS = compat.UniqueFrozenset([
1651
  IALLOCATOR_DIR_IN,
1652
  IALLOCATOR_DIR_OUT,
1653
  ])
1654
IALLOCATOR_MODE_ALLOC = "allocate"
1655
IALLOCATOR_MODE_RELOC = "relocate"
1656
IALLOCATOR_MODE_CHG_GROUP = "change-group"
1657
IALLOCATOR_MODE_NODE_EVAC = "node-evacuate"
1658
IALLOCATOR_MODE_MULTI_ALLOC = "multi-allocate"
1659
VALID_IALLOCATOR_MODES = compat.UniqueFrozenset([
1660
  IALLOCATOR_MODE_ALLOC,
1661
  IALLOCATOR_MODE_RELOC,
1662
  IALLOCATOR_MODE_CHG_GROUP,
1663
  IALLOCATOR_MODE_NODE_EVAC,
1664
  IALLOCATOR_MODE_MULTI_ALLOC,
1665
  ])
1666
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
1667
DEFAULT_IALLOCATOR_SHORTCUT = "."
1668

    
1669
IALLOCATOR_NEVAC_PRI = "primary-only"
1670
IALLOCATOR_NEVAC_SEC = "secondary-only"
1671
IALLOCATOR_NEVAC_ALL = "all"
1672
IALLOCATOR_NEVAC_MODES = compat.UniqueFrozenset([
1673
  IALLOCATOR_NEVAC_PRI,
1674
  IALLOCATOR_NEVAC_SEC,
1675
  IALLOCATOR_NEVAC_ALL,
1676
  ])
1677

    
1678
# Node evacuation
1679
NODE_EVAC_PRI = "primary-only"
1680
NODE_EVAC_SEC = "secondary-only"
1681
NODE_EVAC_ALL = "all"
1682
NODE_EVAC_MODES = compat.UniqueFrozenset([
1683
  NODE_EVAC_PRI,
1684
  NODE_EVAC_SEC,
1685
  NODE_EVAC_ALL,
1686
  ])
1687

    
1688
# Job queue
1689
JOB_QUEUE_VERSION = 1
1690
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
1691
JOB_QUEUE_FILES_PERMS = 0640
1692

    
1693
JOB_ID_TEMPLATE = r"\d+"
1694
JOB_FILE_RE = re.compile(r"^job-(%s)$" % JOB_ID_TEMPLATE)
1695

    
1696
# unchanged job return
1697
JOB_NOTCHANGED = "nochange"
1698

    
1699
# Job status
1700
JOB_STATUS_QUEUED = "queued"
1701
JOB_STATUS_WAITING = "waiting"
1702
JOB_STATUS_CANCELING = "canceling"
1703
JOB_STATUS_RUNNING = "running"
1704
JOB_STATUS_CANCELED = "canceled"
1705
JOB_STATUS_SUCCESS = "success"
1706
JOB_STATUS_ERROR = "error"
1707
JOBS_PENDING = compat.UniqueFrozenset([
1708
  JOB_STATUS_QUEUED,
1709
  JOB_STATUS_WAITING,
1710
  JOB_STATUS_CANCELING,
1711
  ])
1712
JOBS_FINALIZED = compat.UniqueFrozenset([
1713
  JOB_STATUS_CANCELED,
1714
  JOB_STATUS_SUCCESS,
1715
  JOB_STATUS_ERROR,
1716
  ])
1717
JOB_STATUS_ALL = compat.UniqueFrozenset([
1718
  JOB_STATUS_RUNNING,
1719
  ]) | JOBS_PENDING | JOBS_FINALIZED
1720

    
1721
# OpCode status
1722
# not yet finalized
1723
OP_STATUS_QUEUED = "queued"
1724
OP_STATUS_WAITING = "waiting"
1725
OP_STATUS_CANCELING = "canceling"
1726
OP_STATUS_RUNNING = "running"
1727
# finalized
1728
OP_STATUS_CANCELED = "canceled"
1729
OP_STATUS_SUCCESS = "success"
1730
OP_STATUS_ERROR = "error"
1731
OPS_FINALIZED = compat.UniqueFrozenset([
1732
  OP_STATUS_CANCELED,
1733
  OP_STATUS_SUCCESS,
1734
  OP_STATUS_ERROR,
1735
  ])
1736

    
1737
# OpCode priority
1738
OP_PRIO_LOWEST = +19
1739
OP_PRIO_HIGHEST = -20
1740

    
1741
OP_PRIO_LOW = +10
1742
OP_PRIO_NORMAL = 0
1743
OP_PRIO_HIGH = -10
1744

    
1745
OP_PRIO_SUBMIT_VALID = compat.UniqueFrozenset([
1746
  OP_PRIO_LOW,
1747
  OP_PRIO_NORMAL,
1748
  OP_PRIO_HIGH,
1749
  ])
1750

    
1751
OP_PRIO_DEFAULT = OP_PRIO_NORMAL
1752

    
1753
# Lock recalculate mode
1754
LOCKS_REPLACE = "replace"
1755
LOCKS_APPEND = "append"
1756

    
1757
# Lock timeout (sum) before we should go into blocking acquire (still
1758
# can be reset by priority change); computed as max time (10 hours)
1759
# before we should actually go into blocking acquire given that we
1760
# start from default priority level; in seconds
1761
# TODO
1762
LOCK_ATTEMPTS_TIMEOUT = 10 * 3600 / (OP_PRIO_DEFAULT - OP_PRIO_HIGHEST)
1763
LOCK_ATTEMPTS_MAXWAIT = 15.0
1764
LOCK_ATTEMPTS_MINWAIT = 1.0
1765

    
1766
# Execution log types
1767
ELOG_MESSAGE = "message"
1768
ELOG_REMOTE_IMPORT = "remote-import"
1769
ELOG_JQUEUE_TEST = "jqueue-test"
1770

    
1771
# /etc/hosts modification
1772
ETC_HOSTS_ADD = "add"
1773
ETC_HOSTS_REMOVE = "remove"
1774

    
1775
# Job queue test
1776
JQT_MSGPREFIX = "TESTMSG="
1777
JQT_EXPANDNAMES = "expandnames"
1778
JQT_EXEC = "exec"
1779
JQT_LOGMSG = "logmsg"
1780
JQT_STARTMSG = "startmsg"
1781
JQT_ALL = compat.UniqueFrozenset([
1782
  JQT_EXPANDNAMES,
1783
  JQT_EXEC,
1784
  JQT_LOGMSG,
1785
  JQT_STARTMSG,
1786
  ])
1787

    
1788
# Query resources
1789
QR_CLUSTER = "cluster"
1790
QR_INSTANCE = "instance"
1791
QR_NODE = "node"
1792
QR_LOCK = "lock"
1793
QR_GROUP = "group"
1794
QR_OS = "os"
1795
QR_JOB = "job"
1796
QR_EXPORT = "export"
1797
QR_NETWORK = "network"
1798
QR_EXTSTORAGE = "extstorage"
1799

    
1800
#: List of resources which can be queried using L{opcodes.OpQuery}
1801
QR_VIA_OP = compat.UniqueFrozenset([
1802
  QR_CLUSTER,
1803
  QR_INSTANCE,
1804
  QR_NODE,
1805
  QR_GROUP,
1806
  QR_OS,
1807
  QR_EXPORT,
1808
  QR_NETWORK,
1809
  QR_EXTSTORAGE,
1810
  ])
1811

    
1812
#: List of resources which can be queried using Local UniX Interface
1813
QR_VIA_LUXI = QR_VIA_OP.union([
1814
  QR_LOCK,
1815
  QR_JOB,
1816
  ])
1817

    
1818
#: List of resources which can be queried using RAPI
1819
QR_VIA_RAPI = QR_VIA_LUXI
1820

    
1821
# Query field types
1822
QFT_UNKNOWN = "unknown"
1823
QFT_TEXT = "text"
1824
QFT_BOOL = "bool"
1825
QFT_NUMBER = "number"
1826
QFT_UNIT = "unit"
1827
QFT_TIMESTAMP = "timestamp"
1828
QFT_OTHER = "other"
1829

    
1830
#: All query field types
1831
QFT_ALL = compat.UniqueFrozenset([
1832
  QFT_UNKNOWN,
1833
  QFT_TEXT,
1834
  QFT_BOOL,
1835
  QFT_NUMBER,
1836
  QFT_UNIT,
1837
  QFT_TIMESTAMP,
1838
  QFT_OTHER,
1839
  ])
1840

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

    
1856
RS_ALL = compat.UniqueFrozenset([
1857
  RS_NORMAL,
1858
  RS_UNKNOWN,
1859
  RS_NODATA,
1860
  RS_UNAVAIL,
1861
  RS_OFFLINE,
1862
  ])
1863

    
1864
#: Dictionary with special field cases and their verbose/terse formatting
1865
RSS_DESCRIPTION = {
1866
  RS_UNKNOWN: ("(unknown)", "??"),
1867
  RS_NODATA: ("(nodata)", "?"),
1868
  RS_OFFLINE: ("(offline)", "*"),
1869
  RS_UNAVAIL: ("(unavail)", "-"),
1870
  }
1871

    
1872
# max dynamic devices
1873
MAX_NICS = 8
1874
MAX_DISKS = 16
1875

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

    
1903
SS_FILE_PERMS = 0444
1904

    
1905
# cluster wide default parameters
1906
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
1907

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

    
2014
HVC_GLOBALS = compat.UniqueFrozenset([
2015
  HV_MIGRATION_PORT,
2016
  HV_MIGRATION_BANDWIDTH,
2017
  HV_MIGRATION_MODE,
2018
  ])
2019

    
2020
BEC_DEFAULTS = {
2021
  BE_MINMEM: 128,
2022
  BE_MAXMEM: 128,
2023
  BE_VCPUS: 1,
2024
  BE_AUTO_BALANCE: True,
2025
  BE_ALWAYS_FAILOVER: False,
2026
  BE_SPINDLE_USE: 1,
2027
  }
2028

    
2029
NDC_DEFAULTS = {
2030
  ND_OOB_PROGRAM: "",
2031
  ND_SPINDLE_COUNT: 1,
2032
  ND_EXCLUSIVE_STORAGE: False,
2033
  }
2034

    
2035
NDC_GLOBALS = compat.UniqueFrozenset([
2036
  ND_EXCLUSIVE_STORAGE,
2037
  ])
2038

    
2039
DISK_LD_DEFAULTS = {
2040
  LD_DRBD8: {
2041
    LDP_RESYNC_RATE: CLASSIC_DRBD_SYNC_SPEED,
2042
    LDP_BARRIERS: _autoconf.DRBD_BARRIERS,
2043
    LDP_NO_META_FLUSH: _autoconf.DRBD_NO_META_FLUSH,
2044
    LDP_DEFAULT_METAVG: DEFAULT_VG,
2045
    LDP_DISK_CUSTOM: "",
2046
    LDP_NET_CUSTOM: "",
2047
    LDP_DYNAMIC_RESYNC: False,
2048

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

    
2071
# readability shortcuts
2072
_LV_DEFAULTS = DISK_LD_DEFAULTS[LD_LV]
2073
_DRBD_DEFAULTS = DISK_LD_DEFAULTS[LD_DRBD8]
2074

    
2075
DISK_DT_DEFAULTS = {
2076
  DT_PLAIN: {
2077
    LV_STRIPES: DISK_LD_DEFAULTS[LD_LV][LDP_STRIPES],
2078
    },
2079
  DT_DRBD8: {
2080
    DRBD_RESYNC_RATE: _DRBD_DEFAULTS[LDP_RESYNC_RATE],
2081
    DRBD_DATA_STRIPES: _LV_DEFAULTS[LDP_STRIPES],
2082
    DRBD_META_STRIPES: _LV_DEFAULTS[LDP_STRIPES],
2083
    DRBD_DISK_BARRIERS: _DRBD_DEFAULTS[LDP_BARRIERS],
2084
    DRBD_META_BARRIERS: _DRBD_DEFAULTS[LDP_NO_META_FLUSH],
2085
    DRBD_DEFAULT_METAVG: _DRBD_DEFAULTS[LDP_DEFAULT_METAVG],
2086
    DRBD_DISK_CUSTOM: _DRBD_DEFAULTS[LDP_DISK_CUSTOM],
2087
    DRBD_NET_CUSTOM: _DRBD_DEFAULTS[LDP_NET_CUSTOM],
2088
    DRBD_DYNAMIC_RESYNC: _DRBD_DEFAULTS[LDP_DYNAMIC_RESYNC],
2089
    DRBD_PLAN_AHEAD: _DRBD_DEFAULTS[LDP_PLAN_AHEAD],
2090
    DRBD_FILL_TARGET: _DRBD_DEFAULTS[LDP_FILL_TARGET],
2091
    DRBD_DELAY_TARGET: _DRBD_DEFAULTS[LDP_DELAY_TARGET],
2092
    DRBD_MAX_RATE: _DRBD_DEFAULTS[LDP_MAX_RATE],
2093
    DRBD_MIN_RATE: _DRBD_DEFAULTS[LDP_MIN_RATE],
2094
    },
2095
  DT_DISKLESS: {},
2096
  DT_FILE: {},
2097
  DT_SHARED_FILE: {},
2098
  DT_BLOCK: {},
2099
  DT_RBD: {
2100
    RBD_POOL: DISK_LD_DEFAULTS[LD_RBD][LDP_POOL]
2101
    },
2102
  DT_EXT: {},
2103
  }
2104

    
2105
# we don't want to export the shortcuts
2106
del _LV_DEFAULTS, _DRBD_DEFAULTS
2107

    
2108
NICC_DEFAULTS = {
2109
  NIC_MODE: NIC_MODE_BRIDGED,
2110
  NIC_LINK: DEFAULT_BRIDGE,
2111
  }
2112

    
2113
# All of the following values are quite arbitrarily - there are no
2114
# "good" defaults, these must be customised per-site
2115
IPOLICY_DEFAULTS = {
2116
  ISPECS_MIN: {
2117
    ISPEC_MEM_SIZE: 128,
2118
    ISPEC_CPU_COUNT: 1,
2119
    ISPEC_DISK_COUNT: 1,
2120
    ISPEC_DISK_SIZE: 1024,
2121
    ISPEC_NIC_COUNT: 1,
2122
    ISPEC_SPINDLE_USE: 1,
2123
    },
2124
  ISPECS_MAX: {
2125
    ISPEC_MEM_SIZE: 32768,
2126
    ISPEC_CPU_COUNT: 8,
2127
    ISPEC_DISK_COUNT: MAX_DISKS,
2128
    ISPEC_DISK_SIZE: 1024 * 1024,
2129
    ISPEC_NIC_COUNT: MAX_NICS,
2130
    ISPEC_SPINDLE_USE: 12,
2131
    },
2132
  ISPECS_STD: {
2133
    ISPEC_MEM_SIZE: 128,
2134
    ISPEC_CPU_COUNT: 1,
2135
    ISPEC_DISK_COUNT: 1,
2136
    ISPEC_DISK_SIZE: 1024,
2137
    ISPEC_NIC_COUNT: 1,
2138
    ISPEC_SPINDLE_USE: 1,
2139
    },
2140
  IPOLICY_DTS: list(DISK_TEMPLATES),
2141
  IPOLICY_VCPU_RATIO: 4.0,
2142
  IPOLICY_SPINDLE_RATIO: 32.0,
2143
  }
2144

    
2145
MASTER_POOL_SIZE_DEFAULT = 10
2146

    
2147
# Exclusive storage:
2148
# Error margin used to compare physical disks
2149
PART_MARGIN = .01
2150
# Space reserved when creating instance disks
2151
PART_RESERVED = .02
2152

    
2153
CONFD_PROTOCOL_VERSION = 1
2154

    
2155
CONFD_REQ_PING = 0
2156
CONFD_REQ_NODE_ROLE_BYNAME = 1
2157
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
2158
CONFD_REQ_CLUSTER_MASTER = 3
2159
CONFD_REQ_NODE_PIP_LIST = 4
2160
CONFD_REQ_MC_PIP_LIST = 5
2161
CONFD_REQ_INSTANCES_IPS_LIST = 6
2162
CONFD_REQ_NODE_DRBD = 7
2163

    
2164
# Confd request query fields. These are used to narrow down queries.
2165
# These must be strings rather than integers, because json-encoding
2166
# converts them to strings anyway, as they're used as dict-keys.
2167
CONFD_REQQ_LINK = "0"
2168
CONFD_REQQ_IP = "1"
2169
CONFD_REQQ_IPLIST = "2"
2170
CONFD_REQQ_FIELDS = "3"
2171

    
2172
CONFD_REQFIELD_NAME = "0"
2173
CONFD_REQFIELD_IP = "1"
2174
CONFD_REQFIELD_MNODE_PIP = "2"
2175

    
2176
CONFD_REQS = compat.UniqueFrozenset([
2177
  CONFD_REQ_PING,
2178
  CONFD_REQ_NODE_ROLE_BYNAME,
2179
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
2180
  CONFD_REQ_CLUSTER_MASTER,
2181
  CONFD_REQ_NODE_PIP_LIST,
2182
  CONFD_REQ_MC_PIP_LIST,
2183
  CONFD_REQ_INSTANCES_IPS_LIST,
2184
  CONFD_REQ_NODE_DRBD,
2185
  ])
2186

    
2187
CONFD_REPL_STATUS_OK = 0
2188
CONFD_REPL_STATUS_ERROR = 1
2189
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
2190

    
2191
CONFD_REPL_STATUSES = compat.UniqueFrozenset([
2192
  CONFD_REPL_STATUS_OK,
2193
  CONFD_REPL_STATUS_ERROR,
2194
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
2195
  ])
2196

    
2197
(CONFD_NODE_ROLE_MASTER,
2198
 CONFD_NODE_ROLE_CANDIDATE,
2199
 CONFD_NODE_ROLE_OFFLINE,
2200
 CONFD_NODE_ROLE_DRAINED,
2201
 CONFD_NODE_ROLE_REGULAR,
2202
 ) = range(5)
2203

    
2204
# A few common errors for confd
2205
CONFD_ERROR_UNKNOWN_ENTRY = 1
2206
CONFD_ERROR_INTERNAL = 2
2207
CONFD_ERROR_ARGUMENT = 3
2208

    
2209
# Each request is "salted" by the current timestamp.
2210
# This constants decides how many seconds of skew to accept.
2211
# TODO: make this a default and allow the value to be more configurable
2212
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
2213

    
2214
# When we haven't reloaded the config for more than this amount of
2215
# seconds, we force a test to see if inotify is betraying us. Using a
2216
# prime number to ensure we get less chance of 'same wakeup' with
2217
# other processes.
2218
CONFD_CONFIG_RELOAD_TIMEOUT = 17
2219

    
2220
# If we receive more than one update in this amount of microseconds,
2221
# we move to polling every RATELIMIT seconds, rather than relying on
2222
# inotify, to be able to serve more requests.
2223
CONFD_CONFIG_RELOAD_RATELIMIT = 250000
2224

    
2225
# Magic number prepended to all confd queries.
2226
# This allows us to distinguish different types of confd protocols and handle
2227
# them. For example by changing this we can move the whole payload to be
2228
# compressed, or move away from json.
2229
CONFD_MAGIC_FOURCC = "plj0"
2230

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

    
2236
# Timeout in seconds to expire pending query request in the confd client
2237
# library. We don't actually expect any answer more than 10 seconds after we
2238
# sent a request.
2239
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
2240

    
2241
# Maximum UDP datagram size.
2242
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
2243
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
2244
#   (assuming we can't use jumbo frames)
2245
# We just set this to 60K, which should be enough
2246
MAX_UDP_DATA_SIZE = 61440
2247

    
2248
# User-id pool minimum/maximum acceptable user-ids.
2249
UIDPOOL_UID_MIN = 0
2250
UIDPOOL_UID_MAX = 2 ** 32 - 1 # Assuming 32 bit user-ids
2251

    
2252
# Name or path of the pgrep command
2253
PGREP = "pgrep"
2254

    
2255
# Name of the node group that gets created at cluster init or upgrade
2256
INITIAL_NODE_GROUP_NAME = "default"
2257

    
2258
# Possible values for NodeGroup.alloc_policy
2259
ALLOC_POLICY_PREFERRED = "preferred"
2260
ALLOC_POLICY_LAST_RESORT = "last_resort"
2261
ALLOC_POLICY_UNALLOCABLE = "unallocable"
2262
VALID_ALLOC_POLICIES = [
2263
  ALLOC_POLICY_PREFERRED,
2264
  ALLOC_POLICY_LAST_RESORT,
2265
  ALLOC_POLICY_UNALLOCABLE,
2266
  ]
2267

    
2268
# Temporary external/shared storage parameters
2269
BLOCKDEV_DRIVER_MANUAL = "manual"
2270

    
2271
# qemu-img path, required for ovfconverter
2272
QEMUIMG_PATH = _autoconf.QEMUIMG_PATH
2273

    
2274
# Whether htools was enabled at compilation time
2275
HTOOLS = _autoconf.HTOOLS
2276
# The hail iallocator
2277
IALLOC_HAIL = "hail"
2278

    
2279
# Fake opcodes for functions that have hooks attached to them via
2280
# backend.RunLocalHooks
2281
FAKE_OP_MASTER_TURNUP = "OP_CLUSTER_IP_TURNUP"
2282
FAKE_OP_MASTER_TURNDOWN = "OP_CLUSTER_IP_TURNDOWN"
2283

    
2284
# SSH key types
2285
SSHK_RSA = "rsa"
2286
SSHK_DSA = "dsa"
2287
SSHK_ALL = compat.UniqueFrozenset([SSHK_RSA, SSHK_DSA])
2288

    
2289
# SSH authorized key types
2290
SSHAK_RSA = "ssh-rsa"
2291
SSHAK_DSS = "ssh-dss"
2292
SSHAK_ALL = compat.UniqueFrozenset([SSHAK_RSA, SSHAK_DSS])
2293

    
2294
# SSH setup
2295
SSHS_CLUSTER_NAME = "cluster_name"
2296
SSHS_SSH_HOST_KEY = "ssh_host_key"
2297
SSHS_SSH_ROOT_KEY = "ssh_root_key"
2298
SSHS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2299

    
2300
#: Key files for SSH daemon
2301
SSH_DAEMON_KEYFILES = {
2302
  SSHK_RSA: (pathutils.SSH_HOST_RSA_PRIV, pathutils.SSH_HOST_RSA_PUB),
2303
  SSHK_DSA: (pathutils.SSH_HOST_DSA_PRIV, pathutils.SSH_HOST_DSA_PUB),
2304
  }
2305

    
2306
# Node daemon setup
2307
NDS_CLUSTER_NAME = "cluster_name"
2308
NDS_NODE_DAEMON_CERTIFICATE = "node_daemon_certificate"
2309
NDS_SSCONF = "ssconf"
2310
NDS_START_NODE_DAEMON = "start_node_daemon"
2311

    
2312
# Path generating random UUID
2313
RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
2314

    
2315
# Regex string for verifying a UUID
2316
UUID_REGEX = "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
2317

    
2318
# Auto-repair tag prefixes
2319
AUTO_REPAIR_TAG_PREFIX = "ganeti:watcher:autorepair:"
2320
AUTO_REPAIR_TAG_ENABLED = AUTO_REPAIR_TAG_PREFIX
2321
AUTO_REPAIR_TAG_SUSPENDED = AUTO_REPAIR_TAG_ENABLED + "suspend:"
2322
AUTO_REPAIR_TAG_PENDING = AUTO_REPAIR_TAG_PREFIX + "pending:"
2323
AUTO_REPAIR_TAG_RESULT = AUTO_REPAIR_TAG_PREFIX + "result:"
2324

    
2325
# Auto-repair levels
2326
AUTO_REPAIR_FIX_STORAGE = "fix-storage"
2327
AUTO_REPAIR_MIGRATE = "migrate"
2328
AUTO_REPAIR_FAILOVER = "failover"
2329
AUTO_REPAIR_REINSTALL = "reinstall"
2330
AUTO_REPAIR_ALL_TYPES = [
2331
  AUTO_REPAIR_FIX_STORAGE,
2332
  AUTO_REPAIR_MIGRATE,
2333
  AUTO_REPAIR_FAILOVER,
2334
  AUTO_REPAIR_REINSTALL,
2335
]
2336

    
2337
# Auto-repair results
2338
AUTO_REPAIR_SUCCESS = "success"
2339
AUTO_REPAIR_FAILURE = "failure"
2340
AUTO_REPAIR_ENOPERM = "enoperm"
2341
AUTO_REPAIR_ALL_RESULTS = frozenset([
2342
    AUTO_REPAIR_SUCCESS,
2343
    AUTO_REPAIR_FAILURE,
2344
    AUTO_REPAIR_ENOPERM,
2345
])
2346

    
2347
# The version identifier for builtin data collectors
2348
BUILTIN_DATA_COLLECTOR_VERSION = "B"
2349

    
2350
# Do not re-export imported modules
2351
del re, _vcsversion, _autoconf, socket, pathutils, compat