Ejemplo n.º 1
0
 def prep_resize(
     self,
     ctxt,
     image,
     instance,
     instance_type,
     host,
     reservations=None,
     request_spec=None,
     filter_properties=None,
     node=None,
 ):
     version = "3.0"
     instance_type_p = jsonutils.to_primitive(instance_type)
     image_p = jsonutils.to_primitive(image)
     cctxt = self.client.prepare(server=host, version=version)
     cctxt.cast(
         ctxt,
         "prep_resize",
         instance=instance,
         instance_type=instance_type_p,
         image=image_p,
         reservations=reservations,
         request_spec=request_spec,
         filter_properties=filter_properties,
         node=node,
     )
Ejemplo n.º 2
0
    def test_depth(self):
        class LevelsGenerator(object):
            def __init__(self, levels):
                self._levels = levels

            def iteritems(self):
                if self._levels == 0:
                    return iter([])
                else:
                    return iter([(0, LevelsGenerator(self._levels - 1))])

        l4_obj = LevelsGenerator(4)

        json_l2 = {0: {0: '?'}}
        json_l3 = {0: {0: {0: '?'}}}
        json_l4 = {0: {0: {0: {0: '?'}}}}

        ret = jsonutils.to_primitive(l4_obj, max_depth=2)
        self.assertEqual(ret, json_l2)

        ret = jsonutils.to_primitive(l4_obj, max_depth=3)
        self.assertEqual(ret, json_l3)

        ret = jsonutils.to_primitive(l4_obj, max_depth=4)
        self.assertEqual(ret, json_l4)
Ejemplo n.º 3
0
 def _notify(self, priority, ctxt, event_type, payload):
     payload = self._serializer.serialize_entity(ctxt, payload)
     # NOTE(sileht): simulate the kombu serializer
     # this permit to raise an exception if something have not
     # been serialized correctly
     jsonutils.to_primitive(payload)
     msg = FakeMessage(self.publisher_id, priority, event_type, payload)
     NOTIFICATIONS.append(msg)
Ejemplo n.º 4
0
 def build_instances(self, ctxt, **kwargs):
     """Build instances."""
     build_inst_kwargs = kwargs
     instances = build_inst_kwargs["instances"]
     instances_p = [jsonutils.to_primitive(inst) for inst in instances]
     build_inst_kwargs["instances"] = instances_p
     build_inst_kwargs["image"] = jsonutils.to_primitive(build_inst_kwargs["image"])
     cctxt = self.client.prepare(version="1.8")
     cctxt.cast(ctxt, "build_instances", build_inst_kwargs=build_inst_kwargs)
Ejemplo n.º 5
0
 def build_instances(self, ctxt, **kwargs):
     """Build instances."""
     build_inst_kwargs = kwargs
     instances = build_inst_kwargs['instances']
     instances_p = [jsonutils.to_primitive(inst) for inst in instances]
     build_inst_kwargs['instances'] = instances_p
     build_inst_kwargs['image'] = jsonutils.to_primitive(
             build_inst_kwargs['image'])
     cctxt = self.client.prepare(version='1.8')
     cctxt.cast(ctxt, 'build_instances',
                build_inst_kwargs=build_inst_kwargs)
Ejemplo n.º 6
0
    def test_instance(self):
        class MysteryClass(object):
            a = 10

            def __init__(self):
                self.b = 1

        x = MysteryClass()
        self.assertEqual(jsonutils.to_primitive(x, convert_instances=True),
                         dict(b=1))

        self.assertEqual(jsonutils.to_primitive(x), x)
Ejemplo n.º 7
0
 def build_instances(self, ctxt, **kwargs):
     """Build instances."""
     build_inst_kwargs = kwargs
     instances = build_inst_kwargs["instances"]
     instances_p = [jsonutils.to_primitive(inst) for inst in instances]
     build_inst_kwargs["instances"] = instances_p
     build_inst_kwargs["image"] = jsonutils.to_primitive(build_inst_kwargs["image"])
     if "filter_properties" in build_inst_kwargs:
         flavor = build_inst_kwargs["filter_properties"]["instance_type"]
         flavor_p = objects_base.obj_to_primitive(flavor)
         build_inst_kwargs["filter_properties"]["instance_type"] = flavor_p
     cctxt = self.client.prepare(version="1.8")
     cctxt.cast(ctxt, "build_instances", build_inst_kwargs=build_inst_kwargs)
Ejemplo n.º 8
0
 def setUp(self):
     super(ComputeRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     instance_attr = {'host': 'fake_host',
                      'instance_type_id': 1}
     self.fake_instance_obj = fake_instance_obj(self.context,
                                                **instance_attr)
     self.fake_instance = jsonutils.to_primitive(self.fake_instance_obj)
     self.fake_volume_bdm = jsonutils.to_primitive(
             fake_block_device.FakeDbBlockDeviceDict(
                 {'source_type': 'volume', 'destination_type': 'volume',
                  'instance_uuid': self.fake_instance['uuid'],
                  'volume_id': 'fake-volume-id'}))
Ejemplo n.º 9
0
 def notify_usage_exists(self, context, instance, current_period=False,
                         ignore_missing_network_data=True,
                         system_metadata=None, extra_usage_info=None):
     instance_p = jsonutils.to_primitive(instance)
     system_metadata_p = jsonutils.to_primitive(system_metadata)
     extra_usage_info_p = jsonutils.to_primitive(extra_usage_info)
     cctxt = self.client.prepare()
     return cctxt.call(
         context, 'notify_usage_exists',
         instance=instance_p,
         current_period=current_period,
         ignore_missing_network_data=ignore_missing_network_data,
         system_metadata=system_metadata_p,
         extra_usage_info=extra_usage_info_p)
Ejemplo n.º 10
0
 def get_instance_diagnostics(self, ctxt, instance):
     instance_p = jsonutils.to_primitive(instance)
     kwargs = {'instance': instance_p}
     version = '3.31'
     cctxt = self.client.prepare(server=_compute_host(None, instance),
             version=version)
     return cctxt.call(ctxt, 'get_instance_diagnostics', **kwargs)
Ejemplo n.º 11
0
 def refresh_instance_security_rules(self, ctxt, host, instance):
     version = '3.0'
     instance_p = jsonutils.to_primitive(instance)
     cctxt = self.client.prepare(server=_compute_host(None, instance),
             version=version)
     cctxt.cast(ctxt, 'refresh_instance_security_rules',
                instance=instance_p)
Ejemplo n.º 12
0
 def block_device_mapping_get_all_by_instance(self, context, instance,
                                              legacy):
     bdms = self.db.block_device_mapping_get_all_by_instance(
         context, instance['uuid'])
     if legacy:
         bdms = block_device.legacy_mapping(bdms)
     return jsonutils.to_primitive(bdms)
Ejemplo n.º 13
0
 def instance_get_all_by_filters(self, context, filters, sort_key,
                                 sort_dir, columns_to_join,
                                 use_slave):
     result = self.db.instance_get_all_by_filters(
         context, filters, sort_key, sort_dir,
         columns_to_join=columns_to_join, use_slave=use_slave)
     return jsonutils.to_primitive(result)
Ejemplo n.º 14
0
    def run_instance(
        self,
        ctxt,
        instance,
        host,
        request_spec,
        filter_properties,
        requested_networks,
        injected_files,
        admin_password,
        is_first_time,
        node=None,
        legacy_bdm_in_spec=True,
    ):
        if self.client.can_send_version("3.27"):
            version = "3.27"
        else:
            version = "3.0"
            instance = jsonutils.to_primitive(instance)
        msg_kwargs = {
            "instance": instance,
            "request_spec": request_spec,
            "filter_properties": filter_properties,
            "requested_networks": requested_networks,
            "injected_files": injected_files,
            "admin_password": admin_password,
            "is_first_time": is_first_time,
            "node": node,
            "legacy_bdm_in_spec": legacy_bdm_in_spec,
        }

        cctxt = self.client.prepare(server=host, version=version)
        cctxt.cast(ctxt, "run_instance", **msg_kwargs)
Ejemplo n.º 15
0
def build_request_spec(ctxt, image, instances, instance_type=None):
    """Build a request_spec for the scheduler.

    The request_spec assumes that all instances to be scheduled are the same
    type.
    """
    instance = instances[0]
    if isinstance(instance, obj_base.NovaObject):
        instance = obj_base.obj_to_primitive(instance)

    if instance_type is None:
        instance_type = flavors.extract_flavor(instance)
        # NOTE(danms): This won't have extra_specs, so fill in the gaps
        _instance_type = objects.Flavor.get_by_flavor_id(
            ctxt, instance_type['flavorid'])
        instance_type.extra_specs = instance_type.get('extra_specs', {})
        instance_type.extra_specs.update(_instance_type.extra_specs)

    if isinstance(instance_type, objects.Flavor):
        instance_type = obj_base.obj_to_primitive(instance_type)

    request_spec = {
            'image': image or {},
            'instance_properties': instance,
            'instance_type': instance_type,
            'num_instances': len(instances)}
    return jsonutils.to_primitive(request_spec)
Ejemplo n.º 16
0
    def build_instances(self, context, instances, image, filter_properties,
            admin_password, injected_files, requested_networks,
            security_groups, block_device_mapping, legacy_bdm=True):
        image_p = jsonutils.to_primitive(image)
        if 'instance_type' in filter_properties:
            flavor = filter_properties['instance_type']
            flavor_p = objects_base.obj_to_primitive(flavor)
            filter_properties = dict(filter_properties, instance_type=flavor_p)
        kw = {'instances': instances, 'image': image_p,
               'filter_properties': filter_properties,
               'admin_password': admin_password,
               'injected_files': injected_files,
               'requested_networks': requested_networks,
               'security_groups': security_groups}

        version = '1.9'
        if not self.client.can_send_version('1.9'):
            version = '1.8'
            kw['requested_networks'] = kw['requested_networks'].as_tuples()
        if not self.client.can_send_version('1.7'):
            version = '1.5'
            kw.update({'block_device_mapping': block_device_mapping,
                       'legacy_bdm': legacy_bdm})

        cctxt = self.client.prepare(version=version)
        cctxt.cast(context, 'build_instances', **kw)
Ejemplo n.º 17
0
def build_request_spec(ctxt, image, instances, instance_type=None):
    """Build a request_spec for the scheduler.

    The request_spec assumes that all instances to be scheduled are the same
    type.
    """
    instance = instances[0]
    if isinstance(instance, obj_base.NovaObject):
        instance = obj_base.obj_to_primitive(instance)

    if instance_type is None:
        instance_type = flavors.extract_flavor(instance)
    # NOTE(comstud): This is a bit ugly, but will get cleaned up when
    # we're passing an InstanceType internal object.
    extra_specs = db.flavor_extra_specs_get(ctxt, instance_type['flavorid'])
    instance_type['extra_specs'] = extra_specs
    request_spec = {
            'image': image or {},
            'instance_properties': instance,
            'instance_type': instance_type,
            'num_instances': len(instances),
            # NOTE(alaski): This should be removed as logic moves from the
            # scheduler to conductor.  Provides backwards compatibility now.
            'instance_uuids': [inst['uuid'] for inst in instances]}
    return jsonutils.to_primitive(request_spec)
Ejemplo n.º 18
0
 def instance_update_at_top(self, ctxt, instance):
     """Update instance at API level."""
     if not CONF.cells.enable:
         return
     # Make sure we have a dict, not a SQLAlchemy model
     instance_p = jsonutils.to_primitive(instance)
     self.client.cast(ctxt, "instance_update_at_top", instance=instance_p)
Ejemplo n.º 19
0
 def instance_fault_create_at_top(self, ctxt, instance_fault):
     """Create an instance fault at the top."""
     if not CONF.cells.enable:
         return
     instance_fault_p = jsonutils.to_primitive(instance_fault)
     self.client.cast(ctxt, 'instance_fault_create_at_top',
                      instance_fault=instance_fault_p)
Ejemplo n.º 20
0
 def _sanitizer(self, obj):
     """Sanitizer method that will be passed to jsonutils.dumps."""
     if hasattr(obj, "to_dict"):
         return obj.to_dict()
     if isinstance(obj, multidict.MultiDict):
         return obj.mixed()
     return jsonutils.to_primitive(obj)
Ejemplo n.º 21
0
    def test_shelve(self):
        # Ensure instance can be shelved.
        fake_instance = self._create_fake_instance({'display_name': 'vm01'})
        instance = jsonutils.to_primitive(fake_instance)
        instance_uuid = instance['uuid']

        self.assertIsNone(instance['task_state'])

        def fake_init(self2):
            # In original _FakeImageService.__init__(), some fake images are
            # created. To verify the snapshot name of this test only, here
            # sets a fake method.
            self2.images = {}

        def fake_create(self2, ctxt, metadata, data=None):
            self.assertEqual(metadata['name'], 'vm01-shelved')
            metadata['id'] = '8b24ed3f-ee57-43bc-bc2e-fb2e9482bc42'
            return metadata

        fake_image.stub_out_image_service(self.stubs)
        self.stubs.Set(fake_image._FakeImageService, '__init__', fake_init)
        self.stubs.Set(fake_image._FakeImageService, 'create', fake_create)

        inst_obj = objects.Instance.get_by_uuid(self.context, instance_uuid)
        self.compute_api.shelve(self.context, inst_obj)

        inst_obj.refresh()
        self.assertEqual(inst_obj.task_state, task_states.SHELVING)

        db.instance_destroy(self.context, instance['uuid'])
Ejemplo n.º 22
0
 def instance_info_cache_update_at_top(self, ctxt, instance_info_cache):
     """Broadcast up that an instance's info_cache has changed."""
     if not CONF.cells.enable:
         return
     iicache = jsonutils.to_primitive(instance_info_cache)
     instance = {"uuid": iicache["instance_uuid"], "info_cache": iicache}
     self.client.cast(ctxt, "instance_update_at_top", instance=instance)
Ejemplo n.º 23
0
def build_request_spec(ctxt, image, instances, instance_type=None):
    """Build a request_spec for the scheduler.

    The request_spec assumes that all instances to be scheduled are the same
    type.
    """
    instance = instances[0]
    if isinstance(instance, obj_base.NovaObject):
        instance = obj_base.obj_to_primitive(instance)

    if instance_type is None:
        instance_type = flavors.extract_flavor(instance)

    if isinstance(instance_type, objects.Flavor):
        instance_type = obj_base.obj_to_primitive(instance_type)

    request_spec = {
            'image': image or {},
            'instance_properties': instance,
            'instance_type': instance_type,
            'num_instances': len(instances),
            # NOTE(alaski): This should be removed as logic moves from the
            # scheduler to conductor.  Provides backwards compatibility now.
            'instance_uuids': [inst['uuid'] for inst in instances]}
    return jsonutils.to_primitive(request_spec)
Ejemplo n.º 24
0
        def _formatZone(zone_dict):
            result = []

            # Zone tree view item
            result.append({'zoneName': zone_dict['zoneName'],
                           'zoneState': u'available'
                               if zone_dict['zoneState']['available'] else
                                   u'not available'})

            if zone_dict['hosts'] is not None:
                for (host, services) in zone_dict['hosts'].items():
                    # Host tree view item
                    result.append({'zoneName': u'|- %s' % host,
                                   'zoneState': u''})
                    for (svc, state) in services.items():
                        # Service tree view item
                        result.append({'zoneName': u'| |- %s' % svc,
                                       'zoneState': u'%s %s %s' % (
                                           'enabled' if state['active'] else
                                               'disabled',
                                           ':-)' if state['available'] else
                                               'XXX',
                                           jsonutils.to_primitive(
                                               state['updated_at']))})
            return result
Ejemplo n.º 25
0
 def resize_instance(self, ctxt, instance, extra_instance_updates, scheduler_hint, flavor, reservations):
     if not CONF.cells.enable:
         return
     flavor_p = jsonutils.to_primitive(flavor)
     cctxt = self.client.prepare(version="1.20")
     cctxt.cast(
         ctxt, "resize_instance", instance=instance, flavor=flavor_p, extra_instance_updates=extra_instance_updates
     )
Ejemplo n.º 26
0
 def migrate_server(self, context, instance, scheduler_hint, live, rebuild,
               flavor, block_migration, disk_over_commit,
               reservations=None):
     if self.client.can_send_version('1.6'):
         version = '1.6'
     else:
         instance = jsonutils.to_primitive(
                 objects_base.obj_to_primitive(instance))
         version = '1.4'
     flavor_p = jsonutils.to_primitive(flavor)
     cctxt = self.client.prepare(version=version)
     return cctxt.call(context, 'migrate_server',
                       instance=instance, scheduler_hint=scheduler_hint,
                       live=live, rebuild=rebuild, flavor=flavor_p,
                       block_migration=block_migration,
                       disk_over_commit=disk_over_commit,
                       reservations=reservations)
Ejemplo n.º 27
0
    def serialize_entity(self, context, entity):
        if isinstance(entity, (tuple, list, set)):
            entity = self._process_iterable(context, self.serialize_entity,
                                            entity)
        elif hasattr(entity, 'to_primitive') and callable(entity.to_primitive):
            entity = entity.to_primitive()

        return jsonutils.to_primitive(entity, convert_instances=True)
Ejemplo n.º 28
0
    def test_iteritems_with_cycle(self):
        class IterItemsClass(object):
            def __init__(self):
                self.data = dict(a=1, b=2, c=3)
                self.index = 0

            def iteritems(self):
                return self.data.items()

        x = IterItemsClass()
        x2 = IterItemsClass()
        x.data['other'] = x2
        x2.data['other'] = x

        # If the cycle isn't caught, to_primitive() will eventually result in
        # an exception due to excessive recursion depth.
        jsonutils.to_primitive(x)
Ejemplo n.º 29
0
 def select_instance_destinations(self, context, app, filter_properties):
     """Returns destinations(s) best suited for this request_spec and
     filter_properties.
     The result should be a list of dicts with 'host', 'nodename' and
     'limits' as keys.
     """
     dests = self.driver.select_instance_destinations(context, app, filter_properties)
     return jsonutils.to_primitive(dests)
Ejemplo n.º 30
0
 def instance_update(self, context, instance_uuid, updates,
                     service=None):
     updates_p = jsonutils.to_primitive(updates)
     cctxt = self.client.prepare()
     return cctxt.call(context, 'instance_update',
                       instance_uuid=instance_uuid,
                       updates=updates_p,
                       service=service)
Ejemplo n.º 31
0
 def remove_volume_connection(self, ctxt, instance, volume_id, host):
     if self.client.can_send_version('3.30'):
         version = '3.30'
     else:
         version = '3.0'
         instance = jsonutils.to_primitive(instance)
     cctxt = self.client.prepare(server=host, version=version)
     return cctxt.call(ctxt, 'remove_volume_connection',
                       instance=instance, volume_id=volume_id)
Ejemplo n.º 32
0
 def instance_get_all_by_host(self, context, host, node,
                              columns_to_join):
     if node is not None:
         result = self.db.instance_get_all_by_host_and_node(
             context.elevated(), host, node)
     else:
         result = self.db.instance_get_all_by_host(context.elevated(), host,
                                                   columns_to_join)
     return jsonutils.to_primitive(result)
Ejemplo n.º 33
0
 def notify_usage_exists(self, context, instance, current_period=False,
                         ignore_missing_network_data=True,
                         system_metadata=None, extra_usage_info=None):
     if self.client.can_send_version('2.1'):
         version = '2.1'
     else:
         version = '2.0'
         instance = jsonutils.to_primitive(instance)
     system_metadata_p = jsonutils.to_primitive(system_metadata)
     extra_usage_info_p = jsonutils.to_primitive(extra_usage_info)
     cctxt = self.client.prepare(version=version)
     return cctxt.call(
         context, 'notify_usage_exists',
         instance=instance,
         current_period=current_period,
         ignore_missing_network_data=ignore_missing_network_data,
         system_metadata=system_metadata_p,
         extra_usage_info=extra_usage_info_p)
Ejemplo n.º 34
0
 def setUp(self):
     super(ComputeRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     instance_attr = {'host': 'fake_host', 'instance_type_id': 1}
     self.fake_instance_obj = fake_instance_obj(self.context,
                                                **instance_attr)
     self.fake_instance = jsonutils.to_primitive(self.fake_instance_obj)
     self.fake_volume_bdm = jsonutils.to_primitive(
         fake_block_device.FakeDbBlockDeviceDict({
             'source_type':
             'volume',
             'destination_type':
             'volume',
             'instance_uuid':
             self.fake_instance['uuid'],
             'volume_id':
             'fake-volume-id'
         }))
Ejemplo n.º 35
0
 def manage_existing(self, ctxt, topic, volume_id,
                     request_spec=None, filter_properties=None):
     cctxt = self.client.prepare(version='1.5')
     request_spec_p = jsonutils.to_primitive(request_spec)
     return cctxt.cast(ctxt, 'manage_existing',
                       topic=topic,
                       volume_id=volume_id,
                       request_spec=request_spec_p,
                       filter_properties=filter_properties)
Ejemplo n.º 36
0
 def resize_instance(self, ctxt, instance, extra_instance_updates,
                    scheduler_hint, flavor, reservations):
     if not CONF.cells.enable:
         return
     flavor_p = jsonutils.to_primitive(flavor)
     cctxt = self.client.prepare(version='1.20')
     cctxt.cast(ctxt, 'resize_instance',
                instance=instance, flavor=flavor_p,
                extra_instance_updates=extra_instance_updates)
Ejemplo n.º 37
0
 def block_device_mapping_get_all_by_instance(self,
                                              context,
                                              instance,
                                              legacy=True):
     instance_p = jsonutils.to_primitive(instance)
     cctxt = self.client.prepare()
     return cctxt.call(context,
                       'block_device_mapping_get_all_by_instance',
                       instance=instance_p,
                       legacy=legacy)
Ejemplo n.º 38
0
 def detach_volume(self, ctxt, instance, volume_id):
     if self.client.can_send_version('3.25'):
         version = '3.25'
     else:
         version = '3.0'
         instance = jsonutils.to_primitive(instance)
     cctxt = self.client.prepare(server=_compute_host(None, instance),
             version=version)
     cctxt.cast(ctxt, 'detach_volume',
                instance=instance, volume_id=volume_id)
Ejemplo n.º 39
0
    def select_destinations(self, context, request_spec, filter_properties):
        """Returns destinations(s) best suited for this request_spec and
        filter_properties.

        The result should be a list of dicts with 'host', 'nodename' and
        'limits' as keys.
        """
        dests = self.driver.select_destinations(context, request_spec,
                                                filter_properties)
        return jsonutils.to_primitive(dests)
Ejemplo n.º 40
0
 def get_console_output(self, ctxt, instance, tail_length):
     if self.client.can_send_version('3.28'):
         version = '3.28'
     else:
         version = '3.0'
         instance = jsonutils.to_primitive(instance)
     cctxt = self.client.prepare(server=_compute_host(None, instance),
             version=version)
     return cctxt.call(ctxt, 'get_console_output',
                       instance=instance, tail_length=tail_length)
Ejemplo n.º 41
0
 def instance_get_all_by_filters(self, context, filters, sort_key, sort_dir,
                                 columns_to_join, use_slave):
     result = self.db.instance_get_all_by_filters(
         context,
         filters,
         sort_key,
         sort_dir,
         columns_to_join=columns_to_join,
         use_slave=use_slave)
     return jsonutils.to_primitive(result)
Ejemplo n.º 42
0
 def bw_usage_update(self, context, uuid, mac, start_period,
                     bw_in, bw_out, last_ctr_in, last_ctr_out,
                     last_refreshed, update_cells):
     if [bw_in, bw_out, last_ctr_in, last_ctr_out].count(None) != 4:
         self.db.bw_usage_update(context, uuid, mac, start_period,
                                 bw_in, bw_out, last_ctr_in, last_ctr_out,
                                 last_refreshed,
                                 update_cells=update_cells)
     usage = self.db.bw_usage_get(context, uuid, start_period, mac)
     return jsonutils.to_primitive(usage)
Ejemplo n.º 43
0
 def live_migration(self, ctxt, instance, dest, block_migration, host,
                    migrate_data=None):
     if self.client.can_send_version('3.26'):
         version = '3.26'
     else:
         version = '3.0'
         instance = jsonutils.to_primitive(instance)
     cctxt = self.client.prepare(server=host, version=version)
     cctxt.cast(ctxt, 'live_migration', instance=instance,
                dest=dest, block_migration=block_migration,
                migrate_data=migrate_data)
Ejemplo n.º 44
0
 def vol_usage_update(self, context, vol_id, rd_req, rd_bytes, wr_req,
                      wr_bytes, instance, last_refreshed=None,
                      update_totals=False):
     instance_p = jsonutils.to_primitive(instance)
     cctxt = self.client.prepare()
     return cctxt.call(context, 'vol_usage_update',
                       vol_id=vol_id, rd_req=rd_req,
                       rd_bytes=rd_bytes, wr_req=wr_req,
                       wr_bytes=wr_bytes,
                       instance=instance_p, last_refreshed=last_refreshed,
                       update_totals=update_totals)
Ejemplo n.º 45
0
 def prep_resize(self, ctxt, image, instance, instance_type, host,
                 reservations=None, request_spec=None,
                 filter_properties=None, node=None,
                 clean_shutdown=True):
     instance_type_p = jsonutils.to_primitive(instance_type)
     image_p = jsonutils.to_primitive(image)
     msg_args = {'instance': instance,
                 'instance_type': instance_type_p,
                 'image': image_p,
                 'reservations': reservations,
                 'request_spec': request_spec,
                 'filter_properties': filter_properties,
                 'node': node,
                 'clean_shutdown': clean_shutdown}
     version = '3.38'
     if not self.client.can_send_version(version):
         del msg_args['clean_shutdown']
         version = '3.0'
     cctxt = self.client.prepare(server=host, version=version)
     cctxt.cast(ctxt, 'prep_resize', **msg_args)
Ejemplo n.º 46
0
 def check_instance_shared_storage(self, ctxt, instance, data):
     if self.client.can_send_version('3.29'):
         version = '3.29'
     else:
         version = '3.0'
         instance = jsonutils.to_primitive(instance)
     cctxt = self.client.prepare(server=_compute_host(None, instance),
             version=version)
     return cctxt.call(ctxt, 'check_instance_shared_storage',
                       instance=instance,
                       data=data)
 def test_numa_topology_filter_numa_host_no_numa_instance_pass(self):
     instance = fake_instance.fake_instance_obj(mock.sentinel.ctx)
     instance.numa_topology = None
     filter_properties = {
         'request_spec': {
             'instance_properties':
             jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
         }
     }
     host = fakes.FakeHostState('host1', 'node1',
                                {'numa_topology': fakes.NUMA_TOPOLOGY})
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
    def test_iteritems(self):
        class IterItemsClass(object):
            def __init__(self):
                self.data = dict(a=1, b=2, c=3).items()
                self.index = 0

            def iteritems(self):
                return self.data

        x = IterItemsClass()
        p = jsonutils.to_primitive(x)
        self.assertEqual(p, {'a': 1, 'b': 2, 'c': 3})
Ejemplo n.º 49
0
 def build_instances(self, ctxt, **kwargs):
     """Build instances."""
     build_inst_kwargs = kwargs
     instances = build_inst_kwargs['instances']
     build_inst_kwargs['image'] = jsonutils.to_primitive(
             build_inst_kwargs['image'])
     version = '1.32'
     if not self.client.can_send_version('1.32'):
         instances_p = [jsonutils.to_primitive(inst) for inst in instances]
         build_inst_kwargs['instances'] = instances_p
         version = '1.30'
     if not self.client.can_send_version('1.30'):
         if 'filter_properties' in build_inst_kwargs:
             filter_properties = build_inst_kwargs['filter_properties']
             flavor = filter_properties['instance_type']
             flavor_p = objects_base.obj_to_primitive(flavor)
             filter_properties['instance_type'] = flavor_p
         version = '1.8'
     cctxt = self.client.prepare(version=version)
     cctxt.cast(ctxt, 'build_instances',
                build_inst_kwargs=build_inst_kwargs)
Ejemplo n.º 50
0
 def create_share(self, ctxt, share, host,
                  request_spec, filter_properties,
                  snapshot_id=None):
     cctxt = self.client.prepare(server=host, version='1.0')
     request_spec_p = jsonutils.to_primitive(request_spec)
     cctxt.cast(
         ctxt,
         'create_share',
         share_id=share['id'],
         request_spec=request_spec_p,
         filter_properties=filter_properties,
         snapshot_id=snapshot_id,
     )
Ejemplo n.º 51
0
    def create_volume(self, ctxt, topic, volume_id, snapshot_id=None,
                      image_id=None, request_spec=None,
                      filter_properties=None):

        cctxt = self.client.prepare(version='1.2')
        request_spec_p = jsonutils.to_primitive(request_spec)
        return cctxt.cast(ctxt, 'create_volume',
                          topic=topic,
                          volume_id=volume_id,
                          snapshot_id=snapshot_id,
                          image_id=image_id,
                          request_spec=request_spec_p,
                          filter_properties=filter_properties)
Ejemplo n.º 52
0
    def migrate_volume_to_host(self, ctxt, topic, volume_id, host,
                               force_host_copy=False, request_spec=None,
                               filter_properties=None):

        cctxt = self.client.prepare(version='1.3')
        request_spec_p = jsonutils.to_primitive(request_spec)
        return cctxt.cast(ctxt, 'migrate_volume_to_host',
                          topic=topic,
                          volume_id=volume_id,
                          host=host,
                          force_host_copy=force_host_copy,
                          request_spec=request_spec_p,
                          filter_properties=filter_properties)
Ejemplo n.º 53
0
 def test_numa_topology_filter_numa_host_no_numa_instance_pass(self):
     instance = fake_instance.fake_instance_obj(self.context)
     instance.numa_topology = None
     filter_properties = {
         'request_spec': {
             'instance_properties':
             jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
         }
     }
     host = fakes.FakeHostState('host1', 'node1',
                                {'numa_topology': fakes.NUMA_TOPOLOGY})
     filt_cls = self.class_map['NUMATopologyFilter']()
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
Ejemplo n.º 54
0
 def resize_instance(self, ctxt, instance, migration, image, instance_type,
                     reservations=None, clean_shutdown=True):
     instance_type_p = jsonutils.to_primitive(instance_type)
     msg_args = {'instance': instance, 'migration': migration,
                 'image': image, 'reservations': reservations,
                 'instance_type': instance_type_p}
     if self.client.can_send_version('3.37'):
         version = '3.37'
         msg_args['clean_shutdown'] = clean_shutdown
     else:
         version = '3.0'
     cctxt = self.client.prepare(server=_compute_host(None, instance),
             version=version)
     cctxt.cast(ctxt, 'resize_instance', **msg_args)
 def test_nasties(self):
     def foo():
         pass
     x = [datetime, foo, dir]
     ret = jsonutils.to_primitive(x)
     self.assertEqual(len(ret), 3)
     self.assertTrue(ret[0].startswith(u"<module 'datetime' from "))
     if six.PY3:
         self.assertTrue(ret[1].startswith(
             '<function ToPrimitiveTestCase.test_nasties.<locals>.foo at 0x'
         ))
     else:
         self.assertTrue(ret[1].startswith('<function foo at 0x'))
     self.assertEqual(ret[2], '<built-in function dir>')
Ejemplo n.º 56
0
 def prep_resize(self,
                 ctxt,
                 image,
                 instance,
                 instance_type,
                 host,
                 reservations=None,
                 request_spec=None,
                 filter_properties=None,
                 node=None):
     version = '3.0'
     instance_type_p = jsonutils.to_primitive(instance_type)
     image_p = jsonutils.to_primitive(image)
     cctxt = self.client.prepare(server=host, version=version)
     cctxt.cast(ctxt,
                'prep_resize',
                instance=instance,
                instance_type=instance_type_p,
                image=image_p,
                reservations=reservations,
                request_spec=request_spec,
                filter_properties=filter_properties,
                node=node)
Ejemplo n.º 57
0
    def setUp(self):
        super(VolumeRpcAPITestCase, self).setUp()
        self.context = context.get_admin_context()
        vol = {}
        vol['host'] = 'fake_host'
        vol['availability_zone'] = CONF.storage_availability_zone
        vol['status'] = "available"
        vol['attach_status'] = "detached"
        vol['metadata'] = {"test_key": "test_val"}
        volume = db.volume_create(self.context, vol)

        snpshot = {
            'volume_id': 'fake_id',
            'status': "creating",
            'progress': '0%',
            'volume_size': 0,
            'display_name': 'fake_name',
            'display_description': 'fake_description'}
        snapshot = db.snapshot_create(self.context, snpshot)
        self.fake_volume = jsonutils.to_primitive(volume)
        self.fake_volume_metadata = volume["volume_metadata"]
        self.fake_snapshot = jsonutils.to_primitive(snapshot)
        self.fake_reservations = ["RESERVATION"]
Ejemplo n.º 58
0
    def create_consistencygroup(self, ctxt, topic, group_id,
                                request_spec_list=None,
                                filter_properties_list=None):

        cctxt = self.client.prepare(version='1.6')
        request_spec_p_list = []
        for request_spec in request_spec_list:
            request_spec_p = jsonutils.to_primitive(request_spec)
            request_spec_p_list.append(request_spec_p)

        return cctxt.cast(ctxt, 'create_consistencygroup',
                          topic=topic,
                          group_id=group_id,
                          request_spec_list=request_spec_p_list,
                          filter_properties_list=filter_properties_list)
Ejemplo n.º 59
0
    def instance_update(self, context, instance_uuid,
                        updates, service):
        for key, value in updates.iteritems():
            if key not in allowed_updates:
                LOG.error(_("Instance update attempted for "
                            "'%(key)s' on %(instance_uuid)s"),
                          {'key': key, 'instance_uuid': instance_uuid})
                raise KeyError("unexpected update keyword '%s'" % key)
            if key in datetime_fields and isinstance(value, six.string_types):
                updates[key] = timeutils.parse_strtime(value)

        old_ref, instance_ref = self.db.instance_update_and_get_original(
            context, instance_uuid, updates)
        notifications.send_update(context, old_ref, instance_ref, service)
        return jsonutils.to_primitive(instance_ref)
Ejemplo n.º 60
0
 def instance_delete_everywhere(self, ctxt, instance, delete_type):
     """Delete instance everywhere.  delete_type may be 'soft_delete'
     or 'delete'.  This is generally only used to resolve races
     when API cell doesn't know to what cell an instance belongs.
     """
     if not CONF.cells.enable:
         return
     if self.client.can_send_version('1.27'):
         version = '1.27'
     else:
         version = '1.0'
         instance = jsonutils.to_primitive(instance)
     cctxt = self.client.prepare(version=version)
     cctxt.cast(ctxt, 'instance_delete_everywhere', instance=instance,
             delete_type=delete_type)