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

« back to all changes in this revision

Viewing changes to cloudinit/__init__.py

  • Committer: Scott Moser
  • Date: 2012-01-12 16:33:53 UTC
  • mto: This revision was merged to the branch mainline in revision 141.
  • Revision ID: smoser@ubuntu.com-20120112163353-nip749m6ytls8sva
Tags: upstream-0.6.3~bzr502
ImportĀ upstreamĀ versionĀ 0.6.3~bzr502

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
    old_conffile = '/etc/ec2-init/ec2-config.cfg'
116
116
    ds_deps = [ DataSource.DEP_FILESYSTEM, DataSource.DEP_NETWORK ]
117
117
    datasource = None
 
118
    cloud_config_str = ''
 
119
    datasource_name = ''
118
120
 
119
121
    builtin_handlers = [ ]
120
122
 
137
139
 
138
140
        try:
139
141
            conf = util.get_base_cfg(self.sysconfig,cfg_builtin, parsed_cfgs)
140
 
        except Exception as e:
 
142
        except Exception:
141
143
            conf = get_builtin_cfg()
142
144
 
143
145
        # support reading the old ConfigObj format file and merging
176
178
                
177
179
        try:
178
180
            f=open(cache, "wb")
179
 
            data = cPickle.dump(self.datasource,f)
 
181
            cPickle.dump(self.datasource,f)
180
182
            f.close()
181
183
            os.chmod(cache,0400)
182
184
        except:
191
193
 
192
194
        cfglist=self.cfg['datasource_list']
193
195
        dslist = list_sources(cfglist, self.ds_deps)
194
 
        dsnames = map(lambda f: f.__name__, dslist)
 
196
        dsnames = [f.__name__ for f in dslist]
 
197
 
195
198
        log.debug("searching for data source in %s" % dsnames)
196
199
        for cls in dslist:
197
200
            ds = cls.__name__
205
208
            except Exception as e:
206
209
                log.warn("get_data of %s raised %s" % (ds,e))
207
210
                util.logexc(log)
208
 
                pass
209
211
        msg = "Did not find data source. searched classes: %s" % dsnames
210
212
        log.debug(msg)
211
213
        raise DataSourceNotFoundException(msg)
298
300
    # if that does not exist, then call 'func' with given 'args'
299
301
    # if 'clear_on_fail' is True and func throws an exception
300
302
    #  then remove the lock (so it would run again)
301
 
    def sem_and_run(self,semname,freq,func,args=[],clear_on_fail=False):
 
303
    def sem_and_run(self,semname,freq,func,args=None,clear_on_fail=False):
 
304
        if args is None:
 
305
            args = []
302
306
        if self.sem_has_run(semname,freq):
303
307
            log.debug("%s already ran %s", semname, freq)
304
308
            return False
360
364
 
361
365
        # give callbacks opportunity to finalize
362
366
        called = [ ]
363
 
        for (mtype, mod) in part_handlers.iteritems():
 
367
        for (_mtype, mod) in part_handlers.iteritems():
364
368
            if mod in called:
365
369
                continue
366
370
            handler_call_end(mod, data, frequency)
367
371
 
368
 
    def handle_user_script(self,data,ctype,filename,payload, frequency):
 
372
    def handle_user_script(self,_data,ctype,filename,payload, _frequency):
369
373
        if ctype == "__end__": return
370
374
        if ctype == "__begin__":
371
375
            # maybe delete existing things here
376
380
        util.write_file("%s/%s" % 
377
381
            (scriptsdir,filename), util.dos2unix(payload), 0700)
378
382
 
379
 
    def handle_upstart_job(self,data,ctype,filename,payload, frequency):
 
383
    def handle_upstart_job(self,_data,ctype,filename,payload, frequency):
380
384
        # upstart jobs are only written on the first boot
381
385
        if frequency != per_instance:
382
386
            return
388
392
        util.write_file("%s/%s" % ("/etc/init",filename),
389
393
            util.dos2unix(payload), 0644)
390
394
 
391
 
    def handle_cloud_config(self,data,ctype,filename,payload, frequency):
 
395
    def handle_cloud_config(self,_data,ctype,filename,payload, _frequency):
392
396
        if ctype == "__begin__":
393
397
            self.cloud_config_str=""
394
398
            return
408
412
 
409
413
        self.cloud_config_str+="\n#%s\n%s" % (filename,payload)
410
414
 
411
 
    def handle_cloud_boothook(self,data,ctype,filename,payload, frequency):
 
415
    def handle_cloud_boothook(self,_data,ctype,filename,payload, _frequency):
412
416
        if ctype == "__end__": return
413
417
        if ctype == "__begin__": return
414
418
 
425
429
        try:
426
430
            env=os.environ.copy()
427
431
            env['INSTANCE_ID']= self.datasource.get_instance_id()
428
 
            ret = subprocess.check_call([filepath], env=env)
 
432
            subprocess.check_call([filepath], env=env)
429
433
        except subprocess.CalledProcessError as e:
430
434
            log.error("boothooks script %s returned %i" %
431
435
                (filepath,e.returncode))
538
542
    else:
539
543
        mod.handle_part(data, ctype, filename, payload, frequency)
540
544
 
541
 
def partwalker_handle_handler(pdata, ctype, filename, payload):
 
545
def partwalker_handle_handler(pdata, _ctype, _filename, payload):
542
546
 
543
547
    curcount = pdata['handlercount']
544
548
    modname  = 'part-handler-%03d' % curcount