/* * Copyright (c) 2016 Cisco and/or its affiliates. * 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. */ /* * pci.c: Linux user space PCI bus management. * * Copyright (c) 2008 Eliot Dresselhaus * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static const char *sysfs_pci_dev_path = "/sys/bus/pci/devices"; static const char *sysfs_pci_drv_path = "/sys/bus/pci/drivers"; static char *sysfs_mod_vfio_noiommu = "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode"; #define pci_log_debug(vm, dev, f, ...) \ vlib_log(VLIB_LOG_LEVEL_DEBUG, pci_main.log_default, "%U: " f, \ format_vlib_pci_addr, vlib_pci_get_addr(vm, dev->handle), ## __VA_ARGS__) #define pci_log_err(vm, dev, f, ...) \ vlib_log(VLIB_LOG_LEVEL_ERR, pci_main.log_default, "%U: " f, \ format_vlib_pci_addr, vlib_pci_get_addr(vm, dev->handle), ## __VA_ARGS__) typedef struct { int fd; void *addr; size_t size; } linux_pci_region_t; typedef struct { int fd; u32 clib_file_index; union { pci_intx_handler_function_t *intx_handler; pci_msix_handler_function_t *msix_handler; }; } linux_pci_irq_t; typedef enum { LINUX_PCI_DEVICE_TYPE_UNKNOWN, LINUX_PCI_DEVICE_TYPE_UIO, LINUX_PCI_DEVICE_TYPE_VFIO, } linux_pci_device_type_t; typedef struct { linux_pci_device_type_t type; vlib_pci_dev_handle_t handle; vlib_pci_addr_t addr; u32 numa_node; /* Resource file descriptors. */ linux_pci_region_t *regions; /* File descriptor for config space read/write. */ int config_fd; u64 config_offset; /* Device File descriptor */ int fd; /* read/write file descriptor for io bar */ int io_fd; u64 io_offset; /* Minor device for uio device. */ u32 uio_minor; /* Interrupt handlers */ linux_pci_irq_t intx_irq; linux_pci_irq_t *msix_irqs; /* private data */ uword private_data; u8 supports_va_dma; } linux_pci_device_t; /* Pool of PCI devices. */ typedef struct { vlib_main_t *vlib_main; linux_pci_device_t *linux_pci_devices; } linux_pci_main_t; extern linux_pci_main_t linux_pci_main; static linux_pci_device_t * linux_pci_get_device (vlib_pci_dev_handle_t h) { linux_pci_main_t *lpm = &linux_pci_main; return pool_elt_at_index (lpm->linux_pci_devices, h); } uword vlib_pci_get_private_data (vlib_main_t * vm, vlib_pci_dev_handle_t h) { linux_pci_device_t *d = linux_pci_get_device (h); return d->private_data; } void vlib_pci_set_private_data (vlib_main_t * vm, vlib_pci_dev_handle_t h, uword private_data) { linux_pci_device_t *d = linux_pci_get_device (h); d->private_data = private_data; } vlib_pci_addr_t * vlib_pci_get_addr (vlib_main_t * vm, vlib_pci_dev_handle_t h) { linux_pci_device_t *d = linux_pci_get_device (h); return &d->addr; } u32 vlib_pci_get_numa_node (vlib_main_t * vm, vlib_pci_dev_handle_t h) { linux_pci_device_t *d = linux_pci_get_device (h); return d->numa_node; } /* Call to allocate/initialize the pci subsystem. This is not an init function so that users can explicitly enable pci only when it's needed. */ clib_error_t *pci_bus_init (vlib_main_t * vm); linux_pci_main_t linux_pci_main; vlib_pci_device_info_t * vlib_pci_get_device_info (vlib_main_t * vm, vlib_pci_addr_t * addr, clib_error_t ** error) { linux_vfio_main_t *lvm = &vfio_main; clib_error_t *err; vlib_pci_device_info_t *di; u8 *f = 0; u32 tmp; int fd; di = clib_mem_alloc (sizeof (vlib_pci_device_info_t)); clib_memset (di, 0, sizeof (vlib_pci_device_info_t)); di->addr.as_u32 = addr->as_u32; u8 *dev_dir_name = format (0, "%s/%U", sysfs_pci_dev_path, format_vlib_pci_addr, addr); f = format (0, "%v/config%c", dev_dir_name, 0); fd = open ((char *) f, O_RDWR); /* Try read-only access if write fails. */ if (fd < 0) fd = open ((char *) f, O_RDONLY); if (fd < 0) { err = clib_error_return_unix (0, "open `%s'", f); goto error; } /* You can only read more that 64 bytes of config space as root; so we try to read the full space but fall back to just the first 64 bytes. */ if (read (fd, &di->config_data, sizeof (di->config_data)) < sizeof (di->config0)) { err = clib_error_return_unix (0, "read `%s'", f); close (fd); goto error; } { static pci_config_header_t all_ones; if (all_ones.vendor_id == 0) clib_memset (&all_ones, ~0, sizeof (all_ones)); if (!memcmp (&di->config0.header, &all_ones, sizeof (all_ones))) { err = clib_error_return (0, "invalid PCI config for `%s'", f); close (fd); goto error; } } if (di->config0.header.header_type == 0) pci_config_type0_little_to_host (&di->config0); else pci_config_type1_little_to_host (&di->config1); di->numa_node = -1; vec_reset_length (f); f = format (f, "%v/numa_node%c", dev_dir_name, 0); err = clib_sysfs_read ((char *) f, "%u", &di->numa_node); if (err) { di->numa_node = -1; clib_error_free (err); } vec_reset_length (f); f = format (f, "%v/class%c", dev_dir_name, 0); err = clib_sysfs_read ((char *) f, "0x%x", &tmp); if (err) goto error; di->device_class = tmp >> 8; vec_reset_length (f); f = format (f, "%v/vendor%c", dev_dir_name, 0); err = clib_sysfs_read ((char *) f, "0x%x", &tmp); if (err) goto error; di->vendor_id = tmp; vec_reset_length (f); f = format (f, "%v/device%c", dev_dir_name, 0); err = clib_sysfs_read ((char *) f, "0x%x", &tmp); if (err) goto error; di->device_id = tmp; vec_reset_length (f); f = format (f, "%v/driver%c", dev_dir_name, 0); di->driver_name = clib_sysfs_link_to_name ((char *) f); di->iommu_group = -1; if (lvm->container_fd != -1) { u8 *tmpstr; vec_reset_length (f); f = format (f, "%v/iommu_group%c", dev_dir_name, 0); tmpstr = clib_sysfs_link_to_name ((char *) f); if (tmpstr) { di->iommu_group = atoi ((char *) tmpstr); vec_free (tmpstr); } vec_reset_length (f); f = format (f, "%v/iommu_group/name%c", dev_dir_name, 0); err = clib_sysfs_read ((char *) f, "%s", &tmpstr); if (err == 0) { if (strncmp ((char *) tmpstr, "vfio-noiommu", 12) == 0) di->flags |= VLIB_PCI_DEVICE_INFO_F_NOIOMMU; vec_free (tmpstr); } else clib_error_free (err); } close (fd); vec_reset_length (f); f = format (f, "%v/vpd%c", dev_dir_name, 0); fd = open ((char *) f, O_RDONLY); if (fd >= 0) { while (1) { u8 tag[3]; u8 *data = 0; uword len; if (read (fd, &tag, 3) != 3) break; if (tag[0] != 0x82 && tag[0] != 0x90 && tag[0] != 0x91) break; len = (tag[2] << 8) | tag[1]; vec_validate (data, len); if (read (fd, data, len) != len) { vec_free (data); break; } if (tag[0] == 0x82) di->product_name = data; else if (tag[0] == 0x90) di->vpd_r = data; else if (tag[0] == 0x91) di->vpd_w = data; data = 0; } close (fd); } goto done; error: vlib_pci_free_device_info (di); di = 0; done: vec_free (f); vec_free (dev_dir_name); if (error) *error = err; else clib_error_free (err); return di; } static int directory_exists (char *path) { struct stat s = { 0 }; if (stat (path, &s) == -1) return 0; return S_ISDIR (s.st_mode); } clib_error_t * vlib_pci_bind_to_uio (vlib_main_t * vm, vlib_pci_addr_t * addr, char *uio_drv_name) { clib_error_t *error = 0; u8 *s = 0, *driver_name = 0; DIR *dir = 0; struct dirent *e; vlib_pci_device_info_t *di; int fd, clear_driver_override = 0; u8 *dev_dir_name = format (0, "%s/%U", sysfs_pci_dev_path, format_vlib_pci_addr, addr); di = vlib_pci_get_device_info (vm, addr, &error); if (error) return error; if (strncmp ("auto", uio_drv_name, 5) == 0) { int vfio_pci_loaded = 0; if (directory_exists ("/sys/module/vfio_pci")) vfio_pci_loaded = 1; if (di->iommu_group != -1) { /* device is bound to IOMMU group */ if (!vfio_pci_loaded) { error = clib_error_return (0, "Skipping PCI device %U: device " "is bound to IOMMU group and " "vfio-pci driver is not loaded", format_vlib_pci_addr, addr); goto done; } else uio_drv_name = "vfio-pci"; } else { /* device is not bound to IOMMU group so we have multiple options */ if (vfio_pci_loaded && (error = clib_sysfs_write (sysfs_mod_vfio_noiommu, "Y")) == 0) uio_drv_name = "vfio-pci"; else if (directory_exists ("/sys/module/uio_pci_generic")) uio_drv_name = "uio_pci_generic"; else if (directory_exists ("/sys/module/igb_uio")) uio_drv_name = "igb_uio"; else { clib_error_free (error); error = clib_error_return (0, "Skipping PCI device %U: missing " "kernel VFIO or UIO driver", format_vlib_pci_addr, addr); goto done; } clib_error_free (error); } } s = format (s, "%v/driver%c", dev_dir_name, 0); driver_name = clib_sysfs_link_to_name ((char *) s); vec_reset_length (s); if (driver_name && ((strcmp ("vfio-pci", (char *) driver_name) == 0) || (strcmp ("uio_pci_generic", (char *) driver_name) == 0) || (strcmp ("igb_uio", (char *) driver_name) == 0))) goto done; /* walk trough all linux interfaces and if interface belonging to this device is founf check if interface is admin up */ dir = opendir ("/sys/class/net"); s = format (s, "%U%c", format_vlib_pci_addr, addr, 0); if (!dir) { error = clib_error_return (0, "Skipping PCI device %U: failed to " "read /sys/class/net", format_vlib_pci_addr, addr); goto done; } fd = socket (PF_INET, SOCK_DGRAM, 0); if (fd < 0) { error = clib_error_return_unix (0, "socket"); goto done; } while ((e = readdir (dir))) { struct ifreq ifr; struct ethtool_drvinfo drvinfo; if (e->d_name[0] == '.') /* skip . and .. */ continue; clib_memset (&ifr, 0, sizeof ifr); clib_memset (&drvinfo, 0, sizeof drvinfo); ifr.ifr_data = (char *) &drvinfo; strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name) - 1); drvinfo.cmd = ETHTOOL_GDRVINFO; if (ioctl (fd, SIOCETHTOOL, &ifr) < 0) { /* Some interfaces (eg "lo") don't support this ioctl */ if ((errno != ENOTSUP) && (errno != ENODEV)) clib_unix_warning ("ioctl fetch intf %s bus info error", e->d_name); continue; } if (strcmp ((char *) s, drvinfo.bus_info)) continue; clib_memset (&ifr, 0, sizeof (ifr)); strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name) - 1); if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0) { error = clib_error_return_unix (0, "ioctl fetch intf %s flags", e->d_name); close (fd); goto done; } if (ifr.ifr_flags & IFF_UP) { error = clib_error_return (0, "Skipping PCI device %U as host " "interface %s is up", format_vlib_pci_addr, addr, e->d_name); close (fd); goto done; } } close (fd); vec_reset_length (s); s = format (s, "%v/driver/unbind%c", dev_dir_name, 0); clib_sysfs_write ((char *) s, "%U", format_vlib_pci_addr, addr); vec_reset_length (s); s = format (s, "%v/driver_override%c", dev_dir_name, 0); if (access ((char *) s, F_OK) == 0) { clib_sysfs_write ((char *) s, "%s", uio_drv_name); clear_driver_override = 1; } else { vec_reset_length (s); s = format (s, "%s/%s/new_id%c", sysfs_pci_drv_path, uio_drv_name, 0); clib_sysfs_write ((char *) s, "0x%04x 0x%04x", di->vendor_id, di->device_id); } vec_reset_length (s); s = format (s, "%s/%s/bind%c", sysfs_pci_drv_path, uio_drv_name, 0); clib_sysfs_write ((char *) s, "%U", format_vlib_pci_addr, addr); vec_reset_length (s); if (clear_driver_override) { s = format (s, "%v/driver_override%c", dev_dir_name, 0); clib_sysfs_write ((char *) s, "%c", 0); vec_reset_length (s); } done: closedir (dir); vec_free (s); vec_free (dev_dir_name); vec_free (driver_name); return error; } static clib_error_t * scan_uio_dir (void *arg, u8 * path_name, u8 * file_name) { linux_pci_device_t *l = arg; unformat_input_t input; unformat_init_string (&input, (char *) file_name, vec_len (file_name)); if (!unformat (&input, "uio%d", &l->uio_minor)) abort (); unformat_free (&input); return 0; } static clib_error_t * vfio_set_irqs (vlib_main_t * vm, linux_pci_device_t * p, u32 index, u32 start, u32 count, u32 flags, int *efds) { int data_len = efds ? count * sizeof (int) : 0; u8 buf[sizeof (struct vfio_irq_set) + data_len]; struct vfio_irq_info ii = { 0 }; struct vfio_irq_set *irq_set = (struct vfio_irq_set *) buf; ii.argsz = sizeof (struct vfio_irq_info); ii.index = index; if (ioctl (p->fd, VFIO_DEVICE_GET_IRQ_INFO, &ii) < 0) return clib_error_return_unix (0, "ioctl(VFIO_DEVICE_GET_IRQ_INFO) " "'%U'", format_vlib_pci_addr, &p->addr); pci_log_debug (vm, p, "%s index:%u count:%u flags: %s%s%s%s(0x%x)", __func__, ii.index, ii.count, ii.flags & VFIO_IRQ_INFO_EVENTFD ? "eventfd " : "", ii.flags & VFIO_IRQ_INFO_MASKABLE ? "maskable " : "", ii.flags & VFIO_IRQ_INFO_AUTOMASKED ? "automasked " : "", ii.flags & VFIO_IRQ_INFO_NORESIZE ? "noresize " : "", ii.flags); if (ii.count < start + count) return clib_error_return_unix (0, "vfio_set_irq: unexistng interrupt on " "'%U'", format_vlib_pci_addr, &p->addr); if (efds) { flags |= VFIO_IRQ_SET_DATA_EVENTFD; clib_memcpy_fast (&irq_set->data, efds, data_len); } else flags |= VFIO_IRQ_SET_DATA_NONE; ASSERT ((flags & (VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_DATA_EVENTFD)) != (VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_DATA_EVENTFD)); irq_set->argsz = sizeof (struct vfio_irq_set) + data_len; irq_set->index = index; irq_set->start = start; irq_set->count = count; irq_set->flags = flags; if (ioctl (p->fd, VFIO_DEVICE_SET_IRQS, irq_set) < 0) return clib_error_return_unix (0, "%U:ioctl(VFIO_DEVICE_SET_IRQS) " "[index = %u, start = %u, count = %u, " "flags = 0x%x]", format_vlib_pci_addr, &p->addr, index, start, count, flags); return 0; } static clib_error_t * linux_pci_uio_read_ready (clib_file_t * uf) { vlib_main_t *vm = vlib_get_main (); int __attribute__ ((unused)) rv; vlib_pci_dev_handle_t h = uf->private_data; linux_pci_device_t *p = linux_pci_get_device (h); linux_pci_irq_t *irq = &p->intx_irq; u32 icount; rv = read (uf->file_descriptor, &icount, 4); if (irq->intx_handler) irq->intx_handler (vm, h); vlib_pci_intr_enable (vm, h); return /* no error */ 0; } static clib_error_t * linux_pci_vfio_unmask_intx (vlib_main_t * vm, linux_pci_device_t * d) { return vfio_set_irqs (vm, d, VFIO_PCI_INTX_IRQ_INDEX, 0, 1, VFIO_IRQ_SET_ACTION_UNMASK, 0); } static clib_error_t * linux_pci_uio_error_ready (clib_file_t * uf) { u32 error_index = (u32) uf->private_data; return clib_error_return (0, "pci device %d: error", error_index); } static clib_error_t * linux_pci_vfio_msix_read_ready (clib_file_t * uf) { vlib_main_t *vm = vlib_get_main (); int __attribute__ ((unused)) rv; vlib_pci_dev_handle_t h = uf->private_data >> 16; u16 line = uf->private_data & 0xffff; linux_pci_device_t *p = linux_pci_get_device (h); linux_pci_irq_t *irq = vec_elt_at_index (p->msix_irqs, line); u64 icount; rv = read (uf->file_descriptor, &icount, sizeof (icount)); if (irq->msix_handler) irq->msix_handler (vm, h, line); return /* no error */ 0; } static clib_error_t * linux_pci_vfio_intx_read_ready (clib_file_t * uf) { vlib_main_t *vm = vlib_get_main (); int __attribute__ ((unused)) rv; vlib_pci_dev_handle_t h = uf->private_data; linux_pci_device_t *p = linux_pci_get_device (h); linux_pci_irq_t *irq = &p->intx_irq; u64 icount; rv = read (uf->file_descriptor, &icount, sizeof (icount)); if (irq->intx_handler) irq->intx_handler (vm, h); linux_pci_vfio_unmask_intx (vm, p); return /* no error */ 0; } static clib_error_t * linux_pci_vfio_error_ready (clib_file_t * uf) { u32 error_index = (u32) uf->private_data; return clib_error_return (0, "pci device %d: error", error_index); } static clib_error_t * add_device_uio (vlib_main_t * vm, linux_pci_device_t * p, vlib_pci_device_info_t * di, pci_device_registration_t * r) { linux_pci_main_t *lpm = &linux_pci_main; clib_error_t *err = 0; u8 *s = 0; p->fd = -1; p->type = LINUX_PCI_DEVICE_TYPE_UIO; s = format (s, "%s/%U/config%c", sysfs_pci_dev_path, format_vlib_pci_addr, &di->addr, 0); p->config_fd = open ((char *) s, O_RDWR); p->config_offset = 0; vec_reset_length (s); if (p->config_fd == -1) { err = clib_error_return_unix (0, "open '%s'", s); goto error; } s = format (0, "%s/%U/uio", sysfs_pci_dev_path, format_vlib_pci_addr, &di->addr); foreach_directory_file ((char *) s, scan_uio_dir, p, /* scan_dirs */ 1); vec_reset_length (s); s = format (s, "/dev/uio%d%c", p->uio_minor, 0); p->fd = open ((char *) s, O_RDWR); if (p->fd < 0) { err = clib_error_return_unix (0, "open '%s'", s); goto error; } if (r && r->interrupt_handler) vlib_pci_register_intx_handler (vm, p->handle, r->interrupt_handler); if (r && r->init_function) err = r->init_function (lpm->vlib_main, p->handle); error: vec_free (s); if (err) { if
#!/bin/bash
# Copyright (c) 2016 Cisco and/or its affiliates.
# 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 -x

cat /etc/hostname
cat /etc/hosts

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
VIRL_SERVER=""

VIRL_USERNAME=jenkins-in
VIRL_PKEY=priv_key
VIRL_SERVER_STATUS_FILE="status"
VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"

JOB_ARCHIVE_ARTIFACTS=(log.html output.xml report.html honeycomb.log)
LOG_ARCHIVE_ARTIFACTS=(log.html output.xml report.html honeycomb.log)
JOB_ARCHIVE_DIR="archive"
LOG_ARCHIVE_DIR="$WORKSPACE/archives"
mkdir -p ${JOB_ARCHIVE_DIR}
mkdir -p ${LOG_ARCHIVE_DIR}
OS=$1

if [ -f "/etc/redhat-release" ]; then
    DISTRO="CENTOS"
    sudo yum install -y python-devel python-virtualenv
    VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_CENTOS)
    VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_CENTOS)
else
    DISTRO="UBUNTU"
    export DEBIAN_FRONTEND=noninteractive
    sudo apt-get -y update
    sudo apt-get -y install libpython2.7-dev python-virtualenv
    VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_UBUNTU)
    VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_UBUNTU)
fi

SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"

function ssh_do() {
    echo
    echo "### "  ssh $@
    ssh ${SSH_OPTIONS} $@
}

rm -f ${VIRL_PKEY}
cat > ${VIRL_PKEY} <<EOF
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX
VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9
asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz
L3dM3iSmlmQlzv9bThjo+nI4KFYh6m5wrZmAo5r/4q9CIJc21HVnTqkGOWJIZz6J
73lePJVSq5gYqaoGw3swFEA/MDkOx7baWKSoLQIDAQABAoIBAQCNBeolNp+JWJ76
gQ4fwLsknyXSV6sxYyhkDW4PEwwcTU06uqce0AAzXVffxne0fMe48x47+zqBgPbb
4huM+Pu8B9nfojUMr5TaYtl9Zbgpk3F8H7dT7LKOa6XrxvZTZrADSRc30+Z26zPN
e9zTaf42Gvt0/l0Zs1BHwbaOXqO+XuwJ3/F9Sf3PQYWXD3EOWjpHDP/X/1vAs6lV
SLkm6J/9KKE1m6I6LTYjIXuYt4SXybW6N2TSy54hhQtYcDUnIU2hR/PHVWKrGA0J
kELgrtTNTdbML27O5gFWU4PLUEYTZ9fN11D6qUZKxLcPOiPPHXkiILMRCCnG5DYI
ksBAU/YlAoGBAPxZO9VO18TYc8THV1nLKcvT2+1oSs1UcA2wNQMU55t910ZYinRa
MRwUhMOf8Mv5wOeiZaRICQB1PnVWtDVmGECgPpK6jUxqAwn8rgJcnoafLGL5YKMY
RVafTe6N5LXgCaOcJrk21wxs6v7ninEbUxxc575urOvZMBkymDw91dwbAoGBAPwa
YRhKhrzFKZzdK0RadVjnxKvolUllpoqqg3XuvmeAJHAOAnaOgVWq68NAcp5FZJv0
2D2Up7TX8pjf9MofP1SJbcraKBpK4NzfNkA0dSdEi+FhVofAJ9umB2o5LW1n7sab
UIrjsdzSJK/9Zb9yTTHPyibYzNEgaJV1HsbxfEFXAoGAYO2RmvRm0phll18OQVJV
IpKk9kLKAKZ/R/K32hAsikBC8SVPQTPniyaifFWx81diblalff2hX4ipTf7Yx24I
wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS
NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
-----END RSA PRIVATE KEY-----
EOF
chmod 600 ${VIRL_PKEY}

#
# Pick a random host from the array of VIRL servers, and attempt
# to reach it and verify it's status.
#
# The server must be reachable, and have a "status" file with
# the content "PRODUCTION", to be selected.
#
# If the server is not reachable, or does not have the correct
# status, remove it from the array and start again.
#
# Abort if there are no more servers left in the array.
#
while [[ ! "$VIRL_SERVER" ]]
do
    num_hosts=${#VIRL_SERVERS[@]}
    if [ $num_hosts == 0 ]
    then
        echo "No more VIRL candidate hosts available, failing."
        exit 127
    fi
    element=$[ $RANDOM % $num_hosts ]