import sqlite3 import convert import auth_data_const import volume_kv as kv import threadutils # All supported vmdk commands CMD_CREATE = 'create' CMD_REMOVE = 'remove' CMD_ATTACH = 'attach' CMD_DETACH = 'detach' SIZE = 'size' # thread local storage in this module namespace thread_local = threadutils.get_local_storage() def get_auth_mgr(): """ Get a connection to auth DB. """ global thread_local if not hasattr(thread_local, '_auth_mgr'): thread_local._auth_mgr = auth_data.AuthorizationDataManager() thread_local._auth_mgr.connect() return thread_local._auth_mgr def get_tenant(vm_uuid): """ Get tenant which owns this VM by querying the auth DB. """ _auth_mgr = get_auth_mgr() try: cur = _auth_mgr.conn.execute( "SELECT tenant_id FROM vms WHERE vm_id = ?",
import error_code import vmdk_utils from error_code import ErrorCode from error_code import error_code_to_message # All supported vmdk commands that need authorization checking CMD_CREATE = 'create' CMD_REMOVE = 'remove' CMD_ATTACH = 'attach' CMD_DETACH = 'detach' CMD_GET = 'get' SIZE = 'size' # thread local storage in this module namespace thread_local = threadutils.get_local_storage() def get_auth_mgr(): """ Get a connection to auth DB. """ global thread_local if not hasattr(thread_local, '_auth_mgr'): try: thread_local._auth_mgr = auth_data.AuthorizationDataManager() thread_local._auth_mgr.connect() except (auth_data.DbConnectionError, auth_data.DbAccessError, auth_data.DbUpgradeError) as err: return str(err), None return None, thread_local._auth_mgr def get_default_tenant(): """ Get DEFAULT tenant by querying the auth DB or from hardcoded defaults.