Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ 1b045f5d

History | View | Annotate | Download (27.2 kB)

1
#
2
#
3

    
4
# Copyright (C) 2006, 2007 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
PROTOCOL_VERSION = 40
30
RELEASE_VERSION = _autoconf.PACKAGE_VERSION
31
OS_API_V10 = 10
32
OS_API_V15 = 15
33
OS_API_V20 = 20
34
OS_API_VERSIONS = frozenset([OS_API_V10, OS_API_V15, OS_API_V20])
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
# user separation
87
DAEMONS_GROUP = _autoconf.DAEMONS_GROUP
88
MASTERD_USER = _autoconf.MASTERD_USER
89
RAPI_USER = _autoconf.RAPI_USER
90

    
91
# file paths
92
DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti"
93
RUN_DIR = _autoconf.LOCALSTATEDIR + "/run"
94
RUN_GANETI_DIR = RUN_DIR + "/ganeti"
95
BDEV_CACHE_DIR = RUN_GANETI_DIR + "/bdev-cache"
96
DISK_LINKS_DIR = RUN_GANETI_DIR + "/instance-disks"
97
RUN_DIRS_MODE = 0775
98
SOCKET_DIR = RUN_GANETI_DIR + "/socket"
99
SECURE_DIR_MODE = 0700
100
SOCKET_DIR_MODE = 0750
101
CRYPTO_KEYS_DIR = RUN_GANETI_DIR + "/crypto"
102
CRYPTO_KEYS_DIR_MODE = SECURE_DIR_MODE
103
IMPORT_EXPORT_DIR = RUN_GANETI_DIR + "/import-export"
104
IMPORT_EXPORT_DIR_MODE = 0755
105
# keep RUN_GANETI_DIR first here, to make sure all get created when the node
106
# daemon is started (this takes care of RUN_DIR being tmpfs)
107
SUB_RUN_DIRS = [ RUN_GANETI_DIR, BDEV_CACHE_DIR, DISK_LINKS_DIR ]
108
LOCK_DIR = _autoconf.LOCALSTATEDIR + "/lock"
109
SSCONF_LOCK_FILE = LOCK_DIR + "/ganeti-ssconf.lock"
110
# User-id pool lock directory
111
# The user-ids that are in use have a corresponding lock file in this directory
112
UIDPOOL_LOCKDIR = RUN_GANETI_DIR + "/uid-pool"
113
CLUSTER_CONF_FILE = DATA_DIR + "/config.data"
114
NODED_CERT_FILE = DATA_DIR + "/server.pem"
115
RAPI_CERT_FILE = DATA_DIR + "/rapi.pem"
116
CONFD_HMAC_KEY = DATA_DIR + "/hmac.key"
117
CLUSTER_DOMAIN_SECRET_FILE = DATA_DIR + "/cluster-domain-secret"
118
WATCHER_STATEFILE = DATA_DIR + "/watcher.data"
119
WATCHER_PAUSEFILE = DATA_DIR + "/watcher.pause"
120
INSTANCE_UPFILE = RUN_GANETI_DIR + "/instance-status"
121
SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
122
RAPI_USERS_FILE = DATA_DIR + "/rapi_users"
123
QUEUE_DIR = DATA_DIR + "/queue"
124
DAEMON_UTIL = _autoconf.PKGLIBDIR + "/daemon-util"
125
ETC_HOSTS = "/etc/hosts"
126
DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
127
ENABLE_FILE_STORAGE = _autoconf.ENABLE_FILE_STORAGE
128
SYSCONFDIR = _autoconf.SYSCONFDIR
129
TOOLSDIR = _autoconf.TOOLSDIR
130
CONF_DIR = SYSCONFDIR + "/ganeti"
131

    
132
ALL_CERT_FILES = frozenset([NODED_CERT_FILE, RAPI_CERT_FILE])
133

    
134
MASTER_SOCKET = SOCKET_DIR + "/ganeti-master"
135

    
136
NODED = "ganeti-noded"
137
CONFD = "ganeti-confd"
138
RAPI = "ganeti-rapi"
139
MASTERD = "ganeti-masterd"
140
# used in the ganeti-nbma project
141
NLD = "ganeti-nld"
142

    
143
DAEMONS_PORTS = {
144
  # daemon-name: ("proto", "default-port")
145
  NODED: ("tcp", 1811),
146
  CONFD: ("udp", 1814),
147
  RAPI: ("tcp", 5080),
148
  # used in the ganeti-nbma project
149
  NLD: ("udp", 1816),
150
}
151
DEFAULT_NODED_PORT = DAEMONS_PORTS[NODED][1]
152
DEFAULT_CONFD_PORT = DAEMONS_PORTS[CONFD][1]
153
DEFAULT_RAPI_PORT = DAEMONS_PORTS[RAPI][1]
154
# used in the ganeti-nbma project
155
DEFAULT_NLD_PORT = DAEMONS_PORTS[NLD][1]
156

    
157
FIRST_DRBD_PORT = 11000
158
LAST_DRBD_PORT = 14999
159
MASTER_SCRIPT = "ganeti-master"
160

    
161
LOG_DIR = _autoconf.LOCALSTATEDIR + "/log/ganeti/"
162
DAEMONS_LOGFILES = {
163
  # "daemon-name": "logfile"
164
  NODED: LOG_DIR + "node-daemon.log",
165
  CONFD: LOG_DIR + "conf-daemon.log",
166
  RAPI: LOG_DIR + "rapi-daemon.log",
167
  MASTERD: LOG_DIR + "master-daemon.log",
168
  # used in the ganeti-nbma project
169
  NLD: LOG_DIR + "nl-daemon.log",
170
  }
171

    
172
LOG_OS_DIR = LOG_DIR + "os"
173
LOG_WATCHER = LOG_DIR + "watcher.log"
174
LOG_COMMANDS = LOG_DIR + "commands.log"
175
LOG_BURNIN = LOG_DIR + "burnin.log"
176

    
177
DEV_CONSOLE = "/dev/console"
178

    
179
PROC_MOUNTS = "/proc/mounts"
180

    
181
# luxi related constants
182
LUXI_EOM = "\3"
183

    
184
# one of 'no', 'yes', 'only'
185
SYSLOG_USAGE = _autoconf.SYSLOG_USAGE
186
SYSLOG_NO = "no"
187
SYSLOG_YES = "yes"
188
SYSLOG_ONLY = "only"
189
SYSLOG_SOCKET = "/dev/log"
190

    
191
OS_SEARCH_PATH = _autoconf.OS_SEARCH_PATH
192
EXPORT_DIR = _autoconf.EXPORT_DIR
193

    
194
EXPORT_CONF_FILE = "config.ini"
195

    
196
XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER
197
XEN_KERNEL = _autoconf.XEN_KERNEL
198
XEN_INITRD = _autoconf.XEN_INITRD
199

    
200
KVM_PATH = _autoconf.KVM_PATH
201
SOCAT_PATH = _autoconf.SOCAT_PATH
202
SOCAT_USE_ESCAPE = _autoconf.SOCAT_USE_ESCAPE
203
SOCAT_ESCAPE_CODE = "0x1d"
204

    
205
# For RSA keys more bits are better, but they also make operations more
206
# expensive. NIST SP 800-131 recommends a minimum of 2048 bits from the year
207
# 2010 on.
208
RSA_KEY_BITS = 2048
209

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

    
218
# Digest used to sign certificates ("openssl x509" uses SHA1 by default)
219
X509_CERT_SIGN_DIGEST = "SHA1"
220

    
221
X509_CERT_SIGNATURE_HEADER = "X-Ganeti-Signature"
222

    
223
IMPORT_EXPORT_DAEMON = _autoconf.PKGLIBDIR + "/import-export"
224

    
225
# Import/export daemon mode
226
IEM_IMPORT = "import"
227
IEM_EXPORT = "export"
228

    
229
# Import/export transport compression
230
IEC_NONE = "none"
231
IEC_GZIP = "gzip"
232
IEC_ALL = frozenset([
233
  IEC_NONE,
234
  IEC_GZIP,
235
  ])
236

    
237
IE_CUSTOM_SIZE = "fd"
238

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

    
241
# Import/export I/O
242
# Direct file I/O, equivalent to a shell's I/O redirection using '<' or '>'
243
IEIO_FILE = "file"
244
# Raw block device I/O using "dd"
245
IEIO_RAW_DISK = "raw"
246
# OS definition import/export script
247
IEIO_SCRIPT = "script"
248

    
249
VALUE_DEFAULT = "default"
250
VALUE_AUTO = "auto"
251
VALUE_GENERATE = "generate"
252
VALUE_NONE = "none"
253
VALUE_TRUE = "true"
254
VALUE_FALSE = "false"
255

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

    
259
# hooks-related constants
260
HOOKS_BASE_DIR = CONF_DIR + "/hooks"
261
HOOKS_PHASE_PRE = "pre"
262
HOOKS_PHASE_POST = "post"
263
HOOKS_NAME_CFGUPDATE = "config-update"
264
HOOKS_NAME_WATCHER = "watcher"
265
HOOKS_VERSION = 2
266

    
267
# hooks subject type (what object type does the LU deal with)
268
HTYPE_CLUSTER = "CLUSTER"
269
HTYPE_NODE = "NODE"
270
HTYPE_INSTANCE = "INSTANCE"
271

    
272
HKR_SKIP = 0
273
HKR_FAIL = 1
274
HKR_SUCCESS = 2
275

    
276
# Storage types
277
ST_FILE = "file"
278
ST_LVM_PV = "lvm-pv"
279
ST_LVM_VG = "lvm-vg"
280

    
281
# Storage fields
282
# first two are valid in LU context only, not passed to backend
283
SF_NODE = "node"
284
SF_TYPE = "type"
285
# and the rest are valid in backend
286
SF_NAME = "name"
287
SF_SIZE = "size"
288
SF_FREE = "free"
289
SF_USED = "used"
290
SF_ALLOCATABLE = "allocatable"
291

    
292
# Storage operations
293
SO_FIX_CONSISTENCY = "fix-consistency"
294

    
295
# Available fields per storage type
296
VALID_STORAGE_FIELDS = frozenset([SF_NAME, SF_TYPE, SF_SIZE,
297
                                  SF_USED, SF_FREE, SF_ALLOCATABLE])
298

    
299
VALID_STORAGE_TYPES = frozenset([ST_FILE, ST_LVM_PV, ST_LVM_VG])
300

    
301
MODIFIABLE_STORAGE_FIELDS = {
302
  ST_LVM_PV: frozenset([SF_ALLOCATABLE]),
303
  }
304

    
305
VALID_STORAGE_OPERATIONS = {
306
  ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
307
  }
308

    
309
# Local disk status
310
# Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
311
(LDS_OKAY,
312
 LDS_UNKNOWN,
313
 LDS_FAULTY) = range(1, 4)
314

    
315
# disk template types
316
DT_DISKLESS = "diskless"
317
DT_PLAIN = "plain"
318
DT_DRBD8 = "drbd"
319
DT_FILE = "file"
320

    
321
# the set of network-mirrored disk templates
322
DTS_NET_MIRROR = frozenset([DT_DRBD8])
323

    
324
# the set of non-lvm-based disk templates
325
DTS_NOT_LVM = frozenset([DT_DISKLESS, DT_FILE])
326

    
327
# the set of disk templates which can be grown
328
DTS_GROWABLE = frozenset([DT_PLAIN, DT_DRBD8, DT_FILE])
329

    
330
# the set of disk templates that allow adoption
331
DTS_MAY_ADOPT = frozenset([DT_PLAIN])
332

    
333
# logical disk types
334
LD_LV = "lvm"
335
LD_DRBD8 = "drbd8"
336
LD_FILE = "file"
337
LDS_BLOCK = frozenset([LD_LV, LD_DRBD8])
338

    
339
# drbd constants
340
DRBD_HMAC_ALG = "md5"
341
DRBD_NET_PROTOCOL = "C"
342
DRBD_BARRIERS = _autoconf.DRBD_BARRIERS
343

    
344
# file backend driver
345
FD_LOOP = "loop"
346
FD_BLKTAP = "blktap"
347

    
348
# the set of drbd-like disk types
349
LDS_DRBD = frozenset([LD_DRBD8])
350

    
351
# disk access mode
352
DISK_RDONLY = "ro"
353
DISK_RDWR = "rw"
354
DISK_ACCESS_SET = frozenset([DISK_RDONLY, DISK_RDWR])
355

    
356
# disk replacement mode
357
REPLACE_DISK_PRI = "replace_on_primary"    # replace disks on primary
358
REPLACE_DISK_SEC = "replace_on_secondary"  # replace disks on secondary
359
REPLACE_DISK_CHG = "replace_new_secondary" # change secondary node
360
REPLACE_DISK_AUTO = "replace_auto"
361
REPLACE_MODES = frozenset([
362
  REPLACE_DISK_PRI,
363
  REPLACE_DISK_SEC,
364
  REPLACE_DISK_CHG,
365
  REPLACE_DISK_AUTO,
366
  ])
367

    
368
# Instance export mode
369
EXPORT_MODE_LOCAL = "local"
370
EXPORT_MODE_REMOTE = "remote"
371
EXPORT_MODES = frozenset([
372
  EXPORT_MODE_LOCAL,
373
  EXPORT_MODE_REMOTE,
374
  ])
375

    
376
# lock recalculate mode
377
LOCKS_REPLACE = 'replace'
378
LOCKS_APPEND = 'append'
379

    
380
# instance creation modes
381
INSTANCE_CREATE = "create"
382
INSTANCE_IMPORT = "import"
383
INSTANCE_REMOTE_IMPORT = "remote-import"
384
INSTANCE_CREATE_MODES = frozenset([
385
  INSTANCE_CREATE,
386
  INSTANCE_IMPORT,
387
  INSTANCE_REMOTE_IMPORT,
388
  ])
389

    
390
# Remote import/export handshake message and version
391
RIE_VERSION = 0
392
RIE_HANDSHAKE = "Hi, I'm Ganeti"
393

    
394
# Remote import/export certificate validity in seconds
395
RIE_CERT_VALIDITY = 24 * 60 * 60
396

    
397
# Remote import/export connect timeout for socat
398
RIE_CONNECT_TIMEOUT = 60
399

    
400
DISK_TEMPLATES = frozenset([DT_DISKLESS, DT_PLAIN,
401
                            DT_DRBD8, DT_FILE])
402

    
403
FILE_DRIVER = frozenset([FD_LOOP, FD_BLKTAP])
404

    
405
# import/export config options
406
INISECT_EXP = "export"
407
INISECT_INS = "instance"
408
INISECT_HYP = "hypervisor"
409
INISECT_BEP = "backend"
410
INISECT_OSP = "os"
411

    
412
# dynamic device modification
413
DDM_ADD = 'add'
414
DDM_REMOVE = 'remove'
415

    
416
# common exit codes
417
EXIT_SUCCESS = 0
418
EXIT_FAILURE = 1
419
EXIT_NOTCLUSTER = 5
420
EXIT_NOTMASTER = 11
421
EXIT_NODESETUP_ERROR = 12
422
EXIT_CONFIRMATION = 13 # need user confirmation
423

    
424
# tags
425
TAG_CLUSTER = "cluster"
426
TAG_NODE = "node"
427
TAG_INSTANCE = "instance"
428
VALID_TAG_TYPES = frozenset([
429
  TAG_CLUSTER,
430
  TAG_NODE,
431
  TAG_INSTANCE,
432
  ])
433
MAX_TAG_LEN = 128
434
MAX_TAGS_PER_OBJ = 4096
435

    
436
# others
437
DEFAULT_BRIDGE = "xen-br0"
438
SYNC_SPEED = 60 * 1024
439
IP4_ADDRESS_LOCALHOST = "127.0.0.1"
440
IP4_ADDRESS_ANY = "0.0.0.0"
441
IP6_ADDRESS_LOCALHOST = "::1"
442
IP6_ADDRESS_ANY = "::"
443
TCP_PING_TIMEOUT = 10
444
GANETI_RUNAS = "root"
445
DEFAULT_VG = "xenvg"
446
DEFAULT_DRBD_HELPER = "/bin/true"
447
MIN_VG_SIZE = 20480
448
DEFAULT_MAC_PREFIX = "aa:00:00"
449
LVM_STRIPECOUNT = _autoconf.LVM_STRIPECOUNT
450
# default maximum instance wait time, in seconds.
451
DEFAULT_SHUTDOWN_TIMEOUT = 120
452
NODE_MAX_CLOCK_SKEW = 150
453
# Time for an intra-cluster disk transfer to wait for a connection
454
DISK_TRANSFER_CONNECT_TIMEOUT = 30
455

    
456
# runparts results
457
(RUNPARTS_SKIP,
458
 RUNPARTS_RUN,
459
 RUNPARTS_ERR) = range(3)
460

    
461
RUNPARTS_STATUS = frozenset([RUNPARTS_SKIP, RUNPARTS_RUN, RUNPARTS_ERR])
462

    
463
# RPC constants
464
(RPC_ENCODING_NONE,
465
 RPC_ENCODING_ZLIB_BASE64) = range(2)
466

    
467
# os related constants
468
OS_SCRIPT_CREATE = 'create'
469
OS_SCRIPT_IMPORT = 'import'
470
OS_SCRIPT_EXPORT = 'export'
471
OS_SCRIPT_RENAME = 'rename'
472
OS_SCRIPT_VERIFY = 'verify'
473
OS_SCRIPTS = frozenset([OS_SCRIPT_CREATE, OS_SCRIPT_IMPORT,
474
                        OS_SCRIPT_EXPORT, OS_SCRIPT_RENAME,
475
                        OS_SCRIPT_VERIFY])
476

    
477
OS_API_FILE = 'ganeti_api_version'
478
OS_VARIANTS_FILE = 'variants.list'
479
OS_PARAMETERS_FILE = 'parameters.list'
480

    
481
OS_VALIDATE_PARAMETERS = 'parameters'
482
OS_VALIDATE_CALLS = frozenset([OS_VALIDATE_PARAMETERS])
483

    
484
# ssh constants
485
SSH_CONFIG_DIR = _autoconf.SSH_CONFIG_DIR
486
SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_dsa_key"
487
SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
488
SSH_HOST_RSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_rsa_key"
489
SSH_HOST_RSA_PUB = SSH_HOST_RSA_PRIV + ".pub"
490
SSH = "ssh"
491
SCP = "scp"
492

    
493
# reboot types
494
INSTANCE_REBOOT_SOFT = "soft"
495
INSTANCE_REBOOT_HARD = "hard"
496
INSTANCE_REBOOT_FULL = "full"
497

    
498
REBOOT_TYPES = frozenset([INSTANCE_REBOOT_SOFT,
499
                          INSTANCE_REBOOT_HARD,
500
                          INSTANCE_REBOOT_FULL])
501

    
502
VTYPE_STRING = 'string'
503
VTYPE_BOOL = 'bool'
504
VTYPE_SIZE = 'size' # size, in MiBs
505
VTYPE_INT = 'int'
506
ENFORCEABLE_TYPES = frozenset([
507
                      VTYPE_STRING,
508
                      VTYPE_BOOL,
509
                      VTYPE_SIZE,
510
                      VTYPE_INT,
511
                      ])
512

    
513
# HV parameter names (global namespace)
514
HV_BOOT_ORDER = "boot_order"
515
HV_CDROM_IMAGE_PATH = "cdrom_image_path"
516
HV_NIC_TYPE = "nic_type"
517
HV_DISK_TYPE = "disk_type"
518
HV_VNC_BIND_ADDRESS = "vnc_bind_address"
519
HV_VNC_PASSWORD_FILE = "vnc_password_file"
520
HV_VNC_TLS = "vnc_tls"
521
HV_VNC_X509 = "vnc_x509_path"
522
HV_VNC_X509_VERIFY = "vnc_x509_verify"
523
HV_ACPI = "acpi"
524
HV_PAE = "pae"
525
HV_USE_BOOTLOADER = "use_bootloader"
526
HV_BOOTLOADER_ARGS = "bootloader_args"
527
HV_BOOTLOADER_PATH = "bootloader_path"
528
HV_KERNEL_ARGS = "kernel_args"
529
HV_KERNEL_PATH = "kernel_path"
530
HV_INITRD_PATH = "initrd_path"
531
HV_ROOT_PATH = "root_path"
532
HV_SERIAL_CONSOLE = "serial_console"
533
HV_USB_MOUSE = "usb_mouse"
534
HV_DEVICE_MODEL = "device_model"
535
HV_INIT_SCRIPT = "init_script"
536
HV_MIGRATION_PORT = "migration_port"
537
HV_MIGRATION_BANDWIDTH = "migration_bandwidth"
538
HV_MIGRATION_DOWNTIME = "migration_downtime"
539
HV_USE_LOCALTIME = "use_localtime"
540
HV_DISK_CACHE = "disk_cache"
541
HV_SECURITY_MODEL = "security_model"
542
HV_SECURITY_DOMAIN = "security_domain"
543
HV_KVM_FLAG = "kvm_flag"
544
HV_VHOST_NET = "vhost_net"
545
HV_KVM_USE_CHROOT = "use_chroot"
546

    
547
HVS_PARAMETER_TYPES = {
548
  HV_BOOT_ORDER: VTYPE_STRING,
549
  HV_CDROM_IMAGE_PATH: VTYPE_STRING,
550
  HV_NIC_TYPE: VTYPE_STRING,
551
  HV_DISK_TYPE: VTYPE_STRING,
552
  HV_VNC_PASSWORD_FILE: VTYPE_STRING,
553
  HV_VNC_BIND_ADDRESS: VTYPE_STRING,
554
  HV_VNC_TLS: VTYPE_BOOL,
555
  HV_VNC_X509: VTYPE_STRING,
556
  HV_VNC_X509_VERIFY: VTYPE_BOOL,
557
  HV_ACPI: VTYPE_BOOL,
558
  HV_PAE: VTYPE_BOOL,
559
  HV_USE_BOOTLOADER: VTYPE_BOOL,
560
  HV_BOOTLOADER_PATH: VTYPE_STRING,
561
  HV_BOOTLOADER_ARGS: VTYPE_STRING,
562
  HV_KERNEL_PATH: VTYPE_STRING,
563
  HV_KERNEL_ARGS: VTYPE_STRING,
564
  HV_INITRD_PATH: VTYPE_STRING,
565
  HV_ROOT_PATH: VTYPE_STRING,
566
  HV_SERIAL_CONSOLE: VTYPE_BOOL,
567
  HV_USB_MOUSE: VTYPE_STRING,
568
  HV_DEVICE_MODEL: VTYPE_STRING,
569
  HV_INIT_SCRIPT: VTYPE_STRING,
570
  HV_MIGRATION_PORT: VTYPE_INT,
571
  HV_MIGRATION_BANDWIDTH: VTYPE_INT,
572
  HV_MIGRATION_DOWNTIME: VTYPE_INT,
573
  HV_USE_LOCALTIME: VTYPE_BOOL,
574
  HV_DISK_CACHE: VTYPE_STRING,
575
  HV_SECURITY_MODEL: VTYPE_STRING,
576
  HV_SECURITY_DOMAIN: VTYPE_STRING,
577
  HV_KVM_FLAG: VTYPE_STRING,
578
  HV_VHOST_NET: VTYPE_BOOL,
579
  HV_KVM_USE_CHROOT: VTYPE_BOOL,
580
  }
581

    
582
HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
583

    
584
# BE parameter names
585
BE_MEMORY = "memory"
586
BE_VCPUS = "vcpus"
587
BE_AUTO_BALANCE = "auto_balance"
588

    
589
BES_PARAMETER_TYPES = {
590
    BE_MEMORY: VTYPE_SIZE,
591
    BE_VCPUS: VTYPE_INT,
592
    BE_AUTO_BALANCE: VTYPE_BOOL,
593
    }
594

    
595
BES_PARAMETERS = frozenset(BES_PARAMETER_TYPES.keys())
596

    
597
# Instance Parameters Profile
598
PP_DEFAULT = "default"
599

    
600
NIC_MODE = "mode"
601
NIC_LINK = "link"
602

    
603
NIC_MODE_BRIDGED = "bridged"
604
NIC_MODE_ROUTED = "routed"
605

    
606
NIC_VALID_MODES = frozenset([NIC_MODE_BRIDGED, NIC_MODE_ROUTED])
607

    
608
NICS_PARAMETER_TYPES = {
609
    NIC_MODE: VTYPE_STRING,
610
    NIC_LINK: VTYPE_STRING,
611
    }
612

    
613
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
614

    
615
IDISK_SIZE = "size"
616
IDISK_MODE = "mode"
617
IDISK_ADOPT = "adopt"
618
IDISK_PARAMS = frozenset([IDISK_SIZE, IDISK_MODE, IDISK_ADOPT])
619
IDISK_PARAMS_TYPES = {
620
  IDISK_SIZE: VTYPE_SIZE,
621
  IDISK_MODE: VTYPE_STRING,
622
  IDISK_ADOPT: VTYPE_STRING,
623
  }
624
INIC_MAC = "mac"
625
INIC_IP = "ip"
626
INIC_MODE = "mode"
627
INIC_LINK = "link"
628
INIC_BRIDGE = "bridge"
629
INIC_PARAMS = frozenset([INIC_MAC, INIC_IP, INIC_MODE, INIC_LINK, INIC_BRIDGE])
630
INIC_PARAMS_TYPES = dict([(name, VTYPE_STRING) for name in INIC_PARAMS])
631

    
632
# Hypervisor constants
633
HT_XEN_PVM = "xen-pvm"
634
HT_FAKE = "fake"
635
HT_XEN_HVM = "xen-hvm"
636
HT_KVM = "kvm"
637
HT_CHROOT = "chroot"
638
HT_LXC = "lxc"
639
HYPER_TYPES = frozenset([
640
  HT_XEN_PVM,
641
  HT_FAKE,
642
  HT_XEN_HVM,
643
  HT_KVM,
644
  HT_CHROOT,
645
  HT_LXC,
646
  ])
647
HTS_REQ_PORT = frozenset([HT_XEN_HVM, HT_KVM])
648

    
649
VNC_BASE_PORT = 5900
650
VNC_PASSWORD_FILE = CONF_DIR + "/vnc-cluster-password"
651
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
652

    
653
# NIC types
654
HT_NIC_RTL8139 = "rtl8139"
655
HT_NIC_NE2K_PCI = "ne2k_pci"
656
HT_NIC_NE2K_ISA = "ne2k_isa"
657
HT_NIC_I82551 = "i82551"
658
HT_NIC_I85557B = "i82557b"
659
HT_NIC_I8259ER = "i82559er"
660
HT_NIC_PCNET = "pcnet"
661
HT_NIC_E1000 = "e1000"
662
HT_NIC_PARAVIRTUAL = HT_DISK_PARAVIRTUAL = "paravirtual"
663

    
664
HT_HVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
665
                                    HT_NIC_NE2K_ISA, HT_NIC_PARAVIRTUAL])
666
HT_KVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
667
                                    HT_NIC_NE2K_ISA, HT_NIC_I82551,
668
                                    HT_NIC_I85557B, HT_NIC_I8259ER,
669
                                    HT_NIC_PCNET, HT_NIC_E1000,
670
                                    HT_NIC_PARAVIRTUAL])
671
# Disk types
672
HT_DISK_IOEMU = "ioemu"
673
HT_DISK_IDE = "ide"
674
HT_DISK_SCSI = "scsi"
675
HT_DISK_SD = "sd"
676
HT_DISK_MTD = "mtd"
677
HT_DISK_PFLASH = "pflash"
678

    
679
HT_CACHE_DEFAULT = "default"
680
HT_CACHE_NONE = "none"
681
HT_CACHE_WTHROUGH = "writethrough"
682
HT_CACHE_WBACK = "writeback"
683
HT_VALID_CACHE_TYPES = frozenset([HT_CACHE_DEFAULT,
684
                                  HT_CACHE_NONE,
685
                                  HT_CACHE_WTHROUGH,
686
                                  HT_CACHE_WBACK])
687

    
688
HT_HVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IOEMU])
689
HT_KVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IDE,
690
                                     HT_DISK_SCSI, HT_DISK_SD, HT_DISK_MTD,
691
                                     HT_DISK_PFLASH])
692

    
693
# Mouse types:
694
HT_MOUSE_MOUSE = "mouse"
695
HT_MOUSE_TABLET = "tablet"
696

    
697
HT_KVM_VALID_MOUSE_TYPES = frozenset([HT_MOUSE_MOUSE, HT_MOUSE_TABLET])
698

    
699
# Boot order
700
HT_BO_CDROM = "cdrom"
701
HT_BO_DISK = "disk"
702
HT_BO_NETWORK = "network"
703

    
704
HT_KVM_VALID_BO_TYPES = frozenset([HT_BO_CDROM, HT_BO_DISK, HT_BO_NETWORK])
705

    
706
# Security models
707
HT_SM_NONE = "none"
708
HT_SM_USER = "user"
709
HT_SM_POOL = "pool"
710

    
711
HT_KVM_VALID_SM_TYPES = frozenset([HT_SM_NONE, HT_SM_USER, HT_SM_POOL])
712

    
713
# Kvm flag values
714
HT_KVM_ENABLED = "enabled"
715
HT_KVM_DISABLED = "disabled"
716

    
717
HT_KVM_FLAG_VALUES = frozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
718

    
719
# Cluster Verify steps
720
VERIFY_NPLUSONE_MEM = 'nplusone_mem'
721
VERIFY_OPTIONAL_CHECKS = frozenset([VERIFY_NPLUSONE_MEM])
722

    
723
# Node verify constants
724
NV_DRBDHELPER = "drbd-helper"
725
NV_DRBDLIST = "drbd-list"
726
NV_FILELIST = "filelist"
727
NV_HVINFO = "hvinfo"
728
NV_HYPERVISOR = "hypervisor"
729
NV_INSTANCELIST = "instancelist"
730
NV_LVLIST = "lvlist"
731
NV_MASTERIP = "master-ip"
732
NV_NODELIST = "nodelist"
733
NV_NODENETTEST = "node-net-test"
734
NV_NODESETUP = "nodesetup"
735
NV_OSLIST = "oslist"
736
NV_PVLIST = "pvlist"
737
NV_TIME = "time"
738
NV_VERSION = "version"
739
NV_VGLIST = "vglist"
740

    
741
# SSL certificate check constants (in days)
742
SSL_CERT_EXPIRATION_WARN = 30
743
SSL_CERT_EXPIRATION_ERROR = 7
744

    
745
# Allocator framework constants
746
IALLOCATOR_VERSION = 2
747
IALLOCATOR_DIR_IN = "in"
748
IALLOCATOR_DIR_OUT = "out"
749
VALID_IALLOCATOR_DIRECTIONS = frozenset([
750
  IALLOCATOR_DIR_IN,
751
  IALLOCATOR_DIR_OUT,
752
  ])
753
IALLOCATOR_MODE_ALLOC = "allocate"
754
IALLOCATOR_MODE_RELOC = "relocate"
755
IALLOCATOR_MODE_MEVAC = "multi-evacuate"
756
VALID_IALLOCATOR_MODES = frozenset([
757
  IALLOCATOR_MODE_ALLOC,
758
  IALLOCATOR_MODE_RELOC,
759
  IALLOCATOR_MODE_MEVAC,
760
  ])
761
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
762

    
763
# Job queue
764
JOB_QUEUE_VERSION = 1
765
JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock"
766
JOB_QUEUE_VERSION_FILE = QUEUE_DIR + "/version"
767
JOB_QUEUE_SERIAL_FILE = QUEUE_DIR + "/serial"
768
JOB_QUEUE_ARCHIVE_DIR = QUEUE_DIR + "/archive"
769
JOB_QUEUE_DRAIN_FILE = QUEUE_DIR + "/drain"
770
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
771
JOB_QUEUE_DIRS = [QUEUE_DIR, JOB_QUEUE_ARCHIVE_DIR]
772
JOB_QUEUE_DIRS_MODE = SECURE_DIR_MODE
773

    
774
JOB_ID_TEMPLATE = r"\d+"
775

    
776
# unchanged job return
777
JOB_NOTCHANGED = "nochange"
778

    
779
# Job status
780
JOB_STATUS_QUEUED = "queued"
781
JOB_STATUS_WAITLOCK = "waiting"
782
JOB_STATUS_CANCELING = "canceling"
783
JOB_STATUS_RUNNING = "running"
784
JOB_STATUS_CANCELED = "canceled"
785
JOB_STATUS_SUCCESS = "success"
786
JOB_STATUS_ERROR = "error"
787

    
788
# OpCode status
789
# not yet finalized
790
OP_STATUS_QUEUED = "queued"
791
OP_STATUS_WAITLOCK = "waiting"
792
OP_STATUS_CANCELING = "canceling"
793
OP_STATUS_RUNNING = "running"
794
# finalized
795
OP_STATUS_CANCELED = "canceled"
796
OP_STATUS_SUCCESS = "success"
797
OP_STATUS_ERROR = "error"
798
OPS_FINALIZED = frozenset([OP_STATUS_CANCELED,
799
                           OP_STATUS_SUCCESS,
800
                           OP_STATUS_ERROR])
801

    
802
# Execution log types
803
ELOG_MESSAGE = "message"
804
ELOG_PROGRESS = "progress"
805
ELOG_REMOTE_IMPORT = "remote-import"
806

    
807
# max dynamic devices
808
MAX_NICS = 8
809
MAX_DISKS = 16
810

    
811
# SSCONF keys
812
SS_CLUSTER_NAME = "cluster_name"
813
SS_CLUSTER_TAGS = "cluster_tags"
814
SS_FILE_STORAGE_DIR = "file_storage_dir"
815
SS_MASTER_CANDIDATES = "master_candidates"
816
SS_MASTER_CANDIDATES_IPS = "master_candidates_ips"
817
SS_MASTER_IP = "master_ip"
818
SS_MASTER_NETDEV = "master_netdev"
819
SS_MASTER_NODE = "master_node"
820
SS_NODE_LIST = "node_list"
821
SS_NODE_PRIMARY_IPS = "node_primary_ips"
822
SS_NODE_SECONDARY_IPS = "node_secondary_ips"
823
SS_OFFLINE_NODES = "offline_nodes"
824
SS_ONLINE_NODES = "online_nodes"
825
SS_INSTANCE_LIST = "instance_list"
826
SS_RELEASE_VERSION = "release_version"
827
SS_HYPERVISOR_LIST = "hypervisor_list"
828
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
829
SS_UID_POOL = "uid_pool"
830

    
831
# cluster wide default parameters
832
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
833

    
834
HVC_DEFAULTS = {
835
  HT_XEN_PVM: {
836
    HV_USE_BOOTLOADER: False,
837
    HV_BOOTLOADER_PATH: XEN_BOOTLOADER,
838
    HV_BOOTLOADER_ARGS: '',
839
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-xenU",
840
    HV_INITRD_PATH: '',
841
    HV_ROOT_PATH: '/dev/sda1',
842
    HV_KERNEL_ARGS: 'ro',
843
    HV_MIGRATION_PORT: 8002,
844
    },
845
  HT_XEN_HVM: {
846
    HV_BOOT_ORDER: "cd",
847
    HV_CDROM_IMAGE_PATH: '',
848
    HV_NIC_TYPE: HT_NIC_RTL8139,
849
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
850
    HV_VNC_BIND_ADDRESS: IP4_ADDRESS_ANY,
851
    HV_VNC_PASSWORD_FILE: VNC_PASSWORD_FILE,
852
    HV_ACPI: True,
853
    HV_PAE: True,
854
    HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
855
    HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
856
    HV_MIGRATION_PORT: 8002,
857
    HV_USE_LOCALTIME: False,
858
    },
859
  HT_KVM: {
860
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
861
    HV_INITRD_PATH: '',
862
    HV_KERNEL_ARGS: 'ro',
863
    HV_ROOT_PATH: '/dev/vda1',
864
    HV_ACPI: True,
865
    HV_SERIAL_CONSOLE: True,
866
    HV_VNC_BIND_ADDRESS: '',
867
    HV_VNC_TLS: False,
868
    HV_VNC_X509: '',
869
    HV_VNC_X509_VERIFY: False,
870
    HV_VNC_PASSWORD_FILE: '',
871
    HV_CDROM_IMAGE_PATH: '',
872
    HV_BOOT_ORDER: HT_BO_DISK,
873
    HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
874
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
875
    HV_USB_MOUSE: '',
876
    HV_MIGRATION_PORT: 8102,
877
    HV_MIGRATION_BANDWIDTH: 32, # MiB/s
878
    HV_MIGRATION_DOWNTIME: 30,  # ms
879
    HV_USE_LOCALTIME: False,
880
    HV_DISK_CACHE: HT_CACHE_DEFAULT,
881
    HV_SECURITY_MODEL: HT_SM_NONE,
882
    HV_SECURITY_DOMAIN: '',
883
    HV_KVM_FLAG: "",
884
    HV_VHOST_NET: False,
885
    HV_KVM_USE_CHROOT: False,
886
    },
887
  HT_FAKE: {
888
    },
889
  HT_CHROOT: {
890
    HV_INIT_SCRIPT: "/ganeti-chroot",
891
    },
892
  HT_LXC: {
893
    },
894
  }
895

    
896
HVC_GLOBALS = frozenset([
897
  HV_MIGRATION_PORT,
898
  HV_MIGRATION_BANDWIDTH,
899
  ])
900

    
901
BEC_DEFAULTS = {
902
  BE_MEMORY: 128,
903
  BE_VCPUS: 1,
904
  BE_AUTO_BALANCE: True,
905
  }
906

    
907
NICC_DEFAULTS = {
908
  NIC_MODE: NIC_MODE_BRIDGED,
909
  NIC_LINK: DEFAULT_BRIDGE,
910
  }
911

    
912
MASTER_POOL_SIZE_DEFAULT = 10
913

    
914
CONFD_PROTOCOL_VERSION = 1
915

    
916
CONFD_REQ_PING = 0
917
CONFD_REQ_NODE_ROLE_BYNAME = 1
918
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
919
CONFD_REQ_CLUSTER_MASTER = 3
920
CONFD_REQ_NODE_PIP_LIST = 4
921
CONFD_REQ_MC_PIP_LIST = 5
922
CONFD_REQ_INSTANCES_IPS_LIST = 6
923

    
924
# Confd request query fields. These are used to narrow down queries.
925
# These must be strings rather than integers, because json-encoding
926
# converts them to strings anyway, as they're used as dict-keys.
927
CONFD_REQQ_LINK = "0"
928
CONFD_REQQ_IP = "1"
929
CONFD_REQQ_IPLIST = "2"
930
CONFD_REQQ_FIELDS = "3"
931

    
932
CONFD_REQFIELD_NAME = "0"
933
CONFD_REQFIELD_IP = "1"
934
CONFD_REQFIELD_MNODE_PIP = "2"
935

    
936
CONFD_REQS = frozenset([
937
  CONFD_REQ_PING,
938
  CONFD_REQ_NODE_ROLE_BYNAME,
939
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
940
  CONFD_REQ_CLUSTER_MASTER,
941
  CONFD_REQ_NODE_PIP_LIST,
942
  CONFD_REQ_MC_PIP_LIST,
943
  CONFD_REQ_INSTANCES_IPS_LIST,
944
  ])
945

    
946
CONFD_REPL_STATUS_OK = 0
947
CONFD_REPL_STATUS_ERROR = 1
948
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
949

    
950
CONFD_REPL_STATUSES = frozenset([
951
  CONFD_REPL_STATUS_OK,
952
  CONFD_REPL_STATUS_ERROR,
953
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
954
  ])
955

    
956
(CONFD_NODE_ROLE_MASTER,
957
 CONFD_NODE_ROLE_CANDIDATE,
958
 CONFD_NODE_ROLE_OFFLINE,
959
 CONFD_NODE_ROLE_DRAINED,
960
 CONFD_NODE_ROLE_REGULAR,
961
 ) = range(5)
962

    
963
# A few common errors for confd
964
CONFD_ERROR_UNKNOWN_ENTRY = 1
965
CONFD_ERROR_INTERNAL = 2
966
CONFD_ERROR_ARGUMENT = 3
967

    
968
# Each request is "salted" by the current timestamp.
969
# This constants decides how many seconds of skew to accept.
970
# TODO: make this a default and allow the value to be more configurable
971
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
972

    
973
# When we haven't reloaded the config for more than this amount of seconds, we
974
# force a test to see if inotify is betraying us.
975
CONFD_CONFIG_RELOAD_TIMEOUT = 60
976

    
977
# If we receive more than one update in this amount of seconds, we move to
978
# polling every RATELIMIT seconds, rather than relying on inotify, to be able
979
# to serve more requests.
980
CONFD_CONFIG_RELOAD_RATELIMIT = 2
981

    
982
# Magic number prepended to all confd queries.
983
# This allows us to distinguish different types of confd protocols and handle
984
# them. For example by changing this we can move the whole payload to be
985
# compressed, or move away from json.
986
CONFD_MAGIC_FOURCC = 'plj0'
987

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

    
993
# Timeout in seconds to expire pending query request in the confd client
994
# library. We don't actually expect any answer more than 10 seconds after we
995
# sent a request.
996
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
997

    
998
# Maximum UDP datagram size.
999
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
1000
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
1001
#   (assuming we can't use jumbo frames)
1002
# We just set this to 60K, which should be enough
1003
MAX_UDP_DATA_SIZE = 61440
1004

    
1005
# User-id pool minimum/maximum acceptable user-ids.
1006
UIDPOOL_UID_MIN = 0
1007
UIDPOOL_UID_MAX = 2**32-1 # Assuming 32 bit user-ids
1008

    
1009
# Name or path of the pgrep command
1010
PGREP = "pgrep"