~lutostag/ubuntu/trusty/maas/1.5.4+keystone

« back to all changes in this revision

Viewing changes to scripts/maas-import-ephemerals

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-03-04 11:49:44 UTC
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20130304114944-azcvu9anlf8mizpa
Tags: upstream-1.3+bzr1452+dfsg
ImportĀ upstreamĀ versionĀ 1.3+bzr1452+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
22
VERBOSITY=0
23
 
REMOTE_IMAGES_MIRROR=${REMOTE_IMAGES_MIRROR:-https://maas.ubuntu.com/images}
 
23
 
 
24
# Mirror to load cloud images from.  When the cluster controller runs the
 
25
# import scripts, it provides a setting from the server side.
 
26
CLOUD_IMAGES_ARCHIVE=${CLOUD_IMAGES_ARCHIVE:-https://maas.ubuntu.com/images}
24
27
 
25
28
# iSCSI targets configuration file.
26
29
SYS_TGT_CONF="/etc/tgt/targets.conf"
88
91
}
89
92
 
90
93
 
 
94
uniq_major_arches() {
 
95
    # print on stdout a uniq set of arches out of the list of arch/subarch
 
96
    # pairs supplied in $@
 
97
    # Eg. armhf/highbank armhf/armadaxp i386/generic amd64/generic ->
 
98
    #           "armhf\ni386\namd64\n"
 
99
    local arch
 
100
    for arch in "$@"; do echo "${arch%%/*}"; done|uniq
 
101
}
 
102
 
 
103
 
 
104
subarches() {
 
105
    # print on stdout a list of subarches available for a given major arch $1
 
106
    # given a list of arch/subarch pairs in $2-
 
107
    # Eg. armhf armhf/highbank armhf/armadaxp i386/generic ->
 
108
    #           "highbank\narmadaxp\n"
 
109
    local major_arch="$1" candidate
 
110
    shift
 
111
    for candidate in "$@"; do
 
112
        case "$candidate" in
 
113
            "$major_arch"/*) echo "${candidate#*/}" ;;
 
114
            *) ;;
 
115
        esac
 
116
    done
 
117
}
 
118
 
 
119
 
91
120
query_remote() {
92
 
    # query /query data at REMOTE_IMAGES_MIRROR
 
121
    # query /query data at CLOUD_IMAGES_ARCHIVE
93
122
    # returns 7 values prefixed with 'r_'
94
123
    local iarch=$1 irelease=$2 istream=$3 out=""
95
 
    local burl="${REMOTE_IMAGES_MIRROR}/query"
 
124
    local burl="${CLOUD_IMAGES_ARCHIVE}/query"
96
125
    local url="$burl/$irelease/$istream/${STREAM}-dl.current.txt"
97
126
    local target="$TEMP_D/query/$release.$stream"
98
127
    mkdir -p -- "$TEMP_D/query"
168
197
    local wd="$1" exdir="" tarball=""
169
198
    shift
170
199
    local release=$1 stream=$2 label=$3 serial=$4 arch=$5 url=$6 name=$7
171
 
    local furl="$REMOTE_IMAGES_MIRROR/$url"
 
200
    local furl="$CLOUD_IMAGES_ARCHIVE/$url"
172
201
 
173
202
    mkdir -p "$wd"
174
203
    cat > "$wd/info" <<EOF
235
264
    [ -z "$initrd" ] || mv "$initrd" "$wd/initrd.gz" ||
236
265
        { error "failed to move extracted initrd to $wd/initrd.gz"; return 1; }
237
266
 
 
267
    [ ! -d "$exdir/subarch" ] || mv "$exdir/subarch" "$wd/" ||
 
268
        { error "failed to move extracted subarch to $wd/subarch"; return 1; }
 
269
 
238
270
    rm -Rf "$exdir" || { error "failed to cleanup extraction dir"; return 1; }
239
271
    { [ -z "$rmtar" ] || rm "$rmtar"; } ||
240
272
        { error "failed to remove temporary tarball $rmtar"; return 1; }
301
333
    # deletes it.
302
334
    tmpdir="$(mktemp -d)"
303
335
 
304
 
    copy_first_available "$src/linux" "$src/kernel" "$tmpdir/linux" ||
305
 
        return 1
306
 
    copy_first_available "$src/initrd.gz" "$src/initrd" "$tmpdir/initrd.gz" ||
307
 
        return 1
 
336
    if [ -f "$src/subarch/$subarch/linux" -a \
 
337
            -f "$src/subarch/$subarch/initrd.gz" ]; then
 
338
        cp "$src/subarch/$subarch/linux" "$tmpdir/linux" || return 1
 
339
        cp "$src/subarch/$subarch/initrd.gz" "$tmpdir/initrd.gz" || return 1
 
340
    else
 
341
        copy_first_available "$src/linux" "$src/kernel" "$tmpdir/linux" ||
 
342
            return 1
 
343
        copy_first_available "$src/initrd.gz" "$src/initrd" "$tmpdir/initrd.gz" ||
 
344
            return 1
 
345
    fi
308
346
 
309
347
    local cmd out=""
310
348
    cmd=( maas-provision install-pxe-image
358
396
 
359
397
updates=0
360
398
for release in $RELEASES; do
361
 
    for arch_tuple in $ARCHES; do
362
 
        arch="${arch_tuple%%/*}"
363
 
        subarch="${arch_tuple#*/}"
364
 
 
 
399
    for arch in $(uniq_major_arches $ARCHES); do
365
400
        query_local "$arch" "$release" "$BUILD_NAME" ||
366
401
            fail "failed to query local for $release/$arch"
367
402
        query_remote "$arch" "$release" "$BUILD_NAME" ||
368
 
            fail "remote query of $REMOTE_IMAGES_MIRROR failed"
 
403
            fail "remote query of $CLOUD_IMAGES_ARCHIVE failed"
369
404
 
370
405
        info="rel: $r_release, arch: $arch: name: $r_name"
371
406
        debug 2 "$info"
402
437
            name="${l_name}"
403
438
        fi
404
439
 
405
 
        # Even if there was no need to update the image, we make sure it
406
 
        # gets installed.
407
 
        debug 1 "adding images for $release/$arch/$subarch to maas"
408
 
        install_tftp_image "$fpfinal_d" "$arch" "$subarch" "$release" ||
409
 
            fail "failed to install ftp image [$info]"
 
440
        for subarch in $(subarches "$arch" $ARCHES); do
 
441
                # Even if there was no need to update the image, we make sure
 
442
                # it gets installed.
 
443
                debug 1 "adding images for $release/$arch/$subarch to maas"
 
444
                install_tftp_image "$fpfinal_d" "$arch" "$subarch" "$release" ||
 
445
                    fail "failed to install tftp image [$info]"
 
446
        done
410
447
 
411
448
        target_name="${TARGET_NAME_PREFIX}${name}"
412
449
        rel_tgt="../${final_d}/tgt.conf"