[PATCH 0/3] Issue #302

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> let 'create' attr of networks model to create the default network ShaoHe Feng (3): move _default_network_check from top model to networks model add a new function to get an available network address Issue #302: let 'create' attr of networks model to create default network src/kimchi/model/model.py | 35 --------------------------------- src/kimchi/model/networks.py | 46 +++++++++++++++++++++++++++++++++++++------- src/kimchi/network.py | 7 +++++-- 3 files changed, 44 insertions(+), 44 deletions(-) -- 1.8.4.2

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Top model should load other model and structure preparing. The default network check is network function, move to networks model is more reasonable. And the important: it is more convenient to call attr of networks model Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/model/model.py | 35 ----------------------------------- src/kimchi/model/networks.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/kimchi/model/model.py b/src/kimchi/model/model.py index aa5eab5..a7d843e 100644 --- a/src/kimchi/model/model.py +++ b/src/kimchi/model/model.py @@ -39,7 +39,6 @@ class Model(BaseModel): if 'qemu:///' in libvirt_uri: self._default_pool_check() - self._default_network_check() this = os.path.basename(__file__) this_mod = os.path.splitext(this)[0] @@ -58,40 +57,6 @@ class Model(BaseModel): return super(Model, self).__init__(models) - def _default_network_check(self): - conn = self.conn.get() - xml = """ - <network> - <name>default</name> - <forward mode='nat'/> - <bridge name='virbr0' stp='on' delay='0' /> - <ip address='192.168.122.1' netmask='255.255.255.0'> - <dhcp> - <range start='192.168.122.2' end='192.168.122.254' /> - </dhcp> - </ip> - </network> - """ - try: - net = conn.networkLookupByName("default") - except libvirt.libvirtError: - try: - net = conn.networkDefineXML(xml) - except libvirt.libvirtError, e: - cherrypy.log.error("Fatal: Cannot create default network " - "because of %s, exit kimchid" % e.message, - severity=logging.ERROR) - sys.exit(1) - - if net.isActive() == 0: - try: - net.create() - except libvirt.libvirtError, e: - cherrypy.log.error("Fatal: Cannot activate default network " - "because of %s, exit kimchid" % e.message, - severity=logging.ERROR) - sys.exit(1) - def _default_pool_check(self): conn = self.conn.get() xml = """ diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py index f032875..bd9c03a 100644 --- a/src/kimchi/model/networks.py +++ b/src/kimchi/model/networks.py @@ -32,6 +32,42 @@ from kimchi.rollbackcontext import RollbackContext class NetworksModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] + if 'qemu:///' in self.conn.get().getURI(): + self._default_network_check() + + def _default_network_check(self): + conn = self.conn.get() + xml = """ + <network> + <name>default</name> + <forward mode='nat'/> + <bridge name='virbr0' stp='on' delay='0' /> + <ip address='192.168.122.1' netmask='255.255.255.0'> + <dhcp> + <range start='192.168.122.2' end='192.168.122.254' /> + </dhcp> + </ip> + </network> + """ + try: + net = conn.networkLookupByName("default") + except libvirt.libvirtError: + try: + net = conn.networkDefineXML(xml) + except libvirt.libvirtError, e: + cherrypy.log.error("Fatal: Cannot create default network " + "because of %s, exit kimchid" % e.message, + severity=logging.ERROR) + sys.exit(1) + + if net.isActive() == 0: + try: + net.create() + except libvirt.libvirtError, e: + cherrypy.log.error("Fatal: Cannot activate default network " + "because of %s, exit kimchid" % e.message, + severity=logging.ERROR) + sys.exit(1) def create(self, params): conn = self.conn.get() -- 1.8.4.2

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Then the default network check code can make use it. Also add a new argument for get_one_free_network to make it more flexible Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/model/networks.py | 18 +++++++++++------- src/kimchi/network.py | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py index bd9c03a..7103085 100644 --- a/src/kimchi/model/networks.py +++ b/src/kimchi/model/networks.py @@ -103,17 +103,21 @@ class NetworksModel(object): conn = self.conn.get() return sorted(conn.listNetworks() + conn.listDefinedNetworks()) + def _get_available_address(self, addr_pools=[]): + invalid_addrs=[] + for net_name in self.get_list(): + network = NetworkModel.get_network(self.conn.get(), net_name) + xml = network.XMLDesc(0) + subnet = NetworkModel.get_network_from_xml(xml)['subnet'] + subnet and invalid_addrs.append(ipaddr.IPNetwork(subnet)) + addr_pools = addr_pools if addr_pools else knetwork.PrivateNets + return knetwork.get_one_free_network(invalid_addrs, addr_pools) + def _set_network_subnet(self, params): netaddr = params.get('subnet', '') - net_addrs = [] # lookup a free network address for nat and isolated automatically if not netaddr: - for net_name in self.get_list(): - network = NetworkModel.get_network(self.conn.get(), net_name) - xml = network.XMLDesc(0) - subnet = NetworkModel.get_network_from_xml(xml)['subnet'] - subnet and net_addrs.append(ipaddr.IPNetwork(subnet)) - netaddr = knetwork.get_one_free_network(net_addrs) + netaddr = self._get_available_address() if not netaddr: raise OperationFailed("KCHNET0009E", {'name': params['name']}) diff --git a/src/kimchi/network.py b/src/kimchi/network.py index 24439df..9ad95b4 100644 --- a/src/kimchi/network.py +++ b/src/kimchi/network.py @@ -44,7 +44,7 @@ def get_dev_netaddrs(): # used_nets should include all the subnet allocated in libvirt network # will get host network by get_dev_netaddrs -def get_one_free_network(used_nets): +def get_one_free_network(used_nets, nets_pool=PrivateNets): def _get_free_network(nets, used_nets): for net in nets.subnet(new_prefix=24): if not any(net.overlaps(used) for used in used_nets): @@ -52,7 +52,7 @@ def get_one_free_network(used_nets): return None used_nets = used_nets + get_dev_netaddrs() - for nets in PrivateNets: + for nets in nets_pool: net = _get_free_network(nets, used_nets) if net: return net -- 1.8.4.2

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Then the IP and Bridge name will not be hard coded. Also in some scenarios, such as in nested KVM, the default network created by kimchi on L2 guest can avoid the same network address of L2. https://github.com/kimchi-project/kimchi/issues/302 Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/model/networks.py | 18 +++++------------- src/kimchi/network.py | 3 +++ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py index 7103085..4959add 100644 --- a/src/kimchi/model/networks.py +++ b/src/kimchi/model/networks.py @@ -37,23 +37,15 @@ class NetworksModel(object): def _default_network_check(self): conn = self.conn.get() - xml = """ - <network> - <name>default</name> - <forward mode='nat'/> - <bridge name='virbr0' stp='on' delay='0' /> - <ip address='192.168.122.1' netmask='255.255.255.0'> - <dhcp> - <range start='192.168.122.2' end='192.168.122.254' /> - </dhcp> - </ip> - </network> - """ try: net = conn.networkLookupByName("default") except libvirt.libvirtError: try: - net = conn.networkDefineXML(xml) + subnet = self._get_available_address(knetwork.DefaultNetsPool) + params = {"name": "default", "connection": "nat", + "subnet": subnet} + self.create(params) + net = conn.networkLookupByName("default") except libvirt.libvirtError, e: cherrypy.log.error("Fatal: Cannot create default network " "because of %s, exit kimchid" % e.message, diff --git a/src/kimchi/network.py b/src/kimchi/network.py index 9ad95b4..9bf0c66 100644 --- a/src/kimchi/network.py +++ b/src/kimchi/network.py @@ -26,6 +26,9 @@ APrivateNets = ipaddr.IPNetwork("10.0.0.0/8") BPrivateNets = ipaddr.IPNetwork("172.16.0.0/12") CPrivateNets = ipaddr.IPNetwork('192.168.0.0/16') PrivateNets = [CPrivateNets, BPrivateNets, APrivateNets] +DefaultNetsPool = [ipaddr.IPNetwork('192.168.122.0/23'), + ipaddr.IPNetwork('192.168.124.0/22'), + ipaddr.IPNetwork('192.168.128.0/17')] def get_dev_netaddr(dev): -- 1.8.4.2

It will not work in most of cases. 1. The default network and storage pool is usually created by libvirt with the default values. So an kimchi user will face the same issue while running kimchi on nested virtualization. I.e, there is not way to fix it. Just warning the user about the problem. 2. This issue is in some way related to https://github.com/kimchi-project/kimchi/issues/265 And why should not the user delete default network/storage pool? This limitation should be impose to user when a network/storage pool is used by a template or vm. Otherwise, the user can remove it. Usually the default network/storage pool is created by libvirt. But some time ago, we identified it did not happen in some distros. And as the Kimchi default configuration for templates is pointing to those resources we decided to create them manually on kimchi code to avoid problems while using the templates. So my proposal is: let's revisit all the supported distros and check if libvirt creates default network/storage pool by default, and if so remove this code from kimchi. Then default network/storage pool will have the same behavior from other networks/storage pools. On 03/07/2014 06:52 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
let 'create' attr of networks model to create the default network
ShaoHe Feng (3): move _default_network_check from top model to networks model add a new function to get an available network address Issue #302: let 'create' attr of networks model to create default network
src/kimchi/model/model.py | 35 --------------------------------- src/kimchi/model/networks.py | 46 +++++++++++++++++++++++++++++++++++++------- src/kimchi/network.py | 7 +++++-- 3 files changed, 44 insertions(+), 44 deletions(-)

On 03/07/2014 03:13 PM, Aline Manera wrote:
It will not work in most of cases.
1. The default network and storage pool is usually created by libvirt with the default values. So an kimchi user will face the same issue while running kimchi on nested virtualization. I.e, there is not way to fix it. Just warning the user about the problem.
2. This issue is in some way related to https://github.com/kimchi-project/kimchi/issues/265 And why should not the user delete default network/storage pool? This limitation should be impose to user when a network/storage pool is used by a template or vm. Otherwise, the user can remove it.
Usually the default network/storage pool is created by libvirt. But some time ago, we identified it did not happen in some distros. And as the Kimchi default configuration for templates is pointing to those resources we decided to create them manually on kimchi code to avoid problems while using the templates.
So my proposal is: let's revisit all the supported distros and check if libvirt creates default network/storage pool by default, and if so remove this code from kimchi. Then default network/storage pool will have the same behavior from other networks/storage pools.
So when starting kimchi we just need to make sure the default network/storage pool are active. And activate them if needed. For nested virtualization, the default network will fail to activate as the address is already in use. In this case, we can get the properly error and automatically edit the default network for the user to get an unused address. So the steps to close issue #302 are: 1) Check if libvirt creates the default network/storage pool by default 1.1) If so, remove this code from kimchi code 2) On Kimchi start up, make sure default network/storage pool are active. 2.1) If network activate fails /because/ of the address is already in use, kimchi automatically update the network address and start it.
On 03/07/2014 06:52 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
let 'create' attr of networks model to create the default network
ShaoHe Feng (3): move _default_network_check from top model to networks model add a new function to get an available network address Issue #302: let 'create' attr of networks model to create default network
src/kimchi/model/model.py | 35 --------------------------------- src/kimchi/model/networks.py | 46 +++++++++++++++++++++++++++++++++++++------- src/kimchi/network.py | 7 +++++-- 3 files changed, 44 insertions(+), 44 deletions(-)
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel

On 03/08/2014 02:27 AM, Aline Manera wrote:
So when starting kimchi we just need to make sure the default network/storage pool are active. And activate them if needed. For nested virtualization, the default network will fail to activate as the address is already in use. In this case, we can get the properly error and automatically edit the default network for the user to get an unused address.
So the steps to close issue #302 are: 1) Check if libvirt creates the default network/storage pool by default 1.1) If so, remove this code from kimchi code
Actually, there are 2 issues about "default" network/storage pool on git hub. https://github.com/kimchi-project/kimchi/issues/56 https://github.com/kimchi-project/kimchi/issues/24 Here is some history about these bugs: *From adam:* Recently I have found that some distributions (Fedora 17+) separate the network config into another package. On Fedora it's libvirt-daemon-config-network. Can you just check if adding that as a package dependency will resolve the problem? If so, let's find out if the same solution will resolve the problem of the missing default storage pool. * From BingBu: *'libvirt-daemon-config-network' package is in the libvirt deplist, so if you installed the libvirt, the libvirt-daemon-config-network is installed as as well. I don't think we should add it to the dependency.* **From Aline:* I've already gotten an error about the network default was not active. It should be good to know which networks are available and active. I also send a patch to fix this patch. [project-kimchi] [PATCH] bug fix: Add a default network if no network exists But I give up for: 1. as Bingbu comments: we should avoid hard code. 2. as Bingbu investigation: 'libvirt-daemon-config-network' package is in the libvirt deplist 3. we can make use the network REST API, networks_create method. But later another similar patch was sent and merged, it introduce hard code. [project-kimchi] [PATCH 4/4] Create default network if it does not exist commit 71a3a88 <https://github.com/kimchi-project/kimchi/commit/71a3a883906f54ae8a5bdc9480258b9223aef2c0>. I really do not know why this patch was merged, though some of us do not think this patch is well. So here I just fixed the #302 introduce by 71a3a88 <https://github.com/kimchi-project/kimchi/commit/71a3a883906f54ae8a5bdc9480258b9223aef2c0>, remove the hard code to avoid some bugs.
2) On Kimchi start up, make sure default network/storage pool are active. 2.1) If network activate fails /because/ of the address is already in use, kimchi automatically update the network address and start it.
-- Thanks and best regards! Sheldon Feng(???)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 03/07/2014 03:13 PM, Aline Manera wrote:
It will not work in most of cases.
1. The default network and storage pool is usually created by libvirt with the default values. So an kimchi user will face the same issue while running kimchi on nested virtualization. I.e, there is not way to fix it. Just warning the user about the problem.
Yeap, there is something we can do. If kimchih fails to start the default network because the address is already in use we can automatically update the default network address by using get_free_network()
2. This issue is in some way related to https://github.com/kimchi-project/kimchi/issues/265 And why should not the user delete default network/storage pool? This limitation should be impose to user when a network/storage pool is used by a template or vm. Otherwise, the user can remove it.
Usually the default network/storage pool is created by libvirt. But some time ago, we identified it did not happen in some distros. And as the Kimchi default configuration for templates is pointing to those resources we decided to create them manually on kimchi code to avoid problems while using the templates.
So my proposal is: let's revisit all the supported distros and check if libvirt creates default network/storage pool by default, and if so remove this code from kimchi. Then default network/storage pool will have the same behavior from other networks/storage pools.
I thought more about that and while creating a template user only provides the ISO file and all other configuration is provided by kimchi. Which means we will always set the default network and storage pool for a new template. So default network and storage pool are special resources for kimchi and they should not be deactivated or removed otherwise we will create inconsistent templates from scratch
On 03/07/2014 06:52 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
let 'create' attr of networks model to create the default network
ShaoHe Feng (3): move _default_network_check from top model to networks model add a new function to get an available network address Issue #302: let 'create' attr of networks model to create default network
src/kimchi/model/model.py | 35 --------------------------------- src/kimchi/model/networks.py | 46 +++++++++++++++++++++++++++++++++++++------- src/kimchi/network.py | 7 +++++-- 3 files changed, 44 insertions(+), 44 deletions(-)
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel

On 03/08/2014 02:13 AM, Aline Manera wrote:
It will not work in most of cases.
This patch is to fix #302. I just touch the the related code to create default network. I can works in default network missing case. As the code says, if nested kvm does not has default network, then kimchi can choose a network address and create a default network. If it has, then it will do not create it. I agree, we should not to send patch just for fix issue, we can consider more. actually the Issue #302 is caused by the patch fixing the Issue #22 and Issue #56 we can list all cases, and let me fixed this time.
1. The default network and storage pool is usually created by libvirt with the default values. So an kimchi user will face the same issue while running kimchi on nested virtualization. I.e, there is not way to fix it. Just warning the user about the problem.
2. This issue is in some way related to https://github.com/kimchi-project/kimchi/issues/265 And why should not the user delete default network/storage pool? This limitation should be impose to user when a network/storage pool is used by a template or vm. Otherwise, the user can remove it.
Usually the default network/storage pool is created by libvirt. But some time ago, we identified it did not happen in some distros. And as the Kimchi default configuration for templates is pointing to those resources we decided to create them manually on kimchi code to avoid problems while using the templates.
So my proposal is: let's revisit all the supported distros and check if libvirt creates default network/storage pool by default, and if so remove this code from kimchi. Then default network/storage pool will have the same behavior from other networks/storage pools.
On 03/07/2014 06:52 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
let 'create' attr of networks model to create the default network
ShaoHe Feng (3): move _default_network_check from top model to networks model add a new function to get an available network address Issue #302: let 'create' attr of networks model to create default network
src/kimchi/model/model.py | 35 --------------------------------- src/kimchi/model/networks.py | 46 +++++++++++++++++++++++++++++++++++++------- src/kimchi/network.py | 7 +++++-- 3 files changed, 44 insertions(+), 44 deletions(-)
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 03/10/2014 10:06 AM, Sheldon wrote:
On 03/08/2014 02:13 AM, Aline Manera wrote:
It will not work in most of cases.
This patch is to fix #302.
Yeap! And I agree with it. I am suggesting you to also edit the current network default to an unused address - for the nested virtualization case. For example: # check default network exists try: net = networkLookupByName(default) except: # network default does not exist <create network default using _get_available_address as you did in this patch set> # now we need to make sure the network is active if net.isActive() == 0: try: net.create() except libvirt.libvirtError, e: # default network exists but it is using an used address # libvir: Network Driver error : internal error Network is already in use by interface eth0 try: <update network address> <activate network> except: cherrypy.log.error("Fatal: Cannot activate default network " "because of %s, exit kimchid" % e.message, severity=logging.ERROR) sys.exit(1) What do you think about it?
I just touch the the related code to create default network. I can works in default network missing case.
As the code says, if nested kvm does not has default network, then kimchi can choose a network address and create a default network. If it has, then it will do not create it.
I agree, we should not to send patch just for fix issue, we can consider more. actually the Issue #302 is caused by the patch fixing the Issue #22 and Issue #56
we can list all cases, and let me fixed this time.
1. The default network and storage pool is usually created by libvirt with the default values. So an kimchi user will face the same issue while running kimchi on nested virtualization. I.e, there is not way to fix it. Just warning the user about the problem.
2. This issue is in some way related to https://github.com/kimchi-project/kimchi/issues/265 And why should not the user delete default network/storage pool? This limitation should be impose to user when a network/storage pool is used by a template or vm. Otherwise, the user can remove it.
Usually the default network/storage pool is created by libvirt. But some time ago, we identified it did not happen in some distros. And as the Kimchi default configuration for templates is pointing to those resources we decided to create them manually on kimchi code to avoid problems while using the templates.
So my proposal is: let's revisit all the supported distros and check if libvirt creates default network/storage pool by default, and if so remove this code from kimchi. Then default network/storage pool will have the same behavior from other networks/storage pools.
On 03/07/2014 06:52 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
let 'create' attr of networks model to create the default network
ShaoHe Feng (3): move _default_network_check from top model to networks model add a new function to get an available network address Issue #302: let 'create' attr of networks model to create default network
src/kimchi/model/model.py | 35 --------------------------------- src/kimchi/model/networks.py | 46 +++++++++++++++++++++++++++++++++++++------- src/kimchi/network.py | 7 +++++-- 3 files changed, 44 insertions(+), 44 deletions(-)

On 03/10/2014 10:48 PM, Aline Manera wrote:
On 03/10/2014 10:06 AM, Sheldon wrote:
On 03/08/2014 02:13 AM, Aline Manera wrote:
It will not work in most of cases.
This patch is to fix #302.
Yeap! And I agree with it. I am suggesting you to also edit the current network default to an unused address - for the nested virtualization case.
For example:
# check default network exists try: net = networkLookupByName(default) except: # network default does not exist <create network default using _get_available_address as you did in this patch set>
# now we need to make sure the network is active if net.isActive() == 0: try: net.create() except libvirt.libvirtError, e: # default network exists but it is using an used address # libvir: Network Driver error : internal error Network is already in use by interface eth0 try: <update network address> <activate network> except: cherrypy.log.error("Fatal: Cannot activate default network " "because of %s, exit kimchid" % e.message, severity=logging.ERROR) sys.exit(1)
What do you think about it? ACK
I just touch the the related code to create default network. I can works in default network missing case.
As the code says, if nested kvm does not has default network, then kimchi can choose a network address and create a default network. If it has, then it will do not create it.
I agree, we should not to send patch just for fix issue, we can consider more. actually the Issue #302 is caused by the patch fixing the Issue #22 and Issue #56
we can list all cases, and let me fixed this time.
1. The default network and storage pool is usually created by libvirt with the default values. So an kimchi user will face the same issue while running kimchi on nested virtualization. I.e, there is not way to fix it. Just warning the user about the problem.
2. This issue is in some way related to https://github.com/kimchi-project/kimchi/issues/265 And why should not the user delete default network/storage pool? This limitation should be impose to user when a network/storage pool is used by a template or vm. Otherwise, the user can remove it.
Usually the default network/storage pool is created by libvirt. But some time ago, we identified it did not happen in some distros. And as the Kimchi default configuration for templates is pointing to those resources we decided to create them manually on kimchi code to avoid problems while using the templates.
So my proposal is: let's revisit all the supported distros and check if libvirt creates default network/storage pool by default, and if so remove this code from kimchi. Then default network/storage pool will have the same behavior from other networks/storage pools.
On 03/07/2014 06:52 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
let 'create' attr of networks model to create the default network
ShaoHe Feng (3): move _default_network_check from top model to networks model add a new function to get an available network address Issue #302: let 'create' attr of networks model to create default network
src/kimchi/model/model.py | 35 --------------------------------- src/kimchi/model/networks.py | 46 +++++++++++++++++++++++++++++++++++++------- src/kimchi/network.py | 7 +++++-- 3 files changed, 44 insertions(+), 44 deletions(-)
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 03/10/2014 10:48 PM, Aline Manera wrote:
On 03/10/2014 10:06 AM, Sheldon wrote:
On 03/08/2014 02:13 AM, Aline Manera wrote:
It will not work in most of cases.
This patch is to fix #302.
Yeap! And I agree with it. I am suggesting you to also edit the current network default to an unused address - for the nested virtualization case.
For example:
# check default network exists try: net = networkLookupByName(default) except: # network default does not exist <create network default using _get_available_address as you did in this patch set>
# now we need to make sure the network is active if net.isActive() == 0: try: net.create() except libvirt.libvirtError, e: # default network exists but it is using an used address # libvir: Network Driver error : internal error Network is already in use by interface eth0 try: <update network address>
So how about delete this network and recreate it? Try network update method for IP modify, it can not work. This function is not supported by the connection driver static int virNetworkDefUpdateIP(virNetworkDefPtr def, unsigned int command ATTRIBUTE_UNUSED, int parentIndex ATTRIBUTE_UNUSED, xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED, /* virNetworkUpdateFlags */ unsigned int fflags ATTRIBUTE_UNUSED) { * virNetworkDefUpdateNoSupport(def, "ip");* return -1; } In [89]: net1.update(libvirt.VIR_NETWORK_UPDATE_COMMAND_MODIFY, libvirt.VIR_NETWORK_SECTION_IP, -1, "<ip address='192.168.44.1' />", flags=0) libvirt: Network Driver error : this function is not supported by the connection driver: can't update 'ip' section of network 'test_abc' --------------------------------------------------------------------------- libvirtError Traceback (most recent call last) <ipython-input-89-3ba60f76cce4> in <module>() 1 net1.update(libvirt.VIR_NETWORK_UPDATE_COMMAND_MODIFY, 2 libvirt.VIR_NETWORK_SECTION_IP, ----> 3 -1, "<ip address='192.168.44.1' />", flags=0) /usr/lib64/python2.7/site-packages/libvirt.pyc in update(self, command, section, parentIndex, xml, flags) 2363 running state, its persistent configuration, or both. """ 2364 ret = libvirtmod.virNetworkUpdate(self._o, command, section, parentIndex, xml, flags) -> 2365 if ret == -1: raise libvirtError ('virNetworkUpdate() failed', net=self) 2366 return ret 2367 libvirtError: this function is not supported by the connection driver: can't update 'ip' section of network 'test_abc'
<activate network> except: cherrypy.log.error("Fatal: Cannot activate default network " "because of %s, exit kimchid" % e.message, severity=logging.ERROR) sys.exit(1)
What do you think about it?
I just touch the the related code to create default network. I can works in default network missing case.
As the code says, if nested kvm does not has default network, then kimchi can choose a network address and create a default network. If it has, then it will do not create it.
I agree, we should not to send patch just for fix issue, we can consider more. actually the Issue #302 is caused by the patch fixing the Issue #22 and Issue #56
we can list all cases, and let me fixed this time.
1. The default network and storage pool is usually created by libvirt with the default values. So an kimchi user will face the same issue while running kimchi on nested virtualization. I.e, there is not way to fix it. Just warning the user about the problem.
2. This issue is in some way related to https://github.com/kimchi-project/kimchi/issues/265 And why should not the user delete default network/storage pool? This limitation should be impose to user when a network/storage pool is used by a template or vm. Otherwise, the user can remove it.
Usually the default network/storage pool is created by libvirt. But some time ago, we identified it did not happen in some distros. And as the Kimchi default configuration for templates is pointing to those resources we decided to create them manually on kimchi code to avoid problems while using the templates.
So my proposal is: let's revisit all the supported distros and check if libvirt creates default network/storage pool by default, and if so remove this code from kimchi. Then default network/storage pool will have the same behavior from other networks/storage pools.
On 03/07/2014 06:52 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
let 'create' attr of networks model to create the default network
ShaoHe Feng (3): move _default_network_check from top model to networks model add a new function to get an available network address Issue #302: let 'create' attr of networks model to create default network
src/kimchi/model/model.py | 35 --------------------------------- src/kimchi/model/networks.py | 46 +++++++++++++++++++++++++++++++++++++------- src/kimchi/network.py | 7 +++++-- 3 files changed, 44 insertions(+), 44 deletions(-)
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 03/11/2014 06:41 AM, Sheldon wrote:
On 03/10/2014 10:48 PM, Aline Manera wrote:
On 03/10/2014 10:06 AM, Sheldon wrote:
On 03/08/2014 02:13 AM, Aline Manera wrote:
It will not work in most of cases.
This patch is to fix #302.
Yeap! And I agree with it. I am suggesting you to also edit the current network default to an unused address - for the nested virtualization case.
For example:
# check default network exists try: net = networkLookupByName(default) except: # network default does not exist <create network default using _get_available_address as you did in this patch set>
# now we need to make sure the network is active if net.isActive() == 0: try: net.create() except libvirt.libvirtError, e: # default network exists but it is using an used address # libvir: Network Driver error : internal error Network is already in use by interface eth0 try: <update network address>
So how about delete this network and recreate it?
It is Ok for me
Try network update method for IP modify, it can not work. This function is not supported by the connection driver
static int virNetworkDefUpdateIP(virNetworkDefPtr def, unsigned int command ATTRIBUTE_UNUSED, int parentIndex ATTRIBUTE_UNUSED, xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED, /* virNetworkUpdateFlags */ unsigned int fflags ATTRIBUTE_UNUSED) { * virNetworkDefUpdateNoSupport(def, "ip");* return -1; }
In [89]: net1.update(libvirt.VIR_NETWORK_UPDATE_COMMAND_MODIFY, libvirt.VIR_NETWORK_SECTION_IP, -1, "<ip address='192.168.44.1' />", flags=0) libvirt: Network Driver error : this function is not supported by the connection driver: can't update 'ip' section of network 'test_abc' --------------------------------------------------------------------------- libvirtError Traceback (most recent call last) <ipython-input-89-3ba60f76cce4> in <module>() 1 net1.update(libvirt.VIR_NETWORK_UPDATE_COMMAND_MODIFY, 2 libvirt.VIR_NETWORK_SECTION_IP, ----> 3 -1, "<ip address='192.168.44.1' />", flags=0)
/usr/lib64/python2.7/site-packages/libvirt.pyc in update(self, command, section, parentIndex, xml, flags) 2363 running state, its persistent configuration, or both. """ 2364 ret = libvirtmod.virNetworkUpdate(self._o, command, section, parentIndex, xml, flags) -> 2365 if ret == -1: raise libvirtError ('virNetworkUpdate() failed', net=self) 2366 return ret 2367
libvirtError: this function is not supported by the connection driver: can't update 'ip' section of network 'test_abc'
<activate network> except: cherrypy.log.error("Fatal: Cannot activate default network " "because of %s, exit kimchid" % e.message, severity=logging.ERROR) sys.exit(1)
What do you think about it?
I just touch the the related code to create default network. I can works in default network missing case.
As the code says, if nested kvm does not has default network, then kimchi can choose a network address and create a default network. If it has, then it will do not create it.
I agree, we should not to send patch just for fix issue, we can consider more. actually the Issue #302 is caused by the patch fixing the Issue #22 and Issue #56
we can list all cases, and let me fixed this time.
1. The default network and storage pool is usually created by libvirt with the default values. So an kimchi user will face the same issue while running kimchi on nested virtualization. I.e, there is not way to fix it. Just warning the user about the problem.
2. This issue is in some way related to https://github.com/kimchi-project/kimchi/issues/265 And why should not the user delete default network/storage pool? This limitation should be impose to user when a network/storage pool is used by a template or vm. Otherwise, the user can remove it.
Usually the default network/storage pool is created by libvirt. But some time ago, we identified it did not happen in some distros. And as the Kimchi default configuration for templates is pointing to those resources we decided to create them manually on kimchi code to avoid problems while using the templates.
So my proposal is: let's revisit all the supported distros and check if libvirt creates default network/storage pool by default, and if so remove this code from kimchi. Then default network/storage pool will have the same behavior from other networks/storage pools.
On 03/07/2014 06:52 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
let 'create' attr of networks model to create the default network
ShaoHe Feng (3): move _default_network_check from top model to networks model add a new function to get an available network address Issue #302: let 'create' attr of networks model to create default network
src/kimchi/model/model.py | 35 --------------------------------- src/kimchi/model/networks.py | 46 +++++++++++++++++++++++++++++++++++++------- src/kimchi/network.py | 7 +++++-- 3 files changed, 44 insertions(+), 44 deletions(-)
-- Thanks and best regards!
Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center
participants (3)
-
Aline Manera
-
shaohef@linux.vnet.ibm.com
-
Sheldon