lxdui icon indicating copy to clipboard operation
lxdui copied to clipboard

Clone copies Mac address

Open jkelleyrtp opened this issue 7 years ago • 4 comments

Cloning a container from /ui/containers copies the mac address for the container.

image

web6 was created by using lxc copy web5 web6 but web5 was created by using the clone option in the UI.

It seems like LXC knows to change mac addresses when starting the new container but the UI just copies the entire config to the new container (mac address included).

jkelleyrtp avatar Dec 30 '18 22:12 jkelleyrtp

https://github.com/AdaptiveScale/lxdui/blob/270eda96bab8cb16241170f8f9b126883fb42ca6/app/api/models/LXCContainer.py#L258

I'm curious if this is intended behavior... I normally use the UI for building and managing the environment and don't expect new containers to retain their mac address (networking and such).

I think a good compromise between changing the default behavior and not retaining the mac address would be to add another option (copy, duplicate, etc.) to the dropdown list as a separate behavior.

I'd be willing to file a pull request is this would be the intended route.

jkelleyrtp avatar Dec 31 '18 03:12 jkelleyrtp

Hi @jkelleyrtp

From what I remember this is a limitation with PyLXD's migrate function. There are two workarounds:

  1. Delete and recreate the nic acter it's been copied, or
  2. create a snapshot and then create a new container from the snapshot.

I agree with you, I think a copy operation should clear all NIC data before creating the new container. A PR that implements this functionality would be great.

vhajdari avatar Jan 21 '19 03:01 vhajdari

I solve the same problem by del hwaddr config in generate_migration_data and it works

copy_data = container.generate_migration_data()
for c in copy_data["config"].keys():
    if "hwaddr" in c:
        del copy_data["config"][c]

lufeng4828 avatar Jun 06 '19 02:06 lufeng4828

This is still an issue... I solved this for now by changing the macaddress in the config after cloning, but this is a bit of a hassle.

@lufeng4828 I changed this in LXCContainer.py But now when i clone a container i get the error message: FORBIDDEN dictionary changed size during iteration

Edit: Since i use macvlan, this might not work for everyone, but i changed a few things:

sudo nano /home/ubuntu/lxdui/app/api/models/LXCContainer.py

#----------------------------------------- import random

#add new method

def createMacAddress(self):
    mac = [ 0x00, 0x24, 0x81,random.randint(0x00, 0x7f),random.randint(0x00, 0xff),random.randint(0x00, 0xff) ]

    return ':'.join(map(lambda x: "%02x" % x, mac))

#in method 'clone':

        copyData = container.generate_migration_data()
        for c in copyData["config"].keys():
            if "hwaddr" in c:
                copyData["config"][c]=self.createMacAddress()

#-----------------------------------------

And it works. Now every clone gets its own new shiny macaddress.

rinkek avatar Jan 06 '21 21:01 rinkek