def terminate_connection(self, volume, connector, **kwargs): self.do_setup_status.wait() ldev = self.common.get_ldev(volume) if ldev is None: msg = basic_lib.set_msg(302, volume_id=volume["id"]) LOG.warning(msg) return if "wwpns" not in connector: msg = basic_lib.output_err(650, resource="HBA") raise exception.HBSDError(message=msg) hostgroups = [] self._get_hostgroup_info(hostgroups, connector["wwpns"], login=False) if not hostgroups: msg = basic_lib.output_err(649) raise exception.HBSDError(message=msg) self.common.add_volinfo(ldev, volume["id"]) with nested(self.common.volume_info[ldev]["lock"], self.common.volume_info[ldev]["in_use"]): self._terminate_connection(ldev, connector, hostgroups) properties = self._get_properties(volume, hostgroups, terminate=True) LOG.debug("Terminate volume_info: %s" % self.common.volume_info) return {"driver_volume_type": "fibre_channel", "data": properties}
def _range2list(self, conf, param): str = getattr(conf, param) lists = str.split('-') if len(lists) != 2: msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) first_type = None for i in range(len(lists)): if lists[i].isdigit(): lists[i] = int(lists[i], 10) if first_type == 'hex': msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) first_type = 'dig' else: if (first_type == 'dig' or not re.match('\w\w:\w\w:\w\w', lists[i])): msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) try: lists[i] = int(lists[i].replace(':', ''), 16) first_type = 'hex' except Exception: msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) if lists[0] > lists[1]: msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) return lists
def terminate_connection(self, volume, connector, **kwargs): self.do_setup_status.wait() ldev = self.common.get_ldev(volume) if ldev is None: LOG.warning(basic_lib.set_msg(302, volume_id=volume['id'])) return if 'wwpns' not in connector: msg = basic_lib.output_err(650, resource='HBA') raise exception.HBSDError(message=msg) hostgroups = [] self._get_hostgroup_info(hostgroups, connector['wwpns'], login=False) if not hostgroups: msg = basic_lib.output_err(649) raise exception.HBSDError(message=msg) self.common.add_volinfo(ldev, volume['id']) with self.common.volume_info[ldev]['lock'],\ self.common.volume_info[ldev]['in_use']: self._terminate_connection(ldev, connector, hostgroups) properties = self._get_properties(volume, hostgroups, terminate=True) LOG.debug('Terminate volume_info: %s', self.common.volume_info) return { 'driver_volume_type': 'fibre_channel', 'data': properties }
def comm_get_iscsi_ip(self, port): unit = self.unit_name ret, stdout, stderr = self.exec_hsnm("auiscsi", "-unit %s -refer" % unit) if ret: msg = basic_lib.output_err(600, cmd="auiscsi", ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) lines = stdout.splitlines() is_target_port = False for line in lines: line_array = shlex.split(line) if not line_array: continue if line_array[0] == "Port" and line_array[1] != "Number": if line_array[1] == port: is_target_port = True else: is_target_port = False continue if is_target_port and re.search("IPv4 Address", line): ip_addr = shlex.split(line)[3] break if is_target_port and re.search("Port Number", line): ip_port = shlex.split(line)[3] else: msg = basic_lib.output_err(651) raise exception.HBSDError(message=msg) return ip_addr, ip_port
def get_unused_ldev(self, ldev_range): start = ldev_range[0] end = ldev_range[1] unit = self.unit_name ret, stdout, stderr = self.exec_hsnm("auluref", "-unit %s" % unit) if ret: msg = basic_lib.output_err(600, cmd="auluref", ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) free_ldev = start lines = stdout.splitlines() found = False for line in lines[2:]: line = shlex.split(line) if not line: continue ldev_num = int(line[0]) if free_ldev > ldev_num: continue if free_ldev == ldev_num: free_ldev += 1 else: found = True break if free_ldev > end: break else: found = True if not found: msg = basic_lib.output_err(648, resource="LDEV") raise exception.HBSDError(message=msg) return free_ldev
def comm_get_target_iqn(self, port, gid): unit = self.unit_name ret, stdout, stderr = self.exec_hsnm("autargetdef", "-unit %s -refer" % unit) if ret: msg = basic_lib.output_err(600, cmd="autargetdef", ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) is_target_host = False tmp_port = None lines = stdout.splitlines() for line in lines: line = shlex.split(line) if not line: continue if line[0] == "Port": tmp_port = line[1] continue if port != tmp_port: continue gid_tmp = line[0][0:3] if gid_tmp.isdigit() and int(gid_tmp) == gid: is_target_host = True continue if is_target_host and line[0] == "iSCSI": target_iqn = line[3] break else: msg = basic_lib.output_err(650, resource="IQN") raise exception.HBSDError(message=msg) return target_iqn
def delete_volume(self, volume): ldev = self.get_ldev(volume) if ldev is None: LOG.warning(basic_lib.set_msg(304, method='delete_volume', id=volume['id'])) return self.add_volinfo(ldev, volume['id']) if not self.volume_info[ldev]['in_use'].lock.acquire(False): desc = self.volume_info[ldev]['in_use'].desc basic_lib.output_err(660, desc=desc) raise exception.VolumeIsBusy(volume_name=volume['name']) try: is_vvol = self.get_volume_is_vvol(volume) try: self.delete_ldev(ldev, is_vvol) except exception.HBSDNotFound: with self.volinfo_lock: if ldev in self.volume_info: self.volume_info.pop(ldev) LOG.warning(basic_lib.set_msg( 305, type='volume', id=volume['id'])) except exception.HBSDBusy: raise exception.VolumeIsBusy(volume_name=volume['name']) finally: if ldev in self.volume_info: self.volume_info[ldev]['in_use'].lock.release()
def create_cloned_volume(self, volume, src_vref): pvol = self.get_ldev(src_vref) if pvol is None: msg = basic_lib.output_err(624, type='volume', id=src_vref['id']) raise exception.HBSDError(message=msg) self.add_volinfo(pvol, src_vref['id']) with self.volume_info[pvol]['in_use']: is_vvol = self.get_volume_is_vvol(src_vref) self.check_volume_status(self.get_volume(src_vref['id']), is_vvol) size = volume['size'] src_size = src_vref['size'] if size != src_size: msg = basic_lib.output_err(617, type='volume', volume_id=volume['id']) raise exception.HBSDError(message=msg) metadata = self.get_volume_metadata(volume['id']) method = None if is_vvol else self.get_copy_method(volume) svol, type = self.copy_data(pvol, size, is_vvol, method) metadata['type'] = type metadata['volume'] = src_vref['id'] metadata['ldev'] = svol return {'provider_location': svol, 'metadata': metadata}
def delete_snapshot(self, snapshot): ldev = self.get_ldev(snapshot) if ldev is None: msg = basic_lib.set_msg( 304, method='delete_snapshot', id=snapshot['id']) LOG.warning(msg) return self.add_volinfo(ldev, id=snapshot['id'], type='snapshot') if not self.volume_info[ldev]['in_use'].lock.acquire(False): desc = self.volume_info[ldev]['in_use'].desc basic_lib.output_err(660, desc=desc) raise exception.SnapshotIsBusy(snapshot_name=snapshot['name']) try: is_vvol = self.get_snapshot_is_vvol(snapshot) try: self.delete_ldev(ldev, is_vvol) except exception.HBSDNotFound: with self.volinfo_lock: if ldev in self.volume_info: self.volume_info.pop(ldev) msg = basic_lib.set_msg( 305, type='snapshot', id=snapshot['id']) LOG.warning(msg) except exception.HBSDBusy: raise exception.SnapshotIsBusy(snapshot_name=snapshot['name']) finally: if ldev in self.volume_info: self.volume_info[ldev]['in_use'].lock.release()
def unmanage(self, volume): """Remove the specified volume from Cinder management.""" ldev = self.get_ldev(volume) if ldev is None: return self.add_volinfo(ldev, volume['id']) if not self.volume_info[ldev]['in_use'].lock.acquire(False): desc = self.volume_info[ldev]['in_use'].desc basic_lib.output_err(660, desc=desc) raise exception.HBSDVolumeIsBusy(volume_name=volume['name']) is_vvol = self.get_volume_is_vvol(volume) if is_vvol: basic_lib.output_err(706, volume_id=volume['id'], volume_type=basic_lib.NORMAL_VOLUME_TYPE) raise exception.HBSDVolumeIsBusy(volume_name=volume['name']) try: self._unmanage(volume, ldev) except exception.HBSDBusy: raise exception.HBSDVolumeIsBusy(volume_name=volume['name']) else: msg = basic_lib.set_msg(5, volume_id=volume['id'], ldev=ldev) LOG.info(msg) finally: if ldev in self.volume_info: self.volume_info[ldev]['in_use'].lock.release()
def create_volume_from_snapshot(self, volume, snapshot): pvol = self.get_ldev(snapshot) if pvol is None: msg = basic_lib.output_err(624, type='snapshot', id=snapshot['id']) raise exception.HBSDError(message=msg) self.add_volinfo(pvol, id=snapshot['id'], type='snapshot') with self.volume_info[pvol]['in_use']: is_vvol = self.get_snapshot_is_vvol(snapshot) if snapshot['status'] != 'available': msg = basic_lib.output_err(655, status=snapshot['status']) raise exception.HBSDError(message=msg) size = volume['size'] src_size = snapshot['volume_size'] if size != src_size: msg = basic_lib.output_err(617, type='snapshot', volume_id=volume['id']) raise exception.HBSDError(message=msg) metadata = self.get_volume_metadata(volume['id']) method = None if is_vvol else self.get_copy_method(volume) svol, type = self.copy_data(pvol, size, is_vvol, method) metadata['type'] = type metadata['snapshot'] = snapshot['id'] metadata['ldev'] = svol return {'provider_location': svol, 'metadata': metadata}
def create_volume_from_snapshot(self, volume, snapshot): pvol = self.get_ldev(snapshot) if pvol is None: msg = basic_lib.output_err(624, type="snapshot", id=snapshot["id"]) raise exception.HBSDError(message=msg) self.add_volinfo(pvol, id=snapshot["id"], type="snapshot") with self.volume_info[pvol]["in_use"]: is_vvol = self.get_snapshot_is_vvol(snapshot) if snapshot["status"] != "available": msg = basic_lib.output_err(655, status=snapshot["status"]) raise exception.HBSDError(message=msg) size = volume["size"] src_size = snapshot["volume_size"] if size != src_size: msg = basic_lib.output_err(617, type="snapshot", volume_id=volume["id"]) raise exception.HBSDError(message=msg) metadata = self.get_volume_metadata(volume["id"]) method = None if is_vvol else self.get_copy_method(volume) svol, type = self.copy_data(pvol, size, is_vvol, method) metadata["type"] = type metadata["snapshot"] = snapshot["id"] metadata["ldev"] = svol return {"provider_location": svol, "metadata": metadata}
def create_cloned_volume(self, volume, src_vref): pvol = self.get_ldev(src_vref) if pvol is None: msg = basic_lib.output_err(624, type="volume", id=src_vref["id"]) raise exception.HBSDError(message=msg) self.add_volinfo(pvol, src_vref["id"]) with self.volume_info[pvol]["in_use"]: is_vvol = self.get_volume_is_vvol(src_vref) self.check_volume_status(self.get_volume(src_vref["id"]), is_vvol) size = volume["size"] src_size = src_vref["size"] if size != src_size: msg = basic_lib.output_err(617, type="volume", volume_id=volume["id"]) raise exception.HBSDError(message=msg) metadata = self.get_volume_metadata(volume["id"]) method = None if is_vvol else self.get_copy_method(volume) svol, type = self.copy_data(pvol, size, is_vvol, method) metadata["type"] = type metadata["volume"] = src_vref["id"] metadata["ldev"] = svol return {"provider_location": svol, "metadata": metadata}
def _range2list(self, conf, param): str = getattr(conf, param) lists = str.split("-") if len(lists) != 2: msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) first_type = None for i in range(len(lists)): if lists[i].isdigit(): lists[i] = int(lists[i], 10) if first_type == "hex": msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) first_type = "dig" else: if first_type == "dig" or not re.match("\w\w:\w\w:\w\w", lists[i]): msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) try: lists[i] = int(lists[i].replace(":", ""), 16) first_type = "hex" except Exception: msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) if lists[0] > lists[1]: msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) return lists
def set_chap_authention(self, port, gid): ctl_no = port[0] port_no = port[1] unit = self.unit_name auth_username = self.conf.hitachi_auth_user auth_password = self.conf.hitachi_auth_password add_chap_user = self.conf.hitachi_add_chap_user assign_flag = True added_flag = False opt = "-unit %s -refer %s %s -user %s" % (unit, ctl_no, port_no, auth_username) ret, stdout, stderr = self.exec_hsnm("auchapuser", opt, noretry=True) if ret: if not add_chap_user: msg = basic_lib.output_err(643, user=auth_username) raise exception.HBSDError(message=msg) root_helper = utils.get_root_helper() cmd = "%s env %s auchapuser -unit %s -add %s %s " "-tno %d -user %s" % ( root_helper, SNM2_ENV, unit, ctl_no, port_no, gid, auth_username, ) LOG.debug("Add CHAP user") loop = loopingcall.FixedIntervalLoopingCall( self._wait_for_add_chap_user, cmd, auth_username, auth_password, time.time() ) added_flag = loop.start(interval=EXEC_INTERVAL).wait() else: lines = stdout.splitlines()[4:] for line in lines: if int(shlex.split(line)[0][0:3]) == gid: assign_flag = False break if assign_flag: opt = "-unit %s -assign %s %s -tno %d -user %s" % (unit, ctl_no, port_no, gid, auth_username) ret, stdout, stderr = self.exec_hsnm("auchapuser", opt) if ret: if added_flag: _ret, _stdout, _stderr = self.delete_chap_user(port) if _ret: msg = basic_lib.set_msg(303, user=auth_username) LOG.warning(msg) msg = basic_lib.output_err(600, cmd="auchapuser", ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) return added_flag
def get_copy_method(self, volume): method = self.get_value(volume, "volume_metadata", "copy_method") if method: if method not in COPY_METHOD: msg = basic_lib.output_err(602, meta="copy_method") raise exception.HBSDError(message=msg) elif method == "THIN" and self.configuration.hitachi_thin_pool_id is None: msg = basic_lib.output_err(601, param="hitachi_thin_pool_id") raise exception.HBSDError(message=msg) else: method = self.configuration.hitachi_default_copy_method return method
def get_gid_from_targetiqn(self, target_iqn, target_alias, port): unit = self.unit_name ret, stdout, stderr = self.exec_hsnm('autargetdef', '-unit %s -refer' % unit) if ret: msg = basic_lib.output_err( 600, cmd='autargetdef', ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) gid = None tmp_port = None found_alias_full = False found_alias_part = False lines = stdout.splitlines() for line in lines: line = shlex.split(line) if not line: continue if line[0] == "Port": tmp_port = line[1] continue if port != tmp_port: continue if line[0][0:3].isdigit(): tmp_gid = int(line[0][0:3]) if re.match(basic_lib.NAME_PREFIX, line[0][4:]): found_alias_part = True if line[0][4:] == target_alias: found_alias_full = True continue if line[0] == "iSCSI": if line[3] == target_iqn: gid = tmp_gid break else: found_alias_part = False if found_alias_full and gid is None: msg = basic_lib.output_err(641) raise exception.HBSDError(message=msg) # When 'gid' is 0, it should be true. # So, it cannot remove 'is not None'. if not found_alias_part and gid is not None: msg = basic_lib.output_err(641) raise exception.HBSDError(message=msg) return gid
def comm_delete_lun_core(self, command, hostgroups, lun): unit = self.unit_name no_lun_cnt = 0 deleted_hostgroups = [] for hostgroup in hostgroups: LOG.debug('comm_delete_lun: hostgroup is %s' % hostgroup) port = hostgroup['port'] gid = hostgroup['gid'] ctl_no = port[0] port_no = port[1] is_deleted = False for deleted in deleted_hostgroups: if port == deleted['port'] and gid == deleted['gid']: is_deleted = True if is_deleted: continue ret, stdout, stderr = self.exec_hsnm(command, '-unit %s -refer' % unit) if ret: msg = basic_lib.output_err( 600, cmd=command, ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) lines = stdout.splitlines() for line in lines[2:]: line = shlex.split(line) if not line: continue if (line[0] == port and int(line[1][0:3]) == gid and int(line[3]) == lun): hlu = int(line[2]) break else: no_lun_cnt += 1 if no_lun_cnt == len(hostgroups): raise exception.HBSDNotFound else: continue opt = '-unit %s -rm %s %s %d %d %d' % (unit, ctl_no, port_no, gid, hlu, lun) ret, stdout, stderr = self.exec_hsnm(command, opt) if ret: msg = basic_lib.output_err( 600, cmd=command, ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) deleted_hostgroups.append({'port': port, 'gid': gid}) LOG.debug('comm_delete_lun is over (%d)' % lun)
def get_unused_gid(self, group_range, port): start = group_range[0] end = group_range[1] unit = self.unit_name ret, stdout, stderr = self.exec_hsnm('auhgdef', '-unit %s -refer' % unit) if ret: msg = basic_lib.output_err( 600, cmd='auhgdef', ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) lines = stdout.splitlines() is_target_port = False free_gid = start found = False for line in lines: line = shlex.split(line) if not line: continue if line[0] == 'Port' and line[1] == port: is_target_port = True continue if is_target_port: if line[0] == 'Port': found = True break if not line[0].isdigit(): continue gid = int(line[0]) if free_gid > gid: continue if free_gid == gid: free_gid += 1 else: found = True break if free_gid > end or free_gid > MAX_HOSTGROUPS: break else: found = True if not found: msg = basic_lib.output_err(648, resource='GID') raise exception.HBSDError(message=msg) return free_gid
def add_hostgroup_master(self, hgs, master_wwns, host_ip, security_ports): target_ports = self.configuration.hitachi_target_ports group_request = self.configuration.hitachi_group_request wwns = [] for wwn in master_wwns: wwns.append(wwn.lower()) if target_ports and group_request: host_grp_name = '%s%s' % (basic_lib.NAME_PREFIX, host_ip) for port in security_ports: wwns_copy = wwns[:] for hostgroup in hgs: if (hostgroup['port'] == port and hostgroup['initiator_wwn'].lower() in wwns_copy): wwns_copy.remove(hostgroup['initiator_wwn'].lower()) if wwns_copy: try: self._fill_group(hgs, port, host_grp_name, wwns_copy) except Exception as ex: LOG.warning(_('Failed to add host group: %s') % six.text_type(ex)) msg = basic_lib.set_msg( 308, port=port, name=host_grp_name) LOG.warning(msg) if not hgs: msg = basic_lib.output_err(649) raise exception.HBSDError(message=msg)
def copy_volume_to_image(self, context, volume, image_service, image_meta): self.do_setup_status.wait() if volume["instance_uuid"] or volume["attached_host"]: desc = "volume %s" % volume["id"] msg = basic_lib.output_err(660, desc=desc) raise exception.HBSDError(message=msg) super(HBSDFCDriver, self).copy_volume_to_image(context, volume, image_service, image_meta)
def _wait_for_pair_status(self, pvol, svol, is_vvol, status, timeout, start): if self._comm_pairevtwait(pvol, svol, is_vvol) in status: raise loopingcall.LoopingCallDone() if time.time() - start >= timeout: msg = basic_lib.output_err(637, method="_wait_for_pair_status", timeout=timeout) raise exception.HBSDError(message=msg)
def get_hgname_gid(self, port, host_grp_name): unit = self.unit_name ret, stdout, stderr = self.exec_hsnm('auhgdef', '-unit %s -refer' % unit) if ret: msg = basic_lib.output_err( 600, cmd='auhgdef', ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) lines = stdout.splitlines() is_target_port = False for line in lines: line = shlex.split(line) if not line: continue if line[0] == 'Port' and line[1] == port: is_target_port = True continue if is_target_port: if line[0] == 'Port': break if not line[0].isdigit(): continue gid = int(line[0]) if line[1] == host_grp_name: return gid return None
def get_comm_version(self): ret, stdout, stderr = self.exec_hsnm("auman", "-help") m = re.search("Version (\d+).(\d+)", stdout) if not m: msg = basic_lib.output_err(600, cmd="auman", ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) return "%s.%s" % (m.group(1), m.group(2))
def add_hostgroup_pair(self, pair_hostgroups): if self.configuration.hitachi_unit_name: return properties = utils.brick_get_connector_properties() if "wwpns" not in properties: msg = basic_lib.output_err(650, resource="HBA") raise exception.HBSDError(message=msg) hostgroups = [] self._get_hostgroup_info(hostgroups, properties["wwpns"], login=False) host_grp_name = "%spair%02x" % (basic_lib.NAME_PREFIX, self.pair_hostnum) for hostgroup in hostgroups: gid = self._get_hgname_gid(hostgroup["port"], host_grp_name) # When 'gid' is 0, it should be true. # So, it cannot remove 'is not None'. if gid is not None: pair_hostgroups.append({"port": hostgroup["port"], "gid": gid, "initiator_wwn": None, "detected": True}) break if not pair_hostgroups: for hostgroup in hostgroups: pair_port = hostgroup["port"] try: self._fill_group(pair_hostgroups, pair_port, host_grp_name, None) except Exception: if hostgroup is hostgroups[-1]: raise else: break
def comm_set_target_wwns(self, target_ports): unit = self.unit_name ret, stdout, stderr = self.exec_hsnm("aufibre1", "-unit %s -refer" % unit) if ret: msg = basic_lib.output_err(600, cmd="aufibre1", ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) lines = stdout.splitlines() target_wwns = {} for line in lines[3:]: if re.match("Transfer", line): break line = shlex.split(line) if len(line) < 4: continue port = "%s%s" % (line[0], line[1]) if target_ports: if port in target_ports: target_wwns[port] = line[3] else: target_wwns[port] = line[3] LOG.debug("target wwns: %s" % target_wwns) return target_wwns
def comm_get_hostgroup_info_iscsi(self, hgs, host_iqn, target_ports): unit = self.unit_name ret, stdout, stderr = self.exec_hsnm("autargetini", "-unit %s -refer" % unit) if ret: msg = basic_lib.output_err(600, cmd="autargetini", ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) security_ports = [] lines = stdout.splitlines() hostgroups = [] security = True for line in lines: if not shlex.split(line): continue if re.match("Port", line): line = shlex.split(line) port = line[1] security = True if line[4] == "ON" else False continue if target_ports and port not in target_ports: continue if security: if host_iqn in shlex.split(line[72:]) and re.match(basic_lib.NAME_PREFIX, shlex.split(line)[0][4:]): gid = int(shlex.split(line)[0][0:3]) hostgroups.append({"port": port, "gid": gid, "detected": True}) LOG.debug("Find port=%(port)s gid=%(gid)d" % {"port": port, "gid": gid}) if port not in security_ports: security_ports.append(port) for hostgroup in hostgroups: hgs.append(hostgroup) return security_ports
def create_snapshot(self, snapshot): src_ref = self.get_volume(snapshot['volume_id']) pvol = self.get_ldev(src_ref) if pvol is None: msg = basic_lib.output_err(624, type='volume', id=src_ref['id']) raise exception.HBSDError(message=msg) self.add_volinfo(pvol, src_ref['id']) with self.volume_info[pvol]['in_use']: is_vvol = self.get_volume_is_vvol(src_ref) self.check_volume_status(src_ref, is_vvol) size = snapshot['volume_size'] snap_metadata = self.get_snapshot_metadata(snapshot['id']) method = None if is_vvol else self.get_copy_method(src_ref) svol, type = self.copy_data(pvol, size, is_vvol, method) if type == 'V-VOL': snap_metadata['type'] = type snap_metadata['ldev'] = svol snapshot_metadata = api._metadata_refs(snap_metadata, models.SnapshotMetadata) return {'provider_location': svol, 'snapshot_metadata': snapshot_metadata}
def _initialize_connection(self, ldev, connector, src_hgs=None): LOG.debug("Call _initialize_connection " "(config_group: %(group)s ldev: %(ldev)d)", {'group': self.configuration.config_group, 'ldev': ldev}) if src_hgs is self.pair_hostgroups: hostgroups = src_hgs else: hostgroups = [] security_ports = self._get_hostgroup_info( hostgroups, connector['wwpns'], login=True) self.add_hostgroup_master(hostgroups, connector['wwpns'], connector['ip'], security_ports) if src_hgs is self.pair_hostgroups: try: self._add_lun(hostgroups, ldev) except exception.HBSDNotFound: LOG.warning(basic_lib.set_msg(311, ldev=ldev)) for i in range(self.max_hostgroups + 1): self.pair_hostnum += 1 pair_hostgroups = [] try: self.add_hostgroup_pair(pair_hostgroups) self.pair_hostgroups.extend(pair_hostgroups) except exception.HBSDNotFound: if i >= self.max_hostgroups: msg = basic_lib.output_err(648, resource='GID') raise exception.HBSDError(message=msg) else: break self.pair_initialize_connection(ldev) else: self._add_lun(hostgroups, ldev) return hostgroups
def extend_volume(self, volume, new_size): pvol = self.get_ldev(volume) self.add_volinfo(pvol, volume['id']) with self.volume_info[pvol]['in_use']: if self.get_volume_is_vvol(volume): msg = basic_lib.output_err(618, volume_id=volume['id']) raise exception.HBSDError(message=msg) self._extend_volume(pvol, volume['size'], new_size)
def create_ldev(self, size, ldev_range, pool_id, is_vvol): LOG.debug('create start (normal)') for i in basic_lib.DEFAULT_TRY_RANGE: LOG.debug('Try number: %(tries)s / %(max_tries)s' % { 'tries': i + 1, 'max_tries': len(basic_lib.DEFAULT_TRY_RANGE) }) new_ldev = self._get_unused_volume_num(ldev_range) try: self._add_ldev(new_ldev, size, pool_id, is_vvol) except exception.HBSDNotFound: msg = basic_lib.set_msg(312, resource='LDEV') LOG.warning(msg) continue else: break else: msg = basic_lib.output_err(636) raise exception.HBSDError(message=msg) LOG.debug('create end (normal: %s)' % six.text_type(new_ldev)) self.init_volinfo(self.volume_info, new_ldev) return new_ldev
def comm_add_ldev(self, pool_id, ldev, capacity, is_vvol): unit = self.unit_name if is_vvol: command = 'aureplicationvvol' opt = ('-unit %s -add -lu %d -size %dg' % (unit, ldev, capacity)) else: command = 'auluadd' opt = ('-unit %s -lu %d -dppoolno %d -size %dg' % (unit, ldev, pool_id, capacity)) ret, stdout, stderr = self.exec_hsnm(command, opt) if ret: if (re.search('DMEC002047', stderr) or re.search('DMES052602', stderr) or re.search('DMED09000A', stderr)): raise exception.HBSDNotFound else: msg = basic_lib.output_err( 600, cmd=command, ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
def _initialize_connection(self, ldev, connector, src_hgs=None): LOG.debug("Call _initialize_connection " "(config_group: %(group)s ldev: %(ldev)d)" % { 'group': self.configuration.config_group, 'ldev': ldev }) if src_hgs is self.pair_hostgroups: hostgroups = src_hgs else: hostgroups = [] security_ports = self._get_hostgroup_info(hostgroups, connector['wwpns'], login=True) self.add_hostgroup_master(hostgroups, connector['wwpns'], connector['ip'], security_ports) if src_hgs is self.pair_hostgroups: try: self._add_lun(hostgroups, ldev) except exception.HBSDNotFound: msg = basic_lib.set_msg(311, ldev=ldev) LOG.warning(msg) for i in range(self.max_hostgroups + 1): self.pair_hostnum += 1 pair_hostgroups = [] try: self.add_hostgroup_pair(pair_hostgroups) self.pair_hostgroups.extend(pair_hostgroups) except exception.HBSDNotFound: if i >= self.max_hostgroups: msg = basic_lib.output_err(648, resource='GID') raise exception.HBSDError(message=msg) else: break self.pair_initialize_connection(ldev) else: self._add_lun(hostgroups, ldev) return hostgroups
def create_snapshot(self, snapshot): src_ref = self.get_volume(snapshot['volume_id']) pvol = self.get_ldev(src_ref) if pvol is None: msg = basic_lib.output_err(624, type='volume', id=src_ref['id']) raise exception.HBSDError(message=msg) self.add_volinfo(pvol, src_ref['id']) with self.volume_info[pvol]['in_use']: is_vvol = self.get_volume_is_vvol(src_ref) self.check_volume_status(src_ref, is_vvol) size = snapshot['volume_size'] snap_metadata = snapshot.get('metadata') method = None if is_vvol else self.get_copy_method(src_ref) svol, type = self.copy_data(pvol, size, is_vvol, method) if type == 'V-VOL': snap_metadata['type'] = type snap_metadata['ldev'] = svol return {'provider_location': svol, 'metadata': snap_metadata}
def add_used_hlun(self, command, port, gid, used_list, ldev): unit = self.unit_name ret, stdout, stderr = self.exec_hsnm(command, '-unit %s -refer' % unit) if ret: msg = basic_lib.output_err( 600, cmd=command, ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) lines = stdout.splitlines() for line in lines[2:]: line = shlex.split(line) if not line: continue if line[0] == port and int(line[1][0:3]) == gid: if int(line[2]) not in used_list: used_list.append(int(line[2])) if int(line[3]) == ldev: hlu = int(line[2]) LOG.warning(_LW('ldev(%(ldev)d) is already mapped ' '(hlun: %(hlu)d)'), {'ldev': ldev, 'hlu': hlu}) return hlu return None
def _fill_group(self, hgs, port, host_grp_name, wwns): added_hostgroup = False LOG.debug('Create host group (hgs: %(hgs)s port: %(port)s ' 'name: %(name)s wwns: %(wwns)s)' % {'hgs': hgs, 'port': port, 'name': host_grp_name, 'wwns': wwns}) gid = self._get_hgname_gid(port, host_grp_name) if gid is None: for retry_cnt in basic_lib.DEFAULT_TRY_RANGE: try: gid = self._get_unused_gid(port) self._add_hostgroup(port, gid, host_grp_name) added_hostgroup = True except exception.HBSDNotFound: gid = None msg = basic_lib.set_msg(312, resource='GID') LOG.warning(msg) continue else: LOG.debug('Completed to add host target' '(port: %(port)s gid: %(gid)d)' % {'port': port, 'gid': gid}) break else: msg = basic_lib.output_err(641) raise exception.HBSDError(message=msg) try: if wwns: self._add_wwn(hgs, port, gid, wwns) else: hgs.append({'port': port, 'gid': gid, 'initiator_wwn': None, 'detected': True}) except Exception: with excutils.save_and_reraise_exception(): if added_hostgroup: self._delete_hostgroup(port, gid, host_grp_name)
def add_hostgroup_pair(self, pair_hostgroups): if self.configuration.hitachi_unit_name: return properties = utils.brick_get_connector_properties() if 'wwpns' not in properties: msg = basic_lib.output_err(650, resource='HBA') raise exception.HBSDError(message=msg) hostgroups = [] self._get_hostgroup_info(hostgroups, properties['wwpns'], login=False) host_grp_name = '%spair%02x' % (basic_lib.NAME_PREFIX, self.pair_hostnum) for hostgroup in hostgroups: gid = self._get_hgname_gid(hostgroup['port'], host_grp_name) # When 'gid' is 0, it should be true. # So, it cannot remove 'is not None'. if gid is not None: pair_hostgroups.append({ 'port': hostgroup['port'], 'gid': gid, 'initiator_wwn': None, 'detected': True }) break if not pair_hostgroups: for hostgroup in hostgroups: pair_port = hostgroup['port'] try: self._fill_group(pair_hostgroups, pair_port, host_grp_name, None) except Exception: if hostgroup is hostgroups[-1]: raise else: break
def _wait_for_add_chap_user(self, cmd, auth_username, auth_password, start): # Don't move 'import pexpect' to the beginning of the file so that # a tempest can work. import pexpect lock = basic_lib.get_process_lock(self.hsnm_lock_file) with self.hsnm_lock, lock: try: child = pexpect.spawn(cmd) child.expect('Secret: ', timeout=CHAP_TIMEOUT) child.sendline(auth_password) child.expect('Re-enter Secret: ', timeout=CHAP_TIMEOUT) child.sendline(auth_password) child.expect( 'The CHAP user information has ' 'been added successfully.', timeout=CHAP_TIMEOUT) except Exception: if time.time() - start >= EXEC_TIMEOUT: msg = basic_lib.output_err(642, user=auth_username) raise exception.HBSDError(message=msg) else: raise loopingcall.LoopingCallDone(True)
def comm_add_lun(self, command, hostgroups, ldev, is_once=False): unit = self.unit_name tmp_hostgroups = hostgroups[:] used_list = [] is_ok = False hlu = None old_hlu = None for hostgroup in hostgroups: port = hostgroup['port'] gid = hostgroup['gid'] hlu = self.add_used_hlun(command, port, gid, used_list, ldev) # When 'hlu' or 'old_hlu' is 0, it should be true. # So, it cannot remove 'is not None'. if hlu is not None: if old_hlu is not None and old_hlu != hlu: msg = basic_lib.output_err(648, resource='LUN (HLUN)') raise exception.HBSDError(message=msg) is_ok = True hostgroup['lun'] = hlu tmp_hostgroups.remove(hostgroup) old_hlu = hlu else: hlu = old_hlu if not used_list: hlu = 0 elif hlu is None: for i in range(MAX_HLUN + 1): if i not in used_list: hlu = i break else: raise exception.HBSDNotFound ret = 0 stdout = None stderr = None invalid_hgs_str = None for hostgroup in tmp_hostgroups: port = hostgroup['port'] gid = hostgroup['gid'] ctl_no = port[0] port_no = port[1] if not hostgroup['detected']: if invalid_hgs_str: invalid_hgs_str = '%s, %s:%d' % (invalid_hgs_str, port, gid) else: invalid_hgs_str = '%s:%d' % (port, gid) continue opt = '-unit %s -add %s %s %d %d %d' % (unit, ctl_no, port_no, gid, hlu, ldev) ret, stdout, stderr = self.exec_hsnm(command, opt) if ret == 0: is_ok = True hostgroup['lun'] = hlu if is_once: break else: msg = basic_lib.set_msg(314, ldev=ldev, lun=hlu, port=port, id=gid) LOG.warning(msg) if not is_ok: if stderr: msg = basic_lib.output_err(600, cmd=command, ret=ret, out=stdout, err=stderr) raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr) else: msg = basic_lib.output_err(659, gid=invalid_hgs_str) raise exception.HBSDError(message=msg)
def __enter__(self): if not self.lock.acquire(False): msg = basic_lib.output_err(660, desc=self.desc) raise exception.HBSDError(message=msg) return self
def delete_pair(self, ldev, all_split=True, is_vvol=None): paired_info = self.command.get_paired_info(ldev) LOG.debug('paired_info: %s', paired_info) pvol = paired_info['pvol'] svols = paired_info['svol'] driver = self.generated_from restart = False svol_list = [] try: if pvol is None: return elif pvol == ldev: for svol in svols[:]: if svol['is_vvol'] or svol['status'] != basic_lib.PSUS: continue self.command.delete_pair(pvol, svol['lun'], False) restart = True driver.pair_terminate_connection(svol['lun']) svols.remove(svol) if all_split and svols: svol_list.append(six.text_type(svols[0]['lun'])) for svol in svols[1:]: svol_list.append(', %d' % svol['lun']) msg = basic_lib.output_err(616, pvol=pvol, svol=''.join(svol_list)) raise exception.HBSDBusy(message=msg) if not svols: driver.pair_terminate_connection(pvol) else: self.add_volinfo(pvol) if not self.volume_info[pvol]['in_use'].lock.acquire(False): desc = self.volume_info[pvol]['in_use'].desc msg = basic_lib.output_err(660, desc=desc) raise exception.HBSDBusy(message=msg) try: paired_info = self.command.get_paired_info(ldev) if paired_info['pvol'] is None: return svol = paired_info['svol'][0] if svol['status'] != basic_lib.PSUS: msg = basic_lib.output_err(616, pvol=pvol, svol=ldev) raise exception.HBSDBusy(message=msg) self.command.delete_pair(pvol, ldev, svol['is_vvol']) if not svol['is_vvol']: restart = True driver.pair_terminate_connection(ldev) paired_info = self.command.get_paired_info(pvol) if paired_info['pvol'] is None: driver.pair_terminate_connection(pvol) finally: self.volume_info[pvol]['in_use'].lock.release() except Exception: with excutils.save_and_reraise_exception(): if restart: try: self.command.restart_pair_horcm() except Exception as e: LOG.warning('Failed to restart horcm: %s', e) else: if (all_split or is_vvol) and restart: try: self.command.restart_pair_horcm() except Exception as e: LOG.warning('Failed to restart horcm: %s', e)