Statistics
| Branch: | Tag: | Revision:

root / tools / upgrade-kvm-runtime @ 4ae49c63

History | View | Annotate | Download (1.2 kB)

1
#!/usr/bin/env python
2

    
3
import os
4
import sys
5

    
6
from glob import glob
7

    
8
from ganeti import constants
9
from ganeti import serializer
10
from ganeti import utils
11
from ganeti.hypervisor.hv_kvm import KVMHypervisor
12

    
13
if len(sys.argv) == 1:
14
  root = KVMHypervisor._CONF_DIR
15
else:
16
  root = sys.argv[1]
17

    
18
for path in glob(os.path.join(root, "*.runtime")):
19
  try:
20
    data = utils.ReadFile(path)
21
  except EnvironmentError, e:
22
    print "Failed to read file %s: %s" % (path, str(e))
23
    continue
24

    
25
  try:
26
    kvm_cmd, nics, hvparams = serializer.Load(data)
27
  except Exception, e:
28
    print "Failed to parse file %s: %s" % (path, str(e))
29
    continue
30

    
31
  # Replace the run_as parameter or remove it completely
32
  if "run_as" in hvparams:
33
    if hvparams["run_as"]:
34
      print "Replacing 'run_as' in %s with 'security_model' = 'user'" % path
35
      hvparams["security_model"] = "user"
36
      hvparams["security_domain"] = hvparams["run_as"]
37
    else:
38
      print "Removing 'run_as' from %s" % path
39

    
40
    del hvparams["run_as"]
41

    
42
  try:
43
    utils.WriteFile(path,
44
                    data=serializer.Dump((kvm_cmd, nics, hvparams)),
45
                    backup=True)
46
  except EnvironmentError, e:
47
    print "Failed to write %s" % path