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'
|
||||
$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
|
||||
User script
|
||||
IdentityFile /root/.ssh/id_script"
|
||||
|
@ -253,25 +265,31 @@ class sunetdrive::script (
|
|||
}
|
||||
# Opt in to folder structure in projectbuckets
|
||||
if $customer in ['gih', 'mdu'] {
|
||||
sunet::scriptherder::cronjob { 'create_folders_in_project_buckets':
|
||||
ensure => absent,
|
||||
}
|
||||
file { '/root/tasks/create_folders_in_project_buckets.sh':
|
||||
ensure => absent,
|
||||
}
|
||||
file { '/root/tasks/create_folders_in_fullnode_buckets.sh':
|
||||
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',
|
||||
group => 'root',
|
||||
mode => '0700',
|
||||
}
|
||||
}
|
||||
if $customer in ['gih'] {
|
||||
sunet::scriptherder::cronjob { 'create_folders_in_project_buckets':
|
||||
cmd => '/root/tasks/create_folders_in_project_buckets.sh',
|
||||
sunet::scriptherder::cronjob { 'create_folders_in_fullnode_buckets':
|
||||
cmd => '/root/tasks/create_folders_in_fullnode_buckets.sh',
|
||||
minute => '*/30',
|
||||
ok_criteria => ['exit_status=0','max_age=1h'],
|
||||
warn_criteria => ['exit_status=1','max_age=2h'],
|
||||
}
|
||||
}
|
||||
if $customer in ['mdu'] {
|
||||
sunet::scriptherder::cronjob { 'create_folders_in_project_buckets':
|
||||
cmd => '/root/tasks/create_folders_in_project_buckets.sh "Arbetsmaterial (work material)" "Bevarande (retention)" "Gallringsbart (disposal)"',
|
||||
sunet::scriptherder::cronjob { 'create_folders_in_fullnode_buckets':
|
||||
cmd => '/root/tasks/create_folders_in_fullnodde_buckets.sh "Arbetsmaterial (work material)" "Bevarande (retention)" "Gallringsbart (disposal)"',
|
||||
minute => '*/30',
|
||||
ok_criteria => ['exit_status=0','max_age=1h'],
|
||||
warn_criteria => ['exit_status=1','max_age=2h'],
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
customer="<%= @customer %>"
|
||||
environment="<%= @environment %>"
|
||||
eppn_suffix="<%= @eppn_suffix %>"
|
||||
include_userbuckets="<%= @include_userbuckets %>"
|
||||
container="nextcloud_app_1"
|
||||
yq="/usr/local/bin/yq"
|
||||
if ! [[ -x ${yq} ]]; then
|
||||
|
@ -16,12 +18,20 @@ else
|
|||
directories+=("Bevarande")
|
||||
directories+=("Gallringsbart")
|
||||
fi
|
||||
|
||||
olddir="${PWD}"
|
||||
tempdir=$(mktemp -d)
|
||||
dirty=0
|
||||
primary=''
|
||||
declare -a users=( 'admin' )
|
||||
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
|
||||
for bucket in $(rclone lsd "${project}:" | awk '{print $NF}'); do
|
||||
declare -a projects=( "${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.assigned | "\(.[].project)"' /etc/hiera/data/common.yaml )
|
||||
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)
|
||||
if [[ ${count} -gt 0 ]]; then
|
||||
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
|
||||
for directory in "${directories[@]}"; do
|
||||
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"
|
||||
temp="README.md"
|
||||
echo "**${directory}**" >"${temp}"
|
||||
|
@ -40,5 +54,7 @@ done
|
|||
cd "${olddir}" || echo "could not cd to home dir"
|
||||
rmdir "${tempdir}"
|
||||
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
|
Loading…
Add table
Reference in a new issue