Example #1
0
    def get(self, *args, **kwargs):    
        """
        List all instances
        """
        (args, token) = (self.params.get, kwargs.get('token'))

        instances = Instance.select()

        if args['state']:
            instances = instances.where(Instance.state == 
                                INSTANCE_STATES[args['state']])
        if not args['all']:
            instances = instances.where(
                Instance.token == kwargs.get('token'))

        m_instances = []
        for instance in instances:
            resource_filters = args.get('resource_filter', None)
            if resource_filters:
                if instance.has_resources(resource_filters) == True:
                    m_instances.append(instance)
            else:
                m_instances.append(instance)

        m_instances = map(lambda i: i.hydrate(marshal, 
                                              self.params.fields, 
                                              self.params.resource.fields), 
                                              m_instances)
        instances = {
           'count' : len(m_instances),
           'instances': m_instances
        }

        return instances
Example #2
0
    def get(self, public_key):
        """
           List all instances
        """
        instances = Instance.select().where(
            Instance.public_key == public_key)

        if self.params.get['state'] is not None:
            instances = instances.where(
            Instance.state == self.params.get['state'])

        m_instances = []
        for instance in instances:
            resource_filters = self.params.get.get('resource_filter', None)
            if resource_filters:
                if instance.has_resources(resource_filters):
                    m_instances.append(instance)
            else:
                m_instances.append(instance)

        m_instances = map(lambda i: i.hydrate(marshal,
                          self.params.fields,
                          self.params.resource.fields),
                          m_instances)

        return marshal_and_count('instances', m_instances)