Skip to content

Commit

Permalink
Ensure hairpin_mode is set whenever vifs is added to bridge.
Browse files Browse the repository at this point in the history
Fix the bug that when create a snapshot of an instance, the
instance cann't ping it's floating ip.
fix bug lp:1040537

Change-Id: I25aa1a323fa84e8c72f969cb56ada4dffa509150
  • Loading branch information
yaguangtang committed Aug 24, 2012
1 parent af687ff commit ee7b56f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions nova/virt/libvirt/driver.py
Expand Up @@ -1014,8 +1014,8 @@ def poll_rebooting_instances(self, timeout):
def poll_rescued_instances(self, timeout):
pass

def _enable_hairpin(self, instance):
interfaces = self.get_interfaces(instance['name'])
def _enable_hairpin(self, xml):
interfaces = self.get_interfaces(xml)
for interface in interfaces:
utils.execute('tee',
'/sys/class/net/%s/brport/hairpin_mode' % interface,
Expand Down Expand Up @@ -1846,6 +1846,7 @@ def _create_domain(self, xml=None, domain=None, launch_flags=0):
if xml:
domain = self._conn.defineXML(xml)
domain.createWithFlags(launch_flags)
self._enable_hairpin(domain.XMLDesc(0))
return domain

def _create_domain_and_network(self, xml, instance, network_info,
Expand All @@ -1866,7 +1867,6 @@ def _create_domain_and_network(self, xml, instance, network_info,
self.firewall_driver.setup_basic_filtering(instance, network_info)
self.firewall_driver.prepare_instance_filter(instance, network_info)
domain = self._create_domain(xml)
self._enable_hairpin(instance)
self.firewall_driver.apply_instance_filter(instance, network_info)
return domain

Expand Down Expand Up @@ -1908,14 +1908,12 @@ def get_disks(self, instance_name):
[target.get("dev")
for target in doc.findall('devices/disk/target')])

def get_interfaces(self, instance_name):
def get_interfaces(self, xml):
"""
Note that this function takes an instance name.
Note that this function takes an domain xml.
Returns a list of all network interfaces for this instance.
"""
domain = self._lookup_by_name(instance_name)
xml = domain.XMLDesc(0)
doc = None

try:
Expand Down

0 comments on commit ee7b56f

Please sign in to comment.