#!/bin/bash

[ -n "$_INCGD_openstack" ] && return || readonly _INCGD_openstack=1
source /usr/lib/app-setup-scalet/openstack

source /usr/lib/app-setup-scalet/json

# Check for exported vendordata/metadata availability
if [[ -z "$VENDORDATA" ]]; then
    error "Failed to get VendorData"
    exit 101
fi
if [[ -z "$METADATA" ]]; then
    error "Failed to get MetaData"
    exit 102
fi

# We used too get VendorData directly from api...
_openstack_get_vd()
{
    echo ${VENDORDATA}
}

_openstack_get_md()
{
    echo ${METADATA}
}

openstack_get_hostname()
{
    _openstack_get_md | json_read hostname
}

openstack_get_uuid()
{
    _openstack_get_md | json_read uuid
}

openstack_get_passwordhash()
{
    _openstack_get_md | json_read "meta" "x_sel_server_password_hash"
}

openstack_get_authorizedkeys()
{
    _openstack_get_md | json_read "public_keys" ".\+"
}

openstack_get_network_config()
{
    _openstack_get_vd | json_get_branch "x_sel_server_networks"
}

openstack_get_panelpassword()
{
    _openstack_get_md | json_read "meta" "x_sel_server_panelpassword"
}

openstack_get_paneluser()
{
    _openstack_get_md | json_read "meta" "x_sel_server_paneluser"
}
