Modify container network create for seamless additions
This change adds the ability for a container to have network interfaces added without needing to restart to get the interfaces online. Adding the interface with the container online will be faster and allow for rolling changes in an environment that may effect critical services that run from within a container. Change-Id: I68048ae10cdd52fc3b5c43542686e056237a9305 Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
parent
56792db4db
commit
e48e4fe204
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright 2016, Rackspace US, Inc.
|
||||
#
|
||||
# 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.
|
||||
set -ev
|
||||
|
||||
# Execution example: lxc-veth-wiring.sh testing VETHTEST eth1 br-mgmt
|
||||
|
||||
# CLI variables
|
||||
CONTAINER_NAME="${1}"
|
||||
VETH="${2}"
|
||||
INTERFACE="${3}"
|
||||
BRIDGE="${4}"
|
||||
VETH_PEER="$(openssl rand -hex 4)"
|
||||
|
||||
# PID of running container
|
||||
PID="$(lxc-info -pHn ${CONTAINER_NAME})"
|
||||
|
||||
# Exit 0 means no change, exit 3 is changed, any other exit is fail.
|
||||
EXIT_CODE=0
|
||||
|
||||
if ! ip a l "${VETH}";then
|
||||
ip link add name "${VETH}" type veth peer name "${VETH_PEER}"
|
||||
ip link set dev "${VETH}" up
|
||||
EXIT=3
|
||||
else
|
||||
ip link set dev "${VETH}" up
|
||||
fi
|
||||
|
||||
if ip a l "${VETH_PEER}";then
|
||||
ip link set dev "${VETH_PEER}" up
|
||||
ip link set dev "${VETH_PEER}" netns "${PID}" name "${INTERFACE}"
|
||||
EXIT=3
|
||||
fi
|
||||
|
||||
if ! brctl show "${BRIDGE}" | grep -q "${VETH}"; then
|
||||
brctl addif "${BRIDGE}" "${VETH}"
|
||||
EXIT=3
|
||||
fi
|
||||
|
||||
lxc-attach --name "${CONTAINER_NAME}" <<EOC
|
||||
ip link set dev "${INTERFACE}" up
|
||||
ifdown "${INTERFACE}"
|
||||
ifup "${INTERFACE}"
|
||||
EOC
|
||||
|
||||
exit ${EXIT}
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
features:
|
||||
- The LXC container creation and modification process now supports
|
||||
online network additions. This ensures a container remains online
|
||||
when additional networks are added to a system.
|
|
@ -180,8 +180,6 @@
|
|||
group: "root"
|
||||
mode: "0644"
|
||||
with_dict: "{{ container_networks | default({}) }}"
|
||||
notify:
|
||||
- Lxc container restart
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc-container-networks
|
||||
|
@ -205,10 +203,36 @@
|
|||
line: "lxc.include = /var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.ini"
|
||||
backup: "true"
|
||||
with_dict: "{{ container_networks | default({}) }}"
|
||||
when: >
|
||||
item.value.interface is defined
|
||||
notify:
|
||||
- Lxc container restart
|
||||
when: item.value.interface is defined
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc-container-networks
|
||||
|
||||
- name: Create wiring script
|
||||
copy:
|
||||
src: "lxc-veth-wiring.sh"
|
||||
dest: "/usr/local/bin/lxc-veth-wiring"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0755"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc-container-networks
|
||||
|
||||
- name: Run container veth wiring script
|
||||
shell: >
|
||||
/usr/local/bin/lxc-veth-wiring
|
||||
"{{ inventory_hostname }}"
|
||||
"{{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_{{ item.value.interface }}"
|
||||
"{{ item.value.interface }}"
|
||||
"{{ item.value.bridge }}"
|
||||
register: wiring_script
|
||||
with_dict: "{{ container_networks | default({}) }}"
|
||||
when:
|
||||
- item.value.interface is defined
|
||||
- item.value.type is not defined or item.value.type == 'veth'
|
||||
failed_when: wiring_script.rc not in [3, 0]
|
||||
changed_when: wiring_script.rc == 3
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc-container-networks
|
||||
|
|
Loading…
Reference in New Issue