from .iscsi_client import IscsiClient
from .iscsi_config import IscsiGatewaysConfig, IscsiGatewayAlreadyExists, InvalidServiceUrl, \
- ManagedByOrchestratorException, IscsiGatewayDoesNotExist
+ ManagedByOrchestratorException, IscsiGatewayDoesNotExist, IscsiGatewayInUse
from ..rest_client import RequestException
'Remove iSCSI gateway configuration')
def remove_iscsi_gateway(_, name):
try:
+ try:
+ iscsi_config = IscsiClient.instance(gateway_name=name).get_config()
+ if name in iscsi_config['gateways']:
+ raise IscsiGatewayInUse(name)
+ except RequestException:
+ pass
IscsiGatewaysConfig.remove_gateway(name)
return 0, 'Success', ''
+ except IscsiGatewayInUse as ex:
+ return -errno.EBUSY, '', str(ex)
except IscsiGatewayDoesNotExist as ex:
return -errno.ENOENT, '', str(ex)
except ManagedByOrchestratorException as ex:
"iSCSI gateway '{}' does not exist".format(hostname))
+class IscsiGatewayInUse(Exception):
+ def __init__(self, hostname):
+ super(IscsiGatewayInUse, self).__init__(
+ "iSCSI gateway '{}' is in use".format(hostname))
+
+
class InvalidServiceUrl(Exception):
def __init__(self, service_url):
super(InvalidServiceUrl, self).__init__(