Package Peach :: Package Agent :: Module vm
[hide private]

Source Code for Module Peach.Agent.vm

 1   
 2  ''' 
 3  vmware controler for Peach Agent.  Allows manipulating the state of a vm 
 4  during a fuzzing run.  Common use case here is to revert to a known good 
 5  state after a fault or N tests. 
 6   
 7  @author: Michael Eddington 
 8  @version: $Id: vm.py 780 2008-03-23 02:58:49Z meddingt $ 
 9  ''' 
10   
11  # 
12  # Copyright (c) 2007 Michael Eddington 
13  # 
14  # Permission is hereby granted, free of charge, to any person obtaining a copy  
15  # of this software and associated documentation files (the "Software"), to deal 
16  # in the Software without restriction, including without limitation the rights  
17  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
18  # copies of the Software, and to permit persons to whom the Software is  
19  # furnished to do so, subject to the following conditions: 
20  # 
21  # The above copyright notice and this permission notice shall be included in     
22  # all copies or substantial portions of the Software. 
23  # 
24  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
25  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
26  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
27  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
28  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
29  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
30  # SOFTWARE. 
31  # 
32   
33  # Authors: 
34  #   Michael Eddington (mike@phed.org) 
35   
36  # $Id: vm.py 780 2008-03-23 02:58:49Z meddingt $ 
37   
38  import sys 
39  from Peach.agent import Monitor 
40   
41  try: 
42          from vix import Vix 
43  except: 
44          print "Warning: Module pyvix not found.  VMWare Monitor will not function." 
45   
46 -class Vmware(Monitor):
47 ''' 48 Control a vmware server instance to start/revert the 49 target vm. 50 ''' 51
52 - def __init__(self, args):
53 ''' 54 Start VM 55 ''' 56 57 index = -1 58 59 try: 60 if args['snapshotindex'] != None: 61 index = int(args['snapshotindex']) 62 except: 63 pass 64 65 self.vm = Vix() 66 67 try: 68 self.vm.Connect(str(args['host'])) 69 except: 70 self.vm.Connect() 71 72 print "About to open:", args['vmx'] 73 self.vm.Open(str(args['vmx'])) 74 75 if index > -1: 76 self.vm.GetRootSnapshot(index) 77 else: 78 self.vm.GetRootSnapshot() 79 80 self.vm.RevertToSnapshot()
81
82 - def OnFault(self):
83 ''' 84 On a fault, restart VM to save point. 85 ''' 86 self.vm.RevertToSnapshot()
87
88 - def OnShutdown(self):
89 ''' 90 Shutdown vm 91 ''' 92 self.vm.PowerOff() 93 self.vm.Disconnect()
94 95 # end 96