<s> from vt_manager . communication . utils . XmlHelper import XmlHelper <EOL> import os <EOL> import sys <EOL> from vt_manager . models import * <EOL> from vt_manager . controller import * <EOL> from vt_manager . communication . utils import * <EOL> from vt_manager . utils . ServiceThread import * <EOL> import xmlrpclib , threading , logging , copy <EOL> from django . conf import settings <EOL> from django import forms <EOL> from vt_manager . utils . HttpUtils import HttpUtils <EOL> from django . db . models . query import QuerySet <EOL> from vt_manager . models . VirtualMachine import VirtualMachine <EOL> from vt_manager . controller . actions . ActionController import ActionController <EOL> from vt_manager . utils . ServiceThread import * <EOL> from django . core . exceptions import ValidationError <EOL> from vt_manager . utils . HttpUtils import HttpUtils <EOL> class VTDriver ( ) : <EOL> CONTROLLER_TYPE_XEN = "<STR_LIT>" <EOL> __possibleVirtTechs = [ CONTROLLER_TYPE_XEN ] <EOL> @ staticmethod <EOL> def getDriver ( virtType ) : <EOL> from vt_manager . controller . drivers . XenDriver import XenDriver <EOL> if virtType == VTDriver . CONTROLLER_TYPE_XEN : <EOL> return XenDriver . getInstance ( ) <EOL> @ staticmethod <EOL> def getAllDrivers ( ) : <EOL> from vt_manager . controller . drivers . XenDriver import XenDriver <EOL> drivers = [ ] <EOL> for vt in Driver . __possibleVirtTechs : <EOL> drivers . append ( Driver . getDriver ( vt ) ) <EOL> return drivers <EOL> @ staticmethod <EOL> def getAllServers ( ) : <EOL> from vt_manager . models . VTServer import VTServer <EOL> servers = VTServer . objects . all ( ) <EOL> serversChild = [ ] <EOL> for server in servers : <EOL> server = server . getChildObject ( ) <EOL> serversChild . append ( server ) <EOL> return serversChild <EOL> @ staticmethod <EOL> def createServerFromPOST ( request , instance ) : <EOL> from vt_manager . models . VTServer import VTServer <EOL> controller = VTDriver . getDriver ( HttpUtils . getFieldInPost ( request , VTServer , "<STR_LIT>" ) ) <EOL> return controller . createOrUpdateServerFromPOST ( request , instance ) <EOL> @ staticmethod <EOL> def crudServerFromInstance ( instance ) : <EOL> s = xmlrpclib . Server ( instance . agentURL ) <EOL> try : <EOL> s . pingAuth ( "<STR_LIT>" , instance . agentPassword ) <EOL> except : <EOL> raise forms . ValidationError ( "<STR_LIT>" ) <EOL> controller = VTDriver . getDriver ( instance . getVirtTech ( ) ) <EOL> return controller . crudServerFromInstance ( instance ) <EOL> @ staticmethod <EOL> def setMgmtBridge ( request , server ) : <EOL> name = HttpUtils . getFieldInPost ( request , "<STR_LIT>" ) <EOL> mac = HttpUtils . getFieldInPost ( request , "<STR_LIT>" ) <EOL> server . setMgmtBridge ( name , mac ) <EOL> @ staticmethod <EOL> def crudDataBridgeFromInstance ( server , ifaces , ifacesToDelete ) : <EOL> serverIfaces = server . getNetworkInterfaces ( ) . filter ( isMgmt = False ) <EOL> for newIface in ifaces : <EOL> if newIface . id == None : <EOL> server . addDataBridge ( newIface . getName ( ) , "<STR_LIT>" , newIface . getSwitchID ( ) , newIface . getPort ( ) ) <EOL> else : <EOL> server . updateDataBridge ( newIface ) <EOL> for id in ifacesToDelete : <EOL> if id != '<STR_LIT>' : <EOL> try : <EOL> server . deleteDataBridge ( serverIfaces . get ( id = id ) ) <EOL> except Exception as e : <EOL> raise ValidationError ( str ( e ) ) <EOL> @ staticmethod <EOL> def getServerById ( id ) : <EOL> from vt_manager . models . VTServer import VTServer <EOL> try : <EOL> return VTServer . objects . get ( id = id ) . getChildObject ( ) <EOL> except : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> @ staticmethod <EOL> def getServerByUUID ( uuid ) : <EOL> try : <EOL> from vt_manager . models . VTServer import VTServer <EOL> return VTServer . objects . get ( uuid = uuid ) . getChildObject ( ) <EOL> except : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> @ staticmethod <EOL> def getVMsInServer ( server ) : <EOL> try : <EOL> return server . vms . all ( ) <EOL> except : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> @ staticmethod <EOL> def getInstance ( ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> @ staticmethod <EOL> def getVMbyUUID ( uuid ) : <EOL> try : <EOL> return VirtualMachine . objects . get ( uuid = uuid ) . getChildObject ( ) <EOL> except : <EOL> raise <EOL> @ staticmethod <EOL> def getVMbyId ( id ) : <EOL> try : <EOL> return VirtualMachine . objects . get ( id = id ) . getChildObject ( ) <EOL> except : <EOL> raise <EOL> def deleteVM ( ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def getServerAndCreateVM ( ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def getServers ( self ) : <EOL> return self . ServerClass . objects . all ( ) <EOL> @ staticmethod <EOL> def deleteServer ( server ) : <EOL> server . destroy ( ) <EOL> @ staticmethod <EOL> def manageEthernetRanges ( request , server , totalMacRanges ) : <EOL> justUnsubscribed = [ ] <EOL> for macRange in server . getSubscribedMacRangesNoGlobal ( ) : <EOL> try : <EOL> request . POST [ '<STR_LIT>' + str ( macRange . id ) ] <EOL> except : <EOL> server . unsubscribeToMacRange ( macRange ) <EOL> justUnsubscribed . append ( macRange ) <EOL> for macRange in totalMacRanges : <EOL> if macRange not in ( server . getSubscribedMacRangesNoGlobal ( ) or justUnsubscribed ) : <EOL> try : <EOL> request . POST [ '<STR_LIT>' + str ( macRange . id ) ] <EOL> server . subscribeToMacRange ( macRange ) <EOL> except : <EOL> pass <EOL> @ staticmethod <EOL> def manageIp4Ranges ( request , server , totalIpRanges ) : <EOL> justUnsubscribed = [ ] <EOL> for ipRange in server . getSubscribedIp4RangesNoGlobal ( ) : <EOL> try : <EOL> request . POST [ '<STR_LIT>' + str ( ipRange . id ) ] <EOL> except : <EOL> server . unsubscribeToIp4Range ( ipRange ) <EOL> justUnsubscribed . append ( ipRange ) <EOL> for ipRange in totalIpRanges : <EOL> if ipRange not in ( server . getSubscribedIp4RangesNoGlobal ( ) or justUnsubscribed ) : <EOL> try : <EOL> request . POST [ '<STR_LIT>' + str ( ipRange . id ) ] <EOL> server . subscribeToIp4Range ( ipRange ) <EOL> except Exception as e : <EOL> pass <EOL> @ staticmethod <EOL> def PropagateActionToProvisioningDispatcher ( vm_id , serverUUID , action ) : <EOL> from vt_manager . communication . utils . XmlHelper import XmlHelper <EOL> from vt_manager . controller . dispatchers . xmlrpc . DispatcherLauncher import DispatcherLauncher <EOL> vm = VirtualMachine . objects . get ( id = vm_id ) . getChildObject ( ) <EOL> rspec = XmlHelper . getSimpleActionSpecificQuery ( action , serverUUID ) <EOL> ActionController . PopulateNewActionWithVM ( rspec . query . provisioning . action [ <NUM_LIT:0> ] , vm ) <EOL> ServiceThread . startMethodInNewThread ( DispatcherLauncher . processXmlQuery , rspec ) </s>
