Remote CLI wrapper scripts

As part of the providing remote CLI capabilities, we provide
docker images for both platform and application, each
containing clients preinstalled.

To make remote clients easier to use, we also provide a set
of configuration and wrapper scripts. These scripts take as
input an RC file downloaded from Horizon (platform or
application horizon) and generate a script with the proper
authentication variables and aliases.

For more details, a README file is also included.

These scripts also work on Windows, by using cygwin to
interpret the bash scripts

Note: these files are not supposed to be included in the
ISO or be built as part of the normal build. These files
are to be distributed separately as a tarball.

Change-Id: I00f6358b8b984150fc11e9087afba83063cb8bb3
Signed-off-by: Stefan Dinescu <stefan.dinescu@windriver.com>
Closes-Bug: 1834667
Closes-Bug: 1834668
This commit is contained in:
Stefan Dinescu 2019-07-02 13:16:54 +03:00
parent 2006523e65
commit e6df168e35
4 changed files with 268 additions and 0 deletions

87
remote_cli_linux/README Normal file
View File

@ -0,0 +1,87 @@
Copyright (c) 2019 Wind River Systems, Inc.
SPDX-License-Identifier: Apache-2.0
--------------------------------------------------
StarlingX Remote CLI Clients
--------------------------------------------------
To enable access to StarlingX CLI remotely, docker images
containing the CLI and Client packages have been created,
for installation on a remote workstation. Two CLI/Client
docker images are used; one for the Kubernetes platform
CLIs/Clients and one for the OpenStack application CLIs/Clients.
This SDK Module includes scripts to configure and provide aliases
for Kubernetes platform and OpenStack application CLI.
Dependencies
-------------------------------------------------
Please make sure Docker is installed on the remote workstation
before using the remote CLI clients. The proper docker images
are pulled automatically by the client scripts.
For instructions on how to install Docker for your system please
follow instructions at the following link: https://docs.docker.com/install/
Using the Remote CLI Clients on a Linux machine:
------------------------------------------------
To install the clients on a Linux machine follow these steps:
1. Untar the provided SDK module tarball
2. Download the openrc file from Horizon.
Log in to Horizon as the user and tenant that you want to use the
remote CLIs as, go to:
Project -> API Access -> Download Openstack RC file -> Openstack RC file
NOTE: You can do this for either the Kubernetes platform Horizon or
OpenStack application Horizon side, or both
3. Configure the clients for Kubernetes platform / OpenStack application side
Kubernetes platform side:
./configure_client.sh -t platform -r admin_openrc.sh
By default this will generate a remote_client_platform.sh file
Openstack application side:
./configure_client.sh -t openstack -r admin_openrc.sh
By default this will generate a remote_client_openstack.sh file
4. When access to the Kubernetes platform side is required, on your console,
source the platform side generated at step 3.
Example: source remote_client_platform.sh
When access to the Openstack application side is required, on your console,
source the platform side generated at step 3.
Example: source remote_client_openstack.sh
When prompted, enter your openstack password.
And then execute either platform or openstack application CLI commands
The sourcing of the config files will also populate aliases for
platform/application clients.
NOTE: do not source both the platform and application config
files from the same console. To use both the kubernetes
platform and openstack application remote clients, source
each config file from separate consoles.
5. For commands that require local filesystem access, you can configure a work
directory as part of the configure_client.sh script.
The configuration parameter is "-w" and by default it uses the local folder
from where the configuration script was called.
This working directory is mounted at "/wd" in the docker container.
If commands need access to local files, copy the files in your configured
work directory and then provide the command with the path to the mounted
folder inside the container.
Example (uploading an image to glance for the openstack application):
1. cp centos63.qcow2 <configured_work_dir>/
2. openstack image create --disk-format qcow2 --container-format bare \
--public --file /wd/centos63.qcow2 centos63-image

View File

@ -0,0 +1,37 @@
#!/bin/bash
#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
if [[ "$CONFIG_TYPE" = "platform" ]]; then
CLIENT_IMAGE_NAME="docker.io/starlingx/stx-platformclients:master-centos-stable-latest"
else
CLIENT_IMAGE_NAME="docker.io/starlingx/stx-openstackclients:master-centos-stable-latest"
fi
# Environment variables related to keystone authentication
# Note: Keep this list up-to-date
read -d '' EXPORTS << EOF
OS_PASSWORD OS_PROJECT_DOMAIN_ID OS_PROJECT_ID OS_REGION_NAME
OS_USER_DOMAIN_NAME OS_PROJECT_NAME OS_IDENTITY_API_SERVICE
OS_AUTH_URL OS_USERNAME OS_INTERFACE OS_PROJECT_DOMAIN_NAME
OS_AUTH_TYPE
EOF
COMMAND_ENV=""
for exp in $EXPORTS; do
# If variable is not defined, don't pass it over to the container
if [[ ! -z "$(printenv $exp)" ]]; then
COMMAND_ENV="$COMMAND_ENV -e $exp=$(printenv $exp)"
fi
done
if [ -z "$2" ]; then
exec docker run -ti ${COMMAND_ENV} --volume ${OSC_WORKDIR}:/wd --workdir /wd ${CLIENT_IMAGE_NAME} "$@"
else
exec docker run -t ${COMMAND_ENV} --volume ${OSC_WORKDIR}:/wd --workdir /wd ${CLIENT_IMAGE_NAME} "$@"
fi

View File

@ -0,0 +1,28 @@
#!/bin/bash
#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# The script may be called from locations other
# than its own folder, so build the full path to
# the script.
if [[ $BASH_SOURCE = '/'* ]]; then
PATH_TO_SCRIPT="$(dirname $BASH_SOURCE)"
else
PATH_TO_SCRIPT="$(pwd)/$(dirname $BASH_SOURCE)"
fi
if [[ "$CONFIG_TYPE" = "platform" ]]; then
SERVICES="system fm openstack"
alias "platform_shell"="${PATH_TO_SCRIPT}/client_wrapper.sh /bin/bash"
else
SERVICES="openstack nova cinder glance heat"
alias "application_shell"="${PATH_TO_SCRIPT}/client_wrapper.sh /bin/bash"
fi
for service in $SERVICES; do
alias "$service"="${PATH_TO_SCRIPT}/client_wrapper.sh $service"
done

View File

@ -0,0 +1,116 @@
#!/bin/bash
#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Default values
RC_FILE="admin-openrc.sh"
CONF_FILE=remote_client_config.sh
ALIAS_FILE=config_aliases.sh
WORK_DIR='.'
custom_conf_file=0
explicit_client_type=0
# The script may be called from locations other
# than its own folder, so build the full path to
# the script.
if [[ $BASH_SOURCE = '/'* ]]; then
PATH_TO_SCRIPT="$(dirname $BASH_SOURCE)"
else
PATH_TO_SCRIPT="$(pwd)/$(dirname $BASH_SOURCE)"
fi
usage(){
echo "Usage:"
echo "configure_client [-t client_type] [-h] [-w workdir] [-o outputfile] [-r RC_FILE]"
echo "-h show help options"
echo "-t client_type type of client configuration (platform/openstack)"
echo " (default value is platform)"
echo "-w workdir local directory to be mounted in docker container"
echo " (default is local directory)"
echo "-o output output RC file"
echo " (default is remote_client_<app/platform>.sh)"
echo "-r RC_FILE tenant RC file"
echo " (default value is admin-openrc.sh"
}
while getopts ":hr:w:o:t:" opt; do
case $opt in
h)
usage
exit 1
;;
r)
RC_FILE=${OPTARG}
;;
w)
WORK_DIR=${OPTARG}
;;
o)
CUSTOM_CONF_FILE=${OPTARG}
custom_conf_file=1
;;
t)
CLIENT_TYPE=${OPTARG}
explicit_client_type=1
;;
*)
echo "Invalid parameter provided"
usage
exit 1
;;
esac
done
# Check if we configure a platform or an application client
if [[ $explicit_client_type -eq 1 ]]; then
if [[ "$CLIENT_TYPE" == "platform" ]]; then
CONFIG_TYPE="platform"
CONF_FILE="remote_client_platform.sh"
elif [[ "$CLIENT_TYPE" == "openstack" ]]; then
CONFIG_TYPE="application"
CONF_FILE="remote_client_openstack.sh"
else
echo "ERROR: Invalid client type option."
echo "Valid options are platform or openstack."
exit 1
fi
else
CONFIG_TYPE="platform"
CONF_FILE="remote_client_platform.sh"
fi
# If custom output RC_FILE is given, use that instead
if [[ $custom_conf_file -eq 1 ]]; then
CONF_FILE=$CUSTOM_CONF_FILE
fi
# Check if input RC file path actually exists
if [[ ! -f "$RC_FILE" ]]; then
echo "ERROR: File at location $RC_FILE does NOT exist"
exit 1
fi
# Delete previous config file
rm -f $CONF_FILE
# We output a complete path for the scripts, so first determine
# if the given path is relative or absolute
if [[ $RC_FILE = '/'* ]]; then
echo "source $RC_FILE" >> $CONF_FILE
else
echo "source $(pwd)/$RC_FILE" >> $CONF_FILE
fi
echo "export CONFIG_TYPE=${CONFIG_TYPE}" >> $CONF_FILE
if [[ $WORK_DIR = '/'* ]]; then
echo "export OSC_WORKDIR=${WORK_DIR}" >> $CONF_FILE
else
echo "export OSC_WORKDIR=$(pwd)/${WORK_DIR}" >> $CONF_FILE
fi
echo "source ${PATH_TO_SCRIPT}/$ALIAS_FILE" >> $CONF_FILE