[libvirt] Are there interfaces to change IP address of given domain before it runn

Dear all, I has created a image file in local filesystem. And now, I wrote a program based on libvirt to run two instances of given image file. But I found they are using the same IP address which make them cut off the network. So, I wonder there are any solution to guarantee that both VM instances would be given different IP address after they are started. Thanks in advance, Ian

On Tue, Nov 25, 2008 at 4:11 AM, Ian jonhson <jonhson.ian@gmail.com> wrote:
So, I wonder there are any solution to guarantee that both VM instances would be given different IP address after they are started.
Use DHCP, and ensure that when you create the domain configuration xml file for the second instance that you remove the MAC address lines before you define it in virsh so libvirt generates new MAC addresses for the copies. You want libvirt to be abstract from the guest, so it's not going to be meddling around in your guest's filesystem to configure anything. Bryan

On Tue, Nov 25, 2008 at 12:57:06PM -0800, Bryan McLellan wrote:
On Tue, Nov 25, 2008 at 4:11 AM, Ian jonhson <jonhson.ian@gmail.com> wrote:
So, I wonder there are any solution to guarantee that both VM instances would be given different IP address after they are started.
Use DHCP, and ensure that when you create the domain configuration xml file for the second instance that you remove the MAC address lines before you define it in virsh so libvirt generates new MAC addresses for the copies.
Seconded - DHCP is your friend. Aside from MAC address, when cloning VMs you must also change name, UUID, posibly VNC port if hardcoded. To automate this, we provide a virt-clone tool. It won't touch anything inside the guest, but it'll take care of the disk copy and changing all neccessary bits of the XML config. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Seconded - DHCP is your friend. Aside from MAC address, when cloning VMs you must also change name, UUID, posibly VNC port if hardcoded. To automate this, we provide a virt-clone tool.
agree.
It won't touch anything inside the guest, but it'll take care of the disk copy and changing all neccessary bits of the XML config.
So, are there any idea to create or clone a new VM instance so that I can connect it with internet and then ship some applications into the new VM to run? Thanks, Ian

Use DHCP, and ensure that when you create the domain configuration xml file for the second instance that you remove the MAC address lines before you define it in virsh so libvirt generates new MAC addresses for the copies.
However, I can not know the IP address before it has been allocated by DHCP service. So, I can not scp my applications outside into new cloned VM. Have any solution to bind a given IP address to a VM instance?
You want libvirt to be abstract from the guest, so it's not going to be meddling around in your guest's filesystem to configure anything.
As said above, I can not login VM instance and change the network configuration. Also, I can not get the new-allocated IP address if I want to login the VM and do some jobs, right? Thanks again, Ian

On Wed, Nov 26, 2008 at 08:02:42PM +0800, Ian jonhson wrote:
Use DHCP, and ensure that when you create the domain configuration xml file for the second instance that you remove the MAC address lines before you define it in virsh so libvirt generates new MAC addresses for the copies.
However, I can not know the IP address before it has been allocated by DHCP service. So, I can not scp my applications outside into new cloned VM. Have any solution to bind a given IP address to a VM instance?
Setup fixed MAC -> hostname -> IP address mappings in your DNS / DHCP servers Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (3)
-
Bryan McLellan
-
Daniel P. Berrange
-
Ian jonhson