General cleanup
* Reorder imports * Remove unused code * Add missing copyright header in glance.api.v1.members * Pass in 'pool' to glance.store.scrubber.Scrubber._cleanup * Fix NameError in glance.api.v1.images.Controller: request -> req * Fix except block in glance.notifier to properly catch multiple exceptions Change-Id: I30d895b5ff1246e8d637720ef2f4aacab9cf7ede
This commit is contained in:
parent
f1bc67c24b
commit
ee2d212f81
@ -43,7 +43,6 @@ if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
|
|||||||
|
|
||||||
gettext.install('glance', unicode=1)
|
gettext.install('glance', unicode=1)
|
||||||
|
|
||||||
from glance import version
|
|
||||||
from glance.common import cfg
|
from glance.common import cfg
|
||||||
from glance.common import config
|
from glance.common import config
|
||||||
|
|
||||||
|
@ -21,13 +21,9 @@ Controller for Image Cache Management API
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import webob.exc
|
|
||||||
|
|
||||||
from glance.common import exception
|
|
||||||
from glance.common import wsgi
|
|
||||||
from glance.api.v1 import controller
|
from glance.api.v1 import controller
|
||||||
|
from glance.common import wsgi
|
||||||
from glance import image_cache
|
from glance import image_cache
|
||||||
from glance import registry
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -30,12 +30,12 @@ import re
|
|||||||
|
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from glance import image_cache
|
|
||||||
from glance import registry
|
|
||||||
from glance.api.v1 import images
|
from glance.api.v1 import images
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
from glance.common import utils
|
from glance.common import utils
|
||||||
from glance.common import wsgi
|
from glance.common import wsgi
|
||||||
|
from glance import image_cache
|
||||||
|
from glance import registry
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
get_images_re = re.compile(r'^(/v\d+)*/images/([^\/]+)$')
|
get_images_re = re.compile(r'^(/v\d+)*/images/([^\/]+)$')
|
||||||
|
@ -24,9 +24,6 @@ return
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import routes
|
|
||||||
|
|
||||||
from glance.api import v1
|
|
||||||
from glance.api import versions
|
from glance.api import versions
|
||||||
from glance.common import wsgi
|
from glance.common import wsgi
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ class Controller(controller.BaseController):
|
|||||||
"%(max_image_size)d. Supplied image size was "
|
"%(max_image_size)d. Supplied image size was "
|
||||||
"%(image_size)d") % locals()
|
"%(image_size)d") % locals()
|
||||||
logger.warn(msg)
|
logger.warn(msg)
|
||||||
raise HTTPBadRequest(msg, request=request)
|
raise HTTPBadRequest(msg, request=req)
|
||||||
|
|
||||||
location, size, checksum = store.add(image_meta['id'],
|
location, size, checksum = store.add(image_meta['id'],
|
||||||
image_data,
|
image_data,
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
|
# Copyright 2012 OpenStack LLC.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
from glance import api
|
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
from glance.common import wsgi
|
from glance.common import wsgi
|
||||||
from glance import registry
|
from glance import registry
|
||||||
|
@ -24,8 +24,6 @@ import json
|
|||||||
|
|
||||||
import webob.dec
|
import webob.dec
|
||||||
|
|
||||||
from glance.common import wsgi
|
|
||||||
|
|
||||||
|
|
||||||
class Controller(object):
|
class Controller(object):
|
||||||
|
|
||||||
|
@ -30,10 +30,11 @@ Keystone (an identity management system).
|
|||||||
> auth_plugin.management_url
|
> auth_plugin.management_url
|
||||||
http://service_endpoint/
|
http://service_endpoint/
|
||||||
"""
|
"""
|
||||||
import httplib2
|
|
||||||
import json
|
import json
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
|
import httplib2
|
||||||
|
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ import collections
|
|||||||
import errno
|
import errno
|
||||||
import functools
|
import functools
|
||||||
import httplib
|
import httplib
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import select
|
import select
|
||||||
import urllib
|
import urllib
|
||||||
|
@ -26,9 +26,9 @@ import logging.handlers
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from glance import version
|
|
||||||
from glance.common import cfg
|
from glance.common import cfg
|
||||||
from glance.common import wsgi
|
from glance.common import wsgi
|
||||||
|
from glance import version
|
||||||
|
|
||||||
|
|
||||||
paste_deploy_group = cfg.OptGroup('paste_deploy')
|
paste_deploy_group = cfg.OptGroup('paste_deploy')
|
||||||
@ -169,8 +169,6 @@ def load_paste_app(conf, app_name=None):
|
|||||||
# Setup logging early
|
# Setup logging early
|
||||||
setup_logging(conf)
|
setup_logging(conf)
|
||||||
|
|
||||||
logger = logging.getLogger(app_name)
|
|
||||||
|
|
||||||
app = wsgi.paste_deploy_app(conf_file, app_name, conf)
|
app = wsgi.paste_deploy_app(conf_file, app_name, conf)
|
||||||
|
|
||||||
# Log the options used when starting if we're in debug mode...
|
# Log the options used when starting if we're in debug mode...
|
||||||
|
@ -19,7 +19,6 @@ from glance.common import cfg
|
|||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
from glance.common import utils
|
from glance.common import utils
|
||||||
from glance.common import wsgi
|
from glance.common import wsgi
|
||||||
from glance.registry.db import api as db_api
|
|
||||||
|
|
||||||
|
|
||||||
class RequestContext(object):
|
class RequestContext(object):
|
||||||
|
@ -21,8 +21,6 @@ Routines for URL-safe encrypting/decrypting
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import string
|
|
||||||
import os
|
|
||||||
|
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
from Crypto import Random
|
from Crypto import Random
|
||||||
|
@ -22,13 +22,10 @@ System-level utilities and helper functions.
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import errno
|
import errno
|
||||||
import inspect
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import random
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import socket
|
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -327,7 +324,7 @@ def get_terminal_size():
|
|||||||
if not height_width:
|
if not height_width:
|
||||||
try:
|
try:
|
||||||
p = subprocess.Popen(['stty', 'size'],
|
p = subprocess.Popen(['stty', 'size'],
|
||||||
shell=false,
|
shell=False,
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
return tuple(int(x) for x in p.communicate()[0].split())
|
return tuple(int(x) for x in p.communicate()[0].split())
|
||||||
except:
|
except:
|
||||||
|
@ -20,7 +20,6 @@ LRU Cache for Image Data
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
|
|
||||||
from glance.common import cfg
|
from glance.common import cfg
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
|
@ -22,8 +22,6 @@ Base attribute driver class
|
|||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from contextlib import contextmanager
|
|
||||||
|
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
from glance.common import utils
|
from glance.common import utils
|
||||||
|
|
||||||
|
@ -21,8 +21,6 @@ Cache driver that uses SQLite to store information about cached images
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import datetime
|
|
||||||
import itertools
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
|
@ -57,7 +57,6 @@ from __future__ import absolute_import
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import datetime
|
import datetime
|
||||||
import errno
|
import errno
|
||||||
import itertools
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import uuid
|
|
||||||
import socket
|
import socket
|
||||||
|
import uuid
|
||||||
|
|
||||||
from glance.common import cfg
|
from glance.common import cfg
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
@ -46,7 +46,7 @@ class Notifier(object):
|
|||||||
strategy = conf.notifier_strategy
|
strategy = conf.notifier_strategy
|
||||||
try:
|
try:
|
||||||
self.strategy = utils.import_class(_STRATEGIES[strategy])(conf)
|
self.strategy = utils.import_class(_STRATEGIES[strategy])(conf)
|
||||||
except KeyError, ImportError:
|
except (KeyError, ImportError):
|
||||||
raise exception.InvalidNotifierStrategy(strategy=strategy)
|
raise exception.InvalidNotifierStrategy(strategy=strategy)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
|
|
||||||
import routes
|
import routes
|
||||||
|
|
||||||
|
from glance.common import wsgi
|
||||||
from glance.registry.api.v1 import images
|
from glance.registry.api.v1 import images
|
||||||
from glance.registry.api.v1 import members
|
from glance.registry.api.v1 import members
|
||||||
from glance.common import wsgi
|
|
||||||
|
|
||||||
|
|
||||||
class API(wsgi.Router):
|
class API(wsgi.Router):
|
||||||
|
@ -21,7 +21,6 @@ the Glance Registry API
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import urllib
|
|
||||||
|
|
||||||
from glance.common.client import BaseClient
|
from glance.common.client import BaseClient
|
||||||
from glance.common import crypt
|
from glance.common import crypt
|
||||||
|
@ -26,7 +26,6 @@ import logging
|
|||||||
|
|
||||||
from sqlalchemy import asc, create_engine, desc
|
from sqlalchemy import asc, create_engine, desc
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
from sqlalchemy.orm import exc
|
from sqlalchemy.orm import exc
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
@ -22,7 +22,6 @@ Various conveniences used for migration scripts
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import sqlalchemy.types
|
import sqlalchemy.types
|
||||||
from sqlalchemy.schema import MetaData
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('glance.registry.db.migrate_repo.schema')
|
logger = logging.getLogger('glance.registry.db.migrate_repo.schema')
|
||||||
|
@ -20,17 +20,15 @@
|
|||||||
SQLAlchemy models for glance data
|
SQLAlchemy models for glance data
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from sqlalchemy.orm import relationship, backref, exc, object_mapper, validates
|
from sqlalchemy.orm import relationship, backref, object_mapper
|
||||||
from sqlalchemy import Column, Integer, String, BigInteger
|
from sqlalchemy import Column, Integer, String, BigInteger
|
||||||
from sqlalchemy import ForeignKey, DateTime, Boolean, Text
|
from sqlalchemy import ForeignKey, DateTime, Boolean, Text
|
||||||
from sqlalchemy import UniqueConstraint
|
from sqlalchemy import UniqueConstraint
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
import glance.registry.db.api
|
import glance.registry.db.api
|
||||||
from glance.common import exception
|
|
||||||
from glance.common import utils
|
from glance.common import utils
|
||||||
|
|
||||||
BASE = declarative_base()
|
BASE = declarative_base()
|
||||||
|
@ -16,16 +16,14 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import urlparse
|
|
||||||
|
|
||||||
from glance import registry
|
|
||||||
from glance.common import cfg
|
from glance.common import cfg
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
from glance.common import utils
|
from glance.common import utils
|
||||||
|
from glance import registry
|
||||||
from glance.store import location
|
from glance.store import location
|
||||||
|
|
||||||
logger = logging.getLogger('glance.store')
|
logger = logging.getLogger('glance.store')
|
||||||
|
@ -29,8 +29,6 @@ from glance import registry
|
|||||||
from glance import store
|
from glance import store
|
||||||
from glance.common import cfg
|
from glance.common import cfg
|
||||||
from glance.common import utils
|
from glance.common import utils
|
||||||
from glance.common import exception
|
|
||||||
from glance.registry import context
|
|
||||||
from glance.registry import client
|
from glance.registry import client
|
||||||
|
|
||||||
|
|
||||||
@ -121,7 +119,7 @@ class Scrubber(object):
|
|||||||
pool.starmap(self._delete, delete_work)
|
pool.starmap(self._delete, delete_work)
|
||||||
|
|
||||||
if self.cleanup:
|
if self.cleanup:
|
||||||
self._cleanup()
|
self._cleanup(pool)
|
||||||
|
|
||||||
def _delete(self, id, uri, now):
|
def _delete(self, id, uri, now):
|
||||||
file_path = os.path.join(self.datadir, str(id))
|
file_path = os.path.join(self.datadir, str(id))
|
||||||
@ -136,7 +134,7 @@ class Scrubber(object):
|
|||||||
self.registry.update_image(id, {'status': 'deleted'})
|
self.registry.update_image(id, {'status': 'deleted'})
|
||||||
utils.safe_remove(file_path)
|
utils.safe_remove(file_path)
|
||||||
|
|
||||||
def _cleanup(self):
|
def _cleanup(self, pool):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
cleanup_file = os.path.join(self.datadir, self.CLEANUP_FILE)
|
cleanup_file = os.path.join(self.datadir, self.CLEANUP_FILE)
|
||||||
if not os.path.exists(cleanup_file):
|
if not os.path.exists(cleanup_file):
|
||||||
|
@ -23,7 +23,6 @@ import hashlib
|
|||||||
import httplib
|
import httplib
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import tempfile
|
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
from glance.common import cfg
|
from glance.common import cfg
|
||||||
@ -266,13 +265,6 @@ class Store(glance.store.base.Store):
|
|||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
#if expected_size:
|
|
||||||
# obj_size = int(resp_headers['content-length'])
|
|
||||||
# if obj_size != expected_size:
|
|
||||||
# raise glance.store.BackendException(
|
|
||||||
# "Expected %s byte file, Swift has %s bytes" %
|
|
||||||
# (expected_size, obj_size))
|
|
||||||
|
|
||||||
class ResponseIndexable(glance.store.Indexable):
|
class ResponseIndexable(glance.store.Indexable):
|
||||||
def another(self):
|
def another(self):
|
||||||
try:
|
try:
|
||||||
@ -448,7 +440,7 @@ class Store(glance.store.base.Store):
|
|||||||
# of each chunk...so we ignore this result in favour of
|
# of each chunk...so we ignore this result in favour of
|
||||||
# the MD5 of the entire image file contents, so that
|
# the MD5 of the entire image file contents, so that
|
||||||
# users can verify the image file contents accordingly
|
# users can verify the image file contents accordingly
|
||||||
_ignored = swift_conn.put_object(self.container, obj_name,
|
swift_conn.put_object(self.container, obj_name,
|
||||||
None, headers=headers)
|
None, headers=headers)
|
||||||
obj_etag = checksum.hexdigest()
|
obj_etag = checksum.hexdigest()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user