Esempio n. 1
0
    def InventorySysLinux(self, mac, inventory, ip_address):
        """
        Minimal inventory received from PXE.

        @param mac: MAC address
        @type mac: str

        @param inventory: inventory from PXE
        @type inventory: str

        @rtype: deferred
        """
        logging.getLogger().debug("INJECT INVENTORY NEXT HOSTNAME AND ENTITY")
        m = re.search('<REQUEST>.*<\/REQUEST>', inventory)
        file_content = str(m.group(0))

        ipadress = self.ip_adressexml(file_content)
        mac1= self.mac_adressexml(file_content)
        hostnamexml = self.hostname_xml(file_content)

        inventory ="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n%s"%(file_content)
        ip_address = ipadress
        mac =  mac1

        self.api.logClientAction(mac,
                                 LOG_LEVEL.DEBUG,
                                 LOG_STATE.MENU,
                                 "boot menu shown")
        if not "Mc" in inventory :
            inventory = inventory + "\nMAC Address:%s\n" % mac
        else :
            inventory = inventory.replace("Mc", "MAC Address")
        parsed_inventory1 = BootInventory()
        parsed_inventory1.initialise(file_content)
        parsed_inventory = parsed_inventory1.dump()
        self.api.logClientAction(mac,
                                 LOG_LEVEL.DEBUG,
                                 LOG_STATE.MENU,
                                 "boot menu shown")
        d = self.api.injectInventory(mac, parsed_inventory)

        # 2nd step - send inventory by HTTP POST to inventory server
        d.addCallback(self._injectedInventoryOk, mac, inventory)
        d.addErrback(self._injectedInventoryError)
        #self.send_inventory(parsed_inventory1., hostname)
        return d
Esempio n. 2
0
    def _injectedInventorySend (self, computer, mac, inventory):
        """
        Inventory sending by HTTP POST to inventory server.

        @param computer: ComputerManager container
        @type computer: dist

        @param mac: MAC address
        @type mac: str

        @param inventory: inventory from PXE
        @type inventory: str

        """
        self.api.logClientAction(mac,
                                 LOG_LEVEL.DEBUG,
                                 LOG_STATE.INVENTORY,
                                 "hardware inventory received")

        if not isinstance(computer, dict) :
            logging.getLogger().debug("PXE Proxy: Unknown client, ignore received inventory")
            return

        inventory = BootInventory(inventory)
        inventory.macaddr_info = mac

        hostname = computer['shortname']
        entity = computer['entity']

        inventory = inventory.dumpOCS(hostname, entity)

        d = self.send_inventory(inventory, hostname)
        @d.addCallback
        def _cb(result):
            self.api.logClientAction(mac,
                                     LOG_LEVEL.INFO,
                                     LOG_STATE.INVENTORY,
                                     "hardware inventory updated")
        @d.addErrback
        def _eb(failure):
            self.api.logClientAction(mac,
                                     LOG_LEVEL.WARNING,
                                     LOG_STATE.INVENTORY,
                                     "hardware inventory not updated")
Esempio n. 3
0
    def InventorySysLinux(self, mac, inventory, ip_address):
        """
        Minimal inventory received from PXE.

        @param mac: MAC address
        @type mac: str

        @param inventory: inventory from PXE
        @type inventory: str

        @rtype: deferred
        """
        logging.getLogger().debug("INJECT INVENTORY NEXT HOSTNAME AND ENTITY")
        m = re.search('<REQUEST>.*<\/REQUEST>', inventory)
        file_content = str(m.group(0))

        ipadress = self.ip_adressexml(file_content)
        mac1 = self.mac_adressexml(file_content)
        hostnamexml = self.hostname_xml(file_content)

        inventory = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n%s" % (
            file_content)
        ip_address = ipadress
        mac = mac1

        self.api.logClientAction(mac, LOG_LEVEL.DEBUG, LOG_STATE.MENU,
                                 "boot menu shown")
        if not "Mc" in inventory:
            inventory = inventory + "\nMAC Address:%s\n" % mac
        else:
            inventory = inventory.replace("Mc", "MAC Address")
        parsed_inventory1 = BootInventory()
        parsed_inventory1.initialise(file_content)
        parsed_inventory = parsed_inventory1.dump()
        self.api.logClientAction(mac, LOG_LEVEL.DEBUG, LOG_STATE.MENU,
                                 "boot menu shown")
        d = self.api.injectInventory(mac, parsed_inventory)

        # 2nd step - send inventory by HTTP POST to inventory server
        d.addCallback(self._injectedInventoryOk, mac, inventory)
        d.addErrback(self._injectedInventoryError)
        #self.send_inventory(parsed_inventory1., hostname)
        return d
Esempio n. 4
0
    def _injectedInventorySend(self, computer, mac, inventory):
        """
        Inventory sending by HTTP POST to inventory server.

        @param computer: ComputerManager container
        @type computer: dist

        @param mac: MAC address
        @type mac: str

        @param inventory: inventory from PXE
        @type inventory: str

        """
        self.api.logClientAction(mac, LOG_LEVEL.DEBUG, LOG_STATE.INVENTORY,
                                 "hardware inventory received")

        if not isinstance(computer, dict):
            logging.getLogger().debug(
                "PXE Proxy: Unknown client, ignore received inventory")
            return

        inventory = BootInventory(inventory)
        inventory.macaddr_info = mac

        hostname = computer['shortname']
        entity = computer['entity']

        inventory = inventory.dumpOCS(hostname, entity)

        d = self.send_inventory(inventory, hostname)

        @d.addCallback
        def _cb(result):
            self.api.logClientAction(mac, LOG_LEVEL.INFO, LOG_STATE.INVENTORY,
                                     "hardware inventory updated")

        @d.addErrback
        def _eb(failure):
            self.api.logClientAction(mac, LOG_LEVEL.WARNING,
                                     LOG_STATE.INVENTORY,
                                     "hardware inventory not updated")
Esempio n. 5
0
    def injectInventory(self, mac, inventory, ip_address):
        """
        Minimal inventory received from PXE.

        @param mac: MAC address
        @type mac: str

        @param inventory: inventory from PXE
        @type inventory: str

        @rtype: deferred
        """
        # XXX - A little hack to add networking info on GLPI mode
        logging.getLogger().debug("injectInventory mac %s ip : %s \n\n" %
                                  (mac, ip_address))
        if not "Mc" in inventory:
            inventory = inventory + "\nMAC Address:%s\n" % mac
        else:
            inventory = inventory.replace("Mc", "MAC Address")
        if not "IPADDR" in inventory:
            inventory = inventory + "\nIP Address:%\n" % ip_address
        else:
            inventory = inventory.replace("IPADDR", "IP Address")
        inventory = [
            i.strip(' \t\n\r').lstrip('\x00\x00').strip()
            for i in inventory.split("\n")
        ]

        logging.getLogger().debug("low level inventory: %s\n" % (inventory))
        parsed_inventory1 = BootInventory(inventory)
        parsed_inventory = parsed_inventory1.dump()
        self.api.logClientAction(mac, LOG_LEVEL.DEBUG, LOG_STATE.MENU,
                                 "boot menu shown")
        # 1st step - inject inventory trough imaging (only disk info)
        d = self.api.injectInventory(mac, parsed_inventory)

        # 2nd step - send inventory by HTTP POST to inventory server
        d.addCallback(self._injectedInventoryOk, mac, inventory)
        d.addErrback(self._injectedInventoryError)
        #self.send_inventory(parsed_inventory1., hostname)
        return d
Esempio n. 6
0
    def glpi_register(self, mac, hostname, ip_address):
        """
        Computer register sending a minimal inventory

        @param mac: MAC address
        @type mac: str

        @param hostname: hostname of inventoried machine
        @type hostname: str

        @param ip_address: machine IP address
        @type ip_address: str

        """
        boot_inv = BootInventory()
        boot_inv.macaddr_info = mac
        boot_inv.ipaddr_info = {'ip': ip_address, 'port': 0}

        inventory = boot_inv.dumpOCS(hostname, "root")

        return self.send_inventory(inventory, hostname)
Esempio n. 7
0
    def glpi_register(self, mac, hostname, ip_address):
        """
        Computer register sending a minimal inventory

        @param mac: MAC address
        @type mac: str

        @param hostname: hostname of inventoried machine
        @type hostname: str

        @param ip_address: machine IP address
        @type ip_address: str

        """
        boot_inv = BootInventory()
        boot_inv.macaddr_info = mac
        boot_inv.ipaddr_info = {'ip': ip_address, 'port': 0}

        inventory = boot_inv.dumpOCS(hostname, "root")

        return self.send_inventory(inventory, hostname)
Esempio n. 8
0
    def injectInventory(self, mac, inventory, ip_address):
        """
        Minimal inventory received from PXE.

        @param mac: MAC address
        @type mac: str

        @param inventory: inventory from PXE
        @type inventory: str

        @rtype: deferred
        """
        # XXX - A little hack to add networking info on GLPI mode
        logging.getLogger().debug("injectInventory mac %s ip : %s \n\n" %(mac,ip_address))
        if not "Mc" in inventory :
            inventory = inventory + "\nMAC Address:%s\n" % mac
        else :
            inventory = inventory.replace("Mc", "MAC Address")
        if not "IPADDR" in inventory :
            inventory = inventory + "\nIP Address:%\n" % ip_address
        else :
            inventory = inventory.replace("IPADDR", "IP Address")
        inventory = [i.strip(' \t\n\r').lstrip('\x00\x00').strip() for i in inventory.split("\n")]

        logging.getLogger().debug("low level inventory: %s\n" %(inventory))
        parsed_inventory1 = BootInventory(inventory)
        parsed_inventory = parsed_inventory1.dump()
        self.api.logClientAction(mac,
                                 LOG_LEVEL.DEBUG,
                                 LOG_STATE.MENU,
                                 "boot menu shown")
        # 1st step - inject inventory trough imaging (only disk info)
        d = self.api.injectInventory(mac, parsed_inventory)

        # 2nd step - send inventory by HTTP POST to inventory server
        d.addCallback(self._injectedInventoryOk, mac, inventory)
        d.addErrback(self._injectedInventoryError)
        #self.send_inventory(parsed_inventory1., hostname)
        return d
Esempio n. 9
0
    def glpi_register(self, mac, hostname, ip_address):
        """
        Computer register sending a minimal inventory

        @param mac: MAC address
        @type mac: str

        @param hostname: hostname of inventoried machine
        @type hostname: str

        @param ip_address: machine IP address
        @type ip_address: str

        """
        logging.getLogger().debug("glpi_register")
        boot_inv = BootInventory()
        boot_inv.macaddr_info = mac
        boot_inv.ipaddr_info = {'ip': ip_address, 'port': 0}
        # add information network in xml glpi
        boot_inv.netmask_info = P2PServerCP().public_mask
        boot_inv.subnet_info = self.subnetreseau(boot_inv.ipaddr_info['ip'],
                                                 boot_inv.netmask_info)
        inventory = boot_inv.dumpOCS(hostname, "root")
        return self.send_inventory(inventory, hostname)
Esempio n. 10
0
    def glpi_register(self, mac, hostname, ip_address):
        """
        Computer register sending a minimal inventory

        @param mac: MAC address
        @type mac: str

        @param hostname: hostname of inventoried machine
        @type hostname: str

        @param ip_address: machine IP address
        @type ip_address: str

        """
        logging.getLogger().debug("glpi_register")
        boot_inv = BootInventory()
        boot_inv.macaddr_info = mac
        boot_inv.ipaddr_info = {'ip': ip_address, 'port': 0}
        # add information network in xml glpi
        boot_inv.netmask_info = P2PServerCP().public_mask
        boot_inv.subnet_info  = self.subnetreseau(boot_inv.ipaddr_info['ip'],boot_inv.netmask_info)
        inventory = boot_inv.dumpOCS(hostname, "root")
        return self.send_inventory(inventory, hostname)