[CalendarServer-changes] [5574] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri May 7 09:36:06 PDT 2010
Revision: 5574
http://trac.macosforge.org/projects/calendarserver/changeset/5574
Author: sagen at apple.com
Date: 2010-05-07 09:36:05 -0700 (Fri, 07 May 2010)
Log Message:
-----------
Adds "changeip" support for calendar server
Modified Paths:
--------------
CalendarServer/trunk/support/Makefile.Apple
Added Paths:
-----------
CalendarServer/trunk/calendarserver/tools/changeip_calendar.py
CalendarServer/trunk/calendarserver/tools/test/test_changeip.py
Added: CalendarServer/trunk/calendarserver/tools/changeip_calendar.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/changeip_calendar.py (rev 0)
+++ CalendarServer/trunk/calendarserver/tools/changeip_calendar.py 2010-05-07 16:36:05 UTC (rev 5574)
@@ -0,0 +1,153 @@
+#!/usr/bin/env python
+#
+# changeip script for calendar server
+#
+# Copyright (c) 2005-2010 Apple Inc. All Rights Reserved.
+#
+# IMPORTANT NOTE: This file is licensed only for use on Apple-labeled
+# computers and is subject to the terms and conditions of the Apple
+# Software License Agreement accompanying the package this file is a
+# part of. You may not port this file to another platform without
+# Apple's written consent.
+
+from __future__ import with_statement
+
+import datetime
+import optparse
+import os
+import shutil
+import sys
+from getopt import getopt, GetoptError
+
+from plistlib import readPlist, writePlist
+
+
+def usage():
+ name = os.path.basename(sys.argv[0])
+ print "Usage: %s [-hv] old-ip new-ip [old-hostname new-hostname]" % (name,)
+ print " Options:"
+ print " -h - print this message and exit"
+ print " -v - print additional information when running"
+ print " Arguments:"
+ print " old-ip - current IPv4 address of the server"
+ print " new-ip - new IPv4 address of the server"
+ print " old-hostname - current FQDN for the server"
+ print " new-hostname - new FQDN for the server"
+
+
+def main():
+
+ name = os.path.basename(sys.argv[0])
+
+ # Since the serveradmin command must be run as root, so must this script
+ if os.getuid() != 0:
+ print "%s must be run as root" % (name,)
+ sys.exit(1)
+
+ try:
+ (optargs, args) = getopt(
+ sys.argv[1:], "hvf:", [
+ "help",
+ "verbose",
+ "config=",
+ ]
+ )
+ except GetoptError:
+ usage()
+ sys.exit(1)
+
+ verbose = False
+ configFile = "/etc/caldavd/caldavd.plist"
+
+ for opt, arg in optargs:
+ if opt in ("-h", "--help"):
+ usage()
+ sys.exit(1)
+
+ elif opt in ("-v", "--verbose"):
+ verbose = True
+
+ elif opt in ("-f", "--config"):
+ configFile = arg
+
+ oldIP, newIP = args[0:2]
+ try:
+ oldHostname, newHostname = args[2:4]
+ except ValueError:
+ oldHostname = newHostname = None
+
+ if verbose:
+ print "Calendar Server: updating %s" % (configFile,)
+
+ try:
+ plist = readPlist(configFile)
+ except IOError:
+ print "Error: could not open %s" % (configFile,)
+ sys.exit(1)
+ except Exception, e:
+ print "Error: could not parse %s" % (configFile,)
+ raise e
+
+ writePlist(plist, "%s.changeip.bak" % (configFile,))
+
+ updatePlist(plist, oldIP, newIP, oldHostname, newHostname, verbose=verbose)
+ writePlist(plist, configFile)
+
+ if verbose:
+ print "Calendar Server: done"
+
+def updatePlist(plist, oldIP, newIP, oldHostname, newHostname, verbose=False):
+
+ keys = (
+ ("Authentication", "Wiki", "Hostname"),
+ ("BindAddresses",),
+ ("Notifications", "Services", "XMPPNotifier", "Host"),
+ ("Notifications", "Services", "XMPPNotifier", "JID"),
+ ("Notifications", "Services", "XMPPNotifier", "ServiceAddress"),
+ ("Scheduling", "iMIP", "Receiving", "Server"),
+ ("Scheduling", "iMIP", "Sending", "Server"),
+ ("ServerHostName",),
+ )
+
+ def _replace(value, oldIP, newIP, oldHostname, newHostname):
+ newValue = value.replace(oldIP, newIP)
+ if oldHostname and newHostname:
+ newValue = newValue.replace(oldHostname, newHostname)
+ if verbose and value != newValue:
+ print "Changed %s -> %s" % (value, newValue)
+ return newValue
+
+ for keyPath in keys:
+ parent = plist
+ path = keyPath[:-1]
+ key = keyPath[-1]
+
+ for step in path:
+ if not parent.has_key(step):
+ parent = None
+ break
+ parent = parent[step]
+
+ if parent:
+ if parent.has_key(key):
+ value = parent[key]
+
+ if isinstance(value, list):
+ newValue = []
+ for item in value:
+ item = _replace(item, oldIP, newIP, oldHostname,
+ newHostname)
+ newValue.append(item)
+ else:
+ newValue = _replace(value, oldIP, newIP, oldHostname,
+ newHostname)
+
+ parent[key] = newValue
+
+
+
+
+
+
+if __name__ == '__main__':
+ main()
Property changes on: CalendarServer/trunk/calendarserver/tools/changeip_calendar.py
___________________________________________________________________
Added: svn:executable
+ *
Added: CalendarServer/trunk/calendarserver/tools/test/test_changeip.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_changeip.py (rev 0)
+++ CalendarServer/trunk/calendarserver/tools/test/test_changeip.py 2010-05-07 16:36:05 UTC (rev 5574)
@@ -0,0 +1,75 @@
+##
+# Copyright (c) 2005-2010 Apple Inc. All rights reserved.
+#
+# 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.
+##
+
+from twistedcaldav.test.util import TestCase
+from calendarserver.tools.changeip_calendar import updatePlist
+
+class ChangeIPTestCase(TestCase):
+
+ def test_updatePlist(self):
+
+ plist = {
+ "Authentication" : {
+ "Wiki" : {
+ "Hostname" : "original_hostname",
+ "Other" : "should_be_untouched",
+ },
+ },
+ "Untouched" : "dont_change_me",
+ "BindAddresses" : [
+ "10.1.1.1",
+ "192.168.1.1",
+ "original_hostname",
+ ],
+ "ServerHostName" : "",
+ "Notifications" : {
+ "Services" : {
+ "XMPPNotifier" : {
+ "Host" : "original_hostname",
+ "JID" : "com.apple.notificationuser at original_hostname",
+ },
+ },
+ },
+ }
+
+ updatePlist(plist, "10.1.1.1", "10.1.1.2", "original_hostname",
+ "new_hostname")
+
+ self.assertEquals(plist,
+ {
+ "Authentication" : {
+ "Wiki" : {
+ "Hostname" : "new_hostname",
+ "Other" : "should_be_untouched",
+ },
+ },
+ "Untouched" : "dont_change_me",
+ "BindAddresses" : [
+ "10.1.1.2",
+ "192.168.1.1",
+ "new_hostname",
+ ],
+ "ServerHostName" : "",
+ "Notifications" : {
+ "Services" : {
+ "XMPPNotifier" : {
+ "Host" : "new_hostname",
+ "JID" : "com.apple.notificationuser at new_hostname",
+ },
+ },
+ },
+ }
+ )
Modified: CalendarServer/trunk/support/Makefile.Apple
===================================================================
--- CalendarServer/trunk/support/Makefile.Apple 2010-05-07 01:48:46 UTC (rev 5573)
+++ CalendarServer/trunk/support/Makefile.Apple 2010-05-07 16:36:05 UTC (rev 5574)
@@ -102,6 +102,10 @@
$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)/System/Library/ServerSetup/MigrationExtras"
$(_v) $(INSTALL_FILE) "$(Sources)/contrib/migration/59_calendarmigrator.py" "$(DSTROOT)/System/Library/ServerSetup/MigrationExtras/59_calendarmigrator.py"
$(_v) chmod ugo+x "$(DSTROOT)/System/Library/ServerSetup/MigrationExtras/59_calendarmigrator.py"
+ @echo "Installing changeip config..."
+ $(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)/usr/libexec/changeip"
+ $(_v) $(INSTALL_FILE) "$(Sources)/calendarserver/tools/changeip_calendar.py" "$(DSTROOT)/usr/libexec/changeip/changeip_calendar.py"
+ $(_v) chmod ugo+x "$(DSTROOT)/usr/libexec/changeip/changeip_calendar.py"
@echo "Installing backup config..."
$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(ETCDIR)/server_backup/"
$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(LIBEXECDIR)/server_backup/"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100507/725c156f/attachment.html>
More information about the calendarserver-changes
mailing list