Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
eea56ea0
Commit
eea56ea0
authored
Nov 20, 2015
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
定义通用模块执行
parent
ab313aac
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
12 deletions
+25
-12
ansible_api.py
jperm/ansible_api.py
+8
-9
perm_api.py
jperm/perm_api.py
+5
-0
api.py
jumpserver/api.py
+11
-2
user_api.py
juser/user_api.py
+1
-1
No files found.
jperm/ansible_api.py
View file @
eea56ea0
...
@@ -82,11 +82,13 @@ class MyInventory(object):
...
@@ -82,11 +82,13 @@ class MyInventory(object):
hostport
=
host
.
get
(
"port"
)
hostport
=
host
.
get
(
"port"
)
username
=
host
.
get
(
"username"
)
username
=
host
.
get
(
"username"
)
password
=
host
.
get
(
"password"
)
password
=
host
.
get
(
"password"
)
ssh_key
=
host
.
get
(
"ssh_key"
)
my_host
=
Host
(
name
=
hostname
,
port
=
hostport
)
my_host
=
Host
(
name
=
hostname
,
port
=
hostport
)
my_host
.
set_variable
(
'ansible_ssh_host'
,
hostname
)
my_host
.
set_variable
(
'ansible_ssh_host'
,
hostname
)
my_host
.
set_variable
(
'ansible_ssh_port'
,
hostport
)
my_host
.
set_variable
(
'ansible_ssh_port'
,
hostport
)
my_host
.
set_variable
(
'ansible_ssh_user'
,
username
)
my_host
.
set_variable
(
'ansible_ssh_user'
,
username
)
my_host
.
set_variable
(
'ansible_ssh_pass'
,
password
)
my_host
.
set_variable
(
'ansible_ssh_pass'
,
password
)
my_host
.
set_variable
(
'ansible_ssh_private_key_file'
,
ssh_key
)
# set other variables
# set other variables
for
key
,
value
in
host
.
iteritems
():
for
key
,
value
in
host
.
iteritems
():
if
key
not
in
[
"hostname"
,
"port"
,
"username"
,
"password"
]:
if
key
not
in
[
"hostname"
,
"port"
,
"username"
,
"password"
]:
...
@@ -156,12 +158,12 @@ class Command(MyInventory):
...
@@ -156,12 +158,12 @@ class Command(MyInventory):
if
module_name
not
in
[
"raw"
,
"command"
,
"shell"
]:
if
module_name
not
in
[
"raw"
,
"command"
,
"shell"
]:
raise
CommandValueError
(
"module_name"
,
raise
CommandValueError
(
"module_name"
,
"module_name must be of the 'raw, command, shell'"
)
"module_name must be of the 'raw, command, shell'"
)
hoc
=
My
Runner
(
module_name
=
module_name
,
hoc
=
Runner
(
module_name
=
module_name
,
module_args
=
command
,
module_args
=
command
,
timeout
=
timeout
,
timeout
=
timeout
,
inventory
=
self
.
inventory
,
inventory
=
self
.
inventory
,
pattern
=
pattern
,
pattern
=
pattern
,
forks
=
forks
,
forks
=
forks
,
)
)
self
.
results
=
hoc
.
run
()
self
.
results
=
hoc
.
run
()
...
@@ -418,8 +420,6 @@ class Tasks(Command):
...
@@ -418,8 +420,6 @@ class Tasks(Command):
return
{
"status"
:
"failed"
,
"msg"
:
self
.
msg
}
if
self
.
msg
else
{
"status"
:
"ok"
,
"result"
:
result
}
return
{
"status"
:
"failed"
,
"msg"
:
self
.
msg
}
if
self
.
msg
else
{
"status"
:
"ok"
,
"result"
:
result
}
class
CustomAggregateStats
(
callbacks
.
AggregateStats
):
class
CustomAggregateStats
(
callbacks
.
AggregateStats
):
"""
"""
Holds stats about per-host activity during playbook runs.
Holds stats about per-host activity during playbook runs.
...
@@ -438,7 +438,6 @@ class CustomAggregateStats(callbacks.AggregateStats):
...
@@ -438,7 +438,6 @@ class CustomAggregateStats(callbacks.AggregateStats):
self
.
results
.
append
(
runner_results
)
self
.
results
.
append
(
runner_results
)
def
summarize
(
self
,
host
):
def
summarize
(
self
,
host
):
"""
"""
Return information about a particular host
Return information about a particular host
...
...
jperm/perm_api.py
View file @
eea56ea0
...
@@ -10,6 +10,11 @@ from jperm.models import PermRole
...
@@ -10,6 +10,11 @@ from jperm.models import PermRole
from
jperm.models
import
PermRule
from
jperm.models
import
PermRule
class
PermGet
(
object
):
def
__init__
(
self
):
pass
def
get_object_list
(
model
,
id_list
):
def
get_object_list
(
model
,
id_list
):
"""根据id列表获取对象列表"""
"""根据id列表获取对象列表"""
object_list
=
[]
object_list
=
[]
...
...
jumpserver/api.py
View file @
eea56ea0
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
os
,
sys
,
time
,
re
import
os
,
sys
,
time
,
re
from
Crypto.Cipher
import
AES
from
Crypto.Cipher
import
AES
import
crypt
import
crypt
import
pwd
from
binascii
import
b2a_hex
,
a2b_hex
from
binascii
import
b2a_hex
,
a2b_hex
import
hashlib
import
hashlib
import
datetime
import
datetime
...
@@ -44,6 +45,14 @@ def set_log(level):
...
@@ -44,6 +45,14 @@ def set_log(level):
return
logger_f
return
logger_f
def
chown
(
path
,
user
,
group
=
''
,
):
if
not
group
:
group
=
user
uid
=
pwd
.
getpwnam
(
user
)
.
pwd_uid
gid
=
pwd
.
getpwnam
(
group
)
.
gr_gid
os
.
chown
(
path
,
uid
,
gid
)
def
page_list_return
(
total
,
current
=
1
):
def
page_list_return
(
total
,
current
=
1
):
"""
"""
page
page
...
@@ -390,7 +399,7 @@ def bash(cmd):
...
@@ -390,7 +399,7 @@ def bash(cmd):
return
subprocess
.
call
(
cmd
,
shell
=
True
)
return
subprocess
.
call
(
cmd
,
shell
=
True
)
def
mkdir
(
dir_name
,
username
=
'
root
'
,
mode
=
0755
):
def
mkdir
(
dir_name
,
username
=
''
,
mode
=
0755
):
"""
"""
insure the dir exist and mode ok
insure the dir exist and mode ok
目录存在,如果不存在就建立,并且权限正确
目录存在,如果不存在就建立,并且权限正确
...
@@ -399,7 +408,7 @@ def mkdir(dir_name, username='root', mode=0755):
...
@@ -399,7 +408,7 @@ def mkdir(dir_name, username='root', mode=0755):
os
.
makedirs
(
dir_name
)
os
.
makedirs
(
dir_name
)
os
.
chmod
(
dir_name
,
mode
)
os
.
chmod
(
dir_name
,
mode
)
if
username
:
if
username
:
bash
(
'chown
%
s:
%
s
%
s'
%
(
username
,
username
,
dir_name
)
)
chown
(
dir_name
,
username
)
def
http_success
(
request
,
msg
):
def
http_success
(
request
,
msg
):
...
...
juser/user_api.py
View file @
eea56ea0
...
@@ -143,7 +143,7 @@ def gen_ssh_key(username, password='',
...
@@ -143,7 +143,7 @@ def gen_ssh_key(username, password='',
with
open
(
authorized_key_file
,
'w'
)
as
auth_f
:
with
open
(
authorized_key_file
,
'w'
)
as
auth_f
:
auth_f
.
write
(
pub_f
.
read
())
auth_f
.
write
(
pub_f
.
read
())
os
.
chmod
(
authorized_key_file
,
0600
)
os
.
chmod
(
authorized_key_file
,
0600
)
bash
(
'chown
%
s:
%
s
%
s'
%
(
username
,
username
,
authorized_key_file
)
)
chown
(
authorized_key_file
,
username
)
def
server_add_user
(
username
,
password
,
ssh_key_pwd
,
ssh_key_login_need
):
def
server_add_user
(
username
,
password
,
ssh_key_pwd
,
ssh_key_login_need
):
...
...
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