def __init__(self, context, is_unit_test=False):

        super(HeatFlameTemplate, self).__init__(context)
        self.dr_image_snapshot_ids = []
        self.dr_protected_server_names = []
        self.dr_volumes = []     # each has : volume name only !
        self.dr_replicated_volumes = []
        self.dr_networks = []
        self.credentials = {}
        self.dr_keynames = []
        self.context = context
        self.clients = Clients(context)
        LOG.debug("heat_flame_template  . initializing ")

        if is_unit_test is True:
            password = '******'
        else:
            importutils.import_module('keystoneclient.middleware.auth_token')
            password = cfg.CONF.keystone_authtoken.admin_password

        self.credentials = {'user': self.context.username,
                            'password': password,
                            'project': self.context.tenant,
                            'auth_url': self.context.auth_url,
                            'auth_token': self.context.auth_token}

        LOG.debug("heat_flame_template  credentials: user: %s, password : %s,"
                  "project: %s, auth_url %s , auth_token %s" %
                  (self.credentials['user'], self.credentials['password'],
                   self.credentials['project'], self.credentials['auth_url'],
                   self.credentials['auth_token']))
 def __init__(self, app, conf):
     self.app = app
     self.conf = conf
     auth_url = None
     if not cfg.CONF.auth_password.multi_cloud:
         if "auth_uri" in self.conf:
             auth_url = self.conf["auth_uri"]
         else:
             # Import auth_token to have keystone_authtoken settings setup.
             importutils.import_module("keystoneclient.middleware.auth_token")
             auth_url = cfg.CONF.keystone_authtoken["auth_uri"]
     self.auth_url = auth_url
 def __init__(self, backend_mapping=None):
     if backend_mapping is None:
         backend_mapping = {}
     backend_name = CONF.database.backend
     # Import the untranslated name if we don't have a
     # mapping.
     backend_path = backend_mapping.get(backend_name, backend_name)
     backend_mod = importutils.import_module(backend_path)
     self.__backend = backend_mod.get_backend()
    def _service_admin_creds(api_version=2):
        # Import auth_token to have keystone_authtoken settings setup.
        importutils.import_module('keystoneclient.middleware.auth_token')

        creds = {
            'username': cfg.CONF.keystone_authtoken.admin_user,
            'password': cfg.CONF.keystone_authtoken.admin_password,
        }
        if api_version >= 3:
            creds['auth_url'] =\
                cfg.CONF.keystone_authtoken.auth_uri.replace('v2.0', 'v3')
            creds['project_name'] =\
                cfg.CONF.keystone_authtoken.admin_tenant_name
        else:
            creds['auth_url'] = cfg.CONF.keystone_authtoken.auth_uri
            creds['tenant_name'] =\
                cfg.CONF.keystone_authtoken.admin_tenant_name

        return creds
def _get_drivers():
    """Instantiates and returns drivers based on the flag values."""
    global drivers
    if drivers is None:
        drivers = []
        for notification_driver in CONF.list_notifier_drivers:
            try:
                drivers.append(importutils.import_module(notification_driver))
            except ImportError as e:
                drivers.append(ImportFailureNotifier(e))
    return drivers
def _import_module(mod_str):
    try:
        if mod_str.startswith('bin.'):
            imp.load_source(mod_str[4:], os.path.join('bin', mod_str[4:]))
            return sys.modules[mod_str[4:]]
        else:
            return importutils.import_module(mod_str)
    except ImportError as ie:
        sys.stderr.write("%s\n" % str(ie))
        return None
    except Exception:
        return None
def add_driver(notification_driver):
    """Add a notification driver at runtime."""
    # Make sure the driver list is initialized.
    _get_drivers()
    if isinstance(notification_driver, basestring):
        # Load and add
        try:
            drivers.append(importutils.import_module(notification_driver))
        except ImportError as e:
            drivers.append(ImportFailureNotifier(e))
    else:
        # Driver is already loaded; just add the object.
        drivers.append(notification_driver)
        if ceilometerclient is None:
            return None
        if self._ceilometer:
            return self._ceilometer

        if self.auth_token is None:
            logger.error("Ceilometer connection failed, no auth_token!")
            return None
        con = self.context
        args = {
            'auth_url': con.auth_url,
            'service_type': 'metering',
            'project_id': con.tenant,
            'token': lambda: self.auth_token,
            'endpoint': self.url_for(service_type='metering'),
        }

        client = ceilometerclient.Client(**args)

        self._ceilometer = client
        return self._ceilometer


if cfg.CONF.cloud_backend:
    cloud_backend_module = importutils.import_module(cfg.CONF.cloud_backend)
    Clients = cloud_backend_module.Clients
else:
    Clients = OpenStackClients

logger.debug('Using backend %s' % Clients)