示例#1
0
    def get_resource(self, key, extras):
        """
        Retrieve a single resource.
        """
        context = extras['nova_ctx']
        iden = key[key.rfind('/') + 1:]

        vms = vm.get_vms(context)
        vm_res_ids = [item['uuid'] for item in vms]
        stors = storage.get_storage_volumes(context)
        stor_res_ids = [item['id'] for item in stors]

        if (key, context.user_id) in self.cache:
            # I have seen it - need to update or delete if gone in OS!
            # I have already seen it
            cached_item = self.cache[(key, context.user_id)]
            if not iden in vm_res_ids and cached_item.kind == \
                    infrastructure.COMPUTE:
                # it was delete in OS -> remove links, cache + KeyError!
                # can delete it because it was my item!
                for link in cached_item.links:
                    self.cache.pop((link.identifier, repr(extras)))
                self.cache.pop((key, repr(extras)))
                raise KeyError
            if not iden in stor_res_ids and cached_item.kind == \
                    infrastructure.STORAGE:
                # it was delete in OS -> remove from cache + KeyError!
                # can delete it because it was my item!
                self.cache.pop((key, repr(extras)))
                raise KeyError
            elif iden in vm_res_ids:
                # it also exists in OS -> update it (take links, mixins
                # from cached one)
                result = self._update_occi_compute(cached_item, extras)
            elif iden in stor_res_ids:
                # it also exists in OS -> update it!
                result = self._update_occi_storage(cached_item, extras)
            else:
                # return cached item (links)
                return cached_item
        elif (key, None) in self.cache:
            # return shared entities from cache!
            return self.cache[(key, None)]
        else:
            # construct it.
            if iden in vm_res_ids:
                # create new & add to cache!
                result = self._construct_occi_compute(iden, extras)[0]
            elif iden in stor_res_ids:
                result = self._construct_occi_storage(iden, extras)[0]
            else:
                # doesn't exist!
                raise KeyError

        if result.identifier != key:
            raise AttributeError('Key/identifier mismatch! Requested: ' +
                                 key + ' Got: ' + result.identifier)
        return result
示例#2
0
    def get_resource(self, key, extras):
        """
        Retrieve a single resource.
        """
        context = extras['nova_ctx']
        iden = key[key.rfind('/') + 1:]

        vms = vm.get_vms(context)
        vm_res_ids = [item['uuid'] for item in vms]
        stors = storage.get_storage_volumes(context)
        stor_res_ids = [item['id'] for item in stors]

        if (key, context.user_id) in self.cache:
            # I have seen it - need to update or delete if gone in OS!
            # I have already seen it
            cached_item = self.cache[(key, context.user_id)]
            if not iden in vm_res_ids and cached_item.kind == \
                    infrastructure.COMPUTE:
                # it was delete in OS -> remove links, cache + KeyError!
                # can delete it because it was my item!
                for link in cached_item.links:
                    self.cache.pop((link.identifier, repr(extras)))
                self.cache.pop((key, repr(extras)))
                raise KeyError
            if not iden in stor_res_ids and cached_item.kind == \
                    infrastructure.STORAGE:
                # it was delete in OS -> remove from cache + KeyError!
                # can delete it because it was my item!
                self.cache.pop((key, repr(extras)))
                raise KeyError
            elif iden in vm_res_ids:
                # it also exists in OS -> update it (take links, mixins
                # from cached one)
                result = self._update_occi_compute(cached_item, extras)
            elif iden in stor_res_ids:
                # it also exists in OS -> update it!
                result = self._update_occi_storage(cached_item, extras)
            else:
                # return cached item (links)
                return cached_item
        elif (key, None) in self.cache:
            # return shared entities from cache!
            return self.cache[(key, None)]
        else:
            # construct it.
            if iden in vm_res_ids:
                # create new & add to cache!
                result = self._construct_occi_compute(iden, extras)[0]
            elif iden in stor_res_ids:
                result = self._construct_occi_storage(iden, extras)[0]
            else:
                # doesn't exist!
                raise KeyError

        if result.identifier != key:
            raise AttributeError('Key/identifier mismatch! Requested: ' + key +
                                 ' Got: ' + result.identifier)
        return result
示例#3
0
    def get_resources(self, extras):
        """
        Retrieve a set of resources.
        """
        # TODO: add security rules!
        context = extras['nova_ctx']
        result = []

        # VMs
        vms = vm.get_vms(context)
        for instance in vms:
            occi_compute = self._construct_occi_compute(instance, extras)
            result.append(occi_compute)
            result.extend(occi_compute.links)
        # Volumes
        stors = storage.get_storage_volumes(context)
        for stor in stors:
            occi_storage = self._construct_occi_storage(stor, extras)
            result.append(occi_storage)
            result.extend(occi_storage.links)
        # Networks, XXX not sure if I need to return this
        result.extend(self.nets.values())
        return result
示例#4
0
    def get_resources(self, extras):
        """
        Retrieve a set of resources.
        """

        # TODO: add security rules!

        context = extras['nova_ctx']
        result = []

        vms = vm.get_vms(context)
        vm_res_ids = [item['uuid'] for item in vms]

        stors = storage.get_storage_volumes(context)
        stor_res_ids = [item['id'] for item in stors]

        for item in self.cache.values():
            if item.extras is not None and item.extras['user_id'] != \
                    context.user_id:
                # filter out items not belonging to this user!
                continue
            item_id = item.identifier[item.identifier.rfind('/') + 1:]
            if item.extras is None:
                # add to result set
                result.append(item)
            elif item_id in vm_res_ids and item.kind == \
                    infrastructure.COMPUTE:
                # check & update (take links, mixins from cache)
                # add compute and it's links to result
                self._update_occi_compute(item, extras)
                result.append(item)
                result.extend(item.links)
            elif item_id in stor_res_ids and item.kind == \
                    infrastructure.STORAGE:
                # check & update (take links, mixins from cache)
                # add compute and it's links to result
                self._update_occi_storage(item, extras)
                result.append(item)
            elif item_id not in vm_res_ids and item.kind == \
                    infrastructure.COMPUTE:
                # remove item and it's links from cache!
                for link in item.links:
                    self.cache.pop((link.identifier, item.extras['user_id']))
                self.cache.pop((item.identifier, item.extras['user_id']))
            elif item_id not in stor_res_ids and item.kind == \
                    infrastructure.STORAGE:
                # remove item
                self.cache.pop((item.identifier, item.extras['user_id']))
        for item in vms:
            if (infrastructure.COMPUTE.location + item['uuid'],
                    context.user_id) in self.cache:
                continue
            else:
                # construct (with links and mixins and add to cache!
                # add compute and it's linke to result
                ent_list = self._construct_occi_compute(item['uuid'], extras)
                result.extend(ent_list)
        for item in stors:
            if (infrastructure.STORAGE.location + item['id'],
                    context.user_id) in self.cache:
                continue
            else:
                # construct (with links and mixins and add to cache!
                # add compute and it's linke to result
                ent_list = self._construct_occi_storage(item['id'], extras)
                result.extend(ent_list)

        return result
示例#5
0
    def get_resources(self, extras):
        """
        Retrieve a set of resources.
        """

        # TODO: add security rules!

        context = extras['nova_ctx']
        result = []

        vms = vm.get_vms(context)
        vm_res_ids = [item['uuid'] for item in vms]

        stors = storage.get_storage_volumes(context)
        stor_res_ids = [item['id'] for item in stors]

        for item in self.cache.values():
            if item.extras is not None and item.extras['user_id'] != \
                    context.user_id:
                # filter out items not belonging to this user!
                continue
            item_id = item.identifier[item.identifier.rfind('/') + 1:]
            if item.extras is None:
                # add to result set
                result.append(item)
            elif item_id in vm_res_ids and item.kind == \
                    infrastructure.COMPUTE:
                # check & update (take links, mixins from cache)
                # add compute and it's links to result
                self._update_occi_compute(item, extras)
                result.append(item)
                result.extend(item.links)
            elif item_id in stor_res_ids and item.kind == \
                    infrastructure.STORAGE:
                # check & update (take links, mixins from cache)
                # add compute and it's links to result
                self._update_occi_storage(item, extras)
                result.append(item)
            elif item_id not in vm_res_ids and item.kind == \
                    infrastructure.COMPUTE:
                # remove item and it's links from cache!
                for link in item.links:
                    self.cache.pop((link.identifier, item.extras['user_id']))
                self.cache.pop((item.identifier, item.extras['user_id']))
            elif item_id not in stor_res_ids and item.kind == \
                    infrastructure.STORAGE:
                # remove item
                self.cache.pop((item.identifier, item.extras['user_id']))
        for item in vms:
            if (infrastructure.COMPUTE.location + item['uuid'],
                    context.user_id) in self.cache:
                continue
            else:
                # construct (with links and mixins and add to cache!
                # add compute and it's linke to result
                ent_list = self._construct_occi_compute(item['uuid'], extras)
                result.extend(ent_list)
        for item in stors:
            if (infrastructure.STORAGE.location + item['id'],
                    context.user_id) in self.cache:
                continue
            else:
                # construct (with links and mixins and add to cache!
                # add compute and it's linke to result
                ent_list = self._construct_occi_storage(item['id'], extras)
                result.extend(ent_list)

        return result