def _discover_nodes(cls, ip=None, node_id=None):
     # type: (Optional[str], Optional[str]) -> Dict[str, AlbaNode]
     """
     :param ip: IP of ALBA node to retrieve
     :type ip: str
     :param node_id: ID of the ALBA node
     :type node_id: str
     :return: Dict with guid of the node mapped to the node itself
     :rtype: Dict[str, AlbaNode]
     """
     nodes = {}
     if ip is not None:
         # List the requested node
         node = AlbaNodeController.model_volatile_node(
             node_id, AlbaNode.NODE_TYPES.ASD, ip)
         data = node.client.get_metadata()
         if data['_success'] is False and data[
                 '_error'] == 'Invalid credentials':
             raise HttpNotAcceptableException(
                 error='invalid_data',
                 error_description='Invalid credentials')
         if data['node_id'] != node_id:
             raise HttpNotAcceptableException(
                 error='invalid_data',
                 error_description='Unexpected node identifier. {0} vs {1}'.
                 format(data['node_id'], node_id))
         nodes[node.guid] = node
     else:
         nodes.update(AlbaNodeController.discover_nodes())
     return nodes
 def generate_empty_slot(self, albanode):
     """
     Generates an empty slot on the Alba Node
     :param albanode: The AlbaNode to generate a slot on
     :type albanode: ovs.dal.hybrids.albanode.AlbaNode
     :return: slot information
     :rtype: dict
     """
     return AlbaNodeController.generate_empty_slot(albanode.guid)
Пример #3
0
    def add_alba_backend(name, scaling='LOCAL', wait=True):
        """
        Put an ALBA backend in the model
        :param name: Name of the backend
        :param scaling: Alba backend can be LOCAL or GLOBAL
        :param wait: Wait for backend to enter RUNNING state
        :return: Newly created ALBA backend
        """
        alba_backend = GeneralAlba.get_by_name(name)
        if alba_backend is None:
            backend = GeneralBackend.add_backend(name, 'alba')
            alba_backend = AlbaBackend(GeneralAlba.api.add('alba/backends', {'backend_guid': backend.guid,
                                                                             'scaling': scaling})['guid'])
            if wait is True:
                GeneralAlba.wait_for_alba_backend_status(alba_backend)

        alba_nodes = [alba_node for alba_node in Configuration.list('/ovs/alba/asdnodes')]
        if len(alba_nodes):
            AlbaNodeController.model_albanodes()

        return GeneralAlba.get_by_name(name)
Пример #4
0
    def initialise_disks(alba_backend, nr_of_disks, disk_type):
        """
        Initialize disks
        :param alba_backend: ALBA backend
        :param nr_of_disks: Amount of disks to initialize
        :param disk_type: Type of disks
        :return: None
        """
        # Assume no disks are claimed by a remote environment
        alba_backend.invalidate_dynamics(['local_stack'])
        local_stack = alba_backend.local_stack

        initialised_disks = 0
        uninitialised_disks = 0
        uninitialized_disk_names = {}
        for disks in local_stack.values():
            for disk_id, disk in disks.iteritems():
                if disk['status'] == 'initialized':
                    initialised_disks += 1
                elif disk['status'] == 'uninitialized':
                    uninitialised_disks += 1
                    if disk['node_id'] in uninitialized_disk_names.keys():
                        uninitialized_disk_names[disk['node_id']].append(disk_id)
                    else:
                        uninitialized_disk_names[disk['node_id']] = [disk_id]
        nr_of_disks_to_init = nr_of_disks - initialised_disks
        if nr_of_disks_to_init <= 0:
            return True

        assert uninitialised_disks >= nr_of_disks_to_init, "Not enough disks to initialize!"

        disks_to_init = GeneralAlba.filter_disks(uninitialized_disk_names, nr_of_disks_to_init, disk_type)
        disks_found = 0
        for node_id, disks in disks_to_init.iteritems():
            disks_found += len(disks)
        assert disks_found >= nr_of_disks_to_init, "Not enough disks to initialize!"

        for node_id, disks in disks_to_init.iteritems():
            alba_node = AlbaNodeList.get_albanode_by_node_id(node_id)
            failures = AlbaNodeController.initialize_disks(alba_node.guid, dict(('/dev/disk/by-id/' + disk_id, 1) for disk_id in disks))
            assert not failures,\
                'Alba disk initialization failed for (some) disks: {0}'.format(failures)