From 50c49495d863c2183edb6a871c71edf2bd61476d Mon Sep 17 00:00:00 2001
From: Sharmin Choksey <schoksey@cisco.com>
Date: Sat, 22 Dec 2018 19:02:34 -0800
Subject: [PATCH] [ipv4_sriov] Support for IPv4 with SRIOV

Enables support for IPv4 with SRIOV on RHEL guest images

Change-Id: I9b1ec46cc25d81e64c329903956a3794337652da
---
 vmtp/compute.py  |  2 +-
 vmtp/instance.py | 36 +++++++++++++++++++++++++++++++++---
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/vmtp/compute.py b/vmtp/compute.py
index ffae6e3..70e71fb 100644
--- a/vmtp/compute.py
+++ b/vmtp/compute.py
@@ -435,7 +435,7 @@ class Compute(object):
         if self.config.ipv6_mode:
             self.neutron.create_security_group_rule(
                 self.generate_security_group_rule_dict(group_id=group["id"],
-                                                       protocol="icmp",
+                                                       protocol="icmpv6",
                                                        ethertype="IPv6"))
 
         # Allow SSH traffic
diff --git a/vmtp/instance.py b/vmtp/instance.py
index 1f16a48..1c8bbd7 100644
--- a/vmtp/instance.py
+++ b/vmtp/instance.py
@@ -89,7 +89,7 @@ class Instance(object):
             dns_servers = ','.join(subnet_info['dns_nameservers'])
             network_dict['dns'] = 'dns-nameservers %s\n' % dns_servers
 
-        retStr = (
+        interface_snippet = (
             '# The loopback network interface\n'
             'auto lo\n'
             'iface lo inet loopback\n'
@@ -104,6 +104,37 @@ class Instance(object):
             '        gateway %(gateway)s\n'
             '        %(dns)s'
         ) % network_dict
+        files = {'/etc/network/interfaces': interface_snippet}
+
+        if self.config.vm_image_url:
+            pattern = re.search(r'rhel', self.config.vm_image_url, re.I)
+            if pattern:
+                interface_snippet = \
+                    self.generate_rhel_interface(network_dict)
+                files = {
+                    '/etc/sysconfig/network-scripts/ifcfg-eth0':
+                    interface_snippet
+                }
+
+        return files
+
+    def generate_rhel_interface(self, network_dict):
+        retStr = None
+        # Note: For v6, no network custimizaton is needed. If the
+        # upstream router sends the correct RA in response to the RS
+        # then the interface should get auto-calculated and the default
+        # route should automatically be injected
+        if not self.config.ipv6_mode:
+            retStr = (
+                'DEVICE=eth0\n'
+                'BOOTPROTO=static\n'
+                'ONBOOT=no\n'
+                'DEFROUTE=yes\n'
+                'NM_CONTROLLED=no\n'
+                'IPADDR=%(ip_address)s\n'
+                'NETMASK=%(netmask)s\n'
+                'GATEWAY=%(gateway)s'
+            ) % network_dict
 
         return retStr
 
@@ -142,8 +173,7 @@ class Instance(object):
 
         files = None
         if self.config.no_dhcp:
-            network_interface = self.get_network_interface(self.port)
-            files = {'/etc/network/interfaces': network_interface}
+            files = self.get_network_interface(self.port)
 
         self.instance = self.comp.create_server(self.name,
                                                 image,