Ejemplo n.º 1
0
def create_vms_list(vmdict):
    # Takes in a "vmdict" and converts it into a list of JSON objects representing ganeti nodes.
    vms_list = []
    i = 0
    for instance in sorted(vmdict.keys()):
        pnode = vmdict[instance][0]
        snode = vmdict[instance][1]
        i+=1
        vm_obj = {}
        vm_obj["status"] = weighted_pick(vm_status_possibilities)
        vm_obj["hostname"] =  instance
        vm_obj["secondary_node__hostname"] = snode
        vm_obj["operating_system"] = "image+cirros"
        vm_obj["owner"] = 'Pranjal'
        vm_obj["primary_node__hostname"] = pnode
        vms_list.append(vm_obj)  
    return vms_list
Ejemplo n.º 2
0
    def draw_card(self):
        """
        Returns next card (just the cue is returned)
        card[cue] can be used to get the target
        """
        tdist = self.get_tdist()

        #E_recall = get_expectation_of_recall(telapsed, self.strength)  # This dict indicates relative strength of recall of each card
                                                                    # Note: recall relative strength is different from strength
                                                                    # It also depends on number of seconds elapsed since card was last shown
        
        #E_notrecall = complementary_dict(E_recall)                  # Relative strength of not-recalling a word

        self.draw_dist = weighted_combination([self.wdist_weight, self.tdist_weight], [self.weakness, tdist])
        #self.draw_dist = self.weakness

        # Draw a card from the distribution
        cue = weighted_pick(self.draw_dist)               # Draw distribution should be updated as per the new times just before drawing a new card
        self.last_draw_timestamp[cue] = datetime.now()    # Update last shown time of card drawn to current time

        self.ncards_drawn += 1
        return cue
def vms_json(vmdict):
    # Takes in a "vmdict" and converts it into a list of JSON objects representing ganeti nodes.
    vms_list = []
    i = 0
    for instance in sorted(vmdict.keys()):
        pnode = vmdict[instance][0]
        snode = vmdict[instance][1]
        i+=1
        vm_obj = {}
        vm_obj["pk"] = i
        vm_obj["model"] =  "ganeti_web.virtualmachine"
        vm_obj["fields"] = {
                            "status": weighted_pick(vm_status_possibilities),
                            "ram": 128,
                            "hostname": instance,
                            "secondary_node": snode,
                            "operating_system": "image+cirros",
                            "owner": 'Pranjal',
                            "minram": -1,
                            "primary_node": pnode
                           }
        vms_list.append(vm_obj)  
    return dumps(vms_list)