Example #1
0
    def test_existing_ips(self):
        action = baremetal.GetCandidateNodes([], [], [], self.existing_nodes)
        result = action._existing_ips()

        self.assertEqual(
            {('10.0.0.1', 623), ('10.0.0.1', 6235), ('10.0.0.2', None),
             ('10.0.0.3', 6230)}, set(result))
 def test_invalid_subnet(self):
     action = baremetal.GetCandidateNodes(
         'meow',
         [623, 6230, 6235],
         [['admin', 'password'], ['admin', 'admin']],
         self.existing_nodes)
     result = action.run(mock.Mock())
     self.assertTrue(result.is_error())
    def test_with_subnet(self):
        action = baremetal.GetCandidateNodes(
            '10.0.0.0/30',
            [623, 6230, 6235],
            [['admin', 'password'], ['admin', 'admin']],
            self.existing_nodes)
        result = action.run(mock.Mock())

        self.assertEqual([
            {'ip': '10.0.0.1', 'port': 6230,
             'username': '******', 'password': '******'},
            {'ip': '10.0.0.1', 'port': 6230,
             'username': '******', 'password': '******'},
        ], result)
def discover_and_enroll(clients, ip_addresses, credentials, kernel_name,
                        ramdisk_name, instance_boot_option,
                        existing_nodes=None, ports=None):
    """Discover nodes and enroll baremetal nodes.

    :param clients: application client object.
    :type clients: Object

    :param ip_addresses: List of IP addresses.
    :type ip_addresses: List || String

    :param credentials: Credential information object
    :type credentials: Tuple

    :param kernel_name: Kernel to use
    :type kernel_name: String

    :param ramdisk_name: RAMDISK to use
    :type ramdisk_name: String

    :param instance_boot_option: Boot options to use
    :type instance_boot_option: String

    :param existing_nodes: List of nodes already discovered. If this is
                           undefined this object will be set to an empty
                           array.
    :type existing_nodes: List

    :param ports: List of ports, if no ports are provided the list of ports
                  will be limted to [623].
    :type ports: List

    :returns: List
    """

    if not ports:
        ports = [623]

    if not existing_nodes:
        existing_nodes = list()

    context = clients.tripleoclient.create_mistral_context()

    get_candiate_nodes = baremetal.GetCandidateNodes(
        ip_addresses,
        ports,
        credentials,
        existing_nodes
    )
    probed_nodes = list()
    for node in get_candiate_nodes.run(context=context):
        probed_nodes.append(
            baremetal.ProbeNode(**node).run(context=context)
        )
        print('Successfully probed node IP {}'.format(node['ip']))

    return register_or_update(
        clients=clients,
        nodes_json=probed_nodes,
        instance_boot_option=instance_boot_option,
        kernel_name=kernel_name,
        ramdisk_name=ramdisk_name
    )