Example #1
0
 def __init__(self, config):
     """
         Initalize anythign that we need and save our config file.
     """
     
     self.type = G.MACHINE_TYPES.PHYSICAL
     
     Machine.__init__(self, config)
Example #2
0
    def __init__(self, config):
        """
            Initalize anythign that we need and save our config file.
        """

        self.type = G.MACHINE_TYPES.PHYSICAL

        Machine.__init__(self, config)
Example #3
0
    def __init__(self, vm_name, 
                 vm_type=G.MACHINE_TYPES.KVM, 
                 static_mac=None,
                 memory_size=1073741824,
                 cpu_count=1, 
                 force_new=False,
                 volatility_profile=None,
                 **kargs):
        """
            Initialize 
            
            @param config: Machine configuration object
            @param init_sensors: Initialize all sensors by default
        """
        # Initialize our state variables
        self.type = vm_type
        self.MACHINE_TYPE = vm_type
        
        class MachineConfig():
            # Name
            name = vm_name
            # DISK
            disk = os.path.join(G.DIR_ROOT,G.DIR_VM_OUTPUT,vm_name+".qcow2")
            disk_base = None
            # Config
            vm_config = os.path.join(G.DIR_ROOT,G.DIR_VM_OUTPUT,vm_name+".xml")
            
        config = MachineConfig()
        # MAC
        if static_mac is None:
            config.__dict__['mac_addr'] = self.__get_new_mac()
        else:
            config.__dict__['mac_addr'] = static_mac
        config.__dict__['vm_name'] = vm_name
        config.__dict__['memory_size'] = memory_size
        config.__dict__['cpu_count'] = cpu_count
        config.__dict__['volatility_profile'] = volatility_profile
        

        Machine.__init__(self, config)
        
        # Add all of our sensors
        
        # Control sensor must be added first to interact with libvirt
        self.add_sensor(ControlSensorVirtual(vm_name,vm_type))
        
        # What state are we in?
        state = self.control.get_state()
        
        # UKNOWN is does not exist
        if force_new and state is None:
            self.lophi_init()
        elif state != G.SENSOR_CONTROL.POWER_STATUS.UNKNOWN:
            logger.debug("VM (%s) already exists."%self.config.name)
        
        # Add all of our sensors to this VM
        vm_disk = self.disk_get_filename()
        if vm_disk is not None:
            self.add_sensor(DiskSensorVirtual(vm_disk))
        else:
            self.add_sensor(DiskSensorVirtual(self.config.disk))
        self.add_sensor(CPUSensorVirtual(config.vm_name))
        self.add_sensor(MemorySensorVirtual(config.vm_name))
        
        net_iface = self.network_get_interface()
        if net_iface is not None:
            self.add_sensor(NetworkSensorVirtual(net_iface))
        else:
            logger.warn("No network intface exists for %s"%self.config.vm_name)
            
            
        # Do we need to mutex these accesses?
        self.REQUIRE_MUTEX = False
        if "require_mutex" in kargs and kargs['require_mutex']:
            self.REQUIRE_MUTEX = True

        # Force a completely fresh instance?
        if "force_new" in kargs and kargs['force_new']:
            # Poweroff existing machine
            self.control.power_off()