Add in support for fullnode customers to folders in userbuckets
This commit is contained in:
parent
d09dc50d0f
commit
e9e70c5b29
2 changed files with 42 additions and 8 deletions
|
@ -19,6 +19,18 @@ class sunetdrive::script (
|
||||||
$local_path = '/tmp/rclone-current-linux-amd64.deb'
|
$local_path = '/tmp/rclone-current-linux-amd64.deb'
|
||||||
$singlenodes = hiera('singlenodes')
|
$singlenodes = hiera('singlenodes')
|
||||||
|
|
||||||
|
if $customer == 'mdu' {
|
||||||
|
$eppn_suffix = 'mdh.se'
|
||||||
|
$include_userbuckets = 'true'
|
||||||
|
} elsif $customer == 'uu' {
|
||||||
|
$eppn_suffix = 'users.uu.se'
|
||||||
|
$include_userbuckets = 'false'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$eppn_suffix = "${customer}.se"
|
||||||
|
$include_userbuckets = 'false'
|
||||||
|
}
|
||||||
|
|
||||||
$ssh_config = "Host *.sunet.se
|
$ssh_config = "Host *.sunet.se
|
||||||
User script
|
User script
|
||||||
IdentityFile /root/.ssh/id_script"
|
IdentityFile /root/.ssh/id_script"
|
||||||
|
@ -253,25 +265,31 @@ class sunetdrive::script (
|
||||||
}
|
}
|
||||||
# Opt in to folder structure in projectbuckets
|
# Opt in to folder structure in projectbuckets
|
||||||
if $customer in ['gih', 'mdu'] {
|
if $customer in ['gih', 'mdu'] {
|
||||||
|
sunet::scriptherder::cronjob { 'create_folders_in_project_buckets':
|
||||||
|
ensure => absent,
|
||||||
|
}
|
||||||
file { '/root/tasks/create_folders_in_project_buckets.sh':
|
file { '/root/tasks/create_folders_in_project_buckets.sh':
|
||||||
|
ensure => absent,
|
||||||
|
}
|
||||||
|
file { '/root/tasks/create_folders_in_fullnode_buckets.sh':
|
||||||
ensure => file,
|
ensure => file,
|
||||||
content => template('sunetdrive/script/create_folders_in_project_buckets.erb.sh'),
|
content => template('sunetdrive/script/create_folders_in_fullnode_buckets.erb.sh'),
|
||||||
owner => 'root',
|
owner => 'root',
|
||||||
group => 'root',
|
group => 'root',
|
||||||
mode => '0700',
|
mode => '0700',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if $customer in ['gih'] {
|
if $customer in ['gih'] {
|
||||||
sunet::scriptherder::cronjob { 'create_folders_in_project_buckets':
|
sunet::scriptherder::cronjob { 'create_folders_in_fullnode_buckets':
|
||||||
cmd => '/root/tasks/create_folders_in_project_buckets.sh',
|
cmd => '/root/tasks/create_folders_in_fullnode_buckets.sh',
|
||||||
minute => '*/30',
|
minute => '*/30',
|
||||||
ok_criteria => ['exit_status=0','max_age=1h'],
|
ok_criteria => ['exit_status=0','max_age=1h'],
|
||||||
warn_criteria => ['exit_status=1','max_age=2h'],
|
warn_criteria => ['exit_status=1','max_age=2h'],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if $customer in ['mdu'] {
|
if $customer in ['mdu'] {
|
||||||
sunet::scriptherder::cronjob { 'create_folders_in_project_buckets':
|
sunet::scriptherder::cronjob { 'create_folders_in_fullnode_buckets':
|
||||||
cmd => '/root/tasks/create_folders_in_project_buckets.sh "Arbetsmaterial (work material)" "Bevarande (retention)" "Gallringsbart (disposal)"',
|
cmd => '/root/tasks/create_folders_in_fullnodde_buckets.sh "Arbetsmaterial (work material)" "Bevarande (retention)" "Gallringsbart (disposal)"',
|
||||||
minute => '*/30',
|
minute => '*/30',
|
||||||
ok_criteria => ['exit_status=0','max_age=1h'],
|
ok_criteria => ['exit_status=0','max_age=1h'],
|
||||||
warn_criteria => ['exit_status=1','max_age=2h'],
|
warn_criteria => ['exit_status=1','max_age=2h'],
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
customer="<%= @customer %>"
|
customer="<%= @customer %>"
|
||||||
environment="<%= @environment %>"
|
environment="<%= @environment %>"
|
||||||
|
eppn_suffix="<%= @eppn_suffix %>"
|
||||||
|
include_userbuckets="<%= @include_userbuckets %>"
|
||||||
container="nextcloud_app_1"
|
container="nextcloud_app_1"
|
||||||
yq="/usr/local/bin/yq"
|
yq="/usr/local/bin/yq"
|
||||||
if ! [[ -x ${yq} ]]; then
|
if ! [[ -x ${yq} ]]; then
|
||||||
|
@ -16,12 +18,20 @@ else
|
||||||
directories+=("Bevarande")
|
directories+=("Bevarande")
|
||||||
directories+=("Gallringsbart")
|
directories+=("Gallringsbart")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
olddir="${PWD}"
|
olddir="${PWD}"
|
||||||
tempdir=$(mktemp -d)
|
tempdir=$(mktemp -d)
|
||||||
dirty=0
|
dirty=0
|
||||||
|
primary=''
|
||||||
|
declare -a users=( 'admin' )
|
||||||
cd "${tempdir}" || echo "Could not cd to tempdir"
|
cd "${tempdir}" || echo "Could not cd to tempdir"
|
||||||
for project in $(${yq} -r '.project_mapping.'"${customer}"'.'"${environment}"'.assigned | "\(.[].project)"' /etc/hiera/data/common.yaml); do
|
declare -a projects=( "${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.assigned | "\(.[].project)"' /etc/hiera/data/common.yaml )
|
||||||
for bucket in $(rclone lsd "${project}:" | awk '{print $NF}'); do
|
if [[ "${include_userbuckets}" == "true" ]]; then
|
||||||
|
primary=$("${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.primary_project' /etc/hiera/data/common.yaml)
|
||||||
|
projects+=( "${primary}" )
|
||||||
|
fi
|
||||||
|
for project in "${projects[@]}"; do
|
||||||
|
for bucket in $(rclone lsd "${project}:" | awk '{print $NF}' | grep -E -v '^primary'); do
|
||||||
count=$(rclone size --json "${project}:${bucket}" | jq -r .count)
|
count=$(rclone size --json "${project}:${bucket}" | jq -r .count)
|
||||||
if [[ ${count} -gt 0 ]]; then
|
if [[ ${count} -gt 0 ]]; then
|
||||||
echo "Skipping ${project}:${bucket} because it has stuff in it already"
|
echo "Skipping ${project}:${bucket} because it has stuff in it already"
|
||||||
|
@ -29,6 +39,10 @@ for project in $(${yq} -r '.project_mapping.'"${customer}"'.'"${environment}"'.a
|
||||||
fi
|
fi
|
||||||
for directory in "${directories[@]}"; do
|
for directory in "${directories[@]}"; do
|
||||||
dirty=1
|
dirty=1
|
||||||
|
if [[ -n ${primary} ]] && [[ ${project} == "${primary}" ]] ; then
|
||||||
|
user=$(echo "${bucket}" | awk -F '-' '{print $0}')
|
||||||
|
users+=( "${user}@${eppn_suffix}" )
|
||||||
|
fi
|
||||||
echo "Creating ${project}:${bucket}/${directory} because it looks nice and empty"
|
echo "Creating ${project}:${bucket}/${directory} because it looks nice and empty"
|
||||||
temp="README.md"
|
temp="README.md"
|
||||||
echo "**${directory}**" >"${temp}"
|
echo "**${directory}**" >"${temp}"
|
||||||
|
@ -40,5 +54,7 @@ done
|
||||||
cd "${olddir}" || echo "could not cd to home dir"
|
cd "${olddir}" || echo "could not cd to home dir"
|
||||||
rmdir "${tempdir}"
|
rmdir "${tempdir}"
|
||||||
if [[ ${dirty} -gt 0 ]]; then
|
if [[ ${dirty} -gt 0 ]]; then
|
||||||
ssh -t "node3.$(hostname -d)" -l script -i .ssh/id_script "sudo /usr/local/bin/occ ${container} files:scan admin"
|
for user in "${users[@]}"; do
|
||||||
|
ssh -t "node3.$(hostname -d)" -l script -i .ssh/id_script "sudo /usr/local/bin/occ ${container} files:scan ${user}"
|
||||||
|
done
|
||||||
fi
|
fi
|
Loading…
Add table
Reference in a new issue