[Kimchi-devel] [PATCH V2] Implement integrity verification: don't disable network used by guest
Leonardo Augusto Guimarães Garcia
lagarcia at linux.vnet.ibm.com
Mon Feb 17 20:18:19 UTC 2014
Reviewed-by: Leonardo Garcia <lagarcia at br.ibm.com>
Tested-by: Leonardo Garcia <lagarcia at br.ibm.com>
On 02/17/2014 11:46 AM, shaohef at linux.vnet.ibm.com wrote:
> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>
> do not allow to delete a network when the network is used by more than
> one guest.
> do not allow to deactivate a network when the network is used by more
> than one guest with running state.
>
> add a filter for _get_vms_attach_to_a_network
>
> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> ---
> src/kimchi/i18n.py | 2 ++
> src/kimchi/model/networks.py | 13 +++++++++++--
> 2 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
> index fd61d4e..03b232d 100644
> --- a/src/kimchi/i18n.py
> +++ b/src/kimchi/i18n.py
> @@ -163,6 +163,8 @@ messages = {
> "KCHNET0014E": _("Network interface must be a string"),
> "KCHNET0015E": _("Network VLAN ID must be an integer between 1 and 4094"),
> "KCHNET0016E": _("Specify name and type to create a Network"),
> + "KCHNET0017E": _("Unable to delete network %(name)s. There are still some VMs linked to this network."),
> + "KCHNET0018E": _("Unable to deactivate network %(name)s. There are some VMs running linked to this network."),
>
> "KCHDR0001E": _("Debug report %(name)s does not exist"),
> "KCHDR0002E": _("Debug report tool not found in system"),
> diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py
> index 05105df..9a88fe9 100644
> --- a/src/kimchi/model/networks.py
> +++ b/src/kimchi/model/networks.py
> @@ -188,12 +188,17 @@ class NetworkModel(object):
> 'autostart': network.autostart() == 1,
> 'state': network.isActive() and "active" or "inactive"}
>
> - def _get_vms_attach_to_a_network(self, network):
> + def _get_vms_attach_to_a_network(self, network, filter="all"):
> + DOM_STATE_MAP = {'nostate': 0, 'running': 1, 'blocked': 2,
> + 'paused':3, 'shutdown': 4, 'shutoff': 5,
> + 'crashed': 6}
> + state = DOM_STATE_MAP.get(filter)
> vms = []
> conn = self.conn.get()
> for dom in conn.listAllDomains(0):
> networks = self._vm_get_networks(dom)
> - if network in networks:
> + if network in networks and (state == None or
> + state == dom.state()[0]):
> vms.append(dom.name())
> return vms
>
> @@ -208,12 +213,16 @@ class NetworkModel(object):
>
> def deactivate(self, name):
> network = self._get_network(name)
> + if self._get_vms_attach_to_a_network(name, "running"):
> + raise InvalidOperation("KCHNET0018E", {'name': name})
> network.destroy()
>
> def delete(self, name):
> network = self._get_network(name)
> if network.isActive():
> raise InvalidOperation("KCHNET0005E", {'name': name})
> + if self._get_vms_attach_to_a_network(name):
> + raise InvalidOperation("KCHNET0017E", {'name': name})
>
> self._remove_vlan_tagged_bridge(network)
> network.undefine()
More information about the Kimchi-devel
mailing list