├── .github ├── dco.yml └── workflows │ └── shellcheck.yml ├── .gitignore ├── LICENSE ├── README.md └── minione /.github/dco.yml: -------------------------------------------------------------------------------- 1 | require: 2 | members: false 3 | -------------------------------------------------------------------------------- /.github/workflows/shellcheck.yml: -------------------------------------------------------------------------------- 1 | name: 'ShellCheck' 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | shellcheck: 7 | name: Shellcheck 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Run ShellCheck 12 | uses: ludeeus/action-shellcheck@master 13 | env: 14 | SHELLCHECK_OPTS: -e SC2317 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *pyc 2 | docs/build 3 | docs/source/toc.html 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # miniONE 2 | 3 | **miniONE** is an easy to use deployment tool to build an evaluation OpenNebula cloud based on virtual machines (KVM). All necessary components to manage and run the virtual machines are installed and configured on your dedicated system with just a single command run. 4 | 5 | **Follow the detailed [tutorial](https://docs.opennebula.io/stable/quick_start/deployment_basics/overview.html)**. 6 | 7 | ## Requirements 8 | You’ll need a server (physical or virtual) to try out OpenNebula. The provided Host should have a fresh default installation of the required operating system with the latest updates and without any customizations. 9 | 10 | - 4 GiB RAM 11 | - 20 GiB free space on disk 12 | - privileged user access (root) 13 | - openssh-server package installed 14 | - **operating system**: AlmaLinux 8 or 9, Debian 11, Ubuntu 22.04 or 24.04 15 | - open ports: 22 (SSH), 80 (Sunstone), 2616 (FireEdge) 16 | 17 | ## Quickstart 18 | 19 | Download the [latest release](https://github.com/OpenNebula/minione/releases/latest) of the **miniONE** tool, run it and follow the instructions on the terminal. 20 | 21 | ### Get Frontend Only 22 | 23 | Run the following commands to deploy only the OpenNebula frontend: 24 | 25 | ``` 26 | wget 'https://github.com/OpenNebula/minione/releases/latest/download/minione' 27 | sudo bash minione --frontend 28 | ``` 29 | 30 | For frontend only installation either a virtual machine or bare-metal host could be used. Afterwards, you can follow this [tutorial](https://docs.opennebula.io/stable/quick_start/deployment_basics/overview.html) to deploy edge clusters on-premises or on-cloud. 31 | 32 | ### Get Frontend and KVM Node Cloud 33 | 34 | Run the following commands to deploy an evaluation cloud with a front-end and a single KVM node: 35 | 36 | ``` 37 | wget 'https://github.com/OpenNebula/minione/releases/latest/download/minione' 38 | sudo bash minione 39 | ``` 40 | 41 | This option is suitable for bare-metal hosts to utilize HW virtualization, however the deployment will fallback to emulation (QEMU) if running on virtual machine or CPU without the virt. capabilities. 42 | 43 | ## License 44 | 45 | Copyright 2002-2023, OpenNebula Systems (formerly C12G Labs) 46 | 47 | Licensed under the Apache License, Version 2.0 (the "License"); you may 48 | not use this file except in compliance with the License. You may obtain 49 | a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 50 | 51 | Unless required by applicable law or agreed to in writing, software 52 | distributed under the License is distributed on an "AS IS" BASIS, 53 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 54 | See the License for the specific language governing permissions and 55 | limitations under the License. 56 | -------------------------------------------------------------------------------- /minione: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2024, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # default parameters values 20 | VERSION='6.10' 21 | EE='no' 22 | FORCE='no' 23 | VERBOSE='no' 24 | ASK='yes' 25 | PASSWORD=$(tr /dev/null) 118 | LIBVIRTD='libvirtd' 119 | ONE_WAIT_TIMEOUT=60 120 | IMAGE_WAIT_TIMEOUT=300 121 | STAR_NET='' 122 | AUGEAS_PKG='augeas-tools' 123 | PIP='pip3' 124 | PYTHON_PIP='python3-pip' 125 | REPO_BASE='' 126 | HAVE_CURL=false 127 | HAVE_WGET=false 128 | INSTALL_TERRAFORM=false 129 | TERRAFORM_URL='https://releases.hashicorp.com/terraform/1.6.3/terraform_1.6.3_linux_amd64.zip' 130 | ETH0_IP='' 131 | PUBLIC_IP='' 132 | ONE_SERVICES=(opennebula opennebula-fireedge opennebula-flow opennebula-gate) 133 | ONE_FE_PKGS=(opennebula opennebula-common opennebula-common-onecfg 134 | opennebula-flow opennebula-fireedge opennebula-gate 135 | opennebula-libs opennebula-rubygems opennebula-tools opennebula-guacd) 136 | NODE_KVM_PKG='opennebula-node-kvm' 137 | REPO_KEY='repo2.key' 138 | SSHD_SERVICE='sshd' 139 | 140 | while true; do 141 | case "$1" in 142 | -v | --verbose) 143 | VERBOSE="yes" 144 | shift 145 | ;; 146 | -f | --force) 147 | FORCE="yes" 148 | shift 149 | ;; 150 | --help) 151 | usage 152 | exit 0 153 | ;; 154 | --yes) 155 | ASK="no" 156 | shift 157 | ;; 158 | --frontend) 159 | NODE="no" 160 | NETWORKING="no" 161 | shift 162 | ;; 163 | --enterprise) 164 | EE='yes' 165 | EE_TOKEN="$2" 166 | shift 2 167 | ;; 168 | --version) 169 | VERSION="$2" 170 | VERSION_GIVEN="yes" 171 | shift 2 172 | ;; 173 | --ssh-pubkey) 174 | SSH_PUBKEY="$2" 175 | shift 2 176 | ;; 177 | --password) 178 | PASSWORD="$2" 179 | shift 2 180 | ;; 181 | --bridge-interface) 182 | BRIDGE_INTERFACE="$2" 183 | shift 2 184 | ;; 185 | --nat-interface) 186 | NAT_INTERFACE="$2" 187 | shift 2 188 | ;; 189 | --vnet-address) 190 | VNET_ADDRESS="$2" 191 | shift 2 192 | ;; 193 | --vnet-netmask) 194 | VNET_NETMASK="$2" 195 | shift 2 196 | ;; 197 | --vnet-gateway) 198 | VNET_GATEWAY="$2" 199 | shift 2 200 | ;; 201 | --vnet-ar-ip-start) 202 | VNET_AR_IP_START="$2" 203 | shift 2 204 | ;; 205 | --vnet-ar-ip-count) 206 | VNET_AR_IP_COUNT="$2" 207 | shift 2 208 | ;; 209 | --marketapp-name) 210 | MARKET_APP_NAME="$2" 211 | shift 2 212 | ;; 213 | --vm-password) 214 | VM_PASSWORD="$2" 215 | shift 2 216 | ;; 217 | --lxc) 218 | LXC="yes" 219 | MARKET_APP_NAME="alpine_edge - LXD" 220 | shift 221 | ;; 222 | --sunstone-port) 223 | SUNSTONE_PORT="$2" 224 | shift 2 225 | ;; 226 | --purge) 227 | PURGE="yes" 228 | shift 229 | ;; 230 | --preserve-user) 231 | DELETE_ONEADMIN="no" 232 | shift 233 | ;; 234 | --repo-base) 235 | REPO_BASE="$2" 236 | shift 2 237 | ;; 238 | --) 239 | shift 240 | break 241 | ;; 242 | *) 243 | usage 244 | exit 1 245 | ;; 246 | esac 247 | done 248 | 249 | # Don't ask if there is no TTY on stdin 250 | [[ ! -t 0 ]] && ASK='no' 251 | 252 | # 172.16.0.0 ~> 172.16.*.*, but 10.0.1.0~> 10.0.1.* 253 | STAR_NET=${VNET_ADDRESS} 254 | for I in 1 2 3 4; do 255 | # shellcheck disable=SC2001 256 | STAR_NET=$(echo "${STAR_NET}" | sed -e 's/\(.*\)\.0\([0\.\*]*\)$/\1.*\2/') 257 | done 258 | 259 | # compare version strings 260 | verlte() { 261 | [[ $1. =~ ^v*([0-9][0-9]*\.){1,3}$ ]] || return 1 262 | [[ $2. =~ ^v*([0-9][0-9]*\.){1,3}$ ]] || return 1 263 | 264 | [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] 265 | } 266 | 267 | #------------------------------------------------------------------------------- 268 | # Options validation 269 | #------------------------------------------------------------------------------- 270 | 271 | if [[ $EE == yes ]]; then 272 | REPO_URL="https://${EE_TOKEN}@enterprise.opennebula.io/repo" 273 | fi 274 | 275 | if [[ -z "$REPO_BASE" ]]; then 276 | REPO_BASE="$REPO_URL"/"$VERSION" 277 | else 278 | VERSION=$(echo "$REPO_BASE" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?') 279 | fi 280 | 281 | #------------------------------------------------------------------------------- 282 | # Helpers and detection functions 283 | #------------------------------------------------------------------------------- 284 | 285 | title() { 286 | echo "" 287 | echo "### $*" 288 | } 289 | 290 | interface_exists() { 291 | local DEV=$1 292 | ip link show dev "$DEV" >/dev/null 293 | } 294 | 295 | get_interface_name() { 296 | DEV=$(ip route | grep default | head -1 | awk '{print $5}' 2>/dev/null) 297 | if [[ -z "${DEV}" ]]; then 298 | DEV=$(ip addr | grep '^[0-9]' | awk -F": " '{print $2}' | head -2 | tail -1 2>/dev/null) 299 | fi 300 | echo "$DEV" 301 | } 302 | 303 | get_my_ip() { 304 | DEV=$(get_interface_name) 305 | IP=$(ip addr show dev "${DEV}" | grep inet | head -1 | awk '{print $2}') 306 | echo "${IP//\/[0-9]*/}" 307 | } 308 | 309 | get_public_ip() { 310 | dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null 311 | } 312 | 313 | get_distname_and_version() { 314 | local DIST 315 | local VER 316 | 317 | if type -t lsb_release >/dev/null; then 318 | DIST=$(lsb_release -si 2>/dev/null) 319 | VER=$(lsb_release -sr 2>/dev/null) 320 | elif [ -f /etc/redhat-release ]; then 321 | DIST=$(cut -d ' ' -f1 "${STDERR_TMP_FILE}" >"${STDOUT_TMP_FILE}" 393 | RC=$? 394 | if [ $RC -gt 0 ]; then 395 | [[ "$ON_FAIL" = "" && $TRIES -gt 1 ]] && echo -ne "retry $I " 396 | sleep 1 397 | fi 398 | I=$((I + 1)) 399 | done 400 | 401 | STDERR=$(cat "$STDERR_TMP_FILE") 402 | STDOUT=$(cat "$STDOUT_TMP_FILE") 403 | unlink "${STDERR_TMP_FILE}" 404 | unlink "${STDOUT_TMP_FILE}" 405 | 406 | if [[ ${RC} = '0' ]]; then 407 | [[ ${VERBOSE} = 'yes' ]] && green "OK" 408 | return ${RC} 409 | else 410 | [[ ${VERBOSE} = 'no' ]] && echo -ne "${TEXT} " 411 | if [[ "$ON_FAIL" =~ "SKIP" ]]; then 412 | orange "${ON_FAIL}" 413 | return ${RC} 414 | elif [[ ${FORCE} = 'no' && -n "${ON_FAIL}" ]]; then 415 | red "FAILED" 416 | if [[ -n "${HINT}" ]]; then 417 | echo "${HINT}" 418 | else 419 | echo 'Consider running with "--force" to override' 420 | fi 421 | exit 1 422 | elif [[ ${FORCE} = 'yes' && "${ON_FAIL}" =~ "IGNORE" ]]; then 423 | orange "${ON_FAIL}" 424 | return ${RC} 425 | else 426 | red "FAILED" 427 | if [[ -n "${ON_FAIL}" && ! "${ON_FAIL}" =~ "IGNORE" ]]; then 428 | echo "${ON_FAIL}" 429 | fi 430 | echo "${STDOUT}" 431 | if [[ -n "${STDERR}" ]]; then 432 | echo "--- STDERR ---" 433 | echo "${STDERR}" 434 | echo "--------------" 435 | fi 436 | exit 1 437 | fi 438 | fi 439 | } 440 | 441 | fail() { 442 | echo -ne "$1 " 443 | red "FAILED" 444 | exit 1 445 | } 446 | 447 | run_and_print_if_failed() { 448 | $1 >/dev/null 449 | 450 | local RC=$? 451 | local MSG=$* 452 | 453 | [ ! "$RC" -eq 0 ] && echo "$MSG" 454 | 455 | return "$RC" 456 | } 457 | 458 | centos() { 459 | [[ "$DISTNAME" =~ CentOS|RedHat|AlmaLinux ]] 460 | } 461 | 462 | redhat() { 463 | [[ "$DISTNAME" =~ RedHat ]] 464 | } 465 | 466 | debian() { 467 | [[ "$DISTNAME" =~ Ubuntu|Debian ]] 468 | } 469 | 470 | firewalld_running() { 471 | systemctl -q is-active firewalld 472 | } 473 | 474 | netplan_on() { 475 | [ ! -s /run/network/ifstate ] && type -t netplan >/dev/null 476 | } 477 | 478 | node() { 479 | [[ $NODE == yes ]] 480 | } 481 | 482 | aws() { 483 | # try detect AWS instance by seeing 'Server: EC2ws' in headers 484 | curl --connect-timeout 1 http://169.254.169.254 -v 2>&1 | grep -q EC2 485 | } 486 | 487 | kvm() { 488 | [[ $NODE == yes && $LXC == no ]] 489 | } 490 | 491 | lxc() { 492 | [[ $NODE == yes && $LXC == yes ]] 493 | } 494 | 495 | networking() { 496 | [[ $NETWORKING == yes ]] 497 | } 498 | 499 | supported_dist_ver() { 500 | local DIST_VER_MATCH=$1 501 | 502 | if [[ ! "${DISTNAME}${DISTVER} ${VERSION}" =~ $DIST_VER_MATCH ]]; then 503 | echo "\"${DISTNAME}${DISTVER} ${VERSION}\" not in ${DIST_VER_MATCH:2:-2}" >&2 504 | return 2 505 | fi 506 | } 507 | 508 | repo_exists() { 509 | if [[ ! "$DISTNAME" =~ AlmaLinux|CentOS|RedHat|Ubuntu|Debian ]]; then 510 | echo "Currently only CentOS, RedHat, AlmaLinux, Ubuntu or Debian are supported" >&2 511 | return 1 512 | else 513 | URL="${REPO_BASE}/${DISTNAME}/${DISTVER}" 514 | if type -t curl >/dev/null; then 515 | HAVE_CURL=true 516 | run_and_print_if_failed "curl -f -s -S $URL" 517 | elif type -t wget >/dev/null; then 518 | HAVE_WGET=true 519 | wget "$URL" 520 | else 521 | echo "Missing curl/wget to check repository" >&2 522 | return 2 523 | fi 524 | fi 525 | } 526 | 527 | disk_free() { 528 | local LIMIT=$1 529 | local WHERE=$2 530 | 531 | read -r AVAIL TARGET <<<"$(df -BG --output=avail,target "$WHERE" | tail -1)" 532 | AVAIL=${AVAIL%G} 533 | 534 | if [[ "${AVAIL}" -lt "${LIMIT}" ]]; then 535 | echo "Insufficient disk space, expected at least ${LIMIT}G on" \ 536 | "\"${TARGET}\" filesystem" 537 | return 1 538 | fi 539 | } 540 | 541 | #------------------------------------------------------------------------------- 542 | # Install functions 543 | #------------------------------------------------------------------------------- 544 | 545 | disable_selinux() { 546 | setenforce 0 >/dev/null || return 1 547 | sed -ie 's/^SELINUX=.*$/SELINUX=permissive/' /etc/selinux/config >/dev/null 2>&1 548 | } 549 | 550 | modify_apparmor() { 551 | if ! grep '/var/lib/one/datastores' /etc/apparmor.d/abstractions/libvirt-qemu >/dev/null 2>&1; then 552 | echo ' /var/lib/one/datastores/** rwk,' >>/etc/apparmor.d/abstractions/libvirt-qemu 553 | systemctl reload apparmor 554 | else 555 | if [[ "$1" = 'purge' ]]; then 556 | sed -i '/\/var\/lib\/one\/datastores/d' /etc/apparmor.d/abstractions/libvirt-qemu >/dev/null 2>&1 557 | fi 558 | fi 559 | } 560 | 561 | install_pkg() { 562 | if centos; then 563 | run_and_print_if_failed "yum -y install $*" 564 | elif debian; then 565 | export DEBIAN_FRONTEND=noninteractive 566 | run_and_print_if_failed "apt-get -q -y install $*" 567 | RC=$? 568 | unset DEBIAN_FRONTEND 569 | return "$RC" 570 | fi 571 | } 572 | 573 | create_bridge() { 574 | if centos && [[ $DISTVER -le 8 ]]; then 575 | if [[ $1 = purge ]]; then 576 | rm -f /etc/sysconfig/network-scripts/ifcfg-minionebr 577 | ip link set down dev "${BRIDGE_INTERFACE}" || true 578 | ip link del "${BRIDGE_INTERFACE}" || true 579 | else 580 | cat >/etc/sysconfig/network-scripts/ifcfg-minionebr </etc/systemd/network/minionebr-nic.netdev </etc/netplan/minione.yaml </dev/null 641 | cat >/etc/network/interfaces.d/tap.cfg </etc/network/interfaces.d/minionebr.cfg <>"$FILE" 663 | fi 664 | fi 665 | fi 666 | fi 667 | } 668 | 669 | ifup_bridge() { 670 | if netplan_on; then 671 | netplan apply 672 | else 673 | debian && ifup tap0 674 | 675 | if type -t ifup >/dev/null; then 676 | ifup "${BRIDGE_INTERFACE}" 677 | else 678 | true # not needed when NM is used 679 | fi 680 | fi 681 | } 682 | 683 | disable_invalid_net_cfg() { 684 | # This is mainly to hack-around packet vanila Centos images 685 | # containig ifcfg- file for non-existing device 686 | 687 | cd /etc/sysconfig/network-scripts || return 1 688 | ip link >/dev/null || return 1 689 | CHANGED='' 690 | for FILE in ifcfg-*; do 691 | # skip interfaces disabled "on boot" 692 | if grep -q -i '^ONBOOT=["'\'']no' "$FILE"; then 693 | continue 694 | fi 695 | 696 | # get interface name from configuration or filename 697 | IFACE=$(awk -F= 'toupper($1) ~ /(DEVICE|NAME)/ { gsub("['\''\"]", "", $2); print $2; exit }' "${FILE}") 698 | IFACE=${IFACE:-${FILE##ifcfg-}} 699 | # if interface does not exist, disable configuration 700 | if ! ip link show "${IFACE}" >/dev/null 2>&1; then 701 | CHANGED=yes 702 | mv "${FILE}" disabled-"${FILE}" 703 | fi 704 | done 705 | if [ -n "${CHANGED}" ] && systemctl is-failed network.service >/dev/null 2>&1; then 706 | ifdown ifcfg-* || : 707 | systemctl restart network.service || return 1 708 | fi 709 | 710 | cd - || : 711 | } 712 | 713 | disable_firewalld() { 714 | systemctl stop firewalld >/dev/null && 715 | systemctl disable firewalld >/dev/null 716 | } 717 | 718 | configure_nat() { 719 | ACTION='-A' 720 | [[ $1 = 'purge' ]] && ACTION='-D' 721 | 722 | IPTABLES_COMMAND=$( 723 | cat </dev/null 743 | cat </etc/dnsmasq.conf || return 1 744 | interface=${BRIDGE_INTERFACE},lo 745 | bind-interfaces 746 | EOT 747 | systemctl start dnsmasq 748 | systemctl enable dnsmasq 749 | fi 750 | } 751 | 752 | configure_repos() { 753 | if centos; then 754 | if [[ $1 = 'purge' ]]; then 755 | rm -f /etc/yum.repos.d/opennebula.repo 756 | else 757 | cat </etc/yum.repos.d/opennebula.repo 758 | [opennebula] 759 | name=opennebula 760 | baseurl=${REPO_BASE}/${DISTNAME}/${DISTVER}/$(arch) 761 | enabled=1 762 | gpgkey=https://downloads.opennebula.io/repo/${REPO_KEY} 763 | gpgcheck=1 764 | EOT 765 | fi 766 | elif debian; then 767 | if [[ $1 = 'purge' ]]; then 768 | rm -f /etc/apt/sources.list.d/opennebula.list 769 | else 770 | # Check if /etc/apt/keyrings directory exists, if not, create it 771 | if [ ! -d /etc/apt/keyrings ]; then 772 | install -m 0755 -d /etc/apt/keyrings 773 | fi 774 | 775 | (wget -q -O- https://downloads.opennebula.io/repo/"${REPO_KEY}" | 776 | gpg --dearmor --yes --output /etc/apt/keyrings/opennebula.gpg) || return 1 777 | echo "deb [signed-by=/etc/apt/keyrings/opennebula.gpg] ${REPO_BASE}/${DISTNAME}/${DISTVER} stable opennebula" \ 778 | >/etc/apt/sources.list.d/opennebula.list || return 1 779 | fi 780 | fi 781 | } 782 | 783 | enable_epel() { 784 | if redhat; then 785 | dnf install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${DISTVER}.noarch.rpm" 786 | elif centos; then 787 | if [[ "${DISTNAME}" =~ AlmaLinux ]] && [[ "${DISTVER}" -ge 9 ]]; then 788 | dnf config-manager --set-enabled crb || return 1 789 | fi 790 | 791 | install_pkg "epel-release" 792 | fi 793 | } 794 | 795 | install_opennebula_pkgs() { 796 | install_pkg "${ONE_FE_PKGS[@]}" || return 1 797 | systemctl daemon-reload 798 | } 799 | 800 | install_opennebula_kvm_pkgs() { 801 | install_pkg "$NODE_KVM_PKG" || return 1 802 | } 803 | 804 | install_opennebula_lxc_pkgs() { 805 | install_pkg opennebula-node-lxc || return 1 806 | } 807 | 808 | uninstall_opennebula_pkgs() { 809 | if centos; then 810 | yum --quiet -y remove "$NODE_KVM_PKG" "${ONE_FE_PKGS[@]}" 811 | systemctl restart "${LIBVIRTD}" || true 812 | 813 | if redhat; then 814 | yum --quiet -y remove qemu-kvm-rhev || true 815 | else 816 | yum --quiet -y remove qemu-kvm-ev >/dev/null || true 817 | fi 818 | elif debian; then 819 | apt-get purge -q -y "${ONE_FE_PKGS[@]}" >/dev/null 820 | apt-get purge -q -y "$NODE_KVM_PKG" >/dev/null 821 | systemctl restart "${LIBVIRTD}" || true 822 | dpkg-statoverride --remove /var/lib/one || true 823 | fi 824 | } 825 | 826 | detect_installed_version() { 827 | if centos; then 828 | if RPM_STR=$(rpm -q opennebula 2>/dev/null); then 829 | VERSION=$(echo "$RPM_STR" | awk -F- '{print $3}' | cut -d. -f1,2) 830 | else 831 | return 1 832 | fi 833 | else 834 | 835 | if DEB_STR=$(dpkg -s opennebula 2>/dev/null | grep '^Version:'); then 836 | VERSION=$(echo "$DEB_STR" | awk '{print $2}' | cut -d. -f1,2) 837 | else 838 | return 1 839 | fi 840 | fi 841 | } 842 | 843 | gen_ssh_key() { 844 | local KEY=${1:-$HOME/.ssh/id_rsa} 845 | 846 | mkdir -p "$(dirname "$KEY")" 847 | chmod 0700 "$(dirname "$KEY")" 848 | if [ ! -f "$KEY" ]; then 849 | ssh-keygen -t rsa -P "" -f "$KEY" >/dev/null 850 | fi 851 | } 852 | 853 | install_terraform() { 854 | curl --retry 3 -s -o /tmp/terraform.zip "$TERRAFORM_URL" || return 1 855 | unzip /tmp/terraform.zip -d /usr/bin || return 1 856 | rm /tmp/terraform.zip 857 | } 858 | 859 | # Initialize some usefull vars 860 | NETMASK_BITS=$(mask2cidr "${VNET_NETMASK}") 861 | read -r DISTNAME DISTVER <<<"$(get_distname_and_version)" 862 | 863 | centos && AUGEAS_PKG='augeas' 864 | 865 | if [[ "$PURGE" = "yes" ]] && [[ "$VERSION_GIVEN" != "yes" ]]; then 866 | check "detect_installed_version" "Detecting ONE installed version" 1 \ 867 | "SKIP Will try to uninstall default $VERSION" 868 | fi 869 | 870 | PUBLIC_IP=$(get_public_ip) 871 | ETH0_IP=$(get_my_ip) 872 | 873 | # FRONTEND + KVM NODE 874 | if node; then 875 | ONEGATE_ENDPOINT=$VNET_GATEWAY 876 | ONEGATE_SERVER=$VNET_GATEWAY 877 | REPORT_IP=$ETH0_IP 878 | 879 | # FRONTEND + PREPARE FIREEDGE, ONEPROVISION 880 | else 881 | ONEGATE_ENDPOINT=${PUBLIC_IP:-$ETH0_IP} 882 | ONEGATE_SERVER=$ETH0_IP 883 | REPORT_IP=${PUBLIC_IP:-$ETH0_IP} 884 | fi 885 | 886 | # On AWS always report PUBLIC_IP, if exists 887 | if aws; then 888 | REPORT_IP=${PUBLIC_IP:-$ETH0_IP} 889 | fi 890 | 891 | lxc && MARKET_APP_NAME='alpine' 892 | 893 | if [[ "${DISTNAME}${DISTVER}" == Ubuntu24.04 ]]; then 894 | SSHD_SERVICE='ssh' 895 | fi 896 | 897 | #------------------------------------------------------------------------------- 898 | # Uninstall 899 | #------------------------------------------------------------------------------- 900 | 901 | purge() { 902 | echo "Really uninstall? [yes/no]:" 903 | [[ "${ASK}" = 'yes' ]] && yes_no 904 | FORCE='yes' 905 | 906 | title "Uninstalling" 907 | check "systemctl stop opennebula" "Stopping OpenNebula" 1 "SKIP" 908 | [[ "${ENABLED_APPARMOR}" = 'yes' ]] && check "modify_apparmor" "Restoring AppArmor" 909 | check "uninstall_opennebula_pkgs" "Uninstalling OpenNebula packages" 1 "SKIP" 910 | check "start_dnsmasq purge" "Stopping DNSMasq" 1 "SKIP" 911 | check "configure_repos purge" "Unconfiguring repositories" 912 | check "configure_nat purge" "Unconfiguring NAT using iptables" 1 "SKIP" 913 | check "create_bridge purge" "Deleting bridge interface ${BRIDGE_INTERFACE}" 914 | check "rm -rf /etc/one $HOME/.one >/dev/null" "Deleting /etc/one" 915 | check "rm -rf /var/log/one >/dev/null" "Deleting /var/log/one" 916 | 917 | if [[ "${DELETE_ONEADMIN}" = 'yes' ]]; then 918 | check "userdel -r -f oneadmin>/dev/null" "Deleting oneadmin user" 1 "SKIP" 919 | check "rm -rf /var/lib/one >/dev/null" "Deleting /var/lib/one" 920 | fi 921 | } 922 | 923 | if [[ $PURGE = 'yes' ]]; then 924 | VERBOSE='yes' 925 | purge 926 | exit 0 927 | fi 928 | 929 | clean() { 930 | [[ -d /var/lib/one/.one ]] && check \ 931 | 'rm -rf /var/lib/one/.one.old; mv /var/lib/one/.one /var/lib/one/.one.old' \ 932 | 'Move old oneadmin auth-dir away' 933 | 934 | [[ -f /var/lib/one/one.db ]] && check \ 935 | 'mv /var/lib/one/one.db /var/lib/one/one.db.old' \ 936 | "Move old db away" 937 | } 938 | 939 | #------------------------------------------------------------------------------- 940 | # Checks & detection 941 | #------------------------------------------------------------------------------- 942 | 943 | title "Checks & detection" 944 | 945 | # check Opennebula veriosn & distribution & version 946 | check "supported_dist_ver \"$SUPPORTED_MAP\"" \ 947 | "Checking distribution and version [${DISTNAME} ${DISTVER} ${VERSION}]" \ 948 | 1 "IGNORED Will try to install if repository exists" 949 | 950 | # check if repository exists 951 | check "repo_exists" "Checking if OpenNebula repository exists" 3 952 | 953 | # check cpu flgas for virtualizaton capabilities 954 | node && { 955 | check 'grep flags /proc/cpuinfo | grep vmx\\\|svm > /dev/null' \ 956 | "Checking cpu virtualization capabilities" 1 \ 957 | "SKIP QEMU will be used" || LOCALHOST_VM_MAD='qemu' 958 | } 959 | 960 | check "type -t augtool >/dev/null" "Checking augeas is installed" 1 \ 961 | "SKIP will try to install" || MISSING_PKGS="${MISSING_PKGS} $AUGEAS_PKG" 962 | 963 | check "type -t curl >/dev/null" "Checking curl is installed" 1 \ 964 | "SKIP will try to install" || MISSING_PKGS="${MISSING_PKGS} curl" 965 | 966 | debian && { 967 | check "type -t add-apt-repository >/dev/null" "Checking add-apt-repository is available" 1 \ 968 | "SKIP will try to install" || MISSING_PKGS="${MISSING_PKGS} software-properties-common" 969 | } 970 | 971 | # check available disk space on /var 972 | check 'disk_free 20 /var' 'Checking free disk space' 1 'IGNORE' 973 | 974 | # check existing directories from previous installation 975 | check "[[ ! -e /etc/one && ! -e /var/lib/one ]]" \ 976 | "Checking directories from previous installation" 1 \ 977 | "IGNORED will be cleaned" || CLEAN='yes' 978 | 979 | # check existing user from previous installation 980 | check "! id oneadmin >/dev/null" \ 981 | "Checking user from previous installation" 1 "IGNORE" 982 | 983 | # check if sshd service is running 984 | check "systemctl status -n0 ${SSHD_SERVICE} >/dev/null" \ 985 | "Checking ${SSHD_SERVICE} service is running" 986 | 987 | # check if we have networking tools 988 | networking && { 989 | check "type -t iptables >/dev/null" "Checking iptables are installed" 1 \ 990 | "SKIP will try to install" || MISSING_PKGS="${MISSING_PKGS} iptables" 991 | 992 | if [[ "${DISTNAME}${DISTVER}" =~ CentOS8|RedHat8 ]]; then 993 | check "rpm -q network-scripts >/dev/null" "Checking network-scripts are installed" 1 \ 994 | "SKIP will try to install" || MISSING_PKGS="${MISSING_PKGS} network-scripts" 995 | fi 996 | } 997 | 998 | debian && { 999 | # check if we have apt-transport-https 1000 | check "dpkg -L apt-transport-https >/dev/null 2>&1" \ 1001 | "Checking apt-transport-https is installed" 1 \ 1002 | "SKIP will try to install" || 1003 | MISSING_PKGS="${MISSING_PKGS} apt-transport-https" 1004 | 1005 | # check if gnupg is installed 1006 | check "dpkg -L gnupg >/dev/null 2>&1" \ 1007 | "Checking if gnupg is installed" 1 \ 1008 | "SKIP will try to install" || 1009 | MISSING_PKGS="${MISSING_PKGS} gnupg" 1010 | 1011 | # check if ca-certificates is up-to-date 1012 | check "[[ -z \"$(apt list --upgradable 2>&1 | grep ca-certificates)\" ]]" \ 1013 | "Checking if ca-certificates is up-to-date" 1 \ 1014 | "SKIP will try to update" || 1015 | MISSING_PKGS="${MISSING_PKGS} ca-certificates" 1016 | } 1017 | 1018 | # Check SELinux or AppArmor 1019 | SELINUX=$(getenforce 2>/dev/null) 1020 | centos && { check "[[ ! \"${SELINUX}\" = 'Enforcing' ]]" \ 1021 | "Checking SELinux" 1 "SKIP will try to disable" || DISABLE_SELINUX='yes'; } 1022 | debian && { check "! aa-status >/dev/null 2>&1" \ 1023 | "Checking AppArmor" 1 "SKIP will try to modify" || ENABLED_APPARMOR='yes'; } 1024 | 1025 | # check for given ssh key 1026 | if [[ -n "${SSH_PUBKEY}" ]]; then 1027 | check "[[ -f \"${SSH_PUBKEY}\" ]]" \ 1028 | "Checking ssh pub key ${SSH_PUBKEY} exists" 1029 | # or take the first founc, or generate 1030 | else 1031 | SSH_PUBKEY=$(get_first_ssh_key) 1032 | if ! check "[[ -f \"${SSH_PUBKEY}\" ]]" "Checking for present ssh key" 1 \ 1033 | "SKIP"; then 1034 | check "gen_ssh_key" "Generating ssh keypair in $HOME/.ssh/id_rsa" 1035 | SSH_PUBKEY="$HOME/.ssh/id_rsa.pub" 1036 | fi 1037 | fi 1038 | 1039 | if [[ "${DISTNAME}${DISTVER}" = "RedHat8" ]]; then 1040 | check "verlte 1.8.5 $(rpm -q --qf '%{VERSION}' libgcrypt)" \ 1041 | "Checking libgcrypt version" 1 \ 1042 | "SKIP will try to update" || 1043 | MISSING_PKGS="${MISSING_PKGS} libgcrypt" 1044 | fi 1045 | 1046 | networking && { 1047 | # check if given interface exists 1048 | if [[ -n "${NAT_INTERFACE}" ]]; then 1049 | check "interface_exists ${NAT_INTERFACE}" \ 1050 | "Checking [${NAT_INTERFACE}] net device exists" 1051 | else 1052 | NAT_INTERFACE=$(get_interface_name) 1053 | check "[[ -n \"${NAT_INTERFACE}\" ]]" \ 1054 | "Checking local interface [${NAT_INTERFACE}]" 1055 | fi 1056 | 1057 | # check if we have iptables-persistent and netfilter-persistent 1058 | if debian; then 1059 | check "type -t iptables-persistent > /dev/null" \ 1060 | "Checking iptables-persistent is installed" 1 \ 1061 | "SKIP will try to install" || 1062 | MISSING_PKGS="${MISSING_PKGS} iptables-persistent" 1063 | check "type -t netfilter-persistent > /dev/null" \ 1064 | "Checking netfilter-persistent is installed" 1 \ 1065 | "SKIP will try to install" || 1066 | MISSING_PKGS="${MISSING_PKGS} netfilter-persistent" 1067 | fi 1068 | 1069 | #check if birdge iface is not already present 1070 | check "! interface_exists ${BRIDGE_INTERFACE}" \ 1071 | "Checking $BRIDGE_INTERFACE interface is not present" 1 "IGNORED" 1072 | 1073 | # check if given virtual network is already in routing table 1074 | check "! ip route show ${VNET_ADDRESS}/${NETMASK_BITS} | grep dev >/dev/null" \ 1075 | "Checking virtual network ${VNET_ADDRESS}/${NETMASK_BITS} is not routed" 1076 | } 1077 | 1078 | # check if the requested app name exists on market place 1079 | if kvm; then 1080 | if $HAVE_CURL; then 1081 | check "curl -s -H \"${JSON_HEADERS}\" ${APPS_URL} \ 1082 | | grep '\"name\":\"${MARKET_APP_NAME}\"' >/dev/null" \ 1083 | "Checking presence of the market app: \"$MARKET_APP_NAME\"" 3 "Not found" 1084 | elif $HAVE_WGET; then 1085 | check "wget --quiet -O - --header \"${JSON_HEADERS}\" ${APPS_URL} \ 1086 | | grep '\"name\":\"${MARKET_APP_NAME}\"' >/dev/null" \ 1087 | "Checking presence of the market app: \"$MARKET_APP_NAME\"" 3 "Not found" 1088 | else 1089 | # Always fail, but continue with info when --force was given 1090 | check "false" "Missing curl/wget to check market app" 1 "IGNORE Can't check" 1091 | fi 1092 | fi 1093 | 1094 | # Install newer then system ansible using PIP for some distros or for <=6.8 1095 | if [[ "${DISTNAME}${DISTVER}" =~ Ubuntu2204|Debian10 ]] || verlte "$VERSION" 6.8; then 1096 | check "type -t $PIP >/dev/null" "Checking ${PYTHON_PIP} is installed" 1 \ 1097 | "SKIP will try to install" || MISSING_PKGS="${MISSING_PKGS} ${PYTHON_PIP}" 1098 | if type -t ansible >/dev/null; then 1099 | ANSIBLE_VERSION=$(ansible --version | head -1 | tr -cd '[:digit:]' | cut -c 1-3) 1100 | check "[ $ANSIBLE_VERSION -ge 215 ]" "Checking ansible version (2.15+)" 1 \ 1101 | "SKIP will try to install" || MISSING_PIP_PKGS="'ansible==8.7.0'" 1102 | else 1103 | check "false" "Checking ansible" 1 "SKIP will try to install" || MISSING_PIP_PKGS="'ansible==8.7.0'" 1104 | fi 1105 | fi 1106 | 1107 | if type -t terraform >/dev/null; then 1108 | TERRAFORM_VERSION=$(terraform --version | head -1 | cut -d ' ' -f 2) 1109 | check "verlte v0.13.6 $TERRAFORM_VERSION" \ 1110 | "Checking terrafrom version (>= v0.13.6)" 1111 | else 1112 | check "false" "Checking terraform" 1 "SKIP will try to install" 1113 | INSTALL_TERRAFORM=true 1114 | 1115 | check "type -t unzip >/dev/null" "Checking unzip is installed" 1 \ 1116 | "SKIP will try to install" || MISSING_PKGS="${MISSING_PKGS} unzip" 1117 | fi 1118 | 1119 | #------------------------------------------------------------------------------- 1120 | # Pre-installation report 1121 | #------------------------------------------------------------------------------- 1122 | 1123 | title "Main deployment steps:" 1124 | echo "Install OpenNebula frontend version ${VERSION}" 1125 | 1126 | $INSTALL_TERRAFORM && echo "Install Terraform" 1127 | 1128 | node && { 1129 | centos && firewalld_running && echo "Disable_firewalld" 1130 | echo "Configure bridge ${BRIDGE_INTERFACE} with IP ${VNET_GATEWAY}/${NETMASK_BITS}" 1131 | echo "Enable NAT over ${NAT_INTERFACE}" 1132 | [[ "${ENABLED_APPARMOR}" = yes ]] && echo "Modify AppArmor" 1133 | kvm && echo "Install OpenNebula KVM node" 1134 | lxc && echo "Install OpenNebula LXC node" 1135 | echo "Export appliance and update VM template" 1136 | } 1137 | 1138 | [[ "${CLEAN}" = yes ]] && echo "Clean oneadmin home" 1139 | [[ "${DISABLE_SELINUX}" = yes ]] && echo "Disable SELinux" 1140 | [[ -n "${MISSING_PKGS}" ]] && echo "Install ${MISSING_PKGS}" 1141 | [[ -n "${MISSING_PIP_PKGS}" ]] && echo "Install pip ${MISSING_PIP_PKGS}" 1142 | 1143 | echo "" 1144 | echo "Do you agree? [yes/no]:" 1145 | [[ "${ASK}" = 'yes' ]] && yes_no 1146 | 1147 | #------------------------------------------------------------------------------- 1148 | # Installation 1149 | #------------------------------------------------------------------------------- 1150 | 1151 | title "Installation" 1152 | VERBOSE='yes' 1153 | 1154 | [[ "${CLEAN}" = yes ]] && clean 1155 | debian && check "apt-get -q -y update >/dev/null" "Updating APT cache" 1156 | [[ "${DISABLE_SELINUX}" = 'yes' ]] && check "disable_selinux" "Disabling SELinux" 1157 | [[ -n "${MISSING_PKGS}" ]] && check "install_pkg ${MISSING_PKGS}" "Install ${MISSING_PKGS}" 3 1158 | if [[ -n "${MISSING_PIP_PKGS}" ]]; then 1159 | # it's evaluation tool, we can do ugly things 1160 | export PIP_BREAK_SYSTEM_PACKAGES=1 1161 | check "$PIP install --upgrade pip || true" "Updating PIP" 1162 | check "$PIP install ${MISSING_PIP_PKGS}" \ 1163 | "Install from PyPI ${MISSING_PIP_PKGS}" 3 1164 | fi 1165 | 1166 | centos && firewalld_running && check "disable_firewalld" "Disabling firewalld" 1167 | 1168 | networking && { 1169 | centos && check "disable_invalid_net_cfg" "Rename invalid network configs" 1170 | check "create_bridge" "Creating bridge interface ${BRIDGE_INTERFACE}" 1171 | check "ifup_bridge" "Bring bridge interfaces up" 1172 | [[ "$FORWARD" = 0 ]] && { 1173 | check "sysctl -w net.ipv4.ip_forward=1 >/dev/null" "Enabling IPv4 forward" 1174 | check "grep -q \"^net.ipv4.ip_forward=1$\" /etc/sysctl.conf || \ 1175 | echo \"net.ipv4.ip_forward=1\" >> /etc/sysctl.conf" "Persisting IPv4 forward" 1176 | } 1177 | check "configure_nat" "Configuring NAT using iptables" 1178 | centos && check "iptables-save > /etc/sysconfig/iptables" "Saving iptables changes" 1179 | debian && check "netfilter-persistent save" "Saving iptables changes" 1180 | check "install_pkg dnsmasq" "Installing DNSMasq" 3 1181 | check "start_dnsmasq" "Starting DNSMasq" 1182 | } 1183 | 1184 | check "configure_repos" "Configuring repositories" 1185 | 1186 | debian && check "apt-get -q -y update >/dev/null" "Updating APT cache" 1187 | 1188 | centos && check "enable_epel" "Installing EPEL" 1189 | check "install_opennebula_pkgs" "Installing OpenNebula packages" 3 1190 | $INSTALL_TERRAFORM && check "install_terraform" "Installing TerraForm" 1191 | 1192 | if kvm; then 1193 | check "install_opennebula_kvm_pkgs" "Installing OpenNebula kvm node packages" 3 1194 | 1195 | [[ "${ENABLED_APPARMOR}" = 'yes' ]] && check "modify_apparmor" "Updating AppArmor" 1196 | 1197 | check "rm -f /etc/libvirt/qemu/networks/autostart/default.xml" \ 1198 | "Disable default libvirtd networking" 1199 | 1200 | check "systemctl restart ${LIBVIRTD}" "Restart libvirtd" 1201 | elif lxc; then 1202 | check "install_opennebula_lxc_pkgs" "Installing OpenNebula lxc node packages" 3 1203 | fi 1204 | 1205 | #------------------------------------------------------------------------------- 1206 | # Configuration functions 1207 | #------------------------------------------------------------------------------- 1208 | 1209 | sed_subst() { 1210 | local KEY=$1 1211 | local VALUE=$2 1212 | 1213 | if [ -z "$3" ]; then 1214 | local CONF='/etc/one/oned.conf' 1215 | else 1216 | local CONF=$3 1217 | fi 1218 | sed -i -e "s/^${KEY}/${VALUE}/" "${CONF}" >/dev/null 1219 | } 1220 | 1221 | aug_set() { 1222 | local KEY="$1" 1223 | local VALUE="$2" 1224 | local CONF="${3:-/etc/one/oned.conf}" 1225 | 1226 | [ ! -f /usr/share/augeas/lenses/oned.aug ] && { 1227 | echo "Missing oned.aug" >&2 1228 | return 1 1229 | } 1230 | 1231 | augtool -s set "/files$CONF/$KEY" "'$VALUE'" >/dev/null 1232 | } 1233 | 1234 | set_init_password() { 1235 | [[ ! -d $HOME/.one ]] && { mkdir "$HOME"/.one || return 1; } 1236 | echo "oneadmin:$PASSWORD" >"$HOME"/.one/one_auth || return 1 1237 | echo "oneadmin:$PASSWORD" >/var/lib/one/.one/one_auth 1238 | } 1239 | 1240 | set_fireedge_port() { 1241 | local FIREEDGE_PORT="$1" 1242 | sed_subst "port:.*" "port: ${FIREEDGE_PORT}" /etc/one/fireedge-server.conf 1243 | } 1244 | 1245 | one_is_ready() { 1246 | for I in $(seq "$ONE_WAIT_TIMEOUT"); do 1247 | onehost list >/dev/null 2>&1 && return 0 1248 | sleep 1 1249 | done 1250 | echo "OpenNebula did not start within the timeout" >&2 1251 | return 1 1252 | } 1253 | 1254 | deny_ssh_from_vnet() { 1255 | if grep -v "DenyUsers ${STAR_NET}" /etc/ssh/sshd_config >/dev/null; then 1256 | echo "" >>/etc/ssh/sshd_config 1257 | echo "DenyUsers ${STAR_NET}" >>/etc/ssh/sshd_config 1258 | fi 1259 | systemctl restart "${SSHD_SERVICE}" 1260 | } 1261 | 1262 | add_keys_to_known_hosts() { 1263 | su oneadmin -c 'ssh-keyscan localhost > ~/.ssh/known_hosts' || return 1 1264 | HOSTNAME=$(hostname) 1265 | su oneadmin -c "ssh-keyscan ${HOSTNAME} >> ~/.ssh/known_hosts" || return 1 1266 | FQDN=$(hostname -f 2>/dev/null) 1267 | if [[ -n "$FQDN" && "$HOSTNAME" != "${FQDN}" ]]; then 1268 | su oneadmin -c "ssh-keyscan ${FQDN} >> ~/.ssh/known_hosts" || return 1 1269 | fi 1270 | } 1271 | 1272 | test_ssh_connection() { 1273 | sudo -u oneadmin ssh localhost true /dev/null || return 1 1274 | } 1275 | 1276 | add_ssh_keys_to_oneadmin() { 1277 | local TMP_FILE 1278 | TMP_FILE=$(mktemp) || return 1 1279 | 1280 | # put current template to the tempfile 1281 | oneuser show 0 | 1282 | sed '/USER TEMPLATE/,/VMS USAGE/!d;//d' >"${TMP_FILE}" 1283 | 1284 | ONEADMIN_OS_USER_KEY=$(cat /var/lib/one/.ssh/id*pub 2>/dev/null) 1285 | SSH_PUBKEY_CONTENT=$(cat "${SSH_PUBKEY}" 2>/dev/null) 1286 | 1287 | cat >>"${TMP_FILE}" <>/var/lib/one/.ssh/config <>~/.ssh/config </dev/null; then 1332 | return 0 1333 | fi 1334 | 1335 | if [ ! -f /usr/share/augeas/lenses/oned.aug ]; then 1336 | echo "Missing oned.aug" >&2 1337 | return 1 1338 | fi 1339 | 1340 | MATCH=$(augtool match '/files/etc/hosts/*/ipaddr' "$IP") 1341 | 1342 | if [ -n "$MATCH" ]; then 1343 | # IP already in /etc/hosts 1344 | augtool -s set "/files/etc/hosts/*[ipaddr=\"$IP\"]/alias[.=\"$HOSTNAME\"] \"$HOSTNAME\"" 1345 | else 1346 | # IP not in /etc/hosts yet 1347 | LAST=$(augtool ls '/files/etc/hosts' | tail -1 | awk -F/ '{print $1}') 1348 | LAST=$((LAST + 1)) 1349 | AUG_CMD=$(mktemp) 1350 | echo "set /files/etc/hosts/$LAST/ipaddr \"$IP\"" >"$AUG_CMD" 1351 | echo "set /files/etc/hosts/$LAST/canonical \"$HOSTNAME\"" >>"$AUG_CMD" 1352 | augtool -s -f "$AUG_CMD" 1353 | rm "$AUG_CMD" 1354 | fi 1355 | set +e 1356 | } 1357 | 1358 | update_network_hooks() { 1359 | for VN_MAD in 802.1Q bridge dummy ebtables fw ovswitch ovswitch_vxlan vxlan; do 1360 | cp /var/lib/one/remotes/vnm/hooks/pre/firecracker /var/lib/one/remotes/vnm/"${VN_MAD}"/pre.d/firecracker 1361 | cp /var/lib/one/remotes/vnm/hooks/clean/firecracker /var/lib/one/remotes/vnm/"${VN_MAD}"/clean.d/firecracker 1362 | chown oneadmin:oneadmin /var/lib/one/remotes/vnm/"${VN_MAD}"/pre.d/firecracker 1363 | chown oneadmin:oneadmin /var/lib/one/remotes/vnm/"${VN_MAD}"/clean.d/firecracker 1364 | done 1365 | } 1366 | 1367 | #------------------------------------------------------------------------------- 1368 | # Configuration 1369 | #------------------------------------------------------------------------------- 1370 | title "Configuration" 1371 | 1372 | if verlte "$VERSION" 6.8.99; then 1373 | check "update_network_hooks" "Update network hooks" 1374 | fi 1375 | 1376 | check "aug_set ONEGATE_ENDPOINT '\"http://${ONEGATE_ENDPOINT}:5030\"'" \ 1377 | "Switching OneGate endpoint in oned.conf" 1378 | 1379 | check "sed_subst \":host: .*\" \":host: ${ONEGATE_SERVER}\" \"/etc/one/onegate-server.conf\"" \ 1380 | "Switching OneGate endpoint in onegate-server.conf" 1381 | 1382 | check "sed_subst \":keep_empty_bridge: .*\" \":keep_empty_bridge: true\" \"/var/lib/one/remotes/etc/vnm/OpenNebulaNetwork.conf\"" \ 1383 | "Switching keep_empty_bridge on in OpenNebulaNetwork.conf" 1384 | 1385 | 1386 | # new scheduler in 6.99+ 1387 | if verlte "$VERSION" 6.10.99; then 1388 | check "aug_set SCHED_INTERVAL 10 /etc/one/sched.conf" \ 1389 | "Switching scheduler interval in sched.conf" 1390 | else 1391 | check "aug_set SCHED_RETRY_TIME 10 /etc/one/oned.conf" \ 1392 | "Switching scheduler interval in oned.conf" 1393 | fi 1394 | 1395 | check "set_init_password" "Setting initial password for current user and oneadmin" 1396 | 1397 | check "aug_set DEFAULT_CDROM_DEVICE_PREFIX '\"sd\"'" \ 1398 | "Switching DEFAULT_CDROM_DEVICE_PREFIX in oned.conf" 1399 | 1400 | [[ ${SUNSTONE_PORT} != 2616 ]] && check "set_fireedge_port ${SUNSTONE_PORT}" "Switching FireEdge port" 1401 | 1402 | check "systemctl start ${ONE_SERVICES[*]}" "Starting OpenNebula services" 1403 | check "systemctl enable ${ONE_SERVICES[*]}" "Enabling OpenNebula services" 1404 | check "add_ssh_keys_to_oneadmin" "Add ssh key to oneadmin user" 1405 | check "update_ssh_configs" "Update ssh configs to allow VM addresses reusing" 1406 | check "ensure_hostname_resolvable" "Ensure own hostname is resolvable" 1407 | 1408 | check "one_is_ready" "Checking OpenNebula is working" 1409 | 1410 | networking && { 1411 | check "deny_ssh_from_vnet" "Disabling ssh from virtual network" 1412 | check "add_keys_to_known_hosts" "Adding localhost ssh key to known_hosts" 1413 | check "test_ssh_connection" "Testing ssh connection to localhost" 1414 | } 1415 | 1416 | #------------------------------------------------------------------------------- 1417 | # Bootstrap functions 1418 | #------------------------------------------------------------------------------- 1419 | onecli_cmd_tmpl() { 1420 | local COMMAND=$1 1421 | local DATA=$2 1422 | local TMP_FILE 1423 | TMP_FILE=$(mktemp) || return 1 1424 | 1425 | cat >"${TMP_FILE}" < 1441 | $MAD 1442 | FILE 1443 | 1444 | EOF 1445 | ) 1446 | 1447 | onecli_cmd_tmpl "onedatastore update 0" "${TEMPLATE}" >/dev/null || return 1 1448 | onecli_cmd_tmpl "onedatastore update 1" "${TEMPLATE}" >/dev/null 1449 | } 1450 | 1451 | create_vnet() { 1452 | SIZE=$((VNET_AR_IP_COUNT - 1)) 1453 | 1454 | TEMPLATE=$( 1455 | cat </dev/null 2>&1 1471 | } 1472 | 1473 | poll_for_marketplace() { 1474 | APP_COUNT=$(onemarketapp list | wc -l) 1475 | for I in $(seq 30); do 1476 | sleep 5 1477 | NEW_APP_COUNT=$(onemarketapp list | wc -l) 1478 | 1479 | if [[ "${NEW_APP_COUNT}" = "${APP_COUNT}" && "${APP_COUNT}" -gt 20 ]]; then 1480 | return 0 1481 | fi 1482 | APP_COUNT=${NEW_APP_COUNT} 1483 | done 1484 | return 1 1485 | } 1486 | 1487 | export_marketapp() { 1488 | local APP_NAME="$1" 1489 | local DS_ID="${2:-1}" 1490 | local SUFFIX="$3" 1491 | local NEW_NAME="${4:-$APP_NAME$SUFFIX}" 1492 | 1493 | poll_for_marketplace 1494 | 1495 | ID=$(onemarketapp list --filter NAME="${APP_NAME}" \ 1496 | --csv | tail -1 | awk -F, '{print $1}') || return 1 1497 | 1498 | # onemarketapp always return 0 and prints to STDOUT 1499 | OUT=$(mktemp) 1500 | 1501 | onemarketapp export "${ID}" "${NEW_NAME}" --datastore "$DS_ID" >"$OUT" 1502 | 1503 | if grep -q -i error <"$OUT"; then 1504 | cat "$OUT" >&2 1505 | rm "$OUT" 1506 | return 1 1507 | fi 1508 | 1509 | rm "$OUT" 1510 | } 1511 | 1512 | image_is_ready() { 1513 | for I in $(seq "$IMAGE_WAIT_TIMEOUT"); do 1514 | STATES=$(oneimage list --csv --no-header -l stat) 1515 | 1516 | # some error occurs 1517 | echo "$STATES" | grep err && { 1518 | echo "Image download error" 1519 | return 1 1520 | } 1521 | 1522 | # all images are ready 1523 | echo "$STATES" | grep -q -v rdy || return 0 1524 | 1525 | sleep 1 1526 | done 1527 | 1528 | echo "Image download reached timeout" >&2 1529 | return 1 1530 | } 1531 | 1532 | update_template() { 1533 | local ID 1534 | local TMP_FILE 1535 | 1536 | # the last template 1537 | ID=$(onetemplate list --no-header -l ID | head -1 | tr -d '[:space:]') 1538 | TMP_FILE=$(mktemp) 2>/dev/null || return 1 1539 | 1540 | # Add root password, report_ready and token setting to context 1541 | onetemplate show "$ID" | grep CONTEXT -A1000 | 1542 | sed -e "s/CONTEXT=\[/CONTEXT=[ PASSWORD=\"${VM_PASSWORD}\",/" | 1543 | sed -e "s/CONTEXT=\[/CONTEXT=[ REPORT_READY=\"YES\",/" | 1544 | sed -e "s/CONTEXT=\[/CONTEXT=[ TOKEN=\"YES\",/" \ 1545 | >"${TMP_FILE}" 1546 | 1547 | # Add network 1548 | node && echo 'NIC=[ NETWORK="vnet", NETWORK_UNAME="oneadmin", SECURITY_GROUPS="0" ]' >>"${TMP_FILE}" 1549 | 1550 | onetemplate update "$ID" "${TMP_FILE}" >/dev/null 1551 | RC=$? 1552 | rm "${TMP_FILE}" 1553 | return "${RC}" 1554 | } 1555 | 1556 | update_kvm_host() { 1557 | TMP_FILE=$(mktemp) 2>/dev/null || return 1 1558 | cat >"$TMP_FILE" </dev/null 2>&1" \ 1583 | "Creating $LOCALHOST_VM_MAD host" 1584 | 1585 | if [ "$(arch)" = "aarch64" ]; then 1586 | check "update_kvm_host" "Updating kvm host with ARM64 specifics" 1587 | fi 1588 | } 1589 | 1590 | lxc && { 1591 | check "onehost create -i lxc -v lxc localhost >/dev/null 2>&1" \ 1592 | "Creating LXC host" 1593 | } 1594 | 1595 | node && { 1596 | check "systemctl restart opennebula" "Restarting OpenNebula" 1597 | check "sudo -u oneadmin onehost sync -f" "Ensure host is synced" 1598 | } 1599 | 1600 | networking && check "create_vnet" "Creating virtual network" 1601 | 1602 | check "export_marketapp \"$MARKET_APP_NAME\"" "Exporting [${MARKET_APP_NAME}] from Marketplace to local datastore" 1603 | check "image_is_ready" "Waiting until the image is ready" 1604 | 1605 | check "update_template" "Updating VM template" 1606 | 1607 | #------------------------------------------------------------------------------- 1608 | # Report 1609 | #------------------------------------------------------------------------------- 1610 | [[ $SUNSTONE_PORT != 80 ]] && PORT_STR=":$SUNSTONE_PORT" 1611 | 1612 | title 'Report' 1613 | echo "OpenNebula ${VERSION} was installed" 1614 | echo "Sunstone is running on:" 1615 | echo " http://${REPORT_IP}${PORT_STR}/" 1616 | 1617 | echo "FireEdge is running on:" 1618 | echo " http://${REPORT_IP}:${SUNSTONE_PORT}/" 1619 | 1620 | echo "Use following to login:" 1621 | echo " user: oneadmin" 1622 | echo " password: ${PASSWORD}" 1623 | 1624 | exit 0 1625 | --------------------------------------------------------------------------------