Alon Bar-Lev has uploaded a new change for review. Change subject: db: cleanup: move entity lock to unlock_entity script ......................................................................
db: cleanup: move entity lock to unlock_entity script Change-Id: I5c62a8ada1ff93687cc2041d5df7bb6c1921a4af Signed-off-by: Alon Bar-Lev <[email protected]> --- M packaging/dbscripts/dbfunc-common.sh M packaging/dbscripts/unlock_entity.sh 2 files changed, 146 insertions(+), 155 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/24/25224/1 diff --git a/packaging/dbscripts/dbfunc-common.sh b/packaging/dbscripts/dbfunc-common.sh index 174a84f..ab78fb8 100644 --- a/packaging/dbscripts/dbfunc-common.sh +++ b/packaging/dbscripts/dbfunc-common.sh @@ -85,135 +85,6 @@ )" } -#unlocks the given VM/Template and its disks or a given disk -#in case of VM/Template the id is the name, in case of a disk, the id is the disk UUID -dbfunc_common_entity_unlock() { - local object_type="$1" - local id="$2" - local user="$3" - local recursive="$4" - [ -z "${recursive}" ] && recursive=false || recursive=true - local CMD="" - if [ "${object_type}" = "vm" -o "${object_type}" = "template" ]; then - CMD="select fn_db_unlock_entity('${object_type}', '${id}', ${recursive});" - elif [ "${object_type}" = "disk" ]; then - CMD="select fn_db_unlock_disk('${id}');" - elif [ "${object_type}" = "snapshot" ]; then - CMD="select fn_db_unlock_snapshot('${id}');" - else - printf "Error: $* " - fi - - if [ -n "${CMD}" ]; then - echo "${CMD}" - if dbfunc_psql --command="${CMD}"; then - _dbfunc_common_log_unlock_entity ${object_type} ${id} ${user} - echo "unlock ${object_type} ${id} completed successfully." - else - echo "unlock ${object_type} ${id} completed with errors." - fi - fi -} - -#Displays locked entities -dbfunc_common_entity_query() { - local object_type="$1" - local LOCKED=2 - local TEMPLATE_LOCKED=1 - local IMAGE_LOCKED=15; - local SNAPSHOT_LOCKED=LOCKED - local CMD - if [ "${object_type}" = "vm" ]; then - dbfunc_psql_die --command=" - select - vm_name as vm_name - from - vm_static a, - vm_dynamic b - where - a.vm_guid = b.vm_guid and - status = ${IMAGE_LOCKED}; - - select - vm_name as vm_name, - image_group_id as disk_id - from - images a, - vm_static b, - vm_device c - where - a.image_group_id = c.device_id and - b.vm_guid = c.vm_id and - imagestatus = ${LOCKED} and - entity_type ilike 'VM' and - image_group_id in ( - select device_id - from vm_device - where is_plugged - ); - - select - vm_name as vm_name, - snapshot_id as snapshot_id - from - vm_static a, - snapshots b - where - a.vm_guid = b.vm_id and - status ilike '${SNAPSHOT_LOCKED}'; - " - elif [ "${object_type}" = "template" ]; then - dbfunc_psql_die --command=" - select vm_name as template_name - from vm_static - where template_status = ${TEMPLATE_LOCKED}; - - select - vm_name as template_name, - image_group_id as disk_id - from - images a, - vm_static b, - vm_device c - where - a.image_group_id = c.device_id and - b.vm_guid = c.vm_id and - imagestatus = ${LOCKED} and - entity_type ilike 'TEMPLATE' and - image_group_id in ( - select device_id - from vm_device - where is_plugged - ); - " - elif [ "${object_type}" = "disk" ]; then - dbfunc_psql_die --command=" - select - vm_id as entity_id, - disk_id - from - base_disks a, - images b, - vm_device c - where - a.disk_id = b.image_group_id and - b.image_group_id = c.device_id and - imagestatus = ${LOCKED} and - is_plugged; - " - elif [ "${object_type}" = "snapshot" ]; then - dbfunc_psql_die --command=" - select - vm_id as entity_id, - snapshot_id - from - snapshots a - where - status ilike '${SNAPSHOT_LOCKED}'; - " - fi -} - _dbfunc_common_schema_refresh_drop() { _dbfunc_common_views_drop _dbfunc_common_sps_drop @@ -542,28 +413,4 @@ [ "${ver}" != "${prev}" ] || die "Operation aborted, found duplicate version: ${ver}" prev="${ver}" done || exit $? -} - -#adds a record to audit_log in case of calling unlock_entity -_dbfunc_common_log_unlock_entity() { - local object_type="$1" - local id="$2" - local user="$3" - - dbfunc_psql_die --command=" - insert into audit_log( - log_time, - log_type_name, - log_type, - severity, - message - ) - values( - now(), - 'USER_RUN_UNLOCK_ENTITY_SCRIPT', - 2024, - 10, - 'System user ${user} run unlock_entity script on ${object_type} ${id} with db user ${DBUTILS_DB_USER}}' - ) - " } diff --git a/packaging/dbscripts/unlock_entity.sh b/packaging/dbscripts/unlock_entity.sh index 61180f7..8566214 100755 --- a/packaging/dbscripts/unlock_entity.sh +++ b/packaging/dbscripts/unlock_entity.sh @@ -28,6 +28,150 @@ __EOF__ } +#unlocks the given VM/Template and its disks or a given disk +#in case of VM/Template the id is the name, in case of a disk, the id is the disk UUID +entity_unlock() { + local object_type="$1" + local id="$2" + local user="$3" + local recursive="$4" + [ -z "${recursive}" ] && recursive=false || recursive=true + local CMD="" + if [ "${object_type}" = "vm" -o "${object_type}" = "template" ]; then + CMD="select fn_db_unlock_entity('${object_type}', '${id}', ${recursive});" + elif [ "${object_type}" = "disk" ]; then + CMD="select fn_db_unlock_disk('${id}');" + elif [ "${object_type}" = "snapshot" ]; then + CMD="select fn_db_unlock_snapshot('${id}');" + else + printf "Error: $* " + fi + + if [ -n "${CMD}" ]; then + echo "${CMD}" + if dbfunc_psql --command="${CMD}"; then + dbfunc_psql_die --command=" + insert into audit_log( + log_time, + log_type_name, + log_type, + severity, + message + ) + values( + now(), + 'USER_RUN_UNLOCK_ENTITY_SCRIPT', + 2024, + 10, + 'System user ${user} run unlock_entity script on ${object_type} ${id} with db user ${DBUTILS_DB_USER}}' + ) + " + echo "unlock ${object_type} ${id} completed successfully." + else + echo "unlock ${object_type} ${id} completed with errors." + fi + fi +} + +#Displays locked entities +entity_query() { + local object_type="$1" + local LOCKED=2 + local TEMPLATE_LOCKED=1 + local IMAGE_LOCKED=15; + local SNAPSHOT_LOCKED=LOCKED + local CMD + if [ "${object_type}" = "vm" ]; then + dbfunc_psql_die --command=" + select + vm_name as vm_name + from + vm_static a, + vm_dynamic b + where + a.vm_guid = b.vm_guid and + status = ${IMAGE_LOCKED}; + + select + vm_name as vm_name, + image_group_id as disk_id + from + images a, + vm_static b, + vm_device c + where + a.image_group_id = c.device_id and + b.vm_guid = c.vm_id and + imagestatus = ${LOCKED} and + entity_type ilike 'VM' and + image_group_id in ( + select device_id + from vm_device + where is_plugged + ); + + select + vm_name as vm_name, + snapshot_id as snapshot_id + from + vm_static a, + snapshots b + where + a.vm_guid = b.vm_id and + status ilike '${SNAPSHOT_LOCKED}'; + " + elif [ "${object_type}" = "template" ]; then + dbfunc_psql_die --command=" + select vm_name as template_name + from vm_static + where template_status = ${TEMPLATE_LOCKED}; + + select + vm_name as template_name, + image_group_id as disk_id + from + images a, + vm_static b, + vm_device c + where + a.image_group_id = c.device_id and + b.vm_guid = c.vm_id and + imagestatus = ${LOCKED} and + entity_type ilike 'TEMPLATE' and + image_group_id in ( + select device_id + from vm_device + where is_plugged + ); + " + elif [ "${object_type}" = "disk" ]; then + dbfunc_psql_die --command=" + select + vm_id as entity_id, + disk_id + from + base_disks a, + images b, + vm_device c + where + a.disk_id = b.image_group_id and + b.image_group_id = c.device_id and + imagestatus = ${LOCKED} and + is_plugged; + " + elif [ "${object_type}" = "snapshot" ]; then + dbfunc_psql_die --command=" + select + vm_id as entity_id, + snapshot_id + from + snapshots a + where + status ilike '${SNAPSHOT_LOCKED}'; + " + fi +} + TYPE= RECURSIVE= QUERY= @@ -62,8 +206,8 @@ [ "${answer}" = "y" ] || die "Please contact support for further assistance." for ID in ${IDS} ; do - dbfunc_common_entity_unlock "${TYPE}" "${ID}" "$(whoami)" ${RECURSIVE} + entity_unlock "${TYPE}" "${ID}" "$(whoami)" ${RECURSIVE} done elif [ -n "${QUERY}" ]; then - dbfunc_common_entity_query "${TYPE}" + entity_query "${TYPE}" fi -- To view, visit http://gerrit.ovirt.org/25224 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5c62a8ada1ff93687cc2041d5df7bb6c1921a4af Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
