#!/usr/bin/env oo-ruby #-- # Copyright 2010 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #++ require 'rubygems' require 'parseconfig' require 'getoptlong' require 'ipaddr' def usage puts <.key) -g|--gss-tsig Use GSS-TSIG Kerberos credentials to bind (optional) -?|--help Print this message USAGE end opts = GetoptLong.new( ["--with-node-hostname", "-h", GetoptLong::REQUIRED_ARGUMENT], ["--with-node-ip", "-n", GetoptLong::REQUIRED_ARGUMENT], ["--domain", "-d", GetoptLong::OPTIONAL_ARGUMENT], ["--dns-server", "-s", GetoptLong::OPTIONAL_ARGUMENT], ["--key-file", "-k", GetoptLong::OPTIONAL_ARGUMENT], ["--gss-tsig", "-g", GetoptLong::NO_ARGUMENT], ["--help", "-?", GetoptLong::NO_ARGUMENT] ) args = {} begin opts.each{ |k,v| args[k]=v } rescue GetoptLong::Error => e usage exit 255 end ip = args["--with-node-ip"] node_hostname = args["--with-node-hostname"] node_domain = args["--domain"] || "example.com" server = args["--dns-server"] || "127.0.0.1" key = args["--key-file"] || "/var/named/#{node_domain}.key" if args["--help"] usage exit 0 end if ip.nil? || ip.empty? || node_hostname.nil? || node_hostname.empty? usage exit 255 end rectype = IPAddr.new(ip).ipv6? ? "AAAA" : "A" command =<<-EOF server #{server} update delete #{node_hostname}.#{node_domain} #{rectype} update add #{node_hostname}.#{node_domain} 180 #{rectype} #{ip} send EOF if args["--gss-tsig"] system "nsupdate -g <