コード例 #1
0
    def configure_add(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """
        self.datadir = CONF.filesystem_store_datadir
        if self.datadir is None:
            reason = (_("Could not find %s in configuration options.") %
                      'filesystem_store_datadir')
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name="filesystem",
                                                  reason=reason)

        if not os.path.exists(self.datadir):
            msg = _("Directory to write image files does not exist "
                    "(%s). Creating.") % self.datadir
            LOG.info(msg)
            try:
                os.makedirs(self.datadir)
            except (IOError, OSError):
                if os.path.exists(self.datadir):
                    # NOTE(markwash): If the path now exists, some other
                    # process must have beat us in the race condition. But it
                    # doesn't hurt, so we can safely ignore the error.
                    return
                reason = _("Unable to create datadir: %s") % self.datadir
                LOG.error(reason)
                raise exception.BadStoreConfiguration(store_name="filesystem",
                                                      reason=reason)
コード例 #2
0
ファイル: sheepdog.py プロジェクト: jacobwagner/glance
    def configure_add(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """

        try:
            self.chunk_size = CONF.sheepdog_store_chunk_size * units.Mi
            self.addr = CONF.sheepdog_store_address.strip()
            self.port = CONF.sheepdog_store_port
        except cfg.ConfigFileValueError as e:
            reason = _("Error in store configuration: %s") % e
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name='sheepdog',
                                                  reason=reason)

        if ' ' in self.addr:
            reason = (_("Invalid address configuration of sheepdog store: %s")
                      % self.addr)
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name='sheepdog',
                                                  reason=reason)

        try:
            cmd = ["collie", "vdi", "list", "-a", self.addr, "-p", self.port]
            processutils.execute(*cmd)
        except Exception as e:
            reason = _("Error in store configuration: %s") % e
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name='sheepdog',
                                                  reason=reason)
コード例 #3
0
    def _get_datadir_path_and_priority(self, datadir):
        """
        Gets directory paths and its priority from
        filesystem_store_datadirs option in glance-api.conf.

        :datadir is directory path with its priority.
        :returns datadir_path as directory path
                 priority as priority associated with datadir_path
        :raise BadStoreConfiguration exception if priority is invalid or
               empty directory path is specified.
        """
        priority = 0
        parts = map(lambda x: x.strip(), datadir.rsplit(":", 1))
        datadir_path = parts[0]
        if len(parts) == 2 and parts[1]:
            priority = parts[1]
            if not priority.isdigit():
                msg = (_("Invalid priority value %(priority)s in "
                         "filesystem configuration") % {
                             'priority': priority
                         })
                LOG.exception(msg)
                raise exception.BadStoreConfiguration(store_name="filesystem",
                                                      reason=msg)

        if not datadir_path:
            msg = _("Invalid directory specified in filesystem configuration")
            LOG.exception(msg)
            raise exception.BadStoreConfiguration(store_name="filesystem",
                                                  reason=msg)

        return datadir_path, priority
コード例 #4
0
    def configure_add(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """

        try:
            self.chunk_size = CONF.sheepdog_store_chunk_size * units.Mi
            self.addr = CONF.sheepdog_store_address
            self.port = CONF.sheepdog_store_port
        except cfg.ConfigFileValueError as e:
            reason = _("Error in store configuration: %s") % e
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name='sheepdog',
                                                  reason=reason)

        try:
            processutils.execute("collie", shell=True)
        except processutils.ProcessExecutionError as exc:
            reason = _("Error in store configuration: %s") % exc
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name='sheepdog',
                                                  reason=reason)
コード例 #5
0
    def configure_add(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """
        self.datadir = CONF.filesystem_store_datadir
        if self.datadir is None:
            reason = (_("Could not find %s in configuration options.") %
                      'filesystem_store_datadir')
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name="filesystem",
                                                  reason=reason)

        if not os.path.exists(self.datadir):
            msg = _("Directory to write image files does not exist "
                    "(%s). Creating.") % self.datadir
            LOG.info(msg)
            try:
                os.makedirs(self.datadir)
            except IOError:
                reason = _("Unable to create datadir: %s") % self.datadir
                LOG.error(reason)
                raise exception.BadStoreConfiguration(store_name="filesystem",
                                                      reason=reason)
コード例 #6
0
 def _sanity_check(self):
     if CONF.vmware_api_retry_count <= 0:
         msg = _("vmware_api_retry_count should be greater than zero")
         LOG.error(msg)
         raise exception.BadStoreConfiguration(
             store_name='vmware_datastore', reason=msg)
     if CONF.vmware_task_poll_interval <= 0:
         msg = _("vmware_task_poll_interval should be greater than zero")
         LOG.error(msg)
         raise exception.BadStoreConfiguration(
             store_name='vmware_datastore', reason=msg)
コード例 #7
0
    def _create_image_directories(self, directory_paths):
        """
        Create directories to write image files if
        it does not exist.

        :directory_paths is a list of directories belonging to glance store.
        :raise BadStoreConfiguration exception if creating a directory fails.
        """
        for datadir in directory_paths:
            if os.path.exists(datadir):
                self._check_write_permission(datadir)
            else:
                msg = _("Directory to write image files does not exist "
                        "(%s). Creating.") % datadir
                LOG.info(msg)
                try:
                    os.makedirs(datadir)
                    self._check_write_permission(datadir)
                except (IOError, OSError):
                    if os.path.exists(datadir):
                        # NOTE(markwash): If the path now exists, some other
                        # process must have beat us in the race condition.
                        # But it doesn't hurt, so we can safely ignore
                        # the error.
                        self._check_write_permission(datadir)
                        continue
                    reason = _("Unable to create datadir: %s") % datadir
                    LOG.error(reason)
                    raise exception.BadStoreConfiguration(
                        store_name="filesystem", reason=reason)
コード例 #8
0
ファイル: swift.py プロジェクト: young8/openstack-bill
    def configure(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """
        self.auth_address = self._option_get('swift_store_auth_address')
        self.user = self._option_get('swift_store_user')
        self.key = self._option_get('swift_store_key')
        self.container = self.options.get('swift_store_container',
                                          DEFAULT_CONTAINER)
        try:
            if self.options.get('swift_store_large_object_size'):
                self.large_object_size = int(
                    self.options.get('swift_store_large_object_size')
                    ) * (1024 * 1024)  # Size specified in MB in conf files
            else:
                self.large_object_size = DEFAULT_LARGE_OBJECT_SIZE

            if self.options.get('swift_store_large_object_chunk_size'):
                self.large_object_chunk_size = int(
                    self.options.get('swift_store_large_object_chunk_size')
                    ) * (1024 * 1024)  # Size specified in MB in conf files
            else:
                self.large_object_chunk_size = DEFAULT_LARGE_OBJECT_CHUNK_SIZE
        except Exception, e:
            reason = _("Error in configuration options: %s") % e
            logger.error(reason)
            raise exception.BadStoreConfiguration(store_name="swift",
                                                  reason=reason)
コード例 #9
0
ファイル: rbd.py プロジェクト: nicoleLiu/glance
 def configure_add(self):
     """
     Configure the Store to use the stored configuration options
     Any store that needs special configuration should implement
     this method. If the store was not able to successfully configure
     itself, it should raise `exception.BadStoreConfiguration`
     """
     try:
         self.chunk_size = int(
             self.options.get(
                 'rbd_store_chunk_size',
                 DEFAULT_CHUNKSIZE)) * 1024 * 1024
         # these must not be unicode since they will be passed to a
         # non-unicode-aware C library
         self.pool = str(self.options.get('rbd_store_pool',
                                          DEFAULT_POOL))
         self.user = str(self.options.get('rbd_store_user',
                                          DEFAULT_USER))
         self.conf_file = str(self.options.get('rbd_store_ceph_conf',
                                               DEFAULT_CONFFILE))
     except Exception, e:
         reason = _("Error in store configuration: %s") % e
         logger.error(reason)
         raise exception.BadStoreConfiguration(store_name='rbd',
                                               reason=reason)
コード例 #10
0
    def configure_add(self):
        self.datacenter_path = CONF.vmware_datacenter_path
        self.datastore_name = self._option_get('vmware_datastore_name')
        global _datastore_info_valid
        if not _datastore_info_valid:
            search_index_moref = self._service_content.searchIndex

            inventory_path = ('%s/datastore/%s' %
                              (self.datacenter_path, self.datastore_name))
            ds_moref = self._session.invoke_api(self._session.vim,
                                                'FindByInventoryPath',
                                                search_index_moref,
                                                inventoryPath=inventory_path)
            if ds_moref is None:
                msg = (_("Could not find datastore %(ds_name)s "
                         "in datacenter %(dc_path)s") % {
                             'ds_name': self.datastore_name,
                             'dc_path': self.datacenter_path
                         })
                LOG.error(msg)
                raise exception.BadStoreConfiguration(
                    store_name='vmware_datastore', reason=msg)
            else:
                _datastore_info_valid = True
        self.store_image_dir = CONF.vmware_store_image_dir
コード例 #11
0
ファイル: cinder.py プロジェクト: yuyonglucky/glance
    def configure_add(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """

        if self.context is None:
            reason = _("Cinder storage requires a context.")
            raise exception.BadStoreConfiguration(store_name="cinder",
                                                  reason=reason)
        if self.context.service_catalog is None:
            reason = _("Cinder storage requires a service catalog.")
            raise exception.BadStoreConfiguration(store_name="cinder",
                                                  reason=reason)
コード例 #12
0
ファイル: vmware_datastore.py プロジェクト: zaina/glance
 def _option_get(self, param):
     result = getattr(CONF, param)
     if not result:
         reason = (_("Could not find %(param)s in configuration "
                     "options.") % {'param': param})
         raise exception.BadStoreConfiguration(
             store_name='vmware_datastore', reason=reason)
     return result
コード例 #13
0
 def _option_get(self, param):
     result = self.options.get(param)
     if not result:
         reason = _("Could not find %s in configuration options.") % param
         logger.error(reason)
         raise exception.BadStoreConfiguration(store_name="filesystem",
                                               reason=reason)
     return result
コード例 #14
0
ファイル: gridfs.py プロジェクト: jacobwagner/glance
 def _option_get(self, param):
     result = getattr(CONF, param)
     if not result:
         reason = (_("Could not find %(param)s in configuration "
                     "options.") % {'param': param})
         LOG.debug(reason)
         raise exception.BadStoreConfiguration(store_name="gridfs",
                                               reason=reason)
     return result
コード例 #15
0
 def configure_add(self):
     self.container = CONF.swift_store_container
     if self.context is None:
         reason = _("Multi-tenant Swift storage requires a context.")
         raise exception.BadStoreConfiguration(store_name="swift",
                                               reason=reason)
     if self.context.service_catalog is None:
         reason = _("Multi-tenant Swift storage requires "
                    "a service catalog.")
         raise exception.BadStoreConfiguration(store_name="swift",
                                               reason=reason)
     self.storage_url = auth.get_endpoint(
             self.context.service_catalog, service_type=self.service_type,
             endpoint_region=self.region, endpoint_type=self.endpoint_type)
     if self.storage_url.startswith('http://'):
         self.scheme = 'swift+http'
     else:
         self.scheme = 'swift+https'
コード例 #16
0
ファイル: swift.py プロジェクト: stateman/glance
 def _option_get(self, param):
     result = getattr(CONF, param)
     if not result:
         reason = (_("Could not find %(param)s in configuration "
                     "options.") % locals())
         LOG.error(reason)
         raise exception.BadStoreConfiguration(store_name="swift",
                                               reason=reason)
     return result
コード例 #17
0
ファイル: s3.py プロジェクト: young8/openstack-bill
 def _option_get(self, param):
     result = self.options.get(param)
     if not result:
         reason = _("Could not find %(param)s in configuration "
                    "options.") % locals()
         logger.error(reason)
         raise exception.BadStoreConfiguration(store_name="s3",
                                               reason=reason)
     return result
コード例 #18
0
    def configure_add(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """
        if not (CONF.filesystem_store_datadir
                or CONF.filesystem_store_datadirs):
            reason = (_("Specify at least 'filesystem_store_datadir' or "
                        "'filesystem_store_datadirs' option"))
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name="filesystem",
                                                  reason=reason)

        if CONF.filesystem_store_datadir and CONF.filesystem_store_datadirs:
            reason = (_("Specify either 'filesystem_store_datadir' or "
                        "'filesystem_store_datadirs' option"))
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name="filesystem",
                                                  reason=reason)

        self.multiple_datadirs = False
        directory_paths = set()
        if CONF.filesystem_store_datadir:
            self.datadir = CONF.filesystem_store_datadir
            directory_paths.add(self.datadir)
        else:
            self.multiple_datadirs = True
            self.priority_data_map = {}
            for datadir in CONF.filesystem_store_datadirs:
                (datadir_path,
                 priority) = self._get_datadir_path_and_priority(datadir)
                self._check_directory_paths(datadir_path, directory_paths)
                directory_paths.add(datadir_path)
                self.priority_data_map.setdefault(int(priority),
                                                  []).append(datadir_path)

            self.priority_list = sorted(self.priority_data_map,
                                        reverse=True)

        self._create_image_directories(directory_paths)
コード例 #19
0
    def _check_write_permission(self, datadir):
        """
        Checks if directory created to write image files has
        write permission.

        :datadir is a directory path in which glance wites image files.
        :raise BadStoreConfiguration exception if datadir is read-only.
        """
        if not os.access(datadir, os.W_OK):
            msg = (_("Permission to write in %s denied") % datadir)
            LOG.exception(msg)
            raise exception.BadStoreConfiguration(store_name="filesystem",
                                                  reason=msg)
コード例 #20
0
ファイル: swift.py プロジェクト: stateman/glance
    def configure_add(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """
        self.auth_address = self._option_get('swift_store_auth_address')
        self.user = self._option_get('swift_store_user')
        self.key = self._option_get('swift_store_key')
        self.container = CONF.swift_store_container

        if self.multi_tenant:
            if self.context is None:
                reason = _("Multi-tenant Swift storage requires a context.")
                raise exception.BadStoreConfiguration(store_name="swift",
                                                      reason=reason)
            self.token = self.context.auth_tok
            self.key = None  # multi-tenant uses tokens, not (passwords)
            if self.context.tenant and self.context.user:
                self.user = self.context.tenant + ':' + self.context.user
            if self.context.service_catalog:
                service_catalog = self.context.service_catalog
                self.storage_url = self._get_swift_endpoint(service_catalog)

        try:
            # The config file has swift_store_large_object_*size in MB, but
            # internally we store it in bytes, since the image_size parameter
            # passed to add() is also in bytes.
            _obj_size = CONF.swift_store_large_object_size
            self.large_object_size = _obj_size * ONE_MB
            _obj_chunk_size = CONF.swift_store_large_object_chunk_size
            self.large_object_chunk_size = _obj_chunk_size * ONE_MB
        except cfg.ConfigFileValueError, e:
            reason = _("Error in configuration conf: %s") % e
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name="swift",
                                                  reason=reason)
コード例 #21
0
    def configure_add(self):
        default_swift_reference = \
            SWIFT_STORE_REF_PARAMS.get(
                CONF.default_swift_reference)
        if default_swift_reference:
            self.auth_address = default_swift_reference.get('auth_address')
        if (not default_swift_reference) or (not self.auth_address):
            reason = _("A value for swift_store_auth_address is required.")
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name="swift",
                                                  reason=reason)
        if self.auth_address.startswith('http://'):
            self.scheme = 'swift+http'
        else:
            self.scheme = 'swift+https'
        self.container = CONF.swift_store_container
        self.user = default_swift_reference.get('user')
        self.key = default_swift_reference.get('key')

        if not (self.user or self.key):
            reason = _("A value for swift_store_ref_params is required.")
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name="swift",
                                                  reason=reason)
コード例 #22
0
    def _check_directory_paths(self, datadir_path, directory_paths):
        """
        Checks if directory_path is already present in directory_paths.

        :datadir_path is directory path.
        :datadir_paths is set of all directory paths.
        :raise BadStoreConfiguration exception if same directory path is
               already present in directory_paths.
        """
        if datadir_path in directory_paths:
            msg = (_("Directory %(datadir_path)s specified "
                     "multiple times in filesystem_store_datadirs "
                     "option of filesystem configuration") %
                   {'datadir_path': datadir_path})
            LOG.exception(msg)
            raise exception.BadStoreConfiguration(
                store_name="filesystem", reason=msg)
コード例 #23
0
ファイル: gridfs.py プロジェクト: pipul/glance
    def configure_add(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """
        if pymongo is None:
            msg = _("Missing dependecies: pymongo")
            raise exception.BadStoreConfiguration(store_name="gridfs",
                                                  reason=msg)

        self.mongodb_uri = self._option_get('mongodb_store_uri')

        parsed = uri_parser.parse_uri(self.mongodb_uri)
        self.mongodb_db = self._option_get('mongodb_store_db') or \
            parsed.get("database")

        self.mongodb = pymongo.MongoClient(self.mongodb_uri)
        self.fs = gridfs.GridFS(self.mongodb[self.mongodb_db])
コード例 #24
0
ファイル: rbd.py プロジェクト: pipul/glance
    def configure_add(self):
        """
        Configure the Store to use the stored configuration options
        Any store that needs special configuration should implement
        this method. If the store was not able to successfully configure
        itself, it should raise `exception.BadStoreConfiguration`
        """
        try:
            self.chunk_size = CONF.rbd_store_chunk_size * 1024 * 1024

            # these must not be unicode since they will be passed to a
            # non-unicode-aware C library
            self.pool = str(CONF.rbd_store_pool)
            self.user = str(CONF.rbd_store_user)
            self.conf_file = str(CONF.rbd_store_ceph_conf)
        except cfg.ConfigFileValueError as e:
            reason = _("Error in store configuration: %s") % e
            LOG.error(reason)
            raise exception.BadStoreConfiguration(store_name='rbd',
                                                  reason=reason)
コード例 #25
0
 def configure_add(self):
     """
     Configure the Store to use the stored configuration options
     Any store that needs special configuration should implement
     this method. If the store was not able to successfully configure
     itself, it should raise `exception.BadStoreConfiguration`
     """
     self.auth_address = self._option_get('swift_store_auth_address')
     self.user = self._option_get('swift_store_user')
     self.key = self._option_get('swift_store_key')
     self.container = self.conf.swift_store_container
     try:
         self.large_object_size = self.conf.swift_store_large_object_size
         self.large_object_chunk_size = \
             self.conf.swift_store_large_object_chunk_size
         self.swift_store_object_buffer_dir = \
             self.conf.swift_store_object_buffer_dir
     except cfg.ConfigFileValueError, e:
         reason = _("Error in configuration conf: %s") % e
         logger.error(reason)
         raise exception.BadStoreConfiguration(store_name="swift",
                                               reason=reason)
コード例 #26
0
 def configure_add(self):
     """
     Configure the Store to use the stored configuration options
     Any store that needs special configuration should implement
     this method. If the store was not able to successfully configure
     itself, it should raise `exception.BadStoreConfiguration`
     """
     self.auth_address = self._option_get('swift_store_auth_address')
     self.user = self._option_get('swift_store_user')
     self.key = self._option_get('swift_store_key')
     self.container = self.conf.swift_store_container
     try:
         # The config file has swift_store_large_object_*size in MB, but
         # internally we store it in bytes, since the image_size parameter
         # passed to add() is also in bytes.
         _obj_size = self.conf.swift_store_large_object_size
         self.large_object_size = _obj_size * ONE_MB
         _obj_chunk_size = self.conf.swift_store_large_object_chunk_size
         self.large_object_chunk_size = _obj_chunk_size * ONE_MB
     except cfg.ConfigFileValueError, e:
         reason = _("Error in configuration conf: %s") % e
         logger.error(reason)
         raise exception.BadStoreConfiguration(store_name="swift",
                                               reason=reason)
コード例 #27
0
ファイル: base.py プロジェクト: ynshenoy/glance
 def _fun(*args, **kwargs):
     if passing_config:
         return None
     else:
         raise exception.BadStoreConfiguration()
コード例 #28
0
 def configure(self):
     raise exception.BadStoreConfiguration("Unconfigurable store driver.")