(self, request, tenant_id)
return json.dumps({
            'values': [{'agent_id': entity.agent_id,
                        'entity_id': entity_id,
                        'entity_uri': entity.uri,
                        'host_info': agent.get_host_info(
                            maas_store.host_info_types,
                            [arg.decode('utf-8')
                             for arg in request.args[b'include']],
                            entity_id,
                            self._session_store.clock)}],
            'metadata': {'count': 1,
                         'limit': 100,
                         'marker': None,
                         'next_marker': None,
                         'next_href': None}})
Mocks the /views/agent_host_info API call.
Mocks the /views/agent_host_info API call.
Mocks the / views / agent_host_info API call .
def view_agent_host_info(self, request, tenant_id):
        """
        Mocks the /views/agent_host_info API call.
        """
        entities = self._entity_cache_for_tenant(tenant_id).entities
        maas_store = self._entity_cache_for_tenant(tenant_id).maas_store

        if b'include' not in request.args:
            request.setResponseCode(400)
            return json.dumps({'type': 'badRequest',
                               'code': 400,
                               'message': 'Validation error for key \'include\'',
                               'details': 'Must include at least one HOST_INFO_TYPE.',
                               'txnId': ('.fake.mimic.transaction.id.c-1111111'
                                          '.ts-123444444.v-12344frf')})

        if b'entityId' not in request.args:
            request.setResponseCode(400)
            return json.dumps({'type': 'badRequest',
                               'code': 400,
                               'message': 'Validation error for key \'agentId, entityId, uri\'',
                               'details': 'You must specify an agentId, entityId, or an entity URI.',
                               'mimicNotes': 'But mimic will only accept entityId right now',
                               'txnId': ('.fake.mimic.transaction.id.c-1111111'
                                         '.ts-123444444.v-12344frf')})

        entity_id = request.args[b'entityId'][0].strip().decode("utf-8")
        entity = None

        try:
            entity = _get_entity(entities, entity_id)
        except ObjectDoesNotExist as e:
            request.setResponseCode(e.code)
            return json.dumps(e.to_json())

        if entity.agent_id is None:
            request.setResponseCode(400)
            return json.dumps({'type': 'agentDoesNotExist',
                               'code': 400,
                               'message': 'Agent does not exist',
                               'details': 'Agent null does not exist',
                               'txnId': ('.fake.mimic.transaction.id.c-1111111.'
                                         'ts-123444444.v-12344frf')})

        try:
            agent = maas_store.agents[entity.agent_id]
        except KeyError:
            request.setResponseCode(400)
            return json.dumps({'type': 'agentDoesNotExist',
                               'code': 400,
                               'message': 'Agent does not exist',
                               'details': 'Agent {0} does not exist'.format(entity.agent_id),
                               'txnId': ('.fake.mimic.transaction.id.c-1111111.'
                                         'ts-123444444.v-12344frf')})

        request.setResponseCode(200)
        return json.dumps({
            'values': [{'agent_id': entity.agent_id,
                        'entity_id': entity_id,
                        'entity_uri': entity.uri,
                        'host_info': agent.get_host_info(
                            maas_store.host_info_types,
                            [arg.decode('utf-8')
                             for arg in request.args[b'include']],
                            entity_id,
                            self._session_store.clock)}],
            'metadata': {'count': 1,
                         'limit': 100,
                         'marker': None,
                         'next_marker': None,
                         'next_href': None}})
def view_agent_host_info ( self , request , tenant_id ) : entities = self . _entity_cache_for_tenant ( tenant_id ) . entities maas_store = self . _entity_cache_for_tenant ( tenant_id ) . maas_store if b'include' not in request . args : request . setResponseCode ( 400 ) return json . dumps ( { 'type' : 'badRequest' , 'code' : 400 , 'message' : 'Validation error for key \'include\'' , 'details' : 'Must include at least one HOST_INFO_TYPE.' , 'txnId' : ( '.fake.mimic.transaction.id.c-1111111' '.ts-123444444.v-12344frf' ) } ) if b'entityId' not in request . args : request . setResponseCode ( 400 ) return json . dumps ( { 'type' : 'badRequest' , 'code' : 400 , 'message' : 'Validation error for key \'agentId, entityId, uri\'' , 'details' : 'You must specify an agentId, entityId, or an entity URI.' , 'mimicNotes' : 'But mimic will only accept entityId right now' , 'txnId' : ( '.fake.mimic.transaction.id.c-1111111' '.ts-123444444.v-12344frf' ) } ) entity_id = request . args [ b'entityId' ] [ 0 ] . strip ( ) . decode ( "utf-8" ) entity = None try : entity = _get_entity ( entities , entity_id ) except ObjectDoesNotExist as e : request . setResponseCode ( e . code ) return json . dumps ( e . to_json ( ) ) if entity . agent_id is None : request . setResponseCode ( 400 ) return json . dumps ( { 'type' : 'agentDoesNotExist' , 'code' : 400 , 'message' : 'Agent does not exist' , 'details' : 'Agent null does not exist' , 'txnId' : ( '.fake.mimic.transaction.id.c-1111111.' 'ts-123444444.v-12344frf' ) } ) try : agent = maas_store . agents [ entity . agent_id ] except KeyError : request . setResponseCode ( 400 ) return json . dumps ( { 'type' : 'agentDoesNotExist' , 'code' : 400 , 'message' : 'Agent does not exist' , 'details' : 'Agent {0} does not exist' . format ( entity . agent_id ) , 'txnId' : ( '.fake.mimic.transaction.id.c-1111111.' 'ts-123444444.v-12344frf' ) } ) request . setResponseCode ( 200 ) return json . dumps ( { 'values' : [ { 'agent_id' : entity . agent_id , 'entity_id' : entity_id , 'entity_uri' : entity . uri , 'host_info' : agent . get_host_info ( maas_store . host_info_types , [ arg . decode ( 'utf-8' ) for arg in request . args [ b'include' ] ] , entity_id , self . _session_store . clock ) } ] , 'metadata' : { 'count' : 1 , 'limit' : 100 , 'marker' : None , 'next_marker' : None , 'next_href' : None } } )