3
# Copyright (C) 2009-2010 Canonical Ltd.
5
# Author: Scott Moser <scott.moser@canonical.com>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License version 3, as
9
# published by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
from cloudinit.CloudConfig import per_instance
19
from cloudinit import util
24
frequency = per_instance
25
tz_base = "/usr/share/zoneinfo"
27
def handle(name,cfg,cloud,log,args):
32
timezone = util.get_cfg_option_str(cfg,"timezone",False)
34
if not timezone: return
36
tz_file = "%s/%s" % (tz_base , timezone)
38
if not os.path.isfile(tz_file):
39
log.debug("Invalid timezone %s" % tz_file)
40
raise Exception("Invalid timezone %s" % tz_file)
43
fp=open("/etc/timezone","wb")
44
fp.write("%s\n" % timezone)
47
log.debug("failed to write to /etc/timezone")
51
shutil.copy(tz_file, "/etc/localtime")
53
log.debug("failed to copy %s to /etc/localtime" % tz_file)
56
log.debug("set timezone to %s" % timezone)