diff --git a/PythonScripts/exe/vmscript.rar b/PythonScripts/exe/vmscript.rar index 1030560..0def120 100644 Binary files a/PythonScripts/exe/vmscript.rar and b/PythonScripts/exe/vmscript.rar differ diff --git a/PythonScripts/vmfonctions.py b/PythonScripts/vmfonctions.py index ffae57e..b759cb7 100644 --- a/PythonScripts/vmfonctions.py +++ b/PythonScripts/vmfonctions.py @@ -1,7 +1,6 @@ import collections import json import virtualbox #pyvbox -import time vbox = virtualbox.VirtualBox() @@ -102,51 +101,4 @@ def infosvm(type): vm['caracteristiques'] = vmcar #On ajoute les caracteristique de la vm vmdata['vm_' + str(vmnb)] = vm #On ajoute toutes les infos de la vm numero x dans le dictionnaire correspondant vminfos['data'] = vmdata - return vminfos #Envoi des informations - - -def startvm(id): - idvm = id - vm = vbox.find_machine(idvm) - infos = collections.OrderedDict() - if str(vm.state) == 'FirstOnline': #Si la vm est lancee - infos['start_vm'] = 'false_vmalreadyonline' - elif str(vm.state) == 'PoweredOff': #Si la vm est a l'arret - if str(vm.session_state) == 'Locked': # Si la session est lock - infos['start_vm'] = 'false_sessionlocked' - elif str(vm.session_state) == 'Unlocked': #Si session debloque alors on lance la vm - session = virtualbox.Session() - vm.launch_vm_process(session, 'headless', '') #Pas d'affiche de l'ecran lors du demarrage - time.sleep(5) #Attente de cinq secondes - if str(vm.state) == 'FirstOnline': #On reverifie - infos['start_vm'] = 'true' - else: - infos['start_vm'] = 'false_startfailed' - else: - infos['start_vm'] = 'false_sessionunknown' - else: - infos['start_vm'] = 'false_statevmunknown' - return infos - -def stopvm(id): - idvm = id - vm = vbox.find_machine(idvm) - infos = collections.OrderedDict() - if str(vm.state) == 'PoweredOff': - infos['stop_vm'] = 'false_vmalreadyoff' #VM deja eteinte - elif str(vm.state) == 'FirstOnline': - session = vm.create_session() #Creation d'une session, meme si une autre existe deja - if str(vm.session_state) == 'Unlocked': # Si la session est lock - infos['stop_vm'] = 'false_sessionlocked' - elif str(vm.session_state) == 'Locked': # Si la session est lock - session.console.power_down() # Eteindre la vm - time.sleep(5) # Attente de cinq secondes - if str(vm.state) == 'PoweredOff': #On reverifie - infos['stop_vm'] = 'true' - else: - infos['stop_vm'] = 'false_stopfailed' - else: - infos['stop_vm'] = 'false_sessionunknown' - else: - infos['stop_vm'] = 'false_statevmunknown' - return infos \ No newline at end of file + return vminfos #Envoi des informations \ No newline at end of file diff --git a/PythonScripts/vmscript.py b/PythonScripts/vmscript.py index e43e54d..46bea77 100644 --- a/PythonScripts/vmscript.py +++ b/PythonScripts/vmscript.py @@ -46,23 +46,6 @@ sockethelper.send_data(ivm) #Envoi des informations en json sockethelper.close_socket() #Fermeture de la socket - elif 'start_vm' in data: - type = python_obj['start_vm'] - svm = vmfonctions.startvm(type) - svm = vmfonctions.jsondata(svm) - print 'Json envoyee : ' - print svm - sockethelper.send_data(svm) #Envoi des informations en json - sockethelper.close_socket() #Fermeture de la socket - - elif 'stop_vm' in data: - type = python_obj['stop_vm'] - stvm = vmfonctions.stopvm(type) - stvm = vmfonctions.jsondata(stvm) - print 'Json envoyee : ' - print stvm - sockethelper.send_data(stvm) # Envoi des informations en json - sockethelper.close_socket() # Fermeture de la socket else: sockethelper.send_data("Erreur") sockethelper.close_socket() \ No newline at end of file