Created
March 6, 2017 08:51
-
-
Save Openpalm/a12361f3b27ad2429c466c1fcea0fcfe to your computer and use it in GitHub Desktop.
Revisions
-
Openpalm created this gist
Mar 6, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ def getNewSrvIp(project: String, stage: String): Option[String] = { val ipList = dba.getServer.filter(_.project.equals(project)).map(x => x.ip) val subnet = dba.getSubnet.filter(_.project.equals(project)).head.subnet val prjRange = dba.getIpRanges.filter(_.project.equals(project)).filter(_.stage.equals(stage)).hea val upperBound = prjRange.upp val lowerBound = prjRange.low val ipInts = ipList.map(x => x.split("\\.").map(x => x.toInt)) val fourthOctetList = ipInts.map(x => x(3)).sorted val ipGap = getIntGap(fourthOctetList.toList) match { case Some(x: Int) => Some(subnet + "." + (x . toString)) case None => { if (fourthOctetList.length == 0) { // empty list Some(subnet + "." + ((lowerBound + 1) . toString)) } else if (fourthOctetList.last < upperBound) { // list has more than 1 item Some(subnet + "." + ((fourthOctetList.last + 1) . toString)) } else { println("ip range limit exceeded.") // limit exceeded None } } } }