Skip to content

Instantly share code, notes, and snippets.

@Openpalm
Created March 6, 2017 08:51
Show Gist options
  • Select an option

  • Save Openpalm/a12361f3b27ad2429c466c1fcea0fcfe to your computer and use it in GitHub Desktop.

Select an option

Save Openpalm/a12361f3b27ad2429c466c1fcea0fcfe to your computer and use it in GitHub Desktop.

Revisions

  1. Openpalm created this gist Mar 6, 2017.
    24 changes: 24 additions & 0 deletions unit vs option
    Original 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
    }
    }
    }
    }