Mailinglist Archive: yast-devel (121 mails)

< Previous Next >
Re: [yast-devel] Re: [yast-commit] r64487 - in /branches/SuSE-Code-11-SP2-Branch/dns-server: VERSION package/yast2-dns-server.changes src/dialog-main.ycp
  • From: Lukas Ocilka <lukas.ocilka@xxxxxxx>
  • Date: Tue, 21 Jun 2011 09:39:14 +0200
  • Message-id: <4E004AA2.9070200@suse.cz>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dne 20.6.2011 17:26, Martin Vidner napsal(a):
On Mon, Jun 20, 2011 at 01:47:39PM -0000, locilka@xxxxxxxxxxxxxxxxx wrote:
/**
+ * Returns list of IPs currently used by the system.
+ *
+ * @param boolean whether local addresses should be returned as well (the
default is false)
+ */
+list <string> CurrentlyUsedIPs (boolean including_local) {
+ string cmd = "ip addr show | grep 'inet\\(6\\)\\?' | sed 's/^[
\\t]\\+inet\\(6\\)\\?[ \\t]\\+\\([^\\/]\\+\\)\\/.*$/\\2/'";

BTW the -E/--extended-regexp flag makes it easier: grep -E 'inet6?' | ...

And what I learned today, sed has -r/--regexp-extended
(don't you love consistent tools?)

In this case I might rather do all the parsing in YCP/Perl/Ruby and omit
using grep/sed.

+ map cmd_ret = (map) SCR::Execute (.target.bash_output, cmd);
+
+ if (cmd_ret == nil || cmd_ret["exit"]:-1 != 0) {
+ y2error ("Cannot get list of used IPs: %1", cmd_ret);
+ return nil;
+ }
+
+ list <string> used_ips = splitstring (cmd_ret["stdout"]:"", "\n");
+ used_ips = filter (string used_ip, used_ips, ``(used_ip != nil &&
used_ip != ""));

list <string> used_ips = String::NewlineItems(cmd_ret["stdout"]:"");

Everyone raise your mouse cursor if you've ever reimplemented this
function ;-)

OK, reinvented Wheel replaced with Wheel 2.0.
In fact, this String::XYZ should rather be a built-in ... IM(A)O ... but
in another programming language ;)

Thanks for your hints.

- --

Lukas Ocilka, Appliances Department, SUSE LINUX s.r.o.
MD: Jeff Hawn, Jennifer Guild, Alena Hendrichova
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/

iD8DBQFOAEqiVSqMdRCqTiwRAsWHAJ9kTriYoEDVmJjg9SBJbJhM6yYfmQCffYAB
FwcdP1NFkXWnCqW6HEJJSGU=
=Y/Yz
-----END PGP SIGNATURE-----
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
References