Gentoo Archives: gentoo-commits

From: Doug Goldstein <cardoe@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-emulation/libvirt/files/
Date: Fri, 28 Aug 2015 13:48:32
Message-Id: 1440769675.5ed04d55b9a56c932128d867b596bebc6e3ff4ce.cardoe@gentoo
1 commit: 5ed04d55b9a56c932128d867b596bebc6e3ff4ce
2 Author: Doug Goldstein <cardoe <AT> gentoo <DOT> org>
3 AuthorDate: Fri Aug 28 13:35:39 2015 +0000
4 Commit: Doug Goldstein <cardoe <AT> gentoo <DOT> org>
5 CommitDate: Fri Aug 28 13:47:55 2015 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5ed04d55
7
8 app-emulation/libvirt: tweak libvirt-guests init script
9
10 After discussing the new init script on bug #558034 there are two tweaks
11 being added:
12 * shift the first argument so that future uses can pass in more arguments
13 to virsh and the wrapper commands.
14 * Added LIBVIRT_IGNORE_AUTOSTART to ignore domains that start marked for
15 autostart in the libvirt XML.
16
17 Signed-off-by: Doug Goldstein <cardoe <AT> gentoo.org>
18
19 app-emulation/libvirt/files/libvirt-guests.confd | 10 +++++++
20 app-emulation/libvirt/files/libvirt-guests.init | 33 +++++++++++++++++++-----
21 2 files changed, 37 insertions(+), 6 deletions(-)
22
23 diff --git a/app-emulation/libvirt/files/libvirt-guests.confd b/app-emulation/libvirt/files/libvirt-guests.confd
24 index 6e98dc2..514c8ee 100644
25 --- a/app-emulation/libvirt/files/libvirt-guests.confd
26 +++ b/app-emulation/libvirt/files/libvirt-guests.confd
27 @@ -39,6 +39,16 @@
28 #LIBVIRT_MAXWAIT="500"
29
30
31 +# LIBVIRT_IGNORE_AUTOSTART
32 +# If the VM is marked for autostart in its XML configuration then we won't
33 +# save its start when the init script is stopped. The result is that when
34 +# the init script starts back up, no attempt will be made to start the VM or
35 +# confirm it is started.
36 +# Valid values are yes or no
37 +
38 +#LIBVIRT_IGNORE_AUTOSTART="no"
39 +
40 +
41 # LIBVIRT_NET_SHUTDOWN
42 # If libvirtd created networks for you (e.g. NATed networks) then this init
43 # script will shut them down for you if this is set to 'yes'. Otherwise,
44
45 diff --git a/app-emulation/libvirt/files/libvirt-guests.init b/app-emulation/libvirt/files/libvirt-guests.init
46 index 045f04d..2b63dea 100644
47 --- a/app-emulation/libvirt/files/libvirt-guests.init
48 +++ b/app-emulation/libvirt/files/libvirt-guests.init
49 @@ -38,20 +38,32 @@ do_virsh() {
50
51 libvirtd_dom_list() {
52 # Only work with domains by their UUIDs
53 - do_virsh "$1" list --uuid $2
54 + local hvuri=$1
55 + shift
56 +
57 + do_virsh "${hvuri}" list --uuid $@
58 }
59
60 libvirtd_dom_count() {
61 - libvirtd_dom_list "$1" $2 | wc -l
62 + local hvuri=$1
63 + shift
64 +
65 + libvirtd_dom_list "${hvuri}" $@ | wc -l
66 }
67
68 libvirtd_net_list() {
69 # Only work with networks by their UUIDs
70 - do_virsh "$1" net-list --uuid $2
71 + local hvuri=$1
72 + shift
73 +
74 + do_virsh "${hvuri}" net-list --uuid $@
75 }
76
77 libvirtd_net_count() {
78 - libvirtd_net_list "$1" $2 | wc -l
79 + local hvuri=$1
80 + shift
81 +
82 + libvirtd_net_list "${hvuri}" $@ | wc -l
83 }
84
85 libvirtd_dom_stop() {
86 @@ -64,6 +76,7 @@ libvirtd_dom_stop() {
87 local shutdown_type=${LIBVIRT_SHUTDOWN}
88 local counter=${LIBVIRT_MAXWAIT}
89 local dom_name=
90 + local dom_as=
91 local dom_ids=
92 local uuid=
93 local dom_count=
94 @@ -80,10 +93,18 @@ libvirtd_dom_stop() {
95 # Get the name
96 dom_name=$(do_virsh ${uri} domname ${uuid})
97 einfo " ${dom_name}"
98 + # Get autostart state
99 + dom_as=$(do_virsh ${uri} dominfo ${uuid} | \
100 + awk '$1 == "Autostart:" { print $2 }')
101
102 if [ "${persist}" = "--persistent" ]; then
103 - # Save our running state
104 - echo "${uri} ${uuid}" >> ${gueststatefile}
105 + # Save our running state only if LIBVIRT_IGNORE_AUTOSTART != yes
106 + if [ "x${LIBVIRT_IGNORE_AUTOSTART}" = "xyes" ] && \
107 + [ ${dom_as} = "enabled" ]; then
108 + :
109 + else
110 + echo "${uri} ${uuid}" >> ${gueststatefile}
111 + fi
112
113 fi