Skip to content

Commit

Permalink
Merge pull request #4 from ggtakec/update_codes
Browse files Browse the repository at this point in the history
Added an option to specify a block device when launching VM
  • Loading branch information
ggtakec authored Apr 8, 2021
2 parents 48ed01f + 206df3c commit c2de36c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/libexec/database/command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@ elif [ "X${K2HR3CLI_SUBCOMMAND}" = "X${_DATABASE_COMMAND_SUB_ADD}" ]; then
"${K2HR3CLI_OPENSTACK_FLAVOR_ID}" \
"${_DATABASE_ADD_HOST_USD64}" \
"${K2HR3CLI_OPENSTACK_KEYPAIR}" \
"${_DATABASE_ADD_HOST_SECGRP}")
"${_DATABASE_ADD_HOST_SECGRP}" \
"${K2HR3CLI_OPENSTACK_BCLOKDEVICE}")

#
# Create Virtual Machine
Expand Down
21 changes: 21 additions & 0 deletions src/libexec/database/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ dbaas_create_role_token()
# $4 : user data
# $5 : keypair name(allow empty)
# $6 : security group name(allow empty)
# $7 : block device mapping parameter(optional)
# $? : result
# Output : json post data for launching host
#
Expand Down Expand Up @@ -574,6 +575,11 @@ dbaas_get_openstack_launch_post_data()
else
_DBAAS_LAUNCH_DATA_SECGRP=$6
fi
if [ "X$7" = "X" ]; then
_DBAAS_LAUNCH_DATA_BLOCKDEVICE=""
else
_DBAAS_LAUNCH_DATA_BLOCKDEVICE=$7
fi

#
# Check template file
Expand Down Expand Up @@ -657,10 +663,25 @@ dbaas_get_openstack_launch_post_data()
#
_DBAAS_LAUNCH_DATA_KEYPAIR="\"key_name\":\"${_DBAAS_LAUNCH_DATA_KEYPAIR}\","
fi
if [ "X${_DBAAS_LAUNCH_DATA_BLOCKDEVICE}" != "X" ]; then
#
# Set Block Device Mapping(v2)
# "block_device_mapping_v2":[{
# "boot_index":"0",
# "uuid":"f50825f7-da8e-4637-aa11-772ca964fe75",
# "source_type":"image",
# "volume_size":"40",
# "destination_type":"volume",
# "delete_on_termination":true
# }],
#
_DBAAS_LAUNCH_DATA_BLOCKDEVICE="\"block_device_mapping_v2\":${_DBAAS_LAUNCH_DATA_BLOCKDEVICE},"
fi

_DATABASE_CREATE_HOST_DATA=$(pecho -n "${_DATABASE_CREATE_HOST_DATA}" | sed \
-e "s|__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_SECGRP_SET__|${_DBAAS_LAUNCH_DATA_SECGRP}|" \
-e "s|__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_KEYPAIR_SET__|${_DBAAS_LAUNCH_DATA_KEYPAIR}|" \
-e "s|__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_BLOCKDEVICE_SET__|${_DBAAS_LAUNCH_DATA_BLOCKDEVICE}|" \
-e "s|__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_SERVER_NAME__|${_DBAAS_LAUNCH_DATA_SERVER_NAME}|" \
-e "s|__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_IMAGE_ID__|${_DBAAS_LAUNCH_DATA_IMAGE_ID}|" \
-e "s|__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_FLAVOR_ID__|${_DBAAS_LAUNCH_DATA_FLAVOR_ID}|" \
Expand Down
23 changes: 22 additions & 1 deletion src/libexec/database/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ echo " ${K2HR3CLI_COMMAND_OPT_OPENSTACK_FLAVOR_LONG} <flavor name>"
echo " ${K2HR3CLI_COMMAND_OPT_OPENSTACK_FLAVOR_ID_LONG} <flavor id>"
echo " ${K2HR3CLI_COMMAND_OPT_OPENSTACK_IMAGE_LONG} <image name>"
echo " ${K2HR3CLI_COMMAND_OPT_OPENSTACK_IMAGE_ID_LONG} <image id>"
echo " ${K2HR3CLI_COMMAND_OPT_OPENSTACK_BLOCKDEVICE_LONG} <block device mapping json string parameter>"
echo ""
echo "DELETE HOST: Delete Host from Cluster"
echo " This command is used to delete hosts from K2HDKC Cluster."
Expand Down Expand Up @@ -153,7 +154,6 @@ echo ""
echo " ${BINNAME} ${K2HR3CLI_MODE} list [images|flavors] <option...>"
echo " ${K2HR3CLI_COMMAND_OPT_OPENSTACK_TENANT_LONG} <openstack tenant>"
echo ""
# +---+----+----+----+----+----+----+----+----+----+----+----+----|
echo "COMMON OPTION:"
echo " The following options are available for all commands."
echo " Options related to URIs can be stored in configuration."
Expand Down Expand Up @@ -246,6 +246,27 @@ echo ""
echo " ${K2HR3CLI_COMMAND_OPT_OPENSTACK_IMAGE_ID_LONG}"
echo " Specifies the id of the OS Image that boots the host."
echo ""
echo " ${K2HR3CLI_COMMAND_OPT_OPENSTACK_BLOCKDEVICE_LONG}"
echo " Specifies the block device parameters that you specify"
echo " when you start the virtual host."
echo " This option depends on the OpenStack system that works"
echo " with the K2HR3 system and can be omitted."
echo " Check with your OpenStack system administrator to see"
echo " if you need to specify a block device."
echo " This corresponds to the \"block_device_mapping_v2\""
echo " parameter of the OpenStack Compute API."
echo " Specify the object shown below as a JSON string."
echo " [{"
echo " \"boot_index\": \"0\","
echo " \"uuid\": \"<image id>\","
echo " \"source_type\": \"image\","
echo " \"volume_size\": \"<size GB>\","
echo " \"destination_type\": \"volume\","
echo " \"delete_on_termination\": true,"
echo " \"tag\": \"disk1\","
echo " \"disk_bus\": \"scsi\""
echo " }]"
echo ""
echo " ${K2HR3CLI_COMMAND_OPT_OPENSTACK_USER_LONG}"
echo " Specifies the OpenStack user name for credential"
echo " authentication."
Expand Down
1 change: 1 addition & 0 deletions src/libexec/database/k2hdkc_dbaas_create_host.templ
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"server":{
__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_SECGRP_SET__
__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_KEYPAIR_SET__
__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_BLOCKDEVICE_SET__
"name":"__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_SERVER_NAME__",
"imageRef":"__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_IMAGE_ID__",
"flavorRef":"__K2HDKC_DBAAS_LAUNCH_VM_TEMPLATE_FLAVOR_ID__",
Expand Down
22 changes: 22 additions & 0 deletions src/libexec/database/options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ K2HR3CLI_COMMAND_OPT_OPENSTACK_FLAVOR_LONG="--op_flavor"
K2HR3CLI_COMMAND_OPT_OPENSTACK_FLAVOR_ID_LONG="--op_flavor_id"
K2HR3CLI_COMMAND_OPT_OPENSTACK_IMAGE_LONG="--op_image"
K2HR3CLI_COMMAND_OPT_OPENSTACK_IMAGE_ID_LONG="--op_image_id"
K2HR3CLI_COMMAND_OPT_OPENSTACK_BLOCKDEVICE_LONG="--op_block_device"
K2HR3CLI_COMMAND_OPT_OPENSTACK_CONFIRM_YES_SHORT="-y"
K2HR3CLI_COMMAND_OPT_OPENSTACK_CONFIRM_YES_LONG="--yes"

Expand Down Expand Up @@ -87,6 +88,7 @@ K2HR3CLI_COMMAND_OPT_DBAAS_DEFALT_SLAVE_CTLPORT=8031
# K2HR3CLI_OPENSTACK_FLAVOR_ID : --op_flavor_id
# K2HR3CLI_OPENSTACK_IMAGE : --op_image
# K2HR3CLI_OPENSTACK_IMAGE_ID : --op_image_id
# K2HR3CLI_OPENSTACK_BCLOKDEVICE : --op_block_device
# K2HR3CLI_OPENSTACK_CONFIRM_YES : --yes(-y)
#
parse_dbaas_option()
Expand Down Expand Up @@ -114,6 +116,7 @@ parse_dbaas_option()
_OPT_TMP_DBAAS_OPENSTACK_FLAVOR_ID=
_OPT_TMP_DBAAS_OPENSTACK_IMAGE=
_OPT_TMP_DBAAS_OPENSTACK_IMAGE_ID=
_OPT_TMP_DBAAS_OPENSTACK_BLOCKDEVICE=
_OPT_TMP_DBAAS_OPENSTACK_CONFIRM_YES=

K2HR3CLI_OPTION_PARSER_REST=""
Expand Down Expand Up @@ -390,6 +393,18 @@ parse_dbaas_option()
_OPT_TMP_DBAAS_OPENSTACK_IMAGE_ID=$(cut_special_words "$1" | sed -e 's/%20/ /g' -e 's/%25/%/g')
_OPT_TMP_DBAAS_OPENSTACK_IMAGE_ID=$(filter_null_string "${_OPT_TMP_DBAAS_OPENSTACK_IMAGE_ID}")

elif [ "X${_OPTION_TMP}" = "X${K2HR3CLI_COMMAND_OPT_OPENSTACK_BLOCKDEVICE_LONG}" ]; then
if [ -n "${_OPT_TMP_DBAAS_OPENSTACK_BLOCKDEVICE}" ]; then
prn_err "already specified ${K2HR3CLI_COMMAND_OPT_OPENSTACK_BLOCKDEVICE_LONG} option."
return 1
fi
shift
if [ $# -le 0 ]; then
prn_err "${K2HR3CLI_COMMAND_OPT_OPENSTACK_BLOCKDEVICE_LONG} option needs parameter."
return 1
fi
_OPT_TMP_DBAAS_OPENSTACK_BLOCKDEVICE=$(cut_special_words "$1" | sed -e 's/%20/ /g' -e 's/%25/%/g')

elif [ "X${_OPTION_TMP}" = "X${K2HR3CLI_COMMAND_OPT_OPENSTACK_CONFIRM_YES_LONG}" ] || [ "X${_OPTION_TMP}" = "X${K2HR3CLI_COMMAND_OPT_OPENSTACK_CONFIRM_YES_SHORT}" ]; then
if [ -n "${_OPT_TMP_DBAAS_OPENSTACK_CONFIRM_YES}" ]; then
prn_err "already specified ${K2HR3CLI_COMMAND_OPT_OPENSTACK_CONFIRM_YES_LONG}(${K2HR3CLI_COMMAND_OPT_OPENSTACK_CONFIRM_YES_SHORT}) option."
Expand Down Expand Up @@ -538,6 +553,13 @@ parse_dbaas_option()
# shellcheck disable=SC2034
K2HR3CLI_OPENSTACK_IMAGE_ID=""
fi
if [ -n "${_OPT_TMP_DBAAS_OPENSTACK_BLOCKDEVICE}" ]; then
# shellcheck disable=SC2034
K2HR3CLI_OPENSTACK_BCLOKDEVICE=${_OPT_TMP_DBAAS_OPENSTACK_BLOCKDEVICE}
else
# shellcheck disable=SC2034
K2HR3CLI_OPENSTACK_BCLOKDEVICE=""
fi
if [ -n "${_OPT_TMP_DBAAS_OPENSTACK_CONFIRM_YES}" ]; then
# shellcheck disable=SC2034
K2HR3CLI_OPENSTACK_CONFIRM_YES=${_OPT_TMP_DBAAS_OPENSTACK_CONFIRM_YES}
Expand Down

0 comments on commit c2de36c

Please sign in to comment.