Example #1
0
    def delete(self, *args, **kwargs):
        """
        Receives a request for destroy a running/requested instance
        """
        (args, token) = (self.params.delete, kwargs.get('token'))        

        instances = Instance.update(state=INSTANCE_STATES['DELETED']).where(
            Instance.token == kwargs.get('token'))

        if args['state']:
            instances = instances.where(Instance.state == 
                                INSTANCE_STATES[args['state']])
        
        instance_ids = args.get('instance_ids', None)

        if instance_ids:
            instance_filters = []
            for instance_id in instance_ids:
                instance_filters.append(Instance.instance_id == instance_id)

            import operator
            instances = instances.where(reduce(operator.or_, 
                                               instance_filters))
        affected = instances.execute()
        return affected