Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
5955f076
Commit
5955f076
authored
Jan 18, 2013
by
Giorgos Korfiatis
Browse files
Split management command into astakos-quota-verify and project-sync
parent
2d894fbf
Changes
3
Hide whitespace changes
Inline
Side-by-side
snf-astakos-app/astakos/im/management/commands/astakos-quota-verify.py
0 → 100644
View file @
5955f076
# Copyright 2012 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from
optparse
import
make_option
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.db
import
transaction
from
astakos.im.models
import
sync_all_users
,
sync_projects
import
logging
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
help
=
"Inspect quotaholder status"
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--check'
,
action
=
'store_true'
,
dest
=
'check'
,
default
=
True
,
help
=
"Check if quotaholder is in sync with astakos (default)"
),
make_option
(
'--sync'
,
action
=
'store_true'
,
dest
=
'sync'
,
default
=
False
,
help
=
"Sync quotaholder"
),
)
@
transaction
.
commit_on_success
def
handle
(
self
,
*
args
,
**
options
):
sync
=
options
[
'sync'
]
try
:
log
=
sync_all_users
(
sync
=
sync
)
except
BaseException
,
e
:
logger
.
exception
(
e
)
raise
CommandError
(
"Syncing failed."
)
snf-astakos-app/astakos/im/management/commands/
astakos-qh
-sync.py
→
snf-astakos-app/astakos/im/management/commands/
project
-sync.py
View file @
5955f076
...
...
@@ -35,41 +35,33 @@ from optparse import make_option
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.db
import
transaction
from
astakos.im.models
import
sync_all_users
,
sync_projects
from
astakos.im.models
import
sync_projects
import
logging
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
help
=
"
Inspect quotaholder status and sync
"
help
=
"
Check for pending project synchronization
"
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--
users
'
,
make_option
(
'--
check
'
,
action
=
'store_true'
,
dest
=
'users'
,
default
=
False
,
help
=
"Check if users and their quotas are in sync with quotaholder"
),
make_option
(
'--projects'
,
action
=
'store_true'
,
dest
=
'projects'
,
default
=
False
,
help
=
"Check if projects are in sync with quotaholder"
),
make_option
(
'--execute'
,
dest
=
'check'
,
default
=
True
,
help
=
"Check if projects are in sync with quotaholder (default)"
),
make_option
(
'--trigger'
,
action
=
'store_true'
,
dest
=
'
execute
'
,
dest
=
'
trigger
'
,
default
=
False
,
help
=
"
Perform the actual operation
"
),
help
=
"
Sync projects to quotaholder
"
),
)
@
transaction
.
commit_on_success
def
handle
(
self
,
*
args
,
**
options
):
execute
=
options
[
'
execute
'
]
trigger
=
options
[
'
trigger
'
]
try
:
if
options
[
'users'
]:
log
=
sync_all_users
(
execute
=
execute
)
elif
options
[
'projects'
]:
log
=
sync_projects
(
execute
=
execute
)
log
=
sync_projects
(
sync
=
trigger
)
except
BaseException
,
e
:
logger
.
exception
(
e
)
raise
CommandError
(
"Syncing failed."
)
snf-astakos-app/astakos/im/models.py
View file @
5955f076
...
...
@@ -2121,9 +2121,9 @@ def post_sync_projects():
transaction
.
commit
()
def
_sync_projects
(
execute
):
def
_sync_projects
(
sync
):
sync_finish_serials
()
if
not
execute
:
if
not
sync
:
# Do some reporting and
return
...
...
@@ -2132,35 +2132,35 @@ def _sync_projects(execute):
sync_finish_serials
([
serial
])
post_sync_projects
()
def
sync_projects
(
execute
=
True
,
retries
=
3
,
retry_wait
=
1.0
):
def
sync_projects
(
sync
=
True
,
retries
=
3
,
retry_wait
=
1.0
):
return
lock_sync
(
_sync_projects
,
args
=
[
execute
],
args
=
[
sync
],
retries
=
retries
,
retry_wait
=
retry_wait
)
def
_sync_users
(
users
,
execute
):
def
_sync_users
(
users
,
sync
):
sync_finish_serials
()
existing
,
nonexisting
=
qh_check_users
(
users
)
resources
=
get_resource_names
()
quotas
=
qh_get_quota_limits
(
existing
,
resources
)
if
execute
:
if
sync
:
r
=
register_users
(
nonexisting
)
r
=
register_quotas
(
users
)
# TODO: some proper reporting
return
(
existing
,
nonexisting
,
quotas
)
def
sync_users
(
users
,
execute
=
True
,
retries
=
3
,
retry_wait
=
1.0
):
def
sync_users
(
users
,
sync
=
True
,
retries
=
3
,
retry_wait
=
1.0
):
return
lock_sync
(
_sync_users
,
args
=
[
users
,
execute
],
args
=
[
users
,
sync
],
retries
=
retries
,
retry_wait
=
retry_wait
)
def
sync_all_users
(
execute
=
True
,
retries
=
3
,
retry_wait
=
1.0
):
def
sync_all_users
(
sync
=
True
,
retries
=
3
,
retry_wait
=
1.0
):
users
=
AstakosUser
.
objects
.
all
()
return
sync_users
(
users
,
execute
,
retries
=
retries
,
retry_wait
=
retry_wait
)
return
sync_users
(
users
,
sync
,
retries
=
retries
,
retry_wait
=
retry_wait
)
def
lock_sync
(
func
,
args
=
[],
kwargs
=
{},
retries
=
3
,
retry_wait
=
1.0
):
transaction
.
commit
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment