def SelectRack(self, SelectRackReq): #ask pm resource #get current adding vm #run algorithm to pickup a placement #return correspond place def SelectNode(self, SelectNodeReq): #ask pm resource #get current adding vm #run algorithm to pickup a placement #return corresponding place def RackAlgorithm(self, req): vm_id = req.vm_id vm_cpu = req.cpu vm_mem = req.mem vm_disk = req.disk pm_resource_list = req.pm_resource_list # first-fit to scheduule VM on PM for pm in pm_resource_list: if vm_cpu <= pm['cpu'] and vm_mem <= pm['mem'] and vm_disk <= pm['disk']: print( 'put vm' + str(vm_id) + ' on ' + pm['hostname']) return pm['hostname'] return 'No host machine for VM' def sayHello(self): print ('Hello') if __name__ == '__main__': host, port, console_off = passArguments() mymachine = Algorithm( host, port ) mymachine.run(console_off)
self.normalSampleFunction, # It's a example to show how to add startup functions )) def periodlySampleFunction(self): interval = 30 # secs while True: #Doing something and periodly issue sleep(interval) def normalSampleFunction(self): #Doing something you want at server startup time pass def GetAvailableClusters(self, req): ret = None try: import imp tmp = imp.load_source('', self.config.get('CloudComponentsPath')).CloudCoordinator() ret = tmp.GetAvailableClusters(req, self.cfg) #ret = Message.RackHypervisorReqRt(status='Success', msg=req.id + '-' + req.owner) except Exception, e: #Error msg print str(e) return ret if __name__ == '__main__': host, port, console_off = passArguments() mymachine = Cloud(host, port) mymachine.run(console_off)