Exemplo n.º 1
0
    def _find_pool_info(self):
        root = huawei_utils.parse_xml_file(self.xml_conf)
        pool_name = root.findtext('LUN/StoragePool')
        if not pool_name:
            err_msg = _("Invalid resource pool: %s") % pool_name
            LOG.error(err_msg)
            raise exception.InvalidInput(err_msg)

        url = self.url + "/storagepool"
        result = self.call(url, None)
        self._assert_rest_result(result, 'Query resource pool error')

        poolinfo = {}
        if "data" in result:
            for item in result['data']:
                if pool_name.strip() == item['NAME']:
                    poolinfo['ID'] = item['ID']
                    poolinfo['CAPACITY'] = item['USERFREECAPACITY']
                    poolinfo['TOTALCAPACITY'] = item['USERTOTALCAPACITY']
                    break

        if not poolinfo:
            msg = (_('Get pool info error, pool name is:%s') % pool_name)
            LOG.error(msg)
            raise exception.CinderException(msg)

        return poolinfo
Exemplo n.º 2
0
    def _find_pool_info(self):
        root = huawei_utils.parse_xml_file(self.xml_conf)
        pool_name = root.findtext('LUN/StoragePool')
        if not pool_name:
            err_msg = _("Invalid resource pool: %s") % pool_name
            LOG.error(err_msg)
            raise exception.InvalidInput(err_msg)

        url = self.url + "/storagepool"
        result = self.call(url, None)
        self._assert_rest_result(result, 'Query resource pool error')

        poolinfo = {}
        if "data" in result:
            for item in result['data']:
                if pool_name.strip() == item['NAME']:
                    poolinfo['ID'] = item['ID']
                    poolinfo['CAPACITY'] = item['USERFREECAPACITY']
                    poolinfo['TOTALCAPACITY'] = item['USERTOTALCAPACITY']
                    break

        if not poolinfo:
            msg = (_('Get pool info error, pool name is:%s') % pool_name)
            LOG.error(msg)
            raise exception.CinderException(msg)

        return poolinfo
Exemplo n.º 3
0
    def _check_conf_file(self):
        """Check the config file, make sure the essential items are set."""
        root = huawei_utils.parse_xml_file(self.xml_conf)
        check_list = ['Storage/HVSURL', 'Storage/UserName',
                      'Storage/UserPassword']
        for item in check_list:
            if not huawei_utils.is_xml_item_exist(root, item):
                err_msg = (_('_check_conf_file: Config file invalid. '
                             '%s must be set.') % item)
                LOG.error(err_msg)
                raise exception.InvalidInput(reason=err_msg)

        # make sure storage pool is set
        if not huawei_utils.is_xml_item_exist(root, 'LUN/StoragePool'):
            err_msg = _('_check_conf_file: Config file invalid. '
                        'StoragePool must be set.')
            LOG.error(err_msg)
            raise exception.InvalidInput(reason=err_msg)

        # make sure host os type valid
        if huawei_utils.is_xml_item_exist(root, 'Host', 'OSType'):
            os_list = huawei_utils.os_type.keys()
            if not huawei_utils.is_xml_item_valid(root, 'Host', os_list,
                                                  'OSType'):
                err_msg = (_('_check_conf_file: Config file invalid. '
                             'Host OSType invalid.\n'
                             'The valid values are: %(os_list)s')
                           % {'os_list': os_list})
                LOG.error(err_msg)
                raise exception.InvalidInput(reason=err_msg)
Exemplo n.º 4
0
    def _get_lun_conf_params(self):
        """Get parameters from config file for creating lun."""
        # Default lun set information
        lunsetinfo = {
            "LUNType": "Thick",
            "StripUnitSize": "64",
            "WriteType": "1",
            "MirrorSwitch": "1",
            "PrefetchType": "3",
            "PrefetchValue": "0",
            "PrefetchTimes": "0",
        }

        root = huawei_utils.parse_xml_file(self.xml_conf)
        luntype = root.findtext("LUN/LUNType")
        if luntype:
            if luntype.strip() in ["Thick", "Thin"]:
                lunsetinfo["LUNType"] = luntype.strip()
                if luntype.strip() == "Thick":
                    lunsetinfo["LUNType"] = 0
                if luntype.strip() == "Thin":
                    lunsetinfo["LUNType"] = 1

            elif luntype is not "" and luntype is not None:
                err_msg = _('Config file is wrong. LUNType must be "Thin"' ' or "Thick". LUNType:%(fetchtype)s') % {
                    "fetchtype": luntype
                }
                LOG.error(err_msg)
                raise exception.VolumeBackendAPIException(data=err_msg)

        stripunitsize = root.findtext("LUN/StripUnitSize")
        if stripunitsize is not None:
            lunsetinfo["StripUnitSize"] = stripunitsize.strip()
        writetype = root.findtext("LUN/WriteType")
        if writetype is not None:
            lunsetinfo["WriteType"] = writetype.strip()
        mirrorswitch = root.findtext("LUN/MirrorSwitch")
        if mirrorswitch is not None:
            lunsetinfo["MirrorSwitch"] = mirrorswitch.strip()

        prefetch = root.find("LUN/Prefetch")
        fetchtype = prefetch.attrib["Type"]
        if prefetch is not None and prefetch.attrib["Type"]:
            if fetchtype in ["0", "1", "2", "3"]:
                lunsetinfo["PrefetchType"] = fetchtype.strip()
                typevalue = prefetch.attrib["Value"].strip()
                if lunsetinfo["PrefetchType"] == "1":
                    lunsetinfo["PrefetchValue"] = typevalue
                elif lunsetinfo["PrefetchType"] == "2":
                    lunsetinfo["PrefetchValue"] = typevalue
            else:
                err_msg = _(
                    "PrefetchType config is wrong. PrefetchType" " must in 1,2,3,4. fetchtype is:%(fetchtype)s"
                ) % {"fetchtype": fetchtype}
                LOG.error(err_msg)
                raise exception.CinderException(err_msg)
        else:
            LOG.debug(_("Use default prefetch fetchtype. " "Prefetch fetchtype:Intelligent."))

        return lunsetinfo
Exemplo n.º 5
0
    def _find_pool_info(self):
        root = huawei_utils.parse_xml_file(self.xml_conf)
        pool_name = root.findtext("LUN/StoragePool")
        if not pool_name:
            err_msg = _("Invalid resource pool: %s") % pool_name
            LOG.error(err_msg)
            raise exception.InvalidInput(err_msg)

        url = self.url + "/storagepool"
        result = self.call(url, None)
        self._assert_rest_result(result, "Query resource pool error")

        poolinfo = {}
        if "data" in result:
            for item in result["data"]:
                if pool_name.strip() == item["NAME"]:
                    poolinfo["ID"] = item["ID"]
                    poolinfo["CAPACITY"] = item["USERFREECAPACITY"]
                    poolinfo["TOTALCAPACITY"] = item["USERTOTALCAPACITY"]
                    break

        if not poolinfo:
            msg = _("Get pool info error, pool name is:%s") % pool_name
            LOG.error(msg)
            raise exception.CinderException(msg)

        return poolinfo
Exemplo n.º 6
0
    def _check_conf_file(self):
        """Check the config file, make sure the essential items are set."""
        root = huawei_utils.parse_xml_file(self.xml_conf)
        check_list = ["Storage/HVSURL", "Storage/UserName", "Storage/UserPassword"]
        for item in check_list:
            if not huawei_utils.is_xml_item_exist(root, item):
                err_msg = _("_check_conf_file: Config file invalid. " "%s must be set.") % item
                LOG.error(err_msg)
                raise exception.InvalidInput(reason=err_msg)

        # make sure storage pool is set
        if not huawei_utils.is_xml_item_exist(root, "LUN/StoragePool"):
            err_msg = _("_check_conf_file: Config file invalid. " "StoragePool must be set.")
            LOG.error(err_msg)
            raise exception.InvalidInput(reason=err_msg)

        # make sure host os type valid
        if huawei_utils.is_xml_item_exist(root, "Host", "OSType"):
            os_list = huawei_utils.os_type.keys()
            if not huawei_utils.is_xml_item_valid(root, "Host", os_list, "OSType"):
                err_msg = _(
                    "_check_conf_file: Config file invalid. "
                    "Host OSType invalid.\n"
                    "The valid values are: %(os_list)s"
                ) % {"os_list": os_list}
                LOG.error(err_msg)
                raise exception.InvalidInput(reason=err_msg)
Exemplo n.º 7
0
    def _check_conf_file(self):
        """Check the config file, make sure the essential items are set."""
        root = huawei_utils.parse_xml_file(self.xml_conf)
        check_list = [
            'Storage/HVSURL', 'Storage/UserName', 'Storage/UserPassword'
        ]
        for item in check_list:
            if not huawei_utils.is_xml_item_exist(root, item):
                err_msg = (_('_check_conf_file: Config file invalid. '
                             '%s must be set.') % item)
                LOG.error(err_msg)
                raise exception.InvalidInput(reason=err_msg)

        # make sure storage pool is set
        if not huawei_utils.is_xml_item_exist(root, 'LUN/StoragePool'):
            err_msg = _('_check_conf_file: Config file invalid. '
                        'StoragePool must be set.')
            LOG.error(err_msg)
            raise exception.InvalidInput(reason=err_msg)

        # make sure host os type valid
        if huawei_utils.is_xml_item_exist(root, 'Host', 'OSType'):
            os_list = huawei_utils.os_type.keys()
            if not huawei_utils.is_xml_item_valid(root, 'Host', os_list,
                                                  'OSType'):
                err_msg = (_('_check_conf_file: Config file invalid. '
                             'Host OSType invalid.\n'
                             'The valid values are: %(os_list)s') % {
                                 'os_list': os_list
                             })
                LOG.error(err_msg)
                raise exception.InvalidInput(reason=err_msg)
Exemplo n.º 8
0
    def _get_iscsi_conf(self, filename):
        """Get iSCSI info from config file.

        This function returns a dict:
        {'DefaultTargetIP': '11.11.11.11',
         'Initiator': [{'Name': 'iqn.xxxxxx.1', 'TargetIP': '11.11.11.12'},
                       {'Name': 'iqn.xxxxxx.2', 'TargetIP': '11.11.11.13'}
                      ]
        }

        """

        iscsiinfo = {}
        root = huawei_utils.parse_xml_file(filename)

        default_ip = root.findtext('iSCSI/DefaultTargetIP')
        if default_ip:
            iscsiinfo['DefaultTargetIP'] = default_ip.strip()
        else:
            iscsiinfo['DefaultTargetIP'] = None
        initiator_list = []
        tmp_dic = {}
        for dic in root.findall('iSCSI/Initiator'):
            # Strip the values of dict.
            for k, v in dic.items():
                tmp_dic[k] = v.strip()
            initiator_list.append(tmp_dic)
        iscsiinfo['Initiator'] = initiator_list
        return iscsiinfo
Exemplo n.º 9
0
    def _get_lun_conf_params(self):
        """Get parameters from config file for creating lun."""
        # Default lun set information
        lunsetinfo = {'LUNType': 'Thick',
                      'StripUnitSize': '64',
                      'WriteType': '1',
                      'MirrorSwitch': '1',
                      'PrefetchType': '3',
                      'PrefetchValue': '0',
                      'PrefetchTimes': '0'}

        root = huawei_utils.parse_xml_file(self.xml_conf)
        luntype = root.findtext('LUN/LUNType')
        if luntype:
            if luntype.strip() in ['Thick', 'Thin']:
                lunsetinfo['LUNType'] = luntype.strip()
                if luntype.strip() == 'Thick':
                    lunsetinfo['LUNType'] = 0
                if luntype.strip() == 'Thin':
                    lunsetinfo['LUNType'] = 1

            elif luntype is not '' and luntype is not None:
                err_msg = (_('Config file is wrong. LUNType must be "Thin"'
                             ' or "Thick". LUNType:%(fetchtype)s')
                           % {'fetchtype': luntype})
                LOG.error(err_msg)
                raise exception.VolumeBackendAPIException(data=err_msg)

        stripunitsize = root.findtext('LUN/StripUnitSize')
        if stripunitsize is not None:
            lunsetinfo['StripUnitSize'] = stripunitsize.strip()
        writetype = root.findtext('LUN/WriteType')
        if writetype is not None:
            lunsetinfo['WriteType'] = writetype.strip()
        mirrorswitch = root.findtext('LUN/MirrorSwitch')
        if mirrorswitch is not None:
            lunsetinfo['MirrorSwitch'] = mirrorswitch.strip()

        prefetch = root.find('LUN/Prefetch')
        fetchtype = prefetch.attrib['Type']
        if prefetch is not None and prefetch.attrib['Type']:
            if fetchtype in ['0', '1', '2', '3']:
                lunsetinfo['PrefetchType'] = fetchtype.strip()
                typevalue = prefetch.attrib['Value'].strip()
                if lunsetinfo['PrefetchType'] == '1':
                    lunsetinfo['PrefetchValue'] = typevalue
                elif lunsetinfo['PrefetchType'] == '2':
                    lunsetinfo['PrefetchValue'] = typevalue
            else:
                err_msg = (_('PrefetchType config is wrong. PrefetchType'
                             ' must in 1,2,3,4. fetchtype is:%(fetchtype)s')
                           % {'fetchtype': fetchtype})
                LOG.error(err_msg)
                raise exception.CinderException(err_msg)
        else:
            LOG.debug('Use default prefetch fetchtype. '
                      'Prefetch fetchtype:Intelligent.')

        return lunsetinfo
Exemplo n.º 10
0
    def _get_lun_conf_params(self):
        """Get parameters from config file for creating lun."""
        # Default lun set information
        lunsetinfo = {'LUNType': 'Thick',
                      'StripUnitSize': '64',
                      'WriteType': '1',
                      'MirrorSwitch': '1',
                      'PrefetchType': '3',
                      'PrefetchValue': '0',
                      'PrefetchTimes': '0'}

        root = huawei_utils.parse_xml_file(self.xml_conf)
        luntype = root.findtext('LUN/LUNType')
        if luntype:
            if luntype.strip() in ['Thick', 'Thin']:
                lunsetinfo['LUNType'] = luntype.strip()
                if luntype.strip() == 'Thick':
                    lunsetinfo['LUNType'] = 0
                if luntype.strip() == 'Thin':
                    lunsetinfo['LUNType'] = 1

            elif luntype is not '' and luntype is not None:
                err_msg = (_('Config file is wrong. LUNType must be "Thin"'
                             ' or "Thick". LUNType:%(fetchtype)s')
                           % {'fetchtype': luntype})
                LOG.error(err_msg)
                raise exception.VolumeBackendAPIException(data=err_msg)

        stripunitsize = root.findtext('LUN/StripUnitSize')
        if stripunitsize is not None:
            lunsetinfo['StripUnitSize'] = stripunitsize.strip()
        writetype = root.findtext('LUN/WriteType')
        if writetype is not None:
            lunsetinfo['WriteType'] = writetype.strip()
        mirrorswitch = root.findtext('LUN/MirrorSwitch')
        if mirrorswitch is not None:
            lunsetinfo['MirrorSwitch'] = mirrorswitch.strip()

        prefetch = root.find('LUN/Prefetch')
        fetchtype = prefetch.attrib['Type']
        if prefetch is not None and prefetch.attrib['Type']:
            if fetchtype in ['0', '1', '2', '3']:
                lunsetinfo['PrefetchType'] = fetchtype.strip()
                typevalue = prefetch.attrib['Value'].strip()
                if lunsetinfo['PrefetchType'] == '1':
                    lunsetinfo['PrefetchValue'] = typevalue
                elif lunsetinfo['PrefetchType'] == '2':
                    lunsetinfo['PrefetchValue'] = typevalue
            else:
                err_msg = (_('PrefetchType config is wrong. PrefetchType'
                             ' must in 1,2,3,4. fetchtype is:%(fetchtype)s')
                           % {'fetchtype': fetchtype})
                LOG.error(err_msg)
                raise exception.CinderException(err_msg)
        else:
            LOG.debug('Use default prefetch fetchtype. '
                      'Prefetch fetchtype:Intelligent.')

        return lunsetinfo
Exemplo n.º 11
0
 def _get_conf_info(self, filename):
     """Get product type and connection protocol from config file."""
     root = huawei_utils.parse_xml_file(filename)
     product = root.findtext('Storage/Product').strip()
     protocol = root.findtext('Storage/Protocol').strip()
     if (product in self._product.keys() and
             protocol in self._protocol.keys()):
         return (product, protocol)
     else:
         msg = (_('"Product" or "Protocol" is illegal. "Product" should be '
                  'set to 18000. "Protocol" should be set to either iSCSI '
                  'or FC. Product: %(product)s Protocol: %(protocol)s')
                % {'product': six.text_type(product),
                   'protocol': six.text_type(protocol)})
         raise exception.InvalidInput(reason=msg)
Exemplo n.º 12
0
    def _get_iscsi_conf(self):
        """Get iSCSI info from config file."""
        iscsiinfo = {}
        root = huawei_utils.parse_xml_file(self.xml_conf)
        iscsiinfo["DefaultTargetIP"] = root.findtext("iSCSI/DefaultTargetIP").strip()
        initiator_list = []
        tmp_dic = {}
        for dic in root.findall("iSCSI/Initiator"):
            # Strip values of dic
            for k, v in dic.items():
                tmp_dic[k] = v.strip()
            initiator_list.append(tmp_dic)
        iscsiinfo["Initiator"] = initiator_list

        return iscsiinfo
Exemplo n.º 13
0
 def _get_conf_info(self, filename):
     """Get product type and connection protocol from config file."""
     root = huawei_utils.parse_xml_file(filename)
     product = root.findtext('Storage/Product').strip()
     protocol = root.findtext('Storage/Protocol').strip()
     if (product in self._product.keys() and
             protocol in self._protocol.keys()):
         return (product, protocol)
     else:
         msg = (_('Wrong product or protocol. Product should '
                  'be set to either T, Dorado, 18000, TV2 or V3. '
                  'Protocol should be set to either iSCSI or FC. '
                  'Product: %(product)s Protocol: %(protocol)s')
                % {'product': six.text_type(product),
                   'protocol': six.text_type(protocol)})
         raise exception.InvalidInput(reason=msg)
Exemplo n.º 14
0
 def _get_conf_info(self, filename):
     """Get product type and connection protocol from config file."""
     root = huawei_utils.parse_xml_file(filename)
     product = root.findtext('Storage/Product').strip()
     protocol = root.findtext('Storage/Protocol').strip()
     if (product in self._product.keys() and
             protocol in self._protocol.keys()):
         return (product, protocol)
     else:
         msg = (_('"Product" or "Protocol" is illegal. "Product" should '
                  'be set to either T, Dorado or HVS. "Protocol" should '
                  'be set to either iSCSI or FC. Product: %(product)s '
                  'Protocol: %(protocol)s')
                % {'product': product,
                   'protocol': protocol})
         raise exception.InvalidInput(reason=msg)
Exemplo n.º 15
0
    def _get_iscsi_conf(self):
        """Get iSCSI info from config file."""
        iscsiinfo = {}
        root = huawei_utils.parse_xml_file(self.xml_conf)
        iscsiinfo['DefaultTargetIP'] = \
            root.findtext('iSCSI/DefaultTargetIP').strip()
        initiator_list = []
        tmp_dic = {}
        for dic in root.findall('iSCSI/Initiator'):
            # Strip values of dic
            for k, v in dic.items():
                tmp_dic[k] = v.strip()
            initiator_list.append(tmp_dic)
        iscsiinfo['Initiator'] = initiator_list

        return iscsiinfo
Exemplo n.º 16
0
 def _get_conf_info(self, filename):
     """Get product type and connection protocol from config file."""
     root = huawei_utils.parse_xml_file(filename)
     product = root.findtext('Storage/Product').strip()
     protocol = root.findtext('Storage/Protocol').strip()
     if (product in self._product.keys()
             and protocol in self._protocol.keys()):
         return (product, protocol)
     else:
         msg = (_('Wrong product or protocol. Product should '
                  'be set to either T, Dorado, 18000, TV2 or V3. '
                  'Protocol should be set to either iSCSI or FC. '
                  'Product: %(product)s Protocol: %(protocol)s') % {
                      'product': six.text_type(product),
                      'protocol': six.text_type(protocol)
                  })
         raise exception.InvalidInput(reason=msg)
Exemplo n.º 17
0
 def update_volume_stats(self):
     root = huawei_utils.parse_xml_file(self.xml_file_path)
     pool_name = root.findtext('Storage/StoragePool')
     if not pool_name:
         msg = (_(
             'Invalid resource pool name. '
             'Please check the config file.'))
         LOG.error(msg)
         raise exception.InvalidInput(msg)
     data = {}
     capacity = self._get_capacity()
     data["pools"] = []
     pool = {}
     pool.update(dict(
         pool_name=pool_name,
         total_capacity_gb=capacity['total_capacity'],
         free_capacity_gb=capacity['free_capacity'],
         reserved_percentage=0,
         QoS_support=True,
     ))
     data["pools"].append(pool)
     return data