Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
Annulation des commits - [Issue #25] Ajout des fonctions startvm et s…
Browse files Browse the repository at this point in the history
…topvm + [Exe] - Voir mvp2
  • Loading branch information
Saadoune Chamseddine committed Jan 10, 2018
1 parent 58e198d commit c6c8538
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 66 deletions.
Binary file modified PythonScripts/exe/vmscript.rar
Binary file not shown.
50 changes: 1 addition & 49 deletions PythonScripts/vmfonctions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import collections
import json
import virtualbox #pyvbox
import time

vbox = virtualbox.VirtualBox()

Expand Down Expand Up @@ -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
return vminfos #Envoi des informations
17 changes: 0 additions & 17 deletions PythonScripts/vmscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit c6c8538

Please sign in to comment.