Skip to content

Commit

Permalink
Merge pull request #47 from tdviet/devel
Browse files Browse the repository at this point in the history
Add list VMs scripts to setup.cfg
  • Loading branch information
tdviet authored Jul 3, 2021
2 parents c265fc2 + 78d7d33 commit 9f90227
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 3 additions & 4 deletions examples/list-all-my-own-vms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ cat << EOF
Usage: ${0##*/} [-h] --vo <VO>
List all VMs owned by the user in the given VO on all sites in EGI Cloud federation
Arguments:
-h, --help, help Display this help message and exit
--vo VO : VO name
-h, --help, help : Display this help message and exit
--vo <VO> : VO name
EOF
}

Expand Down Expand Up @@ -61,7 +61,6 @@ SITES=$(fedcloud site list)

# and call list-my-own-vms.sh script for each site in parallel
for SITE in $SITES; do
./list-my-own-vms.sh --site "$SITE" --vo "$VO" &
list-my-own-vms.sh --site "$SITE" --vo "$VO" &
done
wait

18 changes: 10 additions & 8 deletions examples/list-my-own-vms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ cat << EOF
Usage: ${0##*/} [-h] --site <SITE> --vo <VO>
List all VMs owned by the user in the given VO/site
Arguments:
-h, --help, help Display this help message and exit
--site SITE : Site name
--vo VO : VO name
-h, --help, help : Display this help message and exit
--site <SITE> : Site name
--vo <VO> : VO name
EOF
}

Expand Down Expand Up @@ -77,21 +77,23 @@ fi
# shellcheck disable=SC2086
LIST_ALL_VM=$(fedcloud openstack server list --site $SITE --vo $VO $COLUMNS -c "User ID" --json-output)

# for usability, ignore the site and print nothing if some errors occur in openstack commands,
# For cleanliness of outputs, ignore the site if some errors occur in openstack commands,
# mostly because the VO is not supported on the site
error_code=$(echo "$LIST_ALL_VM" | jq -r '.[]."Error code"')
if [ "$error_code" != "0" ]; then
exit 0
exit 0
fi

# Get local User ID on the site
USER_ID=$(fedcloud openstack token issue -c user_id -f value --site "$SITE" --vo "$VO" 2> /dev/null)

# Select only VMs with the User ID
# Select only VMs with the User ID and store whole JSON in output
# For printing outputs in other format, just change the last part of jq outputs in the command bellow
# eg. for printing only VM name: jq -r '.[].Result | map(select(."User ID" == "'$USER_ID'")) | .[].Name')
# shellcheck disable=SC2086
LIST_OWN_VM=$(echo $LIST_ALL_VM | jq -r '.[].Result | map(select(."User ID" == "'$USER_ID'")) | .')

# Only print non-empty list
# Only print non-empty list for cleaner outputs
if [ "$LIST_OWN_VM" != "[]" ]; then
printf "List of VMs on site %s:\n%s\n" "$SITE" "$LIST_OWN_VM"
printf "List of VMs on site %s:\n%s\n" "$SITE" "$LIST_OWN_VM"
fi
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ setup_hooks =
packages =
fedcloudclient

scripts =
./examples/list-my-own-vms.sh
./examples/list-all-my-own-vms.sh

[entry_points]
console_scripts =
fedcloud= fedcloudclient.cli:cli
Expand Down

0 comments on commit 9f90227

Please sign in to comment.