Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access lxc.network.link et alii #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

n3storm
Copy link

@n3storm n3storm commented Oct 8, 2018

Some helpful code to help integrators.

@brauner brauner requested a review from stgraber October 8, 2018 10:39
new_key = nk.replace('lxc.network.','lxc.network.{}.'.format(count))
print(container.get_config_item(new_key))
count +=1

Copy link
Member

@stgraber stgraber Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be cleaner that way (untested):

for idx, interface in enumerate(container.get_config_item("lxc.net")):
    for attribute in ("type", "link", "flags", "hwaddr"):
        key = "lxc.net.%s.%s" % (idx, attribute)
        print("%s = %s" % (key, container.get_config_item(key)))

Note the use of lxc.net rather than lxc.network as the code should be aimed at liblxc 3.0 and higher.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much more cleaner :) thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked. Working ok with lxc.network. Looks like lxc.net not yet available in python3 bindinds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What liblxc version are you running? lxc.net needs 2.1 or higher, I confirmed that lxc.network doesn't work here but lxc.net does (on 3.0.2).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debian 9 stretch stable, python3-lxc-3.0.2 latest release
lxc package 2.0.7-2+deb9u2
I checked for you and an updated version of lxc is not available stretch-backports
Debian buster and sid have lxc 2.0.9

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an odd mix, you're certainly not meant to use python3-lxc 3.0.x with lxc 2.0.x :)

Anyway, can you update your pull request to match the suggested version (with lxc.net)?
Then I think we can merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants