예제 #1
0
파일: host_agent.py 프로젝트: f3at/feat
    def announced(self, state, announce):
        state.descriptor = announce.payload['descriptor']
        state.factory = applications.lookup_agent(state.descriptor.type_name)
        state.keep_allocated = False

        if not check_categories(state.agent, state.factory.categories):
            self._refuse()
            return

        resc = state.descriptor.extract_resources()
        agent_id = state.descriptor.doc_id
        partner = agent_id and state.agent.find_partner(agent_id)
        if partner and partner.allocation_id:
            cost = 0
            delta = state.agent.get_allocation_delta(
                partner.allocation_id, **resc)
            if delta:
                alloc = state.agent.premodify_allocation(
                    partner.allocation_id, **delta)
            else:
                alloc = state.agent.get_allocation(partner.allocation_id)
                state.keep_allocated = True
        else:
            cost = 10
            alloc = state.agent.preallocate_resource(**resc)

        if alloc is None:
            self._refuse()
            return

        state.alloc_id = alloc.id

        bid = message.Bid()
        bid.payload = dict(cost=cost)
        state.medium.bid(bid)
예제 #2
0
파일: host_agent.py 프로젝트: pepribas/F3AT
    def announced(self, state, announcement):
        categories = announcement.payload['categories']
        ret = check_categories(state.agent, categories)
        if state.agent.is_migrating():
            self._refuse("We are currently migrating.")
            return

        if not ret:
            self._refuse("Categories doesn't match")
            return

        resources = announcement.payload['resources']
        try:
            preallocation = state.agent.preallocate_resource(**resources)
        except resource.UnknownResource:
            self._refuse("Unknown resource! WTF?")
            return

        if preallocation is None:
            self._refuse("Not enough resource")
            return

        state.preallocation_id = preallocation.id
        # Create a bid
        bid = message.Bid()
        bid.payload['allocation_id'] = state.preallocation_id

        bid = self._get_cost(bid)
        state.medium.bid(bid)
예제 #3
0
파일: host_agent.py 프로젝트: f3at/feat
 def check_requirements(self, state, doc):
     agnt = applications.lookup_agent(doc.type_name)
     ret = check_categories(self, agnt.categories)
     if not ret:
         msg = "Categoryies doesn't match"
         self.error(msg)
         raise CategoryError(msg)
     return doc
예제 #4
0
파일: host_agent.py 프로젝트: pepribas/F3AT
 def check_requirements(self, state, doc):
     agnt = agent.registry_lookup(doc.document_type)
     ret = check_categories(self, agnt.categories)
     if not ret:
         msg = "Categoryies doesn't match"
         self.error(msg)
         raise CategoryError(msg)
     return doc
예제 #5
0
파일: host_agent.py 프로젝트: sylane/feat
    def announced(self, state, announcement):
        # refuse if we are migrating
        if state.agent.is_migrating():
            self._refuse("We are currently migrating.")
            return

        # check that categories match
        categories = announcement.payload['categories']
        ret = check_categories(state.agent, categories)
        if not ret:
            self._refuse("Categories doesn't match")
            return

        resources = announcement.payload['resources']

        # check if we are asked for the allocation
        # for the partner we are already hosting
        agent_id = announcement.payload['agent_id']
        partner = agent_id and state.agent.find_partner(agent_id)
        state.allocation_id = None
        if partner:
            delta = state.agent.get_allocation_delta(
                partner.allocation_id, **resources)
            if delta:
                try:
                    preallocation = state.agent.premodify_allocation(
                        partner.allocation_id, **delta)
                    cost = 0
                except resource.UnknownResource:
                    self._refuse("Unknown resource! WTF?")
                    return
            else:
                preallocation = None
                state.allocation_id = partner.allocation_id
                cost = 0
        else:
            try:
                preallocation = state.agent.preallocate_resource(**resources)
                cost = 10
            except resource.UnknownResource:
                self._refuse("Unknown resource! WTF?")
                return

        if preallocation is None and state.allocation_id is None:
            self._refuse("Not enough resource")
            return

        state.preallocation_id = preallocation and preallocation.id
        # Create a bid
        bid = message.Bid()
        bid.payload['cost'] = cost
        state.medium.bid(bid)
예제 #6
0
파일: host_agent.py 프로젝트: pepribas/F3AT
    def announced(self, state, announce):
        state.descriptor = announce.payload['descriptor']
        state.factory = agent.registry_lookup(state.descriptor.document_type)

        if state.agent.is_migrating():
            self._refuse()
            return

        if not check_categories(state.agent, state.factory.categories):
            self._refuse()
            return

        resc = state.descriptor.extract_resources()
        alloc = state.agent.preallocate_resource(**resc)

        if alloc is None:
            self._refuse()
            return

        state.alloc_id = alloc.id

        bid = message.Bid()
        state.medium.bid(bid)