def cloud_disk_plug(self, iqn, ip, port): log.info('Pluging cloud disk on target %s, ip %s:%d' % (iqn, ip, port)) if not UO.validate_iqn(iqn): log.error('Iqn %s is invalid' % iqn) return [False, 'Iqn %s is invalid' % iqn] if not UO.validate_ip_without_mask(ip): log.error('IP %s is invalid' % ip) return [False, 'IP %s is invalid' % ip] if not UO.validate_port(port): log.error('Port %d is invalid' % port) return [False, 'Port %d is invalid' % port] if not UO.check_iscsi_service_existance(): return [False, 'Iscsi service not exist'] if not UO.check_iscsi_session_existance(iqn): if not UO.discover_iscsi_target(ip, port): return [False, 'Discover target %s:%d error' % (ip, port)] if not UO.login_iscsi_target(iqn, ip, port): return [False, 'Login target %s error' % iqn] return [True, ''] else: if not UO.update_iscsi_target(iqn, ip, port): return [False, 'Update target %s error' % iqn] return [True, '']
def cloud_disk_unplug(self, iqn, ip, port, last): log.info('Upluging cloud disk on target %s, ip %s:%d, last: %s' % (iqn, ip, port, last)) if not UO.validate_iqn(iqn): log.error('Iqn %s is invalid' % iqn) return [False, 'Iqn %s is invalid' % iqn] if not UO.validate_ip_without_mask(ip): log.error('IP %s is invalid' % ip) return [False, 'IP %s is invalid' % ip] if not UO.validate_port(port): log.error('Port %d is invalid' % port) return [False, 'Port %d is invalid' % port] if not UO.check_iscsi_service_existance(): return [False, 'Iscsi service not exist'] if not UO.check_iscsi_session_existance(iqn): log.info('Session %s not exist, do not need to logout' % iqn) return [True, ''] if last is True: if not UO.logout_iscsi_target(iqn, ip, port): return [False, 'Logout Target %s error' % iqn] else: if not UO.update_iscsi_target(iqn, ip, port): return [False, 'Update target %s error' % iqn] return [True, '']