~smoser/ubuntu/quantal/cloud-init/sru

« back to all changes in this revision

Viewing changes to .pc/catchup-391-394.patch/cloudinit/CloudConfig/cc_timezone.py

  • Committer: Package Import Robot
  • Author(s): Scott Moser
  • Date: 2011-10-06 17:11:29 UTC
  • mfrom: (132.1.15 oneiric)
  • Revision ID: package-import@ubuntu.com-20111006171129-7z3pzqavrxt6gbs0
Tags: 0.6.1-0ubuntu22
DataSourceEc2: catch a socket timeout when with a slow metadata
service (LP: #869492).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vi: ts=4 expandtab
 
2
#
 
3
#    Copyright (C) 2009-2010 Canonical Ltd.
 
4
#
 
5
#    Author: Scott Moser <scott.moser@canonical.com>
 
6
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
20
import subprocess
 
21
import os.path
 
22
import shutil
 
23
 
 
24
frequency = per_instance
 
25
tz_base = "/usr/share/zoneinfo"
 
26
 
 
27
def handle(name,cfg,cloud,log,args):
 
28
    print args
 
29
    if len(args) != 0:
 
30
        timezone = args[0]
 
31
    else:
 
32
        timezone = util.get_cfg_option_str(cfg,"timezone",False)
 
33
 
 
34
    if not timezone: return
 
35
 
 
36
    tz_file = "%s/%s" % (tz_base , timezone)
 
37
 
 
38
    if not os.path.isfile(tz_file):
 
39
        log.debug("Invalid timezone %s" % tz_file)
 
40
        raise Exception("Invalid timezone %s" % tz_file)
 
41
 
 
42
    try:
 
43
        fp=open("/etc/timezone","wb")
 
44
        fp.write("%s\n" % timezone)
 
45
        fp.close()
 
46
    except:
 
47
        log.debug("failed to write to /etc/timezone")
 
48
        raise
 
49
 
 
50
    try:
 
51
        shutil.copy(tz_file, "/etc/localtime")
 
52
    except:
 
53
        log.debug("failed to copy %s to /etc/localtime" % tz_file)
 
54
        raise
 
55
        
 
56
    log.debug("set timezone to %s" % timezone)
 
57
    return