def obj_load_attr(self, attrname):
        if attrname not in INSTANCE_OPTIONAL_ATTRS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason='attribute %s not lazy-loadable' % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        LOG.debug(_("Lazy-loading `%(attr)s' on %(name)s uuid %(uuid)s"), {
            'attr': attrname,
            'name': self.obj_name(),
            'uuid': self.uuid,
        })
        # FIXME(comstud): This should be optimized to only load the attr.
        instance = self.__class__.get_by_uuid(self._context,
                                              uuid=self.uuid,
                                              expected_attrs=[attrname])

        # NOTE(danms): Never allow us to recursively-load
        if instance.obj_attr_is_set(attrname):
            self[attrname] = instance[attrname]
        else:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason='loading %s requires recursion' % attrname)
Beispiel #2
0
    def obj_load_attr(self, attrname):
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        LOG.debug("Lazy-loading '%(attr)s' on %(name)s id %(id)s", {
            'attr': attrname,
            'name': self.obj_name(),
            'id': self.id,
        })
        if attrname != 'compute_node':
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason='attribute %s not lazy-loadable' % attrname)
        if self.binary == 'nova-compute':
            # Only n-cpu services have attached compute_node(s)
            compute_nodes = objects.ComputeNodeList.get_all_by_host(
                self._context, self.host)
        else:
            # NOTE(sbauza); Previous behaviour was raising a ServiceNotFound,
            # we keep it for backwards compatibility
            raise exception.ServiceNotFound(service_id=self.id)
        # NOTE(sbauza): Some drivers (VMware, Ironic) can have multiple nodes
        # for the same service, but for keeping same behaviour, returning only
        # the first elem of the list
        self.compute_node = compute_nodes[0]
Beispiel #3
0
 def wrapper(self, *args, **kwargs):
     ctxt = self._context
     try:
         if isinstance(args[0], (context.RequestContext)):
             ctxt = args[0]
             args = args[1:]
     except IndexError:
         pass
     if ctxt is None:
         raise exception.OrphanedObjectError(method=fn.__name__,
                                             objtype=self.obj_name())
     # Force this to be set if it wasn't before.
     self._context = ctxt
     if NovaObject.indirection_api:
         updates, result = NovaObject.indirection_api.object_action(
             ctxt, self, fn.__name__, args, kwargs)
         for key, value in updates.iteritems():
             if key in self.fields:
                 field = self.fields[key]
                 # NOTE(ndipanov): Since NovaObjectSerializer will have
                 # deserialized any object fields into objects already,
                 # we do not try to deserialize them again here.
                 if isinstance(value, NovaObject):
                     self[key] = value
                 else:
                     self[key] = field.from_primitive(self, key, value)
         self.obj_reset_changes()
         self._changed_fields = set(updates.get('obj_what_changed', []))
         return result
     else:
         return fn(self, ctxt, *args, **kwargs)
Beispiel #4
0
    def obj_load_attr(self, attrname):
        if attrname not in INSTANCE_OPTIONAL_ATTRS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason='attribute %s not lazy-loadable' % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        LOG.debug("Lazy-loading `%(attr)s' on %(name)s uuid %(uuid)s", {
            'attr': attrname,
            'name': self.obj_name(),
            'uuid': self.uuid,
        })

        # NOTE(danms): We handle some fields differently here so that we
        # can be more efficient
        if attrname == 'fault':
            self._load_fault()
        elif attrname == 'numa_topology':
            self._load_numa_topology()
        elif attrname == 'pci_requests':
            self._load_pci_requests()
        else:
            # FIXME(comstud): This should be optimized to only load the attr.
            self._load_generic(attrname)
        self.obj_reset_changes([attrname])
Beispiel #5
0
Datei: base.py Projekt: mrda/nova
 def wrapper(self, *args, **kwargs):
     ctxt = self._context
     try:
         if isinstance(
                 args[0],
             (context.RequestContext, rpc_common.CommonRpcContext)):
             ctxt = args[0]
             args = args[1:]
     except IndexError:
         pass
     if ctxt is None:
         raise exception.OrphanedObjectError(method=fn.__name__,
                                             objtype=self.obj_name())
     # Force this to be set if it wasn't before.
     self._context = ctxt
     if NovaObject.indirection_api:
         updates, result = NovaObject.indirection_api.object_action(
             ctxt, self, fn.__name__, args, kwargs)
         for key, value in updates.iteritems():
             if key in self.fields:
                 field = self.fields[key]
                 self[key] = field.from_primitive(self, key, value)
         self._changed_fields = set(updates.get('obj_what_changed', []))
         return result
     else:
         return fn(self, ctxt, *args, **kwargs)
Beispiel #6
0
 def wrapper(self, *args, **kwargs):
     if args and isinstance(args[0], context.RequestContext):
         raise exception.ObjectActionError(
             action=fn.__name__,
             reason='Calling remotables with context is deprecated')
     if self._context is None:
         raise exception.OrphanedObjectError(method=fn.__name__,
                                             objtype=self.obj_name())
     if NovaObject.indirection_api:
         updates, result = NovaObject.indirection_api.object_action(
             self._context, self, fn.__name__, args, kwargs)
         for key, value in six.iteritems(updates):
             if key in self.fields:
                 field = self.fields[key]
                 # NOTE(ndipanov): Since NovaObjectSerializer will have
                 # deserialized any object fields into objects already,
                 # we do not try to deserialize them again here.
                 if isinstance(value, NovaObject):
                     setattr(self, key, value)
                 else:
                     setattr(self, key,
                             field.from_primitive(self, key, value))
         self.obj_reset_changes()
         self._changed_fields = set(updates.get('obj_what_changed', []))
         return result
     else:
         return fn(self, *args, **kwargs)
Beispiel #7
0
 def obj_load_attr(self, attrname):
     if attrname not in FLOATING_IP_OPTIONAL_ATTRS:
         raise exception.ObjectActionError(
             action='obj_load_attr',
             reason='attribute %s is not lazy-loadable' % attrname)
     if not self._context:
         raise exception.OrphanedObjectError(method='obj_load_attr',
                                             objtype=self.obj_name())
     self.fixed_ip = fixed_ip.FixedIP.get_by_id(self._context,
                                                self.fixed_ip_id,
                                                expected_attrs=['network'])
Beispiel #8
0
 def obj_load_attr(self, attrname):
     if not self._context:
         raise exception.OrphanedObjectError(method='obj_load_attr',
                                             objtype=self.obj_name())
     LOG.debug("Lazy-loading `%(attr)s' on %(name)s id %(id)s",
               {'attr': attrname,
                'name': self.obj_name(),
                'id': self.id,
                })
     if attrname != 'compute_node':
         raise exception.ObjectActionError(
             action='obj_load_attr',
             reason='attribute %s not lazy-loadable' % attrname)
     self.compute_node = objects.ComputeNode.get_by_service_id(
         self._context, self.id)
Beispiel #9
0
 def wrapper(self, context=None, **kwargs):
     if context is None:
         context = self._context
     if context is None:
         raise exception.OrphanedObjectError(method=fn.__name__,
                                             objtype=self.obj_name())
     if NovaObject.indirection_api:
         updates, result = NovaObject.indirection_api.object_action(
             context, self, fn.__name__, kwargs)
         for key, value in updates.iteritems():
             if key in self.fields:
                 self[key] = self._attr_from_primitive(key, value)
         self._changed_fields = set(updates.get('obj_what_changed', []))
         return result
     else:
         return fn(self, context, **kwargs)
Beispiel #10
0
    def obj_load_attr(self, attrname):
        if attrname not in BLOCK_DEVICE_OPTIONAL_ATTRS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason='attribute %s not lazy-loadable' % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        LOG.debug("Lazy-loading '%(attr)s' on %(name)s uuid %(uuid)s", {
            'attr': attrname,
            'name': self.obj_name(),
            'uuid': self.uuid,
        })
        self.instance = objects.Instance.get_by_uuid(self._context,
                                                     self.instance_uuid)
        self.obj_reset_changes(fields=['instance'])
Beispiel #11
0
    def obj_as_admin(self):
        """Context manager to make an object call as an admin.

        This temporarily modifies the context embedded in an object to
        be elevated() and restores it after the call completes. Example
        usage:

           with obj.obj_as_admin():
               obj.save()

        """
        if self._context is None:
            raise exception.OrphanedObjectError(method='obj_as_admin',
                                                objtype=self.obj_name())

        original_context = self._context
        self._context = self._context.elevated()
        try:
            yield
        finally:
            self._context = original_context