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


Python instance_types.get_instance_type_by_name函数代码示例

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


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

示例1: test_notify_about_instance_usage

 def test_notify_about_instance_usage(self):
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     extra_usage_info = {'image_name': 'fake_name'}
     db.instance_system_metadata_update(self.context, instance['uuid'],
             sys_metadata, False)
     compute_utils.notify_about_instance_usage(self.context, instance,
     'create.start', extra_usage_info=extra_usage_info)
     self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
     msg = test_notifier.NOTIFICATIONS[0]
     self.assertEquals(msg['priority'], 'INFO')
     self.assertEquals(msg['event_type'], 'compute.instance.create.start')
     payload = msg['payload']
     self.assertEquals(payload['tenant_id'], self.project_id)
     self.assertEquals(payload['user_id'], self.user_id)
     self.assertEquals(payload['instance_id'], instance.uuid)
     self.assertEquals(payload['instance_type'], 'm1.tiny')
     type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
     self.assertEquals(str(payload['instance_type_id']), str(type_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEquals(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     self.assertEquals(payload['image_name'], 'fake_name')
     image_ref_url = "%s/images/1" % utils.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context, instance)
开发者ID:EE-NovRain,项目名称:nova,代码行数:33,代码来源:test_compute_utils.py

示例2: test_resize_instance_notification

    def test_resize_instance_notification(self):
        """Ensure notifications on instance migrate/resize"""
        instance_id = self._create_instance()
        context = self.context.elevated()
        inst_ref = db.instance_get(context, instance_id)

        self.compute.run_instance(self.context, instance_id)
        test_notifier.NOTIFICATIONS = []

        db.instance_update(self.context, instance_id, {'host': 'foo'})
        self.compute.prep_resize(context, inst_ref['uuid'], 1)
        migration_ref = db.migration_get_by_instance_and_status(context,
                inst_ref['uuid'], 'pre-migrating')

        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], 'INFO')
        self.assertEquals(msg['event_type'], 'compute.instance.resize.prep')
        payload = msg['payload']
        self.assertEquals(payload['tenant_id'], self.project_id)
        self.assertEquals(payload['user_id'], self.user_id)
        self.assertEquals(payload['instance_id'], instance_id)
        self.assertEquals(payload['instance_type'], 'm1.tiny')
        type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
        self.assertEquals(str(payload['instance_type_id']), str(type_id))
        self.assertTrue('display_name' in payload)
        self.assertTrue('created_at' in payload)
        self.assertTrue('launched_at' in payload)
        self.assertEquals(payload['image_ref'], '1')
        self.compute.terminate_instance(context, instance_id)
开发者ID:cp16net,项目名称:reddwarf,代码行数:30,代码来源:test_compute.py

示例3: create

    def create(self, req, body):
        """Create a new VSA."""
        context = req.environ["nova.context"]

        if not body or "vsa" not in body:
            LOG.debug(_("No body provided"), context=context)
            raise exc.HTTPUnprocessableEntity()

        vsa = body["vsa"]

        display_name = vsa.get("displayName")
        vc_type = vsa.get("vcType", FLAGS.default_vsa_instance_type)
        try:
            instance_type = instance_types.get_instance_type_by_name(vc_type)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        LOG.audit(_("Create VSA %(display_name)s of type %(vc_type)s"), locals(), context=context)

        args = dict(
            display_name=display_name,
            display_description=vsa.get("displayDescription"),
            instance_type=instance_type,
            storage=vsa.get("storage"),
            shared=vsa.get("shared"),
            availability_zone=vsa.get("placement", {}).get("AvailabilityZone"),
        )

        vsa = self.vsa_api.create(context, **args)

        instances = self._get_instances_by_vsa_id(context, vsa.get("id"))
        return {"vsa": _vsa_view(context, vsa, True, instances)}
开发者ID:nanodayo,项目名称:nova,代码行数:32,代码来源:virtual_storage_arrays.py

示例4: test_finish_migrate_no_local_storage

    def test_finish_migrate_no_local_storage(self):
        tiny_type_id = instance_types.get_instance_type_by_name("m1.tiny")["id"]
        self.values.update({"instance_type_id": tiny_type_id, "local_gb": 0})
        instance = db.instance_create(self.context, self.values)

        def fake_vdi_resize(*args, **kwargs):
            raise Exception("This shouldn't be called")

        self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize)
        stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests)
        stubs.stubout_loopingcall_start(self.stubs)
        conn = xenapi_conn.get_connection(False)
        network_info = [
            (
                {"bridge": "fa0", "id": 0, "injected": False},
                {
                    "broadcast": "192.168.0.255",
                    "dns": ["192.168.0.1"],
                    "gateway": "192.168.0.1",
                    "gateway6": "dead:beef::1",
                    "ip6s": [{"enabled": "1", "ip": "dead:beef::dcad:beff:feef:0", "netmask": "64"}],
                    "ips": [{"enabled": "1", "ip": "192.168.0.100", "netmask": "255.255.255.0"}],
                    "label": "fake",
                    "mac": "DE:AD:BE:EF:00:00",
                    "rxtx_cap": 3,
                },
            )
        ]
        conn.finish_migration(
            self.context, instance, dict(base_copy="hurr", cow="durr"), network_info, resize_instance=True
        )
开发者ID:nii-cloud,项目名称:dodai-compute,代码行数:31,代码来源:test_xenapi.py

示例5: _create_with_injected_files

 def _create_with_injected_files(self, files):
     self.flags(image_service="nova.image.fake.FakeImageService")
     api = compute.API(image_service=self.StubImageService())
     inst_type = instance_types.get_instance_type_by_name("m1.small")
     api.create(
         self.context, min_count=1, max_count=1, instance_type=inst_type, image_href="3", injected_files=files
     )
开发者ID:rlz,项目名称:osc-build-nova,代码行数:7,代码来源:test_quota.py

示例6: _create_with_injected_files

 def _create_with_injected_files(self, files):
     FLAGS.image_service = 'nova.image.fake.FakeImageService'
     api = compute.API(image_service=self.StubImageService())
     inst_type = instance_types.get_instance_type_by_name('m1.small')
     api.create(self.context, min_count=1, max_count=1,
             instance_type=inst_type, image_href='3',
             injected_files=files)
开发者ID:cp16net,项目名称:reddwarf,代码行数:7,代码来源:test_quota.py

示例7: test_notify_usage_exists_deleted_instance

 def test_notify_usage_exists_deleted_instance(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     db.instance_system_metadata_update(self.context, instance['uuid'],
             sys_metadata, False)
     self.compute.terminate_instance(self.context, instance)
     instance = db.instance_get(self.context.elevated(read_deleted='yes'),
                                instance_id)
     compute_utils.notify_usage_exists(self.context, instance)
     msg = test_notifier.NOTIFICATIONS[-1]
     self.assertEquals(msg['priority'], 'INFO')
     self.assertEquals(msg['event_type'], 'compute.instance.exists')
     payload = msg['payload']
     self.assertEquals(payload['tenant_id'], self.project_id)
     self.assertEquals(payload['user_id'], self.user_id)
     self.assertEquals(payload['instance_id'], instance['uuid'])
     self.assertEquals(payload['instance_type'], 'm1.tiny')
     type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
     self.assertEquals(str(payload['instance_type_id']), str(type_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description',
                  'bandwidth', 'audit_period_beginning',
                  'audit_period_ending', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEquals(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
开发者ID:CiscoAS,项目名称:nova,代码行数:34,代码来源:test_compute_utils.py

示例8: test_finish_migrate_no_local_storage

    def test_finish_migrate_no_local_storage(self):
        tiny_type_id = \
                instance_types.get_instance_type_by_name('m1.tiny')['id']
        self.values.update({'instance_type_id': tiny_type_id, 'local_gb': 0})
        instance = db.instance_create(self.context, self.values)

        def fake_vdi_resize(*args, **kwargs):
            raise Exception("This shouldn't be called")

        self.stubs.Set(stubs.FakeSessionForMigrationTests,
                "VDI_resize_online", fake_vdi_resize)
        stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests)
        stubs.stubout_loopingcall_start(self.stubs)
        conn = xenapi_conn.get_connection(False)
        network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False},
                          {'broadcast': '192.168.0.255',
                           'dns': ['192.168.0.1'],
                           'gateway': '192.168.0.1',
                           'gateway6': 'dead:beef::1',
                           'ip6s': [{'enabled': '1',
                                     'ip': 'dead:beef::dcad:beff:feef:0',
                                           'netmask': '64'}],
                           'ips': [{'enabled': '1',
                                    'ip': '192.168.0.100',
                                    'netmask': '255.255.255.0'}],
                           'label': 'fake',
                           'mac': 'DE:AD:BE:EF:00:00',
                           'rxtx_cap': 3})]
        conn.finish_migration(instance, dict(base_copy='hurr', cow='durr'),
                           network_info, resize_instance=True)
开发者ID:cp16net,项目名称:reddwarf,代码行数:30,代码来源:test_xenapi.py

示例9: create

    def create(self, req, body):
        """Create a new VSA."""
        context = req.environ['nova.context']
        authorize(context)

        if not body or 'vsa' not in body:
            LOG.debug(_("No body provided"), context=context)
            raise exc.HTTPUnprocessableEntity()

        vsa = body['vsa']

        display_name = vsa.get('displayName')
        vc_type = vsa.get('vcType', FLAGS.default_vsa_instance_type)
        try:
            instance_type = instance_types.get_instance_type_by_name(vc_type)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        LOG.audit(_("Create VSA %(display_name)s of type %(vc_type)s"),
                    locals(), context=context)

        _vsa_placement = vsa.get('placement', {})
        args = dict(display_name=display_name,
                    display_description=vsa.get('displayDescription'),
                    instance_type=instance_type,
                    storage=vsa.get('storage'),
                    shared=vsa.get('shared'),
                    availability_zone=_vsa_placement.get('AvailabilityZone'))

        vsa = self.vsa_api.create(context, **args)

        instances = self._get_instances_by_vsa_id(context, vsa.get('id'))
        return {'vsa': _vsa_view(context, vsa, True, instances)}
开发者ID:baz-reddwarf,项目名称:nova,代码行数:33,代码来源:virtual_storage_arrays.py

示例10: test_notify_usage_exists_instance_not_found

 def test_notify_usage_exists_instance_not_found(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     self.compute.terminate_instance(self.context, instance)
     compute_utils.notify_usage_exists(self.context, instance)
     msg = test_notifier.NOTIFICATIONS[-1]
     self.assertEquals(msg['priority'], 'INFO')
     self.assertEquals(msg['event_type'], 'compute.instance.exists')
     payload = msg['payload']
     self.assertEquals(payload['tenant_id'], self.project_id)
     self.assertEquals(payload['user_id'], self.user_id)
     self.assertEquals(payload['instance_id'], instance['uuid'])
     self.assertEquals(payload['instance_type'], 'm1.tiny')
     type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
     self.assertEquals(str(payload['instance_type_id']), str(type_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description',
                  'bandwidth', 'audit_period_beginning',
                  'audit_period_ending', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEquals(payload['image_meta'], {})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
开发者ID:CiscoAS,项目名称:nova,代码行数:25,代码来源:test_compute_utils.py

示例11: run_instances

 def run_instances(self, context, **kwargs):
     max_count = int(kwargs.get('max_count', 1))
     if kwargs.get('kernel_id'):
         kernel = self._get_image(context, kwargs['kernel_id'])
         kwargs['kernel_id'] = kernel['id']
     if kwargs.get('ramdisk_id'):
         ramdisk = self._get_image(context, kwargs['ramdisk_id'])
         kwargs['ramdisk_id'] = ramdisk['id']
     instances = self.compute_api.create(context,
         instance_type=instance_types.get_instance_type_by_name(
             kwargs.get('instance_type', None)),
         image_id=self._get_image(context, kwargs['image_id'])['id'],
         min_count=int(kwargs.get('min_count', max_count)),
         max_count=max_count,
         kernel_id=kwargs.get('kernel_id'),
         ramdisk_id=kwargs.get('ramdisk_id'),
         display_name=kwargs.get('display_name'),
         display_description=kwargs.get('display_description'),
         key_name=kwargs.get('key_name'),
         user_data=kwargs.get('user_data'),
         security_group=kwargs.get('security_group'),
         availability_zone=kwargs.get('placement', {}).get(
                               'AvailabilityZone'))
     return self._format_run_instances(context,
                                       instances[0]['reservation_id'])
开发者ID:superstack,项目名称:nova,代码行数:25,代码来源:cloud.py

示例12: test_notify_usage_exists

 def test_notify_usage_exists(self):
     """Ensure 'exists' notification generates appropriate usage data."""
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {"image_md_key1": "val1", "image_md_key2": "val2", "other_data": "meow"}
     db.instance_system_metadata_update(self.context, instance["uuid"], sys_metadata, False)
     compute_utils.notify_usage_exists(self.context, instance)
     self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
     msg = test_notifier.NOTIFICATIONS[0]
     self.assertEquals(msg["priority"], "INFO")
     self.assertEquals(msg["event_type"], "compute.instance.exists")
     payload = msg["payload"]
     self.assertEquals(payload["tenant_id"], self.project_id)
     self.assertEquals(payload["user_id"], self.user_id)
     self.assertEquals(payload["instance_id"], instance.uuid)
     self.assertEquals(payload["instance_type"], "m1.tiny")
     type_id = instance_types.get_instance_type_by_name("m1.tiny")["id"]
     self.assertEquals(str(payload["instance_type_id"]), str(type_id))
     for attr in (
         "display_name",
         "created_at",
         "launched_at",
         "state",
         "state_description",
         "bandwidth",
         "audit_period_beginning",
         "audit_period_ending",
         "image_meta",
     ):
         self.assertTrue(attr in payload, msg="Key %s not in payload" % attr)
     self.assertEquals(payload["image_meta"], {"md_key1": "val1", "md_key2": "val2"})
     image_ref_url = "%s/images/1" % utils.generate_glance_url()
     self.assertEquals(payload["image_ref_url"], image_ref_url)
     self.compute.terminate_instance(self.context, instance["uuid"])
开发者ID:Nesrine85,项目名称:nova,代码行数:35,代码来源:test_compute_utils.py

示例13: test_no_injected_files

 def test_no_injected_files(self):
     self.flags(image_service='nova.image.fake.FakeImageService')
     api = compute.API(image_service=self.StubImageService())
     inst_type = instance_types.get_instance_type_by_name('m1.small')
     image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
     api.create(self.context,
                instance_type=inst_type,
                image_href=image_uuid)
开发者ID:AnyBucket,项目名称:OpenStack-Install-and-Understand-Guide,代码行数:8,代码来源:test_quota.py

示例14: _create_with_injected_files

 def _create_with_injected_files(self, files):
     self.flags(image_service="nova.image.fake.FakeImageService")
     api = compute.API(image_service=self.StubImageService())
     inst_type = instance_types.get_instance_type_by_name("m1.small")
     image_uuid = "cedef40a-ed67-4d10-800e-17455edce175"
     api.create(
         self.context, min_count=1, max_count=1, instance_type=inst_type, image_href=image_uuid, injected_files=files
     )
开发者ID:renuka-apte,项目名称:nova,代码行数:8,代码来源:test_quota.py

示例15: list

 def list(self, name=None):
     """Lists all active or specific instance types / flavors."""
     try:
         if name is None:
             inst_types = instance_types.get_all_types()
         else:
             inst_types = instance_types.get_instance_type_by_name(name)
     except db_exc.DBError, e:
         _db_error(e)
开发者ID:AnyBucket,项目名称:nova,代码行数:9,代码来源:manage.py


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