Feature #1830

regsubst() function

Added by Thomas Bellman over 1 year ago. Updated over 1 year ago.

Status:Closed Start:12/19/2008
Priority:Low Due date:
Assignee:Thomas Bellman % Done:

0%

Category:functions
Target version:0.24.8
Affected version:0.24.6 Branch:
Keywords:
Votes: 0

Description

A function for performing regular expression substitutions on text strings would be nice.

A draft implementation has been posted to the puppet-devel list by me, and I will work on completing it.

0001-Add-regsubst-rvalue-function-bug-1830.patch - Patch implementing regsubst(), with unit tests. (5.4 KB) Thomas Bellman, 01/28/2009 09:53 am

Associated revisions

History

Updated by James Turnbull over 1 year ago

  • Status changed from Unreviewed to Accepted
  • Assignee set to Thomas Bellman
  • Target version set to unplanned

Updated by Thomas Bellman over 1 year ago

Motivation for having this function:

The general problem is that I get some value, for example from a fact or from a parameter to a definition, that needs to be formatted in some way for the specific use it is being put to. regsubst() can also be used for extracting parts of such values.

As a concrete problem I will be solving, I have a large number of machines that are connected with Ethernet and Infiniband. They should have IP addresses on both networks, for example the machine named n23 should have 10.17.0.23 on the Ethernet net, and 10.18.0.23 on the Infiniband net. On the ethernet network, they get their IP addresses using DHCP (and the dhcpd.conf file is generated with an ERB template). However, none of the DHCP clients I have seen, and few of the DHCP servers, can handle Infiniband. Thus, I want Puppet to derive the node’s Infiniband IP address from its Ethernet IP address. With regsubst() and sprintf() I can do that like this:

 $ipre = '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$'
 $i1 = regsubst($ipaddress_eth0, $ipre, '\1')
 $i2 = regsubst($ipaddress_eth0, $ipre, '\2')
 $i3 = regsubst($ipaddress_eth0, $ipre, '\3')
 $i4 = regsubst($ipaddress_eth0, $ipre, '\4')
 $ibip = sprintf("%d.%d.%d.%d", $i1, $i2 + 1, $i3, $i4)

(This uses the sprintf() function requested in #1831.)

Updated by Thomas Bellman over 1 year ago

Updated by James Turnbull over 1 year ago

  • Status changed from Ready for Checkin to Closed

Pushed in commit:“336b6458a2264c550adf8e6799162380822e0d97” in branch 0.24.x

Updated by James Turnbull over 1 year ago

  • Target version changed from unplanned to 0.24.8

Also available in: Atom PDF