示例#1
0
 def model_albanodes(**kwargs):
     """
     Add all ALBA nodes known to the config platform to the model
     :param kwargs: Kwargs containing information regarding the node
     :type kwargs: dict
     :return: None
     :rtype: NoneType
     """
     _ = kwargs
     if Configuration.dir_exists('/ovs/alba/asdnodes'):
         for node_id in Configuration.list('/ovs/alba/asdnodes'):
             node = AlbaNodeList.get_albanode_by_node_id(node_id)
             if node is None:
                 node = AlbaNode()
             main_config = Configuration.get(
                 '/ovs/alba/asdnodes/{0}/config/main'.format(node_id))
             node.type = 'ASD'
             node.node_id = node_id
             node.ip = main_config['ip']
             node.port = main_config['port']
             node.username = main_config['username']
             node.password = main_config['password']
             node.storagerouter = StorageRouterList.get_by_ip(
                 main_config['ip'])
             node.save()
 def register(node_id):
     """
     Adds a Node with a given node_id to the model
     :param node_id: ID of the ALBA node
     :type node_id: str
     :return: None
     """
     node = AlbaNodeList.get_albanode_by_node_id(node_id)
     if node is None:
         main_config = Configuration.get('/ovs/alba/asdnodes/{0}/config/main'.format(node_id))
         node = AlbaNode()
         node.ip = main_config['ip']
         node.port = main_config['port']
         node.username = main_config['username']
         node.password = main_config['password']
         node.storagerouter = StorageRouterList.get_by_ip(main_config['ip'])
     data = node.client.get_metadata()
     if data['_success'] is False and data['_error'] == 'Invalid credentials':
         raise RuntimeError('Invalid credentials')
     if data['node_id'] != node_id:
         AlbaNodeController._logger.error('Unexpected node_id: {0} vs {1}'.format(data['node_id'], node_id))
         raise RuntimeError('Unexpected node identifier')
     node.node_id = node_id
     node.type = 'ASD'
     node.save()
     AlbaController.checkup_maintenance_agents.delay()
示例#3
0
 def get_albanode_by_node_id(alba_node_id):
     """
     Fetches the alba node object with the specified id
     :param alba_node_id: id of the alba node
     :return:
     """
     return AlbaNodeList.get_albanode_by_node_id(alba_node_id)
 def get_node_by_id(node_id):
     """
     Retrieve ASD node by ID
     :param node_id: ID of the ASD node
     :return: ASD node information
     """
     return AlbaNodeList.get_albanode_by_node_id(node_id=node_id)
    def register(node_id):
        """
        Adds a Node with a given node_id to the model
        :param node_id: ID of the ALBA node
        :type node_id: str

        :return: None
        """
        node = AlbaNodeList.get_albanode_by_node_id(node_id)
        if node is None:
            main_config = EtcdConfiguration.get('/ovs/alba/asdnodes/{0}/config/main'.format(node_id))
            node = AlbaNode()
            node.ip = main_config['ip']
            node.port = main_config['port']
            node.username = main_config['username']
            node.password = main_config['password']
            node.storagerouter = StorageRouterList.get_by_ip(main_config['ip'])
        data = node.client.get_metadata()
        if data['_success'] is False and data['_error'] == 'Invalid credentials':
            raise RuntimeError('Invalid credentials')
        if data['node_id'] != node_id:
            AlbaNodeController._logger.error('Unexpected node_id: {0} vs {1}'.format(data['node_id'], node_id))
            raise RuntimeError('Unexpected node identifier')
        node.node_id = node_id
        node.type = 'ASD'
        node.save()

        # increase maintenance agents count for all nodes by 1
        for backend in AlbaBackendList.get_albabackends():
            nr_of_agents_key = AlbaNodeController.NR_OF_AGENTS_ETCD_TEMPLATE.format(backend.guid)
            if EtcdConfiguration.exists(nr_of_agents_key):
                EtcdConfiguration.set(nr_of_agents_key, int(EtcdConfiguration.get(nr_of_agents_key) + 1))
            else:
                EtcdConfiguration.set(nr_of_agents_key, 1)
        AlbaNodeController.checkup_maintenance_agents()
示例#6
0
 def register_node(node_cluster_guid, node_id=None, node_ids=None):
     # type: (str, str, List[str]) -> None
     """
     Register a AlbaNode to the AlbaNodeCluster
     :param node_cluster_guid: Guid of the AlbaNodeCluster to add the node to
     :type node_cluster_guid: basestring
     :param node_id: ID of the ALBA node to register
     :type node_id: basestring
     :param node_ids: List of IDs of AlbaNodes to register
     :type node_ids: list[str]
     :return: None
     :rtype: NoneType
     """
     if all(x is None for x in [node_id, node_ids]):
         raise ValueError('Either node_id or node_ids must be given')
     if node_ids is None:
         node_ids = [node_id]
     an_cluster = AlbaNodeCluster(node_cluster_guid)
     messages = []
     for node_id in node_ids:
         try:
             an_node = AlbaNodeList.get_albanode_by_node_id(node_id)
             if an_node is None:
                 messages.append(
                     'No AlbaNode found with ID {0}'.format(node_id))
                 continue
             # Validation
             for slot_id, slot_info in an_node.stack.iteritems():
                 for osd_id, osd_info in slot_info['osds'].iteritems():
                     claimed_by = osd_info.get('claimed_by')
                     if claimed_by is not None:  # Either UNKNOWN or a GUID:
                         if claimed_by == AlbaNode.OSD_STATUSES.UNKNOWN:
                             raise RuntimeError(
                                 'Unable to link AlbaNode {0}. No information could be retrieved about OSD {1}'
                                 .format(node_id, osd_id))
                         raise RuntimeError(
                             'Unable to link AlbaNode {0} because it already has OSDs which are claimed'
                             .format(node_id))
             try:
                 AlbaNodeClusterController.register_node_to_cluster(
                     an_cluster.guid, an_node.node_id)
             except Exception:
                 message = 'Unable to register the node under cluster'
                 AlbaNodeClusterController._logger.exception(message)
                 messages.append(message)
                 continue
             an_node.alba_node_cluster = an_cluster
             an_node.save()
         except Exception:
             message = 'Unhandled Exception occurred during the registering of AlbaNode with id {0} under AlbaNodeCluster {1}'.format(
                 node_id, node_cluster_guid)
             messages.append(message)
             AlbaNodeClusterController._logger.exception(message)
     if len(messages) > 0:
         raise ValueError(
             'Errors occurred while registering AlbaNodes with IDs {0}:\n - {1}'
             .format(node_ids, '\n - '.join(messages)))
    def filter_disks(disk_names, amount, disk_type):
        """
        Filter the available disks
        :param disk_names: Disks to filter
        :param amount: Amount to retrieve
        :param disk_type: Type of disk
        :return: Filtered disks
        """
        node_ids = []
        list_of_available_disks = {}
        filtered_disks = {}
        disk_count = 0
        # disk_names = dictionary with node_ids as keys and values as a list of uninitialised disk names
        # {u'InA44YDJTKxFGvIKqD3CxYMlK7XxryZ0': [u'ata-TOSHIBA_MK2002TSKB_52Q2KSOTF',
        #                                        u'ata-TOSHIBA_MK2002TSKB_52Q3KR6TF',
        #                                        u'ata-TOSHIBA_MK2002TSKB_52Q2KSORF',
        #                                        u'ata-TOSHIBA_MK2002TSKB_52Q2KSOVF',
        #                                        u'ata-TOSHIBA_MK2002TSKB_52Q2KSOUF']}
        for node_id in disk_names.iterkeys():
            node_ids.append(node_id)
            list_of_available_disks[node_id] = []
            filtered_disks[node_id] = []
            alba_node = AlbaNodeList.get_albanode_by_node_id(node_id)
            storagerouter = GeneralStorageRouter.get_storage_router_by_ip(ip=alba_node.ip)
            root_client = SSHClient(storagerouter, username='******')
            hdds, ssds = GeneralDisk.get_physical_disks(client=root_client)
            if disk_type == 'SATA':
                for hdd in hdds.values():
                    # add it to list_of_available_disks only if it's found in the uninitialised list for that node
                    if hdd['name'] in disk_names[node_id]:
                        list_of_available_disks[node_id].append(hdd)
            if disk_type == 'SSD':
                for ssd in ssds.values():
                    # add it to list_of_available_disks only if it's found in the uninitialised list for that node
                    if ssd['name'] in disk_names[node_id]:
                        list_of_available_disks[node_id].append(ssd)
            disk_count += len(list_of_available_disks[node_id])

        count = 0
        # all disks might be on a single node so we are going with the check to max of what we need
        for disk_index in range(amount):
            for node_id in node_ids:
                # if we still need disks we will add all disks found at the count value index in the list_of_available_disks disk lists
                if count < amount:
                    if disk_index < len(list_of_available_disks[node_id]):
                        filtered_disks[node_id].append('/dev/disk/by-id/' + list_of_available_disks[node_id][disk_index]['name'])
                        count += 1
        # this should run through the whole list even if we haven't reached the amount of disks needed
        return filtered_disks
示例#8
0
 def register(node_id=None, node_type=None, name=None):
     """
     Adds a Node with a given node_id to the model
     :param node_id: ID of the ALBA node
     :type node_id: str
     :param node_type: Type of the node to create
     :type node_type: str
     :param name: Optional name of the node
     :type name: str
     :return: None
     :rtype: NoneType
     """
     # Generic is a special case. Nothing is registered within config mgmt
     if node_type == AlbaNode.NODE_TYPES.GENERIC:
         node = AlbaNode()
         node.name = name
         node.node_id = ''.join(
             random.choice(string.ascii_letters + string.digits)
             for _ in range(32))
         node.type = AlbaNode.NODE_TYPES.GENERIC
         node.save()
     else:
         # Both S3 and ASD type can be added now
         if node_id is None:
             raise RuntimeError('A node_id must be given for type ASD/S3')
         node = AlbaNodeList.get_albanode_by_node_id(
             node_id) or AlbaNodeController.get_discovered_node(node_id)
         if not node:
             # No node could be found in the model or within the discovered nodes. User might have specified the ID
             # of a node that does not exist
             raise RuntimeError(
                 'No node with node_id {0} was found'.format(node_id))
         data = node.client.get_metadata()
         if data['_success'] is False and data[
                 '_error'] == 'Invalid credentials':
             raise RuntimeError('Invalid credentials')
         if data['node_id'] != node_id:
             AlbaNodeController._logger.error(
                 'Unexpected node_id: {0} vs {1}'.format(
                     data['node_id'], node_id))
             raise RuntimeError('Unexpected node identifier')
         if node.type == AlbaNode.NODE_TYPES.S3:
             # The transaction Arakoon is needed. This wil check deployment & extend
             AlbaArakoonController.configure_s3_transaction_cluster()
         node.volatile = False
         node.save()
     AlbaController.checkup_maintenance_agents.delay()
示例#9
0
 def unregister_node(node_cluster_guid, node_id):
     # type: (str) -> None
     """
     Unregisters an AlbaNode from the AlbaNodeCluster
     This will update the cluster to no longer work with active/passive
     :param node_cluster_guid: Guid of the AlbaNodeCluster to add the node to
     :type node_cluster_guid: basestring
     :param node_id: ID of the ALBA node to register
     :type node_id: basestring
     :return: None
     :rtype: NoneType
     """
     _ = node_cluster_guid
     an_node = AlbaNodeList.get_albanode_by_node_id(node_id)
     an_node.alba_node_cluster = None
     an_node.save()
     raise NotImplementedError(
         'Actions after removing the relation has not yet been implemented')
    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)
 def model_albanodes(**kwargs):
     """
     Add all ALBA nodes known to the config platform to the model
     :param kwargs: Kwargs containing information regarding the node
     :type kwargs: dict
     :return: None
     """
     _ = kwargs
     if Configuration.dir_exists('/ovs/alba/asdnodes'):
         for node_id in Configuration.list('/ovs/alba/asdnodes'):
             node = AlbaNodeList.get_albanode_by_node_id(node_id)
             if node is None:
                 node = AlbaNode()
             main_config = Configuration.get('/ovs/alba/asdnodes/{0}/config/main'.format(node_id))
             node.type = 'ASD'
             node.node_id = node_id
             node.ip = main_config['ip']
             node.port = main_config['port']
             node.username = main_config['username']
             node.password = main_config['password']
             node.storagerouter = StorageRouterList.get_by_ip(main_config['ip'])
             node.save()