Groovy web console

subscribe to the feed Subscribe
to this
site

mambo

Published 4 weeks ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonOutput
class Record {

  String content
  Boolean disabled

  Record(content, disabled) {
    this.content = content
    this.disabled = disabled
  }

}

def call(project_name, record_name, record_content, record_type) {
  def records = []
  for (i = 0; i < record_content.size(); i++) {
    records.add(new Record(record_content[i], false))
  }
  def records_json = JsonOutput.prettyPrint(JsonOutput.toJson(records))

  def requestBody=
    """{
    "rrsets": [
        {
            "changetype": "replace",
            "name": "${record_name}",
            "records": ${records_json},
            "ttl": 86000,
            "type": "${record_type}"
        }
    ]
    }"""

   print requestBody
}

def CONSUL_IPS= [
  "10.97.12.14",   "10.97.12.13",   "10.97.12.7" ]

call("molotoff", "consul.svc.molotoff.panta.criticaltechworks.com", CONSUL_IPS, "A")