diff --git a/devstack/lib/ceph b/devstack/lib/ceph index 23cbed12..4c271635 100755 --- a/devstack/lib/ceph +++ b/devstack/lib/ceph @@ -109,6 +109,20 @@ CEPH_RGW_PORT=${CEPH_RGW_PORT:-8080} CEPH_RGW_IDENTITY_API_VERSION=${CEPH_RGW_IDENTITY_API_VERSION:-3} CEPH_RGW_KEYSTONE_SSL=$(trueorfalse False CEPH_RGW_KEYSTONE_SSL) +# iSCSI defaults +CEPH_ISCSI_TARGET_IQN=${CEPH_ISCSI_TARGET_IQN:-iqn.1993-08.org.opendev:01:a9aa4032d2c1} +CEPH_ISCSI_API_USER=${CEPH_ISCSI_API_USER:-openstack} +CEPH_ISCSI_API_PASSWORD=${CEPH_ISCSI_API_PASSWORD:-openstack} +CEPH_ISCSI_API_HOST=${CEPH_ISCSI_API_HOST:-localhost} +CEPH_ISCSI_API_PORT=${CEPH_ISCSI_API_PORT:-5002} +CEPH_ISCSI_GATEWAY_CFG=${CEPH_CONF_DIR}/iscsi-gateway.cfg +# gwcli requires a pool named rbd +CEPH_ISCSI_POOL="rbd" +CEPH_ISCSI_POOL_PG=${CEPH_ISCSI_POOL_PG:-8} +TCMU_RUNNER_REPO="https://github.com/open-iscsi/tcmu-runner.git" +TARGETCLI_REPO="https://github.com/open-iscsi/targetcli-fb.git" +CEPH_ISCSI_REPO="https://github.com/ceph/ceph-iscsi.git" + # Ceph REST API (for containerized version only) # Default is 5000, but Keystone already listens on 5000 CEPH_REST_API_PORT=${CEPH_REST_API_PORT:-5001} @@ -292,6 +306,25 @@ function check_os_support_ceph { fi } + +# check_os_support_ceph_iscsi() - Make sure kernel supports iscsi requirements +function check_os_support_for_iscsi { + KERNEL_CONFIG="/boot/config-$(uname -r)" + + target_core=$(grep -E '(CONFIG_TARGET_CORE=m|CONFIG_TARGET_CORE=y)' $KERNEL_CONFIG) + tcm_user=$(grep -E '(CONFIG_TCM_USER2=m|CONFIG_TCM_USER2=y)' $KERNEL_CONFIG) + iscsi_target=$(grep -E '(CONFIG_ISCSI_TARGET=m|CONFIG_ISCSI_TARGET=y)' $KERNEL_CONFIG) + + if [ -z "$target_core" ] || [ -z "$tcm_user" ] || [ -z "$iscsi_target" ]; then + die "Ceph iSCSI cannot work. The required kernel modules are not installed." + fi + + if [[ ! $INIT_SYSTEM == 'systemd' ]]; then + die "Ceph iSCSI is only supported on systemd enabled systems currently." + fi +} + + # cleanup_ceph() - Remove residual data files, anything left over from previous # runs that a clean run would need to clean up function cleanup_ceph_remote { @@ -335,6 +368,9 @@ function cleanup_ceph_embedded { if [ "$ENABLE_CEPH_RGW" = "True" ]; then sudo killall -w -9 radosgw fi + if [ "$ENABLE_CEPH_ISCSI" = "True" ]; then + stop_ceph_iscsi + fi sudo rm -rf ${CEPH_DATA_DIR}/*/* if egrep -q ${CEPH_DATA_DIR} /proc/mounts; then sudo umount ${CEPH_DATA_DIR} @@ -521,6 +557,10 @@ function configure_ceph { if [ "$ENABLE_CEPH_RGW" = "True" ]; then _configure_ceph_rgw fi + + if [ "$ENABLE_CEPH_ISCSI" = "True" ]; then + _configure_ceph_iscsi + fi } function _configure_rgw_ceph_section { @@ -582,6 +622,69 @@ function _configure_ceph_rgw { } +function _configure_ceph_iscsi_gateway { + iniset -sudo ${CEPH_ISCSI_GATEWAY_CFG} config "trusted_ip_list" "$HOST_IP,localhost" + iniset -sudo ${CEPH_ISCSI_GATEWAY_CFG} config "cluster_name" "ceph" + iniset -sudo ${CEPH_ISCSI_GATEWAY_CFG} config "gateway_keyring" "ceph.client.admin.keyring" + iniset -sudo ${CEPH_ISCSI_GATEWAY_CFG} config "prometheus_host" "$CEPH_ISCSI_API_HOST" + iniset -sudo ${CEPH_ISCSI_GATEWAY_CFG} config "api_secure" "false" + iniset -sudo ${CEPH_ISCSI_GATEWAY_CFG} config "api_user" "$CEPH_ISCSI_API_USER" + iniset -sudo ${CEPH_ISCSI_GATEWAY_CFG} config "api_password" "$CEPH_ISCSI_API_PASSWORD" + iniset -sudo ${CEPH_ISCSI_GATEWAY_CFG} config "api_port" "$CEPH_ISCSI_API_PORT" + iniset -sudo ${CEPH_ISCSI_GATEWAY_CFG} config "api_host" "$CEPH_ISCSI_API_HOST" +} + +function _configure_ceph_iscsi { + _configure_ceph_iscsi_gateway + sudo ceph -c ${CEPH_CONF_FILE} \ + osd pool create ${CEPH_ISCSI_POOL} ${CEPH_ISCSI_POOL_PG} + + if [[ $INIT_SYSTEM == 'systemd' ]]; then + sudo systemctl daemon-reload + sudo systemctl enable tcmu-runner + sudo systemctl enable rbd-target-gw + sudo systemctl enable rbd-target-api + fi +} + +function _post_start_configure_iscsi_gateway { + # Now we setup the rbd-target-gw and rbd-target-api for use + GWCLI=$(which gwcli) + removeme=$(sudo systemctl status rbd-target-api) + HOSTNAME=$(hostname) + + # create the target_iqn for exporting all volumes + sudo $GWCLI /iscsi-targets create $CEPH_ISCSI_TARGET_IQN + + # now we add the gateway definition + # Didn't find the gateway, so lets create it + sudo $GWCLI /iscsi-targets/$CEPH_ISCSI_TARGET_IQN/gateways create $HOSTNAME $HOST_IP skipchecks=true +} + +function start_ceph_iscsi { + if [[ $INIT_SYSTEM == 'systemd' ]]; then + sudo systemctl start tcmu-runner + sudo systemctl start rbd-target-gw + sudo systemctl start rbd-target-api + sleep 10 + fi + + # we have to setup the gateway and api after they start + _post_start_configure_iscsi_gateway +} + +function stop_ceph_iscsi { + HOSTNAME=$(hostname) + sudo $GWCLI /iscsi-targets/$CEPH_ISCSI_TARGET_IQN/gateways delete $HOSTNAME + sudo $GWCLI /iscsi-targets delete $CEPH_ISCSI_TARGET_IQN + + if [[ $INIT_SYSTEM == 'systemd' ]]; then + sudo systemctl stop rbd-target-api + sudo systemctl stop rbd-target-gw + sudo systemctl stop tcmu-runner + fi +} + function _create_swift_endpoint { local swift_service @@ -847,6 +950,12 @@ function init_ceph { if [ "$ENABLE_CEPH_RGW" = "True" ]; then sudo pkill -f radosgw || true fi + if [ "$ENABLE_CEPH_ISCSI" = "True" ]; then + if [[ $INIT_SYSTEM == 'systemd' ]]; then + sudo systemctl stop rbd-target-api + sudo systemctl stop rbd-target-gw + fi + fi if is_ceph_enabled_for_service manila; then sudo pkill -f ceph-mds || true fi @@ -913,6 +1022,44 @@ function configure_repo_nfsganesha { fi } +function setup_packages_for_iscsi { + CWD=$(pwd) + + # We have to install the following required packages for ceph-iscsi + # tcmu-runner, trslib-fb, configshell-fb, targetcli-fb, ceph-iscsi + git_clone $TCMU_RUNNER_REPO $DEST/tcmu-runner master + cd $DEST/tcmu-runner + if is_fedora; then + # we can run the install extras from tcmu-runner here + extra/install_dep.sh + fi + + cmake -Dwith-glfs=false -Dwith-qcow=false -DSUPPORT_SYSTEMD=on -DCMAKE_INSTALL_PREFIX=/usr + sudo make install + + pip_install rtslib-fb + pip_install configshell-fb + + # not in pypi yet. + git_clone $TARGETCLI_REPO $DEST/targetcli-fb master + cd $DEST/targetcli-fb + sudo python setup.py install + if [ ! -d /etc/target ]; then + sudo mkdir /etc/target + fi + if [ ! -d /var/target ]; then + sudo mkdir /var/target + fi + + git_clone $CEPH_ISCSI_REPO $DEST/ceph-iscsi master + cd $DEST/ceph-iscsi + sudo python setup.py install --install-scripts=/usr/bin + sudo cp usr/lib/systemd/system/rbd-target-gw.service /lib/systemd/system + sudo cp usr/lib/systemd/system/rbd-target-api.service /lib/systemd/system + + cd $CWD +} + function setup_packages_for_manila_on_ubuntu { # The 'apt' package manager needs the following package to access # HTTPS enabled repositories such as the Ceph repos hosted by the @@ -997,6 +1144,21 @@ function install_ceph { CEPH_PACKAGES="${CEPH_PACKAGES} radosgw" fi + if [ "$ENABLE_CEPH_ISCSI" = "True" ]; then + CEPH_PACKAGES="${CEPH_PACKAGES} python-pyparsing python-kmodpy python-pyudev" + CEPH_PACKAGES="${CEPH_PACKAGES} python-gobject python-urwid python-rados python-rbd" + CEPH_PACKAGES="${CEPH_PACKAGES} python-netifaces python-crypto python-requests python-flask" + CEPH_PACKAGES="${CEPH_PACKAGES} python-openssl python-rpm open-iscsi" + + # The packages needed to build tcmu-runner, since there is no + # ubuntu package yet. + CEPH_PACKAGES="${CEPH_PACKAGES} cmake make gcc libnl-genl-3-200" + CEPH_PACKAGES="${CEPH_PACKAGES} librbd1 librbd-dev libglib2.0-0 libglib2.0-bin zlib1g" + CEPH_PACKAGES="${CEPH_PACKAGES} libkmod2 libnl-genl-3-dev libglib2.0-dev" + CEPH_PACKAGES="${CEPH_PACKAGES} zlib1g-dev libkmod-dev" + CEPH_PACKAGES="${CEPH_PACKAGES} libgoogle-perftools4 libgoogle-perftools-dev" + fi + # Update package repo. REPOS_UPDATED=False install_package ${CEPH_PACKAGES} @@ -1021,10 +1183,21 @@ function install_ceph { CEPH_PACKAGES="${CEPH_PACKAGES} ceph-radosgw" fi + if [ "$ENABLE_CEPH_ISCSI" = "True" ]; then + CEPH_PACKAGES="${CEPH_PACKAGES} librbd1 libkmod2 python-pyparsing python-kmod python-pyudev" + CEPH_PACKAGES="${CEPH_PACKAGES} python-gobject python-urwid python-rados python-rbd" + CEPH_PACKAGES="${CEPH_PACKAGES} python-netifaces python-crypto python-requests python-flask" + CEPH_PACKAGES="${CEPH_PACKAGES} python-openssl iscsi-initiator-utils" + fi + install_package ${CEPH_PACKAGES} else die $LINENO "${os_VENDOR} is not supported by the Ceph plugin for Devstack" fi + + if [ "$ENABLE_CEPH_ISCSI" = "True" ]; then + setup_packages_for_iscsi + fi } # start_ceph() - Start running processes, including screen @@ -1058,6 +1231,10 @@ function start_ceph { if is_ceph_enabled_for_service manila; then sudo systemctl start ceph-mds@${MDS_ID} fi + + if [ "$ENABLE_CEPH_ISCSI" = "True" ]; then + start_ceph_iscsi + fi else sudo service ceph start fi @@ -1078,6 +1255,9 @@ function stop_ceph { if [ "$ENABLE_CEPH_RGW" = "True" ]; then sudo systemctl stop ceph-radosgw@rgw.$(hostname) fi + if [ "$ENABLE_CEPH_ISCSI" = "True" ]; then + stop_ceph_iscsi + fi if is_ceph_enabled_for_service manila; then sudo systemctl stop ceph-mds@${MDS_ID} if [ $MANILA_CEPH_DRIVER == 'cephfsnfs' ]; then