def get_share_by_name(self, share_name, share_proto, vstore_id=None): if share_proto == 'NFS': share_path = huawei_utils.share_path(share_name) url = "/NFSHARE?filter=SHAREPATH::%s&range=[0-100]" % share_path elif share_proto == 'CIFS': cifs_share = huawei_utils.share_name(share_name) url = "/CIFSHARE?filter=NAME:%s&range=[0-100]" % cifs_share else: msg = _('Invalid NAS protocol %s.') % share_proto raise exception.InvalidInput(reason=msg) data = {'vstoreId': vstore_id} if vstore_id else None result = self.call(url, "GET", data) if _error_code(result) == constants.SHARE_PATH_INVALID: LOG.warning('Share %s not exist.', share_name) return _assert_result(result, 'Get share by name %s error.', share_name) # for CIFS, if didn't get share by NAME, try DESCRIPTION if share_proto == 'CIFS' and not result.get('data'): url = "/CIFSHARE?filter=DESCRIPTION:%s&range=[0-100]" % share_name result = self.call(url, "GET", data) if result.get('data'): return result['data'][0]
def create_share(self, share_name, fs_id, share_proto, vstore_id=None): share_path = huawei_utils.share_path(share_name) data = { "DESCRIPTION": share_name, "FSID": fs_id, "SHAREPATH": share_path, } if share_proto == 'NFS': url = "/NFSHARE" elif share_proto == 'CIFS': url = "/CIFSHARE" data["NAME"] = huawei_utils.share_name(share_name) else: msg = _('Invalid NAS protocol %s.') % share_proto raise exception.InvalidInput(reason=msg) if vstore_id: data['vstoreId'] = vstore_id result = self.call(url, "POST", data) _assert_result(result, 'Create share for %s error.', share_name) return result['data']['ID']