Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
16
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rc
rabbitmq_agents
Commits
abc50481
Commit
abc50481
authored
5 years ago
by
Eesaan Atluri
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop' into feat-add-user-bright-cm
parents
286b320d
9877c0ba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
6 merge requests
!147
Merge previous default branch feat-cod-rmq into main
,
!85
kill nginx process running under user from login node
,
!51
Fix acct create wait
,
!45
Revert 29 feat add user bright cm
,
!39
WIP:Feat cod rmq
,
!29
Feat add user bright cm
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+3
-0
3 additions, 0 deletions
README.md
create_account.py
+25
-0
25 additions, 0 deletions
create_account.py
rc_rmq.py
+8
-10
8 additions, 10 deletions
rc_rmq.py
rc_util.py
+34
-5
34 additions, 5 deletions
rc_util.py
with
70 additions
and
15 deletions
README.md
+
3
−
0
View file @
abc50481
...
...
@@ -41,7 +41,10 @@ def callback_function(ch, method, properties, body):
# start consume messagre from queue with callback function
rc_rmq.start_consume({
'queue': 'queue_name',
'routing_key: 'your_key',
'cb': callback_function
})
# don't forget to close connection
rc_rmq.disconnect()
```
This diff is collapsed.
Click to expand it.
create_account.py
0 → 100755
+
25
−
0
View file @
abc50481
#!/usr/bin/env python
import
sys
import
rc_util
if
len
(
sys
.
argv
)
<
2
:
print
(
"
Usage: {} USERNAME [EMAIL] [FULL_NAME] [REASON]
"
.
format
(
sys
.
argv
[
0
]),
file
=
sys
.
stderr
)
exit
(
1
)
domain
=
'
uab.edu
'
user_name
=
sys
.
argv
[
1
]
email
=
sys
.
argv
[
2
]
if
len
(
sys
.
argv
)
>=
3
else
''
full_name
=
sys
.
argv
[
3
]
if
len
(
sys
.
argv
)
>=
4
else
''
reason
=
sys
.
argv
[
4
]
if
len
(
sys
.
argv
)
>=
5
else
''
if
email
==
''
:
if
'
@
'
in
user_name
:
email
=
user_name
else
:
email
=
user_name
+
'
@
'
+
domain
rc_util
.
add_account
(
user_name
,
email
=
email
,
full
=
full_name
,
reason
=
reason
)
print
(
"
Account requested for user: {}
"
.
format
(
user_name
))
print
(
"
Waiting for confirmation...
"
)
rc_util
.
consume
(
user_name
)
This diff is collapsed.
Click to expand it.
rc_rmq.py
+
8
−
10
View file @
abc50481
...
...
@@ -65,15 +65,16 @@ class RCRMQ(object):
exchange_type
=
self
.
EXCHANGE_TYPE
,
durable
=
True
)
if
self
.
QUEUE
is
not
None
:
self
.
_channel
.
queue_declare
(
queue
=
self
.
QUEUE
,
durable
=
self
.
DURABLE
)
self
.
_channel
.
queue_bind
(
exchange
=
self
.
EXCHANGE
,
queue
=
self
.
QUEUE
,
routing_key
=
self
.
ROUTING_KEY
)
def
bind_queue
(
self
)
:
self
.
_channel
.
queue_declare
(
queue
=
self
.
QUEUE
,
durable
=
self
.
DURABLE
)
self
.
_channel
.
queue_bind
(
exchange
=
self
.
EXCHANGE
,
queue
=
self
.
QUEUE
,
routing_key
=
self
.
ROUTING_KEY
)
def
disconnect
(
self
):
self
.
_channel
.
close
()
self
.
_connection
.
close
()
self
.
_connection
=
None
def
delete_queue
(
self
):
self
.
_channel
.
queue_delete
(
self
.
QUEUE
)
...
...
@@ -89,9 +90,6 @@ class RCRMQ(object):
routing_key
=
self
.
ROUTING_KEY
,
body
=
json
.
dumps
(
obj
[
'
msg
'
]))
if
not
self
.
_consuming
:
self
.
disconnect
()
def
start_consume
(
self
,
obj
):
if
'
queue
'
in
obj
:
self
.
QUEUE
=
obj
[
'
queue
'
]
...
...
@@ -105,6 +103,8 @@ class RCRMQ(object):
if
self
.
_connection
is
None
:
self
.
connect
()
self
.
bind_queue
()
self
.
_consumer_tag
=
self
.
_channel
.
basic_consume
(
self
.
QUEUE
,
obj
[
'
cb
'
])
self
.
_consuming
=
True
try
:
...
...
@@ -112,7 +112,5 @@ class RCRMQ(object):
except
KeyboardInterrupt
:
self
.
_channel
.
stop_consuming
()
self
.
disconnect
()
def
stop_consume
(
self
):
self
.
_channel
.
basic_cancel
(
self
.
_consumer_tag
)
This diff is collapsed.
Click to expand it.
rc_util.py
+
34
−
5
View file @
abc50481
import
logging
import
argparse
from
rc_rmq
import
RCRMQ
import
json
rc_rmq
=
RCRMQ
({
'
exchange
'
:
'
RegUsr
'
,
'
exchange_type
'
:
'
topic
'
})
tasks
=
{
'
ohpc_account
'
:
None
,
'
ood_account
'
:
None
,
'
slurm_account
'
:
None
}
logger_fmt
=
'
%(asctime)s [%(module)s] - %(message)s
'
def
add_account
(
username
,
full
=
''
,
reason
=
''
):
def
add_account
(
username
,
email
,
full
=
''
,
reason
=
''
):
rc_rmq
.
publish_msg
({
'
routing_key
'
:
'
request.
'
+
username
,
'
msg
'
:
{
"
username
"
:
username
,
"
email
"
:
email
,
"
fullname
"
:
full
,
"
reason
"
:
reason
}
})
rc_rmq
.
disconnect
()
def
worker
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
...
...
@@ -27,17 +32,41 @@ def worker(ch, method, properties, body):
print
(
"
{} is not done yet.
"
.
format
(
key
))
done
=
False
if
done
:
c
onfirm
_rmq
.
stop_consume
()
c
onfirm
_rmq
.
delete_queue
()
r
c_rmq
.
stop_consume
()
r
c_rmq
.
delete_queue
()
def
consume
(
username
,
callback
,
debug
=
False
):
def
consume
(
username
,
callback
=
worker
,
debug
=
False
):
if
debug
:
sleep
(
5
)
else
:
c
onfirm
_rmq
.
start_consume
({
r
c_rmq
.
start_consume
({
'
queue
'
:
username
,
'
routing_key
'
:
'
confirm.
'
+
username
,
'
cb
'
:
callback
})
rc_rmq
.
disconnect
()
return
{
'
success
'
:
True
}
def
get_args
():
# Parse arguments
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
-v
'
,
'
--verbose
'
,
action
=
'
store_true
'
,
help
=
'
verbose output
'
)
parser
.
add_argument
(
'
-n
'
,
'
--dry-run
'
,
action
=
'
store_true
'
,
help
=
'
enable dry run mode
'
)
return
parser
.
parse_args
()
def
get_logger
(
args
=
None
):
if
args
is
None
:
args
=
get_args
()
logger_lvl
=
logging
.
WARNING
if
args
.
verbose
:
logger_lvl
=
logging
.
DEBUG
if
args
.
dry_run
:
logger_lvl
=
logging
.
INFO
logging
.
basicConfig
(
format
=
logger_fmt
,
level
=
logger_lvl
)
return
logging
.
getLogger
(
__name__
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment