<s> from vt_manager . controller . drivers . VTDriver import VTDriver <EOL> from vt_manager . models . XenServer import XenServer <EOL> from vt_manager . models . XenVM import XenVM <EOL> from vt_manager . models . VTServer import VTServer <EOL> from vt_manager . utils . HttpUtils import HttpUtils <EOL> import threading <EOL> class XenDriver ( VTDriver ) : <EOL> @ staticmethod <EOL> def getInstance ( ) : <EOL> return XenDriver ( ) <EOL> def deleteVM ( self , vm ) : <EOL> try : <EOL> vm . Server . get ( ) . deleteVM ( vm ) <EOL> except : <EOL> raise <EOL> def getServerAndCreateVM ( self , action ) : <EOL> try : <EOL> Server = XenServer . objects . get ( uuid = action . server . uuid ) <EOL> VMmodel = Server . createVM ( * XenDriver . xenVMtoModel ( action . server . virtual_machines [ <NUM_LIT:0> ] , threading . currentThread ( ) . callBackURL , save = True ) ) <EOL> return Server , VMmodel <EOL> except Exception as e : <EOL> raise e <EOL> @ staticmethod <EOL> def createOrUpdateServerFromPOST ( request , instance ) : <EOL> server = XenServer . objects . get ( uuid = instance . getUUID ( ) ) <EOL> if server : <EOL> return server . updateServer ( HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT:name>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> save = True ) <EOL> else : <EOL> return XenServer . constructor ( HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT:name>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) , <EOL> save = True ) <EOL> def crudServerFromInstance ( self , instance ) : <EOL> server = XenServer . objects . filter ( uuid = instance . getUUID ( ) ) <EOL> if len ( server ) == <NUM_LIT:1> : <EOL> server = server [ <NUM_LIT:0> ] <EOL> return server . updateServer ( instance . getName ( ) , <EOL> instance . getOSType ( ) , <EOL> instance . getOSDistribution ( ) , <EOL> instance . getOSVersion ( ) , <EOL> instance . getNumberOfCPUs ( ) , <EOL> instance . getCPUFrequency ( ) , <EOL> instance . getMemory ( ) , <EOL> instance . getDiscSpaceGB ( ) , <EOL> instance . getAgentURL ( ) , <EOL> instance . getAgentPassword ( ) , <EOL> save = True ) <EOL> elif len ( server ) == <NUM_LIT:0> : <EOL> return XenServer . constructor ( instance . getName ( ) , <EOL> instance . getOSType ( ) , <EOL> instance . getOSDistribution ( ) , <EOL> instance . getOSVersion ( ) , <EOL> instance . getNumberOfCPUs ( ) , <EOL> instance . getCPUFrequency ( ) , <EOL> instance . getMemory ( ) , <EOL> instance . getDiscSpaceGB ( ) , <EOL> instance . getAgentURL ( ) , <EOL> instance . getAgentPassword ( ) , <EOL> save = True ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> @ staticmethod <EOL> def xenVMtoModel ( VMxmlClass , callBackURL , save ) : <EOL> name = VMxmlClass . name <EOL> uuid = VMxmlClass . uuid <EOL> projectId = VMxmlClass . project_id <EOL> projectName = VMxmlClass . project_name <EOL> sliceId = VMxmlClass . slice_id <EOL> sliceName = VMxmlClass . slice_name <EOL> osType = VMxmlClass . operating_system_type <EOL> osVersion = VMxmlClass . operating_system_version <EOL> osDist = VMxmlClass . operating_system_distribution <EOL> memory = VMxmlClass . xen_configuration . memory_mb <EOL> callBackUrl = callBackURL <EOL> hdSetupType = VMxmlClass . xen_configuration . hd_setup_type <EOL> hdOriginPath = VMxmlClass . xen_configuration . hd_origin_path <EOL> virtSetupType = VMxmlClass . xen_configuration . virtualization_setup_type <EOL> return name , uuid , projectId , projectName , sliceId , sliceName , osType , osVersion , osDist , memory , None , None , callBackUrl , hdSetupType , hdOriginPath , virtSetupType , save </s>
