定义通用模块执行

pull/26/head
ibuler 2015-11-20 21:30:57 +08:00
parent ab313aacd8
commit eea56ea0e5
4 changed files with 25 additions and 12 deletions

View File

@ -82,11 +82,13 @@ class MyInventory(object):
hostport = host.get("port")
username = host.get("username")
password = host.get("password")
ssh_key = host.get("ssh_key")
my_host = Host(name=hostname, port=hostport)
my_host.set_variable('ansible_ssh_host', hostname)
my_host.set_variable('ansible_ssh_port', hostport)
my_host.set_variable('ansible_ssh_user', username)
my_host.set_variable('ansible_ssh_pass', password)
my_host.set_variable('ansible_ssh_private_key_file', ssh_key)
# set other variables
for key, value in host.iteritems():
if key not in ["hostname", "port", "username", "password"]:
@ -156,12 +158,12 @@ class Command(MyInventory):
if module_name not in ["raw", "command", "shell"]:
raise CommandValueError("module_name",
"module_name must be of the 'raw, command, shell'")
hoc = MyRunner(module_name=module_name,
module_args=command,
timeout=timeout,
inventory=self.inventory,
pattern=pattern,
forks=forks,
hoc = Runner(module_name=module_name,
module_args=command,
timeout=timeout,
inventory=self.inventory,
pattern=pattern,
forks=forks,
)
self.results = hoc.run()
@ -418,8 +420,6 @@ class Tasks(Command):
return {"status": "failed", "msg": self.msg} if self.msg else {"status": "ok", "result": result}
class CustomAggregateStats(callbacks.AggregateStats):
"""
Holds stats about per-host activity during playbook runs.
@ -438,7 +438,6 @@ class CustomAggregateStats(callbacks.AggregateStats):
self.results.append(runner_results)
def summarize(self, host):
"""
Return information about a particular host

View File

@ -10,6 +10,11 @@ from jperm.models import PermRole
from jperm.models import PermRule
class PermGet(object):
def __init__(self):
pass
def get_object_list(model, id_list):
"""根据id列表获取对象列表"""
object_list = []

View File

@ -3,6 +3,7 @@
import os, sys, time, re
from Crypto.Cipher import AES
import crypt
import pwd
from binascii import b2a_hex, a2b_hex
import hashlib
import datetime
@ -44,6 +45,14 @@ def set_log(level):
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):
"""
page
@ -390,7 +399,7 @@ def bash(cmd):
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
目录存在如果不存在就建立并且权限正确
@ -399,7 +408,7 @@ def mkdir(dir_name, username='root', mode=0755):
os.makedirs(dir_name)
os.chmod(dir_name, mode)
if username:
bash('chown %s:%s %s' % (username, username, dir_name))
chown(dir_name, username)
def http_success(request, msg):

View File

@ -143,7 +143,7 @@ def gen_ssh_key(username, password='',
with open(authorized_key_file, 'w') as auth_f:
auth_f.write(pub_f.read())
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):