Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ e5395072

History | View | Annotate | Download (35 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
# instance creation modes
440
INSTANCE_CREATE = "create"
441
INSTANCE_IMPORT = "import"
442
INSTANCE_REMOTE_IMPORT = "remote-import"
443
INSTANCE_CREATE_MODES = frozenset([
444
  INSTANCE_CREATE,
445
  INSTANCE_IMPORT,
446
  INSTANCE_REMOTE_IMPORT,
447
  ])
448

    
449
# Remote import/export handshake message and version
450
RIE_VERSION = 0
451
RIE_HANDSHAKE = "Hi, I'm Ganeti"
452

    
453
# Remote import/export certificate validity in seconds
454
RIE_CERT_VALIDITY = 24 * 60 * 60
455

    
456
# Overall timeout for establishing connection
457
RIE_CONNECT_TIMEOUT = 180
458

    
459
# Export only: how long to wait per connection attempt (seconds)
460
RIE_CONNECT_ATTEMPT_TIMEOUT = 20
461

    
462
# Export only: number of attempts to connect
463
RIE_CONNECT_RETRIES = 10
464

    
465
#: Give child process up to 5 seconds to exit after sending a signal
466
CHILD_LINGER_TIMEOUT = 5.0
467

    
468
DISK_TEMPLATES = frozenset([DT_DISKLESS, DT_PLAIN, DT_DRBD8,
469
                            DT_FILE, DT_SHARED_FILE, DT_BLOCK])
470

    
471
FILE_DRIVER = frozenset([FD_LOOP, FD_BLKTAP])
472

    
473
# import/export config options
474
INISECT_EXP = "export"
475
INISECT_INS = "instance"
476
INISECT_HYP = "hypervisor"
477
INISECT_BEP = "backend"
478
INISECT_OSP = "os"
479

    
480
# dynamic device modification
481
DDM_ADD = "add"
482
DDM_REMOVE = "remove"
483
DDMS_VALUES = frozenset([DDM_ADD, DDM_REMOVE])
484

    
485
# common exit codes
486
EXIT_SUCCESS = 0
487
EXIT_FAILURE = 1
488
EXIT_NOTCLUSTER = 5
489
EXIT_NOTMASTER = 11
490
EXIT_NODESETUP_ERROR = 12
491
EXIT_CONFIRMATION = 13 # need user confirmation
492

    
493
#: Exit code for query operations with unknown fields
494
EXIT_UNKNOWN_FIELD = 14
495

    
496
# tags
497
TAG_CLUSTER = "cluster"
498
TAG_NODE = "node"
499
TAG_INSTANCE = "instance"
500
VALID_TAG_TYPES = frozenset([
501
  TAG_CLUSTER,
502
  TAG_NODE,
503
  TAG_INSTANCE,
504
  ])
505
MAX_TAG_LEN = 128
506
MAX_TAGS_PER_OBJ = 4096
507

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

    
532
#: Key for job IDs in opcode result
533
JOB_IDS_KEY = "jobs"
534

    
535
# runparts results
536
(RUNPARTS_SKIP,
537
 RUNPARTS_RUN,
538
 RUNPARTS_ERR) = range(3)
539

    
540
RUNPARTS_STATUS = frozenset([RUNPARTS_SKIP, RUNPARTS_RUN, RUNPARTS_ERR])
541

    
542
# RPC constants
543
(RPC_ENCODING_NONE,
544
 RPC_ENCODING_ZLIB_BASE64) = range(2)
545

    
546
# os related constants
547
OS_SCRIPT_CREATE = 'create'
548
OS_SCRIPT_IMPORT = 'import'
549
OS_SCRIPT_EXPORT = 'export'
550
OS_SCRIPT_RENAME = 'rename'
551
OS_SCRIPT_VERIFY = 'verify'
552
OS_SCRIPTS = frozenset([OS_SCRIPT_CREATE, OS_SCRIPT_IMPORT,
553
                        OS_SCRIPT_EXPORT, OS_SCRIPT_RENAME,
554
                        OS_SCRIPT_VERIFY])
555

    
556
OS_API_FILE = 'ganeti_api_version'
557
OS_VARIANTS_FILE = 'variants.list'
558
OS_PARAMETERS_FILE = 'parameters.list'
559

    
560
OS_VALIDATE_PARAMETERS = 'parameters'
561
OS_VALIDATE_CALLS = frozenset([OS_VALIDATE_PARAMETERS])
562

    
563
# ssh constants
564
SSH_CONFIG_DIR = _autoconf.SSH_CONFIG_DIR
565
SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_dsa_key"
566
SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
567
SSH_HOST_RSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_rsa_key"
568
SSH_HOST_RSA_PUB = SSH_HOST_RSA_PRIV + ".pub"
569
SSH = "ssh"
570
SCP = "scp"
571

    
572
# reboot types
573
INSTANCE_REBOOT_SOFT = "soft"
574
INSTANCE_REBOOT_HARD = "hard"
575
INSTANCE_REBOOT_FULL = "full"
576

    
577
REBOOT_TYPES = frozenset([INSTANCE_REBOOT_SOFT,
578
                          INSTANCE_REBOOT_HARD,
579
                          INSTANCE_REBOOT_FULL])
580

    
581
VTYPE_STRING = 'string'
582
VTYPE_MAYBE_STRING = "maybe-string"
583
VTYPE_BOOL = 'bool'
584
VTYPE_SIZE = 'size' # size, in MiBs
585
VTYPE_INT = 'int'
586
ENFORCEABLE_TYPES = frozenset([
587
                      VTYPE_STRING,
588
                      VTYPE_MAYBE_STRING,
589
                      VTYPE_BOOL,
590
                      VTYPE_SIZE,
591
                      VTYPE_INT,
592
                      ])
593

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

    
632
HVS_PARAMETER_TYPES = {
633
  HV_BOOT_ORDER: VTYPE_STRING,
634
  HV_CDROM_IMAGE_PATH: VTYPE_STRING,
635
  HV_NIC_TYPE: VTYPE_STRING,
636
  HV_DISK_TYPE: VTYPE_STRING,
637
  HV_VNC_PASSWORD_FILE: VTYPE_STRING,
638
  HV_VNC_BIND_ADDRESS: VTYPE_STRING,
639
  HV_VNC_TLS: VTYPE_BOOL,
640
  HV_VNC_X509: VTYPE_STRING,
641
  HV_VNC_X509_VERIFY: VTYPE_BOOL,
642
  HV_ACPI: VTYPE_BOOL,
643
  HV_PAE: VTYPE_BOOL,
644
  HV_USE_BOOTLOADER: VTYPE_BOOL,
645
  HV_BOOTLOADER_PATH: VTYPE_STRING,
646
  HV_BOOTLOADER_ARGS: VTYPE_STRING,
647
  HV_KERNEL_PATH: VTYPE_STRING,
648
  HV_KERNEL_ARGS: VTYPE_STRING,
649
  HV_INITRD_PATH: VTYPE_STRING,
650
  HV_ROOT_PATH: VTYPE_STRING,
651
  HV_SERIAL_CONSOLE: VTYPE_BOOL,
652
  HV_USB_MOUSE: VTYPE_STRING,
653
  HV_DEVICE_MODEL: VTYPE_STRING,
654
  HV_INIT_SCRIPT: VTYPE_STRING,
655
  HV_MIGRATION_PORT: VTYPE_INT,
656
  HV_MIGRATION_BANDWIDTH: VTYPE_INT,
657
  HV_MIGRATION_DOWNTIME: VTYPE_INT,
658
  HV_MIGRATION_MODE: VTYPE_STRING,
659
  HV_USE_LOCALTIME: VTYPE_BOOL,
660
  HV_DISK_CACHE: VTYPE_STRING,
661
  HV_SECURITY_MODEL: VTYPE_STRING,
662
  HV_SECURITY_DOMAIN: VTYPE_STRING,
663
  HV_KVM_FLAG: VTYPE_STRING,
664
  HV_VHOST_NET: VTYPE_BOOL,
665
  HV_KVM_USE_CHROOT: VTYPE_BOOL,
666
  HV_CPU_MASK: VTYPE_STRING,
667
  HV_MEM_PATH: VTYPE_STRING,
668
  HV_BLOCKDEV_PREFIX: VTYPE_STRING,
669
  }
670

    
671
HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
672

    
673
# Backend parameter names
674
BE_MEMORY = "memory"
675
BE_VCPUS = "vcpus"
676
BE_AUTO_BALANCE = "auto_balance"
677

    
678
BES_PARAMETER_TYPES = {
679
    BE_MEMORY: VTYPE_SIZE,
680
    BE_VCPUS: VTYPE_INT,
681
    BE_AUTO_BALANCE: VTYPE_BOOL,
682
    }
683

    
684
BES_PARAMETERS = frozenset(BES_PARAMETER_TYPES.keys())
685

    
686
# Node parameter names
687
ND_OOB_PROGRAM = "oob_program"
688

    
689
NDS_PARAMETER_TYPES = {
690
    ND_OOB_PROGRAM: VTYPE_MAYBE_STRING,
691
    }
692

    
693
NDS_PARAMETERS = frozenset(NDS_PARAMETER_TYPES.keys())
694

    
695
# OOB supported commands
696
OOB_POWER_ON = "power-on"
697
OOB_POWER_OFF = "power-off"
698
OOB_POWER_CYCLE = "power-cycle"
699
OOB_POWER_STATUS = "power-status"
700
OOB_HEALTH = "health"
701

    
702
OOB_COMMANDS = frozenset([OOB_POWER_ON, OOB_POWER_OFF, OOB_POWER_CYCLE,
703
                          OOB_POWER_STATUS, OOB_HEALTH])
704

    
705
OOB_POWER_STATUS_POWERED = "powered"
706

    
707
OOB_TIMEOUT = 60 # 60 seconds
708
OOB_POWER_DELAY = 2.0 # 2 seconds
709

    
710
OOB_STATUS_OK = "OK"
711
OOB_STATUS_WARNING = "WARNING"
712
OOB_STATUS_CRITICAL = "CRITICAL"
713
OOB_STATUS_UNKNOWN = "UNKNOWN"
714

    
715
OOB_STATUSES = frozenset([
716
  OOB_STATUS_OK,
717
  OOB_STATUS_WARNING,
718
  OOB_STATUS_CRITICAL,
719
  OOB_STATUS_UNKNOWN,
720
  ])
721

    
722
# Instance Parameters Profile
723
PP_DEFAULT = "default"
724

    
725
# NIC_* constants are used inside the ganeti config
726
NIC_MODE = "mode"
727
NIC_LINK = "link"
728

    
729
NIC_MODE_BRIDGED = "bridged"
730
NIC_MODE_ROUTED = "routed"
731

    
732
NIC_VALID_MODES = frozenset([NIC_MODE_BRIDGED, NIC_MODE_ROUTED])
733

    
734
NICS_PARAMETER_TYPES = {
735
    NIC_MODE: VTYPE_STRING,
736
    NIC_LINK: VTYPE_STRING,
737
    }
738

    
739
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
740

    
741
# IDISK_* constants are used in opcodes, to create/change disks
742
IDISK_SIZE = "size"
743
IDISK_MODE = "mode"
744
IDISK_ADOPT = "adopt"
745
IDISK_VG = "vg"
746
IDISK_PARAMS_TYPES = {
747
  IDISK_SIZE: VTYPE_SIZE,
748
  IDISK_MODE: VTYPE_STRING,
749
  IDISK_ADOPT: VTYPE_STRING,
750
  IDISK_VG: VTYPE_STRING,
751
  }
752
IDISK_PARAMS = frozenset(IDISK_PARAMS_TYPES.keys())
753

    
754
# INIC_* constants are used in opcodes, to create/change nics
755
INIC_MAC = "mac"
756
INIC_IP = "ip"
757
INIC_MODE = "mode"
758
INIC_LINK = "link"
759
INIC_PARAMS_TYPES = {
760
  INIC_IP: VTYPE_MAYBE_STRING,
761
  INIC_LINK: VTYPE_STRING,
762
  INIC_MAC: VTYPE_STRING,
763
  INIC_MODE: VTYPE_STRING,
764
  }
765
INIC_PARAMS = frozenset(INIC_PARAMS_TYPES.keys())
766

    
767
# Hypervisor constants
768
HT_XEN_PVM = "xen-pvm"
769
HT_FAKE = "fake"
770
HT_XEN_HVM = "xen-hvm"
771
HT_KVM = "kvm"
772
HT_CHROOT = "chroot"
773
HT_LXC = "lxc"
774
HYPER_TYPES = frozenset([
775
  HT_XEN_PVM,
776
  HT_FAKE,
777
  HT_XEN_HVM,
778
  HT_KVM,
779
  HT_CHROOT,
780
  HT_LXC,
781
  ])
782
HTS_REQ_PORT = frozenset([HT_XEN_HVM, HT_KVM])
783

    
784
VNC_BASE_PORT = 5900
785
VNC_PASSWORD_FILE = CONF_DIR + "/vnc-cluster-password"
786
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
787

    
788
# NIC types
789
HT_NIC_RTL8139 = "rtl8139"
790
HT_NIC_NE2K_PCI = "ne2k_pci"
791
HT_NIC_NE2K_ISA = "ne2k_isa"
792
HT_NIC_I82551 = "i82551"
793
HT_NIC_I85557B = "i82557b"
794
HT_NIC_I8259ER = "i82559er"
795
HT_NIC_PCNET = "pcnet"
796
HT_NIC_E1000 = "e1000"
797
HT_NIC_PARAVIRTUAL = HT_DISK_PARAVIRTUAL = "paravirtual"
798

    
799
HT_HVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
800
                                    HT_NIC_E1000, HT_NIC_NE2K_ISA,
801
                                    HT_NIC_PARAVIRTUAL])
802
HT_KVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
803
                                    HT_NIC_NE2K_ISA, HT_NIC_I82551,
804
                                    HT_NIC_I85557B, HT_NIC_I8259ER,
805
                                    HT_NIC_PCNET, HT_NIC_E1000,
806
                                    HT_NIC_PARAVIRTUAL])
807
# Disk types
808
HT_DISK_IOEMU = "ioemu"
809
HT_DISK_IDE = "ide"
810
HT_DISK_SCSI = "scsi"
811
HT_DISK_SD = "sd"
812
HT_DISK_MTD = "mtd"
813
HT_DISK_PFLASH = "pflash"
814

    
815
HT_CACHE_DEFAULT = "default"
816
HT_CACHE_NONE = "none"
817
HT_CACHE_WTHROUGH = "writethrough"
818
HT_CACHE_WBACK = "writeback"
819
HT_VALID_CACHE_TYPES = frozenset([HT_CACHE_DEFAULT,
820
                                  HT_CACHE_NONE,
821
                                  HT_CACHE_WTHROUGH,
822
                                  HT_CACHE_WBACK])
823

    
824
HT_HVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IOEMU])
825
HT_KVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IDE,
826
                                     HT_DISK_SCSI, HT_DISK_SD, HT_DISK_MTD,
827
                                     HT_DISK_PFLASH])
828

    
829
# Mouse types:
830
HT_MOUSE_MOUSE = "mouse"
831
HT_MOUSE_TABLET = "tablet"
832

    
833
HT_KVM_VALID_MOUSE_TYPES = frozenset([HT_MOUSE_MOUSE, HT_MOUSE_TABLET])
834

    
835
# Boot order
836
HT_BO_CDROM = "cdrom"
837
HT_BO_DISK = "disk"
838
HT_BO_NETWORK = "network"
839

    
840
HT_KVM_VALID_BO_TYPES = frozenset([HT_BO_CDROM, HT_BO_DISK, HT_BO_NETWORK])
841

    
842
# Security models
843
HT_SM_NONE = "none"
844
HT_SM_USER = "user"
845
HT_SM_POOL = "pool"
846

    
847
HT_KVM_VALID_SM_TYPES = frozenset([HT_SM_NONE, HT_SM_USER, HT_SM_POOL])
848

    
849
# Kvm flag values
850
HT_KVM_ENABLED = "enabled"
851
HT_KVM_DISABLED = "disabled"
852

    
853
HT_KVM_FLAG_VALUES = frozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
854

    
855
# Migration type
856
HT_MIGRATION_LIVE = "live"
857
HT_MIGRATION_NONLIVE = "non-live"
858
HT_MIGRATION_MODES = frozenset([HT_MIGRATION_LIVE, HT_MIGRATION_NONLIVE])
859

    
860
# Cluster Verify steps
861
VERIFY_NPLUSONE_MEM = 'nplusone_mem'
862
VERIFY_OPTIONAL_CHECKS = frozenset([VERIFY_NPLUSONE_MEM])
863

    
864
# Node verify constants
865
NV_DRBDHELPER = "drbd-helper"
866
NV_DRBDLIST = "drbd-list"
867
NV_FILELIST = "filelist"
868
NV_HVINFO = "hvinfo"
869
NV_HYPERVISOR = "hypervisor"
870
NV_HVPARAMS = "hvparms"
871
NV_INSTANCELIST = "instancelist"
872
NV_LVLIST = "lvlist"
873
NV_MASTERIP = "master-ip"
874
NV_NODELIST = "nodelist"
875
NV_NODENETTEST = "node-net-test"
876
NV_NODESETUP = "nodesetup"
877
NV_OSLIST = "oslist"
878
NV_PVLIST = "pvlist"
879
NV_TIME = "time"
880
NV_VERSION = "version"
881
NV_VGLIST = "vglist"
882
NV_VMNODES = "vmnodes"
883
NV_OOB_PATHS = "oob-paths"
884

    
885
# Instance status
886
INSTST_RUNNING = "running"
887
INSTST_ADMINDOWN = "ADMIN_down"
888
INSTST_NODEOFFLINE = "ERROR_nodeoffline"
889
INSTST_NODEDOWN = "ERROR_nodedown"
890
INSTST_WRONGNODE = "ERROR_wrongnode"
891
INSTST_ERRORUP = "ERROR_up"
892
INSTST_ERRORDOWN = "ERROR_down"
893
INSTST_ALL = frozenset([
894
  INSTST_RUNNING,
895
  INSTST_ADMINDOWN,
896
  INSTST_NODEOFFLINE,
897
  INSTST_NODEDOWN,
898
  INSTST_WRONGNODE,
899
  INSTST_ERRORUP,
900
  INSTST_ERRORDOWN,
901
  ])
902

    
903
# Node roles
904
NR_REGULAR = "R"
905
NR_MASTER = "M"
906
NR_MCANDIDATE = "C"
907
NR_DRAINED = "D"
908
NR_OFFLINE = "O"
909
NR_ALL = frozenset([
910
  NR_REGULAR,
911
  NR_MASTER,
912
  NR_MCANDIDATE,
913
  NR_DRAINED,
914
  NR_OFFLINE,
915
  ])
916

    
917
# SSL certificate check constants (in days)
918
SSL_CERT_EXPIRATION_WARN = 30
919
SSL_CERT_EXPIRATION_ERROR = 7
920

    
921
# Allocator framework constants
922
IALLOCATOR_VERSION = 2
923
IALLOCATOR_DIR_IN = "in"
924
IALLOCATOR_DIR_OUT = "out"
925
VALID_IALLOCATOR_DIRECTIONS = frozenset([
926
  IALLOCATOR_DIR_IN,
927
  IALLOCATOR_DIR_OUT,
928
  ])
929
IALLOCATOR_MODE_ALLOC = "allocate"
930
IALLOCATOR_MODE_RELOC = "relocate"
931
IALLOCATOR_MODE_MEVAC = "multi-evacuate"
932
VALID_IALLOCATOR_MODES = frozenset([
933
  IALLOCATOR_MODE_ALLOC,
934
  IALLOCATOR_MODE_RELOC,
935
  IALLOCATOR_MODE_MEVAC,
936
  ])
937
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
938

    
939
# Job queue
940
JOB_QUEUE_VERSION = 1
941
JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock"
942
JOB_QUEUE_VERSION_FILE = QUEUE_DIR + "/version"
943
JOB_QUEUE_SERIAL_FILE = QUEUE_DIR + "/serial"
944
JOB_QUEUE_ARCHIVE_DIR = QUEUE_DIR + "/archive"
945
JOB_QUEUE_DRAIN_FILE = QUEUE_DIR + "/drain"
946
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
947
JOB_QUEUE_DIRS = [QUEUE_DIR, JOB_QUEUE_ARCHIVE_DIR]
948
JOB_QUEUE_DIRS_MODE = SECURE_DIR_MODE
949

    
950
JOB_ID_TEMPLATE = r"\d+"
951

    
952
# unchanged job return
953
JOB_NOTCHANGED = "nochange"
954

    
955
# Job status
956
JOB_STATUS_QUEUED = "queued"
957
JOB_STATUS_WAITLOCK = "waiting"
958
JOB_STATUS_CANCELING = "canceling"
959
JOB_STATUS_RUNNING = "running"
960
JOB_STATUS_CANCELED = "canceled"
961
JOB_STATUS_SUCCESS = "success"
962
JOB_STATUS_ERROR = "error"
963
JOBS_FINALIZED = frozenset([
964
  JOB_STATUS_CANCELED,
965
  JOB_STATUS_SUCCESS,
966
  JOB_STATUS_ERROR,
967
  ])
968
JOB_STATUS_ALL = frozenset([
969
  JOB_STATUS_QUEUED,
970
  JOB_STATUS_WAITLOCK,
971
  JOB_STATUS_CANCELING,
972
  JOB_STATUS_RUNNING,
973
  ]) | JOBS_FINALIZED
974

    
975
# OpCode status
976
# not yet finalized
977
OP_STATUS_QUEUED = "queued"
978
OP_STATUS_WAITLOCK = "waiting"
979
OP_STATUS_CANCELING = "canceling"
980
OP_STATUS_RUNNING = "running"
981
# finalized
982
OP_STATUS_CANCELED = "canceled"
983
OP_STATUS_SUCCESS = "success"
984
OP_STATUS_ERROR = "error"
985
OPS_FINALIZED = frozenset([OP_STATUS_CANCELED,
986
                           OP_STATUS_SUCCESS,
987
                           OP_STATUS_ERROR])
988

    
989
# OpCode priority
990
OP_PRIO_LOWEST = +19
991
OP_PRIO_HIGHEST = -20
992

    
993
OP_PRIO_LOW = +10
994
OP_PRIO_NORMAL = 0
995
OP_PRIO_HIGH = -10
996

    
997
OP_PRIO_SUBMIT_VALID = frozenset([
998
  OP_PRIO_LOW,
999
  OP_PRIO_NORMAL,
1000
  OP_PRIO_HIGH,
1001
  ])
1002

    
1003
OP_PRIO_DEFAULT = OP_PRIO_NORMAL
1004

    
1005
# Execution log types
1006
ELOG_MESSAGE = "message"
1007
ELOG_PROGRESS = "progress"
1008
ELOG_REMOTE_IMPORT = "remote-import"
1009
ELOG_JQUEUE_TEST = "jqueue-test"
1010

    
1011
# /etc/hosts modification
1012
ETC_HOSTS_ADD = "add"
1013
ETC_HOSTS_REMOVE = "remove"
1014

    
1015
# Job queue test
1016
JQT_MSGPREFIX = "TESTMSG="
1017
JQT_EXPANDNAMES = "expandnames"
1018
JQT_EXEC = "exec"
1019
JQT_LOGMSG = "logmsg"
1020
JQT_STARTMSG = "startmsg"
1021
JQT_ALL = frozenset([
1022
  JQT_EXPANDNAMES,
1023
  JQT_EXEC,
1024
  JQT_LOGMSG,
1025
  JQT_STARTMSG,
1026
  ])
1027

    
1028
# Query resources
1029
QR_INSTANCE = "instance"
1030
QR_NODE = "node"
1031
QR_LOCK = "lock"
1032
QR_GROUP = "group"
1033
QR_OS = "os"
1034

    
1035
#: List of resources which can be queried using L{opcodes.OpQuery}
1036
QR_VIA_OP = frozenset([QR_INSTANCE, QR_NODE, QR_GROUP, QR_OS])
1037

    
1038
#: List of resources which can be queried using Local UniX Interface
1039
QR_VIA_LUXI = QR_VIA_OP.union([
1040
  QR_LOCK,
1041
  ])
1042

    
1043
#: List of resources which can be queried using RAPI
1044
QR_VIA_RAPI = QR_VIA_LUXI
1045

    
1046
# Query field types
1047
QFT_UNKNOWN = "unknown"
1048
QFT_TEXT = "text"
1049
QFT_BOOL = "bool"
1050
QFT_NUMBER = "number"
1051
QFT_UNIT = "unit"
1052
QFT_TIMESTAMP = "timestamp"
1053
QFT_OTHER = "other"
1054

    
1055
#: All query field types
1056
QFT_ALL = frozenset([
1057
  QFT_UNKNOWN,
1058
  QFT_TEXT,
1059
  QFT_BOOL,
1060
  QFT_NUMBER,
1061
  QFT_UNIT,
1062
  QFT_TIMESTAMP,
1063
  QFT_OTHER,
1064
  ])
1065

    
1066
# Query result field status (don't change or reuse values as they're used by
1067
# clients)
1068
#: Normal field status
1069
RS_NORMAL = 0
1070
#: Unknown field
1071
RS_UNKNOWN = 1
1072
#: No data (e.g. RPC error), can be used instead of L{RS_OFFLINE}
1073
RS_NODATA = 2
1074
#: Value unavailable/unsupported for item; if this field is supported
1075
#: but we cannot get the data for the moment, RS_NODATA or
1076
#: RS_OFFLINE should be used
1077
RS_UNAVAIL = 3
1078
#: Resource marked offline
1079
RS_OFFLINE = 4
1080

    
1081
RS_ALL = frozenset([
1082
  RS_NORMAL,
1083
  RS_UNKNOWN,
1084
  RS_NODATA,
1085
  RS_UNAVAIL,
1086
  RS_OFFLINE,
1087
  ])
1088

    
1089
#: Dictionary with special field cases and their verbose/terse formatting
1090
RSS_DESCRIPTION = {
1091
  RS_UNKNOWN: ("(unknown)", "??"),
1092
  RS_NODATA:  ("(nodata)",  "?"),
1093
  RS_OFFLINE: ("(offline)", "*"),
1094
  RS_UNAVAIL: ("(unavail)", "-"),
1095
  }
1096

    
1097
# max dynamic devices
1098
MAX_NICS = 8
1099
MAX_DISKS = 16
1100

    
1101
# SSCONF keys
1102
SS_CLUSTER_NAME = "cluster_name"
1103
SS_CLUSTER_TAGS = "cluster_tags"
1104
SS_FILE_STORAGE_DIR = "file_storage_dir"
1105
SS_SHARED_FILE_STORAGE_DIR = "shared_file_storage_dir"
1106
SS_MASTER_CANDIDATES = "master_candidates"
1107
SS_MASTER_CANDIDATES_IPS = "master_candidates_ips"
1108
SS_MASTER_IP = "master_ip"
1109
SS_MASTER_NETDEV = "master_netdev"
1110
SS_MASTER_NODE = "master_node"
1111
SS_NODE_LIST = "node_list"
1112
SS_NODE_PRIMARY_IPS = "node_primary_ips"
1113
SS_NODE_SECONDARY_IPS = "node_secondary_ips"
1114
SS_OFFLINE_NODES = "offline_nodes"
1115
SS_ONLINE_NODES = "online_nodes"
1116
SS_PRIMARY_IP_FAMILY = "primary_ip_family"
1117
SS_INSTANCE_LIST = "instance_list"
1118
SS_RELEASE_VERSION = "release_version"
1119
SS_HYPERVISOR_LIST = "hypervisor_list"
1120
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
1121
SS_UID_POOL = "uid_pool"
1122
SS_NODEGROUPS = "nodegroups"
1123

    
1124
# cluster wide default parameters
1125
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
1126

    
1127
HVC_DEFAULTS = {
1128
  HT_XEN_PVM: {
1129
    HV_USE_BOOTLOADER: False,
1130
    HV_BOOTLOADER_PATH: XEN_BOOTLOADER,
1131
    HV_BOOTLOADER_ARGS: '',
1132
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-xenU",
1133
    HV_INITRD_PATH: '',
1134
    HV_ROOT_PATH: '/dev/sda1',
1135
    HV_KERNEL_ARGS: 'ro',
1136
    HV_MIGRATION_PORT: 8002,
1137
    HV_MIGRATION_MODE: HT_MIGRATION_LIVE,
1138
    HV_BLOCKDEV_PREFIX: "sd",
1139
    },
1140
  HT_XEN_HVM: {
1141
    HV_BOOT_ORDER: "cd",
1142
    HV_CDROM_IMAGE_PATH: '',
1143
    HV_NIC_TYPE: HT_NIC_RTL8139,
1144
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
1145
    HV_VNC_BIND_ADDRESS: IP4_ADDRESS_ANY,
1146
    HV_VNC_PASSWORD_FILE: VNC_PASSWORD_FILE,
1147
    HV_ACPI: True,
1148
    HV_PAE: True,
1149
    HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
1150
    HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
1151
    HV_MIGRATION_PORT: 8002,
1152
    HV_MIGRATION_MODE: HT_MIGRATION_NONLIVE,
1153
    HV_USE_LOCALTIME: False,
1154
    HV_BLOCKDEV_PREFIX: "hd",
1155
    },
1156
  HT_KVM: {
1157
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
1158
    HV_INITRD_PATH: '',
1159
    HV_KERNEL_ARGS: 'ro',
1160
    HV_ROOT_PATH: '/dev/vda1',
1161
    HV_ACPI: True,
1162
    HV_SERIAL_CONSOLE: True,
1163
    HV_VNC_BIND_ADDRESS: '',
1164
    HV_VNC_TLS: False,
1165
    HV_VNC_X509: '',
1166
    HV_VNC_X509_VERIFY: False,
1167
    HV_VNC_PASSWORD_FILE: '',
1168
    HV_CDROM_IMAGE_PATH: '',
1169
    HV_BOOT_ORDER: HT_BO_DISK,
1170
    HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
1171
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
1172
    HV_USB_MOUSE: '',
1173
    HV_MIGRATION_PORT: 8102,
1174
    HV_MIGRATION_BANDWIDTH: 32, # MiB/s
1175
    HV_MIGRATION_DOWNTIME: 30,  # ms
1176
    HV_MIGRATION_MODE: HT_MIGRATION_LIVE,
1177
    HV_USE_LOCALTIME: False,
1178
    HV_DISK_CACHE: HT_CACHE_DEFAULT,
1179
    HV_SECURITY_MODEL: HT_SM_NONE,
1180
    HV_SECURITY_DOMAIN: '',
1181
    HV_KVM_FLAG: "",
1182
    HV_VHOST_NET: False,
1183
    HV_KVM_USE_CHROOT: False,
1184
    HV_MEM_PATH: "",
1185
    },
1186
  HT_FAKE: {
1187
    },
1188
  HT_CHROOT: {
1189
    HV_INIT_SCRIPT: "/ganeti-chroot",
1190
    },
1191
  HT_LXC: {
1192
    HV_CPU_MASK: "",
1193
    },
1194
  }
1195

    
1196
HVC_GLOBALS = frozenset([
1197
  HV_MIGRATION_PORT,
1198
  HV_MIGRATION_BANDWIDTH,
1199
  HV_MIGRATION_MODE,
1200
  ])
1201

    
1202
BEC_DEFAULTS = {
1203
  BE_MEMORY: 128,
1204
  BE_VCPUS: 1,
1205
  BE_AUTO_BALANCE: True,
1206
  }
1207

    
1208
NDC_DEFAULTS = {
1209
  ND_OOB_PROGRAM: None,
1210
  }
1211

    
1212
NICC_DEFAULTS = {
1213
  NIC_MODE: NIC_MODE_BRIDGED,
1214
  NIC_LINK: DEFAULT_BRIDGE,
1215
  }
1216

    
1217
MASTER_POOL_SIZE_DEFAULT = 10
1218

    
1219
CONFD_PROTOCOL_VERSION = 1
1220

    
1221
CONFD_REQ_PING = 0
1222
CONFD_REQ_NODE_ROLE_BYNAME = 1
1223
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
1224
CONFD_REQ_CLUSTER_MASTER = 3
1225
CONFD_REQ_NODE_PIP_LIST = 4
1226
CONFD_REQ_MC_PIP_LIST = 5
1227
CONFD_REQ_INSTANCES_IPS_LIST = 6
1228

    
1229
# Confd request query fields. These are used to narrow down queries.
1230
# These must be strings rather than integers, because json-encoding
1231
# converts them to strings anyway, as they're used as dict-keys.
1232
CONFD_REQQ_LINK = "0"
1233
CONFD_REQQ_IP = "1"
1234
CONFD_REQQ_IPLIST = "2"
1235
CONFD_REQQ_FIELDS = "3"
1236

    
1237
CONFD_REQFIELD_NAME = "0"
1238
CONFD_REQFIELD_IP = "1"
1239
CONFD_REQFIELD_MNODE_PIP = "2"
1240

    
1241
CONFD_REQS = frozenset([
1242
  CONFD_REQ_PING,
1243
  CONFD_REQ_NODE_ROLE_BYNAME,
1244
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
1245
  CONFD_REQ_CLUSTER_MASTER,
1246
  CONFD_REQ_NODE_PIP_LIST,
1247
  CONFD_REQ_MC_PIP_LIST,
1248
  CONFD_REQ_INSTANCES_IPS_LIST,
1249
  ])
1250

    
1251
CONFD_REPL_STATUS_OK = 0
1252
CONFD_REPL_STATUS_ERROR = 1
1253
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
1254

    
1255
CONFD_REPL_STATUSES = frozenset([
1256
  CONFD_REPL_STATUS_OK,
1257
  CONFD_REPL_STATUS_ERROR,
1258
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
1259
  ])
1260

    
1261
(CONFD_NODE_ROLE_MASTER,
1262
 CONFD_NODE_ROLE_CANDIDATE,
1263
 CONFD_NODE_ROLE_OFFLINE,
1264
 CONFD_NODE_ROLE_DRAINED,
1265
 CONFD_NODE_ROLE_REGULAR,
1266
 ) = range(5)
1267

    
1268
# A few common errors for confd
1269
CONFD_ERROR_UNKNOWN_ENTRY = 1
1270
CONFD_ERROR_INTERNAL = 2
1271
CONFD_ERROR_ARGUMENT = 3
1272

    
1273
# Each request is "salted" by the current timestamp.
1274
# This constants decides how many seconds of skew to accept.
1275
# TODO: make this a default and allow the value to be more configurable
1276
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
1277

    
1278
# When we haven't reloaded the config for more than this amount of seconds, we
1279
# force a test to see if inotify is betraying us.
1280
CONFD_CONFIG_RELOAD_TIMEOUT = 60
1281

    
1282
# If we receive more than one update in this amount of seconds, we move to
1283
# polling every RATELIMIT seconds, rather than relying on inotify, to be able
1284
# to serve more requests.
1285
CONFD_CONFIG_RELOAD_RATELIMIT = 2
1286

    
1287
# Magic number prepended to all confd queries.
1288
# This allows us to distinguish different types of confd protocols and handle
1289
# them. For example by changing this we can move the whole payload to be
1290
# compressed, or move away from json.
1291
CONFD_MAGIC_FOURCC = 'plj0'
1292

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

    
1298
# Timeout in seconds to expire pending query request in the confd client
1299
# library. We don't actually expect any answer more than 10 seconds after we
1300
# sent a request.
1301
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
1302

    
1303
# Maximum UDP datagram size.
1304
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
1305
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
1306
#   (assuming we can't use jumbo frames)
1307
# We just set this to 60K, which should be enough
1308
MAX_UDP_DATA_SIZE = 61440
1309

    
1310
# User-id pool minimum/maximum acceptable user-ids.
1311
UIDPOOL_UID_MIN = 0
1312
UIDPOOL_UID_MAX = 2**32-1 # Assuming 32 bit user-ids
1313

    
1314
# Name or path of the pgrep command
1315
PGREP = "pgrep"
1316

    
1317
# Name of the node group that gets created at cluster init or upgrade
1318
INITIAL_NODE_GROUP_NAME = "default"
1319

    
1320
# Possible values for NodeGroup.alloc_policy
1321
ALLOC_POLICY_PREFERRED = "preferred"
1322
ALLOC_POLICY_LAST_RESORT = "last_resort"
1323
ALLOC_POLICY_UNALLOCABLE = "unallocable"
1324
VALID_ALLOC_POLICIES = [
1325
  ALLOC_POLICY_PREFERRED,
1326
  ALLOC_POLICY_LAST_RESORT,
1327
  ALLOC_POLICY_UNALLOCABLE,
1328
  ]
1329

    
1330
# Temporary external/shared storage parameters
1331
BLOCKDEV_DRIVER_MANUAL = "manual"
1332

    
1333
# Whether htools was enabled at compilation time
1334
HTOOLS = _autoconf.HTOOLS
1335
# The hail iallocator
1336
IALLOC_HAIL = "hail"