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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@
# A few basic checks of the current state
assert(len(ips) > 0)

# Getting config items under indexed key
print("Accessing indexed config entries")
count = 0
networks = len(set(container.get_config_item('lxc.network')))
network_keys = ['lxc.network.type','lxc.network.link','lxc.network.flags','lxc.netwo
rk.hwaddr',]
while (count < networks):
for nk in network_keys:
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.


## Test running config
assert(container.name == CONTAINER_NAME
== container.get_config_item("lxc.uts.name")
Expand Down