Compare commits

..

112 Commits

Author SHA1 Message Date
Eugene Zamriy 773e74d25e
Adds MSVSphere distribution support
2 years ago
Jan Orel 67eeaabb18
M #-: Bump version to 6.6.0
2 years ago
Jan Orel 381b5b10da
M #-: Avoid slow contextualization
2 years ago
Ruben S. Montero 7324b69f82
B #-: Avoid netplan race condition
2 years ago
Jan Orel 8073d3271c
B #-: Avoid netplan race condition
2 years ago
Ruben S. Montero 3de2c1f8d3
Update list of Linux distributions
2 years ago
Daniel Clavijo Coca 8d5047d9aa
M #: Bump version to 6.4.1
2 years ago
Ruben S. Montero 6c2ab5c634
F #267: Add EL9 support
2 years ago
Petr Ospalý 7f58221986
Merge pull request #272 from ospalax/b-266-fix-nofsroot-in-old-os
2 years ago
Petr Ospalý 37b46e1a4c
B #266: Workaround old broken util-linux
2 years ago
Petr Ospalý f976d999b2
Merge pull request #271 from ospalax/f-265-improve-start-script
2 years ago
Petr Ospalý 097d9a42e0
F #265: Improve START_SCRIPT
2 years ago
Petr Ospalý 48a469a019
Merge pull request #270 from ospalax/b-266-fix-growfs-btrfs
3 years ago
Petr Ospalý 19a280c91b
B #266: Fix GROW_ROOTFS and GROW_FS on btrfs
3 years ago
Elkhan Mammadli 5cffad221c
F #267: Add EL9 support
3 years ago
Petr Ospalý 3be568eff0
Merge pull request #264 from ospalax/6.4
3 years ago
Petr Ospalý e15422d871
M #-: Update README
3 years ago
Petr Ospalý 0c2ea340fa
Merge pull request #263 from OpenNebula/6.4
3 years ago
Petr Ospalý 587c52781d
M #-: Bump version to 6.4.0
3 years ago
Petr Ospalý 3dcc05a406
Merge pull request #262 from ospalax/add-support-for-ignore-swap
3 years ago
Thomas Lejeune 0831bdf59d
F #260: Add IGNORE_SWAP context param
3 years ago
Thomas Lejeune 439b4af8b9
Allow disabling SWAP
3 years ago
Petr Ospalý 6c18bfb4b4
Merge pull request #261 from ospalax/enforce-lang-c
3 years ago
Petr Ospalý 8c875a1a3c
B #251: Improve locale handling
3 years ago
Ruben S. Montero 40efc92948
M #-: sync onegate with OpenNebula one
3 years ago
Ruben S. Montero 8df3030bcd
Update onegate.rb
3 years ago
Alejandro Huertas b246b8f151
M #-: sync onegate with OpenNebula one
3 years ago
Petr Ospalý 280f193655
Merge pull request #255 from ospalax/f-39-workaround-vmware-tools
3 years ago
Petr Ospalý 6c1ff12d74
F one-infra#39: Add weak dependency support
3 years ago
Daniel Dehennin 74385d0961
B #251: Force $LANG to C.UTF-8
3 years ago
Vlastimil Holer 72b895dcea
M #-: Update README
3 years ago
Vlastimil Holer a5aa14fcc1
M #-: Update tested platforms
3 years ago
Vlastimil Holer 9a6a0182cc
M #-: Update tested platforms
3 years ago
Vlastimil Holer b28cc857d1
B OpenNebula/one#5504: Handle nicely acpid on systemd
3 years ago
Vlastimil Holer 0661840e7c
M #-: Bump version to 6.2.0
3 years ago
Vlastimil Holer 5cb9f3aaa3
F #248: Restart syslog on hostname change
3 years ago
Vlastimil Holer bc0743fcf8
B #247: Retry CD-ROM mount
3 years ago
Vlastimil Holer 484e436596
F #227, #86: Workaround sporadic IPv6 SLAAC privacy address on Ubuntus
3 years ago
Vlastimil Holer 0af852da61
M #-: Fix fallback detection in onesysprep of RHEL/C6
3 years ago
Your Name c228e8c00f
F #227: Fix RHEL 6 detection
3 years ago
Your Name b10f2b32c4
M #-: Fallback detection in onesysprep of RHEL/CentOS 6
3 years ago
Your Name b87d2c8959
M #-: Support amzn, sles, sled in onesysprep
3 years ago
Vlastimil Holer 6796fa0a7d
F OpenNebula/addon-context-linux#86: Update GATEWAY6 to IP6_GATEWAY
3 years ago
Vlastimil Holer df90cb5eb0
F #227, #86: Netcfg default for Amazon Linux 2, typos
3 years ago
Vlastimil Holer d5e3d3ac93
M #-: README.md, Narrow NETCFG_TYPE table
3 years ago
Vlastimil Holer 59591e5dfb
M #-: Drop legacy Arch Linux build descriptors
3 years ago
Vlastimil Holer e463ebf28f
M #-: Put minimal description for network configuration types
3 years ago
Vlastimil Holer 962153d817
F #227, #86: Various fixes
3 years ago
Remy Zandwijk 25690dc21f Add additional (Ubuntu) log files to be deleted.
3 years ago
Vlastimil Holer 4f691774d8
M #-: Update tested platforms
3 years ago
Vlastimil Holer eaccee4ff4
B #243: Occasionally no recontextualization on CD-ROM change
3 years ago
Petr Ospalý bfba520831
F #227: Refactor loc-10-network
3 years ago
Vlastimil Holer 70cf13f434
F #185: Recontextualizaton on vCenter
3 years ago
Vlastimil Holer 7701d3a426
B #163: Drop stderr from update-conf (Alpine)
3 years ago
Vlastimil Holer 3176c6a635
B #163: Enable services on upgrade
3 years ago
Vlastimil Holer bcd3c5b43a
F #237: Timeout on REPORT_READY
3 years ago
Petr Ospalý 914ceae299
F #227: Refactor loc-10-network
3 years ago
Petr Ospalý 688c04e14c
F #227: Refactor loc-10-network
3 years ago
Vlastimil Holer 1e6741b345
M #-: Update tested combinations
3 years ago
Vlastimil Holer c2b10350d0 B #231: Add dependency on gawk
4 years ago
Petr Ospalý 45a8bdb39b B #231: Workaround the mawk issue on Debian
4 years ago
Vlastimil Holer 86f639b670
M #-: onesysprep add Alma, Rocky, OL flavours
4 years ago
Vlastimil Holer d1f4d3a97d
M #-: Replace real mount check for flag check
4 years ago
Vlastimil Holer 9d4d93eaa7
M #-: Bump version to 6.1.80, drop ec2 targets
4 years ago
Vlastimil Holer c6b47e093b
M #-: Improve mount/umount, revamp code
4 years ago
Moin 4238552798
Fix potential mount/umount issue on FreeBSD
4 years ago
Petr Ospalý 789ac3cf4b
F OpenNebula/one#4257: Add non-rootfs resize
4 years ago
Vlastimil Holer 4577d94d62
Revert "M #-: GHA ignore growpart script"
4 years ago
Vlastimil Holer 19623ba9bd
M #-: GHA ignore growpart script
4 years ago
Vlastimil Holer 740623f403
M #-: GitHub Workflow configuration
4 years ago
Petr Ospalý 7a8cb816c8 F #85: Retry report READY
4 years ago
Petr Ospalý 8a4026e4f6
M #-: Sanitize init script names (#225)
4 years ago
Vlastimil Holer b64deb39d3
M #-: Updated tested platforms
4 years ago
Vlastimil Holer cfecad0516
M #-: Updated tested platforms
4 years ago
Vlastimil Holer ee5f8f36f8
M #-: Updated tested platforms
4 years ago
Vlastimil Holer d847784380 B #223: Generate SSH host keys with ssh-keygen -A
4 years ago
Vlastimil Holer bb2df2ab2c
M #-: Bump version to 6.0.0 and year
4 years ago
Petr Ospalý 04d85b45b6 B #112: Move script location outside of /tmp
4 years ago
Alexandre Derumier fccb01f52d F #-: debian: add ifupdown2 support
4 years ago
Vlastimil Holer 2c7775ca8a
B #221: Don't recontextualize on swap cold-plug
4 years ago
Alejandro Huertas 811cf98c49 B #5258: remove comma after shutdown
4 years ago
Vlastimil Holer 23fb8394e7 M #-: Polish script to RECREATE_RUN
4 years ago
Alejandro Huertas c68deb36c2 M #-: add script to recreate TMPFS
4 years ago
Vlastimil Holer 2e487803a0
B #216: More specific detach NIC workarounds
4 years ago
Vlastimil Holer 4144f9a794
M #-: Remove SLES from tested platforms
4 years ago
Vlastimil Holer 092c2a38ee
M #-: Updated tested platforms
4 years ago
Vlastimil Holer 91b180323f
F OpenNebula/one#5112: Update OneGate client to 5.12.6 (EE)
4 years ago
Petr Ospalý d8bcc73e34 F #127: Add onesysprep initial implementation
4 years ago
Vlastimil Holer 18ae88b264
M #-: Bump version to 5.13.80
4 years ago
Petr Ospalý 4ac75a4242 B #212: Fix chown command on FreeBSD
4 years ago
Vlastimil Holer 470d7f8e2b
B #83: Fix RH postinstall
4 years ago
Vlastimil Holer 88c05bae60
M #-: Bump year to 2020, unify banners
5 years ago
Vlastimil Holer 5f8d30999c
M #-: Updated tested platforms
5 years ago
Vlastimil Holer d7cca66be1
M #-: Bump version to 5.12.0
5 years ago
Tino Vázquez f6c124368e
M #-: add OneGate Header
5 years ago
Alejandro Huertas 123b0fcfac
M #-: add OneGate Header
5 years ago
Petr Ospalý a8bed00766 B #83: Fix route metrics for CentOS
5 years ago
Petr Ospalý 3de259bf83
F #83: Add route metric support (#208)
5 years ago
Vlastimil Holer 556739406c
ALT Linux support (#207)
5 years ago
Alejandro Huertas 56bcbbd417 B OpenNebula/one#3571: sync context onegate with one
5 years ago
Vlastimil Holer 5ebfb379d9
M #-: Update tested platforms
5 years ago
Vlastimil Holer 656472c5de
M #-: Set hostname over hostnamectl only if it's working
5 years ago
Vlastimil Holer 94f752c936
M #-: On RH-like systems use systemctl from /usr/bin/
5 years ago
Vlastimil Holer ebbc0d62fa
M #-: Bump version to 5.11.80
5 years ago
Petr Ospalý cda2585f36 M #-: Cleanup Alpine
5 years ago
Vlastimil Holer e2b2c36f2a
F #196: Force recontextualization on NIC detach
5 years ago
Petr Ospalý 8d5542c45e
B #4439: fix Alpine networking
5 years ago
Vlastimil Holer cedee1c812
F OpenNebula/one#4089: busybox blkid simplification
5 years ago
Christian González 46ae040402 F OpenNebula/one#4089: Add changes for Firecracker context support
5 years ago
Vlastimil Holer 4b77825708
B #194: Live-resize boot disk on SCSI
5 years ago
Vlastimil Holer 5df43d72f6
B #190: Drop Python dependency
5 years ago
Vlastimil Holer 9d4e6943ca
M #-: Update tested platforms
5 years ago

@ -5,6 +5,6 @@
<!--//////////////////////////////////////////////////////////--> <!--//////////////////////////////////////////////////////////-->
Changes proposed in this pull request: Changes proposed in this pull request:
- - briefly describe change here,
- - briefly describe change here,
- - briefly describe change here.

@ -0,0 +1,14 @@
name: 'ShellCheck'
on: [push, pull_request]
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
scandir: './src'

1
.gitignore vendored

@ -2,3 +2,4 @@ out/
*.rpm *.rpm
*.deb *.deb
.vagrant*/ .vagrant*/
*~bak

@ -1,20 +0,0 @@
# Maintainer Harvard University FAS Research Computing <rchelp.fas.harvard.edu>
pkgname=one-context
pkgver=4.14.1
pkgrel=1
pkgdesc='OpenNebula Contextualisation'
arch=('any')
url='https://github.com/OpenNebula/addon-context-linux/releases'
license=('Apache')
depends=('mkinitcpio-growrootfs')
source=("")
install=one-context.install
md5sums=('')
package() {
cd ${srcdir}
TARGET=arch OUT=${pkgdir} ./generate.sh
cp -rT ${pkgdir}/usr/sbin ${pkgdir}/usr/bin
rm -rf ${pkgdir}/usr/sbin
}

@ -27,21 +27,83 @@ For beta releases, refer to the latest
List of tested platforms only: List of tested platforms only:
| Platform | Versions | | Platform | Versions |
|---------------------------------|----------------------------------------| |---------------------------------|------------------------------------------|
| AlmaLinux | 8, 9 |
| Alpine Linux | 3.13, 3.14, 3.15 |
| ALT Linux | 9, 10, Sisyphus |
| Amazon Linux | 2 | | Amazon Linux | 2 |
| CentOS | 6, 7 | | CentOS | 7, 8 Stream |
| Red Hat Enterprise Linux | 7, 8 | | Debian | 10, 11, 12 |
| Fedora | 29, 30 | | Devuan | 2 |
| openSUSE | 42.3, 15 | | Fedora | 34, 35 |
| SUSE Linux Enterprise Server | 12 SP3 | | FreeBSD | 12, 13 |
| Debian | 8, 9, 10 | | MSVSphere | 8, 9 |
| Devuan | 1, 2 | | openSUSE | 15 |
| Ubuntu | 14.04, 16.04, 18.04, 19.04 | | Oracle Linux | 7, 8 |
| Alpine Linux | 3.7, 3.8, 3.9, 3.10 | | Red Hat Enterprise Linux | 7, 8, 9 |
| FreeBSD | 11.2, 12.0 | | Rocky Linux | 8 |
| Ubuntu | 16.04, 18.04, 20.04, 21.10, 22.04 |
| Ubuntu Minimal | 20.04, 22.04 |
(the packages might work on other versions or flavours, but those aren't tested) (the packages might work on other versions or flavours, but those aren't tested)
### Guest Network Configuration
> **NOTE: Available since context packages version 6.2.0.**
The context scripts support selectable guest network management service (a component in guest OS responsible for assigning IP addresses, routes, and bringing interfaces up). Following network configuration types can be selected by setting the context variable `NETCFG_TYPE` (empty default fallbacks to autodetection of the most suitable one for a particular platform):
- `bsd` for FreeBSD network configuration,
- `interfaces` for Debian-style configuration in `/etc/network/interfaces`,
- `netplan` for Netplan with following renders set in context variable `NETCFG_NETPLAN_RENDERER`:
- empty or `networkd` for systemd-network (default),
- `NetworkManager` for NetworkManager
- `networkd` for systemd-networkd,
- `nm` for NetworkManager,
- `scripts` for legacy Red Hat-style configuration via `/etc/sysconfig/network-scripts/ifcfg-ethX` files.
Interface IP address configuration method can be customized as well. Following IPv4 configuration methods are supported via NIC attribute `METHOD`:
- empty or `static` for static address assignment based on context variables,
- `dhcp` for DHCPv4,
- `skip` to skip IPv4 configuration.
Following IPv6 configuration methods are supported via NIC attribute `IP6_METHOD`:
- empty or `static` for static address assignment based on context variables,
- `auto` for SLAAC,
- `dhcp` for SLAAC and DHCPv6,
- `disable` to disable IPv6 in guest,
- `skip` to skip IPv6 configuration.
Selectable configuration types and IP configuration methods are **supported only on the following platforms**:
| Platform | Network Type (`NETCFG_TYPE`) |
|-----------------------------------------------------------------|-------------------------------------------|
| Alpine Linux 3.14+ | `interfaces` |
| ALT Linux p10, Sisyphus | `networkd`, `nm` |
| Amazon Linux 2 | `scripts` |
| Debian 10+ | `interfaces`, `netplan`, `nm`, `networkd` |
| Devuan 2 | `interfaces` |
| Fedora 34+ | `scripts`, `nm`, `networkd` |
| FreeBSD 12+ | `bsd` |
| openSUSE 15 | `scripts` |
| RHEL-like 7 (CentOS, Oracle Linux) | `scripts` |
| RHEL-like 8 (CentOS, Oracle/Rocky/AlmaLinux/MSVSphere) | `scripts`, `nm`, `networkd` |
| RHEL-like 9 (CentOS Stream 9, Oracle/Rocky/AlmaLinux/MSVSphere) | `nm`, `networkd` |
| Ubuntu 18.04, 20.04, 21.10, 22.04 | `interfaces`, `netplan`, `nm`, `networkd` |
(other than listed platforms are not supported for using `NETCFG_TYPE` nor `METHOD`/`IP6_METHOD`!):
Known Issues:
- Alpine Linux: `IP6_METHOD=dhcp` runs DHCPv4 client instead of DHCPv6,
- Debian 10: `NETCFG_TYPE=netplan` with **networkd** doesn't configure IPv6 (only) SLAAC (`IP6_METHOD=auto`) when no IPv4 is configured,
- Debian/Ubuntu: `NETCFG_TYPE=netplan` with **NetworkManager** might not configure IPv6 SLAAC (`IP6_METHOD=auto`) for hot-plugged interfaces,
- Debian 10 and Ubuntu 18.04, 20.04: might trigger DHCPv6 with `IP6_METHOD=auto`
- on `NETCFG_TYPE=netplan` with **networkd**,
- on `NETCFG_TYPE=networkd`.
## Build own package ## Build own package
Packages for each release for supported guests are available in the Packages for each release for supported guests are available in the
@ -123,7 +185,7 @@ executed as a first during the post-networking contextualization stage.
## License ## License
Copyright 2002-2019, OpenNebula Project, OpenNebula Systems (formerly C12G Labs) Copyright 2002-2022, OpenNebula Project, OpenNebula Systems (formerly C12G Labs)
Licensed under the Apache License, Version 2.0 (the "License"); you may 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 not use this file except in compliance with the License. You may obtain

@ -3,7 +3,7 @@
set -e set -e
export DATE=$(date +%Y%m%d) export DATE=$(date +%Y%m%d)
TARGETS='el6 el7 el7_ec2 el8 el8_ec2 suse deb deb_ec2 alpine freebsd iso' TARGETS='el6 el7 el8 el9 alt suse deb alpine freebsd iso'
for TARGET in $TARGETS; do for TARGET in $TARGETS; do
TARGET="${TARGET}" ./generate.sh TARGET="${TARGET}" ./generate.sh

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2022, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -16,6 +16,8 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# shellcheck disable=SC1091
if [ -z "${TARGET}" ]; then if [ -z "${TARGET}" ]; then
echo 'Error: env. variable TARGET not set' >&2 echo 'Error: env. variable TARGET not set' >&2
exit 1 exit 1
@ -28,7 +30,7 @@ set +e
### ###
if [ -z "${RELEASE}" ]; then if [ -z "${RELEASE}" ]; then
if git describe --contains $(git rev-parse HEAD) &>/dev/null; then if git describe --contains "$(git rev-parse HEAD)" &>/dev/null; then
RELEASE=1 RELEASE=1
else else
DATE=${DATE:-$(date +%Y%m%d)} DATE=${DATE:-$(date +%Y%m%d)}
@ -39,9 +41,9 @@ fi
### ###
VERSION=${VERSION:-5.10.0} VERSION=${VERSION:-6.6.0}
RELEASE=${RELEASE:-0} RELEASE=${RELEASE:-1}
MAINTAINER=${MAINTAINER:-OpenNebula Systems <support@opennebula.systems>} MAINTAINER=${MAINTAINER:-OpenNebula Systems <contact@opennebula.io>}
LICENSE=${LICENSE:-Apache 2.0} LICENSE=${LICENSE:-Apache 2.0}
VENDOR=${VENDOR:-OpenNebula Systems} VENDOR=${VENDOR:-OpenNebula Systems}
SUMMARY="OpenNebula Contextualization Package" SUMMARY="OpenNebula Contextualization Package"
@ -68,6 +70,9 @@ elif [ "${TARGET}" = 'arch' ]; then
FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}-any.${EXT}" FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}-any.${EXT}"
elif [ "${TARGET}" = 'freebsd' ]; then elif [ "${TARGET}" = 'freebsd' ]; then
FILENAME="${NAME}-${VERSION}_${RELEASE_FULL}.${EXT}" FILENAME="${NAME}-${VERSION}_${RELEASE_FULL}.${EXT}"
elif [ "${TARGET}" = 'alt' ]; then
RELEASE_FULL="${RELSUFFIX}${RELEASE}"
FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.noarch.${EXT}"
elif [ "${TYPE}" = 'iso' ]; then elif [ "${TYPE}" = 'iso' ]; then
LABEL="${NAME}-${VERSION}" LABEL="${NAME}-${VERSION}"
FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.${EXT}" FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.${EXT}"
@ -87,12 +92,14 @@ _PREUN=$(mktemp)
_POSTUN=$(mktemp) _POSTUN=$(mktemp)
_POSTUP=$(mktemp) _POSTUP=$(mktemp)
# shellcheck disable=SC2064
trap "rm -rf ${UNAME_PATH} ${BUILD_DIR} ${_POSTIN} ${_PREUN} ${_POSTUN} ${_POSTUP}" EXIT trap "rm -rf ${UNAME_PATH} ${BUILD_DIR} ${_POSTIN} ${_PREUN} ${_POSTUN} ${_POSTUP}" EXIT
while IFS= read -r -d $'\0' SRC; do while IFS= read -r -d $'\0' SRC; do
F_TAGS=${SRC##*##} F_TAGS=${SRC##*##}
if [ "x${SRC}" != "x${F_TAGS}" ]; then if [ "x${SRC}" != "x${F_TAGS}" ]; then
for F_TAG in $(echo ${F_TAGS} | sed -e 's/\./ /g'); do # shellcheck disable=SC2001
for F_TAG in $(echo "${F_TAGS}" | sed -e 's/\./ /g'); do
for TAG in ${TAGS}; do for TAG in ${TAGS}; do
if [ "${F_TAG}" = "${TAG}" ]; then if [ "${F_TAG}" = "${TAG}" ]; then
continue 2 # tag matches, continue with next tag continue 2 # tag matches, continue with next tag
@ -108,7 +115,7 @@ while IFS= read -r -d $'\0' SRC; do
cp "src/${SRC}" "${BUILD_DIR}/${DST}" cp "src/${SRC}" "${BUILD_DIR}/${DST}"
done < <(cd src/ && find . -type f -print0) done < <(cd src/ && find . -type f -print0)
for F in $@; do for F in "$@"; do
cp -r "$F" "${BUILD_DIR}/" cp -r "$F" "${BUILD_DIR}/"
done done
@ -120,7 +127,8 @@ umask 0022
# cleanup # cleanup
if [ -z "${OUT}" ]; then if [ -z "${OUT}" ]; then
OUT="out/${FILENAME}" OUT="out/${FILENAME}"
mkdir -p $(dirname "${OUT}") _out_dir=$(dirname "${OUT}")
mkdir -p "${_out_dir}"
rm -rf "${OUT}" rm -rf "${OUT}"
fi fi
@ -141,11 +149,12 @@ if [ "${TYPE}" = 'dir' ]; then
cp -rT "${BUILD_DIR}" "${OUT}" cp -rT "${BUILD_DIR}" "${OUT}"
elif [ "${TYPE}" = 'iso' ]; then elif [ "${TYPE}" = 'iso' ]; then
_out_dir=$(dirname "${OUT}")
mkisofs -J -R -input-charset utf8 \ mkisofs -J -R -input-charset utf8 \
-m '*.iso' \ -m '*.iso' \
-V "${LABEL}" \ -V "${LABEL}" \
-o "${OUT}" \ -o "${OUT}" \
$(dirname "${OUT}") "${_out_dir}"
else else
CONFIG_FILES=$(cd "${BUILD_DIR}" && \ CONFIG_FILES=$(cd "${BUILD_DIR}" && \
@ -156,21 +165,26 @@ else
# concatenate pre/postinstall scripts # concatenate pre/postinstall scripts
if [ -n "${POSTIN}" ]; then if [ -n "${POSTIN}" ]; then
cat ${POSTIN} >"${_POSTIN}" cat "${POSTIN}" >"${_POSTIN}"
fi fi
if [ -n "${PREUN}" ]; then if [ -n "${PREUN}" ]; then
cat ${PREUN} >"${_PREUN}" cat "${PREUN}" >"${_PREUN}"
fi fi
if [ -n "${POSTUN}" ]; then if [ -n "${POSTUN}" ]; then
cat ${POSTUN} >"${_POSTUN}" cat "${POSTUN}" >"${_POSTUN}"
fi fi
if [ -n "${POSTUP}" ]; then if [ -n "${POSTUP}" ]; then
cat ${POSTUP} >"${_POSTUP}" cat "${POSTUP}" >"${_POSTUP}"
fi fi
# set the package version of onesysprep
sed -i "s/\<_PACKAGE_VERSION_\>/${VERSION}/" \
"${BUILD_DIR}/usr/sbin/onesysprep"
# shellcheck disable=SC2086
fpm --name "${NAME}" --version "${VERSION}" --iteration "${RELEASE_FULL}" \ fpm --name "${NAME}" --version "${VERSION}" --iteration "${RELEASE_FULL}" \
--architecture all --license "${LICENSE}" \ --architecture all --license "${LICENSE}" \
--vendor "${VENDOR}" --maintainer "${MAINTAINER}" \ --vendor "${VENDOR}" --maintainer "${MAINTAINER}" \
@ -184,6 +198,8 @@ else
--rpm-os linux \ --rpm-os linux \
--rpm-summary "${SUMMARY}" \ --rpm-summary "${SUMMARY}" \
${DEPENDS:+ --depends ${DEPENDS// / --depends }} \ ${DEPENDS:+ --depends ${DEPENDS// / --depends }} \
${RECOMMENDS:+ --rpm-tag Recommends:${RECOMMENDS// / --rpm-tag Recommends:}} \
${RECOMMENDS:+ --deb-recommends ${RECOMMENDS// / --deb-recommends }} \
${REPLACES:+ --replaces ${REPLACES// / --replaces }} \ ${REPLACES:+ --replaces ${REPLACES// / --replaces }} \
${CONFLICTS:+ --conflicts ${CONFLICTS// / --conflicts }} \ ${CONFLICTS:+ --conflicts ${CONFLICTS// / --conflicts }} \
${PROVIDES:+ --provides ${PROVIDES// / --provides }} \ ${PROVIDES:+ --provides ${PROVIDES// / --provides }} \
@ -194,4 +210,4 @@ else
--package "${OUT}" --package "${OUT}"
fi fi
echo $(basename ${OUT}) basename "${OUT}"

@ -1,5 +0,0 @@
post_install(){
systemctl enable one-context
rm -f /etc/systemd/network/*
}

@ -1,8 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
NETWORK=${NETWORK:-yes} SERVICES=${SERVICES:-one-context-local one-context-online one-context}
NETWORK_EC2=${NETWORK_EC2:-no} TIMERS=${TIMERS:-one-context-reconfigure.timer}
SERVICES=${SERVICES:-one-context-local one-context}
rm -f /etc/udev/rules.d/70-persistent-cd.rules rm -f /etc/udev/rules.d/70-persistent-cd.rules
rm -f /etc/udev/rules.d/70-persistent-net.rules rm -f /etc/udev/rules.d/70-persistent-net.rules
@ -19,8 +18,8 @@ if which systemctl >/dev/null 2>&1 && \
then then
systemctl daemon-reload >/dev/null 2>&1 || : systemctl daemon-reload >/dev/null 2>&1 || :
for S in ${SERVICES}; do for S in ${SERVICES} ${TIMERS}; do
systemctl enable "${S}.service" >/dev/null 2>&1 systemctl enable "${S}" >/dev/null 2>&1
done done
fi fi
@ -48,6 +47,21 @@ elif which rc-update >/dev/null 2>&1; then
rc-update add "${S}" boot >/dev/null 2>&1 rc-update add "${S}" boot >/dev/null 2>&1
done done
# Add crontab action for 1min schedules
if ! crontab -l -u root | grep -qF '/etc/periodic/1min'; then
(
crontab -l -u root
echo -e '\n# Added by one-context'
echo -e '* * * * * run-parts /etc/periodic/1min'
) | crontab -u root -
fi
# When existing file is changed, the new one might be created with
# .apk-new suffix. Such files need to be processed by update-conf.
if update-conf -al 2>/dev/null | grep -q context; then
echo 'WARNING: Run update-conf to process any updated one-context files in /etc!' >&2
fi
elif [ -x /bin/freebsd-version ]; then elif [ -x /bin/freebsd-version ]; then
: :
@ -58,33 +72,21 @@ fi
### Cleanup network configuration ########################## ### Cleanup network configuration ##########################
if [ "${NETWORK}" != 'yes' ]; then if [ -f /etc/sysctl.d/50-one-context.conf ]; then
exit rm -f /etc/sysctl.d/50-one-context.conf
fi fi
# Debian based distros # Debian based distros
if [ -d /etc/network ]; then if [ -d /etc/network ]; then
# Prepare network files # Prepare network files
cp /etc/network/interfaces /etc/network/interfaces.$(date "+%s") cp /etc/network/interfaces "/etc/network/interfaces.$(date '+%s')"
rm -rf /etc/network/interfaces.d rm -rf /etc/network/interfaces.d
rm -rf /etc/netplan/*
if [ "${NETWORK_EC2}" = 'yes' ]; then
cat > /etc/network/interfaces <<EOT cat > /etc/network/interfaces <<EOT
# The loopback network interface # The loopback network interface
auto lo auto lo
iface lo inet loopback iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOT EOT
else
cat > /etc/network/interfaces <<EOT
# The loopback network interface
auto lo
iface lo inet loopback
EOT
fi
# Do not reconfigure network interfaces on boot # Do not reconfigure network interfaces on boot
# if [ -f /etc/default/networking ]; then # if [ -f /etc/default/networking ]; then
@ -95,29 +97,16 @@ EOT
fi fi
# Red Hat based distros # Red Hat based distros
if [ -d /etc/sysconfig/network-scripts ]; then if [ -d /etc/sysconfig/network-scripts/ ]; then
# Prepare network files # Prepare network files
find /etc/sysconfig/network-scripts -type f \ find /etc/sysconfig/network-scripts -type f \
-name 'ifcfg-*' ! -name 'ifcfg-lo' \ \( -name 'ifcfg-*' -o -name 'route-*' -o -name 'route6-*' \) \
! -name 'ifcfg-lo' ! -name 'route-lo' ! -name 'route6-lo' \
-exec rm -f {} \; -exec rm -f {} \;
if [ "${NETWORK_EC2}" = 'yes' ]; then
cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<EOT
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
TYPE="Ethernet"
USERCTL="yes"
PEERDNS="yes"
IPV6INIT="no"
NM_CONTROLLED="no"
PERSISTENT_DHCLIENT="1"
EOT
fi
fi fi
# openSUSE based distros # openSUSE based distros
if [ -d /etc/sysconfig/network ]; then if [ -d /etc/sysconfig/network/ ]; then
# Prepare network files # Prepare network files
find /etc/sysconfig/network -type f \ find /etc/sysconfig/network -type f \
\( -name 'ifcfg-*' -o -name 'ifroute-*' -o -name 'ifsysctl-*' \) \ \( -name 'ifcfg-*' -o -name 'ifroute-*' -o -name 'ifsysctl-*' \) \
@ -126,17 +115,25 @@ if [ -d /etc/sysconfig/network ]; then
rm -f /etc/sysconfig/network/routes /etc/sysconfig/network/ifsysctl rm -f /etc/sysconfig/network/routes /etc/sysconfig/network/ifsysctl
sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/="/' /etc/sysconfig/network/config sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=""/' /etc/sysconfig/network/config
sed -i '/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=""/' /etc/sysconfig/network/config sed -i '/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=""/' /etc/sysconfig/network/config
fi
if [ "${NETWORK_EC2}" = 'yes' ]; then # Netplan
cat >/etc/sysconfig/network/ifcfg-eth0 <<EOT if [ -d /etc/netplan/ ]; then
DEVICE=eth0 rm -f /etc/netplan/*
BOOTPROTO=dhcp4
STARTMODE=auto
USERCONTROL=yes
EOT
fi fi
# NetworkManager
if [ -d /etc/NetworkManager/system-connections/ ]; then
rm -f /etc/NetworkManager/system-connections/*
fi
# systemd-networkd
if [ -d /etc/systemd/network/ ]; then
rm -f \
/etc/systemd/networkd/*.network \
/etc/systemd/networkd/*.link
fi fi
# FreeBSD based distros # FreeBSD based distros

@ -1,4 +0,0 @@
#!/usr/bin/env bash
NETWORK_EC2=yes
SERVICES='one-context'

@ -1,7 +1,66 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Reload udev rules
udevadm control --reload >/dev/null 2>&1 || : udevadm control --reload >/dev/null 2>&1 || :
if which systemctl >/dev/null 2>&1 && [ -d /etc/systemd ]; then ### Enable services ########################################
SERVICES=${SERVICES:-one-context-local one-context-online one-context}
TIMERS=${TIMERS:-one-context-reconfigure.timer}
if which systemctl >/dev/null 2>&1 && \
[ -d /etc/systemd ] && \
[ -f /usr/lib/systemd/system/one-context.service ];
then
systemctl daemon-reload >/dev/null 2>&1 || : systemctl daemon-reload >/dev/null 2>&1 || :
for S in ${SERVICES} ${TIMERS}; do
systemctl enable "${S}" >/dev/null 2>&1
done
fi
if which chkconfig >/dev/null 2>&1; then
for S in ${SERVICES}; do
chkconfig --add "${S}" >/dev/null 2>&1
done
# EL6: refresh initramfs via dracut for growroot module
if [ -f /usr/share/dracut/modules.d/50growroot/install ]; then
for I in $(find /boot -name 'initramfs-*.img'); do
KERNEL_VERS=$(echo "${I}" | sed -e 's/.*initramfs-\(.*\)\.img/\1/')
dracut -f "${I}" "${KERNEL_VERS}" || :
done
fi
elif which update-rc.d >/dev/null 2>&1; then
for S in ${SERVICES}; do
update-rc.d "${S}" enable >/dev/null 2>&1
update-rc.d "${S}" defaults >/dev/null 2>&1
done
elif which rc-update >/dev/null 2>&1; then
for S in ${SERVICES}; do
rc-update add "${S}" boot >/dev/null 2>&1
done
# Add crontab action for 1min schedules
if ! crontab -l -u root | grep -qF '/etc/periodic/1min'; then
(
crontab -l -u root
echo -e '\n# Added by one-context'
echo -e '* * * * * run-parts /etc/periodic/1min'
) | crontab -u root -
fi
# When existing file is changed, the new one might be created with
# .apk-new suffix. Such files need to be processed by update-conf.
if update-conf -al 2>/dev/null | grep -q context; then
echo 'WARNING: Run update-conf to process any updated one-context files in /etc!' >&2
fi
elif [ -x /bin/freebsd-version ]; then
:
else
echo 'WARNING: Contextualization service not enabled automatically' >&2
fi fi

@ -1,12 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SERVICES=${SERVICES:-one-context one-context-local} SERVICES=${SERVICES:-one-context one-context-online one-context-local one-context-reconfigure one-context-reconfigure-delayed}
TIMERS=${TIMERS:-one-context-reconfigure.timer}
# Disable services # Disable services
if which systemctl >/dev/null 2>&1 && [ -d /etc/systemd ]; then if which systemctl >/dev/null 2>&1 && [ -d /etc/systemd ]; then
for S in ${SERVICES}; do for S in ${TIMERS} ${SERVICES}; do
systemctl --no-reload disable "${S}.service" >/dev/null 2>&1 || : systemctl --no-reload disable "${S}" >/dev/null 2>&1 || :
systemctl stop "${S}.service" >/dev/null 2>&1 || : systemctl stop "${S}" >/dev/null 2>&1 || :
done done
fi fi

@ -1,3 +0,0 @@
#!/usr/bin/env bash
SERVICES='one-context'

@ -0,0 +1,7 @@
# This enables sensible default for 'unmanaged-devices' on ubuntu:
# https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
# https://askubuntu.com/questions/882806/ethernet-device-not-managed
#
# This file must exist prior start of NetworkManager to take an effect -
# a simple reloading of the already running daemon will not work.

@ -0,0 +1,3 @@
[main]
no-auto-default=*
dns=none

@ -0,0 +1,44 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
# -------------------------------------------------------------------------- #
# As of Netplan 0.102, the NetworkManager renderer can only enable
# IPv6 privacy if ipv6-privacy == true, but doesn't disable it if false.
# Instead of enforcing any global defaults, we set IPv6 privacy via sysctl
# on Netplan described interfaces in case the current settings is -1 (unknown),
# i.e. not explicitly configured. This is a forward compatible workaround, once
# Netplan properly sets NM ipv6.ip6-privacy=0, this code won't be effective.
case "${CONNECTION_ID}" in
netplan-*)
IP6_PRIVACY=$(nmcli -g ipv6.ip6-privacy con show "${CONNECTION_UUID}")
# overwrite only unknown state
if [ "${IP6_PRIVACY}" = '-1' ]; then
sysctl -q -w "net.ipv6.conf.${DEVICE_IFACE}.use_tempaddr=0"
# delete any existing temporary IPv6 addresses
ip -6 address show dev "${DEVICE_IFACE}" | \
grep 'inet6.*temporary' | \
tr -s ' ' | \
cut -d' ' -f 3 | \
xargs -r -n1 ip -6 address del dev "${DEVICE_IFACE}"
fi
;;
esac
exit 0

@ -0,0 +1,6 @@
# Periodically run one-context-reconfigure on VMware
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
MAILTO=''
* * * * * root if [ "$(virt-what 2>/dev/null)" = 'vmware' ]; then service one-context-reconfigure start >/dev/null 2>&1 || service one-context-reconfigure onestart >/dev/null 2>&1; fi

@ -0,0 +1,47 @@
# On NIC hotplug the delayed reconfiguration is triggered.
# NOTE: With hot-attached emulated NICs (e1000, ...) the interface
# and kernel event may appear later, even after CD-ROM is refreshed.
# Such interface doesn't configure, since new change in context
# script is not detected anymore. We hack the state files so that the
# recontextualization is forced to run.
notify 21 {
match "system" "ETHERNET";
match "type" "IFATTACH";
match "subsystem" "!vtnet[0-9]+";
action "/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network; service one-context-reconfigure-delayed onestart'";
};
notify 20 {
match "system" "ETHERNET";
match "type" "IFATTACH";
action "service one-context-reconfigure-delayed onestart";
};
notify 20 {
match "system" "IFNET";
match "type" "DETACH";
action "service one-context-reconfigure-delayed onestart";
};
# On CONTEXT CD-ROM change the immediate reconfiguration is triggered.
notify 20 {
match "system" "DEVFS";
match "subsystem" "CDEV";
match "type" "CREATE";
match "cdev" "iso9660/CONTEXT";
action "service one-context-reconfigure onestart";
};
# Handle disk resize
# NOTE: Event not generated on FreeBSD 12 and older
notify 20 {
match "system" "GEOM";
match "subsystem" "DEV";
match "type" "SIZECHANGE";
match "cdev" "!(cd[0-9]+|.*/.*|.*p[0-9]+)"; # skip CD-ROM/context, filesystems and partitions
action "service one-context-force onestart";
};
# Handle swap hot-attach
# NOTE: swap activation not supported on FreeBSD now

@ -1,11 +1,27 @@
#!/sbin/openrc-run #!/sbin/openrc-run
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
name="OpenNebula contextualization" name="OpenNebula contextualization"
depend() { depend() {
use one-context-local net use one-context-local net
before sshd before sshd
use logger after logger
keyword -stop -shutdown keyword -stop -shutdown
} }

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,5 +1,21 @@
#!/sbin/openrc-run #!/sbin/openrc-run
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
name="OpenNebula forced run" name="OpenNebula forced run"
depend() { depend() {

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,11 +1,27 @@
#!/sbin/openrc-run #!/sbin/openrc-run
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
name="OpenNebula pre-networking contextualization" name="OpenNebula pre-networking contextualization"
depend() { depend() {
need localmount udev udev-trigger udev-settle need localmount udev udev-trigger udev-settle
before net iptables keepalived before net
use logger after logger
keyword -stop -shutdown keyword -stop -shutdown
} }

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,5 +1,21 @@
#!/sbin/openrc-run #!/sbin/openrc-run
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
name="OpenNebula reconfiguration" name="OpenNebula reconfiguration"
depend() { depend() {

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,5 +1,21 @@
#!/sbin/openrc-run #!/sbin/openrc-run
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
name="OpenNebula delayed reconfiguration" name="OpenNebula delayed reconfiguration"
depend() { depend() {

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,3 +1,19 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
description "OpenNebula forced run" description "OpenNebula forced run"
author "OpenNebula Systems <support@opennebula.systems>" author "OpenNebula Systems <support@opennebula.systems>"

@ -1,3 +1,19 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
description "OpenNebula pre-networking contextualization" description "OpenNebula pre-networking contextualization"
author "OpenNebula Systems <support@opennebula.systems>" author "OpenNebula Systems <support@opennebula.systems>"

@ -1,3 +1,19 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
description "OpenNebula delayed reconfiguration" description "OpenNebula delayed reconfiguration"
author "OpenNebula Systems <support@opennebula.systems>" author "OpenNebula Systems <support@opennebula.systems>"

@ -1,3 +1,19 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
description "OpenNebula reconfiguration" description "OpenNebula reconfiguration"
author "OpenNebula Systems <support@opennebula.systems>" author "OpenNebula Systems <support@opennebula.systems>"

@ -1,3 +1,19 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
description "OpenNebula contextualization" description "OpenNebula contextualization"
author "OpenNebula Systems <support@opennebula.systems>" author "OpenNebula Systems <support@opennebula.systems>"

@ -0,0 +1,60 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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 -e
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
# Umount the directory and remove it
cleanup()
{
[ "$MOUNTED" = "yes" ] && umount -l "${ROOTFS_DIR}"
rm -r "${TMP_DIR}"
}
if [ "${RECREATE_RUN^^}" = "YES" ] && [ "$(uname -s)" = 'Linux' ]; then
# Detection of real run-time variable data directory in case there
# would be images with (unusual) reverse symlink /run -> /var/run
if [ -d /run ] && ! [ -L /run ]; then
RUN_DIR=/run
elif [ -d /var/run ] && ! [ -L /var/run ]; then
RUN_DIR=/var/run
else
# this shouldn't happen
echo 'ERROR: No suitable run-time data directory in image!' >&2
exit 1
fi
###
TMP_DIR=$(mktemp -d "/tmp/one-context.XXXXXX")
ROOTFS_DIR="${TMP_DIR}/rootfs"
trap cleanup EXIT
chmod 0700 "${TMP_DIR}"
mkdir "${ROOTFS_DIR}"
mount --bind -o ro,nodev,noexec,nosuid / "${ROOTFS_DIR}"
MOUNTED=yes
# copy, but don't overwrite
# NOTE: using -i </dev/null is a workaround for silly cp in busybox without -n support
cp -aiv "${ROOTFS_DIR}/${RUN_DIR}" "$(dirname "${RUN_DIR}")" 2>/dev/null </dev/null
fi

@ -1,83 +1,293 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
# shellcheck disable=SC2001
set -e set -e
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
GROW_ROOTFS=${GROW_ROOTFS:-YES} GROW_ROOTFS=${GROW_ROOTFS:-YES}
GROW_ROOTFS=${GROW_ROOTFS^^} GROW_ROOTFS=${GROW_ROOTFS^^}
#GROW_FS # list of mountpoints to resize
#
# functions
#
# modified code based on the /etc/rc.d/growfs from FreeBSD
freebsd_growfs()
(
#
# Copyright 2014 John-Mark Gurney
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
#
_FS="$1"
MOUNT_LINE=$(mount -p | awk -v grow_fs="${_FS}" '
{if ( $2 == grow_fs) print $1, $3;}
')
if [ -z "$MOUNT_LINE" ] ; then
echo "GROWFS: No such mountpoint: ${_FS}" >&2
return 1
fi
FSDEV=$(echo "$MOUNT_LINE" | cut -d' ' -f1)
FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f2)
case "$FSTYPE" in
ufs)
rootdev=${FSDEV#/dev/}
;;
zfs)
pool=${FSDEV%%/*}
rootdev=$(zpool list -v "$pool" | awk 'END { print $1 }')
;;
*)
echo "GROWFS: Mount-point '${_FS}' of type '${FSTYPE}' is not supported!" >&2
return 0
esac
if [ x"$rootdev" = x"${rootdev%/*}" ]; then
# raw device
rawdev="$rootdev"
else
rawdev=$(glabel status | awk '$1 == "'"$rootdev"'" { print $3 }')
if [ x"$rawdev" = x"" ]; then
echo "GROWFS: Unable to found a device for '${rootdev}'!" >&2
return 1
fi
fi
if [ -n "$DEBUG" ]; then
echo "DEVICE: ${rootdev}"
echo "RAW DEVICE: ${rawdev}"
echo "FSTYPE: ${FSTYPE}"
fi
sysctl -b kern.geom.conftxt | awk '
{
lvl=$1
device[lvl] = $3
type[lvl] = $2
idx[lvl] = $7
parttype[lvl] = $13
if (dev == $3) {
for (i = 1; i <= lvl; i++) {
# resize
if (type[i] == "PART") {
pdev = device[i - 1]
cmd[i] = "gpart resize -i " idx[i] " " pdev
if (parttype[i] == "GPT")
cmd[i] = "gpart recover " pdev " ; " cmd[i]
} else if (type[i] == "LABEL") {
continue
} else {
print "unhandled type: " type[i]
exit 1
}
}
for (i = 1; i <= lvl; i++) {
if (cmd[i])
system(cmd[i])
}
exit 0
}
}' dev="$rawdev"
gpart commit "$rootdev"
case "$FSTYPE" in
ufs)
growfs -y /dev/"$rootdev"
;;
zfs)
zpool online -e "$pool" "$rootdev"
;;
esac
)
if [ "${GROW_ROOTFS}" != 'YES' ]; then #
echo 'Skipped root filesystem growing.' >&2 # main
#
if [ -z "${GROW_FS}" ] && [ "${GROW_ROOTFS}" != 'YES' ]; then
echo 'GROWFS: Skipping filesystem resize' >&2
exit 0 exit 0
fi fi
# FreeBSD # add rootfs ('/') to the GROW_FS if GROW_ROOTFS=YES
if [ -x /etc/rc.d/growfs ]; then if [ "${GROW_ROOTFS}" = 'YES' ] ; then
/etc/rc.d/growfs onestart # duplicates will be removed by the next command
exit $? GROW_FS="/ ${GROW_FS}"
fi fi
MOUNT_LINE=$(cat /etc/mtab | grep ' / ' | grep -v '^rootfs') # sanitize the GROW_FS
DEVICE=$(echo "$MOUNT_LINE" | cut -d' ' -f1) GROW_FS=$(echo "${GROW_FS}" | sed 's/[[:space:]]\+/\n/g' | sed '/^$/d' | sort -u)
FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f3)
GROWPART=$(which growpart)
if [ $? -ne 0 ]; then OS=$(uname | tr '[:upper:]' '[:lower:]')
echo "growpart command is missing" case "$OS" in
linux)
GROWPART=$(command -v growpart || true)
if [ -z "${GROWPART}" ]; then
echo "GROWFS: growpart command is missing" >&2
exit 1
fi
;;
freebsd)
if ! [ -x /etc/rc.d/growfs ]; then
echo "GROWFS: growfs command is missing" >&2
exit 1 exit 1
fi fi
;;
esac
export DEBUG
_exit_result=0
for _FS in ${GROW_FS} ; do
# FreeBSD
if [ "${OS}" = 'freebsd' ]; then
case "$_FS" in
/)
/etc/rc.d/growfs onestart || _exit_result=$?
;;
*)
freebsd_growfs "$_FS" || _exit_result=$?
;;
esac
continue
fi
# Linux
# try /proc/mounts first otherwise fallback to /etc/mtab
MOUNT_LINE=$(\
if [ -e /proc/mounts ] ; then \
cat /proc/mounts ; \
else \
cat /etc/mtab ; \
fi | awk -v grow_fs="${_FS}" '
{if (($0 !~ /rootfs/) && ($2 == grow_fs)) print $1, $3;}
')
if [ -z "$MOUNT_LINE" ] ; then
echo "GROWFS: No such mountpoint: ${_FS}" >&2
_exit_result=1
continue
fi
if [ $(lvdisplay ${DEVICE} 2>/dev/null | wc -l) -eq 0 ]; then DEVICE=$(echo "$MOUNT_LINE" | cut -d' ' -f1)
DEVICE=$(findmnt -ln -o SOURCE /) FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f2)
LVM=$(lvdisplay "${DEVICE}" 2>/dev/null | wc -l)
if [ "$LVM" -eq 0 ]; then
# findmnt supports --nofsroot since util-linux v2.19.1 but
# unfortunately this is broken even in v2.20 (Ubuntu 14.04)
# so trivial test follows which should filter out old and broken
# versions...
if findmnt -V >/dev/null 2>&1 ; then
DEVICE=$(findmnt -ln -o SOURCE --nofsroot "$_FS")
else
# old broken util-linux does not have the -V option
DEVICE=$(findmnt -ln -o SOURCE "$_FS")
fi
DISK=$(echo "$DEVICE" | sed 's/[0-9]*$//') DISK=$(echo "$DEVICE" | sed 's/[0-9]*$//')
PARTITION=$(echo "$DEVICE" | sed "s|^$DISK||") PARTITION=$(echo "$DEVICE" | sed "s|^$DISK||")
LVM="no" LVM="no"
fi fi
if [ "${LVM}" != "no" ]; then if [ "${LVM}" != "no" ]; then
if [ -f /etc/debian_version ]; then # TODO: This should be rewritten to accomodate other PVs - this expects
DEVICE=$(mount | grep ' / ' | grep -v '^rootfs'|cut -d' ' -f1) # that PV name ends with zero or exactly one numeric: /dev/sda1
fi
PVRESIZE=$(which pvresize) PVRESIZE=$(which pvresize)
LVEXTEND=$(which lvextend) LVEXTEND=$(which lvextend)
DISK=$(pvdisplay |grep "PV Name"|awk '{print $3}'|sed 's/.$//') DISK=$(pvdisplay | awk '/PV Name/ {sub(/.$/, "", $3); print $3;}')
PARTITION=$(pvdisplay |grep "PV Name"|awk '{print $3}'| sed "s|^${DISK}||") PARTITION=$(pvdisplay | awk -v d="$DISK" '/PV Name/ {sub("^" d, "", $3); print $3;}')
PV=$(pvdisplay |grep "PV Name"|awk '{print $3}') PV=$(pvdisplay | awk '/PV Name/ {print $3}')
LV=$(lvdisplay ${DEVICE} |grep "LV Path"|awk '{print $3}') LV=$(lvdisplay "${DEVICE}" | awk '/LV Path/ {print $3}')
# when PV is on MSDOS logical partition, detect the umbrella # when PV is on MSDOS logical partition, detect the umbrella
# extended partition and grow it first # extended partition and grow it first
TABLE=$(parted -s ${DISK} print 2>/dev/null | grep 'Partition Table:' | awk '{print $3}') TABLE=$(parted -s "${DISK}" print 2>/dev/null | awk '/Partition Table:/ {print $3}')
if [ "${TABLE}" = 'msdos' ] && [ ${PARTITION} -gt 4 ]; then if [ "${TABLE}" = 'msdos' ] && [ "${PARTITION}" -gt 4 ]; then
PARTITION="$(parted -s ${DISK} print | grep 'extended' | awk '{print $1}') $PARTITION" EXTENDED=$(parted -s "${DISK}" print | awk '/extended/ {print $1}')
PARTITION="${EXTENDED} ${PARTITION}"
fi fi
fi fi
if [ -n "$DEBUG" ]; then if [ -n "$DEBUG" ]; then
echo DEVICE: ${DEVICE} echo "DEVICE: ${DEVICE}"
echo FSTYPE: ${FSTYPE} echo "FSTYPE: ${FSTYPE}"
echo DISK: ${DISK} echo "DISK: ${DISK}"
echo PARTITION: ${PARTITION} echo "PARTITION: ${PARTITION}"
fi fi
( (
for PART in ${PARTITION}; do for PART in ${PARTITION}; do
${GROWPART} ${DISK} ${PART} ${GROWPART} "${DISK}" "${PART}"
done done
if [ "${LVM}" != "no" ]; then if [ "${LVM}" != "no" ]; then
${PVRESIZE} ${PV} ${PVRESIZE} "${PV}"
${LVEXTEND} -l +100%FREE ${LV} ${LVEXTEND} -l +100%FREE "${LV}"
fi fi
) || : # don't fail, partition can be already extended by dracut ) || : # don't fail, partition can be already extended by dracut
case "${FSTYPE}" in case "${FSTYPE}" in
ext2|ext3|ext4) ext2|ext3|ext4)
resize2fs ${DEVICE} resize2fs "${DEVICE}"
;; ;;
xfs) xfs)
xfs_growfs / xfs_growfs "${_FS}"
;; ;;
btrfs) btrfs)
btrfs filesystem resize max / btrfs filesystem resize max "${_FS}"
;; ;;
esac esac
done
exit "$_exit_result"

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2019, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
if [ -z "${TIMEZONE}" ]; then if [ -z "${TIMEZONE}" ]; then
exit 0 exit 0
fi fi

@ -0,0 +1,165 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
# shellcheck disable=SC1091,SC1090
. /etc/one-context.d/loc-10-network.d/functions
context_type="$1"
action="$2"
os_id=$(detect_os)
if [ -z "${action}" ] ; then
action="configure"
fi
if [ -z "${NETCFG_TYPE}" ] ; then
case "${os_id}" in
alpine)
NETCFG_TYPE='interfaces'
;;
altlinux)
NETCFG_TYPE='networkd nm'
;;
debian|devuan|ubuntu)
NETCFG_TYPE='interfaces netplan nm networkd'
;;
fedora|centos|rhel|almalinux|ol|rocky|msvsphere)
NETCFG_TYPE='scripts nm networkd'
;;
opensuse*|sles|sled)
NETCFG_TYPE='scripts'
;;
amzn)
NETCFG_TYPE='scripts'
;;
freebsd)
NETCFG_TYPE='bsd'
;;
*)
NETCFG_TYPE='none'
;;
esac
else
# trim and lowercase
NETCFG_TYPE=$(echo "$NETCFG_TYPE" | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
tr '[:upper:]' '[:lower:]')
# support alternative names for some configuration renderers
case "${NETCFG_TYPE}" in
networkmanager)
NETCFG_TYPE='nm'
;;
systemd-networkd|systemd-network|systemd)
NETCFG_TYPE='networkd'
;;
redhat)
NETCFG_TYPE='scripts'
;;
debian)
NETCFG_TYPE='interfaces'
;;
freebsd)
NETCFG_TYPE='bsd'
;;
esac
fi
if [ "${NETCFG_TYPE}" != 'none' ] ; then
_found_valid_netcfg='no'
# from a space separated list of $NETCFG_TYPE candidates check one
# by one and select the first suitable one for current environment
for _cfgtype in ${NETCFG_TYPE} ; do
_cfgtype_file="/etc/one-context.d/loc-10-network.d/netcfg-$(basename "${_cfgtype}")"
if [ -e "${_cfgtype_file}" ] ; then
# reload functions to reset back any overrides from prev. netcfg-X
. /etc/one-context.d/loc-10-network.d/functions
. "${_cfgtype_file}"
else
echo "ERROR [!]: Requested network type is not implemented: ${_cfgtype}" >&2
exit 1
fi
if is_network_supported ; then
_found_valid_netcfg='yes'
break
fi
done
if [ "${_found_valid_netcfg}" = 'no' ] ; then
echo "ERROR [!]: None of the requested network types is supported on: ${os_id}" >&2
exit 1
fi
else
# any action is meaningless without functioning network type
action='none'
fi
# regardless of the required_context_type we need cleanup in the 'local' stage
#
# TODO: currently we must skip cleanup during reconfigure action (check-out the
# initialize_network function) otherwise we would wiped-out running config and
# broke the system
if [ "${context_type}" = 'local' ] ; then
case "$action" in
configure|reconfigure)
initialize_network
;;
*)
echo "ERROR [!]: Unknown ACTION: ${action}" >&2
exit 1
;;
esac
fi
# this is a contextualization guard
# shellcheck disable=SC2154
case "${required_context_type}" in
''|local|online)
if [ "${required_context_type:-local}" != "${context_type}" ] ; then
# skip this netcfg at this stage
exit 0
fi
;;
*)
echo "ERROR [!]: Unknown required context type: ${required_context_type}" >&2
exit 1
;;
esac
case "$action" in
none)
echo "INFO: Network will not be configured" >&2
;;
configure)
configure_network
;;
reconfigure)
configure_network
reload_network
;;
*)
echo "ERROR [!]: Unknown ACTION: ${action}" >&2
exit 1
;;
esac
exit 0

@ -1,361 +0,0 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L. #
# #
# 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. #
#--------------------------------------------------------------------------- #
ACTION=$1
if [ -z "$ACTION" ]; then
ACTION="none"
fi
# Gets IP address from a given MAC
mac2ip() {
mac=$1
let ip_a=0x`echo $mac | cut -d: -f 3`
let ip_b=0x`echo $mac | cut -d: -f 4`
let ip_c=0x`echo $mac | cut -d: -f 5`
let ip_d=0x`echo $mac | cut -d: -f 6`
ip="$ip_a.$ip_b.$ip_c.$ip_d"
echo $ip
}
# Gets the network part of an IP
get_network() {
network=$(get_iface_var "NETWORK")
if [ -z "$network" ]; then
IFS=. read -r i1 i2 i3 i4 <<< "$IP"
IFS=. read -r m1 m2 m3 m4 <<< "$(get_mask)"
network=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
fi
echo $network
}
# Gets the network mask
get_mask() {
mask=$(get_iface_var "MASK")
if [ -z "$mask" ]; then
mask="255.255.255.0"
fi
echo $mask
}
# Gets device MTU
get_mtu() {
mtu=$(get_iface_var "MTU")
echo $mtu
}
is_gateway() {
if [ -z "$GATEWAY_IFACE_NUM" ]; then
true
else
[ "$IFACE_NUM" = "$GATEWAY_IFACE_NUM" ]
fi
}
# Gets the network gateway
get_gateway() {
if is_gateway; then
get_iface_var "GATEWAY"
fi
}
# Gets the network gateway6
get_gateway6() {
if is_gateway; then
get_iface_var "GATEWAY6"
fi
}
get_ip() {
ip=$(get_iface_var "IP")
echo $ip
}
get_iface_var() {
var_name="${UPCASE_DEV}_$1"
var=$(eval "echo \"\${$var_name}\"")
echo $var
}
gen_iface_conf() {
cat <<EOT
iface $DEV inet static
address $IP
network $NETWORK
netmask $MASK
EOT
if [ -n "$MTU" ]; then
echo " mtu $MTU"
fi
if [ -n "$GATEWAY" ]; then
echo " gateway $GATEWAY"
if [ -n "$METRIC" ]; then
echo " metric $METRIC"
fi
fi
echo ""
}
gen_alias_conf() {
cat <<EOT
iface $DEV inet static
address $IP
network $NETWORK
netmask $MASK
EOT
echo ""
}
gen_alias6_conf() {
cat <<EOT
iface $DEV inet6 static
address $IP6
netmask ${IP6_PREFIX_LENGTH:-64}
pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/autoconf
pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/accept_ra
EOT
if [ -n "$IP6_ULA" ]; then
cat <<EOT
iface $DEV inet6 static
address $IP6_ULA
netmask 64
EOT
fi
echo ""
}
gen_iface6_conf() {
cat <<EOT
iface $DEV inet6 static
address $IP6
netmask ${IP6_PREFIX_LENGTH:-64}
pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/autoconf
pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/accept_ra
EOT
if [ -n "$MTU" ]; then
echo " mtu $MTU"
fi
if [ -n "$GATEWAY6" ]; then
echo " gateway $GATEWAY6"
if [ -n "$METRIC" ]; then
echo " metric $METRIC"
fi
fi
if [ -n "$IP6_ULA" ]; then
cat <<EOT
iface $DEV inet6 static
address $IP6_ULA
netmask 64
EOT
if [ -n "$MTU" ]; then
echo " mtu $MTU"
fi
fi
echo ""
}
get_interface_mac()
{
ip link show | awk '/^[0-9]+: [A-Za-z0-9@]+:/ { device=$2; gsub(/:/, "",device); split(device,dev,"@")} /link\/ether/ { print dev[1] " " $2 }'
}
get_context_interfaces()
{
env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | sort
}
get_interface_alias()
{
env | grep -E "^ETH${INDEX}_ALIAS[0-9]+_MAC=" | cut -d '_' -f 2 | sort
}
get_dev()
{
list="$1"
mac="$2"
echo "$list" | grep "$mac" | cut -d' ' -f1 | tail -n1
}
gen_network_configuration()
{
cat <<EOT
auto lo
iface lo inet loopback
EOT
INTERFACE_MAC=$(get_interface_mac)
CONTEXT_INTERFACES=$(get_context_interfaces)
GATEWAY_IFACE_NUM=$(echo "$GATEWAY_IFACE" | sed 's/^ETH//')
for interface in $CONTEXT_INTERFACES; do
UPCASE_DEV=$interface
MAC=$(get_iface_var "MAC")
DEV=$(get_dev "$INTERFACE_MAC" "$MAC")
IFACE_NUM=$(echo "$UPCASE_DEV" | sed 's/^ETH//')
IP=$(get_ip)
NETWORK=$(get_network)
MASK=$(get_mask)
MTU=$(get_mtu)
GATEWAY=$(get_gateway)
METRIC=$(get_iface_var "METRIC")
IP6=$(get_iface_var "IP6")
[[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
GATEWAY6=$(get_gateway6)
CONTEXT_FORCE_IPV4=$(get_iface_var "CONTEXT_FORCE_IPV4")
[ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue
echo "auto $DEV"
[[ -n $IP ]] && gen_iface_conf
[[ -n $IP6 ]] && gen_iface6_conf
INDEX=${interface: -1}
ALIAS=$(get_interface_alias)
for nic_alias in $ALIAS; do
UPCASE_DEV="ETH${INDEX}_${nic_alias}"
IP=$(get_ip)
NETWORK=$(get_network)
MASK=$(get_mask)
IP6=$(get_iface_var "IP6")
[[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
EXTERNAL=$(get_iface_var "EXTERNAL")
EXTERNAL=${EXTERNAL^^}
DETACH=$(get_iface_var "DETACH")
if [ -z "${DETACH}" ]; then
if [ -z "${EXTERNAL}" ] || [ $EXTERNAL = "NO" ]; then
[ -n "${IP}" ] && gen_alias_conf
[ -n "${IP6}" ] && gen_alias6_conf
fi
fi
done
done
}
configure_network()
{
gen_network_configuration > /etc/network/interfaces
#echo "source /etc/network/interfaces.d/*.cfg" >> /etc/network/interfaces
}
deactivate_network()
{
. /etc/os-release
case "$ID" in
'ubuntu')
IFACES=$(/sbin/ifquery --list -a)
for i in $IFACES; do
if [ $i != 'lo' ]; then
/sbin/ifdown $i
/sbin/ip addr flush dev $i
fi
done
;;
'alpine')
service networking stop || true
#IFACES=$(ip a | \
# sed -n 's#^[0-9]\+:[[:space:]]\+\([^:]\+\):[[:space:]].*#\1#p')
# took from find_ifaces in the networking service
IFACES=$(\
awk '$1 == "auto" {
for (i = 2; i <= NF; i = i + 1) printf("%s ", $i)
}' /etc/network/interfaces)
for i in $IFACES; do
if [ $i != 'lo' ]; then
/sbin/ip link set dev $i down || true
/sbin/ip addr flush dev $i || true
fi
done
;;
*)
service networking stop
;;
esac
}
activate_network()
{
. /etc/os-release
case "$ID" in
'ubuntu')
IFACES=$(/sbin/ifquery --list -a)
for i in $IFACES; do
/sbin/ifup $i
done
;;
'alpine')
deactivate_network
service networking start
;;
*)
service networking stop
sleep 1
service networking start
;;
esac
}
[ $ACTION == "reconfigure" ] && deactivate_network
configure_network
[ $ACTION == "reconfigure" ] && activate_network

@ -1,277 +0,0 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
# Gets IP address from a given MAC
mac2ip() {
mac=$1
let ip_a=0x`echo $mac | cut -d: -f 3`
let ip_b=0x`echo $mac | cut -d: -f 4`
let ip_c=0x`echo $mac | cut -d: -f 5`
let ip_d=0x`echo $mac | cut -d: -f 6`
ip="$ip_a.$ip_b.$ip_c.$ip_d"
echo $ip
}
mask2cidr() {
mask=$1
nbits=0
IFS=.
for dec in $mask ; do
case $dec in
255) let nbits+=8;;
254) let nbits+=7 ; break ;;
252) let nbits+=6 ; break ;;
248) let nbits+=5 ; break ;;
240) let nbits+=4 ; break ;;
224) let nbits+=3 ; break ;;
192) let nbits+=2 ; break ;;
128) let nbits+=1 ; break ;;
0);;
*) echo "Error: $dec is not recognised"; exit 1
esac
done
echo "$nbits"
}
# Gets the network part of an IP
get_network() {
network=$(get_iface_var "NETWORK")
if [ -z "$network" ]; then
IFS=. read -r i1 i2 i3 i4 <<< "$IP"
IFS=. read -r m1 m2 m3 m4 <<< "$(get_mask)"
network=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
fi
echo $network
}
# Gets the network mask
get_mask() {
mask=$(get_iface_var "MASK")
if [ -z "$mask" ]; then
mask="255.255.255.0"
fi
echo $mask
}
# Gets device MTU
get_mtu() {
mtu=$(get_iface_var "MTU")
echo $mtu
}
is_gateway() {
if [ -z "$GATEWAY_IFACE_NUM" ]; then
true
else
[ "$IFACE_NUM" = "$GATEWAY_IFACE_NUM" ]
fi
}
# Gets the network gateway
get_gateway() {
if is_gateway; then
gateway=$(get_iface_var "GATEWAY")
if [ -z "$gateway" ]; then
if [ "$DEV" = "eth0" ]; then
net_prefix=$(echo $NETWORK | cut -d'.' -f1,2,3)
gateway="${net_prefix}.1"
fi
fi
echo $gateway
fi
}
# Gets the network gateway6
get_gateway6() {
if is_gateway; then
get_iface_var "GATEWAY6"
fi
}
get_dns() {
dns=$(get_iface_var "DNS")
echo $dns
}
get_search_domain() {
search_domain=$(get_iface_var "SEARCH_DOMAIN")
echo $search_domain
}
get_ip() {
ip=$(get_iface_var "IP")
echo $ip
}
get_iface_var() {
var_name="${UPCASE_DEV}_$1"
var=$(eval "echo \"\${$var_name}\"")
echo $var
}
gen_iface_conf() {
cat <<EOT
[Network]
Address=$IP/$CIDR
EOT
if [ -n "$GATEWAY" ]; then
echo "Gateway=$GATEWAY"
fi
if [ -n "$DNS" ]; then
for dns_server in $DNS; do
echo "DNS=$dns_server"
done
fi
if [ -n "$SEARCH_DOMAIN" ]; then
for domain in $SEARCH_DOMAIN; do
echo "Domains=$domain"
done
fi
echo ""
}
gen_iface6_conf() {
cat <<EOT
[Network]
Address=$IP6/${IP6_PREFIX_LENGTH:-64}
IPv6AcceptRA=false
EOT
if [ -n "$GATEWAY6" ]; then
echo "Gateway=$GATEWAY6"
fi
if [ -n "$DNS" ]; then
for dns_server in $DNS; do
echo "DNS=$dns_server"
done
fi
if [ -n "$SEARCH_DOMAIN" ]; then
for domain in $SEARCH_DOMAIN; do
echo "Domains=$domain"
done
fi
if [ -n "$IP6_ULA" ]; then
cat <<EOT
[Network]
Address=$IP6_ULA/64
EOT
fi
echo ""
}
get_interface_mac()
{
ip link show | awk '/^[0-9]+: [A-Za-z0-9@]+:/ { device=$2; gsub(/:/, "",device); split(device,dev,"@")} /link\/ether/ { print dev[1] " " $2 }'
}
get_context_interfaces()
{
env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | sort
}
get_dev()
{
list="$1"
mac="$2"
echo "$list" | grep "$mac" | cut -d' ' -f1 | tail -n1
}
gen_network_configuration()
{
INTERFACE_MAC=$(get_interface_mac)
CONTEXT_INTERFACES=$(get_context_interfaces)
GATEWAY_IFACE_NUM=$(echo "$GATEWAY_IFACE" | sed 's/^ETH//')
for interface in $CONTEXT_INTERFACES; do
UPCASE_DEV=$interface
MAC=$(get_iface_var "MAC")
DEV=$(get_dev "$INTERFACE_MAC" "$MAC")
IFACE_NUM=$(echo "$UPCASE_DEV" | sed 's/^ETH//')
IP=$(get_ip)
NETWORK=$(get_network)
MASK=$(get_mask)
CIDR=$(mask2cidr "$MASK")
MTU=$(get_mtu)
GATEWAY=$(get_gateway)
DNS=$(get_dns)
SEARCH_DOMAIN=$(get_search_domain)
IP6=$(get_iface_var "IP6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
GATEWAY6=$(get_gateway6)
CONTEXT_FORCE_IPV4=$(get_iface_var "CONTEXT_FORCE_IPV4")
[ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue
(
cat <<EOT
[Match]
Name=$DEV
EOT
if [ -n "$MTU" ]; then
cat <<EOT
[Link]
MTUBytes=$MTU
EOT
fi
if [ -n "$IP" ] || [ -n "$CONTEXT_FORCE_IPV4" ]; then
gen_iface_conf
fi
if [ -n "$IP6" ]; then
gen_iface6_conf
fi
) > /etc/systemd/network/"${DEV}".network
done
}
[ -z "$(env | cut -d= -f1 | grep -E '^ETH[0-9]+_IP6*')" ] && exit 0
gen_network_configuration

@ -1,274 +0,0 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
COMMAND=${1}
# Gets IP address from a given MAC
mac2ip() {
mac=$1
let ip_a=0x`echo $mac | cut -d: -f 3`
let ip_b=0x`echo $mac | cut -d: -f 4`
let ip_c=0x`echo $mac | cut -d: -f 5`
let ip_d=0x`echo $mac | cut -d: -f 6`
ip="$ip_a.$ip_b.$ip_c.$ip_d"
echo $ip
}
# Gets the network part of an IP
get_network() {
network=$(get_iface_var "NETWORK")
if [ -z "$network" ]; then
IFS=. read -r i1 i2 i3 i4 <<< "$IP"
IFS=. read -r m1 m2 m3 m4 <<< "$(get_mask)"
network=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
fi
echo $network
}
# Gets the network mask
get_mask() {
mask=$(get_iface_var "MASK")
if [ -z "$mask" ]; then
mask="255.255.255.0"
fi
echo $mask
}
# Gets device MTU
get_mtu() {
mtu=$(get_iface_var "MTU")
echo $mtu
}
is_gateway() {
if [ -z "$GATEWAY_IFACE_NUM" ]; then
true
else
[ "$IFACE_NUM" = "$GATEWAY_IFACE_NUM" ]
fi
}
# Gets the network gateway
get_gateway() {
if is_gateway; then
gateway=$(get_iface_var "GATEWAY")
echo $gateway
fi
}
# Gets the network gateway6
get_gateway6() {
if is_gateway; then
get_iface_var "GATEWAY6"
fi
}
get_ip() {
ip=$(get_iface_var "IP")
echo $ip
}
get_iface_var() {
var_name="${UPCASE_DEV}_$1"
var=$(eval "echo \"\${$var_name}\"")
echo $var
}
gen_iface_conf() {
echo -n "ifconfig_${DEV}=\"inet ${IP} netmask ${MASK}"
if [ -n "${MTU}" ]; then
echo -n " mtu ${MTU}"
fi
echo "\""
###
if [ -n "${GATEWAY}" ]; then
echo "defaultrouter=\"${GATEWAY}\"" >> /etc/rc.conf.d/routing
fi
}
gen_alias_conf() {
echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet ${IP} netmask ${MASK}\""
ALIAS_NUM=$((ALIAS_NUM + 1))
}
gen_alias6_conf() {
# very first IPv6 can't be alias
if [ -n "${HAS_IP6}" ]; then
echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet6 ${IP6} prefixlen ${IP6_PREFIX_LENGTH:-64}\""
ALIAS_NUM=$((ALIAS_NUM + 1))
else
echo -n "ifconfig_${DEV}_ipv6=\"inet6 ${IP6} prefixlen ${IP6_PREFIX_LENGTH:-64}"
if [ -n "${MTU}" ]; then
echo -n " mtu ${MTU}"
fi
echo " -accept_rtadv\""
fi
if [ -n "${IP6_ULA}" ]; then
echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet6 ${IP6_ULA} prefixlen 64\""
ALIAS_NUM=$((ALIAS_NUM + 1))
fi
}
gen_iface6_conf() {
echo -n "ifconfig_${DEV}_ipv6=\"inet6 ${IP6} prefixlen ${IP6_PREFIX_LENGTH:-64}"
if [ -n "${MTU}" ]; then
echo -n " mtu ${MTU}"
fi
echo " -accept_rtadv\""
if [ -n "${IP6_ULA}" ]; then
echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet6 ${IP6_ULA} prefixlen 64\""
ALIAS_NUM=$((ALIAS_NUM + 1))
fi
###
if [ -n "${GATEWAY6}" ]; then
echo "ipv6_defaultrouter=\"${GATEWAY6}\"" >> /etc/rc.conf.d/routing
fi
}
get_interface_mac()
{
macs_array=($(ifconfig | grep ether | awk '{print $2}'))
#iface_name=()
for mac in "${macs_array[@]}"
do
echo "$(ifconfig | grep -B 2 $mac | head -n 1 | awk '{print $1}' | cut -d ':' -f 1) $mac"
#iface_mac+=$(ifconfig | grep -B 2 $mac | head -n 1 | awk '{print $1}' | cut -d ':' -f 1)
done
}
get_context_interfaces()
{
env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | sort
}
get_interface_alias()
{
env | grep -E "^ETH${INDEX}_ALIAS[0-9]+_MAC=" | cut -d '_' -f 2 | sort
}
get_dev()
{
list="$1"
mac="$2"
echo "$list" | grep "$mac" | cut -d' ' -f1 | tail -n1
}
gen_network_configuration()
{
# clean routing information
echo -n > /etc/rc.conf.d/routing
INTERFACE_MAC=$(get_interface_mac)
CONTEXT_INTERFACES=$(get_context_interfaces)
GATEWAY_IFACE_NUM=$(echo "$GATEWAY_IFACE" | sed 's/^ETH//')
for interface in $CONTEXT_INTERFACES; do
UPCASE_DEV=$interface
MAC=$(get_iface_var "MAC")
DEV=$(get_dev "$INTERFACE_MAC" "$MAC")
IFACE_NUM=$(echo "$UPCASE_DEV" | sed 's/^ETH//')
IP=$(get_ip)
NETWORK=$(get_network)
MASK=$(get_mask)
MTU=$(get_mtu)
GATEWAY=$(get_gateway)
IP6=$(get_iface_var "IP6")
[[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
GATEWAY6=$(get_gateway6)
[ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue
INDEX=${interface: -1}
ALIAS=$(get_interface_alias)
ALIAS_NUM=0
HAS_IP6=${IP6}
[ -n "${IP}" ] && gen_iface_conf
[ -n "${IP6}" ] && gen_iface6_conf
for nic_alias in $ALIAS; do
UPCASE_DEV="ETH${INDEX}_${nic_alias}"
IP=$(get_ip)
MASK=$(get_mask)
IP6=$(get_iface_var "IP6")
[[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
EXTERNAL=$(get_iface_var "EXTERNAL")
EXTERNAL=${EXTERNAL^^}
DETACH=$(get_iface_var "DETACH")
if [ -z "${DETACH}" ]; then
if [ -z "${EXTERNAL}" ] || [ "$EXTERNAL" = "NO" ]; then
[ -n "${IP}" ] && gen_alias_conf
if [ -n "${IP6}" ]; then
gen_alias6_conf
HAS_IP6=${IP6}
fi
fi
fi
done
done
}
configure_network()
{
gen_network_configuration >/etc/rc.conf.d/network
if [ "${COMMAND}" = 'reconfigure' ]; then
service netif restart >/dev/null
service routing restart >/dev/null
fi
}
[ -z "$(env | cut -d= -f1 | grep -E '^ETH[0-9]+_IPV*6*')" ] && exit 0
configure_network

@ -1,309 +0,0 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
COMMAND=${1}
# Gets IP address from a given MAC
mac2ip() {
mac=$1
let ip_a=0x`echo $mac | cut -d: -f 3`
let ip_b=0x`echo $mac | cut -d: -f 4`
let ip_c=0x`echo $mac | cut -d: -f 5`
let ip_d=0x`echo $mac | cut -d: -f 6`
ip="$ip_a.$ip_b.$ip_c.$ip_d"
echo $ip
}
# Gets the network part of an IP
get_network() {
network=$(get_iface_var "NETWORK")
if [ -z "$network" ]; then
IFS=. read -r i1 i2 i3 i4 <<< "$IP"
IFS=. read -r m1 m2 m3 m4 <<< "$(get_mask)"
network=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
fi
echo $network
}
# Gets the network mask
get_mask() {
mask=$(get_iface_var "MASK")
if [ -z "$mask" ]; then
mask="255.255.255.0"
fi
echo $mask
}
# Gets device MTU
get_mtu() {
mtu=$(get_iface_var "MTU")
echo $mtu
}
is_gateway() {
if [ -z "$GATEWAY_IFACE_NUM" ]; then
true
else
[ "$IFACE_NUM" = "$GATEWAY_IFACE_NUM" ]
fi
}
# Gets the network gateway
get_gateway() {
if is_gateway; then
gateway=$(get_iface_var "GATEWAY")
echo $gateway
fi
}
# Gets the network gateway6
get_gateway6() {
if is_gateway; then
get_iface_var "GATEWAY6"
fi
}
get_ip() {
ip=$(get_iface_var "IP")
echo $ip
}
get_iface_var() {
var_name="${UPCASE_DEV}_$1"
var=$(eval "echo \"\${$var_name}\"")
echo $var
}
gen_iface_conf() {
cat <<EOT
iface $DEV inet static
address $IP
network $NETWORK
netmask $MASK
EOT
if [ -n "$MTU" ]; then
echo " mtu $MTU"
fi
if [ -n "$GATEWAY" ]; then
echo " gateway $GATEWAY"
fi
echo ""
}
gen_alias_conf() {
cat <<EOT
iface $DEV inet static
address $IP
network $NETWORK
netmask $MASK
EOT
echo ""
}
gen_alias6_conf() {
cat <<EOT
iface $DEV inet6 static
address $IP6
netmask ${IP6_PREFIX_LENGTH:-64}
autoconf 0
accept_ra 0
EOT
if [ -n "$IP6_ULA" ]; then
cat <<EOT
iface $DEV inet6 static
address $IP6_ULA
netmask 64
EOT
fi
echo ""
}
gen_iface6_conf() {
cat <<EOT
iface $DEV inet6 static
address $IP6
netmask ${IP6_PREFIX_LENGTH:-64}
autoconf 0
accept_ra 0
EOT
if [ -n "$MTU" ]; then
echo " mtu $MTU"
fi
if [ -n "$GATEWAY6" ]; then
echo " gateway $GATEWAY6"
fi
if [ -n "$IP6_ULA" ]; then
cat <<EOT
iface $DEV inet6 static
address $IP6_ULA
netmask 64
autoconf 0
accept_ra 0
EOT
if [ -n "$MTU" ]; then
echo " mtu $MTU"
fi
fi
echo ""
}
get_interface_mac()
{
ip link show | awk '/^[0-9]+: [A-Za-z0-9@]+:/ { device=$2; gsub(/:/, "",device); split(device,dev,"@")} /link\/ether/ { print dev[1] " " $2 }'
}
get_context_interfaces()
{
env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | sort
}
get_interface_alias()
{
env | grep -E "^ETH${INDEX}_ALIAS[0-9]+_MAC=" | cut -d '_' -f 2 | sort
}
get_dev()
{
list="$1"
mac="$2"
echo "$list" | grep "$mac" | cut -d' ' -f1 | tail -n1
}
gen_network_configuration()
{
cat <<EOT
auto lo
iface lo inet loopback
EOT
INTERFACE_MAC=$(get_interface_mac)
CONTEXT_INTERFACES=$(get_context_interfaces)
GATEWAY_IFACE_NUM=$(echo "$GATEWAY_IFACE" | sed 's/^ETH//')
for interface in $CONTEXT_INTERFACES; do
UPCASE_DEV=$interface
MAC=$(get_iface_var "MAC")
DEV=$(get_dev "$INTERFACE_MAC" "$MAC")
IFACE_NUM=$(echo "$UPCASE_DEV" | sed 's/^ETH//')
IP=$(get_ip)
NETWORK=$(get_network)
MASK=$(get_mask)
MTU=$(get_mtu)
GATEWAY=$(get_gateway)
IP6=$(get_iface_var "IP6")
[[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
GATEWAY6=$(get_gateway6)
[ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue
echo "auto $DEV"
[[ -n $IP ]] && gen_iface_conf
[[ -n $IP6 ]] && gen_iface6_conf
INDEX=${interface: -1}
ALIAS=$(get_interface_alias)
for nic_alias in $ALIAS; do
UPCASE_DEV="ETH${INDEX}_${nic_alias}"
IP=$(get_ip)
NETWORK=$(get_network)
MASK=$(get_mask)
IP6=$(get_iface_var "IP6")
[[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
EXTERNAL=$(get_iface_var "EXTERNAL")
EXTERNAL=${EXTERNAL^^}
DETACH=$(get_iface_var "DETACH")
if [ -z "${DETACH}" ]; then
if [ -z "${EXTERNAL}" ] || [ $EXTERNAL = "NO" ]; then
[ -n "${IP}" ] && gen_alias_conf
[ -n "${IP6}" ] && gen_alias6_conf
fi
fi
done
done
}
configure_network()
{
gen_network_configuration > /etc/network/interfaces
echo "source /etc/network/interfaces.d/*.cfg" >> /etc/network/interfaces
}
deactivate_network()
{
IFACES=`/sbin/ifquery --list -a`
for i in $IFACES; do
if [ $i != 'lo' ]; then
/sbin/ifdown $i
/sbin/ip addr flush dev $i
fi
done
}
activate_network()
{
IFACES=`/sbin/ifquery --list -a`
for i in $IFACES; do
/sbin/ifup $i
done
}
[ -z "$(env | cut -d= -f1 | grep -E '^ETH[0-9]+_IPV*6*')" ] && exit 0
deactivate_network
configure_network
activate_network

@ -1,316 +0,0 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
COMMAND=${1}
# Gets IP address from a given MAC
mac2ip() {
mac=$1
let ip_a=0x`echo $mac | cut -d: -f 3`
let ip_b=0x`echo $mac | cut -d: -f 4`
let ip_c=0x`echo $mac | cut -d: -f 5`
let ip_d=0x`echo $mac | cut -d: -f 6`
ip="$ip_a.$ip_b.$ip_c.$ip_d"
echo $ip
}
# Gets the network part of an IP
get_network() {
network=$(get_iface_var "NETWORK")
if [ -z "$network" ]; then
IFS=. read -r i1 i2 i3 i4 <<< "$IP"
IFS=. read -r m1 m2 m3 m4 <<< "$(get_mask)"
network=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
fi
echo $network
}
# Gets the network mask
get_mask() {
mask=$(get_iface_var "MASK")
if [ -z "$mask" ]; then
mask="255.255.255.0"
fi
echo $mask
}
# Gets device MTU
get_mtu() {
mtu=$(get_iface_var "MTU")
echo $mtu
}
is_gateway() {
if [ -z "$GATEWAY_IFACE_NUM" ]; then
true
else
[ "$IFACE_NUM" = "$GATEWAY_IFACE_NUM" ]
fi
}
# Gets the network gateway
get_gateway() {
if is_gateway; then
gateway=$(get_iface_var "GATEWAY")
echo $gateway
fi
}
# Gets the network gateway6
get_gateway6() {
if is_gateway; then
get_iface_var "GATEWAY6"
fi
}
get_ip() {
ip=$(get_iface_var "IP")
echo $ip
}
get_iface_var() {
var_name="${UPCASE_DEV}_$1"
var=$(eval "echo \"\${$var_name}\"")
echo $var
}
gen_iface_conf() {
cat <<EOT
NETMASK=$MASK
IPADDR=$IP
EOT
if [ -n "$GATEWAY" ]; then
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "default $GATEWAY - $DEV" >> /etc/sysconfig/network/ifroute-$DEV
else
echo "GATEWAY=$GATEWAY"
fi
fi
if [ -n "$MTU" ]; then
echo "MTU=$MTU"
fi
}
gen_alias_conf() {
cat <<EOT
IPADDR${ALIAS_NUM}="${IP}"
NETMASK${ALIAS_NUM}="${MASK}"
EOT
}
gen_alias6_conf() {
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "IPADDR_A6A${ALIAS_NUM}=$IP6/${IP6_PREFIX_LENGTH:-64}"
else
IPV6ADDR_SECONDARIES="${IPV6ADDR_SECONDARIES} ${IP6}/${IP6_PREFIX_LENGTH:-64}"
fi
if [ -n "$IP6_ULA" ]; then
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "IPADDR_A6B${ALIAS_NUM}=$IP6_ULA/64"
else
IPV6ADDR_SECONDARIES="${IPV6ADDR_SECONDARIES} ${IP6_ULA}/64"
fi
fi
}
gen_iface6_conf() {
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "IPADDR_6A=$IP6/${IP6_PREFIX_LENGTH:-64}"
cat <<EOT >> /etc/sysconfig/network/ifsysctl-$DEV
net.ipv6.conf.\$SYSCTL_IF.autoconf = 0
net.ipv6.conf.\$SYSCTL_IF.accept_ra = 0
EOT
else
cat <<EOT
IPV6INIT=yes
IPV6ADDR=$IP6/${IP6_PREFIX_LENGTH:-64}
IPV6_AUTOCONF=no
EOT
fi
if [ -n "$IP6_ULA" ]; then
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "IPADDR_6B=$IP6_ULA/64"
else
IPV6ADDR_SECONDARIES="${IPV6ADDR_SECONDARIES} ${IP6_ULA}/64"
fi
fi
if [ -n "$GATEWAY6" ]; then
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "default $GATEWAY6 - $DEV" >> /etc/sysconfig/network/ifroute-$DEV
else
echo "IPV6_DEFAULTGW=$GATEWAY6"
fi
fi
if [ -n "$MTU" ]; then
echo "IPV6_MTU=$MTU"
fi
}
get_interface_mac()
{
ip link show | awk '/^[0-9]+: [A-Za-z0-9@]+:/ { device=$2; gsub(/:/, "",device); split(device,dev,"@")} /link\/ether/ { print dev[1] " " $2 }'
}
get_context_interfaces()
{
env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | sort
}
get_interface_alias()
{
env | grep -E "^ETH${INDEX}_ALIAS[0-9]+_MAC=" | cut -d '_' -f 2 | sort
}
get_dev()
{
list="$1"
mac="$2"
echo "$list" | grep "$mac" | cut -d' ' -f1 | tail -n1
}
gen_network_configuration()
{
if [ -d /etc/sysconfig/network-scripts ]; then
CONFIG_PATH=/etc/sysconfig/network-scripts
elif [ -d /etc/sysconfig/network ]; then
CONFIG_PATH=/etc/sysconfig/network
fi
INTERFACE_MAC=$(get_interface_mac)
CONTEXT_INTERFACES=$(get_context_interfaces)
GATEWAY_IFACE_NUM=$(echo "$GATEWAY_IFACE" | sed 's/^ETH//')
for interface in $CONTEXT_INTERFACES; do
UPCASE_DEV=$interface
MAC=$(get_iface_var "MAC")
DEV=$(get_dev "$INTERFACE_MAC" "$MAC")
IFACE_NUM=$(echo "$UPCASE_DEV" | sed 's/^ETH//')
IP=$(get_ip)
NETWORK=$(get_network)
MASK=$(get_mask)
MTU=$(get_mtu)
GATEWAY=$(get_gateway)
IP6=$(get_iface_var "IP6")
[[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
GATEWAY6=$(get_gateway6)
# cumulative variable
IPV6ADDR_SECONDARIES=''
[ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue
(
rm -f /etc/sysconfig/network/ifroute-$DEV
rm -f /etc/sysconfig/network/ifsysctl-$DEV
cat <<EOT
DEVICE=$DEV
BOOTPROTO=static
NM_CONTROLLED=no
TYPE=Ethernet
EOT
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "STARTMODE=auto"
else
echo "ONBOOT=yes"
fi
[[ -n $IP ]] && gen_iface_conf
[[ -n $IP6 ]] && gen_iface6_conf
INDEX=${interface: -1}
ALIAS=$(get_interface_alias)
ALIAS_NUM=0
for nic_alias in $ALIAS; do
UPCASE_DEV="ETH${INDEX}_${nic_alias}"
IP=$(get_ip)
MASK=$(get_mask)
IP6=$(get_iface_var "IP6")
[[ -z $IP6 ]] && IP6=$(get_iface_var "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
EXTERNAL=$(get_iface_var "EXTERNAL")
EXTERNAL=${EXTERNAL^^}
DETACH=$(get_iface_var "DETACH")
if [ -z "${DETACH}" ]; then
if [ -z "${EXTERNAL}" ] || [ "$EXTERNAL" = "NO" ]; then
[ -n "${IP}" ] && gen_alias_conf
[ -n "${IP6}" ] && gen_alias6_conf
if [ -n "${IP}${IP6}" ]; then
ALIAS_NUM=$((ALIAS_NUM + 1))
fi
fi
fi
done
# on Red Hats, we need just a single configuration
# entry with all additional IPv6 addresses
if [ -n "${IPV6ADDR_SECONDARIES}" ]; then
echo "IPV6ADDR_SECONDARIES='${IPV6ADDR_SECONDARIES## }'"
fi
) > ${CONFIG_PATH}/ifcfg-${DEV}
ifup ${DEV}
done
}
configure_network()
{
gen_network_configuration
if [ "${COMMAND}" = 'reconfigure' ]; then
service network restart
fi
sleep 2
}
[ -z "$(env | cut -d= -f1 | grep -E '^ETH[0-9]+_IPV*6*')" ] && exit 0
configure_network

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
get_iface_var() get_iface_var()
{ {
var_name="${UPCASE_DEV}_$1" var_name="${UPCASE_DEV}_$1"
@ -56,8 +61,8 @@ for pci in $PCI_INTERFACES; do
MASK=$(get_iface_var "MASK") MASK=$(get_iface_var "MASK")
MASK=${MASK:-255.255.255.0} MASK=${MASK:-255.255.255.0}
GATEWAY=$(get_iface_var "GATEWAY") GATEWAY=$(get_iface_var "GATEWAY")
METRIC=$(get_iface_var "METRIC")
MTU=$(get_iface_var "MTU") MTU=$(get_iface_var "MTU")
MTU=${MTU:-1500}
VLAN_ID=$(get_iface_var "VLAN_ID") VLAN_ID=$(get_iface_var "VLAN_ID")
IP6=$(get_iface_var "IP6") IP6=$(get_iface_var "IP6")
@ -93,7 +98,7 @@ for pci in $PCI_INTERFACES; do
ip address add $IP/$MASK dev $DEV ip address add $IP/$MASK dev $DEV
if [ -n "$GATEWAY" ]; then if [ -n "$GATEWAY" ]; then
ip route add default via $GATEWAY dev $DEV ip route add default via $GATEWAY dev $DEV ${METRIC:+metric ${METRIC}}
fi fi
fi fi

@ -0,0 +1,573 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
# shellcheck disable=SC2155
#
# network module interface
#
export required_context_type='local' # this is the default, the next option is 'online'
is_network_supported()
{
false
}
initialize_network()
{
# shellcheck disable=SC2154
case "${os_id}" in
freebsd)
:
;;
*)
mkdir -p /etc/sysctl.d/
rm -f /etc/sysctl.d/50-one-context.conf
sysctl --system 2>/dev/null || sysctl -p
;;
esac
#
# remove all stale configs from any of the previous runs
#
# TODO: improve this and support proper network unconfigure and cleanup
# on action=reconfigure too - this becomes problematic when NETCFG_TYPE is
# changed while VM is running (deleting configs will break ifdown etc.)
#
# shellcheck disable=SC2154
[ "${action}" = 'configure' ] || return 0
_context_interfaces=$(get_context_interfaces)
_iface_mac=$(get_interface_mac)
for _iface in $_context_interfaces; do
_mac=$(get_iface_var "${_iface}" "MAC")
_dev=$(get_dev "${_iface_mac}" "${_mac}")
# network-scripts
rm -f \
"/etc/sysconfig/network-scripts/route-${dev}" \
"/etc/sysconfig/network-scripts/route6-${dev}" \
"/etc/sysconfig/network-scripts/ifcfg-${dev}" \
"/etc/sysconfig/network/ifroute-${dev}" \
"/etc/sysconfig/network/ifsysctl-${dev}" \
"/etc/sysconfig/network/ifcfg-${dev}" \
;
# networkd
rm -f \
"/etc/systemd/network/${dev}.network" \
"/etc/systemd/network/${dev}.link"
# nm (on RH systems it was deleted with ifcfg-*)
for _nm_con in /etc/NetworkManager/system-connections/* ; do
if [ -e "${_nm_con}" ] && grep -q "^interface-name=${_dev}$" "${_nm_con}" ; then
rm -f "${_nm_con}"
fi
done
done
# To avoid clashes when running legacy network-scripts and
# NetworkManager/networkd, we disable old-style networking
# on Red Hats and enable later back only if needed.
if [ -d /etc/sysconfig/network-scripts/ ]; then
touch /etc/sysconfig/network
sed -i -e '/^NETWORKING=/d' /etc/sysconfig/network
echo 'NETWORKING=no' >>/etc/sysconfig/network
fi
# interfaces
if [ -e /etc/network/interfaces ] ; then
cat <<EOT >/etc/network/interfaces
# Generated by one-context
auto lo
iface lo inet loopback
EOT
case "${os_id}" in
debian|ubuntu|devuan)
echo "source /etc/network/interfaces.d/*.cfg" >> /etc/network/interfaces
;;
esac
fi
# netplan
rm -f /etc/netplan/50-one-context.yaml
nm_disable
}
nm_disable() {
if [ -d /etc/NetworkManager/conf.d/ ] &&
! [ -e /etc/NetworkManager/conf.d/50-unmanaged-devices.conf ];
then
cat - <<EOF >/etc/NetworkManager/conf.d/50-unmanaged-devices.conf
# Generated by one-context
# NOTE: NetworkManager was dynamically disabled by OpenNebula
# contextualization scripts because interfaces are managed by
# different network service!
[keyfile]
unmanaged-devices=*
EOF
if command -v systemctl >/dev/null; then
systemctl --no-block try-reload-or-restart NetworkManager.service 2>/dev/null
else
service NetworkManager reload 2>/dev/null
fi
fi
}
nm_enable() {
if [ -e /etc/NetworkManager/conf.d/50-unmanaged-devices.conf ]; then
rm -f /etc/NetworkManager/conf.d/50-unmanaged-devices.conf
if command -v systemctl >/dev/null; then
systemctl --no-block try-reload-or-restart NetworkManager.service 2>/dev/null
else
service NetworkManager reload 2>/dev/null
fi
fi
}
configure_network()
{
echo "ERROR [!]: No 'configure_network' implementation for the network type: ${NETCFG_TYPE}" >&2
exit 1
}
stop_network()
{
echo "ERROR [!]: No 'stop_network' implementation for the network type: ${NETCFG_TYPE}" >&2
exit 1
}
start_network()
{
echo "ERROR [!]: No 'start_network' implementation for the network type: ${NETCFG_TYPE}" >&2
exit 1
}
reload_network()
{
echo "ERROR [!]: No 'reload_network' implementation for the network type: ${NETCFG_TYPE}" >&2
exit 1
}
#
# generic shared functions
#
# arg: <true|yes|false|no>
is_true()
(
_value=$(echo "$1" | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
tr '[:upper:]' '[:lower:]')
case "$_value" in
1|true|yes|y)
return 0
;;
esac
return 1
)
# return OS ID
detect_os()
(
if [ -f /etc/os-release ] ; then
ID=
# shellcheck disable=SC1091
. /etc/os-release
echo "$ID" | tr '[:upper:]' '[:lower:]'
# check for legacy RHEL/CentOS 6
elif [ -f /etc/centos-release ]; then
echo 'centos'
elif [ -f /etc/redhat-release ]; then
echo 'rhel'
# fallback to uname (returns Linux, FreeBSD, ...)
else
uname | tr '[:upper:]' '[:lower:]'
fi
)
# arg: <iface>
disable_ipv6()
(
# shellcheck disable=SC2154
case "${os_id}" in
freebsd)
# TODO: these are the relevant options in /etc/rc.conf:
# ip6addrctl_enable="NO"
# ip6addrctl_policy="ipv4_prefer"
# ipv6_activate_all_interfaces="NO"
# ipv6_network_interfaces="none"
echo "ERROR [!]: Disabling of IPv6 on '${os_id}' is not supported" >&2
;;
*)
# VH-TODO: do we suport runtime enable?
for S in \
"net.ipv6.conf.${1}.disable_ipv6=1" \
"net.ipv6.conf.${1}.autoconf=0" \
"net.ipv6.conf.${1}.accept_ra=0";
do
# don't duplicate entries on recontextualization
if ! grep -Fxq "${S}" /etc/sysctl.d/50-one-context.conf 2>/dev/null; then
echo "${S}" >> /etc/sysctl.d/50-one-context.conf
fi
sysctl -w "${S}" >/dev/null
done
;;
esac
)
# arg: <iface>
disable_ipv6_privacy()
(
case "${os_id}" in
freebsd)
echo "ERROR [!]: Disabling of IPv6 privacy on '${os_id}' is not supported" >&2
;;
*)
# shellcheck disable=SC2066
for S in \
"net.ipv6.conf.${1}.use_tempaddr=0";
do
# don't duplicate entries on recontextualization
if ! grep -Fxq "${S}" /etc/sysctl.d/50-one-context.conf 2>/dev/null; then
echo "${S}" >> /etc/sysctl.d/50-one-context.conf
fi
sysctl -w "${S}" >/dev/null
done
;;
esac
)
skip_interface()
{
[ -z "${dev}" ] && return 0
_skip4=
case "${method}" in
''|static)
if [ -z "${ip}" ] ; then
_skip4=yes
else
_skip4=no
fi
;;
skip)
_skip4=yes
;;
dhcp)
_skip4=no
;;
*)
echo "ERROR [!]: Unknown IPv4 method: ${method}, skipping" >&2
_skip4=yes
;;
esac
_skip6=
case "${ip6_method}" in
''|static)
if [ -z "${ip6}" ] ; then
_skip6=yes
else
_skip6=no
fi
;;
skip)
_skip6=yes
;;
disable)
disable_ipv6 "${dev}"
_skip6=yes
;;
auto|dhcp)
_skip6=no
;;
*)
echo "ERROR [!]: Unknown IPv6 method: ${ip6_method}" >&2
_skip6=yes
;;
esac
if is_true "${_skip4}" && is_true "${_skip6}" ; then
return 0
fi
return 1
}
# args: <iface> <name>
get_iface_var()
(
_iface=$(echo "$1" | tr '[:lower:]' '[:upper:]')
_var_name="${_iface}_${2}"
eval "echo \"\${${_var_name}}\""
)
# Gets IP address from a given MAC
mac2ip()
(
_mac="$1"
_ip_a=$(echo "$_mac" | cut -d: -f 3)
_ip_b=$(echo "$_mac" | cut -d: -f 4)
_ip_c=$(echo "$_mac" | cut -d: -f 5)
_ip_d=$(echo "$_mac" | cut -d: -f 6)
echo "0x${_ip_a}.0x${_ip_b}.0x${_ip_c}.0x${_ip_d}"
)
mask2cidr()
(
_mask="$1"
_nbits=0
IFS=.
for _dec in $_mask ; do
case "$_dec" in
255) _nbits=$((_nbits + 8)) ;;
254) _nbits=$((_nbits + 7)) ; break ;;
252) _nbits=$((_nbits + 6)) ; break ;;
248) _nbits=$((_nbits + 5)) ; break ;;
240) _nbits=$((_nbits + 4)) ; break ;;
224) _nbits=$((_nbits + 3)) ; break ;;
192) _nbits=$((_nbits + 2)) ; break ;;
128) _nbits=$((_nbits + 1)) ; break ;;
0) break ;;
*) echo "Error: $_dec is not recognised"; exit 1 ;;
esac
done
echo "$_nbits"
)
# Gets the network part of an IP
# arg: <iface>
get_network()
(
_network=$(get_iface_var "$1" "NETWORK")
if [ -z "$_network" ]; then
_ip=$(get_ip "$1")
_mask=$(get_mask "$1")
_network=$(awk -v ip="$_ip" -v mask="$_mask" 'END {
split(ip, ip_b, "."); split(mask, mask_b, ".");
for (i=1; i<=4; ++i) x = x "." and(ip_b[i], mask_b[i]);
sub(/^./, "", x); print x; }' </dev/null)
fi
echo "$_network"
)
# Gets the network mask
# arg: <iface>
get_mask()
(
_mask=$(get_iface_var "$1" "MASK")
echo "${_mask:-255.255.255.0}"
)
# Gets device MTU
# arg: <iface>
get_mtu()
(
# VH_TODO: drop default 1500, nekde se spoleha na tento default!
_mtu=$(get_iface_var "$1" "MTU")
echo "${_mtu:-1500}"
)
# Gets the network gateway
# arg: <iface>
get_gateway()
(
get_iface_var "$1" "GATEWAY"
)
# arg: <iface>
get_ip()
(
get_iface_var "$1" "IP"
)
# arg: <iface>
get_dns()
(
get_iface_var "$1" "DNS"
)
# arg: <iface>
get_search_domain()
(
get_iface_var "$1" "SEARCH_DOMAIN"
)
# arg: <iface>
get_interface_alias()
(
# sed on freebsd does not recognize '+' - replacing with asterisk
env | sed -n "s#^\(${1}_ALIAS[0-9][0-9]*\)_MAC=.*#\1#p" | sort
)
get_context_interfaces()
(
# sed on freebsd does not recognize '+' - replacing with asterisk
env | sed -n 's/^\(ETH[0-9][0-9]*\)_MAC=.*/\1/p' | sort
)
get_pci_interfaces()
(
# sed on freebsd does not recognize '+' - replacing with asterisk
env | sed -n 's/^\(PCI[0-9][0-9]*\)_MAC=.*/\1/p' | sort
)
get_interface_mac()
(
ip link show | awk '/^[0-9]+: [A-Za-z0-9@]+:/ { device=$2; gsub(/:/, "",device); split(device,dev,"@")} /link\/ether/ { print dev[1] " " $2 }'
)
get_dev()
(
_list="$1"
_mac="$2"
echo "$_list" | grep "$_mac" | cut -d' ' -f1 | tail -n1
)
# arg: <interface/alias>
setup_ipadr_vars()
{
export ip=$(get_ip "$1")
export network=$(get_network "$1")
export mask=$(get_mask "$1")
export cidr=$(mask2cidr "$mask")
}
# arg: <interface/alias>
setup_ip6adr_vars()
{
export ip6=$(get_iface_var "$1" "IP6")
export ip6_prefix_length=$(get_iface_var "$1" "IP6_PREFIX_LENGTH")
export ip6_ula=$(get_iface_var "$1" "IP6_ULA")
[ -z "$ip6" ] && ip6=$(get_iface_var "$1" "IPV6")
[ -z "$ip6_prefix_length" ] && ip6_prefix_length=64
}
# arg: <interface>
setup_iface_vars()
{
_iface_mac=$(get_interface_mac)
export mac=$(get_iface_var "$1" "MAC")
export dev=$(get_dev "$_iface_mac" "$mac")
export mtu=$(get_iface_var "$1" "MTU")
export gateway=$(get_gateway "$1")
export metric=$(get_iface_var "$1" "METRIC")
export dns=$(get_dns "$1")
export search_domains=$(get_search_domain "$1")
export method=$(get_iface_var "$1" "METHOD")
export ip6_gateway=$(get_iface_var "$1" "IP6_GATEWAY")
export ip6_metric=$(get_iface_var "$1" "IP6_METRIC")
export ip6_method=$(get_iface_var "$1" "IP6_METHOD")
# backward compatibility
[ -z "$ip6_gateway" ] && ip6_gateway=$(get_iface_var "$1" "GATEWAY6")
# defaults
[ -z "$ip6_metric" ] && ip6_metric="${metric}"
[ -z "$method" ] && method='static'
[ -z "$ip6_method" ] && ip6_method="${method}"
setup_ipadr_vars "$1"
setup_ip6adr_vars "$1"
}
# arg: <alias>
setup_alias_vars()
{
export external=$(get_iface_var "$1" "EXTERNAL")
export detach=$(get_iface_var "$1" "DETACH")
}
get_nameservers()
(
# sed on freebsd does not recognize '+' - replacing with asterisk
_dns_variables=$(env | sed -n 's/^\(ETH[0-9][0-9]*_DNS\)=.*/\1/p' | sort)
for _dns in DNS ${_dns_variables} ; do
_value=$(eval "echo \"\${$_dns}\"")
if [ -n "$_value" ] ; then
echo "$_value"
fi
done
)
get_searchdomains()
(
# sed on freebsd does not recognize '+' - replacing with asterisk
_search_domains=$(env | sed -n 's/^\(ETH[0-9][0-9]*_SEARCH_DOMAIN\)=.*/\1/p' | sort)
for _search in SEARCH_DOMAIN ${_search_domains} ; do
_value=$(eval "echo \"\${$_search}\"")
if [ -n "$_value" ] ; then
echo "$_value"
fi
done
)
gen_resolvconf()
{
export all_nameservers=$(get_nameservers)
export all_search_domains=$(get_searchdomains)
[ -z "$all_nameservers" ] && return 0
if [ -L /etc/resolv.conf ]; then
unlink /etc/resolv.conf
else
cat /dev/null > /etc/resolv.conf
fi
for _nameserver in $all_nameservers ; do
echo "nameserver ${_nameserver}" >> /etc/resolv.conf
done
if [ -f /etc/sysconfig/network/config ]; then
sed -i "/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=\"${all_nameservers}\"/" /etc/sysconfig/network/config
fi
[ -z "$all_search_domains" ] && return 0
echo "search ${all_search_domains}" >> /etc/resolv.conf
if [ -f /etc/sysconfig/network/config ]; then
sed -i "/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=\"${all_search_domains}\"/" /etc/sysconfig/network/config
fi
}

@ -0,0 +1,285 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
#
# network module implementation
#
is_network_supported()
{
case "${os_id}" in
freebsd)
return 0
;;
esac
return 1
}
configure_network()
{
gen_resolvconf
gen_network_configuration > /etc/rc.conf.d/network
}
stop_network()
{
service netif stop >/dev/null
service routing stop >/dev/null
service rtsold stop >/dev/null
}
start_network()
{
service netif start >/dev/null
service routing start >/dev/null
service rtsold start >/dev/null
}
reload_network()
{
service netif restart >/dev/null
service routing restart >/dev/null
service rtsold restart >/dev/null
}
#
# helper functions
#
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export ip6
export ip6_prefix_length
export ip6_ula
export mac
export dev
export mtu
export gateway
export ip6_gateway
export method
export ip6_method
export metric
export ip6_metric
export dns
export search_domains
export external
export detach
export all_nameservers
export all_search_domains
get_interface_mac()
(
_macs=$(ifconfig | grep ether | awk '{print $2}')
for _mac in ${_macs} ; do
_iface=$(ifconfig | grep -B 2 "$_mac" | head -n 1 | awk '{print $1}' | cut -d ':' -f 1)
echo "${_iface} ${_mac}"
done
)
gen_iface_conf()
{
echo -n "ifconfig_${dev}=\"inet ${ip} netmask ${mask}"
if [ -n "${mtu}" ]; then
echo -n " mtu ${mtu}"
fi
# WARNING: On FreeBSD the interface metrics are used only
# by routing daemons (see man 8 ifconfig)
if [ -n "${metric}" ]; then
echo -n " metric ${metric}"
fi
echo "\""
###
if [ -n "${gateway}" ]; then
echo "defaultrouter=\"${gateway}\"" >> /etc/rc.conf.d/routing
fi
}
gen_dhcp_conf()
{
echo -n "ifconfig_${dev}=\"DHCP"
if [ -n "${mtu}" ]; then
echo -n " inet mtu ${mtu}"
fi
echo "\""
}
gen_alias_conf()
{
echo "ifconfig_${dev}_alias${alias_num}=\"inet ${ip} netmask ${mask}\""
alias_num=$((alias_num + 1))
}
gen_iface6_conf()
{
echo -n "ifconfig_${dev}_ipv6=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}"
if [ -n "${mtu}" ]; then
echo -n " mtu ${mtu}"
fi
# WARNING: On FreeBSD the interface metrics are used only
# by routing daemons (see man 8 ifconfig)
if [ -n "${ip6_metric}" ]; then
echo -n " metric ${ip6_metric}"
fi
echo " -accept_rtadv\""
if [ -n "${ip6_ula}" ]; then
echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6_ula} prefixlen 64\""
alias_num=$((alias_num + 1))
fi
###
if [ -n "${ip6_gateway}" ]; then
echo "ipv6_defaultrouter=\"${ip6_gateway}\"" >> /etc/rc.conf.d/routing
fi
}
gen_dhcp6_conf()
{
echo -n "ifconfig_${dev}_ipv6=\""
if [ "${ip6_method}" = "dhcp" ] ; then
echo -n "DHCP "
# FreeBSD support for DHCP6 does not seem to be great:
# https://forums.freebsd.org/threads/ipv6-dhcpv6-client-and-accept_rtadv-vs-rtsold.77421/
# https://forums.freebsd.org/threads/is-there-a-working-dhcpv6-client-for-freebsd.60168/
# https://subatomicsolutions.org/8-freebsd/13-ipv4-ipv6-client-addresses-via-dhcp
_dhclient_program=$(sysrc -n dhclient_program 2>/dev/null)
if [ -z "${_dhclient_program}" ] || [ "${_dhclient_program}" = '/sbin/dhclient' ]; then
echo "WARNING [!]: DHCPv6 on '${os_id}' is poorly supported, you need a different DHCP client! You can install net/isc-dhcp44-client and put into /etc/rc.conf: dhclient_program=\"/usr/sbin/one-dual-dhclient\"" >&2
fi
fi
echo -n "inet6 accept_rtadv"
if [ -n "${mtu}" ]; then
echo -n " mtu ${mtu}"
fi
echo "\""
# Enable Router Solicitation Deaemon
# NOTE: It's not enough to just enable the daemon during the current
# boot process, since the services to run are already evaluated. We also
# explicitly start the service on our own (but doesn't have to be correct!)
sysrc rtsold_enable="YES" >/dev/null
service rtsold start >/dev/null
}
gen_alias6_conf()
{
# very first IPv6 can't be alias
if [ -n "${has_ip6}" ]; then
echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}\""
alias_num=$((alias_num + 1))
else
echo -n "ifconfig_${dev}_ipv6=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}"
if [ -n "${mtu}" ]; then
echo -n " mtu ${mtu}"
fi
# WARNING: On FreeBSD the interface metrics are used only
# by routing daemons (see man 8 ifconfig)
if [ -n "${ip6_metric}" ]; then
echo -n " metric ${ip6_metric}"
fi
echo " -accept_rtadv\""
fi
if [ -n "${ip6_ula}" ]; then
echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6_ula} prefixlen 64\""
alias_num=$((alias_num + 1))
fi
}
gen_network_configuration()
{
# clean routing information
echo '# Generated by one-context' | tee /etc/rc.conf.d/routing
_context_interfaces=$(get_context_interfaces)
for _iface in $_context_interfaces; do
setup_iface_vars "$_iface"
skip_interface && continue
case "${method}" in
''|static)
[ -n "${ip}" ] && gen_iface_conf
;;
dhcp)
gen_dhcp_conf
;;
esac
case "${ip6_method}" in
''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto|dhcp)
gen_dhcp6_conf
;;
disable)
:
;;
esac
has_ip6="${ip6}"
_aliases=$(get_interface_alias "$_iface")
alias_num=0
for _nic_alias in $_aliases; do
setup_ipadr_vars "$_nic_alias"
setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${detach}" ]; then
if ! is_true "${external}" ; then
[ -n "${ip}" ] && gen_alias_conf
if [ -n "${ip6}" ]; then
gen_alias6_conf
has_ip6="${ip6}"
fi
fi
fi
done
done
}

@ -0,0 +1,403 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
#
# network module implementation
#
is_network_supported()
{
case "${os_id}" in
alpine)
return 0
;;
debian|ubuntu|devuan)
return 0
;;
esac
return 1
}
configure_network()
{
gen_resolvconf
gen_network_configuration > /etc/network/interfaces
}
stop_network()
{
case "${os_id}" in
alpine)
service networking stop || true
# took from find_ifaces in the networking service
_ifaces=$(\
awk '$1 == "auto" {
for (i = 2; i <= NF; i = i + 1) printf("%s ", $i)
}' /etc/network/interfaces)
for _iface in $_ifaces; do
if [ "${_iface}" != 'lo' ]; then
/sbin/ip link set dev "${_iface}" down || true
/sbin/ip addr flush dev "${_iface}" || true
fi
done
;;
debian|ubuntu|devuan)
if [ -f "/usr/sbin/ifreload" ] ; then
return 0
fi
_ifaces=$(/sbin/ifquery --list -a)
for _iface in $_ifaces; do
if [ "${_iface}" != 'lo' ] ; then
/sbin/ifdown "${_iface}"
/sbin/ip link set dev "${_iface}" down || true
/sbin/ip addr flush dev "${_iface}" || true
fi
done
;;
*)
exit 1
;;
esac
}
start_network()
{
case "${os_id}" in
alpine)
service networking start
;;
debian|ubuntu|devuan)
if [ -f "/usr/sbin/ifreload" ] ; then
/usr/sbin/ifreload -a
return 0
fi
_ifaces=$(/sbin/ifquery --list -a)
for _iface in $_ifaces; do
/sbin/ifup "${_iface}"
done
;;
*)
exit 1
;;
esac
}
reload_network()
{
stop_network
start_network
}
#
# helper functions
#
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export ip6
export ip6_prefix_length
export ip6_ula
export mac
export dev
export mtu
export gateway
export ip6_gateway
export method
export ip6_method
export metric
export ip6_metric
export dns
export search_domains
export external
export detach
export all_nameservers
export all_search_domains
gen_iface_conf()
{
cat <<EOT
iface ${dev} inet static
address ${ip}
network ${network}
netmask ${mask}
EOT
if [ -n "$gateway" ]; then
echo " gateway ${gateway}"
if [ -n "$metric" ]; then
echo " metric ${metric}"
fi
fi
if [ -n "$mtu" ]; then
echo " mtu ${mtu}"
fi
echo ""
}
gen_dhcp_conf()
{
echo "iface ${dev} inet dhcp"
if [ -n "$mtu" ]; then
case "${os_id}" in
alpine)
echo " mtu ${mtu}"
;;
debian|ubuntu|devuan)
echo " pre-up ip link set dev ${dev} mtu ${mtu}"
;;
*)
exit 1
;;
esac
fi
echo ""
}
gen_alias_conf()
{
cat <<EOT
iface ${dev} inet static
address ${ip}
network ${network}
netmask ${mask}
EOT
echo ""
}
gen_iface6_conf()
{
case "${os_id}" in
alpine)
cat <<EOT
iface ${dev} inet6 static
address ${ip6}
netmask ${ip6_prefix_length:-64}
pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/autoconf
pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/accept_ra
EOT
;;
debian|ubuntu|devuan)
cat <<EOT
iface ${dev} inet6 static
address ${ip6}
netmask ${ip6_prefix_length:-64}
autoconf 0
accept_ra 0
EOT
;;
esac
# On Alpine Linux when using IPv6 gateway/metric options,
# they override the metric on IPv4 routes. We better configure
# default route via up script.
if [ "${os_id}" = 'alpine' ] && \
[ -n "${ip6_gateway}" ] && [ -n "${ip6_metric}" ];
then
echo " up ip -6 route add default via ${ip6_gateway} dev ${dev} metric ${ip6_metric}"
elif [ -n "${ip6_gateway}" ]; then
echo " gateway ${ip6_gateway}"
if [ -n "${ip6_metric}" ]; then
echo " metric ${ip6_metric}"
fi
fi
if [ -n "${mtu}" ]; then
case "${os_id}" in
alpine)
echo " mtu ${mtu}"
;;
debian|ubuntu|devuan)
# Ignores "mtu x", IPv6-only interfaces would not be configured
echo " pre-up ip link set dev ${dev} mtu ${mtu}"
echo " pre-up echo ${mtu} > /proc/sys/net/ipv6/conf/${dev}/mtu"
;;
*)
exit 1
;;
esac
fi
echo ""
if [ -n "${ip6_ula}" ]; then
cat <<EOT
iface ${dev} inet6 static
address ${ip6_ula}
netmask 64
EOT
fi
echo ""
}
gen_dhcp6_conf()
{
if [ "${ip6_method}" = "auto" ] ; then
echo "iface ${dev} inet6 auto"
else
echo "iface ${dev} inet6 dhcp"
fi
case "${os_id}" in
alpine)
if [ -n "${mtu}" ]; then
echo " mtu ${mtu}"
fi
echo " pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/use_tempaddr"
;;
debian|ubuntu|devuan)
# Privext might not be effective in "dhcp" mode, so we better
# directly configure also sysctl parameters. Also, there might
# be a race condition between activating IPv4 and IPv6 part of
# interface if IPv4 is dhcp. As a aresult, IPv6 SLAAC privacy
# address might appear. So, for safety we better drop any global
# IPv6 addresses as part of pre-up.
echo " privext 0"
echo " pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/use_tempaddr"
echo " pre-up ip -6 addr flush dev ${dev} scope global || /bin/true"
if [ -n "${mtu}" ]; then
# Ignores "mtu x", IPv6-only interfaces would not be configured
echo " pre-up ip link set dev ${dev} mtu ${mtu}"
echo " pre-up echo ${mtu} > /proc/sys/net/ipv6/conf/${dev}/mtu"
fi
;;
*)
exit 1
;;
esac
echo ""
}
gen_alias6_conf()
{
case "${os_id}" in
alpine)
cat <<EOT
iface ${dev} inet6 static
address ${ip6}
netmask ${ip6_prefix_length:-64}
EOT
;;
debian|ubuntu|devuan)
cat <<EOT
iface ${dev} inet6 static
address ${ip6}
netmask ${ip6_prefix_length:-64}
EOT
;;
esac
echo ""
if [ -n "${ip6_ula}" ]; then
cat <<EOT
iface ${dev} inet6 static
address ${ip6_ula}
netmask 64
EOT
fi
echo ""
}
gen_network_configuration()
{
cat <<EOT
# Generated by one-context
auto lo
iface lo inet loopback
EOT
_context_interfaces=$(get_context_interfaces)
for _iface in $_context_interfaces; do
setup_iface_vars "$_iface"
skip_interface && continue
echo "auto ${dev}"
case "${method}" in
''|static)
[ -n "${ip}" ] && gen_iface_conf
;;
dhcp)
gen_dhcp_conf
;;
esac
case "${ip6_method}" in
''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto|dhcp)
gen_dhcp6_conf
;;
disable)
:
;;
esac
_aliases=$(get_interface_alias "$_iface")
for _nic_alias in $_aliases ; do
setup_ipadr_vars "$_nic_alias"
setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${detach}" ]; then
if ! is_true "${external}" ; then
[ -n "${ip}" ] && gen_alias_conf
[ -n "${ip6}" ] && gen_alias6_conf
fi
fi
done
done
case "${os_id}" in
debian|ubuntu|devuan)
echo "source /etc/network/interfaces.d/*.cfg"
;;
esac
}

@ -0,0 +1,346 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
#
# network module implementation
#
is_network_supported()
{
command -v netplan >/dev/null
return $?
}
configure_network()
{
init_netplan_renderer
gen_resolvconf
gen_network_configuration > /etc/netplan/50-one-context.yaml
netplan generate
nm_symlink_run_connections
# On Debian 10 and Ubuntu 18.04 the initial netplan apply is needed to
# set some interface parameters (e.g., MTU). Unfortunately, this deadlocks
# booting of current systems, so we execute netplan apply on the background
case "${NETCFG_NETPLAN_RENDERER}" in
''|networkd)
flock /var/run/one-context/netplan.lock nohup netplan apply &>/dev/null &
;;
esac
}
stop_network()
{
service networking stop
}
start_network()
{
netplan generate
nm_symlink_run_connections
service networking start
flock /var/run/one-context/netplan.lock netplan apply
}
reload_network()
{
netplan generate
nm_symlink_run_connections
flock /var/run/one-context/netplan.lock netplan apply
}
#
# helper functions
#
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export ip6
export ip6_prefix_length
export ip6_ula
export mac
export dev
export mtu
export gateway
export ip6_gateway
export method
export ip6_method
export metric
export ip6_metric
export dns
export search_domains
export external
export detach
export all_nameservers
export all_search_domains
gen_addresses()
{
case "${method}" in
''|static)
[ -n "${ip}" ] && gen_addr_conf
;;
esac
case "${ip6_method}" in
''|static)
[ -n "${ip6}" ] && gen_addr6_conf
;;
esac
_aliases=$(get_interface_alias "$_iface")
for _nic_alias in $_aliases; do
setup_ipadr_vars "$_nic_alias"
setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${detach}" ]; then
if ! is_true "${external}" ; then
[ -n "${ip}" ] && gen_addr_conf
[ -n "${ip6}" ] && gen_addr6_conf
fi
fi
done
}
gen_routes()
{
if [ -n "${gateway}" ] && { [ -z "${method}" ] || [ "${method}" = 'static' ]; }; then
cat <<EOT
- to: "0.0.0.0/0"
via: ${gateway}
EOT
# Force default Linux IPv4 metric (man 8 route) to override
# automatic metrics calculation done by NetworkManager and unify
# behavior among different renderers.
metric=${metric:-0}
if [ -n "${metric}" ] ; then
echo " metric: ${metric}"
fi
fi
if [ -n "${ip6_gateway}" ] && { [ -z "${ip6_method}" ] || [ "${ip6_method}" = 'static' ]; }; then
cat <<EOT
- to: "::/0"
via: ${ip6_gateway}
EOT
# Force default Linux IPv6 metric (man 8 route) to override
# automatic metrics calculation done by NetworkManager and unify
# behavior among different renderers.
ip6_metric=${ip6_metric:-1}
if [ -n "${ip6_metric}" ] ; then
echo " metric: ${ip6_metric}"
fi
fi
}
gen_dhcp_conf()
{
cat <<EOT
dhcp4: true
EOT
}
gen_addr_conf()
{
echo " - ${ip}/${cidr}"
}
gen_addr6_conf()
{
echo " - ${ip6}/${ip6_prefix_length:-64}"
if [ -n "$ip6_ula" ]; then
echo " - ${ip6_ula}/64"
fi
}
gen_dhcp6_conf()
{
if [ "${ip6_method}" = "auto" ] ; then
cat <<EOT
accept-ra: true
dhcp6: false
EOT
else
cat <<EOT
accept-ra: true
dhcp6: true
EOT
fi
cat <<EOT
ipv6-privacy: false
EOT
}
gen_ipv6_disable()
{
cat <<EOT
accept-ra: false
link-local: []
EOT
}
# Old NM doesn't read from /run/NetworkManager/system-connections,
# so the generated Netplan configuration is not respected. As a workaround,
# we symlink the connection files into /etc
nm_symlink_run_connections()
{
if [ "${NETCFG_NETPLAN_RENDERER}" != 'NetworkManager' ] ||
! [ -d /run/NetworkManager/system-connections ];
then
return
fi
# cleanup any old symlinks
rm -f /etc/NetworkManager/system-connections/netplan-*
case "$(NetworkManager --version 2>/dev/null)" in
1.14.*) # Debian 10
echo "WARNING: Symlinking NM's ephemeral connections into /etc" >&2
;;
*)
return
;;
esac
# symlink Netplan connection files
for _src in /run/NetworkManager/system-connections/netplan-*; do
if [ -f "${_src}" ]; then
_dst="/etc/NetworkManager/system-connections/$(basename "${_src}")"
ln -s "${_src}" "${_dst}"
fi
done
}
init_netplan_renderer()
{
if [ -z "${NETCFG_NETPLAN_RENDERER}" ] ; then
if command -v networkctl >/dev/null ; then
NETCFG_NETPLAN_RENDERER='networkd'
elif command -v nmcli >/dev/null ; then
NETCFG_NETPLAN_RENDERER='NetworkManager'
else
# fallback to networkd only not to leave the variable
# uninitialized, deployment most likely won't work!
NETCFG_NETPLAN_RENDERER='networkd'
fi
else
# support alternative names for some configuration renderers
_netcfg_netplan_renderer=$(echo "$NETCFG_NETPLAN_RENDERER" | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
tr '[:upper:]' '[:lower:]')
# normalize renderer names and support alternatives
case "${_netcfg_netplan_renderer}" in
systemd-networkd|systemd-network|systemd|networkd)
NETCFG_NETPLAN_RENDERER='networkd'
;;
networkmanager|nm)
NETCFG_NETPLAN_RENDERER='NetworkManager'
;;
esac
fi
}
gen_network_configuration()
{
if [ "${NETCFG_NETPLAN_RENDERER}" = 'NetworkManager' ]; then
nm_enable
fi
cat <<EOT
# Generated by one-context
network:
version: 2
renderer: ${NETCFG_NETPLAN_RENDERER}
EOT
# ethernets key must have at least one interface
_ethernets_written=
_context_interfaces=$(get_context_interfaces)
for _iface in $_context_interfaces; do
setup_iface_vars "$_iface"
skip_interface && continue
if [ -z "${_ethernets_written}" ] ; then
echo " ethernets:"
_ethernets_written=yes
fi
echo " ${dev}:"
if [ -n "${mtu}" ]; then
echo " mtu: ${mtu}"
fi
## Requires Netplan 0.98+
# if [ -n "${mtu}" ]; then
# echo " ip6-mtu: ${mtu}"
# fi
case "${method}" in
''|static)
: # in gen_addresses
;;
dhcp)
gen_dhcp_conf
;;
esac
case "${ip6_method}" in
''|static)
: # in gen_addresses
;;
auto|dhcp)
gen_dhcp6_conf
;;
disable)
gen_ipv6_disable
;;
esac
_addresses=$(gen_addresses)
if [ -n "${_addresses}" ] ; then
echo " addresses:"
echo "${_addresses}"
fi
_routes=$(gen_routes)
if [ -n "${_routes}" ] ; then
echo " routes:"
echo "${_routes}"
fi
done
}

@ -0,0 +1,380 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
#
# network module implementation
#
is_network_supported()
{
command -v networkctl >/dev/null
return $?
}
configure_network()
{
gen_resolvconf
gen_network_configuration
}
stop_network()
{
systemctl stop systemd-networkd.service
}
start_network()
{
systemctl start systemd-networkd.service
# Dummy query waits until networkd is running
networkctl list &>/dev/null || :
}
reload_network()
{
# TODO: for newer systemd-networkd use
# networkctl reload && networkctl reconfigure ethX
# and fallback to service restart only if needed
systemctl restart systemd-networkd.service
# Dummy query waits until networkd is running
networkctl list &>/dev/null || :
}
#
# helper functions
#
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export ip6
export ip6_prefix_length
export ip6_ula
export mac
export dev
export mtu
export gateway
export ip6_gateway
export method
export ip6_method
export metric
export ip6_metric
export dns
export search_domains
export external
export detach
export all_nameservers
export all_search_domains
gen_iface_conf()
{
cat <<EOT
[Network]
Address=${ip}/${cidr}
EOT
if [ -n "$dns" ]; then
for _domain in $dns; do
echo "DNS=${_domain}"
done
fi
if [ -n "$search_domains" ]; then
for _search_domain in $search_domains; do
echo "Domains=${_search_domain}"
done
fi
cat <<EOT
[Route]
EOT
if [ -n "$gateway" ]; then
echo "Gateway=${gateway}"
if [ -n "$metric" ]; then
echo "Metric=${metric}"
fi
fi
echo ""
}
gen_dhcp_conf()
{
case "${dhcp_conf}" in
ipv4)
cat <<EOT
[Network]
DHCP=ipv4
EOT
;;
ipv4+auto)
cat <<EOT
[Network]
DHCP=ipv4
IPv6AcceptRA=yes
[IPv6AcceptRA]
DHCPv6Client=no
EOT
;;
ipv6)
cat <<EOT
[Network]
DHCP=ipv6
IPv6AcceptRA=yes
EOT
;;
both)
cat <<EOT
[Network]
DHCP=yes
IPv6AcceptRA=yes
EOT
;;
auto)
cat <<EOT
[Network]
DHCP=no
IPv6AcceptRA=yes
[IPv6AcceptRA]
DHCPv6Client=no
EOT
;;
esac
cat <<EOT
[Network]
IPv6PrivacyExtensions=no
EOT
echo ""
}
gen_alias_conf()
{
cat <<EOT
[Address]
Address=${ip}/${cidr}
EOT
echo ""
}
gen_iface6_conf()
{
cat <<EOT
[Network]
Address=${ip6}/${ip6_prefix_length:-64}
EOT
echo "IPv6AcceptRA=false"
if [ -n "$dns" ]; then
for _domain in $dns; do
echo "DNS=${_domain}"
done
fi
if [ -n "$search_domains" ]; then
for _search_domain in $search_domains; do
echo "Domains=${_search_domain}"
done
fi
cat <<EOT
[Route]
EOT
if [ -n "$ip6_gateway" ]; then
echo "Gateway=${ip6_gateway}"
if [ -n "$ip6_metric" ]; then
echo "Metric=${ip6_metric}"
fi
fi
if [ -n "$ip6_ula" ]; then
cat <<EOT
[Network]
Address=${ip6_ula}/64
EOT
fi
echo ""
}
gen_alias6_conf()
{
cat <<EOT
[Address]
Address=${ip6}/${ip6_prefix_length:-64}
EOT
echo ""
}
gen_ipv6_disable()
{
cat <<EOT
[Network]
LinkLocalAddressing=no
IPv6AcceptRA=no
EOT
echo ""
}
# arg: <interface>
is_networkd_iface_managed()
(
_managed=$(LANG=C networkctl list -al --no-pager --no-legend | \
awk -v dev="$1" '{if ($2 == dev) print $NF;}' | \
tr '[:upper:]' '[:lower:]')
case "${_managed}" in
''|unmanaged)
return 1
;;
esac
return 0
)
gen_network_configuration()
{
_context_interfaces=$(get_context_interfaces)
_networkd_version=$(networkctl --version | head -1 | awk '{print $2}')
if [ -n "$_networkd_version" ]; then
# put some dummy low version if not detected
_networkd_version="100"
fi
for _iface in $_context_interfaces; do
setup_iface_vars "$_iface"
skip_interface && continue
# NOTE: This is needed to workaround issue with the networkd metrics.
#
# When attaching new NIC from the same vnet on a running system then
# the networkd will assign some metric to the prefix route of the first
# NIC but leave out metric for the same prefix route of the new NIC.
#
# What happens is that outgoing packets on this subnet will now always
# use the second NIC even while the incoming packets were targeted for
# the IP on the first NIC - the result is a broken connection.
#
# This occurs at least with systemd/networkd version 248, which is on
# Cent OS 8 for example.
if [ $_networkd_version -le 250 ]; then
if is_networkd_iface_managed "${dev}" ; then
# networkctl up/down is not on ubuntu <21.04
networkctl down "$dev" 2>/dev/null || true
# this is still necessary to really unconfigure the interface
ip addr flush "$dev"
fi
fi
{
cat <<EOT
# Generated by one-context
[Match]
Name=${dev}
EOT
if [ -n "${mtu}" ]; then
cat <<EOT
[Link]
MTUBytes=${mtu}
## Supported since Debian 10, Ubuntu 18.04, CentOS 8
# [Network]
# IPv6MTUBytes=${mtu}
EOT
fi
dhcp_conf=''
case "${method}" in
''|static)
[ -n "${ip}" ] && gen_iface_conf
;;
dhcp)
dhcp_conf='ipv4'
;;
esac
case "${ip6_method}" in
''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto)
if [ -n "${dhcp_conf}" ] ; then
dhcp_conf='ipv4+auto'
else
dhcp_conf='auto'
fi
;;
dhcp)
if [ -n "${dhcp_conf}" ] ; then
dhcp_conf='both'
else
dhcp_conf='ipv6'
fi
;;
disable)
gen_ipv6_disable
;;
esac
[ -n "${dhcp_conf}" ] && gen_dhcp_conf
_aliases=$(get_interface_alias "$_iface")
for _nic_alias in $_aliases ; do
setup_ipadr_vars "$_nic_alias"
setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${detach}" ]; then
if ! is_true "${external}" ; then
[ -n "${ip}" ] && gen_alias_conf
[ -n "${ip6}" ] && gen_alias6_conf
fi
fi
done
} > "/etc/systemd/network/${dev}.network"
done
}

@ -0,0 +1,320 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
#
# network module implementation
#
export required_context_type=online
is_network_supported()
{
command -v nmcli >/dev/null
return $?
}
configure_network()
{
wait_for_nm
gen_resolvconf
gen_network_configuration
}
stop_network()
{
service NetworkManager stop
}
start_network()
{
service NetworkManager start
}
reload_network()
{
# VH-TODO: It only reloads configuration from a disk,
# but we don't directly generate configuration files
nmcli connection reload
}
#
# helper functions
#
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export ip6
export ip6_prefix_length
export ip6_ula
export mac
export dev
export mtu
export gateway
export ip6_gateway
export method
export ip6_method
export metric
export ip6_metric
export dns
export search_domains
export external
export detach
export all_nameservers
export all_search_domains
wait_for_nm()
{
nm_enable
_timeout=30
while [ "$_timeout" -gt 0 ] ; do
if _nm_networking=$(nmcli networking 2>/dev/null) ; then
break
fi
_timeout=$(( _timeout - 1 ))
sleep 1
done
if [ "${_timeout}" -eq 0 ] ; then
echo "ERROR [!]: NetworkManager is not running" >&2
exit 1
elif [ "${_nm_networking}" = 'enabled' ] ; then
return 0
else
echo "ERROR [!]: NetworkManager is disabled" >&2
exit 1
fi
}
gen_iface_conf()
{
nmcli con mod "${dev}" ipv4.method manual ipv4.addresses "${ip}/${cidr}"
if [ -n "$gateway" ]; then
nmcli con mod "${dev}" ipv4.gateway "${gateway}"
else
nmcli con mod "${dev}" ipv4.gateway ""
fi
if [ -n "$metric" ]; then
nmcli con mod "${dev}" ipv4.route-metric "${metric}"
else
# Force default Linux IPv4 metric (man 8 route) to override
# automatic metrics calculation done by NetworkManager and unify
# behavior among different renderers.
nmcli con mod "${dev}" ipv4.route-metric "0"
fi
}
reset_iface()
{
# the order is significant - ip.addresses cannot be erased while gateway is set
nmcli con mod "${dev}" ipv4.route-metric ""
nmcli con mod "${dev}" ipv4.gateway ""
nmcli con mod "${dev}" ipv4.addresses ""
}
gen_dhcp_conf()
{
nmcli con mod "${dev}" ipv4.method auto
# cleanup any leftover from the static method
reset_iface
}
gen_alias_conf()
{
nmcli con mod "${dev}" +ipv4.addresses "${ip}/${cidr}"
}
gen_iface6_conf()
{
nmcli con mod "${dev}" ipv6.method manual \
ipv6.addresses "${ip6}/${ip6_prefix_length:-64}"
if [ -n "$ip6_ula" ]; then
nmcli con mod "${dev}" +ipv6.addresses "${ip6_ula}/64"
fi
if [ -n "$ip6_gateway" ]; then
nmcli con mod "${dev}" ipv6.gateway "${ip6_gateway}"
else
nmcli con mod "${dev}" ipv6.gateway ""
fi
if [ -n "$ip6_metric" ]; then
nmcli con mod "${dev}" ipv6.route-metric "${ip6_metric}"
else
# Force default Linux IPv6 metric (man 8 route) to override
# automatic metrics calculation done by NetworkManager and unify
# behavior among different renderers.
nmcli con mod "${dev}" ipv6.route-metric "1"
fi
# We need this to ensure link-local address has expected form
nmcli con mod "${dev}" ipv6.addr-gen-mode eui64
}
reset_iface6()
{
# the order is significant - ipv6.addresses cannot be erased while gateway is set
nmcli con mod "${dev}" ipv6.route-metric ""
nmcli con mod "${dev}" ipv6.gateway ""
nmcli con mod "${dev}" ipv6.addresses ""
}
gen_alias6_conf()
{
nmcli con mod "${dev}" +ipv6.addresses "${ip6}/${ip6_prefix_length:-64}"
if [ -n "$ip6_ula" ]; then
nmcli con mod "${dev}" +ipv6.addresses "${ip6_ula}/64"
fi
}
gen_dhcp6_conf()
{
if [ "${ip6_method}" = "auto" ] ; then
# Method "ignore" relies only on SLAAC configured by the kernel,
# while the "auto" might optionally trigger also DHCPv6 client!
# https://unix.stackexchange.com/questions/440076/disable-dhcpv6-while-not-disabling-slaac-in-network-manager
_dhcp=ignore
else
# Method "auto" optionally triggers DHCPv6 client if RA has relevant
# flags (also netplan+nm configures "auto")! Method "dhcp" could
# ignore RA.
_dhcp=auto
fi
nmcli con mod "${dev}" ipv6.method "${_dhcp}"
nmcli con mod "${dev}" ipv6.addr-gen-mode eui64
nmcli con mod "${dev}" ipv6.ip6-privacy 0
# cleanup any leftover from the static method
reset_iface6
}
# arg: <interface-connection>
nm_connection_exist()
(
# VH-TODO: We should be better checking across all connections, if there
# isn't any with our device to avoid clashes and drop/rename that one
_iface=$(nmcli --field connection.interface-name con show "$1" | awk '{print $2}')
if [ "${_iface}" = "$1" ] ; then
return 0
fi
return 1
)
gen_network_configuration()
{
_context_interfaces=$(get_context_interfaces)
for _iface in $_context_interfaces; do
setup_iface_vars "$_iface"
skip_interface && continue
# We might need to disable IPv6 and privacy directly by sysctl
_disable_ipv6=''
_disable_ipv6_privacy=''
if ! nm_connection_exist "${dev}" ; then
nmcli con add type ethernet \
con-name "${dev}" ifname "${dev}" \
ipv4.method disabled \
ipv6.method ignore
fi
nmcli con mod "${dev}" connection.autoconnect yes
if [ -n "${mtu}" ]; then
nmcli con mod "${dev}" ethernet.mtu "${mtu}"
else
nmcli con mod "${dev}" ethernet.mtu ""
fi
case "${method}" in
''|static)
[ -n "${ip}" ] && gen_iface_conf
;;
dhcp)
gen_dhcp_conf
;;
esac
case "${ip6_method}" in
''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto)
gen_dhcp6_conf
# NOTE: Hot plugged NICs configured with IPv6 method ignore
# doesn't have to properly update the IPv6 privacy.
# We better enforce them via direct sysctl.
# VH-TODO: limit only for reconfigure action?
_disable_ipv6_privacy='yes'
;;
dhcp)
gen_dhcp6_conf
;;
disable)
# NOTE: Older NMs don't support ipv6.method disabled,
# in that case we rely on hard disablemenets via sysctl
nmcli con mod "${dev}" ipv6.method disabled ||
_disable_ipv6='yes'
;;
esac
_aliases=$(get_interface_alias "$_iface")
for _nic_alias in $_aliases; do
setup_ipadr_vars "$_nic_alias"
setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${detach}" ]; then
if ! is_true "${external}" ; then
[ -n "${ip}" ] && gen_alias_conf
[ -n "${ip6}" ] && gen_alias6_conf
fi
fi
done
# 'nmcli con reload' is not enough
nmcli con up "${dev}"
if [ -n "${_disable_ipv6}" ]; then
disable_ipv6 "${dev}"
fi
if [ -n "${_disable_ipv6_privacy}" ]; then
disable_ipv6_privacy "${dev}"
fi
done
}

@ -0,0 +1,393 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
#
# network module implementation
#
is_network_supported()
{
# Red Hat family
if [ -x /etc/sysconfig/network-scripts/ifup ]; then
# On EL8, the network-scripts (package) is legacy
# and network service is not even enabled by default.
# For safety we check if network service is enabled
# and if not, we better choose different renderer.
if command -v systemctl &>/dev/null; then
systemctl is-enabled network &>/dev/null && return 0
# NOTE: Probably not necessary test on old systems
elif chkconfig network --level 3 &>/dev/null || \
chkconfig network --level 5 &>/dev/null;
then
return 0
fi
# SUSE family
elif [ -d /etc/sysconfig/network/ ]; then
return 0
fi
return 1
}
configure_network()
{
gen_resolvconf
gen_network_configuration
}
stop_network()
{
service network stop
}
start_network()
{
service network start
}
reload_network()
{
service network restart
}
#
# helper functions
#
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export ip6
export ip6_prefix_length
export ip6_ula
export mac
export dev
export mtu
export gateway
export ip6_gateway
export method
export ip6_method
export metric
export ip6_metric
export dns
export search_domains
export external
export detach
export all_nameservers
export all_search_domains
gen_iface_conf()
{
cat <<EOT
NETMASK="${mask}"
IPADDR="${ip}"
EOT
### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo 'BOOTPROTO=static'
if [ -n "${gateway}" ]; then
echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" \
>> "${config_path}/ifroute-${dev}"
fi
### Red Hat family ###
else
echo 'BOOTPROTO=none'
if [ -n "${gateway}" ]; then
echo "default via ${gateway} dev ${dev} ${metric:+metric ${metric}}" \
>> "${config_path}/route-${dev}"
fi
fi
if [ -n "${mtu}" ]; then
echo "MTU=${mtu}"
fi
}
gen_dhcp_conf()
{
### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
if [ "${ip6_method}" = 'dhcp' ]; then
echo 'BOOTPROTO=dhcp'
else
echo 'BOOTPROTO=dhcp4'
fi
### Red Hat family ###
else
cat <<EOT
BOOTPROTO=dhcp
PERSISTENT_DHCLIENT=1
EOT
fi
if [ -n "${mtu}" ]; then
echo "MTU=${mtu}"
fi
}
gen_alias_conf() {
cat <<EOT
IPADDR${alias_num}="${ip}"
NETMASK${alias_num}="${mask}"
EOT
}
gen_iface6_conf()
{
### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "IPADDR_6A=${ip6}/${ip6_prefix_length:-64}"
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
net.ipv6.conf.\$SYSCTL_IF.autoconf = 0
net.ipv6.conf.\$SYSCTL_IF.accept_ra = 0
EOT
if [ -n "${mtu}" ]; then
# place only if not set via IPv4 parts
if [ -z "${_set_ipv4}" ]; then
echo "MTU=${mtu}"
fi
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
net.ipv6.conf.\$SYSCTL_IF.mtu = ${mtu}
EOT
fi
### Red Hat family ###
else
cat <<EOT
IPV6INIT=yes
IPV6ADDR=${ip6}/${ip6_prefix_length:-64}
IPV6_AUTOCONF=no
EOT
if [ -n "${mtu}" ]; then
echo "IPV6_MTU=${mtu}"
fi
fi
if [ -n "${ip6_ula}" ]; then
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "IPADDR_6B=${ip6_ula}/64"
else
ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6_ula}/64"
fi
fi
if [ -n "${ip6_gateway}" ]; then
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "default ${ip6_gateway} - ${dev} ${ip6_metric:+metric ${ip6_metric}}" \
>> "/etc/sysconfig/network/ifroute-${dev}"
else
echo "default via ${ip6_gateway} dev ${dev} ${ip6_metric:+metric ${ip6_metric}}" \
>> "${config_path}/route6-${dev}"
fi
fi
}
gen_dhcp6_conf()
{
### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
# On SUSE the BOOTPROTO is shared for both IPv4/6,
# in case IPv4 is not dhcp we configure DHCPv6 only here
# (if IPv4 is static, we unforunately overwrite that)
if [ "${ip6_method}" = 'dhcp' ] && [ "${method}" != 'dhcp' ]; then
echo 'BOOTPROTO=dhcp6'
fi
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
net.ipv6.conf.\$SYSCTL_IF.autoconf = 1
net.ipv6.conf.\$SYSCTL_IF.accept_ra = 1
net.ipv6.conf.\$SYSCTL_IF.use_tempaddr = 0
EOT
if [ -n "${mtu}" ]; then
# place only if not set via IPv4 parts
if [ -z "${_set_ipv4}" ]; then
echo "MTU=${mtu}"
fi
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
net.ipv6.conf.\$SYSCTL_IF.mtu = ${mtu}
EOT
fi
### Red Hat family ###
else
if [ "${ip6_method}" = "auto" ] ; then
cat <<EOT
IPV6INIT=yes
IPV6_AUTOCONF=yes
EOT
else
cat <<EOT
IPV6INIT=yes
IPV6_AUTOCONF=yes
DHCPV6C=yes
EOT
fi
if [ -n "${mtu}" ]; then
echo "IPV6_MTU=${mtu}"
fi
echo 'IPV6_PRIVACY=no'
fi
}
gen_alias6_conf()
{
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "IPADDR_A6A${alias_num}=${ip6}/${ip6_prefix_length:-64}"
else
ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6}/${ip6_prefix_length:-64}"
fi
if [ -n "${ip6_ula}" ]; then
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "IPADDR_A6B${alias_num}=${ip6_ula}/64"
else
ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6_ula}/64"
fi
fi
}
gen_network_configuration()
{
### Red Hat family ###
if [ -d /etc/sysconfig/network-scripts ]; then
config_path=/etc/sysconfig/network-scripts
# if disabled, enable networking via network scripts
if [ -f /etc/sysconfig/network ] &&
! grep -qx 'NETWORKING=yes' /etc/sysconfig/network;
then
sed -i -e '/^NETWORKING=/d' /etc/sysconfig/network
echo 'NETWORKING=yes' >>/etc/sysconfig/network
fi
### SUSE family ###
elif [ -d /etc/sysconfig/network ]; then
config_path=/etc/sysconfig/network
fi
_context_interfaces=$(get_context_interfaces)
for _iface in $_context_interfaces; do
setup_iface_vars "$_iface"
skip_interface && continue
# in IPv6 sections we might need to know if
# any IPv4 configuration was already placed
_set_ipv4=
# cumulative variable
ipv6addr_secondaries=''
{
rm -f "/etc/sysconfig/network-scripts/route-${dev}"
rm -f "/etc/sysconfig/network-scripts/route6-${dev}"
rm -f "/etc/sysconfig/network/ifroute-${dev}"
rm -f "/etc/sysconfig/network/ifsysctl-${dev}"
cat <<EOT
# Generated by one-context
DEVICE=${dev}
NM_CONTROLLED=no
TYPE=Ethernet
EOT
# SUSE family
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "STARTMODE=auto"
else
echo "ONBOOT=yes"
fi
case "${method}" in
''|static)
if [ -n "${ip}" ]; then
gen_iface_conf
_set_ipv4=yes
fi
;;
dhcp)
gen_dhcp_conf
_set_ipv4=yes
;;
esac
case "${ip6_method}" in
''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto|dhcp)
gen_dhcp6_conf
;;
disable)
:
;;
esac
_aliases=$(get_interface_alias "$_iface")
alias_num=0
for _nic_alias in $_aliases; do
setup_ipadr_vars "$_nic_alias"
setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${detach}" ]; then
if ! is_true "${external}" ; then
[ -n "${ip}" ] && gen_alias_conf
[ -n "${ip6}" ] && gen_alias6_conf
if [ -n "${ip}${ip6}" ]; then
alias_num=$((alias_num + 1))
fi
fi
fi
done
# on Red Hats, we need just a single configuration
# entry with all additional IPv6 addresses
if [ -n "${ipv6addr_secondaries}" ]; then
echo "IPV6ADDR_SECONDARIES='${ipv6addr_secondaries## }'"
fi
} > "${config_path}/ifcfg-${dev}"
# TODO: do we want this here?
ifup "${dev}"
done
}

@ -1,63 +0,0 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
export DNS_VARIABLES="DNS $(env | sed 's/=.*$//' | grep -E '^ETH[0-9]+_DNS$' | sort)"
export SEARCH_VARIABLES="SEARCH_DOMAIN $(env | sed 's/=.*$//' | grep -E '^ETH[0-9]+_SEARCH_DOMAIN$' | sort)"
nameservers=$(
for var in ${DNS_VARIABLES}; do
value=$(eval "echo \"\${$var}\"")
if [ -n "$value" ]; then
echo "$value"
fi
done
)
searchdomains=$(
for var in ${SEARCH_VARIABLES}; do
value=$(eval "echo \"\${$var}\"")
if [ -n "$value" ]; then
echo "$value"
fi
done
)
[ -z "$nameservers" ] && exit 0
if [ -L /etc/resolv.conf ]; then
unlink /etc/resolv.conf
else
echo -n '' > /etc/resolv.conf
fi
for nameserver in $nameservers; do
echo nameserver $nameserver >> /etc/resolv.conf
done
if [ -f /etc/sysconfig/network/config ]; then
sed -i "/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=\"$nameservers\"/" /etc/sysconfig/network/config
fi
[ -z "$searchdomains" ] && exit 0
echo search $searchdomains >> /etc/resolv.conf
if [ -f /etc/sysconfig/network/config ]; then
sed -i "/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=\"$searchdomains\"/" /etc/sysconfig/network/config
fi

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
get_management_interfaces() { get_management_interfaces() {
env | grep -E "^ETH[0-9]+_VROUTER_MANAGEMENT=YES" | sed 's/_.*$//' | tr 'ETH' 'eth' | sort env | grep -E "^ETH[0-9]+_VROUTER_MANAGEMENT=YES" | sed 's/_.*$//' | tr 'ETH' 'eth' | sort
} }
@ -81,7 +86,7 @@ gen_footer
) > /etc/iptables/rules-save ) > /etc/iptables/rules-save
if [ "$1" == "reconfigure" ]; then if [ "$2" == "reconfigure" ]; then
reload_service reload_service
else else
rc-update add iptables boot rc-update add iptables boot

@ -1,14 +1,54 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
# arg: <true|yes|false|no>
is_true()
(
_value=$(echo "$1" | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
tr '[:upper:]' '[:lower:]')
case "$_value" in
1|true|yes|y)
return 0
;;
esac
return 1
)
activate_swaps_linux() { activate_swaps_linux() {
SWAP_DRIVES=$(blkid -t TYPE="swap" -o device) SWAP_DRIVES=$(blkid -t TYPE="swap" -o device)
for SWAP in $SWAP_DRIVES ; do for SWAP in $SWAP_DRIVES ; do
if [ -z "$(swapon -s | grep $SWAP)" ]; then if [ -z "$(swapon -s | grep $SWAP)" ]; then
swapon $SWAP swapon "$SWAP"
fi fi
done done
} }
if is_true "${IGNORE_SWAP}" ; then
exit 0
fi
if [ "$(uname -s)" = 'Linux' ]; then if [ "$(uname -s)" = 'Linux' ]; then
activate_swaps_linux activate_swaps_linux
fi fi

@ -1,11 +0,0 @@
#!/usr/bin/env bash
if [ -z "${VROUTER_ID}${VROUTER_KEEPALIVED_ID}" ]; then
if [ -f /etc/sysctl.d/01-one.conf ]; then
unlink /etc/sysctl.d/01-one.conf
sysctl -w net.ipv4.ip_forward=0
fi
else
echo 'net.ipv4.ip_forward = 1' >/etc/sysctl.d/01-one.conf
sysctl -w net.ipv4.ip_forward=1
fi

@ -1,7 +1,7 @@
#!/bin/sh #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -16,21 +16,17 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
### BEGIN INIT INFO # THIS IS A CONTEXTUALIZATION GUARD
# REQUIRE: one-context-local one-context if [ "$1" != 'local' ] ; then
# PROVIDE: one-context-reconfigure-delayed exit 0
### END INIT INFO fi
. /etc/rc.subr if [ -z "${VROUTER_ID}${VROUTER_KEEPALIVED_ID}" ]; then
if [ -f /etc/sysctl.d/01-one.conf ]; then
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin unlink /etc/sysctl.d/01-one.conf
sysctl -w net.ipv4.ip_forward=0
name="one_context_reconfigure_delayed" fi
desc="OpenNebula delayed reconfiguration" else
rcvar="${name}_enable" echo 'net.ipv4.ip_forward = 1' >/etc/sysctl.d/01-one.conf
sysctl -w net.ipv4.ip_forward=1
command="/usr/sbin/one-context-run" fi
load_rc_config $name
: ${one_context_reconfigure_delayed_enable:="no"}
run_rc_command "$1"

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
get_context_interfaces() { get_context_interfaces() {
env | grep -E "^ETH[0-9]+_VROUTER_IP=" | sed 's/_.*$//' | sort env | grep -E "^ETH[0-9]+_VROUTER_IP=" | sed 's/_.*$//' | sort
} }
@ -181,7 +186,7 @@ gen_instances
) > /etc/keepalived/keepalived.conf ) > /etc/keepalived/keepalived.conf
if [ "$1" == "reconfigure" ]; then if [ "$2" == "reconfigure" ]; then
reload_service reload_service
else else
rc-update add keepalived boot rc-update add keepalived boot

@ -1,33 +1,57 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
ENV_FILE=/var/run/one-context/one_env ENV_FILE=/var/run/one-context/one_env
MOUNT_DIR=${MOUNT_DIR:-/mnt} MOUNT_DIR="${MOUNT_DIR:-/mnt}"
TOKENTXT=$(cat "${MOUNT_DIR}/token.txt") TOKEN_FILE="${MOUNT_DIR}/token.txt"
if [ -n "$ONEGATE_TOKEN" ]; then if [ -n "$ONEGATE_TOKEN" ]; then
TOKENTXT="$ONEGATE_TOKEN" TOKENTXT="$ONEGATE_TOKEN"
elif [ -f "$TOKEN_FILE" ]; then
TOKENTXT=$(cat "$TOKEN_FILE")
fi fi
umask 0377 umask 0377
echo "export TOKENTXT=\"$TOKENTXT\"" > $ENV_FILE echo "export TOKENTXT=\"$TOKENTXT\"" > "$ENV_FILE"
echo "export VMID=\"$VMID\"" >> $ENV_FILE echo "export VMID=\"$VMID\"" >> "$ENV_FILE"
echo "export ONEGATE_ENDPOINT=\"$ONEGATE_ENDPOINT\"" >> $ENV_FILE echo "export ONEGATE_ENDPOINT=\"$ONEGATE_ENDPOINT\"" >> "$ENV_FILE"
function export_rc_vars function export_rc_vars
{ {
if [ -f $1 ] ; then if [ -n "$1" ] && [ -f "$1" ] ; then
ONE_VARS=$(cat $1 | egrep -e '^[a-zA-Z\-\_0-9]*=' | sed 's/=.*$//') ONE_VARS=$(grep -E -e '^[a-zA-Z\-\_0-9]*=' "$1" | sed 's/=.*$//')
. $1 # shellcheck disable=SC1090
. "$1"
for v in $ONE_VARS; do for v in $ONE_VARS; do
echo "export $v=\"${!v}\"" >> $ENV_FILE echo "export $v=\"${!v}\"" >> "$ENV_FILE"
done done
fi fi
} }
export_rc_vars ${CONTEXT_FILE} export_rc_vars "${CONTEXT_FILE}"
chown root:root $ENV_FILE chown "root:$(id -gn root)" "$ENV_FILE"
chmod 0400 $ENV_FILE chmod 0400 "$ENV_FILE"

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
# defaults # defaults
USERNAME=${USERNAME:-root} USERNAME=${USERNAME:-root}
USERNAME_SUDO=${USERNAME_SUDO:-${GRANT_SUDO:-YES}} USERNAME_SUDO=${USERNAME_SUDO:-${GRANT_SUDO:-YES}}

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
[ -z "${SSH_PUBLIC_KEY}${EC2_PUBLIC_KEY}" ] && exit 0 [ -z "${SSH_PUBLIC_KEY}${EC2_PUBLIC_KEY}" ] && exit 0
if [ -z "${USERNAME}" ] if [ -z "${USERNAME}" ]

@ -1,6 +1,32 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
if ssh-keygen -A; then
if type restorecon >/dev/null 2>&1; then
restorecon -R -v /etc/ssh/
fi
else
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure openssh-server DEBIAN_FRONTEND=noninteractive dpkg-reconfigure openssh-server
fi fi
fi

@ -1,5 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
# Linux # Linux
for _dev_tty in $(find /dev -type c -name 'tty[0-9]*'); do for _dev_tty in $(find /dev -type c -name 'tty[0-9]*'); do
TERM=linux setterm -blank 0 -powerdown 0 >>"${_dev_tty}" TERM=linux setterm -blank 0 -powerdown 0 >>"${_dev_tty}"

@ -1,5 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
_pam_file="/etc/pam.d/login" _pam_file="/etc/pam.d/login"
if [ ! -f "${_pam_file}" ]; then if [ ! -f "${_pam_file}" ]; then
exit 0 exit 0

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,5 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
_kernel="$(uname -s)" _kernel="$(uname -s)"
if [ "${_kernel}" = 'FreeBSD' ]; then if [ "${_kernel}" = 'FreeBSD' ]; then
SED_I="sed -i ''" SED_I="sed -i ''"
@ -7,29 +23,53 @@ else
SED_I="sed -i''" SED_I="sed -i''"
fi fi
# Detects suitable running syslog service and restarts it
# to propagate the changed hostname into the logs
# (otherwise old or default value remains until reboot)
function restart_syslog() {
for _name in syslog syslogd rsyslog; do
if LANG=C systemctl is-active "${_name}" >/dev/null 2>&1; then
systemctl restart "${_name}" && return
elif service "${_name}" status >/dev/null 2>&1; then
service "${_name}" restart && return
fi
done
}
function set_hostname() { function set_hostname() {
local hostname=$1 local _hostname=$1
if [ -d /run/systemd/system/ ]; then # remember currently set hostname to detect a change
hostnamectl set-hostname --static "${hostname}" local _old_hostname
_old_hostname=$(hostname)
if [ -d /run/systemd/system/ ] && hostnamectl status >/dev/null 2>/dev/null; then
hostnamectl set-hostname --static "${_hostname}"
else else
if [ -f /etc/sysconfig/network ]; then if [ -f /etc/sysconfig/network ]; then
eval "${SED_I} '/^HOSTNAME=.*$/d' /etc/sysconfig/network" eval "${SED_I} '/^HOSTNAME=.*$/d' /etc/sysconfig/network"
echo "HOSTNAME=${hostname}" >>/etc/sysconfig/network echo "HOSTNAME=${_hostname}" >>/etc/sysconfig/network
elif [ "${_kernel}" = 'FreeBSD' ]; then elif [ "${_kernel}" = 'FreeBSD' ]; then
sysrc hostname="${hostname}" sysrc hostname="${_hostname}"
else else
echo "${hostname}" >/etc/hostname echo "${_hostname}" >/etc/hostname
fi
hostname "${_hostname}"
fi fi
hostname "${hostname}" # restart syslog if actual hostname changed
if [ "${_old_hostname}" != "$(hostname)" ]; then
restart_syslog
fi fi
} }
function set_domainname() { function set_domainname() {
domain=$1 local _domain=$1
touch /etc/resolv.conf
eval "${SED_I} -e '/^domain .*/d' /etc/resolv.conf" eval "${SED_I} -e '/^domain .*/d' /etc/resolv.conf"
echo "domain ${domain}" >>/etc/resolv.conf echo "domain ${_domain}" >>/etc/resolv.conf
} }
function get_first_ip() { function get_first_ip() {
@ -115,6 +155,10 @@ if [ -n "${name}" ]; then
domain='' domain=''
fi fi
if [ -n "${domain}" ]; then
set_domainname "${domain}"
fi
# FreeBSD # FreeBSD
if [ "${_kernel}" = 'FreeBSD' ]; then if [ "${_kernel}" = 'FreeBSD' ]; then
set_hostname "${name}" set_hostname "${name}"
@ -122,10 +166,6 @@ if [ -n "${name}" ]; then
set_hostname "${hostname}" set_hostname "${hostname}"
fi fi
if [ -n "${domain}" ]; then
set_domainname "${domain}"
fi
if [ -n "${DNS_HOSTNAME}" ]; then if [ -n "${DNS_HOSTNAME}" ]; then
host_ip=$first_ip host_ip=$first_ip
else else

@ -1,24 +1,48 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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 -e
MOUNT_DIR=${MOUNT_DIR:-/mnt} MOUNT_DIR=${MOUNT_DIR:-/mnt}
TMP_DIR=$(mktemp -d "/tmp/one-context.XXXXXX") TMP_DIR=$(mktemp -d "${TMP_DIR:-/var/lib/one-context/tmp}/one-context.XXXXXX")
TMP_FILE="${TMP_DIR}/one-start-script"
START_SCRIPT_AVAILABLE=no START_SCRIPT_AVAILABLE=no
chmod 700 "${TMP_DIR}" TMP_FILE="${TMP_DIR}/one-start-script"
cleanup()
{
rm -rf "${TMP_DIR}"
}
trap cleanup EXIT
chmod 0700 "${TMP_DIR}"
if [ -n "$START_SCRIPT_BASE64" ]; then if [ -n "${START_SCRIPT_BASE64}" ]; then
echo "${START_SCRIPT_BASE64}" | base64 -d > $TMP_FILE echo "${START_SCRIPT_BASE64}" | base64 -d > "${TMP_FILE}"
START_SCRIPT_AVAILABLE=yes START_SCRIPT_AVAILABLE=yes
elif [ -n "$START_SCRIPT" ]; then elif [ -n "${START_SCRIPT}" ]; then
echo "${START_SCRIPT}" > $TMP_FILE echo "${START_SCRIPT}" > "${TMP_FILE}"
START_SCRIPT_AVAILABLE=yes START_SCRIPT_AVAILABLE=yes
fi fi
if [ "$START_SCRIPT_AVAILABLE" = "yes" ]; then if [ "${START_SCRIPT_AVAILABLE}" = "yes" ]; then
cd $MOUNT_DIR cd "${MOUNT_DIR}"
chmod +x $TMP_FILE chmod +x "${TMP_FILE}"
$TMP_FILE "${TMP_FILE}"
fi fi
rm -rf "${TMP_DIR}"

@ -1,22 +1,55 @@
#!/usr/bin/env bash #!/usr/bin/env bash
MOUNT_DIR=${MOUNT_DIR:-/mnt} # -------------------------------------------------------------------------- #
TMP_DIR=$(mktemp -d "/tmp/one-context.XXXXXX") # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
chmod 700 "${TMP_DIR}" set -e
if [ -z "$INIT_SCRIPTS" ]; then MOUNT_DIR="${MOUNT_DIR:-/mnt}"
if [ -f "$MOUNT_DIR/init.sh" ]; then TMP_DIR=$(mktemp -d "${TMP_DIR:-/var/lib/one-context/tmp}/one-context.XXXXXX")
cleanup()
{
rm -rf "${TMP_DIR}"
}
trap cleanup EXIT
chmod 0700 "${TMP_DIR}"
if [ -z "${INIT_SCRIPTS}" ]; then
if [ -f "${MOUNT_DIR}/init.sh" ]; then
INIT_SCRIPTS=init.sh INIT_SCRIPTS=init.sh
fi fi
fi fi
cd $MOUNT_DIR cd "${MOUNT_DIR}"
_result=0
for f in $INIT_SCRIPTS; do for f in $INIT_SCRIPTS; do
cp "$f" "${TMP_DIR}/" f=$(basename "$f")
chmod +x $TMP_DIR/$f
$TMP_DIR/$f if [ -f "$f" ] ; then
cp "${f}" "${TMP_DIR}/"
chmod +x "${TMP_DIR}/${f}"
"${TMP_DIR}/${f}" || _result=$?
else
echo "ERROR: Init script does not exist: ${f}" >&2
_result=1
fi
done done
rm -rf "${TMP_DIR}" exit $_result

@ -1,6 +1,24 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
ENV_FILE=${ENV_FILE:-/var/run/one-context/one_env} ENV_FILE=${ENV_FILE:-/var/run/one-context/one_env}
RETRY_COUNT="${RETRY_COUNT:-3}"
RETRY_WAIT_PERIOD="${RETRY_WAIT_PERIOD:-10}"
if [ "$REPORT_READY" != "YES" ]; then if [ "$REPORT_READY" != "YES" ]; then
exit 0 exit 0
@ -8,39 +26,57 @@ fi
# $TOKENTXT is available only through the env. file # $TOKENTXT is available only through the env. file
if [ -f "${ENV_FILE}" ]; then if [ -f "${ENV_FILE}" ]; then
# shellcheck disable=SC1090
. "${ENV_FILE}" . "${ENV_FILE}"
fi fi
### ###
if which curl >/dev/null 2>&1; then if command -v curl ; then
_command=curl
elif command -v wget && ! wget --help 2>&1 | grep -q BusyBox; then
_command=wget
elif command -v onegate ; then
_command=onegate
else
echo "ERROR: No way to signal READY=YES (no usable binary)" >&2
exit 1
fi > /dev/null # this will not drop the error message which goes to stderr
while [ "$RETRY_COUNT" -gt 0 ] ; do
case "$_command" in
curl)
curl -X "PUT" "${ONEGATE_ENDPOINT}/vm" \ curl -X "PUT" "${ONEGATE_ENDPOINT}/vm" \
--header "X-ONEGATE-TOKEN: $TOKENTXT" \ --header "X-ONEGATE-TOKEN: $TOKENTXT" \
--header "X-ONEGATE-VMID: $VMID" \ --header "X-ONEGATE-VMID: $VMID" \
--max-time 10 \
--insecure \ --insecure \
-d "READY=YES" -d "READY=YES"
;;
if [ "$?" = "0" ]; then wget)
exit 0
fi
fi
if which wget >/dev/null 2>&1; then
wget --method=PUT "${ONEGATE_ENDPOINT}/vm" \ wget --method=PUT "${ONEGATE_ENDPOINT}/vm" \
--body-data="READY=YES" \ --body-data="READY=YES" \
--header "X-ONEGATE-TOKEN: $TOKENTXT" \ --header "X-ONEGATE-TOKEN: $TOKENTXT" \
--header "X-ONEGATE-VMID: $VMID" \ --header "X-ONEGATE-VMID: $VMID" \
--timeout=10 \
--no-check-certificate --no-check-certificate
;;
onegate)
if command -v timeout >/dev/null; then
timeout 10 onegate vm update --data "READY=YES"
else
onegate vm update --data "READY=YES"
fi
;;
esac
# shellcheck disable=SC2181
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
exit 0 exit 0
fi fi
fi
if which onegate >/dev/null 2>&1; then RETRY_COUNT=$(( RETRY_COUNT - 1 ))
onegate vm update --data "READY=YES" sleep "${RETRY_WAIT_PERIOD}"
done
if [ "$?" = "0" ]; then exit 1
exit 0
fi
fi

@ -0,0 +1,5 @@
#!/bin/sh
# Periodically run one-context-reconfigure on VMware
if [ "$(virt-what 2>/dev/null)" = 'vmware' ]; then
service one-context-reconfigure restart >/dev/null 2>&1
fi

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -18,7 +18,7 @@
### BEGIN INIT INFO ### BEGIN INIT INFO
# PROVIDE: one-context # PROVIDE: one-context
# REQUIRE: LOGIN NETWORKING # REQUIRE: LOGIN NETWORKING one-context-local
### END INIT INFO ### END INIT INFO
. /etc/rc.subr . /etc/rc.subr
@ -26,12 +26,42 @@
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
name="one_context" name="one_context"
desc="OpenNebula's context scripts" desc="OpenNebula contextualization"
rcvar="${name}_enable" rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
command="/usr/sbin/one-contextd" command="/usr/sbin/one-contextd"
command_args="network" command_args="network"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command} ${command_args}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_prestart()
{
if [ -f /var/run/one-context/context.sh.network ]; then
warn "Service started once already."
return 1
fi
}
one_context_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
load_rc_config $name load_rc_config $name
: ${one_context_enable:="yes"} : ${one_context_enable:="yes"}
run_rc_command "$1" run_rc_command "$1"

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -17,9 +17,8 @@
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
### BEGIN INIT INFO ### BEGIN INIT INFO
# REQUIRE: one-context-local one-context
# PROVIDE: one-context-force # PROVIDE: one-context-force
# Short-Description: OpenNebula forced reconfiguration # REQUIRE: one-context-local one-context
### END INIT INFO ### END INIT INFO
. /etc/rc.subr . /etc/rc.subr
@ -29,10 +28,67 @@ export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/b
name="one_context_force" name="one_context_force"
desc="OpenNebula forced reconfiguration" desc="OpenNebula forced reconfiguration"
rcvar="${name}_enable" rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
command="/usr/sbin/one-context-run" command="/usr/sbin/one-context-run"
command_args="force" command_args="force"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command} ${command_args}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_force_status()
{
_pids=$(one_context_get_pids)
if [ -z "${_pids}" ]; then
echo "${name} is not running."
return 1
else
echo "${name} is running as pids ${_pids}."
return 0
fi
}
one_context_force_prestart()
{
if ! [ -f /var/run/one-context/context.sh.local ]; then
warn "Service one-context-local must run first."
return 1
fi
if ! [ -f /var/run/one-context/context.sh.network ]; then
warn "Service one-context must run first."
return 1
fi
_pids=$(one_context_get_pids)
if [ -n "${_pids}" ]; then
warn "${name} already running? (pids=${_pids})"
return 1
fi
return 0
}
one_context_force_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
# run without any delay # run without any delay
export TIMEOUT=0 export TIMEOUT=0

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -18,7 +18,7 @@
### BEGIN INIT INFO ### BEGIN INIT INFO
# PROVIDE: one-context-local # PROVIDE: one-context-local
# REQUIRE: FILESYSTEMS # REQUIRE: FILESYSTEMS ldconfig
# BEFORE: NETWORKING hostname # BEFORE: NETWORKING hostname
### END INIT INFO ### END INIT INFO
@ -29,10 +29,40 @@ export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/b
name="one_context_local" name="one_context_local"
desc="OpenNebula pre-networking contextualization" desc="OpenNebula pre-networking contextualization"
rcvar="${name}_enable" rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
command="/usr/sbin/one-contextd" command="/usr/sbin/one-contextd"
command_args="local" command_args="local"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command} ${command_args}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_local_prestart()
{
if [ -f /var/run/one-context/context.sh.local ]; then
warn "Service started once already."
return 1
fi
}
one_context_local_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
load_rc_config $name load_rc_config $name
: ${one_context_local_enable:="yes"} : ${one_context_local_enable:="yes"}
run_rc_command "$1" run_rc_command "$1"

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -17,8 +17,8 @@
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
### BEGIN INIT INFO ### BEGIN INIT INFO
# REQUIRE: one-context-local one-context
# PROVIDE: one-context-reconfigure # PROVIDE: one-context-reconfigure
# REQUIRE: one-context-local one-context
### END INIT INFO ### END INIT INFO
. /etc/rc.subr . /etc/rc.subr
@ -28,9 +28,69 @@ export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/b
name="one_context_reconfigure" name="one_context_reconfigure"
desc="OpenNebula reconfiguration" desc="OpenNebula reconfiguration"
rcvar="${name}_enable" rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
command="/usr/sbin/one-context-run" command="/usr/sbin/one-context-run"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_reconfigure_status()
{
_pids=$(one_context_get_pids)
if [ -z "${_pids}" ]; then
echo "${name} is not running."
return 1
else
echo "${name} is running as pids ${_pids}."
return 0
fi
}
one_context_reconfigure_prestart()
{
if ! [ -f /var/run/one-context/context.sh.local ]; then
warn "Service one-context-local must run first."
return 1
fi
if ! [ -f /var/run/one-context/context.sh.network ]; then
warn "Service one-context must run first."
return 1
fi
# immediate reconfiguration terminates delayed reconfiguration
service one-context-reconfigure-delayed onestop >/dev/null 2>&1
_pids=$(one_context_get_pids)
if [ -n "${_pids}" ]; then
warn "${name} already running? (pids=${_pids})"
return 1
fi
return 0
}
one_context_reconfigure_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
# run without any delay # run without any delay
export TIMEOUT=0 export TIMEOUT=0

@ -0,0 +1,93 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
### BEGIN INIT INFO
# PROVIDE: one-context-reconfigure-delayed
# REQUIRE: one-context-local one-context
### END INIT INFO
. /etc/rc.subr
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
name="one_context_reconfigure_delayed"
desc="OpenNebula delayed reconfiguration"
rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
command="/usr/sbin/one-context-run"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_reconfigure_delayed_status()
{
_pids=$(one_context_get_pids)
if [ -z "${_pids}" ]; then
echo "${name} is not running."
return 1
else
echo "${name} is running as pids ${_pids}."
return 0
fi
}
one_context_reconfigure_delayed_prestart()
{
if ! [ -f /var/run/one-context/context.sh.local ]; then
warn "Service one-context-local must run first."
return 1
fi
if ! [ -f /var/run/one-context/context.sh.network ]; then
warn "Service one-context must run first."
return 1
fi
_pids=$(one_context_get_pids)
if [ -n "${_pids}" ]; then
warn "${name} already running? (pids=${_pids})"
return 1
fi
return 0
}
one_context_reconfigure_delayed_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
load_rc_config $name
: ${one_context_reconfigure_delayed_enable:="no"}
run_rc_command "$1"

@ -0,0 +1,3 @@
[Unit]
# https://github.com/OpenNebula/one/issues/5504
ConditionVirtualization=!container

@ -2,6 +2,7 @@
# https://github.com/OpenNebula/one/issues/4130 # https://github.com/OpenNebula/one/issues/4130
# https://github.com/OpenNebula/one/issues/4194 # https://github.com/OpenNebula/one/issues/4194
SUBSYSTEM=="net", ACTION=="remove", \ SUBSYSTEM=="net", ACTION=="remove", \
ENV{ID_BUS}=="?*", \
RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'" RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'"
# On NIC hotplug the delayed reconfiguration is triggered. # On NIC hotplug the delayed reconfiguration is triggered.
@ -11,10 +12,12 @@ SUBSYSTEM=="net", ACTION=="add", \
SUBSYSTEM=="net", ACTION=="remove", \ SUBSYSTEM=="net", ACTION=="remove", \
RUN+="/sbin/service one-context-reconfigure-delayed restart" RUN+="/sbin/service one-context-reconfigure-delayed restart"
# On CONTEXT CD-ROM change the immediate reconfiguration is triggered. # Change of CONTEXT CD-ROM triggers immediate reconfiguration,
# which stops any existing delayed reconfiguration.
SUBSYSTEM=="block", ACTION=="change", \ SUBSYSTEM=="block", ACTION=="change", \
ENV{ID_CDROM}=="1", \ ENV{ID_CDROM}=="1", \
ENV{ID_FS_TYPE}=="iso9660" ENV{ID_FS_LABEL_ENC}=="CONTEXT", \ ENV{ID_FS_TYPE}=="iso9660", \
ENV{ID_FS_LABEL_ENC}=="CONTEXT", \
RUN+="/sbin/service one-context-reconfigure restart" RUN+="/sbin/service one-context-reconfigure restart"
# Handle disk resize # Handle disk resize
@ -29,4 +32,5 @@ SUBSYSTEM=="scsi", ACTION=="change", \
# Handle swap hot-attach # Handle swap hot-attach
SUBSYSTEM=="block", ACTION=="add", \ SUBSYSTEM=="block", ACTION=="add", \
ENV{ID_FS_TYPE}=="swap", \ ENV{ID_FS_TYPE}=="swap", \
ENV{DM_ACTIVATION}!="1", \
RUN+="/sbin/service one-context-force restart" RUN+="/sbin/service one-context-force restart"

@ -2,36 +2,35 @@
# https://github.com/OpenNebula/one/issues/4130 # https://github.com/OpenNebula/one/issues/4130
# https://github.com/OpenNebula/one/issues/4194 # https://github.com/OpenNebula/one/issues/4194
SUBSYSTEM=="net", ACTION=="remove", \ SUBSYSTEM=="net", ACTION=="remove", \
ENV{ID_BUS}=="?*", \
RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'" RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'"
# On NIC hotplug the delayed reconfiguration is triggered. # On NIC hotplug the delayed reconfiguration is triggered.
SUBSYSTEM=="net", ACTION=="add", \ SUBSYSTEM=="net", ACTION=="add", \
TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service", \ RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-reconfigure-delayed.service || /usr/sbin/service one-context-reconfigure-delayed start'"
RUN+="/usr/bin/timeout 5 /usr/sbin/service one-context-reconfigure-delayed start"
SUBSYSTEM=="net", ACTION=="remove", \ SUBSYSTEM=="net", ACTION=="remove", \
TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service", \ RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-reconfigure-delayed.service || /usr/sbin/service one-context-reconfigure-delayed start'"
RUN+="/usr/bin/timeout 5 /usr/sbin/service one-context-reconfigure-delayed start"
# When CONTEXT CD-ROM is changed, it generates 2 events. This rule takes # Change of CONTEXT CD-ROM triggers immediate reconfiguration,
# every second event and triggers systemd service one-context-reconfigure. # which stops any existing delayed reconfiguration.
# This service also stops any existing delayed reconfiguration.
SUBSYSTEM=="block", ACTION=="change", \ SUBSYSTEM=="block", ACTION=="change", \
ENV{ID_CDROM}=="1", \ ENV{ID_CDROM}=="1", \
ENV{ID_FS_TYPE}=="iso9660" ENV{ID_FS_LABEL_ENC}=="CONTEXT", \ ENV{ID_FS_TYPE}=="iso9660", \
ENV{SEQNUM}=="*[02468]", \ ENV{ID_FS_LABEL_ENC}=="CONTEXT", \
RUN+="/usr/sbin/service one-context-reconfigure start" RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-reconfigure.service || /usr/sbin/service one-context-reconfigure start'"
# Handle disk resize # Handle disk resize
SUBSYSTEM=="block", ACTION=="change", \ SUBSYSTEM=="block", ACTION=="change", \
ENV{RESIZE}=="1", \ ENV{RESIZE}=="1", \
RUN+="/usr/sbin/service one-context-force start" RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-force.service || /usr/sbin/service one-context-force start'"
SUBSYSTEM=="scsi", ACTION=="change", \ SUBSYSTEM=="scsi", ACTION=="change", \
ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \ ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \
RUN+="/usr/sbin/service one-context-force start" RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-force.service || /usr/sbin/service one-context-force start'"
# Handle swap hot-attach # Handle swap hot-attach
SUBSYSTEM=="block", ACTION=="add", \ SUBSYSTEM=="block", ACTION=="add", \
ENV{ID_FS_TYPE}=="swap", \ ENV{ID_FS_TYPE}=="swap", \
RUN+="/usr/sbin/service one-context-force start" ENV{DM_ACTIVATION}!="1", \
RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-force.service || /usr/sbin/service one-context-force start'"

@ -2,6 +2,7 @@
# https://github.com/OpenNebula/one/issues/4130 # https://github.com/OpenNebula/one/issues/4130
# https://github.com/OpenNebula/one/issues/4194 # https://github.com/OpenNebula/one/issues/4194
SUBSYSTEM=="net", ACTION=="remove", \ SUBSYSTEM=="net", ACTION=="remove", \
ENV{ID_BUS}=="?*", \
RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'" RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'"
# On NIC hotplug the delayed reconfiguration is triggered. # On NIC hotplug the delayed reconfiguration is triggered.
@ -9,27 +10,27 @@ SUBSYSTEM=="net", ACTION=="add", \
TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service" TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service"
SUBSYSTEM=="net", ACTION=="remove", \ SUBSYSTEM=="net", ACTION=="remove", \
RUN+="/bin/systemctl --no-block start one-context-reconfigure-delayed.service" RUN+="/usr/bin/systemctl --no-block start one-context-reconfigure-delayed.service"
# When CONTEXT CD-ROM is changed, it generates 2 events. This rule takes # Change of CONTEXT CD-ROM triggers immediate reconfiguration,
# every second event and triggers systemd service one-context-reconfigure. # which stops any existing delayed reconfiguration.
# This service also stops any existing delayed reconfiguration.
SUBSYSTEM=="block", ACTION=="change", \ SUBSYSTEM=="block", ACTION=="change", \
ENV{ID_CDROM}=="1", \ ENV{ID_CDROM}=="1", \
ENV{ID_FS_TYPE}=="iso9660" ENV{ID_FS_LABEL_ENC}=="CONTEXT", \ ENV{ID_FS_TYPE}=="iso9660", \
ENV{SEQNUM}=="*[02468]", \ ENV{ID_FS_LABEL_ENC}=="CONTEXT", \
RUN+="/bin/systemctl --no-block start one-context-reconfigure.service" RUN+="/usr/bin/systemctl --no-block start one-context-reconfigure.service"
# Handle disk resize # Handle disk resize
SUBSYSTEM=="block", ACTION=="change", \ SUBSYSTEM=="block", ACTION=="change", \
ENV{RESIZE}=="1", \ ENV{RESIZE}=="1", \
RUN+="/bin/systemctl --no-block start one-context-force.service" RUN+="/usr/bin/systemctl --no-block start one-context-force.service"
SUBSYSTEM=="scsi", ACTION=="change", \ SUBSYSTEM=="scsi", ACTION=="change", \
ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \ ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \
RUN+="/bin/systemctl --no-block start one-context-force.service" RUN+="/usr/bin/systemctl --no-block start one-context-force.service"
# Handle swap hot-attach # Handle swap hot-attach
SUBSYSTEM=="block", ACTION=="add", \ SUBSYSTEM=="block", ACTION=="add", \
ENV{ID_FS_TYPE}=="swap", \ ENV{ID_FS_TYPE}=="swap", \
RUN+="/bin/systemctl --no-block start one-context-force.service" ENV{DM_ACTIVATION}!="1", \
RUN+="/usr/bin/systemctl --no-block start one-context-force.service"

@ -2,6 +2,7 @@
# https://github.com/OpenNebula/one/issues/4130 # https://github.com/OpenNebula/one/issues/4130
# https://github.com/OpenNebula/one/issues/4194 # https://github.com/OpenNebula/one/issues/4194
SUBSYSTEM=="net", ACTION=="remove", \ SUBSYSTEM=="net", ACTION=="remove", \
ENV{INTERFACE}=="eth*", \
RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'" RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'"
# On NIC hotplug the delayed reconfiguration is triggered. # On NIC hotplug the delayed reconfiguration is triggered.
@ -23,4 +24,5 @@ SUBSYSTEM=="scsi", ACTION=="change", \
# Handle swap hot-attach # Handle swap hot-attach
SUBSYSTEM=="block", ACTION=="add", \ SUBSYSTEM=="block", ACTION=="add", \
ENV{ID_FS_TYPE}=="swap", \ ENV{ID_FS_TYPE}=="swap", \
ENV{DM_ACTIVATION}!="1", \
RUN+="/sbin/service one-context-force start" RUN+="/sbin/service one-context-force start"

@ -1,5 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
ENV_FILE=/var/run/one-context/one_env ENV_FILE=/var/run/one-context/one_env
if [ -f $ENV_FILE ]; then if [ -f $ENV_FILE ]; then

@ -1,5 +1,21 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2022, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
require 'rubygems' require 'rubygems'
require 'uri' require 'uri'
require 'net/https' require 'net/https'
@ -13,7 +29,7 @@ require 'pp'
module CloudClient module CloudClient
# OpenNebula version # OpenNebula version
VERSION = '5.9.80' VERSION = '6.4.0'
# ######################################################################### # #########################################################################
# Default location for the authentication file # Default location for the authentication file
@ -204,6 +220,10 @@ module OneGate
DISK_RESIZE DISK_RESIZE
DISK_RESIZE_POWEROFF DISK_RESIZE_POWEROFF
DISK_RESIZE_UNDEPLOYED DISK_RESIZE_UNDEPLOYED
HOTPLUG_NIC_POWEROFF
HOTPLUG_RESIZE
HOTPLUG_SAVEAS_UNDEPLOYED
HOTPLUG_SAVEAS_STOPPED
} }
SHORT_VM_STATES={ SHORT_VM_STATES={
@ -284,7 +304,11 @@ module OneGate
"PROLOG_MIGRATE_UNKNOWN_FAILURE" => "fail", "PROLOG_MIGRATE_UNKNOWN_FAILURE" => "fail",
"DISK_RESIZE" => "drsz", "DISK_RESIZE" => "drsz",
"DISK_RESIZE_POWEROFF" => "drsz", "DISK_RESIZE_POWEROFF" => "drsz",
"DISK_RESIZE_UNDEPLOYED" => "drsz" "DISK_RESIZE_UNDEPLOYED" => "drsz",
"HOTPLUG_NIC_POWEROFF" => "hotp",
"HOTPLUG_RESIZE" => "hotp",
"HOTPLUG_SAVEAS_UNDEPLOYED" => "hotp",
"HOTPLUG_SAVEAS_STOPPED" => "hotp"
} }
def self.state_to_str(id, lcm_id) def self.state_to_str(id, lcm_id)
@ -299,9 +323,12 @@ module OneGate
return state_str return state_str
end end
def self.print(json_hash) def self.print(json_hash, extended = false)
OneGate.print_header("VM " + json_hash["VM"]["ID"]) OneGate.print_header("VM " + json_hash["VM"]["ID"])
OneGate.print_key_value("NAME", json_hash["VM"]["NAME"]) OneGate.print_key_value("NAME", json_hash["VM"]["NAME"])
return unless extended
OneGate.print_key_value( OneGate.print_key_value(
"STATE", "STATE",
self.state_to_str( self.state_to_str(
@ -328,7 +355,11 @@ module OneGate
'FAILED_DEPLOYING' => 7, 'FAILED_DEPLOYING' => 7,
'SCALING' => 8, 'SCALING' => 8,
'FAILED_SCALING' => 9, 'FAILED_SCALING' => 9,
'COOLDOWN' => 10 'COOLDOWN' => 10,
'DEPLOYING_NETS' => 11,
'UNDEPLOYING_NETS' => 12,
'FAILED_DEPLOYING_NETS' => 13,
'FAILED_UNDEPLOYING_NETS' => 14
} }
STATE_STR = [ STATE_STR = [
@ -342,7 +373,11 @@ module OneGate
'FAILED_DEPLOYING', 'FAILED_DEPLOYING',
'SCALING', 'SCALING',
'FAILED_SCALING', 'FAILED_SCALING',
'COOLDOWN' 'COOLDOWN',
'DEPLOYING_NETS',
'UNDEPLOYING_NETS',
'FAILED_DEPLOYING_NETS',
'FAILED_UNDEPLOYING_NETS'
] ]
# Returns the string representation of the service state # Returns the string representation of the service state
@ -352,7 +387,7 @@ module OneGate
return STATE_STR[state_number.to_i] return STATE_STR[state_number.to_i]
end end
def self.print(json_hash) def self.print(json_hash, extended = false)
OneGate.print_header("SERVICE " + json_hash["SERVICE"]["id"]) OneGate.print_header("SERVICE " + json_hash["SERVICE"]["id"])
OneGate.print_key_value("NAME", json_hash["SERVICE"]["name"]) OneGate.print_key_value("NAME", json_hash["SERVICE"]["name"])
OneGate.print_key_value("STATE", Service.state_str(json_hash["SERVICE"]['state'])) OneGate.print_key_value("STATE", Service.state_str(json_hash["SERVICE"]['state']))
@ -364,7 +399,7 @@ module OneGate
if role["nodes"] if role["nodes"]
role["nodes"].each{ |node| role["nodes"].each{ |node|
OneGate::VirtualMachine.print(node["vm_info"]) OneGate::VirtualMachine.print(node["vm_info"], extended)
} }
end end
@ -373,6 +408,35 @@ module OneGate
end end
end end
# Virtual Router module
module VirtualRouter
def self.print(json_hash, _extended = false)
OneGate.print_header('VROUTER ' + json_hash['VROUTER']['ID'])
OneGate.print_key_value('NAME', json_hash['VROUTER']['NAME'])
vms_ids = Array(json_hash['VROUTER']['VMS']['ID'])
vms = vms_ids.join(',')
OneGate.print_key_value('VMS', vms)
puts
end
end
# Virtual Network module
module VirtualNetwork
def self.print(json_hash, _extended = false)
OneGate.print_header('VNET')
OneGate.print_key_value('ID', json_hash['VNET']['ID'])
puts
end
end
class Client class Client
def initialize(opts={}) def initialize(opts={})
@vmid = ENV["VMID"] @vmid = ENV["VMID"]
@ -394,8 +458,9 @@ module OneGate
end end
end end
def get(path) def get(path, extra = nil)
req = Net::HTTP::Proxy(@host, @port)::Get.new(path) req = Net::HTTP::Proxy(@host, @port)::Get.new(path)
req.body = extra if extra
do_request(req) do_request(req)
end end
@ -451,8 +516,8 @@ module OneGate
def self.parse_json(response) def self.parse_json(response)
if CloudClient::is_error?(response) if CloudClient::is_error?(response)
puts "ERROR: " STDERR.puts 'ERROR: '
puts response.message STDERR.puts response.message
exit -1 exit -1
else else
return JSON.parse(response.body) return JSON.parse(response.body)
@ -496,7 +561,7 @@ module OneGate
Available commands Available commands
$ onegate vm show [VMID] [--json] $ onegate vm show [VMID] [--json]
$ onegate vm update [VMID] --data KEY=VALUE[\\nKEY2=VALUE2] $ onegate vm update [VMID] --data KEY=VALUE\\nKEY2=VALUE2
$ onegate vm update [VMID] --erase KEY $ onegate vm update [VMID] --erase KEY
@ -512,9 +577,13 @@ Available commands
$ onegate hold [VMID] $ onegate hold [VMID]
$ onegate release [VMID] $ onegate release [VMID]
$ onegate service show [--json] $ onegate service show [--json][--extended]
$ onegate service scale --role ROLE --cardinality CARDINALITY $ onegate service scale --role ROLE --cardinality CARDINALITY
$ onegate vrouter show [--json]
$ onegate vnet show VNETID [--json][--extended]
EOT EOT
end end
end end
@ -545,12 +614,16 @@ OptionParser.new do |opts|
options[:json] = json options[:json] = json
end end
opts.on("", "--extended", "Print resource extended information") do |ext|
options[:extended] = ext
end
opts.on("-f", "--hard", "Hard option for power off operations") do |hard| opts.on("-f", "--hard", "Hard option for power off operations") do |hard|
options[:hard] = hard options[:hard] = hard
end end
opts.on("-h", "--help", "Show this message") do opts.on("-h", "--help", "Show this message") do
puts OneGate.help_str STDERR.puts OneGate.help_str
exit exit
end end
end.parse! end.parse!
@ -575,7 +648,7 @@ when "vm"
end end
when "update" when "update"
if !options[:data] && !options[:erase] if !options[:data] && !options[:erase]
puts "You have to provide the data as a param (--data, --erase)" STDERR.puts 'You have to provide the data as a param (--data, --erase)'
exit -1 exit -1
end end
@ -592,8 +665,8 @@ when "vm"
end end
if CloudClient::is_error?(response) if CloudClient::is_error?(response)
puts "ERROR: " STDERR.puts 'ERROR: '
puts response.message STDERR.puts response.message
exit -1 exit -1
end end
when "resume", when "resume",
@ -608,7 +681,7 @@ when "vm"
"release", "release",
# Compatibility with 4.x # Compatibility with 4.x
"delete", "delete",
"shutdown", "shutdown"
if ARGV[2] if ARGV[2]
action_hash = { action_hash = {
"action" => { "action" => {
@ -623,31 +696,42 @@ when "vm"
response = client.post("/vms/"+ARGV[2]+"/action", action_hash.to_json) response = client.post("/vms/"+ARGV[2]+"/action", action_hash.to_json)
if CloudClient::is_error?(response) if CloudClient::is_error?(response)
puts "ERROR: " STDERR.puts 'ERROR: '
puts response.message STDERR.puts response.message
exit -1 exit -1
end end
else else
puts "You have to provide a VM ID" STDERR.puts 'You have to provide a VM ID'
exit -1 exit -1
end end
else else
puts OneGate.help_str STDERR.puts OneGate.help_str
puts STDERR.puts
puts "Action #{ARGV[1]} not supported" STDERR.puts "Action #{ARGV[1]} not supported"
exit -1 exit -1
end end
when "service" when "service"
case ARGV[1] case ARGV[1]
when "show" when "show"
response = client.get("/service") if options[:extended]
extra = {}
extra['extended'] = true
extra = URI.encode_www_form(extra)
end
response = client.get("/service", extra)
json_hash = OneGate.parse_json(response) json_hash = OneGate.parse_json(response)
#pp json_hash #pp json_hash
if options[:json] if options[:json]
puts JSON.pretty_generate(json_hash) puts JSON.pretty_generate(json_hash)
else
if options[:extended]
OneGate::Service.print(json_hash, true)
else else
OneGate::Service.print(json_hash) OneGate::Service.print(json_hash)
end end
end
when "scale" when "scale"
response = client.put( response = client.put(
"/service/role/" + options[:role], "/service/role/" + options[:role],
@ -656,18 +740,79 @@ when "service"
}.to_json) }.to_json)
if CloudClient::is_error?(response) if CloudClient::is_error?(response)
puts "ERROR: " STDERR.puts 'ERROR: '
puts response.message STDERR.puts response.message
exit -1 exit -1
end end
else else
puts OneGate.help_str STDERR.puts OneGate.help_str
puts STDERR.puts
puts "Action #{ARGV[1]} not supported" STDERR.puts "Action #{ARGV[1]} not supported"
exit -1
end
when 'vrouter'
case ARGV[1]
when 'show'
if options[:extended]
extra = {}
extra['extended'] = true
extra = URI.encode_www_form(extra)
end
response = client.get('/vrouter', extra)
json_hash = OneGate.parse_json(response)
if options[:json]
puts JSON.pretty_generate(json_hash)
else
if options[:extended]
OneGate::VirtualRouter.print(json_hash, true)
else
OneGate::VirtualRouter.print(json_hash)
end
end
else
STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit(-1)
end
when 'vnet'
case ARGV[1]
when 'show'
if ARGV[2]
if options[:extended]
extra = {}
extra['extended'] = true
extra = URI.encode_www_form(extra)
end
response = client.get('/vnet/'+ARGV[2], extra)
json_hash = OneGate.parse_json(response)
if options[:json]
puts JSON.pretty_generate(json_hash)
else
if options[:extended]
OneGate::VirtualNetwork.print(json_hash, true)
else
OneGate::VirtualNetwork.print(json_hash)
end
end
else
STDERR.puts 'You have to provide a VNET ID'
exit -1 exit -1
end end
else else
puts OneGate.help_str STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit(-1)
end
else
STDERR.puts OneGate.help_str
exit -1 exit -1
end end

@ -4,6 +4,7 @@ After=one-context.service
Requisite=one-context.service Requisite=one-context.service
ConditionPathExists=/var/run/one-context/context.sh.local ConditionPathExists=/var/run/one-context/context.sh.local
ConditionPathExists=/var/run/one-context/context.sh.network ConditionPathExists=/var/run/one-context/context.sh.network
StartLimitInterval=0
[Service] [Service]
Type=oneshot Type=oneshot

@ -1,8 +1,8 @@
[Unit] [Unit]
Description=OpenNebula pre-networking contextualization script Description=OpenNebula pre-networking contextualization
DefaultDependencies=no DefaultDependencies=no
Before=network-pre.target
Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target
Before=network-pre.target
After=local-fs.target systemd-udev-settle.service syslog.target After=local-fs.target systemd-udev-settle.service syslog.target
ConditionPathExists=!/var/run/one-context/context.sh.local ConditionPathExists=!/var/run/one-context/context.sh.local

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=OpenNebula pre-networking contextualization script Description=OpenNebula pre-networking contextualization
Before=network-pre.target
Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target
Before=network-pre.target
After=local-fs.target systemd-udev-settle.service syslog.target After=local-fs.target systemd-udev-settle.service syslog.target
ConditionPathExists=!/var/run/one-context/context.sh.local ConditionPathExists=!/var/run/one-context/context.sh.local

@ -0,0 +1,17 @@
[Unit]
Description=OpenNebula early-networking contextualization
Requires=one-context-local.service
After=one-context-local.service
After=NetworkManager.service systemd-networkd.service
Wants=network.target
Before=network.target
Before=NetworkManager-wait-online.service systemd-networkd-wait-online.service
ConditionPathExists=!/var/run/one-context/context.sh.online
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/one-contextd online
[Install]
WantedBy=multi-user.target

@ -1,8 +1,9 @@
[Unit] [Unit]
Description=OpenNebula delayed reconfiguration script Description=OpenNebula delayed reconfiguration
After=one-context.service After=one-context.service
Requisite=one-context.service Requisite=one-context.service
ConditionPathExists=/var/run/one-context/context.sh.network ConditionPathExists=/var/run/one-context/context.sh.network
StartLimitInterval=0
[Service] [Service]
Type=forking Type=forking

@ -1,9 +1,10 @@
[Unit] [Unit]
Description=OpenNebula reconfiguration script Description=OpenNebula reconfiguration
After=one-context.service After=one-context.service
Requisite=one-context.service Requisite=one-context.service
Conflicts=one-context-reconfigure-delayed.service Conflicts=one-context-reconfigure-delayed.service
ConditionPathExists=/var/run/one-context/context.sh.network ConditionPathExists=/var/run/one-context/context.sh.network
StartLimitInterval=0
[Service] [Service]
Type=oneshot Type=oneshot

@ -0,0 +1,11 @@
[Unit]
Description=Periodic OpenNebula reconfiguration
After=one-context.service
ConditionVirtualization=vmware
[Timer]
OnCalendar=*-*-* *:*:0
AccuracySec=1s
[Install]
WantedBy=timers.target

@ -1,5 +1,5 @@
[Unit] [Unit]
Description=OpenNebula contextualization script Description=OpenNebula contextualization
Requires=network.target Requires=network.target
After=multi-user.target After=multi-user.target
ConditionPathExists=!/var/run/one-context/context.sh.local ConditionPathExists=!/var/run/one-context/context.sh.local

@ -1,7 +1,9 @@
[Unit] [Unit]
Description=OpenNebula contextualization script Description=OpenNebula contextualization
Requires=one-context-local.service Requires=one-context-local.service one-context-online.service
After=multi-user.target one-context-local.service After=multi-user.target one-context-local.service one-context-online.service
Wants=network-online.target
After=network-online.target
ConditionPathExists=!/var/run/one-context/context.sh.network ConditionPathExists=!/var/run/one-context/context.sh.network
[Service] [Service]

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# # # #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -19,7 +19,7 @@
# Set PATH # Set PATH
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
TIMEOUT=${TIMEOUT:-60} TIMEOUT=${TIMEOUT:-30}
COMMAND=${1:-reconfigure} COMMAND=${1:-reconfigure}
CONTEXT_BASE=${CONTEXT_BASE:-/var/run/one-context/context.sh} CONTEXT_BASE=${CONTEXT_BASE:-/var/run/one-context/context.sh}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save