Turned down logging (not always needed to be debug and some image creation cleanup).

This commit is contained in:
Joshua Harlow 2012-01-23 16:35:39 -08:00
parent 01a34e87f5
commit 37ff7b2e92
4 changed files with 34 additions and 43 deletions

View File

@ -6,7 +6,7 @@
keys=root keys=root
[logger_root] [logger_root]
level=DEBUG level=INFO
handlers=hand01 handlers=hand01
formatter=form01 formatter=form01

View File

@ -18,6 +18,7 @@ import os
import tarfile import tarfile
import tempfile import tempfile
import urllib import urllib
import ConfigParser
from devstack import log from devstack import log
from devstack import shell from devstack import shell
@ -190,36 +191,29 @@ class ImageRegistry:
class ImageCreationService: class ImageCreationService:
def __init__(self, cfg=None, flat_urls=None, token=None): def __init__(self, cfg):
self.cfg = cfg
if cfg:
token = cfg.get("passwords", "service_token")
flat_urls = cfg.get('img', 'image_urls')
if flat_urls:
self.urls = [x.strip() for x in flat_urls.split(',')]
else:
self.urls = []
self.token = token
def install(self): def install(self):
for url in self.urls: urls = list()
token = None
#extract them
try:
token = self.cfg.get("passwords", "service_token")
flat_urls = self.cfg.get('img', 'image_urls')
if(flat_urls):
expanded_urls = [x.strip() for x in flat_urls.split(',')]
for url in expanded_urls:
if(url):
urls.append(url)
except(ConfigParser.Error):
LOG.info("No image configuration keys found, skipping glance image install")
#install them in glance
am_installed = 0
for url in urls:
try: try:
if(len(url)): Image(url, token).install()
Image(url, self.token).install() am_installed += 1
except (IOError, tarfile.TarError): except (IOError, tarfile.TarError):
#these are the known exceptions we will catch and all that
#should be emitted (except core python errors, catching all
#exceptions is not good...), since this service is not critical
#just log them and carry on.
LOG.exception('Installing "%s" failed', url) LOG.exception('Installing "%s" failed', url)
return am_installed
if __name__ == "__main__":
import sys
import logging
logging.basicConfig()
LOG = logging.getLogger('image.create')
LOG.setLevel(logging.DEBUG)
ImageCreationService(flat_urls=sys.argv[1], token=sys.argv[2]).install()

View File

@ -14,7 +14,6 @@
# under the License. # under the License.
import logging import logging
import logging.config
import os import os
import sys import sys
@ -22,9 +21,6 @@ import sys
#but the colors make it worth it :-) #but the colors make it worth it :-)
from termcolor import colored from termcolor import colored
LOG_FN_ENV = 'LOG_FILE'
LOG_FILE_DEF = os.path.join("conf", 'logging.ini')
class TermFormatter(logging.Formatter): class TermFormatter(logging.Formatter):
def __init__(self, reg_fmt, date_format): def __init__(self, reg_fmt, date_format):
@ -65,12 +61,5 @@ class TermHandler(logging.Handler):
TermHandler.STREAM.flush() TermHandler.STREAM.flush()
def setup():
logfn = os.getenv(LOG_FN_ENV)
if(logfn == None):
logfn = LOG_FILE_DEF
logging.config.fileConfig(logfn)
def getLogger(name): def getLogger(name):
return logging.getLogger(name) return logging.getLogger(name)

14
stack
View File

@ -15,11 +15,19 @@
import os import os
import os.path import os.path
import logging
import logging.config
import sys import sys
# This needs to happen immediately #this needs to happen immediately (or thats what it seems)
from devstack import log as logging LOG_FN_ENV = 'LOG_FILE'
logging.setup() LOG_FILE_DEF = os.path.join("conf", 'logging.ini')
def setupLogging():
logfn = os.getenv(LOG_FN_ENV)
if(logfn == None):
logfn = LOG_FILE_DEF
logging.config.fileConfig(logfn)
setupLogging()
#this handles our option parsing #this handles our option parsing
from devstack import opts from devstack import opts