[Libvirt-cim] [PATCH] [TEST] Make sure network pool is created with a random IP

Deepti B Kalakeri deeptik at linux.vnet.ibm.com
Thu Mar 12 07:15:31 UTC 2009



Kaitlin Rupert wrote:
> # HG changeset patch
> # User Kaitlin Rupert <karupert at us.ibm.com>
> # Date 1236818181 25200
> # Node ID abe81a5626e7959f17e51c52a29003aa31ff6e41
> # Parent  5c33dc7241b63d77428d7f5e852df69d48c2cb50
> [TEST] Make sure network pool is created with a random IP.
>
> This will help prevent overlap with existing networks.  However, this won't
> completely prevent the issue.  We'd need to do test to see if the IP address
> is already used by a different network. If the network is in use, then another
> IP address should be used.
>
> Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>
>
> diff -r 5c33dc7241b6 -r abe81a5626e7 suites/libvirt-cim/lib/XenKvmLib/vxml.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Thu Dec 18 14:10:33 2008 -0800
> +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Wed Mar 11 17:36:21 2009 -0700
> @@ -32,6 +32,7 @@
>  # shared by XenXML & KVMXML.
>  import os
>  import sys
> +import random
>  import platform
>  import tempfile
>  from time import sleep
> @@ -182,7 +183,6 @@
>          def get_valid_bridge_name(server):
>              bridge_list = live.available_bridges(server)
>              if bridgename in bridge_list:
> -                import random
>                  vbr = bridgename + str(random.randint(1, 100))
>                  if vbr in bridge_list:
>                      logger.error('Need to give different bridge name '
> @@ -210,10 +210,14 @@
>          subnet = '192.168.122.'
>          self.add_sub_node(network, 'bridge', name=self.vbr, stp='on',
>                                               forwardDelay='0')
> -        ip = self.add_sub_node(network, 'ip', address=subnet+'1',
> +        ip_base = random.randint(1, 100)
> +        addr = address=subnet+'%d' % ip_base
>   
addr is not used later at all. Hence can be removed.
> +
> +        ip = self.add_sub_node(network, 'ip', address=address,
>                                                netmask='255.255.255.0')
>          dhcp = self.add_sub_node(ip, 'dhcp')
> -        self.add_sub_node(dhcp, 'range', start=subnet+'2',
> +        range_addr = subnet+'%d' % (ip_base + 1)
> +        self.add_sub_node(dhcp, 'range', start=range_addr,
>                                           end=subnet+'254')
>
>
>   
We can do something like the below to print more appropriate error 
message when the ip ranges are already used for some other network pool.


n_list = xm_virt_util.net_list(server, virt)
for net_name in n_list:
cmd = "virsh net-dumpxml %s | awk '/range/ {print}' \
| tr -s [:space:] | cut -d ' ' -f 3,4" % net_name
s, range = utils.run_remote(server, cmd)
start_addr, end_addr=range.split('end=')
if start_addr == address or range_addr == end_addr:
logger.error("Range already used in use")

>      def create_vnet(self):
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
>   

-- 
Thanks and Regards,
Deepti B. Kalakeri
IBM Linux Technology Center
deeptik at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list