當前位置: 首頁>>代碼示例>>Python>>正文


Python Schedule.add_entry_host方法代碼示例

本文整理匯總了Python中schedule.Schedule.add_entry_host方法的典型用法代碼示例。如果您正苦於以下問題:Python Schedule.add_entry_host方法的具體用法?Python Schedule.add_entry_host怎麽用?Python Schedule.add_entry_host使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在schedule.Schedule的用法示例。


在下文中一共展示了Schedule.add_entry_host方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Provisioner

# 需要導入模塊: from schedule import Schedule [as 別名]
# 或者: from schedule.Schedule import add_entry_host [as 別名]
class Provisioner():
    def __init__(self, vm_limit, azure_config, skip_setup, local):
        self.vm_limit = vm_limit # user input
        self.budget = 0
        self.timestamp = datetime.now()
        self.cost_pred = 0
        self.wf_end = None
        
        self.jobs_terminated = False
        self.last_resched = None
        
        self.workflow = Workflow()
        self.logwatcher = LogWatcher()
        
        self.schedule = Schedule()
        
        manager = Machine()
        manager.status = MachineStatus.manager
        manager.condor_slot = 'manager'
        self.machines = [manager]
        
        boot_entry = ScheduleEntry(Job('boot', None), manager, self.timestamp, self.timestamp)
        boot_entry.real_start = self.timestamp
        boot_entry.real_end = self.timestamp
        boot_entry.status = EntryStatus.completed
        self.schedule.add_entry_host(boot_entry, manager)
        
        self.local = local
        if azure_config and not local:
            hostname = socket.gethostname()
            self.exp = AzureExperiment(azure_config, skip_setup=skip_setup, name=hostname)
            self.master_addr = socket.gethostbyname(hostname)
            self.user = azure_config.admin_username
        else:
            self.exp = self.master_addr = self.user = None
        
    def add_workflow(self, workflow_dir, prediction_file, budget):
        self.budget = self.budget + int(round(float(budget)))
        wf_id = self.workflow.add_workflow(workflow_dir, prediction_file=prediction_file)
        self.logwatcher.add(wf_id, workflow_dir)
            
    def update_schedule(self):
        print 'UPDATE SCHED'
        self.update_budget_timestamp()
        self.last_resched = self.timestamp 
    
        # completed and running entries will not change
        self.schedule.rm_scheduled_entries()

        if self.workflow.has_jobs_to_sched(self.schedule):
            # Max number of vms
            nmax = get_nmax(self.workflow, self.machines, self.schedule, self.vm_limit, self.timestamp, self.local)

            print 'NMAX',nmax
            
            # Get the number of machines to be used
            schedule, _cost, _n = sched_number_of_machines(self.workflow, self.machines, self.schedule, nmax, self.timestamp, self.budget, self.local)
            print "N", _n, 'budget', self.budget
            
            # Update schedule
            self.schedule = schedule

    def update_budget_timestamp(self):
        timestamp = datetime.now()
        if self.timestamp != None:
            # Supondo vm_cost em cost/second
            # Supondo que não houve mudança no número de máquinas
            # desde o ultimo self.timestamp
            delta = (timestamp - self.timestamp).seconds
            charged = delta * len(self.machines) * VM_COST_PER_SEC
            self.budget = self.budget - charged
        self.timestamp = timestamp
        
    def update_wf_pred(self):
        self.cost_pred, self.wf_end = sched_cost_pred(self.machines, self.schedule, self.timestamp)

    def allocate_new_vms(self):
        # boot entries
        if self.schedule != None:
            for m in self.schedule.entries_host.keys():
                entry = self.schedule.entries_host[m][0]
                if entry.status == EntryStatus.scheduled and entry.start() <= self.timestamp:
                    m.allocate(self.exp, self.master_addr, self.user)
                    
                    self.machines.append(m)
                    entry.status = EntryStatus.executing
                    entry.log[LogKey.real_start] = self.timestamp
        
    
    def deallocate_vms(self):
        for m in self.machines:
            if m.status == MachineStatus.manager:
                continue
            
            # if there's no more budget or
            # if there's nothing executing or scheduled to the machine
            if self.schedule == None or len([e for e in self.schedule.entries_host[m] if e.status != EntryStatus.completed]) == 0:
                m.deallocate(self.exp)
                print "--Machine", m.condor_slot
                
#.........這裏部分代碼省略.........
開發者ID:rika,項目名稱:dynamic-provisioning,代碼行數:103,代碼來源:provisioner.py


注:本文中的schedule.Schedule.add_entry_host方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。