Exemplo n.º 1
0
    def clear_session_node(node: Node, lock: bool = True) -> None:
        if lock:
            session_nodes_lock.acquire()

        try:
            if not node.name:
                return

            hostname = get_host_name(node.name)

            logger.debug('clear_session_node(): session_nodes=[{0}]'.format(
                ' '.join([session_node for session_node in session_nodes])))

            if hostname in session_nodes:
                logger.debug(
                    'DELETING session_nodes entry: {0}'.format(hostname))

                session_nodes.remove(hostname)

            prov_nics = get_provisioning_nics(node)

            if prov_nics:
                if prov_nics[0].ip in reservedIps:
                    reservedIps.remove(prov_nics[0].ip)
        finally:
            if lock:
                session_nodes_lock.release()
Exemplo n.º 2
0
def test_get_provisioning_nics(node_with_nics):
    prov_nics = get_provisioning_nics(node_with_nics)

    assert prov_nics

    assert prov_nics[0].ip == '192.168.0.4'
    assert prov_nics[0].network.address == '192.168.0.0'
Exemplo n.º 3
0
    def __add_predefined_nodes(self,
                               addNodesRequest: dict,
                               dbSession,
                               dbHardwareProfile,
                               dbSoftwareProfile,
                               dns_zone: str = None) -> List[Nodes]:
        nodeDetails = addNodesRequest['nodeDetails'] \
            if 'nodeDetails' in addNodesRequest else []

        bGenerateIp = dbHardwareProfile.location != 'remote'

        newNodes = []

        for nodeDict in nodeDetails:
            addNodeRequest = {}

            addNodeRequest['addHostSession'] = self.addHostSession

            if 'rack' in addNodesRequest:
                # rack can be undefined, in which case it is not copied
                # into the node request
                addNodeRequest['rack'] = addNodesRequest['rack']

            if 'nics' in nodeDict:
                addNodeRequest['nics'] = nodeDict['nics']

            if 'name' in nodeDict:
                addNodeRequest['name'] = nodeDict['name']

            node = self.nodeApi.createNewNode(dbSession,
                                              addNodeRequest,
                                              dbHardwareProfile,
                                              dbSoftwareProfile,
                                              bGenerateIp=bGenerateIp,
                                              dns_zone=dns_zone)

            dbSession.add(node)

            # Create DHCP/PXE configuration
            self.writeLocalBootConfiguration(node, dbHardwareProfile,
                                             dbSoftwareProfile)

            # Get the provisioning nic
            nics = get_provisioning_nics(node)

            self._pre_add_host(node.name, dbHardwareProfile.name,
                               dbSoftwareProfile.name,
                               nics[0].ip if nics else None)

            newNodes.append(node)

        return newNodes