replace DataSource's self.log
After adding the 'log' element to the DataSource class, pickling would fail with TypeError: can't pickle file objects Instead of having the object with a log reference, use one from 'DataSource.log' and have that set by cloudinit
This commit is contained in:
@@ -22,17 +22,22 @@ DEP_NETWORK = "NETWORK"
|
|||||||
|
|
||||||
import UserDataHandler as ud
|
import UserDataHandler as ud
|
||||||
|
|
||||||
|
log = None
|
||||||
|
def setlog(log_in=None, name="DataSource"):
|
||||||
|
log = log_in
|
||||||
|
if log is None:
|
||||||
|
class NullHandler(logging.Handler):
|
||||||
|
def emit(self,record): pass
|
||||||
|
log = logging.getLogger(name)
|
||||||
|
log.addHandler(NullHandler())
|
||||||
|
|
||||||
class DataSource:
|
class DataSource:
|
||||||
userdata = None
|
userdata = None
|
||||||
metadata = None
|
metadata = None
|
||||||
userdata_raw = None
|
userdata_raw = None
|
||||||
log = None
|
|
||||||
|
|
||||||
def __init__(self, log=None):
|
def __init__(self):
|
||||||
if not log:
|
pass
|
||||||
import logging
|
|
||||||
log = logging.log
|
|
||||||
self.log = log
|
|
||||||
|
|
||||||
def get_userdata(self):
|
def get_userdata(self):
|
||||||
if self.userdata == None:
|
if self.userdata == None:
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import DataSource
|
import DataSource
|
||||||
|
log = DataSource.log
|
||||||
|
|
||||||
from cloudinit import seeddir
|
from cloudinit import seeddir
|
||||||
import cloudinit.util as util
|
import cloudinit.util as util
|
||||||
@@ -40,7 +41,7 @@ class DataSourceEc2(DataSource.DataSource):
|
|||||||
if util.read_optional_seed(seedret,base=self.seeddir+ "/"):
|
if util.read_optional_seed(seedret,base=self.seeddir+ "/"):
|
||||||
self.userdata_raw = seedret['user-data']
|
self.userdata_raw = seedret['user-data']
|
||||||
self.metadata = seedret['meta-data']
|
self.metadata = seedret['meta-data']
|
||||||
self.log.debug("using seeded ec2 data in %s" % self.seeddir)
|
log.debug("using seeded ec2 data in %s" % self.seeddir)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -102,13 +103,13 @@ class DataSourceEc2(DataSource.DataSource):
|
|||||||
reason = "url error [%s]" % e.reason
|
reason = "url error [%s]" % e.reason
|
||||||
|
|
||||||
if x == 0:
|
if x == 0:
|
||||||
self.log.warning("waiting for metadata service at %s\n" % url)
|
log.warning("waiting for metadata service at %s\n" % url)
|
||||||
|
|
||||||
self.log.warning(" %s [%02s/%s]: %s\n" %
|
log.warning(" %s [%02s/%s]: %s\n" %
|
||||||
(time.strftime("%H:%M:%S",time.gmtime()), x+1, sleeps, reason))
|
(time.strftime("%H:%M:%S",time.gmtime()), x+1, sleeps, reason))
|
||||||
time.sleep(sleeptime)
|
time.sleep(sleeptime)
|
||||||
|
|
||||||
self.log.critical("giving up on md after %i seconds\n" %
|
log.critical("giving up on md after %i seconds\n" %
|
||||||
int(time.time()-starttime))
|
int(time.time()-starttime))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ class DataSourceEc2(DataSource.DataSource):
|
|||||||
if entname == "ephemeral" and name == "ephemeral0":
|
if entname == "ephemeral" and name == "ephemeral0":
|
||||||
found = device
|
found = device
|
||||||
if found == None:
|
if found == None:
|
||||||
self.log.warn("unable to convert %s to a device" % name)
|
log.warn("unable to convert %s to a device" % name)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# LP: #611137
|
# LP: #611137
|
||||||
@@ -151,7 +152,7 @@ class DataSourceEc2(DataSource.DataSource):
|
|||||||
for nto in tlist:
|
for nto in tlist:
|
||||||
cand = "/dev/%s%s" % (nto, short[len(nfrom):])
|
cand = "/dev/%s%s" % (nto, short[len(nfrom):])
|
||||||
if os.path.exists(cand):
|
if os.path.exists(cand):
|
||||||
self.log.debug("remapped device name %s => %s" % (found,cand))
|
log.debug("remapped device name %s => %s" % (found,cand))
|
||||||
return(cand)
|
return(cand)
|
||||||
return ofound
|
return ofound
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import DataSource
|
import DataSource
|
||||||
|
log = DataSource.log
|
||||||
|
|
||||||
from cloudinit import seeddir
|
from cloudinit import seeddir
|
||||||
import cloudinit.util as util
|
import cloudinit.util as util
|
||||||
@@ -54,7 +55,7 @@ class DataSourceNoCloud(DataSource.DataSource):
|
|||||||
if parse_cmdline_data(self.cmdline_id, md):
|
if parse_cmdline_data(self.cmdline_id, md):
|
||||||
found.append("cmdline")
|
found.append("cmdline")
|
||||||
except:
|
except:
|
||||||
util.logexc(self.log,util.WARN)
|
util.logexc(log)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# check to see if the seeddir has data.
|
# check to see if the seeddir has data.
|
||||||
@@ -63,7 +64,7 @@ class DataSourceNoCloud(DataSource.DataSource):
|
|||||||
md = util.mergedict(md,seedret['meta-data'])
|
md = util.mergedict(md,seedret['meta-data'])
|
||||||
ud = seedret['user-data']
|
ud = seedret['user-data']
|
||||||
found.append(self.seeddir)
|
found.append(self.seeddir)
|
||||||
self.log.debug("using seeded cache data in %s" % self.seeddir)
|
log.debug("using seeded cache data in %s" % self.seeddir)
|
||||||
|
|
||||||
# there was no indication on kernel cmdline or data
|
# there was no indication on kernel cmdline or data
|
||||||
# in the seeddir suggesting this handler should be used.
|
# in the seeddir suggesting this handler should be used.
|
||||||
@@ -80,14 +81,14 @@ class DataSourceNoCloud(DataSource.DataSource):
|
|||||||
seedfound=proto
|
seedfound=proto
|
||||||
break
|
break
|
||||||
if not seedfound:
|
if not seedfound:
|
||||||
self.log.debug("seed from %s not supported by %s" %
|
log.debug("seed from %s not supported by %s" %
|
||||||
(seedfrom, self.__class__))
|
(seedfrom, self.__class__))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# this could throw errors, but the user told us to do it
|
# this could throw errors, but the user told us to do it
|
||||||
# so if errors are raised, let them raise
|
# so if errors are raised, let them raise
|
||||||
(md_seed,ud) = util.read_seeded(seedfrom)
|
(md_seed,ud) = util.read_seeded(seedfrom)
|
||||||
self.log.debug("using seeded cache data from %s" % seedfrom)
|
log.debug("using seeded cache data from %s" % seedfrom)
|
||||||
|
|
||||||
# values in the command line override those from the seed
|
# values in the command line override those from the seed
|
||||||
md = util.mergedict(md,md_seed)
|
md = util.mergedict(md,md_seed)
|
||||||
|
|||||||
@@ -87,12 +87,12 @@ class DataSourceOVF(DataSource.DataSource):
|
|||||||
seedfound = proto
|
seedfound = proto
|
||||||
break
|
break
|
||||||
if not seedfound:
|
if not seedfound:
|
||||||
self.log.debug("seed from %s not supported by %s" %
|
log.debug("seed from %s not supported by %s" %
|
||||||
(seedfrom, self.__class__))
|
(seedfrom, self.__class__))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
(md_seed,ud) = util.read_seeded(seedfrom)
|
(md_seed,ud) = util.read_seeded(seedfrom)
|
||||||
self.log.debug("using seeded cache data from %s" % seedfrom)
|
log.debug("using seeded cache data from %s" % seedfrom)
|
||||||
|
|
||||||
md = util.mergedict(md,md_seed)
|
md = util.mergedict(md,md_seed)
|
||||||
found.append(seedfrom)
|
found.append(seedfrom)
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ def logging_set_from_cfg(cfg):
|
|||||||
|
|
||||||
|
|
||||||
import DataSource
|
import DataSource
|
||||||
|
DataSource.setlog(log)
|
||||||
import UserDataHandler
|
import UserDataHandler
|
||||||
|
|
||||||
class CloudInit:
|
class CloudInit:
|
||||||
@@ -190,7 +191,7 @@ class CloudInit:
|
|||||||
for cls in dslist:
|
for cls in dslist:
|
||||||
ds = cls.__name__
|
ds = cls.__name__
|
||||||
try:
|
try:
|
||||||
s = cls(log)
|
s = cls()
|
||||||
if s.get_data():
|
if s.get_data():
|
||||||
self.datasource = s
|
self.datasource = s
|
||||||
self.datasource_name = ds
|
self.datasource_name = ds
|
||||||
|
|||||||
Reference in New Issue
Block a user