-
Notifications
You must be signed in to change notification settings - Fork 4
/
allas-list-all
executable file
·123 lines (100 loc) · 2.71 KB
/
allas-list-all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
#read static variables
inst_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $inst_root/a_env_conf
source $inst_root/allas-lib
#allas_conf_path=("/home/kkmattil/allas-cli-utils/allas_conf")
export OS_USERNAME=$(whoami)
export OS_AUTH_URL=https://pouta.csc.fi:5001/v3
export OS_USER_DOMAIN_NAME="Default"
export OS_REGION_NAME="regionOne"
export OS_INTERFACE=public
export OS_IDENTITY_API_VERSION=3
#store swift authentication if it is done
if [ -n "$OS_AUTH_TOKEN" ]
then
ORIG_OS_AUTH_TOKEN=("$OS_AUTH_TOKEN")
fi
if [ -n "$OS_STORAGE_URL" ]
then
ORIG_OS_STORAGE_UR=("$OS_STORAGE_URL")
fi
buk=(1)
usage="
allas-list-all lists all buckets or objects that user has in
Allas. By default only buckets are listed for the current username.
OPTIONS
-o, --objects Show all objects in addition to just bucket names.
-u, --user Define username for Allas.
"
while [[ $# -ge 1 ]]
do
case "$1" in
'-o' | '--objects')
buk=(0)
shift
;;
'-u' | '--user')
export OS_USERNAME=$2
shift
shift
;;
'-k' | '--keeppasswd')
keep_password=(1)
shift
;;
'-h' | '--help')
echo "$usage"
exit 0
shift
;;
*)
export OS_PROJECT_NAME=$1
shift # No more switches
;;
esac
done
if [ -z "$OS_PASSWORD" ]; then
echo "Please enter CSC password for account ${OS_USERNAME}: "
read -sr OS_PASSWORD_INPUT
export OS_PASSWORD=$OS_PASSWORD_INPUT
fi
echo "Collecting project list. Please wait."
openstack project list --my-projects -c Name -f value
all_projects=$(openstack project list --my-projects -c Name -f value)
if [ $buk -eq 1 ]; then
echo ""
echo "Listing all buckets in all projects."
echo ""
else
echo ""
echo "Listing all objects in all projects."
echo ""
fi
for pro in $all_projects
do
echo "-----------------------------------------------"
projnum=$( echo $pro | sed -e s/"project_"/""/g | sed -e s/"Project_"/""/g )
saldo -p $projnum 2> /dev/null | grep "^Project"
source $allas_conf_path -f --silent --keeppasswd $pro
for kont in $(swift list )
do
if [ $buk -ne 1 ]; then
for obj in $(swift list $kont)
do
echo "${pro}:${kont}/$obj"
done
else
echo "${pro}:${kont}"
fi
done
done
#store swift authentication if it is done
if [ -n "$ORIG_OS_AUTH_TOKEN" ]
then
export OS_AUTH_TOKEN=("$ORIG_OS_AUTH_TOKEN")
fi
if [ -n "$ORIG_OS_STORAGE_URL" ]
then
export OS_STORAGE_URL=("$ORIG_OS_STORAGE_URL")
fi