Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
14
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
a0911932
Commit
a0911932
authored
5 years ago
by
Bo-Chun Chen
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite ood account agent
parent
1383fba8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!23
Feat resolve uid gid
,
!18
Redesign RabbitMQ
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ood_account_create.py
+24
-41
24 additions, 41 deletions
ood_account_create.py
with
24 additions
and
41 deletions
ood_account_create.py
+
24
−
41
View file @
a0911932
...
@@ -6,32 +6,12 @@ import socket
...
@@ -6,32 +6,12 @@ import socket
import
subprocess
import
subprocess
import
time
import
time
import
json
import
json
from
rc_rmq
import
RCRMQ
hostname
=
socket
.
gethostname
().
split
(
"
.
"
,
1
)[
0
]
task
=
'
ood_account
'
connect_host
=
rcfg
.
Server
if
hostname
!=
rcfg
.
Server
else
"
localhost
"
queue_name
=
"
ood_account_create
"
duration
=
2
# Set up credentials to connect to RabbitMQ server
# Instantiate rabbitmq object
credentials
=
pika
.
PlainCredentials
(
rcfg
.
User
,
rcfg
.
Password
)
rc_rmq
=
RCRMQ
({
'
exchange
'
:
'
RegUsr
'
,
'
exchange_type
'
:
'
topic
'
})
parameters
=
pika
.
ConnectionParameters
(
connect_host
,
rcfg
.
Port
,
rcfg
.
VHost
,
credentials
)
# Establish connection to RabbitMQ server
connection
=
pika
.
BlockingConnection
(
parameters
)
channel
=
connection
.
channel
()
print
(
"
connection established. Listening for messages:
"
)
# create exchange to pass messages
channel
.
exchange_declare
(
exchange
=
rcfg
.
Exchange
,
exchange_type
=
'
direct
'
)
# creates a random name for the newly generated queue
result
=
channel
.
queue_declare
(
queue
=
queue_name
,
exclusive
=
False
)
channel
.
queue_bind
(
exchange
=
rcfg
.
Exchange
,
queue
=
queue_name
,
routing_key
=
queue_name
)
def
ood_account_create
(
ch
,
method
,
properties
,
body
):
def
ood_account_create
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
msg
=
json
.
loads
(
body
)
...
@@ -39,26 +19,29 @@ def ood_account_create(ch, method, properties, body):
...
@@ -39,26 +19,29 @@ def ood_account_create(ch, method, properties, body):
username
=
msg
[
'
username
'
]
username
=
msg
[
'
username
'
]
user_uid
=
str
(
msg
[
'
uid
'
])
user_uid
=
str
(
msg
[
'
uid
'
])
user_gid
=
str
(
msg
[
'
gid
'
])
user_gid
=
str
(
msg
[
'
gid
'
])
success
=
False
try
:
try
:
subprocess
.
call
([
"
sudo
"
,
"
groupadd
"
,
"
-r
"
,
"
-g
"
,
user_gid
,
username
])
subprocess
.
call
([
"
sudo
"
,
"
groupadd
"
,
"
-r
"
,
"
-g
"
,
user_gid
,
username
])
subprocess
.
call
([
"
sudo
"
,
"
useradd
"
,
"
-u
"
,
user_uid
,
"
-g
"
,
user_gid
,
username
])
subprocess
.
call
([
"
sudo
"
,
"
useradd
"
,
"
-u
"
,
user_uid
,
"
-g
"
,
user_gid
,
username
])
print
(
"
User {} has been added to {}
"
.
format
(
username
,
hostname
))
print
(
"
[{}]: User {} has been added
"
.
format
(
task
,
username
))
success
=
True
except
:
except
:
print
(
"
Failed to create user
"
)
print
(
"
Failed to create user
"
)
channel
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
channel
.
basic_publish
(
exchange
=
rcfg
.
Exchange
,
routing_key
=
'
slurm_add_account
'
,
body
=
json
.
dumps
(
msg
))
# send confirm message
rc_rmq
.
publish_msg
({
'
routing_key
'
:
'
confirm.
'
+
username
,
# ingest messages
'
msg
'
:
{
channel
.
basic_consume
(
queue
=
queue_name
,
on_message_callback
=
ood_account_create
)
'
task
'
:
task
,
'
success
'
:
success
# initiate message ingestion
}
try
:
})
channel
.
start_consuming
()
except
KeyboardInterrupt
:
print
(
"
Start listening to queue: {}
"
.
format
(
task
))
print
(
"
Disconnecting from broker.
"
)
rc_rmq
.
start_consume
({
channel
.
stop_consuming
()
'
queue
'
:
task
,
'
routing_key
'
:
"
create.*
"
,
connection
.
close
()
'
cb
'
:
ood_account_create
})
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