1 # This file is meant to be SOURCED
3 # Copyright 2016 RIFT.IO Inc
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # 24 June 2016 -- Jeremy Mordkoff -- Genesis
22 FATAL "arg is container name"
24 lxc config show $1 2>&1 >/dev/null
26 DEBUG "container $1 exists"
29 DEBUG "container $1 not found"
36 FATAL "args are image container"
38 INFO "creating container $2 using image $1"
39 DEBUG "lxc launch $1 $2"
43 create_privileged_container() {
45 FATAL "args are image container"
47 INFO "creating container $2 using image $1"
48 DEBUG "lxc launch $1 $2"
49 lxc launch "$1" "$2" -c security.privileged=true
55 DEBUG "exec in $container \"$*\""
56 lxc exec "$container" -- $*
60 [ $# -eq 1 ] || FATAL "arg is container name got $# args - $*"
63 while [ $ct -lt 60 ]; do
65 output=$(container_exec "$1" ping -c 1 google.com)
66 if [[ $output =~ $RE ]]; then
70 INFO "waiting for container $1 to start"
71 DEBUG "expected '$RE' in $output"
74 FATAL "container $1 did not start"
76 container_push_tree() {
77 # create a tarball locally, pipe it into the container and unpack it there
78 [ $# -eq 3 ] || FATAL "args are container dir_from dir_to (dir_to MUST exist)"
79 tar -C "$2" -c . -f - | container_exec $1 tar -C "$3" -x -f -
82 container_push_devops() {
83 [ $# -eq 1 ] || FATAL "arg is container name got $# args - $*"
84 container_exec "$1" mkdir -p /root/devops
85 container_push_tree "$1" "$(dirname $OSM_JENKINS)" "/root/devops"