示例#1
0
文件: physical.py 项目: mit-ll/LO-PHI
    def __init__(self, sensor_ip, sensor_port=G.SENSOR_CONTROL.DEFAULT_PORT, name=None):
        """
            Initialize our control sensor (e.g arduino)
        """
        self.sensor_ip = sensor_ip
        self.sensor_port = sensor_port
        self._sock = None

        if name is not None:
            self.name = name

        #         self.sensor_reset()

        self._connect()

        ControlSensor.__init__(self)
示例#2
0
    def __init__(self,
                 sensor_ip,
                 sensor_port=G.SENSOR_CONTROL.DEFAULT_PORT,
                 name=None):
        """
            Initialize our control sensor (e.g arduino)
        """
        self.sensor_ip = sensor_ip
        self.sensor_port = sensor_port
        self._sock = None

        if name is not None:
            self.name = name

#         self.sensor_reset()

        self._connect()

        ControlSensor.__init__(self)
示例#3
0
文件: virtual.py 项目: c0ns0le/LO-PHI
 def __init__(self, vm_name, vm_type=None,isolated_network=True, **kargs):
     """
         Initialize 
     """
     if os.getuid() != 0:
         logger.error("You likely have to run libvirt as root.")
     
     # Do we need to mutex these accesses?
     self.REQUIRE_MUTEX = False
     if "require_mutex" in kargs and kargs['require_mutex']:
         self.REQUIRE_MUTEX = True
     
     # Meta data    
     self.vm_name = vm_name
     self.MACHINE_TYPE = vm_type
     self.name = vm_name+"-ControlSensor"
     
     # Should this be created on the isolated LO-PHI network?
     self.ISOLATED_NETWORK = isolated_network
             
     # See if our VM already exists
     dom = self._connect()
     
     # Dose our domain exist?
     if dom is not None and vm_type is None:
         # Let's determine the type of VM automatically
         logger.debug("Detecting type of vm for %s"%self.vm_name)
         
         from xml.dom.minidom import parseString
         xml = dom.XMLDesc(0)
         xml_dom = parseString(xml)
         root_node = xml_dom.childNodes[0]
         
         domain_type = root_node.getAttribute("type")
         
         if domain_type == "kvm":
             self.MACHINE_TYPE = G.MACHINE_TYPES.KVM
         elif domain_type == "xen":
             self.MACHINE_TYPE = G.MACHINE_TYPES.XEN
     
     # If we are creating it from within LO-PHI make sure we use our 
     #  isolated network
     if self.ISOLATED_NETWORK and not self.ISOLATED_NETWORK_CREATED:
         net = nwf = None
         try:
             # Create our filter and our network
             try:
                 net = self._libvirt_conn.networkLookupByName("network-lophi")
             except:
                 pass
             try:
                 nwf = self._libvirt_conn.nwfilterLookupByName("isolated-lophi")
             except:
                 pass
         
             # Create our network and filter if they don't already exist
             if net is None or net is "":
                 self._libvirt_conn.networkCreateXML(XML_NETWORK)
             if nwf is None or nwf is "":
                 self._libvirt_conn.nwfilterDefineXML(XML_NWFILTER)
             
             ControlSensorVirtual.ISOLATED_NETWORK_CREATED = True
             logger.debug("Isolated network and rules created")
         except:
             logger.error("Could not create libvirt isolated network!")
             pass
         
     self._disconnect()
     
     # Ensure we know what type of meachine we are working with
     if self.MACHINE_TYPE is None:
         logger.error("No machine type given for %s, defaulting to KVM"%self.vm_name)
         self.MACHINE_TYPE = G.MACHINE_TYPES.KVM    
         
     
     ControlSensor.__init__(self)
示例#4
0
    def __init__(self, vm_name, vm_type=None, isolated_network=True, **kargs):
        """
            Initialize 
        """
        if os.getuid() != 0:
            logger.error("You likely have to run libvirt as root.")

        # Do we need to mutex these accesses?
        self.REQUIRE_MUTEX = False
        if "require_mutex" in kargs and kargs['require_mutex']:
            self.REQUIRE_MUTEX = True

        # Meta data
        self.vm_name = vm_name
        self.MACHINE_TYPE = vm_type
        self.name = vm_name + "-ControlSensor"

        # Should this be created on the isolated LO-PHI network?
        self.ISOLATED_NETWORK = isolated_network

        # See if our VM already exists
        dom = self._connect()

        # Dose our domain exist?
        if dom is not None and vm_type is None:
            # Let's determine the type of VM automatically
            logger.debug("Detecting type of vm for %s" % self.vm_name)

            from xml.dom.minidom import parseString
            xml = dom.XMLDesc(0)
            xml_dom = parseString(xml)
            root_node = xml_dom.childNodes[0]

            domain_type = root_node.getAttribute("type")

            if domain_type == "kvm":
                self.MACHINE_TYPE = G.MACHINE_TYPES.KVM
            elif domain_type == "xen":
                self.MACHINE_TYPE = G.MACHINE_TYPES.XEN

        # If we are creating it from within LO-PHI make sure we use our
        #  isolated network
        if self.ISOLATED_NETWORK and not self.ISOLATED_NETWORK_CREATED:
            net = nwf = None
            try:
                # Create our filter and our network
                try:
                    net = self._libvirt_conn.networkLookupByName(
                        "network-lophi")
                except:
                    pass
                try:
                    nwf = self._libvirt_conn.nwfilterLookupByName(
                        "isolated-lophi")
                except:
                    pass

                # Create our network and filter if they don't already exist
                if net is None or net is "":
                    self._libvirt_conn.networkCreateXML(XML_NETWORK)
                if nwf is None or nwf is "":
                    self._libvirt_conn.nwfilterDefineXML(XML_NWFILTER)

                ControlSensorVirtual.ISOLATED_NETWORK_CREATED = True
                logger.debug("Isolated network and rules created")
            except:
                logger.error("Could not create libvirt isolated network!")
                pass

        self._disconnect()

        # Ensure we know what type of meachine we are working with
        if self.MACHINE_TYPE is None:
            logger.error("No machine type given for %s, defaulting to KVM" %
                         self.vm_name)
            self.MACHINE_TYPE = G.MACHINE_TYPES.KVM

        ControlSensor.__init__(self)