Added try loop for floating ip association and deletion, and port deletion
Change-Id: I94eb3c934a97f951893444c83f8a8dd55e9b8d29
This commit is contained in:
parent
0765cc21d3
commit
a429e9c0fb
@ -18,7 +18,9 @@ import re
|
|||||||
from log import LOG
|
from log import LOG
|
||||||
import monitor
|
import monitor
|
||||||
import netaddr
|
import netaddr
|
||||||
|
from novaclient.exceptions import BadRequest
|
||||||
import sshutils
|
import sshutils
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
# a dictionary of sequence number indexed by a name prefix
|
# a dictionary of sequence number indexed by a name prefix
|
||||||
@ -193,7 +195,12 @@ class Instance(object):
|
|||||||
self.ssh_access.host = fip['floatingip']['floating_ip_address']
|
self.ssh_access.host = fip['floatingip']['floating_ip_address']
|
||||||
self.ssh_ip_id = fip['floatingip']['id']
|
self.ssh_ip_id = fip['floatingip']['id']
|
||||||
self.display('Associating floating IP %s', self.ssh_access.host)
|
self.display('Associating floating IP %s', self.ssh_access.host)
|
||||||
self.instance.add_floating_ip(self.ssh_access.host, ipv4_fixed_address)
|
for _ in range(1, 5):
|
||||||
|
try:
|
||||||
|
self.instance.add_floating_ip(self.ssh_access.host, ipv4_fixed_address)
|
||||||
|
break
|
||||||
|
except BadRequest:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
# extract the IP for the data network
|
# extract the IP for the data network
|
||||||
self.display('Internal network IP: %s', self.internal_ip)
|
self.display('Internal network IP: %s', self.internal_ip)
|
||||||
|
@ -17,8 +17,10 @@ import time
|
|||||||
|
|
||||||
from log import LOG
|
from log import LOG
|
||||||
# Module containing a helper class for operating on OpenStack networks
|
# Module containing a helper class for operating on OpenStack networks
|
||||||
|
from neutronclient.common.exceptions import IpAddressInUseClient
|
||||||
from neutronclient.common.exceptions import NetworkInUseClient
|
from neutronclient.common.exceptions import NetworkInUseClient
|
||||||
from neutronclient.common.exceptions import NeutronException
|
from neutronclient.common.exceptions import NeutronException
|
||||||
|
from neutronclient.common.exceptions import PortInUseClient
|
||||||
import vmtp
|
import vmtp
|
||||||
|
|
||||||
class Network(object):
|
class Network(object):
|
||||||
@ -320,7 +322,13 @@ class Network(object):
|
|||||||
|
|
||||||
def delete_port(self, port):
|
def delete_port(self, port):
|
||||||
LOG.debug('Deleting port ' + port['id'])
|
LOG.debug('Deleting port ' + port['id'])
|
||||||
self.neutron_client.delete_port(port['id'])
|
for _ in range(1, 5):
|
||||||
|
try:
|
||||||
|
self.neutron_client.delete_port(port['id'])
|
||||||
|
break
|
||||||
|
except PortInUseClient:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
# Create a floating ip on the external network and return it
|
# Create a floating ip on the external network and return it
|
||||||
def create_floating_ip(self):
|
def create_floating_ip(self):
|
||||||
@ -334,7 +342,13 @@ class Network(object):
|
|||||||
|
|
||||||
# Delete floating ip given a floating ip ad
|
# Delete floating ip given a floating ip ad
|
||||||
def delete_floating_ip(self, floatingip):
|
def delete_floating_ip(self, floatingip):
|
||||||
self.neutron_client.delete_floatingip(floatingip)
|
LOG.info("Deleting floating ip " + floatingip)
|
||||||
|
for _ in range(1, 5):
|
||||||
|
try:
|
||||||
|
self.neutron_client.delete_floatingip(floatingip)
|
||||||
|
break
|
||||||
|
except IpAddressInUseClient:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
# Dispose all network resources, call after all VM have been deleted
|
# Dispose all network resources, call after all VM have been deleted
|
||||||
def dispose(self):
|
def dispose(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user