示例#1
0
    def _find_first_available_id(self, dpid=None):

        def _is_valid_mac_address(dpid):
            return re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$",
                     dpid)

        # If a dpid is provided then validate whether it is a MAC address
        switch_id = 1
        if dpid:
            dpid = dpid.lower()
            if not _is_valid_mac_address(dpid):
                raise MacAddressError('Invalid-mac-address-format')
            switch_id = int(dpid.replace(':', ''), 16)

        logical_devices = self.root_proxy.get('/logical_devices')
        existing_ids = set(ld.id for ld in logical_devices)
        existing_datapath_ids = set(ld.datapath_id for ld in logical_devices)
        core_id = registry('core').core_store_id

        while True:
            ld_id, dp_id = create_cluster_logical_device_ids(core_id, switch_id)
            id_exists = dp_id in existing_datapath_ids or ld_id in \
                                                            existing_ids
            if not id_exists:
                return ld_id, dp_id
            else:
                if dpid:
                    raise MacAddressError('Already-registered-mac-address')
                else:
                    switch_id += 1
示例#2
0
    def _find_first_available_id(self, dpid=None):

        def _is_valid_mac_address(dpid):
            return re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$",
                     dpid)

        # If a dpid is provided then validate whether it is a MAC address
        switch_id = 1
        if dpid:
            dpid = dpid.lower()
            if not _is_valid_mac_address(dpid):
                raise MacAddressError('Invalid-mac-address-format')
            switch_id = int(dpid.replace(':', ''), 16)

        logical_devices = self.root_proxy.get('/logical_devices')
        existing_ids = set(ld.id for ld in logical_devices)
        existing_datapath_ids = set(ld.datapath_id for ld in logical_devices)
        core_id = registry('core').core_store_id

        while True:
            ld_id, dp_id = create_cluster_logical_device_ids(core_id, switch_id)
            id_exists = dp_id in existing_datapath_ids or ld_id in \
                                                            existing_ids
            if not id_exists:
                return ld_id, dp_id
            else:
                if dpid:
                    raise MacAddressError('Already-registered-mac-address')
                else:
                    switch_id += 1
示例#3
0
 def _find_first_available_id(self):
     logical_devices = self.root_proxy.get('/logical_devices')
     existing_ids = set(ld.id for ld in logical_devices)
     existing_datapath_ids = set(ld.datapath_id for ld in logical_devices)
     core_id = registry('core').core_store_id
     i = 1
     while True:
         ld_id, dp_id = create_cluster_logical_device_ids(core_id, i)
         if dp_id not in existing_datapath_ids and ld_id not in existing_ids:
             return ld_id, dp_id
         i += 1
示例#4
0
    def _create_cluster_ids_from_dpid(self, dpid):
        """
        Create a logical device id using a datapath id.
        :param dpid: Must be present and formatted as a mac address
        :return: a unique logical device id and a formatted datapath id.   If
        the dpid was already registered then an exception will be raised.
        """
        switch_id = int(dpid.replace(':', ''), 16)
        logical_devices = self.root_proxy.get('/logical_devices')
        existing_ids = set(ld.id for ld in logical_devices)
        existing_datapath_ids = set(ld.datapath_id for ld in logical_devices)
        core_id = registry('core').core_store_id

        ld_id, dp_id = create_cluster_logical_device_ids(core_id, switch_id)
        ids_exist = dp_id in existing_datapath_ids or \
                    ld_id in existing_ids
        if not ids_exist:
            return ld_id, dp_id
        else:
            self.log.error('ID-already-registered',
                           logical_id=ld_id,
                           dpid=dpid)
            raise IDError('ID-already-registered')