当前位置: 首页>>代码示例>>Python>>正文


Python opts.get_cell_type函数代码示例

本文整理汇总了Python中nova.cells.opts.get_cell_type函数的典型用法代码示例。如果您正苦于以下问题:Python get_cell_type函数的具体用法?Python get_cell_type怎么用?Python get_cell_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_cell_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _save_helper

    def _save_helper(self, cell_type, update_cells):
        obj = instance_info_cache.InstanceInfoCache()
        cells_api = cells_rpcapi.CellsAPI()

        self.mox.StubOutWithMock(db, 'instance_info_cache_update')
        self.mox.StubOutWithMock(cells_opts, 'get_cell_type')
        self.mox.StubOutWithMock(cells_rpcapi, 'CellsAPI',
                                 use_mock_anything=True)
        self.mox.StubOutWithMock(cells_api,
                                 'instance_info_cache_update_at_top')
        nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
        new_info_cache = fake_info_cache.copy()
        new_info_cache['network_info'] = nwinfo.json()
        db.instance_info_cache_update(
                self.context, 'fake-uuid',
                {'network_info': nwinfo.json()}).AndReturn(new_info_cache)
        if update_cells:
            cells_opts.get_cell_type().AndReturn(cell_type)
            if cell_type == 'compute':
                cells_rpcapi.CellsAPI().AndReturn(cells_api)
                cells_api.instance_info_cache_update_at_top(
                    self.context, 'foo')
        self.mox.ReplayAll()
        obj._context = self.context
        obj.instance_uuid = 'fake-uuid'
        obj.network_info = nwinfo
        obj.save(update_cells=update_cells)
开发者ID:Milstein,项目名称:nova,代码行数:27,代码来源:test_instance_info_cache.py

示例2: destroy

    def destroy(self):
        if not self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='destroy',
                                              reason='already destroyed')
        if not self.obj_attr_is_set('uuid'):
            raise exception.ObjectActionError(action='destroy',
                                              reason='no uuid')
        if not self.obj_attr_is_set('host') or not self.host:
            # NOTE(danms): If our host is not set, avoid a race
            constraint = db.constraint(host=db.equal_any(None))
        else:
            constraint = None

        cell_type = cells_opts.get_cell_type()
        if cell_type is not None:
            stale_instance = self.obj_clone()

        try:
            db_inst = db.instance_destroy(self._context, self.uuid,
                                          constraint=constraint)
            self._from_db_object(self._context, self, db_inst)
        except exception.ConstraintNotMet:
            raise exception.ObjectActionError(action='destroy',
                                              reason='host changed')
        if cell_type == 'compute':
            cells_api = cells_rpcapi.CellsAPI()
            cells_api.instance_destroy_at_top(self._context, stale_instance)
        delattr(self, base.get_attrname('id'))
开发者ID:amatuerone,项目名称:nova,代码行数:28,代码来源:instance.py

示例3: _info_cache_cells_update

 def _info_cache_cells_update(ctxt, info_cache):
     cell_type = cells_opts.get_cell_type()
     if cell_type != "compute":
         return
     cells_api = cells_rpcapi.CellsAPI()
     try:
         cells_api.instance_info_cache_update_at_top(ctxt, info_cache)
     except Exception:
         LOG.exception(_LE("Failed to notify cells of instance info " "cache update"))
开发者ID:mathslinux,项目名称:nova,代码行数:9,代码来源:instance_info_cache.py

示例4: _metadata_as_json

    def _metadata_as_json(self, version, path):
        metadata = {'uuid': self.uuid}
        if self.launch_metadata:
            metadata['meta'] = self.launch_metadata
        if self.files:
            metadata['files'] = self.files
        if self.extra_md:
            metadata.update(self.extra_md)
        if self.network_config:
            metadata['network_config'] = self.network_config

        if self.instance.key_name:
            if cells_opts.get_cell_type() == 'compute':
                cells_api = cells_rpcapi.CellsAPI()
                keypair = cells_api.get_keypair_at_top(
                  context.get_admin_context(), self.instance.user_id,
                  self.instance.key_name)
            else:
                keypairs = self.instance.keypairs
                # NOTE(mriedem): It's possible for the keypair to be deleted
                # before it was migrated to the instance_extra table, in which
                # case lazy-loading instance.keypairs will handle the 404 and
                # just set an empty KeyPairList object on the instance.
                keypair = keypairs[0] if keypairs else None

            if keypair:
                metadata['public_keys'] = {
                    keypair.name: keypair.public_key,
                }

                metadata['keys'] = [
                    {'name': keypair.name,
                     'type': keypair.type,
                     'data': keypair.public_key}
                ]
            else:
                LOG.debug("Unable to find keypair for instance with "
                          "key name '%s'.", self.instance.key_name,
                          instance=self.instance)

        metadata['hostname'] = self._get_hostname()
        metadata['name'] = self.instance.display_name
        metadata['launch_index'] = self.instance.launch_index
        metadata['availability_zone'] = self.availability_zone

        if self._check_os_version(GRIZZLY, version):
            metadata['random_seed'] = base64.b64encode(os.urandom(512))

        if self._check_os_version(LIBERTY, version):
            metadata['project_id'] = self.instance.project_id

        if self._check_os_version(NEWTON_ONE, version):
            metadata['devices'] = self._get_device_metadata()

        self.set_mimetype(MIME_TYPE_APPLICATION_JSON)
        return jsonutils.dump_as_bytes(metadata)
开发者ID:2020human,项目名称:nova,代码行数:56,代码来源:base.py

示例5: _metadata_as_json

    def _metadata_as_json(self, version, path):
        metadata = {'uuid': self.uuid}
        if self.launch_metadata:
            metadata['meta'] = self.launch_metadata
        if self.files:
            metadata['files'] = self.files
        if self.extra_md:
            metadata.update(self.extra_md)
        if self.network_config:
            metadata['network_config'] = self.network_config
        if self.instance.key_name:
            metadata['public_keys'] = {
                self.instance.key_name: self.instance.key_data
            }

            if cells_opts.get_cell_type() == 'compute':
                cells_api = cells_rpcapi.CellsAPI()
                keypair = cells_api.get_keypair_at_top(
                  context.get_admin_context(), self.instance.user_id,
                  self.instance.key_name)
            else:
                try:
                    keypair = keypair_obj.KeyPair.get_by_name(
                        context.get_admin_context(), self.instance.user_id,
                        self.instance.key_name)
                except exception.KeypairNotFound:
                    # NOTE(mriedem): If the keypair was deleted from under us
                    # don't totally fail the request, just treat it as if the
                    # instance.key_name wasn't set.
                    keypair = None

            if keypair:
                metadata['keys'] = [
                    {'name': keypair.name,
                     'type': keypair.type,
                     'data': keypair.public_key}
                ]
            else:
                LOG.debug("Unable to find keypair for instance with "
                          "key name '%s'.", self.instance.key_name,
                          instance=self.instance)

        metadata['hostname'] = self._get_hostname()
        metadata['name'] = self.instance.display_name
        metadata['launch_index'] = self.instance.launch_index
        metadata['availability_zone'] = self.availability_zone

        if self._check_os_version(GRIZZLY, version):
            metadata['random_seed'] = base64.b64encode(os.urandom(512))

        if self._check_os_version(LIBERTY, version):
            metadata['project_id'] = self.instance.project_id

        self.set_mimetype(MIME_TYPE_APPLICATION_JSON)
        return jsonutils.dump_as_bytes(metadata)
开发者ID:Snergster,项目名称:virl-salt,代码行数:55,代码来源:nova+api+metadata+base.py

示例6: _save_helper

    def _save_helper(self, cell_type, update_cells):
        obj = instance_info_cache.InstanceInfoCache()
        cells_api = cells_rpcapi.CellsAPI()

        self.mox.StubOutWithMock(db, "instance_info_cache_update")
        self.mox.StubOutWithMock(cells_opts, "get_cell_type")
        self.mox.StubOutWithMock(cells_rpcapi, "CellsAPI", use_mock_anything=True)
        self.mox.StubOutWithMock(cells_api, "instance_info_cache_update_at_top")
        nwinfo = network_model.NetworkInfo.hydrate([{"address": "foo"}])
        db.instance_info_cache_update(self.context, "fake-uuid", {"network_info": nwinfo.json()}).AndReturn("foo")
        if update_cells:
            cells_opts.get_cell_type().AndReturn(cell_type)
            if cell_type == "compute":
                cells_rpcapi.CellsAPI().AndReturn(cells_api)
                cells_api.instance_info_cache_update_at_top(self.context, "foo")
        self.mox.ReplayAll()
        obj._context = self.context
        obj.instance_uuid = "fake-uuid"
        obj.network_info = nwinfo
        obj.save(update_cells=update_cells)
开发者ID:jettang,项目名称:icehouse,代码行数:20,代码来源:test_instance_info_cache.py

示例7: save

 def save(self, context):
     updates = self.obj_get_changes()
     if "instance" in updates:
         raise exception.ObjectActionError(action="save", reason="instance changed")
     updates.pop("id", None)
     updated = db.block_device_mapping_update(self._context, self.id, updates, legacy=False)
     self._from_db_object(context, self, updated)
     cell_type = cells_opts.get_cell_type()
     if cell_type == "compute":
         cells_api = cells_rpcapi.CellsAPI()
         cells_api.bdm_update_or_create_at_top(context, self)
开发者ID:dtroyer,项目名称:nova,代码行数:11,代码来源:block_device.py

示例8: destroy

    def destroy(self):
        if not self.obj_attr_is_set("id"):
            raise exception.ObjectActionError(action="destroy", reason="already destroyed")
        db.block_device_mapping_destroy(self._context, self.id)
        delattr(self, base.get_attrname("id"))

        cell_type = cells_opts.get_cell_type()
        if cell_type == "compute":
            cells_api = cells_rpcapi.CellsAPI()
            cells_api.bdm_destroy_at_top(
                self._context, self.instance_uuid, device_name=self.device_name, volume_id=self.volume_id
            )
开发者ID:EnKalvi,项目名称:nova,代码行数:12,代码来源:block_device.py

示例9: save

 def save(self):
     updates = self.obj_get_changes()
     if 'instance' in updates:
         raise exception.ObjectActionError(action='save',
                                           reason='instance changed')
     updates.pop('id', None)
     updated = db.block_device_mapping_update(self._context, self.id,
                                              updates, legacy=False)
     self._from_db_object(self._context, self, updated)
     cell_type = cells_opts.get_cell_type()
     if cell_type == 'compute':
         cells_api = cells_rpcapi.CellsAPI()
         cells_api.bdm_update_or_create_at_top(self._context, self)
开发者ID:drunkensailor2010,项目名称:nova,代码行数:13,代码来源:block_device.py

示例10: _create

    def _create(self, context, update_or_create=False):
        """Create the block device record in the database.

        In case the id field is set on the object, and if the instance is set
        raise an ObjectActionError. Resets all the changes on the object.

        Returns None

        :param context: security context used for database calls
        :param update_or_create: consider existing block devices for the
                instance based on the device name and swap, and only update
                the ones that match. Normally only used when creating the
                instance for the first time.
        """
        cell_type = cells_opts.get_cell_type()
        if cell_type == 'api':
            raise exception.ObjectActionError(
                    action='create',
                    reason='BlockDeviceMapping cannot be '
                           'created in the API cell.')

        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        if 'instance' in updates:
            raise exception.ObjectActionError(action='create',
                                              reason='instance assigned')

        cells_create = update_or_create or None
        if update_or_create:
            db_bdm = db.block_device_mapping_update_or_create(
                    context, updates, legacy=False)
        else:
            db_bdm = db.block_device_mapping_create(
                    context, updates, legacy=False)

        self._from_db_object(context, self, db_bdm)
        # NOTE(alaski): bdms are looked up by instance uuid and device_name
        # so if we sync up with no device_name an entry will be created that
        # will not be found on a later update_or_create call and a second bdm
        # create will occur.
        if cell_type == 'compute' and db_bdm.get('device_name') is not None:
            cells_api = cells_rpcapi.CellsAPI()
            cells_api.bdm_update_or_create_at_top(
                    context, self, create=cells_create)
开发者ID:ruslanloman,项目名称:nova,代码行数:46,代码来源:block_device.py

示例11: _metadata_as_json

    def _metadata_as_json(self, version, path):
        metadata = {'uuid': self.uuid}
        if self.launch_metadata:
            metadata['meta'] = self.launch_metadata
        if self.files:
            metadata['files'] = self.files
        if self.extra_md:
            metadata.update(self.extra_md)
        if self.network_config:
            metadata['network_config'] = self.network_config
        if self.instance.key_name:
            metadata['public_keys'] = {
                self.instance.key_name: self.instance.key_data
            }

            if cells_opts.get_cell_type() == 'compute':
                cells_api = cells_rpcapi.CellsAPI()
                keypair = cells_api.get_keypair_at_top(
                  context.get_admin_context(), self.instance.user_id,
                  self.instance.key_name)
            else:
                keypair = keypair_obj.KeyPair.get_by_name(
                    context.get_admin_context(), self.instance.user_id,
                    self.instance.key_name)
            metadata['keys'] = [
                {'name': keypair.name,
                 'type': keypair.type,
                 'data': keypair.public_key}
            ]

        metadata['hostname'] = self._get_hostname()
        metadata['name'] = self.instance.display_name
        metadata['launch_index'] = self.instance.launch_index
        metadata['availability_zone'] = self.availability_zone

        if self._check_os_version(GRIZZLY, version):
            metadata['random_seed'] = base64.b64encode(os.urandom(512))

        if self._check_os_version(LIBERTY, version):
            metadata['project_id'] = self.instance.project_id

        self.set_mimetype(MIME_TYPE_APPLICATION_JSON)
        return jsonutils.dump_as_bytes(metadata)
开发者ID:chenglinlee,项目名称:nova,代码行数:43,代码来源:base.py

示例12: save

 def save(self):
     updates = self.obj_get_changes()
     if "instance" in updates:
         raise exception.ObjectActionError(action="save", reason="instance changed")
     updates.pop("id", None)
     updated = db.block_device_mapping_update(self._context, self.id, updates, legacy=False)
     if not updated:
         raise exception.BDMNotFound(id=self.id)
     self._from_db_object(self._context, self, updated)
     cell_type = cells_opts.get_cell_type()
     if cell_type == "compute":
         create = False
         # NOTE(alaski): If the device name has just been set this bdm
         # likely does not exist in the parent cell and we should create it.
         # If this is a modification of the device name we should update
         # rather than create which is why None is used here instead of True
         if "device_name" in updates:
             create = None
         cells_api = cells_rpcapi.CellsAPI()
         cells_api.bdm_update_or_create_at_top(self._context, self, create=create)
开发者ID:EnKalvi,项目名称:nova,代码行数:20,代码来源:block_device.py

示例13: create

    def create(self, context):
        cell_type = cells_opts.get_cell_type()
        if cell_type == 'api':
            raise exception.ObjectActionError(
                    action='create',
                    reason='BlockDeviceMapping cannot be '
                           'created in the API cell.')

        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        if 'instance' in updates:
            raise exception.ObjectActionError(action='create',
                                              reason='instance assigned')

        db_bdm = db.block_device_mapping_create(context, updates, legacy=False)
        self._from_db_object(context, self, db_bdm)
        if cell_type == 'compute':
            cells_api = cells_rpcapi.CellsAPI()
            cells_api.bdm_update_or_create_at_top(context, self, create=True)
开发者ID:HybridCloud-dew,项目名称:hws,代码行数:21,代码来源:block_device.py

示例14: create

 def create(self, context):
     if self.obj_attr_is_set("id"):
         raise exception.ObjectActionError(action="create", reason="already created")
     values = {
         "instance_uuid": self.instance_uuid,
         "code": self.code,
         "message": self.message,
         "details": self.details,
         "host": self.host,
     }
     db_fault = db.instance_fault_create(context, values)
     self._from_db_object(context, self, db_fault)
     self.obj_reset_changes()
     # Cells should only try sending a message over to nova-cells
     # if cells is enabled and we're not the API cell. Otherwise,
     # if the API cell is calling this, we could end up with
     # infinite recursion.
     if cells_opts.get_cell_type() == "compute":
         try:
             cells_rpcapi.CellsAPI().instance_fault_create_at_top(context, db_fault)
         except Exception:
             LOG.exception(_LE("Failed to notify cells of instance fault"))
开发者ID:rcosma-gd,项目名称:openstack-nova,代码行数:22,代码来源:instance_fault.py

示例15: _create

    def _create(self, context, update_or_create=False):
        """Create the block device record in the database.

        In case the id field is set on the object, and if the instance is set
        raise an ObjectActionError. Resets all the changes on the object.

        Returns None

        :param context: security context used for database calls
        :param update_or_create: consider existing block devices for the
                instance based on the device name and swap, and only update
                the ones that match. Normally only used when creating the
                instance for the first time.
        """
        cell_type = cells_opts.get_cell_type()
        if cell_type == "api":
            raise exception.ObjectActionError(
                action="create", reason="BlockDeviceMapping cannot be " "created in the API cell."
            )

        if self.obj_attr_is_set("id"):
            raise exception.ObjectActionError(action="create", reason="already created")
        updates = self.obj_get_changes()
        if "instance" in updates:
            raise exception.ObjectActionError(action="create", reason="instance assigned")

        cells_create = update_or_create or None
        if update_or_create:
            db_bdm = db.block_device_mapping_update_or_create(context, updates, legacy=False)
        else:
            db_bdm = db.block_device_mapping_create(context, updates, legacy=False)

        self._from_db_object(context, self, db_bdm)
        if cell_type == "compute":
            cells_api = cells_rpcapi.CellsAPI()
            cells_api.bdm_update_or_create_at_top(context, self, create=cells_create)
开发者ID:dtroyer,项目名称:nova,代码行数:36,代码来源:block_device.py


注:本文中的nova.cells.opts.get_cell_type函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。