Check instance exists when attach or detach interface

I think it is necessary to check instance exists when attach
or detach interface to a instance. So add some exception handle
when do attach or detach interface.

Change-Id: Ie8db50be05333e413dc98c0b624e456ff1def9d3
This commit is contained in:
changzhi 2015-07-05 14:25:18 +08:00
parent c9d2408eee
commit c57103ffa6
1 changed files with 12 additions and 2 deletions

View File

@ -278,12 +278,22 @@ class DeviceNova(abstract_driver.DeviceAbstractDriver):
LOG.debug(_('ataching interface %(device_id)s %(port_id)s'),
{'device_id': device_id, 'port_id': port_id})
nova = self._nova_client()
instance = nova.servers.get(device_id)
try:
instance = nova.servers.get(device_id)
except self._novaclient.exceptions.NotFound:
LOG.error(_LE("server %s is not found") %
device_id)
return
instance.interface_attach(port_id, None, None)
def dettach_interface(self, plugin, context, device_id, port_id):
LOG.debug(_('detaching interface %(device_id)s %(port_id)s'),
{'device_id': device_id, 'port_id': port_id})
nova = self._nova_client()
instance = nova.servers.get(device_id)
try:
instance = nova.servers.get(device_id)
except self._novaclient.exceptions.NotFound:
LOG.error(_LE("server %s is not found") %
device_id)
return
instance.interface_detach(port_id)