Skip to content

Commit

Permalink
Merge pull request #46 from tdviet/devel
Browse files Browse the repository at this point in the history
Clean site config directory before saving config
  • Loading branch information
tdviet authored Jul 3, 2021
2 parents abe143f + e4e67c5 commit c265fc2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/list-all-my-own-vms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ if [[ $VO == "UNKNOWN" ]]; then
exit 1
fi

# Get list of all sites
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" &
done
Expand Down
3 changes: 2 additions & 1 deletion examples/list-my-own-vms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ 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,
# 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
fi
Expand Down
12 changes: 12 additions & 0 deletions fedcloudclient/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import builtins
import json
import shutil
from pathlib import Path
from typing import List
from urllib.request import Request, urlopen
Expand Down Expand Up @@ -159,6 +160,16 @@ def save_site_config(config_dir):
yaml.dump(site_info, f)


def delete_site_config(config_dir):
"""
Delete site configs to local directory specified in config_dir.
:param config_dir: path to directory containing site configuration
:return: None
"""
shutil.rmtree(config_dir, ignore_errors=True)


def list_sites():
"""
List of all sites IDs in site configurations
Expand Down Expand Up @@ -271,6 +282,7 @@ def save_config():
read_default_site_config()
config_dir = Path.home() / __LOCAL_CONFIG_DIR
print("Saving site configs to directory %s" % config_dir)
delete_site_config(config_dir)
save_site_config(config_dir)


Expand Down

0 comments on commit c265fc2

Please sign in to comment.