Statistics
| Branch: | Tag: | Revision:

root / lib / constants.py @ 9bf56d77

History | View | Annotate | Download (24.7 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 = 30
30
RELEASE_VERSION = _autoconf.PACKAGE_VERSION
31
OS_API_V10 = 10
32
OS_API_V15 = 15
33
OS_API_VERSIONS = frozenset([OS_API_V10, OS_API_V15])
34
EXPORT_VERSION = 0
35
RAPI_VERSION = 2
36

    
37

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

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

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

55
  Returns: int representing version number
56

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

    
65

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

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

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

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

    
77
  return (major, minor, revision)
78

    
79

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

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

    
126
ALL_CERT_FILES = frozenset([NODED_CERT_FILE, RAPI_CERT_FILE])
127

    
128
MASTER_SOCKET = SOCKET_DIR + "/ganeti-master"
129

    
130
NODED = "ganeti-noded"
131
CONFD = "ganeti-confd"
132
RAPI = "ganeti-rapi"
133
MASTERD = "ganeti-masterd"
134
# used in the ganeti-nbma project
135
NLD = "ganeti-nld"
136

    
137
DAEMONS_PORTS = {
138
  # daemon-name: ("proto", "default-port")
139
  NODED: ("tcp", 1811),
140
  CONFD: ("udp", 1814),
141
  RAPI: ("tcp", 5080),
142
  # used in the ganeti-nbma project
143
  NLD: ("udp", 1816),
144
}
145
DEFAULT_NODED_PORT = DAEMONS_PORTS[NODED][1]
146
DEFAULT_CONFD_PORT = DAEMONS_PORTS[CONFD][1]
147
DEFAULT_RAPI_PORT = DAEMONS_PORTS[RAPI][1]
148
# used in the ganeti-nbma project
149
DEFAULT_NLD_PORT = DAEMONS_PORTS[NLD][1]
150

    
151
FIRST_DRBD_PORT = 11000
152
LAST_DRBD_PORT = 14999
153
MASTER_SCRIPT = "ganeti-master"
154

    
155
LOG_DIR = _autoconf.LOCALSTATEDIR + "/log/ganeti/"
156
DAEMONS_LOGFILES = {
157
  # "daemon-name": "logfile"
158
  NODED: LOG_DIR + "node-daemon.log",
159
  CONFD: LOG_DIR + "conf-daemon.log",
160
  RAPI: LOG_DIR + "rapi-daemon.log",
161
  MASTERD: LOG_DIR + "master-daemon.log",
162
  # used in the ganeti-nbma project
163
  NLD: LOG_DIR + "nl-daemon.log",
164
  }
165

    
166
LOG_OS_DIR = LOG_DIR + "os"
167
LOG_WATCHER = LOG_DIR + "watcher.log"
168
LOG_COMMANDS = LOG_DIR + "commands.log"
169
LOG_BURNIN = LOG_DIR + "burnin.log"
170

    
171
DEV_CONSOLE = "/dev/console"
172

    
173
# luxi related constants
174
LUXI_EOM = "\3"
175

    
176
# one of 'no', 'yes', 'only'
177
SYSLOG_USAGE = _autoconf.SYSLOG_USAGE
178
SYSLOG_NO = "no"
179
SYSLOG_YES = "yes"
180
SYSLOG_ONLY = "only"
181
SYSLOG_SOCKET = "/dev/log"
182

    
183
OS_SEARCH_PATH = _autoconf.OS_SEARCH_PATH
184
EXPORT_DIR = _autoconf.EXPORT_DIR
185

    
186
EXPORT_CONF_FILE = "config.ini"
187

    
188
XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER
189
XEN_KERNEL = _autoconf.XEN_KERNEL
190
XEN_INITRD = _autoconf.XEN_INITRD
191

    
192
KVM_PATH = _autoconf.KVM_PATH
193
SOCAT_PATH = _autoconf.SOCAT_PATH
194
SOCAT_USE_ESCAPE = _autoconf.SOCAT_USE_ESCAPE
195
SOCAT_ESCAPE_CODE = "0x1d"
196

    
197
# For RSA keys more bits are better, but they also make operations more
198
# expensive. NIST SP 800-131 recommends a minimum of 2048 bits from the year
199
# 2010 on.
200
RSA_KEY_BITS = 2048
201

    
202
# Digest used to sign certificates ("openssl x509" uses SHA1 by default)
203
X509_CERT_SIGN_DIGEST = "SHA1"
204

    
205
X509_CERT_SIGNATURE_HEADER = "X-Ganeti-Signature"
206

    
207
IMPORT_EXPORT_DAEMON = _autoconf.PKGLIBDIR + "/import-export"
208

    
209
# Import/export daemon mode
210
IEM_IMPORT = "import"
211
IEM_EXPORT = "export"
212

    
213
# Import/export I/O
214
# Direct file I/O, equivalent to a shell's I/O redirection using '<' or '>'
215
IEIO_FILE = "file"
216
# Raw block device I/O using "dd"
217
IEIO_RAW_DISK = "raw"
218
# OS definition import/export script
219
IEIO_SCRIPT = "script"
220

    
221
VALUE_DEFAULT = "default"
222
VALUE_AUTO = "auto"
223
VALUE_GENERATE = "generate"
224
VALUE_NONE = "none"
225
VALUE_TRUE = "true"
226
VALUE_FALSE = "false"
227

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

    
231
# hooks-related constants
232
HOOKS_BASE_DIR = CONF_DIR + "/hooks"
233
HOOKS_PHASE_PRE = "pre"
234
HOOKS_PHASE_POST = "post"
235
HOOKS_NAME_CFGUPDATE = "config-update"
236
HOOKS_NAME_WATCHER = "watcher"
237
HOOKS_VERSION = 2
238

    
239
# hooks subject type (what object type does the LU deal with)
240
HTYPE_CLUSTER = "CLUSTER"
241
HTYPE_NODE = "NODE"
242
HTYPE_INSTANCE = "INSTANCE"
243

    
244
HKR_SKIP = 0
245
HKR_FAIL = 1
246
HKR_SUCCESS = 2
247

    
248
# Storage types
249
ST_FILE = "file"
250
ST_LVM_PV = "lvm-pv"
251
ST_LVM_VG = "lvm-vg"
252

    
253
# Storage fields
254
# first two are valid in LU context only, not passed to backend
255
SF_NODE = "node"
256
SF_TYPE = "type"
257
# and the rest are valid in backend
258
SF_NAME = "name"
259
SF_SIZE = "size"
260
SF_FREE = "free"
261
SF_USED = "used"
262
SF_ALLOCATABLE = "allocatable"
263

    
264
# Storage operations
265
SO_FIX_CONSISTENCY = "fix-consistency"
266

    
267
# Available fields per storage type
268
VALID_STORAGE_FIELDS = frozenset([SF_NAME, SF_TYPE, SF_SIZE,
269
                                  SF_USED, SF_FREE, SF_ALLOCATABLE])
270

    
271
VALID_STORAGE_TYPES = frozenset([ST_FILE, ST_LVM_PV, ST_LVM_VG])
272

    
273
MODIFIABLE_STORAGE_FIELDS = {
274
  ST_LVM_PV: frozenset([SF_ALLOCATABLE]),
275
  }
276

    
277
VALID_STORAGE_OPERATIONS = {
278
  ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
279
  }
280

    
281
# Local disk status
282
# Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
283
(LDS_OKAY,
284
 LDS_UNKNOWN,
285
 LDS_FAULTY) = range(1, 4)
286

    
287
# disk template types
288
DT_DISKLESS = "diskless"
289
DT_PLAIN = "plain"
290
DT_DRBD8 = "drbd"
291
DT_FILE = "file"
292

    
293
# the set of network-mirrored disk templates
294
DTS_NET_MIRROR = frozenset([DT_DRBD8])
295

    
296
# the set of non-lvm-based disk templates
297
DTS_NOT_LVM = frozenset([DT_DISKLESS, DT_FILE])
298

    
299
# the set of disk templates which can be grown
300
DTS_GROWABLE = frozenset([DT_PLAIN, DT_DRBD8, DT_FILE])
301

    
302
# logical disk types
303
LD_LV = "lvm"
304
LD_DRBD8 = "drbd8"
305
LD_FILE = "file"
306
LDS_BLOCK = frozenset([LD_LV, LD_DRBD8])
307

    
308
# drbd constants
309
DRBD_HMAC_ALG = "md5"
310
DRBD_NET_PROTOCOL = "C"
311
DRBD_BARRIERS = _autoconf.DRBD_BARRIERS
312

    
313
# file backend driver
314
FD_LOOP = "loop"
315
FD_BLKTAP = "blktap"
316

    
317
# the set of drbd-like disk types
318
LDS_DRBD = frozenset([LD_DRBD8])
319

    
320
# disk access mode
321
DISK_RDONLY = "ro"
322
DISK_RDWR = "rw"
323
DISK_ACCESS_SET = frozenset([DISK_RDONLY, DISK_RDWR])
324

    
325
# disk replacement mode
326
REPLACE_DISK_PRI = "replace_on_primary"    # replace disks on primary
327
REPLACE_DISK_SEC = "replace_on_secondary"  # replace disks on secondary
328
REPLACE_DISK_CHG = "replace_new_secondary" # change secondary node
329
REPLACE_DISK_AUTO = "replace_auto"
330

    
331
# Instance export mode
332
EXPORT_MODE_LOCAL = "local"
333
EXPORT_MODE_REMOTE = "remote"
334
EXPORT_MODES = frozenset([
335
  EXPORT_MODE_LOCAL,
336
  EXPORT_MODE_REMOTE,
337
  ])
338

    
339
# lock recalculate mode
340
LOCKS_REPLACE = 'replace'
341
LOCKS_APPEND = 'append'
342

    
343
# instance creation modes
344
INSTANCE_CREATE = "create"
345
INSTANCE_IMPORT = "import"
346
INSTANCE_REMOTE_IMPORT = "remote-import"
347
INSTANCE_CREATE_MODES = frozenset([
348
  INSTANCE_CREATE,
349
  INSTANCE_IMPORT,
350
  INSTANCE_REMOTE_IMPORT,
351
  ])
352

    
353
# Remote import/export handshake message and version
354
RIE_VERSION = 0
355
RIE_HANDSHAKE = "Hi, I'm Ganeti"
356

    
357
# Remote import/export certificate validity in seconds
358
RIE_CERT_VALIDITY = 24 * 60 * 60
359

    
360
# Remote import/export connect timeout for socat
361
RIE_CONNECT_TIMEOUT = 60
362

    
363
DISK_TEMPLATES = frozenset([DT_DISKLESS, DT_PLAIN,
364
                            DT_DRBD8, DT_FILE])
365

    
366
FILE_DRIVER = frozenset([FD_LOOP, FD_BLKTAP])
367

    
368
# import/export config options
369
INISECT_EXP = "export"
370
INISECT_INS = "instance"
371
INISECT_HYP = "hypervisor"
372
INISECT_BEP = "backend"
373

    
374
# dynamic device modification
375
DDM_ADD = 'add'
376
DDM_REMOVE = 'remove'
377

    
378
# common exit codes
379
EXIT_SUCCESS = 0
380
EXIT_FAILURE = 1
381
EXIT_NOTCLUSTER = 5
382
EXIT_NOTMASTER = 11
383
EXIT_NODESETUP_ERROR = 12
384
EXIT_CONFIRMATION = 13 # need user confirmation
385

    
386
# tags
387
TAG_CLUSTER = "cluster"
388
TAG_NODE = "node"
389
TAG_INSTANCE = "instance"
390
MAX_TAG_LEN = 128
391
MAX_TAGS_PER_OBJ = 4096
392

    
393
# others
394
DEFAULT_BRIDGE = "xen-br0"
395
SYNC_SPEED = 60 * 1024
396
LOCALHOST_IP_ADDRESS = "127.0.0.1"
397
TCP_PING_TIMEOUT = 10
398
GANETI_RUNAS = "root"
399
DEFAULT_VG = "xenvg"
400
BIND_ADDRESS_GLOBAL = "0.0.0.0"
401
MIN_VG_SIZE = 20480
402
DEFAULT_MAC_PREFIX = "aa:00:00"
403
LVM_STRIPECOUNT = _autoconf.LVM_STRIPECOUNT
404
# default maximum instance wait time, in seconds.
405
DEFAULT_SHUTDOWN_TIMEOUT = 120
406
NODE_MAX_CLOCK_SKEW = 150
407
# Time for an intra-cluster disk transfer to wait for a connection
408
DISK_TRANSFER_CONNECT_TIMEOUT = 30
409

    
410
# runparts results
411
(RUNPARTS_SKIP,
412
 RUNPARTS_RUN,
413
 RUNPARTS_ERR) = range(3)
414

    
415
RUNPARTS_STATUS = frozenset([RUNPARTS_SKIP, RUNPARTS_RUN, RUNPARTS_ERR])
416

    
417
# RPC constants
418
(RPC_ENCODING_NONE,
419
 RPC_ENCODING_ZLIB_BASE64) = range(2)
420

    
421
# os related constants
422
OS_SCRIPT_CREATE = 'create'
423
OS_SCRIPT_IMPORT = 'import'
424
OS_SCRIPT_EXPORT = 'export'
425
OS_SCRIPT_RENAME = 'rename'
426
OS_SCRIPTS = frozenset([OS_SCRIPT_CREATE, OS_SCRIPT_IMPORT,
427
                        OS_SCRIPT_EXPORT, OS_SCRIPT_RENAME])
428

    
429
OS_API_FILE = 'ganeti_api_version'
430
OS_VARIANTS_FILE = 'variants.list'
431

    
432
# ssh constants
433
SSH_CONFIG_DIR = _autoconf.SSH_CONFIG_DIR
434
SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_dsa_key"
435
SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
436
SSH_HOST_RSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_rsa_key"
437
SSH_HOST_RSA_PUB = SSH_HOST_RSA_PRIV + ".pub"
438
SSH = "ssh"
439
SCP = "scp"
440

    
441
# reboot types
442
INSTANCE_REBOOT_SOFT = "soft"
443
INSTANCE_REBOOT_HARD = "hard"
444
INSTANCE_REBOOT_FULL = "full"
445

    
446
REBOOT_TYPES = frozenset([INSTANCE_REBOOT_SOFT,
447
                          INSTANCE_REBOOT_HARD,
448
                          INSTANCE_REBOOT_FULL])
449

    
450
VTYPE_STRING = 'string'
451
VTYPE_BOOL = 'bool'
452
VTYPE_SIZE = 'size' # size, in MiBs
453
VTYPE_INT = 'int'
454
ENFORCEABLE_TYPES = frozenset([
455
                      VTYPE_STRING,
456
                      VTYPE_BOOL,
457
                      VTYPE_SIZE,
458
                      VTYPE_INT,
459
                      ])
460

    
461
# HV parameter names (global namespace)
462
HV_BOOT_ORDER = "boot_order"
463
HV_CDROM_IMAGE_PATH = "cdrom_image_path"
464
HV_NIC_TYPE = "nic_type"
465
HV_DISK_TYPE = "disk_type"
466
HV_VNC_BIND_ADDRESS = "vnc_bind_address"
467
HV_VNC_PASSWORD_FILE = "vnc_password_file"
468
HV_VNC_TLS = "vnc_tls"
469
HV_VNC_X509 = "vnc_x509_path"
470
HV_VNC_X509_VERIFY = "vnc_x509_verify"
471
HV_ACPI = "acpi"
472
HV_PAE = "pae"
473
HV_USE_BOOTLOADER = "use_bootloader"
474
HV_BOOTLOADER_ARGS = "bootloader_args"
475
HV_BOOTLOADER_PATH = "bootloader_path"
476
HV_KERNEL_ARGS = "kernel_args"
477
HV_KERNEL_PATH = "kernel_path"
478
HV_INITRD_PATH = "initrd_path"
479
HV_ROOT_PATH = "root_path"
480
HV_SERIAL_CONSOLE = "serial_console"
481
HV_USB_MOUSE = "usb_mouse"
482
HV_DEVICE_MODEL = "device_model"
483
HV_INIT_SCRIPT = "init_script"
484
HV_MIGRATION_PORT = "migration_port"
485
HV_USE_LOCALTIME = "use_localtime"
486
HV_DISK_CACHE = "disk_cache"
487
HV_SECURITY_MODEL = "security_model"
488
HV_SECURITY_DOMAIN = "security_domain"
489
HV_KVM_FLAG = "kvm_flag"
490
HV_VHOST_NET = "vhost_net"
491

    
492
HVS_PARAMETER_TYPES = {
493
  HV_BOOT_ORDER: VTYPE_STRING,
494
  HV_CDROM_IMAGE_PATH: VTYPE_STRING,
495
  HV_NIC_TYPE: VTYPE_STRING,
496
  HV_DISK_TYPE: VTYPE_STRING,
497
  HV_VNC_PASSWORD_FILE: VTYPE_STRING,
498
  HV_VNC_BIND_ADDRESS: VTYPE_STRING,
499
  HV_VNC_TLS: VTYPE_BOOL,
500
  HV_VNC_X509: VTYPE_STRING,
501
  HV_VNC_X509_VERIFY: VTYPE_BOOL,
502
  HV_ACPI: VTYPE_BOOL,
503
  HV_PAE: VTYPE_BOOL,
504
  HV_USE_BOOTLOADER: VTYPE_BOOL,
505
  HV_BOOTLOADER_PATH: VTYPE_STRING,
506
  HV_BOOTLOADER_ARGS: VTYPE_STRING,
507
  HV_KERNEL_PATH: VTYPE_STRING,
508
  HV_KERNEL_ARGS: VTYPE_STRING,
509
  HV_INITRD_PATH: VTYPE_STRING,
510
  HV_ROOT_PATH: VTYPE_STRING,
511
  HV_SERIAL_CONSOLE: VTYPE_BOOL,
512
  HV_USB_MOUSE: VTYPE_STRING,
513
  HV_DEVICE_MODEL: VTYPE_STRING,
514
  HV_INIT_SCRIPT: VTYPE_STRING,
515
  HV_MIGRATION_PORT: VTYPE_INT,
516
  HV_USE_LOCALTIME: VTYPE_BOOL,
517
  HV_DISK_CACHE: VTYPE_STRING,
518
  HV_SECURITY_MODEL: VTYPE_STRING,
519
  HV_SECURITY_DOMAIN: VTYPE_STRING,
520
  HV_KVM_FLAG: VTYPE_STRING,
521
  HV_VHOST_NET: VTYPE_BOOL,
522
  }
523

    
524
HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
525

    
526
# BE parameter names
527
BE_MEMORY = "memory"
528
BE_VCPUS = "vcpus"
529
BE_AUTO_BALANCE = "auto_balance"
530

    
531
BES_PARAMETER_TYPES = {
532
    BE_MEMORY: VTYPE_SIZE,
533
    BE_VCPUS: VTYPE_INT,
534
    BE_AUTO_BALANCE: VTYPE_BOOL,
535
    }
536

    
537
BES_PARAMETERS = frozenset(BES_PARAMETER_TYPES.keys())
538

    
539
# Instance Parameters Profile
540
PP_DEFAULT = "default"
541

    
542
NIC_MODE = "mode"
543
NIC_LINK = "link"
544

    
545
NIC_MODE_BRIDGED = "bridged"
546
NIC_MODE_ROUTED = "routed"
547

    
548
NIC_VALID_MODES = frozenset([NIC_MODE_BRIDGED, NIC_MODE_ROUTED])
549

    
550
NICS_PARAMETER_TYPES = {
551
    NIC_MODE: VTYPE_STRING,
552
    NIC_LINK: VTYPE_STRING,
553
    }
554

    
555
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
556

    
557
# Hypervisor constants
558
HT_XEN_PVM = "xen-pvm"
559
HT_FAKE = "fake"
560
HT_XEN_HVM = "xen-hvm"
561
HT_KVM = "kvm"
562
HT_CHROOT = "chroot"
563
HYPER_TYPES = frozenset([HT_XEN_PVM, HT_FAKE, HT_XEN_HVM, HT_KVM, HT_CHROOT])
564
HTS_REQ_PORT = frozenset([HT_XEN_HVM, HT_KVM])
565

    
566
VNC_BASE_PORT = 5900
567
VNC_PASSWORD_FILE = CONF_DIR + "/vnc-cluster-password"
568
VNC_DEFAULT_BIND_ADDRESS = '0.0.0.0'
569

    
570
# NIC types
571
HT_NIC_RTL8139 = "rtl8139"
572
HT_NIC_NE2K_PCI = "ne2k_pci"
573
HT_NIC_NE2K_ISA = "ne2k_isa"
574
HT_NIC_I82551 = "i82551"
575
HT_NIC_I85557B = "i82557b"
576
HT_NIC_I8259ER = "i82559er"
577
HT_NIC_PCNET = "pcnet"
578
HT_NIC_E1000 = "e1000"
579
HT_NIC_PARAVIRTUAL = HT_DISK_PARAVIRTUAL = "paravirtual"
580

    
581
HT_HVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
582
                                    HT_NIC_NE2K_ISA, HT_NIC_PARAVIRTUAL])
583
HT_KVM_VALID_NIC_TYPES = frozenset([HT_NIC_RTL8139, HT_NIC_NE2K_PCI,
584
                                    HT_NIC_NE2K_ISA, HT_NIC_I82551,
585
                                    HT_NIC_I85557B, HT_NIC_I8259ER,
586
                                    HT_NIC_PCNET, HT_NIC_E1000,
587
                                    HT_NIC_PARAVIRTUAL])
588
# Disk types
589
HT_DISK_IOEMU = "ioemu"
590
HT_DISK_IDE = "ide"
591
HT_DISK_SCSI = "scsi"
592
HT_DISK_SD = "sd"
593
HT_DISK_MTD = "mtd"
594
HT_DISK_PFLASH = "pflash"
595

    
596
HT_CACHE_DEFAULT = "default"
597
HT_CACHE_NONE = "none"
598
HT_CACHE_WTHROUGH = "writethrough"
599
HT_CACHE_WBACK = "writeback"
600
HT_VALID_CACHE_TYPES = frozenset([HT_CACHE_DEFAULT,
601
                                  HT_CACHE_NONE,
602
                                  HT_CACHE_WTHROUGH,
603
                                  HT_CACHE_WBACK])
604

    
605
HT_HVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IOEMU])
606
HT_KVM_VALID_DISK_TYPES = frozenset([HT_DISK_PARAVIRTUAL, HT_DISK_IDE,
607
                                     HT_DISK_SCSI, HT_DISK_SD, HT_DISK_MTD,
608
                                     HT_DISK_PFLASH])
609

    
610
# Mouse types:
611
HT_MOUSE_MOUSE = "mouse"
612
HT_MOUSE_TABLET = "tablet"
613

    
614
HT_KVM_VALID_MOUSE_TYPES = frozenset([HT_MOUSE_MOUSE, HT_MOUSE_TABLET])
615

    
616
# Boot order
617
HT_BO_CDROM = "cdrom"
618
HT_BO_DISK = "disk"
619
HT_BO_NETWORK = "network"
620

    
621
HT_KVM_VALID_BO_TYPES = frozenset([HT_BO_CDROM, HT_BO_DISK, HT_BO_NETWORK])
622

    
623
# Security models
624
HT_SM_NONE = "none"
625
HT_SM_USER = "user"
626
HT_SM_POOL = "pool"
627

    
628
HT_KVM_VALID_SM_TYPES = frozenset([HT_SM_NONE, HT_SM_USER, HT_SM_POOL])
629

    
630
# Kvm flag values
631
HT_KVM_ENABLED = "enabled"
632
HT_KVM_DISABLED = "disabled"
633

    
634
HT_KVM_FLAG_VALUES = frozenset([HT_KVM_ENABLED, HT_KVM_DISABLED])
635

    
636
# Cluster Verify steps
637
VERIFY_NPLUSONE_MEM = 'nplusone_mem'
638
VERIFY_OPTIONAL_CHECKS = frozenset([VERIFY_NPLUSONE_MEM])
639

    
640
# Node verify constants
641
NV_FILELIST = "filelist"
642
NV_HVINFO = "hvinfo"
643
NV_HYPERVISOR = "hypervisor"
644
NV_INSTANCELIST = "instancelist"
645
NV_NODELIST = "nodelist"
646
NV_NODENETTEST = "node-net-test"
647
NV_VERSION = "version"
648
NV_VGLIST = "vglist"
649
NV_LVLIST = "lvlist"
650
NV_PVLIST = "pvlist"
651
NV_DRBDLIST = "drbd-list"
652
NV_NODESETUP = "nodesetup"
653
NV_TIME = "time"
654
NV_MASTERIP = "master-ip"
655

    
656
# SSL certificate check constants (in days)
657
SSL_CERT_EXPIRATION_WARN = 30
658
SSL_CERT_EXPIRATION_ERROR = 7
659

    
660
# Allocator framework constants
661
IALLOCATOR_VERSION = 2
662
IALLOCATOR_DIR_IN = "in"
663
IALLOCATOR_DIR_OUT = "out"
664
IALLOCATOR_MODE_ALLOC = "allocate"
665
IALLOCATOR_MODE_RELOC = "relocate"
666
IALLOCATOR_MODE_MEVAC = "multi-evacuate"
667
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
668

    
669
# Job queue
670
JOB_QUEUE_VERSION = 1
671
JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock"
672
JOB_QUEUE_VERSION_FILE = QUEUE_DIR + "/version"
673
JOB_QUEUE_SERIAL_FILE = QUEUE_DIR + "/serial"
674
JOB_QUEUE_ARCHIVE_DIR = QUEUE_DIR + "/archive"
675
JOB_QUEUE_DRAIN_FILE = QUEUE_DIR + "/drain"
676
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
677
JOB_QUEUE_SIZE_SOFT_LIMIT = JOB_QUEUE_SIZE_HARD_LIMIT * 0.8
678
JOB_QUEUE_DIRS = [QUEUE_DIR, JOB_QUEUE_ARCHIVE_DIR]
679
JOB_QUEUE_DIRS_MODE = SECURE_DIR_MODE
680

    
681
JOB_ID_TEMPLATE = r"\d+"
682

    
683
# unchanged job return
684
JOB_NOTCHANGED = "nochange"
685

    
686
# Job status
687
JOB_STATUS_QUEUED = "queued"
688
JOB_STATUS_WAITLOCK = "waiting"
689
JOB_STATUS_CANCELING = "canceling"
690
JOB_STATUS_RUNNING = "running"
691
JOB_STATUS_CANCELED = "canceled"
692
JOB_STATUS_SUCCESS = "success"
693
JOB_STATUS_ERROR = "error"
694

    
695
# OpCode status
696
# not yet finalized
697
OP_STATUS_QUEUED = "queued"
698
OP_STATUS_WAITLOCK = "waiting"
699
OP_STATUS_CANCELING = "canceling"
700
OP_STATUS_RUNNING = "running"
701
# finalized
702
OP_STATUS_CANCELED = "canceled"
703
OP_STATUS_SUCCESS = "success"
704
OP_STATUS_ERROR = "error"
705
OPS_FINALIZED = frozenset([OP_STATUS_CANCELED,
706
                           OP_STATUS_SUCCESS,
707
                           OP_STATUS_ERROR])
708

    
709
# Execution log types
710
ELOG_MESSAGE = "message"
711
ELOG_PROGRESS = "progress"
712
ELOG_REMOTE_IMPORT = "remote-import"
713

    
714
# max dynamic devices
715
MAX_NICS = 8
716
MAX_DISKS = 16
717

    
718
# SSCONF keys
719
SS_CLUSTER_NAME = "cluster_name"
720
SS_CLUSTER_TAGS = "cluster_tags"
721
SS_FILE_STORAGE_DIR = "file_storage_dir"
722
SS_MASTER_CANDIDATES = "master_candidates"
723
SS_MASTER_CANDIDATES_IPS = "master_candidates_ips"
724
SS_MASTER_IP = "master_ip"
725
SS_MASTER_NETDEV = "master_netdev"
726
SS_MASTER_NODE = "master_node"
727
SS_NODE_LIST = "node_list"
728
SS_NODE_PRIMARY_IPS = "node_primary_ips"
729
SS_NODE_SECONDARY_IPS = "node_secondary_ips"
730
SS_OFFLINE_NODES = "offline_nodes"
731
SS_ONLINE_NODES = "online_nodes"
732
SS_INSTANCE_LIST = "instance_list"
733
SS_RELEASE_VERSION = "release_version"
734
SS_HYPERVISOR_LIST = "hypervisor_list"
735
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
736
SS_UID_POOL = "uid_pool"
737

    
738
# cluster wide default parameters
739
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
740

    
741
HVC_DEFAULTS = {
742
  HT_XEN_PVM: {
743
    HV_USE_BOOTLOADER: False,
744
    HV_BOOTLOADER_PATH: XEN_BOOTLOADER,
745
    HV_BOOTLOADER_ARGS: '',
746
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-xenU",
747
    HV_INITRD_PATH: '',
748
    HV_ROOT_PATH: '/dev/sda1',
749
    HV_KERNEL_ARGS: 'ro',
750
    HV_MIGRATION_PORT: 8002,
751
    },
752
  HT_XEN_HVM: {
753
    HV_BOOT_ORDER: "cd",
754
    HV_CDROM_IMAGE_PATH: '',
755
    HV_NIC_TYPE: HT_NIC_RTL8139,
756
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
757
    HV_VNC_BIND_ADDRESS: '0.0.0.0',
758
    HV_VNC_PASSWORD_FILE: VNC_PASSWORD_FILE,
759
    HV_ACPI: True,
760
    HV_PAE: True,
761
    HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
762
    HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
763
    HV_MIGRATION_PORT: 8002,
764
    HV_USE_LOCALTIME: False,
765
    },
766
  HT_KVM: {
767
    HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
768
    HV_INITRD_PATH: '',
769
    HV_KERNEL_ARGS: 'ro',
770
    HV_ROOT_PATH: '/dev/vda1',
771
    HV_ACPI: True,
772
    HV_SERIAL_CONSOLE: True,
773
    HV_VNC_BIND_ADDRESS: '',
774
    HV_VNC_TLS: False,
775
    HV_VNC_X509: '',
776
    HV_VNC_X509_VERIFY: False,
777
    HV_VNC_PASSWORD_FILE: '',
778
    HV_CDROM_IMAGE_PATH: '',
779
    HV_BOOT_ORDER: HT_BO_DISK,
780
    HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
781
    HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
782
    HV_USB_MOUSE: '',
783
    HV_MIGRATION_PORT: 8102,
784
    HV_USE_LOCALTIME: False,
785
    HV_DISK_CACHE: HT_CACHE_DEFAULT,
786
    HV_SECURITY_MODEL: HT_SM_NONE,
787
    HV_SECURITY_DOMAIN: '',
788
    HV_KVM_FLAG: "",
789
    HV_VHOST_NET: False,
790
    },
791
  HT_FAKE: {
792
    },
793
  HT_CHROOT: {
794
    HV_INIT_SCRIPT: "/ganeti-chroot",
795
    },
796
  }
797

    
798
HVC_GLOBALS = frozenset([
799
  HV_MIGRATION_PORT,
800
  ])
801

    
802
BEC_DEFAULTS = {
803
  BE_MEMORY: 128,
804
  BE_VCPUS: 1,
805
  BE_AUTO_BALANCE: True,
806
  }
807

    
808
NICC_DEFAULTS = {
809
  NIC_MODE: NIC_MODE_BRIDGED,
810
  NIC_LINK: DEFAULT_BRIDGE,
811
  }
812

    
813
MASTER_POOL_SIZE_DEFAULT = 10
814

    
815
CONFD_PROTOCOL_VERSION = 1
816

    
817
CONFD_REQ_PING = 0
818
CONFD_REQ_NODE_ROLE_BYNAME = 1
819
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
820
CONFD_REQ_CLUSTER_MASTER = 3
821
CONFD_REQ_NODE_PIP_LIST = 4
822
CONFD_REQ_MC_PIP_LIST = 5
823
CONFD_REQ_INSTANCES_IPS_LIST = 6
824

    
825
# Confd request query fields. These are used to narrow down queries.
826
# These must be strings rather than integers, because json-encoding
827
# converts them to strings anyway, as they're used as dict-keys.
828
CONFD_REQQ_LINK = "0"
829
CONFD_REQQ_IP = "1"
830
CONFD_REQQ_IPLIST = "2"
831
CONFD_REQQ_FIELDS = "3"
832

    
833
CONFD_REQFIELD_NAME = "0"
834
CONFD_REQFIELD_IP = "1"
835
CONFD_REQFIELD_MNODE_PIP = "2"
836

    
837
CONFD_REQS = frozenset([
838
  CONFD_REQ_PING,
839
  CONFD_REQ_NODE_ROLE_BYNAME,
840
  CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
841
  CONFD_REQ_CLUSTER_MASTER,
842
  CONFD_REQ_NODE_PIP_LIST,
843
  CONFD_REQ_MC_PIP_LIST,
844
  CONFD_REQ_INSTANCES_IPS_LIST,
845
  ])
846

    
847
CONFD_REPL_STATUS_OK = 0
848
CONFD_REPL_STATUS_ERROR = 1
849
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2
850

    
851
CONFD_REPL_STATUSES = frozenset([
852
  CONFD_REPL_STATUS_OK,
853
  CONFD_REPL_STATUS_ERROR,
854
  CONFD_REPL_STATUS_NOTIMPLEMENTED,
855
  ])
856

    
857
(CONFD_NODE_ROLE_MASTER,
858
 CONFD_NODE_ROLE_CANDIDATE,
859
 CONFD_NODE_ROLE_OFFLINE,
860
 CONFD_NODE_ROLE_DRAINED,
861
 CONFD_NODE_ROLE_REGULAR,
862
 ) = range(5)
863

    
864
# A few common errors for confd
865
CONFD_ERROR_UNKNOWN_ENTRY = 1
866
CONFD_ERROR_INTERNAL = 2
867
CONFD_ERROR_ARGUMENT = 3
868

    
869
# Each request is "salted" by the current timestamp.
870
# This constants decides how many seconds of skew to accept.
871
# TODO: make this a default and allow the value to be more configurable
872
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW
873

    
874
# When we haven't reloaded the config for more than this amount of seconds, we
875
# force a test to see if inotify is betraying us.
876
CONFD_CONFIG_RELOAD_TIMEOUT = 60
877

    
878
# If we receive more than one update in this amount of seconds, we move to
879
# polling every RATELIMIT seconds, rather than relying on inotify, to be able
880
# to serve more requests.
881
CONFD_CONFIG_RELOAD_RATELIMIT = 2
882

    
883
# Magic number prepended to all confd queries.
884
# This allows us to distinguish different types of confd protocols and handle
885
# them. For example by changing this we can move the whole payload to be
886
# compressed, or move away from json.
887
CONFD_MAGIC_FOURCC = 'plj0'
888

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

    
894
# Timeout in seconds to expire pending query request in the confd client
895
# library. We don't actually expect any answer more than 10 seconds after we
896
# sent a request.
897
CONFD_CLIENT_EXPIRE_TIMEOUT = 10
898

    
899
# Maximum UDP datagram size.
900
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
901
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
902
#   (assuming we can't use jumbo frames)
903
# We just set this to 60K, which should be enough
904
MAX_UDP_DATA_SIZE = 61440
905

    
906
# User-id pool minimum/maximum acceptable user-ids.
907
UIDPOOL_UID_MIN = 0
908
UIDPOOL_UID_MAX = 2**32-1 # Assuming 32 bit user-ids
909

    
910
# Name or path of the pgrep command
911
PGREP = "pgrep"