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

Questions About RefreshIP.py #5

Open
mahiuchun opened this issue Mar 24, 2012 · 8 comments
Open

Questions About RefreshIP.py #5

mahiuchun opened this issue Mar 24, 2012 · 8 comments
Assignees

Comments

@mahiuchun
Copy link

https://github.com/liuqun/njit8021xclient/blob/master/src/RefreshIP.py

In summary, this Python script uses D-Bus to ask NM(NetworkManager) to refresh IP.

1.Python's portability is questionable.
http://sheddingbikes.com/posts/1285063820.html

2.The interface selection mechanism is not consistent with njit-client.
njit-client is not dependent on NM, it uses low-level APIs directly.

3.Dependency of D-Bus and NM is annoying for CLI motivated users.
cfy reported that the latest version doesn't work well for him. In fact, he doesn't use NM at all.

My suggestion: Use a Shell script instead, which accepts device name as an argument.
Use POSIX Shell to archive maximal portability.

NM integration is elegant in some aspect. But I guess call NM in a GUI front-end is better.
Information from NM can help casual user pick a right interface.

@liuqun
Copy link
Owner

liuqun commented Mar 25, 2012

When I wrote RefreshIP.py for Ubuntu 9.10, I found it really hard to control NM using its DBus interface. There is a command line tool cnetworkmananger which is helpful to control NM. We only need to refresh the dynamic ip address from command line, but it seems to be not supported from command line.

https://github.com/mvidner/cnetworkmanager

@ghost ghost assigned liuqun Mar 25, 2012
@mahiuchun
Copy link
Author

As I stated in the origin post. I don't think using NM for a CLI tool is philosophically appropriate. I know that NM is shipped with some Desktop-oriented Linux distributions. However, NM has bad reputation among some experienced Linux users.

To refresh IP address by DHCP, you can simply use dhclient(8) .
http://linux.vbird.org/linux_server/0140networkcommand.php#dhclient
http://manpages.ubuntu.com/manpages/precise/man8/dhclient.8.html

BTW, NM has an official command line interface since version 0.8.1, and it is called nmcli(1) .
http://live.gnome.org/NetworkManager/ReleaseProcess
http://manpages.ubuntu.com/manpages/precise/man1/nmcli.1.html

@mahiuchun
Copy link
Author

@liuqun
Copy link
Owner

liuqun commented Mar 27, 2012

The python script to refresh IP address works as follows

#!/usr/bin/python

import dbus

nm = dbus.SystemBus().get_object('org.freedesktop.NetworkManager','/org/freedesktop/NetworkManager')
nmService = ...
nmConnection = ...
nmDevice = ...
nmSpecificObject = ...

dbus.Interface(nm,'org.freedesktop.NetworkManager').ActivateConnection(nmService, nmConnection, nmDevice, nmSpecificObject)

We can also use the command line tool "dbus-send" to talk to NM as the following shell script,
which is similar to using the python script.

#!/bin/sh

echo Refreshing IP address...

#nmService=string:"org.freedesktop.NetworkManagerSystemSettings"
#nmConnection='objpath:/org/freedesktop/NetworkManagerSettings/0'
#nmDevice='objpath:/org/freedesktop/Hal/devices/net_00_16_36_52_53_12'
#nmSpecificObject='objpath:/'

dbus-send --system --type=method_call \
          --dest=org.freedesktop.NetworkManager \
                /org/freedesktop/NetworkManager \
                 org.freedesktop.NetworkManager.ActivateConnection \
            string:"org.freedesktop.NetworkManagerSystemSettings" \
            objpath:/org/freedesktop/NetworkManagerSettings/0 \
            objpath:/org/freedesktop/Hal/devices/net_00_16_36_52_53_12 \
            objpath:/

@mahiuchun
Copy link
Author

Thank you for your work.

But my concern is not about how to talk to NM.
Instead, I doubt whether we can safely assume that NM is running or even exists in users' machine.
Given the very simple usage of dhcpd(8) or dhclient(8), why not use them?

@liuqun
Copy link
Owner

liuqun commented Mar 27, 2012

I've seen ARM-Linux based embedded developing tool-kits which supports D-Bus.
I guess there might be some embedded linux systems, such as an Ubuntu net-book with an ARM CPU, which should probably support the FreeDesktop.org/NetworkManager.

@liuqun
Copy link
Owner

liuqun commented Mar 27, 2012

Third-party developers on njit-client can put an customized RefreshIP script as follows, replacing my python script:

#!/bin/sh

udhcpc --renew


killall dhclient
dhclient

@mahiuchun
Copy link
Author

Put it in another way. What's advantage of using NM?
If there are multiple active ethernet interfaces, what would your current script do?
Why don't you simply use some commands that can specify interface easily?

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

No branches or pull requests

2 participants