Package modules :: Package machinery :: Module esx
[hide private]
[frames] | no frames]

Source Code for Module modules.machinery.esx

 1  # Copyright (C) 2010-2014 Cuckoo Foundation. 
 2  # Copyright (C) 2013 Christopher Schmitt <cschmitt@tankbusta.net> 
 3  # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org 
 4  # See the file 'docs/LICENSE' for copying permission. 
 5   
 6  import logging 
 7  import libvirt 
 8   
 9  from lib.cuckoo.common.abstracts import LibVirtMachinery 
10  from lib.cuckoo.common.exceptions import CuckooCriticalError 
11  from lib.cuckoo.common.exceptions import CuckooMachineError 
12   
13 -class ESX(LibVirtMachinery):
14 """Virtualization layer for ESXi/ESX based on python-libvirt."""
15 - def _initialize_check(self):
16 """Runs all checks when a machine manager is initialized. 17 @raise CuckooMachineError: if configuration is invalid 18 """ 19 if not self.options.esx.dsn: 20 raise CuckooMachineError("ESX(i) DSN is missing, please add it to the config file") 21 if not self.options.esx.username: 22 raise CuckooMachineError("ESX(i) username is missing, please add it to the config file") 23 if not self.options.esx.password: 24 raise CuckooMachineError("ESX(i) password is missing, please add it to the config file") 25 26 self.dsn = self.options.esx.dsn 27 28 super(ESX, self)._initialize_check()
29
30 - def _auth_callback(self, credentials, user_data):
31 for credential in credentials: 32 if credential[0] == libvirt.VIR_CRED_AUTHNAME: 33 credential[4] = self.options.esx.username 34 elif credential[0] == libvirt.VIR_CRED_NOECHOPROMPT: 35 credential[4] = self.options.esx.password 36 else: 37 raise CuckooCriticalError("ESX machinery did not recieve an object to inject a username or password into") 38 39 return 0
40
41 - def _connect(self):
42 try: 43 self.auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_NOECHOPROMPT], self._auth_callback, None] 44 return libvirt.openAuth(self.dsn, self.auth, 0) 45 except libvirt.libvirtError as libvex: 46 raise CuckooCriticalError("libvirt returned an exception on connection: %s" % libvex)
47