예제 #1
0
    def start(self,
              addNodesRequest,
              dbSession,
              dbHardwareProfile,
              dbSoftwareProfile=None):

        nodes = []

        for node_detail in addNodesRequest['nodeDetails']:
            node = Nodes(name=node_detail['name'])
            node.hardwareprofile = dbHardwareProfile
            node.softwareprofile = dbSoftwareProfile

            node.nics = []

            for nic_detail in node_detail['nics']:

                nic = Nics()
                nic.ip = nic_detail['ip']

                print(node_detail)

            node.nics.append(nic)

            nodes.append(node)

        return nodes
예제 #2
0
파일: test_nodes.py 프로젝트: ilumb/tortuga
def test_addnode(dbm):
    node = Nodes(name='mike')

    with dbm.session() as session:
        session.add(node)

        session.commit()
예제 #3
0
    def initializeNode(self,
                       session: Session,
                       dbNode: Nodes,
                       dbHardwareProfile: HardwareProfiles,
                       dbSoftwareProfile,
                       nic_defs: List[dict],
                       bValidateIp: bool = True,
                       bGenerateIp: bool = True,
                       dns_zone: Optional[str] = None) -> NoReturn:         \
            # pylint: disable=unused-argument
        '''
        Assigns hostname and IP address, and inserts new record into
        Node table.

        Raises:
            InvalidArgument
            NodeAlreadyExists
        '''

        # Do not attempt to validate IP addresses for hardware profiles
        # representing remote nodes.
        bValidateIp &= dbHardwareProfile.location != 'remote'

        try:
            if not dbNode.name:
                # Generate unique name for new node
                dbNode.name = self.generate_node_name(
                    session,
                    dbHardwareProfile.nameFormat,
                    rackNumber=dbNode.rack,
                    dns_zone=dns_zone)

            # Create NIC entries
            dbNode.nics = self._initializeNics(dbNode,
                                               dbHardwareProfile,
                                               nic_defs,
                                               bValidateIp=bValidateIp,
                                               bGenerateIp=bGenerateIp)

            self.getLogger().debug(
                'initializeNode(): initialized new node [%s]' % (dbNode.name))
        except Exception:
            with session_nodes_lock:
                self.clear_session_node(dbNode)

            raise
예제 #4
0
def get_nodes():
    n1 = Nodes('compute-01')
    n2 = Nodes('compute-02')
    n3 = Nodes('compute-03')
    n4 = Nodes('compute-04')
    n5 = Nodes('compute-05')
    n6 = Nodes('compute-06')
    n7 = Nodes('compute-07')
    n8 = Nodes('compute-08')

    return [n1, n2, n3, n4, n5, n6, n7, n8]
    def __initialize_node(self, name, db_hardware_profile,
                          db_software_profile):
        node = Nodes(name=name)
        node.softwareprofile = db_software_profile
        node.hardwareprofile = db_hardware_profile
        node.isIdle = False
        node.addHostSession = self.addHostSession

        return node
예제 #6
0
def get_node():
    node = Nodes(name='compute-01.private')
    node.nics = []

    return node
예제 #7
0
    def createNewNode(self,
                      session: Session,
                      addNodeRequest: dict,
                      dbHardwareProfile: HardwareProfiles,
                      dbSoftwareProfile: Optional[SoftwareProfiles] = None,
                      validateIp: bool = True,
                      bGenerateIp: bool = True,
                      dns_zone: Optional[str] = None) -> Nodes:
        """
        Convert the addNodeRequest into a Nodes object

        Raises:
            NicNotFound
        """

        self.getLogger().debug(
            'createNewNode(): session=[%s], addNodeRequest=[%s],'
            ' dbHardwareProfile=[%s], dbSoftwareProfile=[%s],'
            ' validateIp=[%s], bGenerateIp=[%s]' %
            (id(session), addNodeRequest, dbHardwareProfile.name,
             dbSoftwareProfile.name if dbSoftwareProfile else '(none)',
             validateIp, bGenerateIp))

        # This is where the Nodes() object is first created.
        node = Nodes()

        # Set the default node state
        node.state = 'Discovered'

        if 'rack' in addNodeRequest:
            node.rack = addNodeRequest['rack']

        node.addHostSession = addNodeRequest['addHostSession']

        hostname = addNodeRequest['name'] \
            if 'name' in addNodeRequest else None

        # Ensure no conflicting options (ie. specifying host name for
        # hardware profile in which host names are generated)
        self.__validateHostName(hostname, dbHardwareProfile.nameFormat)

        node.name = hostname

        # Complete initialization of new node record
        nic_defs = addNodeRequest['nics'] \
            if 'nics' in addNodeRequest else []

        AddHostServerLocal().initializeNode(session,
                                            node,
                                            dbHardwareProfile,
                                            dbSoftwareProfile,
                                            nic_defs,
                                            bValidateIp=validateIp,
                                            bGenerateIp=bGenerateIp,
                                            dns_zone=dns_zone)

        # Set hardware profile of new node
        node.hardwareProfileId = dbHardwareProfile.id

        # Set software profile of new node; if the software profile is None,
        # attempt to set the software profile to the idle software profile
        # of the associated hardware profile. This may also be None, in
        # which case the software profile is undefined.
        node.softwareprofile = dbSoftwareProfile \
            if dbSoftwareProfile else dbHardwareProfile.idlesoftwareprofile

        node.isIdle = dbSoftwareProfile.isIdle \
            if dbSoftwareProfile else True

        # Return the new node
        return node
예제 #8
0
파일: conftest.py 프로젝트: ilumb/tortuga
def dbm():
    dbm = DbManagerBase(create_engine('sqlite:///:memory:', echo=False))

    dbm.init_database()

    os_info = osInfo.OsInfo('centos', '7.4', 'x86_64')
    os_info.setOsFamilyInfo(osFamilyInfo.OsFamilyInfo('rhel', '7', 'x86_64'))

    settings = {
        'language': 'en',
        'keyboard': 'en_US',
        'timezone': 'UTC',
        'utc': 'true',
        'intWebPort': '8008',
        'intWebServicePort': '8444',
        'adminPort': '8443',
        'eulaAccepted': 'true',
        'depotpath': '/depot',
    }

    installer_fqdn = socket.getfqdn()

    with dbm.session() as session:
        primeDb(session, installer_fqdn, os_info, settings)

        init_global_parameters(session, settings)

        installer_node = session.query(Nodes).filter(
            Nodes.name == installer_fqdn).one()

        os_ = session.query(OperatingSystems).filter(
            OperatingSystems.name == 'centos').one()

        os_family = session.query(OperatingSystemsFamilies).filter(
            OperatingSystemsFamilies.name == 'rhel').one()

        admin = Admins('admin', 'password', 'realname', 'description')
        session.add(admin)

        eth1_network_device = NetworkDevices(name='eth1')

        # Add dummy provisioning network
        network = Networks()
        network.address = '10.2.0.0'
        network.netmask = '255.255.255.0'
        network.name = 'Provisioning network on eth1'
        network.type = 'provision'

        session.add(network)

        installer_nic = Nics()
        installer_nic.network = network
        installer_nic.networkdevice = eth1_network_device

        installer_node.nics = [installer_nic]

        kit = Kits()
        kit.name = 'base'
        kit.version = '6.3.0'
        kit.iteration = '0'
        kit.description = 'Sample base kit'

        installer_component = Components()
        installer_component.name = 'installer'
        installer_component.version = '6.3'
        installer_component.family = [os_family]
        installer_component.kit = kit

        core_component = Components(name='core',
                                    version='6.3',
                                    description='Compute component')
        core_component.family = [os_family]
        core_component.kit = kit

        compute_swprofile = SoftwareProfiles(name='compute')
        compute_swprofile.os = os_
        compute_swprofile.components = [core_component]
        compute_swprofile.type = 'compute'

        localiron_hwprofile = HardwareProfiles(name='localiron')

        session.add(kit)

        for n in range(1, 11):
            compute_node = Nodes('compute-{0:02d}.private'.format(n))
            compute_node.softwareprofile = compute_swprofile
            compute_node.hardwareprofile = localiron_hwprofile

            session.add(compute_node)

        session.commit()

    return dbm