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
ced31774
Commit
ced31774
authored
5 years ago
by
Eesaan Atluri
Browse files
Options
Downloads
Patches
Plain Diff
Add logging and dry-run functionality to bright-account-create agent
parent
bbc37013
No related branches found
No related tags found
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
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
brightcm_account_create.py
+32
-7
32 additions, 7 deletions
brightcm_account_create.py
with
32 additions
and
7 deletions
brightcm_account_create.py
+
32
−
7
View file @
ced31774
#!/usr/bin/env python
#!/usr/bin/env python
import
sys
import
sys
import
json
import
json
import
logging
import
argparse
from
os
import
popen
from
os
import
popen
from
rc_rmq
import
RCRMQ
from
rc_rmq
import
RCRMQ
...
@@ -9,11 +11,29 @@ task = 'bright_account'
...
@@ -9,11 +11,29 @@ task = 'bright_account'
# Instantiate rabbitmq object
# Instantiate rabbitmq object
rc_rmq
=
RCRMQ
({
'
exchange
'
:
'
RegUsr
'
,
'
exchange_type
'
:
'
topic
'
})
rc_rmq
=
RCRMQ
({
'
exchange
'
:
'
RegUsr
'
,
'
exchange_type
'
:
'
topic
'
})
# 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
'
)
args
=
parser
.
parse_args
()
#Default Log level
log_lvl
=
logging
.
WARNING
if
args
.
verbose
:
log_lvl
=
logging
.
DEBUG
if
args
.
dry_run
:
log_lvl
=
logging
.
INFO
# Logger
logging
.
basicConfig
(
format
=
'
%(asctime)s %(levelname)s [%(module)s] - %(message)s
'
,
level
=
log_lvl
)
logger
=
logging
.
getLogger
(
__name__
)
# Define your callback function
# Define your callback function
def
bright_account_create
(
ch
,
method
,
properties
,
body
):
def
bright_account_create
(
ch
,
method
,
properties
,
body
):
# Retrieve message
# Retrieve message
msg
=
json
.
loads
(
body
)
msg
=
json
.
loads
(
body
)
print
(
"
Received
msg
{}
"
.
format
(
msg
))
logger
.
info
(
"
Received {}
"
.
format
(
msg
))
username
=
msg
[
'
username
'
]
username
=
msg
[
'
username
'
]
uid
=
msg
[
'
uid
'
]
uid
=
msg
[
'
uid
'
]
email
=
msg
[
'
email
'
]
email
=
msg
[
'
email
'
]
...
@@ -25,17 +45,18 @@ def bright_account_create(ch, method, properties, body):
...
@@ -25,17 +45,18 @@ def bright_account_create(ch, method, properties, body):
cmd
+=
f
'"
user; add
{
username
}
; set userid
{
uid
}
; set email
{
email
}
; set commonname
\\
"
{
fullname
}
\\
"
;
'
cmd
+=
f
'"
user; add
{
username
}
; set userid
{
uid
}
; set email
{
email
}
; set commonname
\\
"
{
fullname
}
\\
"
;
'
cmd
+=
'
commit;
"'
cmd
+=
'
commit;
"'
#popen(cmd)
if
not
args
.
dry_run
:
print
(
cmd
)
popen
(
cmd
)
logger
.
info
(
f
'
Bright command to create user:
{
cmd
}
'
)
success
=
True
success
=
True
except
:
except
Exception
:
e
=
sys
.
exc_info
()[
0
]
logger
.
exception
(
"
Fatal error:
"
)
print
(
"
[{}]: Error: {}
"
.
format
(
task
,
e
))
# Acknowledge message
# Acknowledge message
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
# send confirm message
# send confirm message
logger
.
debug
(
'
rc_rmq.publish_msg()
'
)
rc_rmq
.
publish_msg
({
rc_rmq
.
publish_msg
({
'
routing_key
'
:
'
confirm.
'
+
username
,
'
routing_key
'
:
'
confirm.
'
+
username
,
'
msg
'
:
{
'
msg
'
:
{
...
@@ -43,19 +64,23 @@ def bright_account_create(ch, method, properties, body):
...
@@ -43,19 +64,23 @@ def bright_account_create(ch, method, properties, body):
'
success
'
:
success
'
success
'
:
success
}
}
})
})
logger
.
info
(
'
confirmation sent
'
)
if
success
:
if
success
:
# send create message to verify dir permissions agent
# send create message to verify dir permissions agent
logger
.
debug
(
f
'
The task
{
task
}
finished successfully
'
)
rc_rmq
.
publish_msg
({
rc_rmq
.
publish_msg
({
'
routing_key
'
:
'
verify.
'
+
username
,
'
routing_key
'
:
'
verify.
'
+
username
,
'
msg
'
:
msg
'
msg
'
:
msg
})
})
logger
.
info
(
'
verify msg sent to next agent
'
)
print
(
"
Start listening to queue: {}
"
.
format
(
task
))
logger
.
info
(
"
Start listening to queue: {}
"
.
format
(
task
))
rc_rmq
.
start_consume
({
rc_rmq
.
start_consume
({
'
queue
'
:
task
,
'
queue
'
:
task
,
'
routing_key
'
:
"
create.*
"
,
'
routing_key
'
:
"
create.*
"
,
'
cb
'
:
bright_account_create
'
cb
'
:
bright_account_create
})
})
logger
.
info
(
"
Disconnected
"
)
rc_rmq
.
disconnect
()
rc_rmq
.
disconnect
()
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