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
Merge requests
!4
Test infra 1
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Test infra 1
github/fork/rtripath89/test_infra_1
into
develop
Overview
1
Commits
29
Pipelines
0
Changes
6
Merged
Ravi Tripathi
requested to merge
github/fork/rtripath89/test_infra_1
into
develop
5 years ago
Overview
1
Commits
29
Pipelines
0
Changes
6
Expand
Created by: rtripath89
ohpc_account_create
ood_account_create
slurm_add_account
👍
0
👎
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
2ca1c89e
29 commits,
1 year ago
6 files
+
237
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
ohpc_account_create.py
0 → 100644
+
63
−
0
Options
#!/usr/bin/env python
import
pika
# python client
import
sys
import
rabbit_config
as
rcfg
import
socket
import
subprocess
import
time
import
json
from
pwd
import
getpwnam
hostname
=
socket
.
gethostname
().
split
(
"
.
"
,
1
)[
0
]
connect_host
=
rcfg
.
Server
if
hostname
!=
rcfg
.
Server
else
"
localhost
"
queue_name
=
"
ohpc_account_create
"
duration
=
2
# Set up credentials to connect to RabbitMQ server
credentials
=
pika
.
PlainCredentials
(
rcfg
.
User
,
rcfg
.
Password
)
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
slurm_account_create
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
print
(
"
Message received {}
"
.
format
(
msg
))
username
=
msg
[
'
username
'
]
try
:
subprocess
.
call
([
"
sudo
"
,
"
useradd
"
,
"
-m
"
,
username
])
print
(
"
User {} has been added to {}
"
.
format
(
username
,
hostname
))
except
:
print
(
"
Failed to create user
"
)
channel
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
msg
[
'
uid
'
]
=
getpwnam
(
username
).
pw_uid
msg
[
'
gid
'
]
=
getpwnam
(
username
).
pw_gid
channel
.
basic_publish
(
exchange
=
rcfg
.
Exchange
,
routing_key
=
'
ood_account_create
'
,
body
=
json
.
dumps
(
msg
))
# ingest messages
channel
.
basic_consume
(
queue
=
queue_name
,
on_message_callback
=
slurm_account_create
)
# initiate message ingestion
try
:
channel
.
start_consuming
()
except
KeyboardInterrupt
:
print
(
"
Disconnecting from broker.
"
)
channel
.
stop_consuming
()
connection
.
close
()
Loading