def remove_vm (vms): nova_server_create.terminate_vm(vms.index(len(vms)-1)) vms.pop(len(vms)-1) print "VM terminated" print "Number of VMs: %s" % len(vms)
#round robin should go to the next vm every time #otherwise it should use the first vm once then every other vm 3 times if round_robin: vm_cur_index = (vm_cur_index+1) % len(vms) else: if vm_cur_index == 0 or vm_cur_num_repeated >= 3: vm_cur_num_repeated = 0 vm_cur_index = (vm_cur_index+1) % len(vms) else: vm_cur_num_repeated += 1 return vms[vm_cur_index] if __name__ == '__main__': print "Instantiating a BaseHTTPServer" server_class = BaseHTTPServer.HTTPServer httpd = server_class ((HOST, PORT), MyHTTPHandler) add_vm(None,vm_array) try: print "Run a BaseHTTPServer" httpd.serve_forever () except KeyboardInterrupt: pass for server in vm_array: nova_server_create.terminate_vm(server) httpd.server_close ()