Revision 8c732208

b/xseg/base.mk
68 68
moduledir=/lib/modules/$(KVER)/extra/
69 69
srcdir=/usr/src/archipelago-modules-dkms-$(VERSION)/xseg/
70 70
ganetidir=/usr/share/ganeti/extstorage/archipelago/
71
ganetihooksdir=/etc/ganeti/hooks/
71 72

  
72 73
INC=-I$(BASE)
73 74
INC+=-I$(BASE)/peers/$(TARGET)
b/xseg/tools/Makefile
13 13
default:
14 14
	make -C archipelago
15 15
	make -C ext_scripts
16
	make -C ganeti-hooks
16 17

  
17 18
clean:
18 19
	make -C archipelago clean
19 20
	make -C ext_scripts clean
21
	make -C ganeti-hooks clean
20 22

  
21 23
install:
22 24
	make -C archipelago install
23 25
	make -C ext_scripts install
26
	make -C ganeti-hooks install
24 27

  
25 28
install-src:
26 29
	make -C archipelago install-src
27 30
	make -C ext_scripts install-src
31
	make -C ganeti-hooks install-src
28 32
	install -d $(DESTDIR)$(srcdir)$(SUBDIR) ;
29 33
	@for f in $(FILES) ; do \
30 34
		install -o 0 -g 0 -m 644 -t $(DESTDIR)$(srcdir)$(SUBDIR) $$f ; \
b/xseg/tools/ganeti-hooks/Makefile
1
.PHONY: default clean install install-src
2

  
3
include $(XSEG_HOME)/base.mk
4

  
5
DEVFILES="Makefile"
6

  
7
HOOKS="instance-migrate-pre.d"
8

  
9
SUBDIR:=$(subst $(XSEG_HOME),,$(CURDIR))
10

  
11
default:
12

  
13
clean:
14

  
15
install:
16
	install -d $(DESTDIR)$(ganetihooksdir)
17
	@for f in $(HOOKS) ; do \
18
		make -C $$f install ; \
19
	done
20

  
21
install-src:
22
	install -d $(DESTDIR)$(srcdir)$(SUBDIR) ;
23
	@for f in $(DEVFILES) ; do \
24
		install -o 0 -g 0 -m 644 -t $(DESTDIR)$(srcdir)$(SUBDIR) $$f ; \
25
	done
26
	@for f in $(HOOKS) ; do \
27
		make -C $$f install-src ; \
28
	done
29

  
b/xseg/tools/ganeti-hooks/instance-migrate-pre.d/Makefile
1
.PHONY: default clean install install-src
2

  
3
include $(XSEG_HOME)/base.mk
4

  
5
DEVFILES="Makefile"
6

  
7
EFILES="archip-openvolumes"
8

  
9
SUBDIR:=$(subst $(XSEG_HOME),,$(CURDIR))
10

  
11
default:
12

  
13
clean:
14

  
15
install:
16
	install -d $(DESTDIR)$(ganetihooksdir)/instance-migrate-pre.d/
17
	@for f in $(EFILES) ; do \
18
		install -o 0 -g 0 -m 755 -t $(DESTDIR)$(ganetihooksdir)/instance-migrate-pre.d/ $$f ; \
19
	done
20

  
21
install-src:
22
	install -d $(DESTDIR)$(srcdir)$(SUBDIR) ;
23
	@for f in $(DEVFILES) ; do \
24
		install -o 0 -g 0 -m 644 -t $(DESTDIR)$(srcdir)$(SUBDIR) $$f ; \
25
	done
26
	@for f in $(EFILES) ; do \
27
		install -o 0 -g 0 -m 755 -t $(DESTDIR)$(srcdir)$(SUBDIR) $$f ; \
28
	done
29

  
b/xseg/tools/ganeti-hooks/instance-migrate-pre.d/archip-openvolumes
1
#!/usr/bin/env python
2

  
3
import os
4
import sys
5

  
6
from archipelago import vlmc as vlmc
7
from archipelago.common import loadrc
8

  
9
def hooks_log(msg):
10
    f = open('/var/log/ganeti/hooks.log', 'a')
11
    f.write("%s\n" % msg)
12
    f.close()
13

  
14

  
15
def archip_premigrate_disk(idx):
16
    provider = os.getenv("GANETI_INSTANCE_DISK%d_PROVIDER" % idx)
17
    vol_name = os.getenv("GANETI_INSTANCE_DISK%d_ID" % idx)
18
    template = os.getenv("GANETI_INSTANCE_DISK%d_TEMPLATE_NAME" % idx)
19

  
20
    if template != 'ext':
21
        raise Exception("Invalid disk template %s" % template)
22

  
23
    if provider != 'archipelago' and provider != 'vlmc':
24
        raise Exception("Unknown provider %s" % provider)
25

  
26
    if not vol_name:
27
        raise Exception("No volume name provided")
28

  
29
    hooks_log("Opening volume %s" % vol_name)
30
    vlmc.open_volume(name=vol_name)
31
    hooks_log("Opened volume %s" % vol_name)
32

  
33

  
34
def archip_premigrate():
35
    try:
36
        count = os.getenv("GANETI_INSTANCE_DISK_COUNT")
37
        template = os.getenv("GANETI_INSTANCE_DISK_TEMPLATE")
38
    except:
39
        return 1
40

  
41
    if template != 'ext':
42
        return 1
43

  
44
    count = int(count)
45
    hooks_log("Found %d disks" % count)
46

  
47
    for i in range(0, count):
48
        try:
49
            archip_premigrate_disk(i)
50
        except Exception as e:
51
            msg = "Failed to open volume %d: %s" % (i, e)
52
            print msg
53
            hooks_log(msg)
54
            return 1
55

  
56
    return 0
57

  
58
if __name__ == '__main__':
59
    loadrc(None)
60
    exit(archip_premigrate())
61

  

Also available in: Unified diff