Thank you, this did the trick! Now I just need to string it all back together.
Craig K. Dalrymple Information Services Consultant (Contractor) FMI/Unisys Inc. working for USDA/OCIO/ITS/IOD/NOB FMI(BPA # AG-3144-B-12-0003) 6501 Beacon Drive Kansas City, MO 64113 816-926-8819 (W) -----Original Message----- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Monday, October 01, 2012 6:18 PM To: Velocity Users List Subject: Re: Having trouble doing math with values retrieved from external data source Velocity 1.4, eh? I suppose upgrading to 1.7 isn't an option? With 1.4, you have a hack: #set( $Integer = 1 ) #set( $wanCEIP = $Integer.parseInt($octetFour) + 1) or you can google for VelocityTools' MathTool, drop an instance in the context and use that to handle the parsing and/or addition in a cleaner way: #set( $wanCEIP = $math.add($octetFour, 1) ) On Mon, Oct 1, 2012 at 3:01 PM, Dalrymple, Craig - OCIO-ITS, Kansas City, MO <craig.dalrym...@kcc.usda.gov> wrote: > First, I apologize if this question has come up before, but after doing some > lengthy searching, I was unable to find anything related to the issue I am > having. > > I have included the segment of the template that is causing my headache > below. Let me explain a little what I am doing, and give a background on why. > > The client I work for has a product from Cisco (Cisco Configuration Engine) > for configuring large numbers of network devices. We are trying to make this > rather cumbersome tool a bit easier to use. Basically what it does is keep a > database of information about each object that can be included into > templates, which are then deployed to those objects to keep configurations > close to a uniform standard. This tool supports two template formats, the > legacy and proprietary .cfgtpl, and .vm which is based on the Velocity > Template Engine. Their legacy format allows for some simplification with > #include directives and very limited conditional checking -- > #if (a == b) > Do this > #else > Do something else > #endif > > By limited I mean you can check for equality, and thats all you can check. > Oh, and you cannot have nested condition tests. Obviously, Velocity doesn't > have this limitation, even on the older version that Cisco has deployed (1.4). > > One of the simplifications we would like to include is to handle IP > addressing for these network elements. Currently this is input by users, and > may or may not be accurate. Since the clients IP addresses conform to a > pretty strict standard, the only information we really need is the subnet, > and the subnet mask. With this, we can compute the IP addresses. > > Below is the segment that has me going even more prematurely bald. I am > trying to break an IP4 address into its four parts given the subnet > information, then assign the CER IP address (my side of the MPLS connection) > by adding 1 to this value, and the PER (carrier side) by adding 2. I have > managed to break the address up into a list, and can access the elements > directly. However, when I try to manipulate the values it becomes really > obvious that I am trying to do addition to strings and not integers. > > #set ( $wanSubnet = $!{dsobj.getValue('WAN-Subnet')} ) ## retrieves data from > database > ! breakupIP($wanSubnet) ## this is a Cisco IOS comment line. It is the only > way I can really debug my code, and is included so I can verify that I am > getting data. > #breakupIP($wanSubnet) ## macro to break apart the IP address. > ! third octet is $addressParts.get(2) ##same as above. > #set ( $octetFour = $addressParts.get(3) ) ## I don't want to change the > original value. > ! octetFour is $octetFour ## yet another display > #set ( $wanCEIP = $octetFour + 1) ## the math > #set ( $wanPEIP = $octetFour + 2 ) > ! wanCEIP = $wanCEIP ## display the results. > ! wanPEIP = $wanPEIP > > The output generated is below. Realize this is part of a much larger > template, and I pretty much have to work within the limitations of the tool. > > ! > ! breakupIP(192.168.100.100) > ! third octet is 100 > ! octetFour is 100 > ! wanCEIP = $wanCEIP > ! wanPEIP = $wanPEIP > ! > > Any help would be appreciated; I am just learning how to do this. > > > Craig K. Dalrymple > Information Services Consultant (Contractor) > FMI/Unisys Inc. working for > USDA/OCIO/ITS/IOD/NOB > FMI(BPA # AG-3144-B-12-0003) > 6501 Beacon Drive > Kansas City, MO 64113 > 816-926-8819 (W) > > > > > > This electronic message contains information generated by the USDA solely for > the intended recipients. Any unauthorized interception of this message or the > use or disclosure of the information it contains may violate the law and > subject the violator to civil or criminal penalties. If you believe you have > received this message in error, please notify the sender and delete the email > immediately. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org > For additional commands, e-mail: user-h...@velocity.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org