Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ 2abc8f57

History | View | Annotate | Download (34.9 kB)

1
#
2
#
3

    
4
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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

    
26
from ganeti import _autoconf
27

    
28
# various versions
29
RELEASE_VERSION = _autoconf.PACKAGE_VERSION
30
OS_API_V10 = 10
31
OS_API_V15 = 15
32
OS_API_V20 = 20
33
OS_API_VERSIONS = frozenset([OS_API_V10, OS_API_V15, OS_API_V20])
34
VCS_VERSION = _autoconf.VCS_VERSION
35
EXPORT_VERSION = 0
36
RAPI_VERSION = 2
37

    
38

    
39
# Format for CONFIG_VERSION:
40
#   01 03 0123 = 01030123
41
#   ^^ ^^ ^^^^
42
#   |  |  + Configuration version/revision
43
#   |  + Minor version
44
#   + Major version
45
#
46
# It stored as an integer. Make sure not to write an octal number.
47

    
48
# BuildVersion and SplitVersion must be in here because we can't import other
49
# modules. The cfgupgrade tool must be able to read and write version numbers
50
# and thus requires these functions. To avoid code duplication, they're kept in
51
# here.
52

    
53
def BuildVersion(major, minor, revision):
54
  """Calculates int version number from major, minor and revision numbers.
55

56
  Returns: int representing version number
57

58
  """
59
  assert isinstance(major, int)
60
  assert isinstance(minor, int)
61
  assert isinstance(revision, int)
62
  return (1000000 * major +
63
            10000 * minor +
64
                1 * revision)
65

    
66

    
67
def SplitVersion(version):
68
  """Splits version number stored in an int.
69

70
  Returns: tuple; (major, minor, revision)
71

72
  """
73
  assert isinstance(version, int)
74

    
75
  (major, remainder) = divmod(version, 1000000)
76
  (minor, revision) = divmod(remainder, 10000)
77

    
78
  return (major, minor, revision)
79

    
80

    
81
CONFIG_MAJOR = int(_autoconf.VERSION_MAJOR)
82
CONFIG_MINOR = int(_autoconf.VERSION_MINOR)
83
CONFIG_REVISION = 0
84
CONFIG_VERSION = BuildVersion(CONFIG_MAJOR, CONFIG_MINOR, CONFIG_REVISION)
85

    
86
#: RPC protocol version
87
PROTOCOL_VERSION = BuildVersion(CONFIG_MAJOR, CONFIG_MINOR, 0)
88

    
89
# user separation
90
DAEMONS_GROUP = _autoconf.DAEMONS_GROUP
91
ADMIN_GROUP = _autoconf.ADMIN_GROUP
92
MASTERD_USER = _autoconf.MASTERD_USER
93
MASTERD_GROUP = _autoconf.MASTERD_GROUP
94
RAPI_USER = _autoconf.RAPI_USER
95
RAPI_GROUP = _autoconf.RAPI_GROUP
96
CONFD_USER = _autoconf.CONFD_USER
97
CONFD_GROUP = _autoconf.CONFD_GROUP
98
NODED_USER = _autoconf.NODED_USER
99

    
100

    
101
# Wipe
102
DD_CMD = "dd"
103
WIPE_BLOCK_SIZE = 1024**2
104
MAX_WIPE_CHUNK = 1024 # 1GB
105
MIN_WIPE_CHUNK_PERCENT = 10
106

    
107

    
108
# file paths
109
DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti"
110
RUN_DIR = _autoconf.LOCALSTATEDIR + "/run"
111
RUN_GANETI_DIR = RUN_DIR + "/ganeti"
112
BDEV_CACHE_DIR = RUN_GANETI_DIR + "/bdev-cache"
113
DISK_LINKS_DIR = RUN_GANETI_DIR + "/instance-disks"
114
RUN_DIRS_MODE = 0775
115
SOCKET_DIR = RUN_GANETI_DIR + "/socket"
116
SECURE_DIR_MODE = 0700
117
SECURE_FILE_MODE = 0600
118
SOCKET_DIR_MODE = 0750
119
CRYPTO_KEYS_DIR = RUN_GANETI_DIR + "/crypto"
120
CRYPTO_KEYS_DIR_MODE = SECURE_DIR_MODE
121
IMPORT_EXPORT_DIR = RUN_GANETI_DIR + "/import-export"
122
IMPORT_EXPORT_DIR_MODE = 0755
123
ADOPTABLE_BLOCKDEV_ROOT = "/dev/disk/"
124
# keep RUN_GANETI_DIR first here, to make sure all get created when the node
125
# daemon is started (this takes care of RUN_DIR being tmpfs)
126
SUB_RUN_DIRS = [ RUN_GANETI_DIR, BDEV_CACHE_DIR, DISK_LINKS_DIR ]
127
LOCK_DIR = _autoconf.LOCALSTATEDIR + "/lock"
128
SSCONF_LOCK_FILE = LOCK_DIR + "/ganeti-ssconf.lock"
129
# User-id pool lock directory
130
# The user-ids that are in use have a corresponding lock file in this directory
131
UIDPOOL_LOCKDIR = RUN_GANETI_DIR + "/uid-pool"
132
CLUSTER_CONF_FILE = DATA_DIR + "/config.data"
133
NODED_CERT_FILE = DATA_DIR + "/server.pem"
134
RAPI_CERT_FILE = DATA_DIR + "/rapi.pem"
135
CONFD_HMAC_KEY = DATA_DIR + "/hmac.key"
136
CLUSTER_DOMAIN_SECRET_FILE = DATA_DIR + "/cluster-domain-secret"
137
WATCHER_STATEFILE = DATA_DIR + "/watcher.data"
138
WATCHER_PAUSEFILE = DATA_DIR + "/watcher.pause"
139
INSTANCE_UPFILE = RUN_GANETI_DIR + "/instance-status"
140
SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
141
RAPI_USERS_FILE = DATA_DIR + "/rapi/users"
142
QUEUE_DIR = DATA_DIR + "/queue"
143
DAEMON_UTIL = _autoconf.PKGLIBDIR + "/daemon-util"
144
SETUP_SSH = _autoconf.TOOLSDIR + "/setup-ssh"
145
KVM_IFUP = _autoconf.PKGLIBDIR + "/kvm-ifup"
146
ETC_HOSTS = "/etc/hosts"
147
DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
148
DEFAULT_SHARED_FILE_STORAGE_DIR = _autoconf.SHARED_FILE_STORAGE_DIR
149
ENABLE_FILE_STORAGE = _autoconf.ENABLE_FILE_STORAGE
150
ENABLE_SHARED_FILE_STORAGE = _autoconf.ENABLE_SHARED_FILE_STORAGE
151
SYSCONFDIR = _autoconf.SYSCONFDIR
152
TOOLSDIR = _autoconf.TOOLSDIR
153
CONF_DIR = SYSCONFDIR + "/ganeti"
154

    
155
ALL_CERT_FILES = frozenset([NODED_CERT_FILE, RAPI_CERT_FILE])
156

    
157
MASTER_SOCKET = SOCKET_DIR + "/ganeti-master"
158

    
159
NODED = "ganeti-noded"
160
CONFD = "ganeti-confd"
161
RAPI = "ganeti-rapi"
162
MASTERD = "ganeti-masterd"
163
# used in the ganeti-nbma project
164
NLD = "ganeti-nld"
165

    
166
DAEMONS_PORTS = {
167
  # daemon-name: ("proto", "default-port")
168
  NODED: ("tcp", 1811),
169
  CONFD: ("udp", 1814),
170
  RAPI: ("tcp", 5080),
171
  "ssh": ("tcp", 22),
172
  # used in the ganeti-nbma project
173
  NLD: ("udp", 1816),
174
}
175
DEFAULT_NODED_PORT = DAEMONS_PORTS[NODED][1]
176
DEFAULT_CONFD_PORT = DAEMONS_PORTS[CONFD][1]
177
DEFAULT_RAPI_PORT = DAEMONS_PORTS[RAPI][1]
178
# used in the ganeti-nbma project
179
DEFAULT_NLD_PORT = DAEMONS_PORTS[NLD][1]
180

    
181
FIRST_DRBD_PORT = 11000
182
LAST_DRBD_PORT = 14999
183
MASTER_SCRIPT = "ganeti-master"
184

    
185
LOG_DIR = _autoconf.LOCALSTATEDIR + "/log/ganeti/"
186
DAEMONS_LOGFILES = {
187
  # "daemon-name": "logfile"
188
  NODED: LOG_DIR + "node-daemon.log",
189
  CONFD: LOG_DIR + "conf-daemon.log",
190
  RAPI: LOG_DIR + "rapi-daemon.log",
191
  MASTERD: LOG_DIR + "master-daemon.log",
192
  # used in the ganeti-nbma project
193
  NLD: LOG_DIR + "nl-daemon.log",
194
  }
195

    
196
LOG_OS_DIR = LOG_DIR + "os"
197
LOG_WATCHER = LOG_DIR + "watcher.log"
198
LOG_COMMANDS = LOG_DIR + "commands.log"
199
LOG_BURNIN = LOG_DIR + "burnin.log"
200
LOG_SETUP_SSH = LOG_DIR + "setup-ssh.log"
201

    
202
DEV_CONSOLE = "/dev/console"
203

    
204
PROC_MOUNTS = "/proc/mounts"
205

    
206
# Local UniX Interface related constants
207
LUXI_EOM = "\3"
208
LUXI_VERSION = CONFIG_VERSION
209

    
210
# one of 'no', 'yes', 'only'
211
SYSLOG_USAGE = _autoconf.SYSLOG_USAGE
212
SYSLOG_NO = "no"
213
SYSLOG_YES = "yes"
214
SYSLOG_ONLY = "only"
215
SYSLOG_SOCKET = "/dev/log"
216

    
217
OS_SEARCH_PATH = _autoconf.OS_SEARCH_PATH
218
EXPORT_DIR = _autoconf.EXPORT_DIR
219

    
220
EXPORT_CONF_FILE = "config.ini"
221

    
222
XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER
223
XEN_KERNEL = _autoconf.XEN_KERNEL
224
XEN_INITRD = _autoconf.XEN_INITRD
225

    
226
KVM_PATH = _autoconf.KVM_PATH
227
SOCAT_PATH = _autoconf.SOCAT_PATH
228
SOCAT_USE_ESCAPE = _autoconf.SOCAT_USE_ESCAPE
229
SOCAT_USE_COMPRESS = _autoconf.SOCAT_USE_COMPRESS
230
SOCAT_ESCAPE_CODE = "0x1d"
231

    
232
#: Console as SSH command
233
CONS_SSH = "ssh"
234

    
235
#: Console as VNC server
236
CONS_VNC = "vnc"
237

    
238
#: Display a message for console access
239
CONS_MESSAGE = "msg"
240

    
241
#: All console types
242
CONS_ALL = frozenset([CONS_SSH, CONS_VNC, CONS_MESSAGE])
243

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

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

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

    
260
# Default validity of certificates in days
261
X509_CERT_DEFAULT_VALIDITY = 365 * 5
262

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

    
266
X509_CERT_SIGNATURE_HEADER = "X-Ganeti-Signature"
267

    
268
IMPORT_EXPORT_DAEMON = _autoconf.PKGLIBDIR + "/import-export"
269

    
270
# Import/export daemon mode
271
IEM_IMPORT = "import"
272
IEM_EXPORT = "export"
273

    
274
# Import/export transport compression
275
IEC_NONE = "none"
276
IEC_GZIP = "gzip"
277
IEC_ALL = frozenset([
278
  IEC_NONE,
279
  IEC_GZIP,
280
  ])
281

    
282
IE_CUSTOM_SIZE = "fd"
283

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

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

    
294
VALUE_DEFAULT = "default"
295
VALUE_AUTO = "auto"
296
VALUE_GENERATE = "generate"
297
VALUE_NONE = "none"
298
VALUE_TRUE = "true"
299
VALUE_FALSE = "false"
300

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

    
304
# hooks-related constants
305
HOOKS_BASE_DIR = CONF_DIR + "/hooks"
306
HOOKS_PHASE_PRE = "pre"
307
HOOKS_PHASE_POST = "post"
308
HOOKS_NAME_CFGUPDATE = "config-update"
309
HOOKS_NAME_WATCHER = "watcher"
310
HOOKS_VERSION = 2
311

    
312
# hooks subject type (what object type does the LU deal with)
313
HTYPE_CLUSTER = "CLUSTER"
314
HTYPE_NODE = "NODE"
315
HTYPE_GROUP = "GROUP"
316
HTYPE_INSTANCE = "INSTANCE"
317

    
318
HKR_SKIP = 0
319
HKR_FAIL = 1
320
HKR_SUCCESS = 2
321

    
322
# Storage types
323
ST_FILE = "file"
324
ST_LVM_PV = "lvm-pv"
325
ST_LVM_VG = "lvm-vg"
326

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

    
338
# Storage operations
339
SO_FIX_CONSISTENCY = "fix-consistency"
340

    
341
# Available fields per storage type
342
VALID_STORAGE_FIELDS = frozenset([SF_NAME, SF_TYPE, SF_SIZE,
343
                                  SF_USED, SF_FREE, SF_ALLOCATABLE])
344

    
345
VALID_STORAGE_TYPES = frozenset([ST_FILE, ST_LVM_PV, ST_LVM_VG])
346

    
347
MODIFIABLE_STORAGE_FIELDS = {
348
  ST_LVM_PV: frozenset([SF_ALLOCATABLE]),
349
  }
350

    
351
VALID_STORAGE_OPERATIONS = {
352
  ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
353
  }
354

    
355
# Local disk status
356
# Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
357
(LDS_OKAY,
358
 LDS_UNKNOWN,
359
 LDS_FAULTY) = range(1, 4)
360

    
361
# disk template types
362
DT_DISKLESS = "diskless"
363
DT_PLAIN = "plain"
364
DT_DRBD8 = "drbd"
365
DT_FILE = "file"
366
DT_SHARED_FILE = "sharedfile"
367
DT_BLOCK = "blockdev"
368

    
369
# the set of network-mirrored disk templates
370
DTS_INT_MIRROR = frozenset([DT_DRBD8])
371

    
372
# the set of externally-mirrored disk templates (e.g. SAN, NAS)
373
DTS_EXT_MIRROR = frozenset([DT_SHARED_FILE, DT_BLOCK])
374

    
375
# the set of non-lvm-based disk templates
376
DTS_NOT_LVM = frozenset([DT_DISKLESS, DT_FILE, DT_SHARED_FILE, DT_BLOCK])
377

    
378
# the set of disk templates which can be grown
379
DTS_GROWABLE = frozenset([DT_PLAIN, DT_DRBD8, DT_FILE, DT_SHARED_FILE])
380

    
381
# the set of disk templates that allow adoption
382
DTS_MAY_ADOPT = frozenset([DT_PLAIN, DT_BLOCK])
383

    
384
# the set of disk templates that *must* use adoption
385
DTS_MUST_ADOPT = frozenset([DT_BLOCK])
386

    
387
# the set of disk templates that allow migrations
388
DTS_MIRRORED = frozenset.union(DTS_INT_MIRROR, DTS_EXT_MIRROR)
389

    
390

    
391
# logical disk types
392
LD_LV = "lvm"
393
LD_DRBD8 = "drbd8"
394
LD_FILE = "file"
395
LD_BLOCKDEV = "blockdev"
396
LDS_BLOCK = frozenset([LD_LV, LD_DRBD8, LD_BLOCKDEV])
397

    
398
# drbd constants
399
DRBD_HMAC_ALG = "md5"
400
DRBD_NET_PROTOCOL = "C"
401
DRBD_BARRIERS = _autoconf.DRBD_BARRIERS
402

    
403
# file backend driver
404
FD_LOOP = "loop"
405
FD_BLKTAP = "blktap"
406

    
407
# the set of drbd-like disk types
408
LDS_DRBD = frozenset([LD_DRBD8])
409

    
410
# disk access mode
411
DISK_RDONLY = "ro"
412
DISK_RDWR = "rw"
413
DISK_ACCESS_SET = frozenset([DISK_RDONLY, DISK_RDWR])
414

    
415
# disk replacement mode
416
REPLACE_DISK_PRI = "replace_on_primary"    # replace disks on primary
417
REPLACE_DISK_SEC = "replace_on_secondary"  # replace disks on secondary
418
REPLACE_DISK_CHG = "replace_new_secondary" # change secondary node
419
REPLACE_DISK_AUTO = "replace_auto"
420
REPLACE_MODES = frozenset([
421
  REPLACE_DISK_PRI,
422
  REPLACE_DISK_SEC,
423
  REPLACE_DISK_CHG,
424
  REPLACE_DISK_AUTO,
425
  ])
426

    
427
# Instance export mode
428
EXPORT_MODE_LOCAL = "local"
429
EXPORT_MODE_REMOTE = "remote"
430
EXPORT_MODES = frozenset([
431
  EXPORT_MODE_LOCAL,
432
  EXPORT_MODE_REMOTE,
433
  ])
434

    
435
# Lock recalculate mode
436
LOCKS_REPLACE = 'replace'
437
LOCKS_APPEND = 'append'
438

    
439
# Lock timeout (sum) before we should go into blocking acquire (still
440
# can be reset by priority change); computed as max time (10 hours)
441
# before we should actually go into blocking acquire given that we
442
# start from default priority level; in seconds
443
LOCK_ATTEMPTS_TIMEOUT = 10 * 3600 / 20.0
444
LOCK_ATTEMPTS_MAXWAIT = 15.0
445
LOCK_ATTEMPTS_MINWAIT = 1.0
446

    
447
# instance creation modes
448
INSTANCE_CREATE = "create"
449
INSTANCE_IMPORT = "import"
450
INSTANCE_REMOTE_IMPORT = "remote-import"
451
INSTANCE_CREATE_MODES = frozenset([
452
  INSTANCE_CREATE,
453
  INSTANCE_IMPORT,
454
  INSTANCE_REMOTE_IMPORT,
455
  ])
456

    
457
# Remote import/export handshake message and version
458
RIE_VERSION = 0
459
RIE_HANDSHAKE = "Hi, I'm Ganeti"
460

    
461
# Remote import/export certificate validity in seconds
462
RIE_CERT_VALIDITY = 24 * 60 * 60
463

    
464
# Overall timeout for establishing connection
465
RIE_CONNECT_TIMEOUT = 180
466

    
467
# Export only: how long to wait per connection attempt (seconds)
468
RIE_CONNECT_ATTEMPT_TIMEOUT = 20
469

    
470
# Export only: number of attempts to connect
471
RIE_CONNECT_RETRIES = 10
472

    
473
#: Give child process up to 5 seconds to exit after sending a signal
474
CHILD_LINGER_TIMEOUT = 5.0
475

    
476
DISK_TEMPLATES = frozenset([DT_DISKLESS, DT_PLAIN, DT_DRBD8,
477
                            DT_FILE, DT_SHARED_FILE, DT_BLOCK])
478

    
479
FILE_DRIVER = frozenset([FD_LOOP, FD_BLKTAP])
480

    
481
# import/export config options
482
INISECT_EXP = "export"
483
INISECT_INS = "instance"
484
INISECT_HYP = "hypervisor"
485
INISECT_BEP = "backend"
486
INISECT_OSP = "os"
487

    
488
# dynamic device modification
489
DDM_ADD = "add"
490
DDM_REMOVE = "remove"
491
DDMS_VALUES = frozenset([DDM_ADD, DDM_REMOVE])
492

    
493
# common exit codes
494
EXIT_SUCCESS = 0
495
EXIT_FAILURE = 1
496
EXIT_NOTCLUSTER = 5
497
EXIT_NOTMASTER = 11
498
EXIT_NODESETUP_ERROR = 12
499
EXIT_CONFIRMATION = 13 # need user confirmation
500

    
501
#: Exit code for query operations with unknown fields
502
EXIT_UNKNOWN_FIELD = 14
503

    
504
# tags
505
TAG_CLUSTER = "cluster"
506
TAG_NODE = "node"
507
TAG_INSTANCE = "instance"
508
VALID_TAG_TYPES = frozenset([
509
  TAG_CLUSTER,
510
  TAG_NODE,
511
  TAG_INSTANCE,
512
  ])
513
MAX_TAG_LEN = 128
514
MAX_TAGS_PER_OBJ = 4096
515

    
516
# others
517
DEFAULT_BRIDGE = "xen-br0"
518
SYNC_SPEED = 60 * 1024
519
IP4_ADDRESS_LOCALHOST = "127.0.0.1"
520
IP4_ADDRESS_ANY = "0.0.0.0"
521
IP6_ADDRESS_LOCALHOST = "::1"
522
IP6_ADDRESS_ANY = "::"
523
IP4_VERSION = 4
524
IP6_VERSION = 6
525
TCP_PING_TIMEOUT = 10
526
GANETI_RUNAS = "root"
527
DEFAULT_VG = "xenvg"
528
DEFAULT_DRBD_HELPER = "/bin/true"
529
MIN_VG_SIZE = 20480
530
DEFAULT_MAC_PREFIX = "aa:00:00"
531
LVM_STRIPECOUNT = _autoconf.LVM_STRIPECOUNT
532
# default maximum instance wait time, in seconds.
533
DEFAULT_SHUTDOWN_TIMEOUT = 120
534
NODE_MAX_CLOCK_SKEW = 150
535
# Time for an intra-cluster disk transfer to wait for a connection
536
DISK_TRANSFER_CONNECT_TIMEOUT = 60
537
# Disk index separator
538
DISK_SEPARATOR = _autoconf.DISK_SEPARATOR
539

    
540
# runparts results
541
(RUNPARTS_SKIP,
542
 RUNPARTS_RUN,
543
 RUNPARTS_ERR) = range(3)
544

    
545
RUNPARTS_STATUS = frozenset([RUNPARTS_SKIP, RUNPARTS_RUN, RUNPARTS_ERR])
546

    
547
# RPC constants
548
(RPC_ENCODING_NONE,
549
 RPC_ENCODING_ZLIB_BASE64) = range(2)
550

    
551
# os related constants
552
OS_SCRIPT_CREATE = 'create'
553
OS_SCRIPT_IMPORT = 'import'
554
OS_SCRIPT_EXPORT = 'export'
555
OS_SCRIPT_RENAME = 'rename'
556
OS_SCRIPT_VERIFY = 'verify'
557
OS_SCRIPTS = frozenset([OS_SCRIPT_CREATE, OS_SCRIPT_IMPORT,
558
                        OS_SCRIPT_EXPORT, OS_SCRIPT_RENAME,
559
                        OS_SCRIPT_VERIFY])
560

    
561
OS_API_FILE = 'ganeti_api_version'
562
OS_VARIANTS_FILE = 'variants.list'
563
OS_PARAMETERS_FILE = 'parameters.list'
564

    
565
OS_VALIDATE_PARAMETERS = 'parameters'
566
OS_VALIDATE_CALLS = frozenset([OS_VALIDATE_PARAMETERS])
567

    
568
# ssh constants
569
SSH_CONFIG_DIR = _autoconf.SSH_CONFIG_DIR
570
SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_dsa_key"
571
SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
572
SSH_HOST_RSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_rsa_key"
573
SSH_HOST_RSA_PUB = SSH_HOST_RSA_PRIV + ".pub"
574
SSH = "ssh"
575
SCP = "scp"
576

    
577
# reboot types
578
INSTANCE_REBOOT_SOFT = "soft"
579
INSTANCE_REBOOT_HARD = "hard"
580
INSTANCE_REBOOT_FULL = "full"
581

    
582
REBOOT_TYPES = frozenset([INSTANCE_REBOOT_SOFT,
583
                          INSTANCE_REBOOT_HARD,
584
                          INSTANCE_REBOOT_FULL])
585

    
586
VTYPE_STRING = 'string'
587
VTYPE_MAYBE_STRING = "maybe-string"
588
VTYPE_BOOL = 'bool'
589
VTYPE_SIZE = 'size' # size, in MiBs
590
VTYPE_INT = 'int'
591
ENFORCEABLE_TYPES = frozenset([
592
                      VTYPE_STRING,
593
                      VTYPE_MAYBE_STRING,
594
                      VTYPE_BOOL,
595
                      VTYPE_SIZE,
596
                      VTYPE_INT,
597
                      ])
598

    
599
# HV parameter names (global namespace)
600
HV_BOOT_ORDER = "boot_order"
601
HV_CDROM_IMAGE_PATH = "cdrom_image_path"
602
HV_KVM_CDROM2_IMAGE_PATH = "cdrom2_image_path"
603
HV_KVM_FLOPPY_IMAGE_PATH = "floppy_image_path"
604
HV_NIC_TYPE = "nic_type"
605
HV_DISK_TYPE = "disk_type"
606
HV_KVM_CDROM_DISK_TYPE = "cdrom_disk_type"
607
HV_VNC_BIND_ADDRESS = "vnc_bind_address"
608
HV_VNC_PASSWORD_FILE = "vnc_password_file"
609
HV_VNC_TLS = "vnc_tls"
610
HV_VNC_X509 = "vnc_x509_path"
611
HV_VNC_X509_VERIFY = "vnc_x509_verify"
612
HV_ACPI = "acpi"
613
HV_PAE = "pae"
614
HV_USE_BOOTLOADER = "use_bootloader"
615
HV_BOOTLOADER_ARGS = "bootloader_args"
616
HV_BOOTLOADER_PATH = "bootloader_path"
617
HV_KERNEL_ARGS = "kernel_args"
618
HV_KERNEL_PATH = "kernel_path"
619
HV_INITRD_PATH = "initrd_path"
620
HV_ROOT_PATH = "root_path"
621
HV_SERIAL_CONSOLE = "serial_console"
622
HV_USB_MOUSE = "usb_mouse"
623
HV_DEVICE_MODEL = "device_model"
624
HV_INIT_SCRIPT = "init_script"
625
HV_MIGRATION_PORT = "migration_port"
626
HV_MIGRATION_BANDWIDTH = "migration_bandwidth"
627
HV_MIGRATION_DOWNTIME = "migration_downtime"
628
HV_MIGRATION_MODE = "migration_mode"
629
HV_USE_LOCALTIME = "use_localtime"
630
HV_DISK_CACHE = "disk_cache"
631
HV_SECURITY_MODEL = "security_model"
632
HV_SECURITY_DOMAIN = "security_domain"
633
HV_KVM_FLAG = "kvm_flag"
634
HV_VHOST_NET = "vhost_net"
635
HV_KVM_USE_CHROOT = "use_chroot"
636
HV_CPU_MASK = "cpu_mask"
637
HV_MEM_PATH = "mem_path"
638
HV_BLOCKDEV_PREFIX = "blockdev_prefix"
639

    
640
HVS_PARAMETER_TYPES = {
641
  HV_BOOT_ORDER: VTYPE_STRING,
642
  HV_KVM_FLOPPY_IMAGE_PATH: VTYPE_STRING,
643
  HV_CDROM_IMAGE_PATH: VTYPE_STRING,
644
  HV_KVM_CDROM2_IMAGE_PATH: VTYPE_STRING,
645
  HV_NIC_TYPE: VTYPE_STRING,
646
  HV_DISK_TYPE: VTYPE_STRING,
647
  HV_KVM_CDROM_DISK_TYPE: VTYPE_STRING,
648
  HV_VNC_PASSWORD_FILE: VTYPE_STRING,
649
  HV_VNC_BIND_ADDRESS: VTYPE_STRING,
650
  HV_VNC_TLS: VTYPE_BOOL,
651
  HV_VNC_X509: VTYPE_STRING,
652
  HV_VNC_X509_VERIFY: VTYPE_BOOL,
653
  HV_ACPI: VTYPE_BOOL,
654
  HV_PAE: VTYPE_BOOL,
655
  HV_USE_BOOTLOADER: VTYPE_BOOL,
656
  HV_BOOTLOADER_PATH: VTYPE_STRING,
657
  HV_BOOTLOADER_ARGS: VTYPE_STRING,
658
  HV_KERNEL_PATH: VTYPE_STRING,
659
  HV_KERNEL_ARGS: VTYPE_STRING,
660
  HV_INITRD_PATH: VTYPE_STRING,
661
  HV_ROOT_PATH: VTYPE_MAYBE_STRING,
662
  HV_SERIAL_CONSOLE: VTYPE_BOOL,
663
  HV_USB_MOUSE: VTYPE_STRING,
664
  HV_DEVICE_MODEL: VTYPE_STRING,
665
  HV_INIT_SCRIPT: VTYPE_STRING,
666
  HV_MIGRATION_PORT: VTYPE_INT,
667
  HV_MIGRATION_BANDWIDTH: VTYPE_INT,
668
  HV_MIGRATION_DOWNTIME: VTYPE_INT,
669
  HV_MIGRATION_MODE: VTYPE_STRING,
670
  HV_USE_LOCALTIME: VTYPE_BOOL,
671
  HV_DISK_CACHE: VTYPE_STRING,
672
  HV_SECURITY_MODEL: VTYPE_STRING,
673
  HV_SECURITY_DOMAIN: VTYPE_STRING,
674
  HV_KVM_FLAG: VTYPE_STRING,
675
  HV_VHOST_NET: VTYPE_BOOL,
676
  HV_KVM_USE_CHROOT: VTYPE_BOOL,
677
  HV_CPU_MASK: VTYPE_STRING,
678
  HV_MEM_PATH: VTYPE_STRING,
679
  HV_BLOCKDEV_PREFIX: VTYPE_STRING,
680
  }
681

    
682
HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
683

    
684
# Backend parameter names
685
BE_MEMORY = "memory"
686
BE_VCPUS = "vcpus"
687
BE_AUTO_BALANCE = "auto_balance"
688

    
689
BES_PARAMETER_TYPES = {
690
    BE_MEMORY: VTYPE_SIZE,
691
    BE_VCPUS: VTYPE_INT,
692
    BE_AUTO_BALANCE: VTYPE_BOOL,
693
    }
694

    
695
BES_PARAMETERS = frozenset(BES_PARAMETER_TYPES.keys())
696

    
697
# Node parameter names
698
ND_OOB_PROGRAM = "oob_program"
699

    
700
NDS_PARAMETER_TYPES = {
701
    ND_OOB_PROGRAM: VTYPE_MAYBE_STRING,
702
    }
703

    
704
NDS_PARAMETERS = frozenset(NDS_PARAMETER_TYPES.keys())
705

    
706
# OOB supported commands
707
OOB_POWER_ON = "power-on"
708
OOB_POWER_OFF = "power-off"
709
OOB_POWER_CYCLE = "power-cycle"
710
OOB_POWER_STATUS = "power-status"
711
OOB_HEALTH = "health"
712

    
713
OOB_COMMANDS = frozenset([OOB_POWER_ON, OOB_POWER_OFF, OOB_POWER_CYCLE,
714
                          OOB_POWER_STATUS, OOB_HEALTH])
715

    
716
OOB_POWER_STATUS_POWERED = "powered"
717

    
718
OOB_TIMEOUT = 60 # 60 seconds
719

    
720
OOB_STATUS_OK = "OK"
721
OOB_STATUS_WARNING = "WARNING"
722
OOB_STATUS_CRITICAL = "CRITICAL"
723
OOB_STATUS_UNKNOWN = "UNKNOWN"
724

    
725
OOB_STATUSES = frozenset([
726
  OOB_STATUS_OK,
727
  OOB_STATUS_WARNING,
728
  OOB_STATUS_CRITICAL,
729
  OOB_STATUS_UNKNOWN,
730
  ])
731

    
732
# Instance Parameters Profile
733
PP_DEFAULT = "default"
734

    
735
NIC_MODE = "mode"
736
NIC_LINK = "link"
737

    
738
NIC_MODE_BRIDGED = "bridged"
739
NIC_MODE_ROUTED = "routed"
740

    
741
NIC_IP_POOL = "pool"
742

    
743
NIC_VALID_MODES = frozenset([NIC_MODE_BRIDGED, NIC_MODE_ROUTED])
744

    
745
NICS_PARAMETER_TYPES = {
746
    NIC_MODE: VTYPE_STRING,
747
    NIC_LINK: VTYPE_STRING,
748
    }
749

    
750
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
751

    
752
IDISK_SIZE = "size"
753
IDISK_MODE = "mode"
754
IDISK_ADOPT = "adopt"
755
IDISK_VG = "vg"
756
IDISK_METAVG = "metavg"
757
IDISK_PARAMS_TYPES = {
758
  IDISK_SIZE: VTYPE_SIZE,
759
  IDISK_MODE: VTYPE_STRING,
760
  IDISK_ADOPT: VTYPE_STRING,
761
  IDISK_VG: VTYPE_STRING,
762
  IDISK_METAVG: VTYPE_STRING,
763
  }
764
IDISK_PARAMS = frozenset(IDISK_PARAMS_TYPES.keys())
765

    
766
INIC_MAC = "mac"
767
INIC_IP = "ip"
768
INIC_MODE = "mode"
769
INIC_LINK = "link"
770
INIC_BRIDGE = "bridge"
771
INIC_PARAMS_TYPES = {
772
  INIC_BRIDGE: VTYPE_STRING,
773
  INIC_IP: VTYPE_MAYBE_STRING,
774
  INIC_LINK: VTYPE_STRING,
775
  INIC_MAC: VTYPE_STRING,
776
  INIC_MODE: VTYPE_STRING,
777
  }
778
INIC_PARAMS = frozenset(INIC_PARAMS_TYPES.keys())
779

    
780
# Hypervisor constants
781
HT_XEN_PVM = "xen-pvm"
782
HT_FAKE = "fake"
783
HT_XEN_HVM = "xen-hvm"
784
HT_KVM = "kvm"
785
HT_CHROOT = "chroot"
786
HT_LXC = "lxc"
787
HYPER_TYPES = frozenset([
788
  HT_XEN_PVM,
789
  HT_FAKE,
790
  HT_XEN_HVM,
791
  HT_KVM,
792
  HT_CHROOT,
793
  HT_LXC,
794
  ])
795
HTS_REQ_PORT = frozenset([HT_XEN_HVM, HT_KVM])
796

    
797
VNC_BASE_PORT = 5900
798
VNC_PASSWORD_FILE = CONF_DIR + "/vnc-cluster-password"
799
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
800

    
801
# NIC types
802
HT_NIC_RTL8139 = "rtl8139"
803
HT_NIC_NE2K_PCI = "ne2k_pci"
804
HT_NIC_NE2K_ISA = "ne2k_isa"
805
HT_NIC_I82551 = "i82551"
806
HT_NIC_I85557B = "i82557b"
807
HT_NIC_I8259ER = "i82559er"
808
HT_NIC_PCNET = "pcnet"
809
HT_NIC_E1000 = "e1000"
810
HT_NIC_PARAVIRTUAL = HT_DISK_PARAVIRTUAL = "paravirtual"
811

    
812
HT_HVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
813
                                    HT_NIC_E1000, HT_NIC_NE2K_ISA,
814
                                    HT_NIC_PARAVIRTUAL])
815
HT_KVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
816
                                    HT_NIC_NE2K_ISA, HT_NIC_I82551,
817
                                    HT_NIC_I85557B, HT_NIC_I8259ER,
818
                                    HT_NIC_PCNET, HT_NIC_E1000,
819
                                    HT_NIC_PARAVIRTUAL])
820
# Disk types
821
HT_DISK_IOEMU = "ioemu"
822
HT_DISK_IDE = "ide"
823
HT_DISK_SCSI = "scsi"
824
HT_DISK_SD = "sd"
825
HT_DISK_MTD = "mtd"
826
HT_DISK_PFLASH = "pflash"
827

    
828
HT_CACHE_DEFAULT = "default"
829
HT_CACHE_NONE = "none"
830
HT_CACHE_WTHROUGH = "writethrough"
831
HT_CACHE_WBACK = "writeback"
832
HT_VALID_CACHE_TYPES = frozenset([HT_CACHE_DEFAULT,
833
                                  HT_CACHE_NONE,
834
                                  HT_CACHE_WTHROUGH,
835
                                  HT_CACHE_WBACK])
836

    
837
HT_HVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IOEMU])
838
HT_KVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IDE,
839
                                     HT_DISK_SCSI, HT_DISK_SD, HT_DISK_MTD,
840
                                     HT_DISK_PFLASH])
841

    
842
# Mouse types:
843
HT_MOUSE_MOUSE = "mouse"
844
HT_MOUSE_TABLET = "tablet"
845

    
846
HT_KVM_VALID_MOUSE_TYPES = frozenset([HT_MOUSE_MOUSE, HT_MOUSE_TABLET])
847

    
848
# Boot order
849
HT_BO_FLOPPY = "floppy"
850
HT_BO_CDROM = "cdrom"
851
HT_BO_DISK = "disk"
852
HT_BO_NETWORK = "network"
853

    
854
HT_KVM_VALID_BO_TYPES = frozenset([HT_BO_FLOPPY, HT_BO_CDROM,
855
                                   HT_BO_DISK, HT_BO_NETWORK])
856

    
857
# Security models
858
HT_SM_NONE = "none"
859
HT_SM_USER = "user"
860
HT_SM_POOL = "pool"
861

    
862
HT_KVM_VALID_SM_TYPES = frozenset([HT_SM_NONE, HT_SM_USER, HT_SM_POOL])
863

    
864
# Kvm flag values
865
HT_KVM_ENABLED = "enabled"
866
HT_KVM_DISABLED = "disabled"
867

    
868
HT_KVM_FLAG_VALUES = frozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
869

    
870
# Migration type
871
HT_MIGRATION_LIVE = "live"
872
HT_MIGRATION_NONLIVE = "non-live"
873
HT_MIGRATION_MODES = frozenset([HT_MIGRATION_LIVE, HT_MIGRATION_NONLIVE])
874

    
875
# Cluster Verify steps
876
VERIFY_NPLUSONE_MEM = 'nplusone_mem'
877
VERIFY_OPTIONAL_CHECKS = frozenset([VERIFY_NPLUSONE_MEM])
878

    
879
# Node verify constants
880
NV_DRBDHELPER = "drbd-helper"
881
NV_DRBDLIST = "drbd-list"
882
NV_FILELIST = "filelist"
883
NV_HVINFO = "hvinfo"
884
NV_HYPERVISOR = "hypervisor"
885
NV_HVPARAMS = "hvparms"
886
NV_INSTANCELIST = "instancelist"
887
NV_LVLIST = "lvlist"
888
NV_MASTERIP = "master-ip"
889
NV_NODELIST = "nodelist"
890
NV_NODENETTEST = "node-net-test"
891
NV_NODESETUP = "nodesetup"
892
NV_OSLIST = "oslist"
893
NV_PVLIST = "pvlist"
894
NV_TIME = "time"
895
NV_VERSION = "version"
896
NV_VGLIST = "vglist"
897
NV_VMNODES = "vmnodes"
898
NV_OOB_PATHS = "oob-paths"
899
NV_BRIDGES = "bridges"
900

    
901
# SSL certificate check constants (in days)
902
SSL_CERT_EXPIRATION_WARN = 30
903
SSL_CERT_EXPIRATION_ERROR = 7
904

    
905
# Allocator framework constants
906
IALLOCATOR_VERSION = 2
907
IALLOCATOR_DIR_IN = "in"
908
IALLOCATOR_DIR_OUT = "out"
909
VALID_IALLOCATOR_DIRECTIONS = frozenset([
910
  IALLOCATOR_DIR_IN,
911
  IALLOCATOR_DIR_OUT,
912
  ])
913
IALLOCATOR_MODE_ALLOC = "allocate"
914
IALLOCATOR_MODE_RELOC = "relocate"
915
IALLOCATOR_MODE_MEVAC = "multi-evacuate"
916
VALID_IALLOCATOR_MODES = frozenset([
917
  IALLOCATOR_MODE_ALLOC,
918
  IALLOCATOR_MODE_RELOC,
919
  IALLOCATOR_MODE_MEVAC,
920
  ])
921
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
922

    
923
# Job queue
924
JOB_QUEUE_VERSION = 1
925
JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock"
926
JOB_QUEUE_VERSION_FILE = QUEUE_DIR + "/version"
927
JOB_QUEUE_SERIAL_FILE = QUEUE_DIR + "/serial"
928
JOB_QUEUE_ARCHIVE_DIR = QUEUE_DIR + "/archive"
929
JOB_QUEUE_DRAIN_FILE = QUEUE_DIR + "/drain"
930
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
931
JOB_QUEUE_DIRS = [QUEUE_DIR, JOB_QUEUE_ARCHIVE_DIR]
932
JOB_QUEUE_DIRS_MODE = SECURE_DIR_MODE
933

    
934
JOB_ID_TEMPLATE = r"\d+"
935

    
936
# unchanged job return
937
JOB_NOTCHANGED = "nochange"
938

    
939
# Job status
940
JOB_STATUS_QUEUED = "queued"
941
JOB_STATUS_WAITLOCK = "waiting"
942
JOB_STATUS_CANCELING = "canceling"
943
JOB_STATUS_RUNNING = "running"
944
JOB_STATUS_CANCELED = "canceled"
945
JOB_STATUS_SUCCESS = "success"
946
JOB_STATUS_ERROR = "error"
947
JOBS_FINALIZED = frozenset([
948
  JOB_STATUS_CANCELED,
949
  JOB_STATUS_SUCCESS,
950
  JOB_STATUS_ERROR,
951
  ])
952
JOB_STATUS_ALL = frozenset([
953
  JOB_STATUS_QUEUED,
954
  JOB_STATUS_WAITLOCK,
955
  JOB_STATUS_CANCELING,
956
  JOB_STATUS_RUNNING,
957
  ]) | JOBS_FINALIZED
958

    
959
# OpCode status
960
# not yet finalized
961
OP_STATUS_QUEUED = "queued"
962
OP_STATUS_WAITLOCK = "waiting"
963
OP_STATUS_CANCELING = "canceling"
964
OP_STATUS_RUNNING = "running"
965
# finalized
966
OP_STATUS_CANCELED = "canceled"
967
OP_STATUS_SUCCESS = "success"
968
OP_STATUS_ERROR = "error"
969
OPS_FINALIZED = frozenset([OP_STATUS_CANCELED,
970
                           OP_STATUS_SUCCESS,
971
                           OP_STATUS_ERROR])
972

    
973
# OpCode priority
974
OP_PRIO_LOWEST = +19
975
OP_PRIO_HIGHEST = -20
976

    
977
OP_PRIO_LOW = +10
978
OP_PRIO_NORMAL = 0
979
OP_PRIO_HIGH = -10
980

    
981
OP_PRIO_SUBMIT_VALID = frozenset([
982
  OP_PRIO_LOW,
983
  OP_PRIO_NORMAL,
984
  OP_PRIO_HIGH,
985
  ])
986

    
987
OP_PRIO_DEFAULT = OP_PRIO_NORMAL
988

    
989
# Execution log types
990
ELOG_MESSAGE = "message"
991
ELOG_PROGRESS = "progress"
992
ELOG_REMOTE_IMPORT = "remote-import"
993
ELOG_JQUEUE_TEST = "jqueue-test"
994

    
995
# /etc/hosts modification
996
ETC_HOSTS_ADD = "add"
997
ETC_HOSTS_REMOVE = "remove"
998

    
999
# Job queue test
1000
JQT_MSGPREFIX = "TESTMSG="
1001
JQT_EXPANDNAMES = "expandnames"
1002
JQT_EXEC = "exec"
1003
JQT_LOGMSG = "logmsg"
1004
JQT_STARTMSG = "startmsg"
1005
JQT_ALL = frozenset([
1006
  JQT_EXPANDNAMES,
1007
  JQT_EXEC,
1008
  JQT_LOGMSG,
1009
  JQT_STARTMSG,
1010
  ])
1011

    
1012
# Query resources
1013
QR_INSTANCE = "instance"
1014
QR_NODE = "node"
1015
QR_LOCK = "lock"
1016
QR_GROUP = "group"
1017

    
1018
#: List of resources which can be queried using L{opcodes.OpQuery}
1019
QR_OP_QUERY = frozenset([QR_INSTANCE, QR_NODE, QR_GROUP])
1020

    
1021
#: List of resources which can be queried using Local UniX Interface
1022
QR_OP_LUXI = QR_OP_QUERY.union([
1023
  QR_LOCK,
1024
  ])
1025

    
1026
# Query field types
1027
QFT_UNKNOWN = "unknown"
1028
QFT_TEXT = "text"
1029
QFT_BOOL = "bool"
1030
QFT_NUMBER = "number"
1031
QFT_UNIT = "unit"
1032
QFT_TIMESTAMP = "timestamp"
1033
QFT_OTHER = "other"
1034

    
1035
#: All query field types
1036
QFT_ALL = frozenset([
1037
  QFT_UNKNOWN,
1038
  QFT_TEXT,
1039
  QFT_BOOL,
1040
  QFT_NUMBER,
1041
  QFT_UNIT,
1042
  QFT_TIMESTAMP,
1043
  QFT_OTHER,
1044
  ])
1045

    
1046
# Query result field status (don't change or reuse values as they're used by
1047
# clients)
1048
#: Normal field status
1049
RS_NORMAL = 0
1050
#: Unknown field
1051
RS_UNKNOWN = 1
1052
#: No data (e.g. RPC error), can be used instead of L{RS_OFFLINE}
1053
RS_NODATA = 2
1054
#: Value unavailable/unsupported for item; if this field is supported
1055
#: but we cannot get the data for the moment, RS_NODATA or
1056
#: RS_OFFLINE should be used
1057
RS_UNAVAIL = 3
1058
#: Resource marked offline
1059
RS_OFFLINE = 4
1060

    
1061
RS_ALL = frozenset([
1062
  RS_NORMAL,
1063
  RS_UNKNOWN,
1064
  RS_NODATA,
1065
  RS_UNAVAIL,
1066
  RS_OFFLINE,
1067
  ])
1068

    
1069
#: Dictionary with special field cases and their verbose/terse formatting
1070
RSS_DESCRIPTION = {
1071
  RS_UNKNOWN: ("(unknown)", "??"),
1072
  RS_NODATA:  ("(nodata)",  "?"),
1073
  RS_OFFLINE: ("(offline)", "*"),
1074
  RS_UNAVAIL: ("(unavail)", "-"),
1075
  }
1076

    
1077
# max dynamic devices
1078
MAX_NICS = 8
1079
MAX_DISKS = 16
1080

    
1081
# SSCONF keys
1082
SS_CLUSTER_NAME = "cluster_name"
1083
SS_CLUSTER_TAGS = "cluster_tags"
1084
SS_FILE_STORAGE_DIR = "file_storage_dir"
1085
SS_SHARED_FILE_STORAGE_DIR = "shared_file_storage_dir"
1086
SS_MASTER_CANDIDATES = "master_candidates"
1087
SS_MASTER_CANDIDATES_IPS = "master_candidates_ips"
1088
SS_MASTER_IP = "master_ip"
1089
SS_MASTER_NETDEV = "master_netdev"
1090
SS_MASTER_NODE = "master_node"
1091
SS_NODE_LIST = "node_list"
1092
SS_NODE_PRIMARY_IPS = "node_primary_ips"
1093
SS_NODE_SECONDARY_IPS = "node_secondary_ips"
1094
SS_OFFLINE_NODES = "offline_nodes"
1095
SS_ONLINE_NODES = "online_nodes"
1096
SS_PRIMARY_IP_FAMILY = "primary_ip_family"
1097
SS_INSTANCE_LIST = "instance_list"
1098
SS_RELEASE_VERSION = "release_version"
1099
SS_HYPERVISOR_LIST = "hypervisor_list"
1100
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
1101
SS_UID_POOL = "uid_pool"
1102
SS_NODEGROUPS = "nodegroups"
1103

    
1104
# cluster wide default parameters
1105
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
1106

    
1107
HVC_DEFAULTS = {
1108
  HT_XEN_PVM: {
1109
    HV_USE_BOOTLOADER: False,
1110
    HV_BOOTLOADER_PATH: XEN_BOOTLOADER,
1111
    HV_BOOTLOADER_ARGS: '',
1112
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-xenU",
1113
    HV_INITRD_PATH: '',
1114
    HV_ROOT_PATH: '/dev/sda1',
1115
    HV_KERNEL_ARGS: 'ro',
1116
    HV_MIGRATION_PORT: 8002,
1117
    HV_MIGRATION_MODE: HT_MIGRATION_LIVE,
1118
    HV_BLOCKDEV_PREFIX: "sd",
1119
    },
1120
  HT_XEN_HVM: {
1121
    HV_BOOT_ORDER: "cd",
1122
    HV_CDROM_IMAGE_PATH: '',
1123
    HV_NIC_TYPE: HT_NIC_RTL8139,
1124
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
1125
    HV_VNC_BIND_ADDRESS: IP4_ADDRESS_ANY,
1126
    HV_VNC_PASSWORD_FILE: VNC_PASSWORD_FILE,
1127
    HV_ACPI: True,
1128
    HV_PAE: True,
1129
    HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
1130
    HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
1131
    HV_MIGRATION_PORT: 8002,
1132
    HV_MIGRATION_MODE: HT_MIGRATION_NONLIVE,
1133
    HV_USE_LOCALTIME: False,
1134
    HV_BLOCKDEV_PREFIX: "hd",
1135
    },
1136
  HT_KVM: {
1137
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
1138
    HV_INITRD_PATH: '',
1139
    HV_KERNEL_ARGS: 'ro',
1140
    HV_ROOT_PATH: '/dev/vda1',
1141
    HV_ACPI: True,
1142
    HV_SERIAL_CONSOLE: True,
1143
    HV_VNC_BIND_ADDRESS: '',
1144
    HV_VNC_TLS: False,
1145
    HV_VNC_X509: '',
1146
    HV_VNC_X509_VERIFY: False,
1147
    HV_VNC_PASSWORD_FILE: '',
1148
    HV_KVM_FLOPPY_IMAGE_PATH: '',
1149
    HV_CDROM_IMAGE_PATH: '',
1150
    HV_KVM_CDROM2_IMAGE_PATH: '',
1151
    HV_BOOT_ORDER: HT_BO_DISK,
1152
    HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
1153
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
1154
    HV_KVM_CDROM_DISK_TYPE: '',
1155
    HV_USB_MOUSE: '',
1156
    HV_MIGRATION_PORT: 8102,
1157
    HV_MIGRATION_BANDWIDTH: 32, # MiB/s
1158
    HV_MIGRATION_DOWNTIME: 30,  # ms
1159
    HV_MIGRATION_MODE: HT_MIGRATION_LIVE,
1160
    HV_USE_LOCALTIME: False,
1161
    HV_DISK_CACHE: HT_CACHE_DEFAULT,
1162
    HV_SECURITY_MODEL: HT_SM_NONE,
1163
    HV_SECURITY_DOMAIN: '',
1164
    HV_KVM_FLAG: "",
1165
    HV_VHOST_NET: False,
1166
    HV_KVM_USE_CHROOT: False,
1167
    HV_MEM_PATH: "",
1168
    },
1169
  HT_FAKE: {
1170
    },
1171
  HT_CHROOT: {
1172
    HV_INIT_SCRIPT: "/ganeti-chroot",
1173
    },
1174
  HT_LXC: {
1175
    HV_CPU_MASK: "",
1176
    },
1177
  }
1178

    
1179
HVC_GLOBALS = frozenset([
1180
  HV_MIGRATION_PORT,
1181
  HV_MIGRATION_BANDWIDTH,
1182
  HV_MIGRATION_MODE,
1183
  ])
1184

    
1185
BEC_DEFAULTS = {
1186
  BE_MEMORY: 128,
1187
  BE_VCPUS: 1,
1188
  BE_AUTO_BALANCE: True,
1189
  }
1190

    
1191
NDC_DEFAULTS = {
1192
  ND_OOB_PROGRAM: None,
1193
  }
1194

    
1195
NICC_DEFAULTS = {
1196
  NIC_MODE: NIC_MODE_BRIDGED,
1197
  NIC_LINK: DEFAULT_BRIDGE,
1198
  }
1199

    
1200
MASTER_POOL_SIZE_DEFAULT = 10
1201

    
1202
CONFD_PROTOCOL_VERSION = 1
1203

    
1204
CONFD_REQ_PING = 0
1205
CONFD_REQ_NODE_ROLE_BYNAME = 1
1206
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
1207
CONFD_REQ_CLUSTER_MASTER = 3
1208
CONFD_REQ_NODE_PIP_LIST = 4
1209
CONFD_REQ_MC_PIP_LIST = 5
1210
CONFD_REQ_INSTANCES_IPS_LIST = 6
1211

    
1212
# Confd request query fields. These are used to narrow down queries.
1213
# These must be strings rather than integers, because json-encoding
1214
# converts them to strings anyway, as they're used as dict-keys.
1215
CONFD_REQQ_LINK = "0"
1216
CONFD_REQQ_IP = "1"
1217
CONFD_REQQ_IPLIST = "2"
1218
CONFD_REQQ_FIELDS = "3"
1219

    
1220
CONFD_REQFIELD_NAME = "0"
1221
CONFD_REQFIELD_IP = "1"
1222
CONFD_REQFIELD_MNODE_PIP = "2"
1223

    
1224
CONFD_REQS = frozenset([
1225
  CONFD_REQ_PING,
1226
  CONFD_REQ_NODE_ROLE_BYNAME,
1227
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
1228
  CONFD_REQ_CLUSTER_MASTER,
1229
  CONFD_REQ_NODE_PIP_LIST,
1230
  CONFD_REQ_MC_PIP_LIST,
1231
  CONFD_REQ_INSTANCES_IPS_LIST,
1232
  ])
1233

    
1234
CONFD_REPL_STATUS_OK = 0
1235
CONFD_REPL_STATUS_ERROR = 1
1236
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
1237

    
1238
CONFD_REPL_STATUSES = frozenset([
1239
  CONFD_REPL_STATUS_OK,
1240
  CONFD_REPL_STATUS_ERROR,
1241
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
1242
  ])
1243

    
1244
(CONFD_NODE_ROLE_MASTER,
1245
 CONFD_NODE_ROLE_CANDIDATE,
1246
 CONFD_NODE_ROLE_OFFLINE,
1247
 CONFD_NODE_ROLE_DRAINED,
1248
 CONFD_NODE_ROLE_REGULAR,
1249
 ) = range(5)
1250

    
1251
# A few common errors for confd
1252
CONFD_ERROR_UNKNOWN_ENTRY = 1
1253
CONFD_ERROR_INTERNAL = 2
1254
CONFD_ERROR_ARGUMENT = 3
1255

    
1256
# Each request is "salted" by the current timestamp.
1257
# This constants decides how many seconds of skew to accept.
1258
# TODO: make this a default and allow the value to be more configurable
1259
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
1260

    
1261
# When we haven't reloaded the config for more than this amount of seconds, we
1262
# force a test to see if inotify is betraying us.
1263
CONFD_CONFIG_RELOAD_TIMEOUT = 60
1264

    
1265
# If we receive more than one update in this amount of seconds, we move to
1266
# polling every RATELIMIT seconds, rather than relying on inotify, to be able
1267
# to serve more requests.
1268
CONFD_CONFIG_RELOAD_RATELIMIT = 2
1269

    
1270
# Magic number prepended to all confd queries.
1271
# This allows us to distinguish different types of confd protocols and handle
1272
# them. For example by changing this we can move the whole payload to be
1273
# compressed, or move away from json.
1274
CONFD_MAGIC_FOURCC = 'plj0'
1275

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

    
1281
# Timeout in seconds to expire pending query request in the confd client
1282
# library. We don't actually expect any answer more than 10 seconds after we
1283
# sent a request.
1284
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
1285

    
1286
# Maximum UDP datagram size.
1287
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
1288
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
1289
#   (assuming we can't use jumbo frames)
1290
# We just set this to 60K, which should be enough
1291
MAX_UDP_DATA_SIZE = 61440
1292

    
1293
# User-id pool minimum/maximum acceptable user-ids.
1294
UIDPOOL_UID_MIN = 0
1295
UIDPOOL_UID_MAX = 2**32-1 # Assuming 32 bit user-ids
1296

    
1297
# Name or path of the pgrep command
1298
PGREP = "pgrep"
1299

    
1300
# Name of the node group that gets created at cluster init or upgrade
1301
INITIAL_NODE_GROUP_NAME = "default"
1302

    
1303
# Possible values for NodeGroup.alloc_policy
1304
ALLOC_POLICY_PREFERRED = "preferred"
1305
ALLOC_POLICY_LAST_RESORT = "last_resort"
1306
ALLOC_POLICY_UNALLOCABLE = "unallocable"
1307
VALID_ALLOC_POLICIES = [
1308
  ALLOC_POLICY_PREFERRED,
1309
  ALLOC_POLICY_LAST_RESORT,
1310
  ALLOC_POLICY_UNALLOCABLE,
1311
  ]
1312

    
1313
# Temporary external/shared storage parameters
1314
BLOCKDEV_DRIVER_MANUAL = "manual"