Пример #1
0
def LoadProvider(provider_name, ignore_package_requirements=True):
    """Loads the all modules in the 'provider_name' package.

  This function first checks the specified provider's Python package
  requirements file, if one exists, and verifies that all requirements are met.
  Next, it loads all modules in the specified provider's package. By loading
  these modules, relevant classes (e.g. VMs) will register themselves.

  Args:
    provider_name: The name of the package whose modules should be loaded.
        Usually the name of the provider in lower case (e.g. the package name
        for the 'GCP' provider is 'gcp'.
    ignore_package_requirements: boolean. If True, the provider's Python package
        requirements file is ignored.
  """
    if not ignore_package_requirements:
        requirements.CheckProviderRequirements(provider_name)
    provider_package_path = os.path.join(__path__[0], provider_name)
    try:
        # Iterating through this generator will load all modules in the provider
        # directory. Simply loading those modules will cause relevant classes
        # to register themselves so that we can run with that provider.
        modules = [
            module for module in import_util.LoadModulesForPath(
                [provider_package_path], __name__ + '.' + provider_name)
        ]
        if not modules:
            raise ImportError('No modules found for provider.')
    except:
        logging.error('Unable to load provider %s.', provider_name)
        raise
Пример #2
0
def _LoadPackages():
    packages = dict([
        (module.__name__.split('.')[-1], module)
        for module in import_util.LoadModulesForPath(__path__, __name__)
    ])
    packages.update(packages['docker'].CreateImagePackages())
    return packages
Пример #3
0
def LoadProvider(provider_name):
    """Loads the all modules in the 'provider_name' package.

  This function loads all modules in the provided package. By loading these
  modules, relevant classes (e.g. VMs) will register themselves. This should
  be called with the exact name of the package, which is usually the name of
  the provider in lower case (e.g. the package name for the 'GCP' provider
  is 'gcp').

  Args:
    provider_name: The name of the package whose modules should be loaded.
  """
    provider_package_path = os.path.join(__path__[0], provider_name)
    try:
        # Iterating through this generator will load all modules in the provider
        # directory. Simply loading those modules will cause relevant classes
        # to register themselves so that we can run with that provider.
        modules = [
            module for module in import_util.LoadModulesForPath(
                [provider_package_path], __name__ + '.' + provider_name)
        ]
        if not modules:
            raise ImportError('No modules found for provider.')
    except:
        logging.error('Unable to load provider %s.', provider_name)
        raise
Пример #4
0
def _LoadPackages():
    """Imports all package modules and returns a dictionary of packages.

    This imports all package modules in this directory and then creates a
    mapping from module names to the modules themselves and returns it.
    """
    return {
        module.__name__.split('.')[-1]: module
        for module in import_util.LoadModulesForPath(__path__, __name__)
    }
Пример #5
0
def LoadProvider(provider_name, ignore_package_requirements=True):
    """Loads the all modules in the 'provider_name' package.

  This function first checks the specified provider's Python package
  requirements file, if one exists, and verifies that all requirements are met.
  Next, it loads all modules in the specified provider's package. By loading
  these modules, relevant classes (e.g. VMs) will register themselves.

  Args:
    provider_name: string chosen from VALID_CLOUDS. The name of the provider
        whose modules should be loaded.
    ignore_package_requirements: boolean. If True, the provider's Python package
        requirements file is ignored.
  """
    if provider_name in _imported_providers:
        return

    # Check package requirements from the provider's pip requirements file.
    normalized_name = provider_name.lower()
    if not ignore_package_requirements:
        requirements.CheckProviderRequirements(normalized_name)

    # Load all modules in the provider's directory. Simply loading those modules
    # will cause relevant classes (e.g. VM and disk classes) to register
    # themselves so that they can be instantiated during resource provisioning.
    provider_package_path = os.path.join(__path__[0], normalized_name)
    try:
        modules = tuple(
            import_util.LoadModulesForPath([provider_package_path],
                                           __name__ + '.' + normalized_name))
        if not modules:
            raise ImportError('No modules found for provider %s.' %
                              provider_name)
    except Exception:
        logging.error('Unable to load provider %s.', provider_name)
        raise

    # Signal that the provider's modules have been imported.
    _imported_providers.add(provider_name)
    events.provider_imported.send(provider_name)
Пример #6
0
#
# 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.
"""Systems for tracking performance counters during a run.

Individual trackers should define a function, 'Register', which will be
called with a single argument, the parsed FLAGS instance, once the Benchmarker
is initialized.
"""

from perfkitbenchmarker import events
from perfkitbenchmarker import import_util

TRACE_COLLECTORS = list(import_util.LoadModulesForPath(__path__, __name__))


def RegisterAll(sender, parsed_flags):
    for module in TRACE_COLLECTORS:
        module.Register(parsed_flags)

    events.RegisterTracingEvents()
Пример #7
0
def _LoadBenchmarks():
    return list(import_util.LoadModulesForPath(__path__, __name__))
def _LoadPackages():
  return dict([(module.__name__.split('.')[-1], module) for module in
               import_util.LoadModulesForPath(__path__, __name__)])