Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
Cloud:OpenStack:Stein:Staging
openstack-octavia
0001-Update-osutil-support-for-SUSE-distro.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0001-Update-osutil-support-for-SUSE-distro.patch of Package openstack-octavia
From 9f6804ac216ee3c639ef8017f8937896c7fa687a Mon Sep 17 00:00:00 2001 From: Swaminathan Vasudevan <SVasudevan@suse.com> Date: Fri, 26 Jan 2018 14:25:32 -0800 Subject: [PATCH] Add support for SUSE in osutils to handle networks Add support for SUSE in osutils to handle network pluging inside the namespace. SUSE distro specific network related OS handling routines are added along with thier template files --- .../amphorae/backends/agent/api_server/osutils.py | 149 +++++++++++++++++++++ .../templates/suse_plug_port_ethX.conf.j2 | 45 +++++++ .../templates/suse_plug_vip_ethX.conf.j2 | 59 ++++++++ .../api_server/templates/suse_route_ethX.conf.j2 | 23 ++++ 4 files changed, 276 insertions(+) create mode 100644 octavia/amphorae/backends/agent/api_server/templates/suse_plug_port_ethX.conf.j2 create mode 100644 octavia/amphorae/backends/agent/api_server/templates/suse_plug_vip_ethX.conf.j2 create mode 100644 octavia/amphorae/backends/agent/api_server/templates/suse_route_ethX.conf.j2 diff --git a/octavia/amphorae/backends/agent/api_server/osutils.py b/octavia/amphorae/backends/agent/api_server/osutils.py index 3d1babf5..91db7451 100644 --- a/octavia/amphorae/backends/agent/api_server/osutils.py +++ b/octavia/amphorae/backends/agent/api_server/osutils.py @@ -452,3 +452,152 @@ class RH(BaseOS): def has_ifup_all(self): return False + + +class Suse(BaseOS): + + ETH_X_PORT_CONF = 'suse_plug_port_ethX.conf.j2' + ETH_X_VIP_CONF = 'suse_plug_vip_ethX.conf.j2' + ROUTE_ETH_X_CONF = 'suse_route_ethX.conf.j2' + + @classmethod + def is_os_name(cls, os_name): + return os_name in ['openSuse', 'SuSE', 'SUSE'] + + def cmd_get_version_of_installed_package(self, package_name): + return "dpkg --status {name}".format(name=package_name) + + def get_network_interface_file(self, interface): + if CONF.amphora_agent.agent_server_network_file: + return CONF.amphora_agent.agent_server_network_file + if CONF.amphora_agent.agent_server_network_dir: + return os.path.join(CONF.amphora_agent.agent_server_network_dir, + 'ifcfg-' + interface) + network_dir = consts.SUSE_AMP_NET_DIR_TEMPLATE.format( + netns=consts.AMPHORA_NAMESPACE) + if 'ifroute' in interface: + return os.path.join(network_dir, interface) + else: + return os.path.join(network_dir, 'ifcfg-' + interface) + + def get_network_path(self): + return '/etc/sysconfig/network' + + def get_netns_network_dir(self): + network_full_path = self.get_network_path() + network_basename = os.path.basename(network_full_path) + network_dirname = os.path.dirname(network_full_path) + network_prefixdir = os.path.basename(network_dirname) + return os.path.join(network_prefixdir, network_basename) + + def static_routes_interface_file(self, interface): + return self.get_network_interface_file('ifroute-' + interface) + + def create_netns_dir( + self, network_dir=None, netns_network_dir=None, ignore=None): + if not netns_network_dir: + netns_network_dir = self.get_netns_network_dir() + LOG.debug("Netns network directory: %s", netns_network_dir) + if not network_dir: + network_dir = self.get_network_path() + LOG.debug("Network directory: %s", network_dir) + if not ignore: + ignore = shutil.ignore_patterns('ifcfg-eth0*') + super(Suse, self).create_netns_dir( + network_dir, netns_network_dir, ignore) + + def write_interfaces_file(self): + # No interfaces file in Suse distros. + return + + def write_vip_interface_file(self, interface_file_path, + primary_interface, vip, ip, broadcast, + netmask, gateway, mtu, vrrp_ip, vrrp_version, + render_host_routes, template_vip=None): + if not template_vip: + template_vip = j2_env.get_template(self.ETH_X_VIP_CONF) + super(Suse, self).write_vip_interface_file( + interface_file_path, primary_interface, vip, ip, broadcast, + netmask, gateway, mtu, vrrp_ip, vrrp_version, render_host_routes, + template_vip) + + routes_interface_file_path = ( + self.get_static_routes_interface_file(primary_interface)) + template_routes = j2_env.get_template(self.ROUTE_ETH_X_CONF) + + self.write_static_routes_interface_file( + routes_interface_file_path, primary_interface, + render_host_routes, template_routes, gateway, vip) + # NOTE: Copy{netns}/etc/sysconfig/network/ifroute-* file to + # /etc/sysconfig/network to overcome an issue with the + # ifup-route and namespace. + dst = '/etc/sysconfig/network' + shutil.copy2(routes_interface_file_path, dst) + + def write_static_routes_interface_file(self, interface_file_path, + interface, host_routes, + template_routes, gateway, vip): + # write static routes interface file + + mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH + + # TODO(johnsom): We need a way to clean out old interfaces records + if CONF.amphora_agent.agent_server_network_file: + flags = os.O_WRONLY | os.O_CREAT | os.O_APPEND + else: + flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC + + with os.fdopen(os.open(interface_file_path, flags, mode), + 'w') as text_file: + text = template_routes.render( + interface=interface, + host_routes=host_routes, + gateway=gateway, + vip=vip, + ) + text_file.write(text) + + def write_port_interface_file(self, netns_interface, fixed_ips, mtu, + interface_file_path=None, + template_port=None): + if not interface_file_path: + interface_file_path = self.get_network_interface_file( + netns_interface) + if not template_port: + template_port = j2_env.get_template(self.ETH_X_PORT_CONF) + super(Suse, self).write_port_interface_file( + netns_interface, fixed_ips, mtu, interface_file_path, + template_port) + + def _bring_ns_if_up(self, interface, what): + # Note, we are not using pyroute2 for this as it is not /etc/netns + # aware. + os.chdir('/etc/sysconfig/network') + cmd = ("ip netns exec {ns} ifup.ns {params}".format( + ns=consts.AMPHORA_NAMESPACE, params=interface)) + try: + subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + LOG.error('Failed to if up %s due to error: %s', interface, e) + raise exceptions.HTTPException( + response=webob.Response(json=dict( + message='Error plugging {0}'.format(what), + details=e.output), status=500)) + + def _bring_ns_if_down(self, interface): + # Note, we are not using pyroute2 for this as it is not /etc/netns + # aware. + os.chdir('/etc/sysconfig/network') + cmd = ("ip netns exec {ns} ifdown.ns {params}".format( + ns=consts.AMPHORA_NAMESPACE, params=interface)) + try: + subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + pass + + def bring_interfaces_up(self, ip, primary_interface, secondary_interface): + self._bring_ns_if_down(primary_interface) + self._bring_ns_if_up(primary_interface, 'VIP') + + def has_ifup_all(self): + return True diff --git a/octavia/amphorae/backends/agent/api_server/templates/suse_plug_port_ethX.conf.j2 b/octavia/amphorae/backends/agent/api_server/templates/suse_plug_port_ethX.conf.j2 new file mode 100644 index 00000000..e130c3b8 --- /dev/null +++ b/octavia/amphorae/backends/agent/api_server/templates/suse_plug_port_ethX.conf.j2 @@ -0,0 +1,45 @@ +{# +# Copyright 2018 SUSE LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +#} +# Generated by Octavia agent +DEVICE="{{ interface }}" +ONBOOT="yes" +STARTMODE="auto" +TYPE="Ethernet" +{%- if ipv6 %} +IPV6INIT="yes" +{%- if mtu %} +IPV6_MTU="{{ mtu }}" +{%- endif %} +{%- if ip_address %} +IPV6_AUTOCONF="no" +IPV6ADDR="{{ ip_address }}" +{%- else %} +IPV6_AUTOCONF="yes" +{%- endif %} +{%- else %} +IPV6INIT="no" +{%- if mtu %} +MTU="{{ mtu }}" +{%- endif %} +{%- if ip_address %} +BOOTPROTO="static" +IPADDR="{{ ip_address }}" +NETMASK="{{ netmask }}" +{%- else %} +BOOTPROTO="dhcp" +{%- endif %} +{%- endif %} + diff --git a/octavia/amphorae/backends/agent/api_server/templates/suse_plug_vip_ethX.conf.j2 b/octavia/amphorae/backends/agent/api_server/templates/suse_plug_vip_ethX.conf.j2 new file mode 100644 index 00000000..79390a38 --- /dev/null +++ b/octavia/amphorae/backends/agent/api_server/templates/suse_plug_vip_ethX.conf.j2 @@ -0,0 +1,59 @@ +{# +# Copyright 2018 SUSE LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +#} +# Generated by Octavia agent +DEVICE="{{ interface }}" +ONBOOT="yes" +TYPE="Ethernet" +USERCTL="yes" +STARTMODE="auto" +LINK_REQUIRED="no" +{%- if vrrp_ip %} +{%- if vrrp_ipv6 %} +IPV6INIT="yes" +IPV6_DEFROUTE="yes" +IPV6_AUTOCONF="no" +IPV6ADDR="{{ vrrp_ip }}/{{ prefix }}" +{%- if gateway %} +IPV6_DEFAULTGW="{{ gateway }}" +{%- endif %} +{%- if mtu %} +IPV6_MTU="{{ mtu }}" +{%- endif %} +{%- else %} {# not vrrp_ipv6 #} +BOOTPROTO="static" +IPADDR="{{ vrrp_ip }}" +NETMASK="{{ netmask }}" +{%- if gateway %} +GATEWAY="{{ gateway }}" +{%- endif %} +MTU="{{ mtu }}" +LABEL_0="0" +IPADDR_0="{{ vip }}" +NETMASK_0="{{ netmask }}" +{%- endif %} {# end if vrrp_ipv6 #} +{%- else %} {# not vrrp_ip #} +{%- if vip_ipv6 %} +IPV6INIT="yes" +IPV6_DEFROUTE="yes" +IPV6_AUTOCONF="yes" +{%- else %} +BOOTPROTO="dhcp" +{%- endif %} {# end if vip_ipv6 #} +{%- endif %} {# end if vrrp_ip #} + +{%- if vip_ipv6 %} +IPV6ADDR_SECONDARIES="{{ vip }}/{{ prefix }}" +{%- endif %} diff --git a/octavia/amphorae/backends/agent/api_server/templates/suse_route_ethX.conf.j2 b/octavia/amphorae/backends/agent/api_server/templates/suse_route_ethX.conf.j2 new file mode 100644 index 00000000..2ed706a7 --- /dev/null +++ b/octavia/amphorae/backends/agent/api_server/templates/suse_route_ethX.conf.j2 @@ -0,0 +1,23 @@ +{# +# Copyright 2018 SUSE LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +#} +# Generated by Octavia agent +{%- for hr in host_routes %} +{{ hr.network }} {{ hr.gw }} {{ hr.netmask}} {{ interface }} +{%- endfor %} +# Add a source routing table to allow members to access the VIP +{%- if gateway %} +default {{ gateway }} - - +{%- endif %} -- 2.13.6
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor