[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: (hopefully perl) API to /etc/network/interfaces?



On 05/31/11 at 04:12am, Mike Mestnik wrote:
> On 05/30/11 21:24, Mike Mestnik wrote:
> > On 05/26/11 18:13, William Hopkins wrote:
> >> On 05/26/11 at 05:16pm, Mike Mestnik wrote:
> >>> In-Reply-To: <20080412023656.GR14599@yi.org>
> >>>
> >>> Hello,
> >>>   This is an old thread, but I find myself in a similar situation.  I'd
> >>> like to edit a 4in6 tunnel endpoint and reconfigure the interface. 
> >>> While I can handle the Apache/sudo parts of this I'm stuck with... OK
> >>> now how and I going to change this one value out of this whole file?
> >>>
> >>> My current plan is to convert the file to XML storing away comments and
> >>> partial white space as well as the settings.  Then I should be able to
> >>> edit the setting a write the file back out.
> >>>
> >>> Any better ideas?  For this project Perl seams to be the ideal language.
> >>>
> >>> I may contact the ifupdown maintainer to include this in his package, so
> >>> I'm looking to get it done right.
> >> Generally, there's no desire for added abstractions to configuration files. 
> >> If you need to have network things done automatically which can't be handled by the file itself, add post-ups and write some scripts. Or write scripts which parse current network info from ifconfig/ip. /etc/network/interfaces is a file used by the debian networking scripts to set up your default interfaces, not the be-all end-all of networking configuration. 
> >>
> > I hadn't though of that.  I was merely trying to automate/script a task
> > that was being performed manually.  The task included changing this
> > configuration file.  The solution may be to abstract parts of this
> > configuration file that would then be updated by scripts/users doing
> > things manually.
> >
> > I believe you have slightly misunderstood me.  I need(would like to) to
> > alter network settings based on CGI scripts from Apache.  Can these
> > variables be abstracted?  I don't see how a pre-up script can
> > effect/alter configuration settings.  As an example the address or
> > gateway settings for a static method.  In my experience I'm specifically
> > trying to alter the "endpoint" setting for a "v4tunnel" method.
> >
> > I'm just as confused trying to accomplish this as I was when I started. 
> > It's something a user can do simple with an editor, but trying to do it
> > programing and correctly is my stumbling block.  "IF" I could store the
> > value of this setting in a file that would solve my issue, I can replace
> > the contents of the file and then proceed as usual.
> >
> To: William Hopkins <we.hopkins@gmail.com>
> 
> I didn't get your reply, but I see it in the archives.  Your advice that
> perhaps there is another method for effecting the contents of
> network/interfaces, for example calling a post-up script, was taken to
> hart.  This indeed would perhaps be better then continually altering a
> system config file.
> 
> I'm fumbling a bit with how to actually implement this.  I don't see a
> clear way to abstract settings, take this example:
> 
> auto eth0
> iface eth0 inet static
>     address $(cat /etc/network/eth0-address)
>     netmask 255.255.255.0
>     gateway 186.106.158.1
>     dns-nameservers 8.8.8.8 8.8.4.4
> 
> AFAIK there is no simple way to have the above address setting be read
> from the /etc/network/eth0-address file.  I could go mucking around in
> the static scripts to implement this and FAIK this is already supported
> and I'm just un-aware.

There's no reason for this level of complication. The interfaces file is where your IP belongs for the boot config. 
The interfaces file is not a shell script, it is a custom configuration file for the Debian networking scripts. 
 
> I'm sure you want to change the permanent setting of something which is
> currently set, both the running and boot configurations.  I'm a bit
> unsure of what command would be needed to change the setting I wish to
> alter in the running config...  I was going to resort to an ifdown/ifup
> combo, but now you have me rethinking that approach as well.

Each setting in the interfaces file has a correlation with a system command. the 'address' setting, for example, would be used as an argument to ifconfig. You might have to do some study to figure out the correlations for your tunnel settings.
 
> I'll need to adjust the configuration on several servers every time my
> DSL modem reboots.  The internet is not only packet switch, it's also
> address switched.
> 
> The concept of using scripts to alter configuration files is where I'd
> like to end up, however after carefully reading the man page for the
> network/interfaces file it's clear that determining where one block ends
> and another begins is a non-trivial task.  I have a script that breaks
> the config into blocks, though it might not always do it under any
> circumstance.

There are lots of examples of modifying complicated files via script. But it shouldn't be that complicated.. if you could post your interfaces file and tell what you want it to look like afterward, I could give more concrete advice.
> 
> This is why having a script that can convert the configuration to and
> from like xml or some other format that's more generically interrogated
> and modified is so important.  Here might be the beginning of such a script:

I continue to disagree with you. Your solution seems (IMO) fragile and overly complicated. 
 

-- 
Liam

Attachment: signature.asc
Description: Digital signature


Reply to: