Merge salt.cloud.loader into salt.loader.

This commit is contained in:
Pedro Algarvio 2013-11-19 21:17:35 +00:00
parent b4a33bd29b
commit 15f50502b8
3 changed files with 46 additions and 79 deletions

View File

@ -17,7 +17,6 @@ from itertools import groupby
# Import salt.cloud libs
import salt.cloud.config
import salt.cloud.utils
import salt.cloud.loader
import salt.utils.event
from salt.cloud.exceptions import (
SaltCloudNotFound,
@ -28,6 +27,7 @@ from salt.cloud.exceptions import (
# Import salt libs
import salt.client
import salt.loader
import salt.utils
# Import third party libs
@ -185,7 +185,7 @@ class Cloud(object):
'''
def __init__(self, opts):
self.opts = opts
self.clouds = salt.cloud.loader.clouds(self.opts)
self.clouds = salt.loader.clouds(self.opts)
self.__filter_non_working_providers()
self.__cached_provider_queries = {}

View File

@ -1,77 +0,0 @@
# -*- coding: utf-8 -*-
'''
The salt cloud module loader interface
'''
# Import python libs
import os
import logging
# Import Salt libs
import salt.loader
import salt.cloud
log = logging.getLogger(__name__)
# Because on the cloud drivers we do `from salt.cloud.libcloudfuncs import *`
# which simplifies code readability, it adds some unsupported functions into
# the driver's module scope.
# We list un-supported functions here. These will be removed from the loaded.
LIBCLOUD_FUNCS_NOT_SUPPORTED = (
'parallels.avail_sizes',
'parallels.avail_locations',
'saltify.destroy',
'saltify.avail_sizes',
'saltify.avail_images',
'saltify.avail_locations',
'rackspace.reboot'
)
def clouds(opts):
'''
Return the cloud functions
'''
salt_base_path = os.path.dirname(salt.cloud.__file__)
def saltcloud_mod_type_check(modpath):
if modpath.startswith(salt_base_path):
return 'int'
return 'ext'
try:
load = salt.loader._create_loader(
opts,
'clouds',
'cloud',
base_path=salt_base_path,
loaded_base_name='salt.cloud.loaded',
mod_type_check=saltcloud_mod_type_check
)
except TypeError:
# Salt is not recent enough
load = salt.loader._create_loader(
opts,
'clouds',
'cloud',
base_path=salt_base_path,
)
# Let's bring __active_provider_name__, defaulting to None, to all cloud
# drivers. This will get temporarily updated/overridden with a context
# manager when needed.
pack = {
'name': '__active_provider_name__',
'value': None
}
functions = load.gen_functions(pack)
for funcname in LIBCLOUD_FUNCS_NOT_SUPPORTED:
log.debug(
'{0!r} has been marked as not supported. Removing from the list '
'of supported cloud functions'.format(
funcname
)
)
functions.pop(funcname, None)
return functions

View File

@ -21,6 +21,20 @@ log = logging.getLogger(__name__)
SALT_BASE_PATH = os.path.dirname(salt.__file__)
LOADED_BASE_NAME = 'salt.loaded'
# Because on the cloud drivers we do `from salt.cloud.libcloudfuncs import *`
# which simplifies code readability, it adds some unsupported functions into
# the driver's module scope.
# We list un-supported functions here. These will be removed from the loaded.
LIBCLOUD_FUNCS_NOT_SUPPORTED = (
'parallels.avail_sizes',
'parallels.avail_locations',
'saltify.destroy',
'saltify.avail_sizes',
'saltify.avail_images',
'saltify.avail_locations',
'rackspace.reboot'
)
def _create_loader(
opts,
@ -316,6 +330,36 @@ def runner(opts):
return load.gen_functions()
def clouds(opts):
'''
Return the cloud functions
'''
load = _create_loader(opts,
'clouds',
'cloud',
base_path=os.path.join(SALT_BASE_PATH, 'cloud'),
int_type='clouds')
# Let's bring __active_provider_name__, defaulting to None, to all cloud
# drivers. This will get temporarily updated/overridden with a context
# manager when needed.
pack = {
'name': '__active_provider_name__',
'value': None
}
functions = load.gen_functions(pack)
for funcname in LIBCLOUD_FUNCS_NOT_SUPPORTED:
log.debug(
'{0!r} has been marked as not supported. Removing from the list '
'of supported cloud functions'.format(
funcname
)
)
functions.pop(funcname, None)
return functions
def _generate_module(name):
if name in sys.modules:
return