def config_detach(self, fcp, assigner_id, target_wwpns, target_lun, multipath, os_version, mount_point, connections, need_restart=True): linuxdist = self._dist_manager.get_linux_dist(os_version)() self.configure_volume_detach(fcp, assigner_id, target_wwpns, target_lun, multipath, os_version, mount_point, linuxdist, connections) iucv_is_ready = self.check_IUCV_is_ready(assigner_id) if need_restart and iucv_is_ready: # active mode should restart zvmguestconfigure to run reader file active_cmds = linuxdist.create_active_net_interf_cmd() ret = self._smtclient.execute_cmd_direct(assigner_id, active_cmds) LOG.debug('detach scripts return values: %s' % ret) if ret['rc'] != 0: get_status_cmd = 'systemctl status zvmguestconfigure.service' exit_code = self._get_status_code_from_systemctl( assigner_id, get_status_cmd) if exit_code == 1: errmsg = ('detach scripts execution failed because the ' 'device %s in the target virtual machine %s ' 'is in use.' % (fcp, assigner_id)) else: errmsg = ('detach scripts execution on fcp %s in the' 'target virtual machine %s failed ' 'with unknow reason, exit code is: %s' % (fcp, assigner_id, exit_code)) LOG.error(errmsg) raise exception.SDKVolumeOperationError(rs=9, userid=assigner_id, msg=errmsg)
def check_IUCV_is_ready(self, assigner_id): # Make sure the iucv channel is ready for communication with VM ready = True try: self._smtclient.execute_cmd(assigner_id, 'pwd') except exception.SDKSMTRequestFailed as err: if 'UNAUTHORIZED_ERROR' in err.format_message(): # If unauthorized, we must raise exception errmsg = err.results['response'][0] msg = ('IUCV failed to get authorization from VM %(vm)s with ' 'error %(err)s' % {'vm': assigner_id, 'err': errmsg}) LOG.error(msg) raise exception.SDKVolumeOperationError(rs=6, userid=assigner_id, msg=errmsg) else: # In such case, we can continue without raising exception ready = False msg = ('Failed to connect VM %(vm)s with error ' '%(err)s, assume it is OFF status ' 'and continue' % {'vm': assigner_id, 'err': err.results['response'][0]}) LOG.debug(msg) return ready
def config_attach(self, fcp_list, assigner_id, target_wwpns, target_lun, multipath, os_version, mount_point): LOG.info("Begin to configure volume (WWPN:%s, LUN:%s) on the " "target machine %s with FCP devices " "%s." % (target_wwpns, target_lun, assigner_id, fcp_list)) linuxdist = self._dist_manager.get_linux_dist(os_version)() self.configure_volume_attach(fcp_list, assigner_id, target_wwpns, target_lun, multipath, os_version, mount_point, linuxdist) iucv_is_ready = self.check_IUCV_is_ready(assigner_id) if iucv_is_ready: # active mode should restart zvmguestconfigure to run reader file active_cmds = linuxdist.create_active_net_interf_cmd() ret = self._smtclient.execute_cmd_direct(assigner_id, active_cmds) LOG.debug('attach scripts return values: %s' % ret) if ret['rc'] != 0: # get exit code by systemctl status get_status_cmd = 'systemctl status zvmguestconfigure.service' exit_code = self._get_status_code_from_systemctl( assigner_id, get_status_cmd) if exit_code == 1: errmsg = ('attach script execution failed because the ' 'volume (WWPN:%s, LUN:%s) did not show up in ' 'the target machine %s , please check its ' 'connections.' % (target_wwpns, target_lun, assigner_id)) else: errmsg = ( 'attach script execution in the target machine ' '%s for volume (WWPN:%s, LUN:%s) ' 'failed with unknown reason, exit code is: %s.' % (assigner_id, target_wwpns, target_lun, exit_code)) LOG.error(errmsg) raise exception.SDKVolumeOperationError(rs=8, userid=assigner_id, msg=errmsg) LOG.info("Configuration of volume (WWPN:%s, LUN:%s) on the " "target machine %s with FCP devices " "%s is done." % (target_wwpns, target_lun, assigner_id, fcp_list))