Exemple #1
0
    def get(self, ip):
        client = Client(app.config["SSH_IDC_HOST"], app.config["SSH_IDC_USER"],
                        app.config["SSH_IDC_PASSWORD"])

        def exec_script(path):
            info = client.exec_script(path, ip, False)
            return json.loads(info.replace("u'", "'").replace("'", "\""))

        return self.succ(
            exec_script("/root/csfscript/host_info/get_ssh_info.py")
            ["host_ssh_info"].replace("\n", "
").replace(" ", " "))
Exemple #2
0
def __deploy_database(rid, data):
    r = Release.query.filter(Release.id == rid).one()
    try:

        client = Client(app.config["SSH_HOST"], app.config["SSH_USER"],
                        app.config["SSH_PASSWORD"])

        if u"任务完成" not in client.exec_script(
                "/root/csfscript/dump_data/dump_data.py", data):
            return

        r.is_deployed = True

        log_path = "%s/data_deploy_log/myapp.%s" % (
            app.root_path, datetime.now().strftime("%Y-%m-%d"))
        Release.add_log(r.id, log_path)
    except Exception, e:
        log.exception(e)
Exemple #3
0
    def __update(submit):
        client = Client(app.config["SSH_IDC_HOST"], app.config["SSH_IDC_USER"],
                        app.config["SSH_IDC_PASSWORD"])

        def exec_script(path):
            info = client.exec_script(path, submit["ip"], False)
            return json.loads(info.replace("u'", "'").replace("'", "\""))

        if not submit.__contains__("ip"):  # 更新描述信息
            idc_host = Database.to_cls(Idc_host, submit)
            return idc_host

        submit["ssh_info"] = exec_script(
            "/root/csfscript/host_info/get_ssh_info.py"
        )["host_ssh_info"].replace("\n", "
").replace(" ", " ")
        submit["system_time"] = datetime.strptime(
            exec_script("/root/csfscript/host_info/get_system_time.py")
            ["system_time"], "%Y-%m-%d %I:%M:%S %p")
        submit.update(
            exec_script("/root/csfscript/host_info/get_host_info.py"))

        host_interfaces = submit.pop("host_interfaces")
        host_disks = submit.pop("host_disks")

        for key in submit:
            if isinstance(submit[key], list):
                submit[key] = ",".join(submit[key])

        idc_host = Database.to_cls(Idc_host, submit)
        idc_host.ps_info = [
            Database.to_cls(Idc_host_ps, _dict) for _dict in exec_script(
                "/root/csfscript/host_info/get_ps_info.py")
        ]

        Idc_host_ps.query.filter(Idc_host_ps.idc_host_id == None).delete()

        idc_host.host_interfaces = [
            Database.to_cls(Idc_host_interface, _dict)
            for _dict in host_interfaces
        ]
        idc_host.host_disks = [
            Database.to_cls(Idc_host_disk, _dict) for _dict in host_disks
        ]
        return idc_host
Exemple #4
0
    def add(cls, _dicts, auto_commit=True):
        idc_host = Idc_host.query.filter(Idc_host.id == _dicts).one()

        client = Client(app.config["SSH_IDC_HOST"], app.config["SSH_IDC_USER"],
                        app.config["SSH_IDC_PASSWORD"])

        def exec_script(path):
            info = client.exec_script(path, idc_host.ip, False)
            return json.loads(info.replace("u'", "'").replace("'", "\""))

        idc_host.ps_info = [
            Database.to_cls(Idc_host_ps, _dict) for _dict in exec_script(
                "/root/csfscript/host_info/get_ps_info.py")
        ]

        Idc_host_ps.query.filter(Idc_host_ps.idc_host_id == None).delete()

        db.session.commit()
        return True
Exemple #5
0
from bmp.apis.base import BaseApi
from bmp.utils.ssh import Client


class Idc_ssh_infoApi(BaseApi):
    route = ["/idc/ssh/<string:ip>"]

    def get(self, ip):
        client = Client(app.config["SSH_IDC_HOST"], app.config["SSH_IDC_USER"],
                        app.config["SSH_IDC_PASSWORD"])

        def exec_script(path):
            info = client.exec_script(path, ip, False)
            return json.loads(info.replace("u'", "'").replace("'", "\""))

        return self.succ(
            exec_script("/root/csfscript/host_info/get_ssh_info.py")
            ["host_ssh_info"].replace("\n", "&#10;").replace(" ", "&#160;"))


if __name__ == "__main__":
    client = Client(app.config["SSH_IDC_HOST"], app.config["SSH_IDC_USER"],
                    app.config["SSH_IDC_PASSWORD"])

    def exec_script(path):
        info = client.exec_script(path, "192.168.0.231", False)
        return json.loads(info.replace("u'", "'").replace("'", "\""))

    exec_script("/root/csfscript/host_info/get_ssh_info.py"
                )["host_ssh_info"].split("\n")
Exemple #6
0
 def __init__(self, timeout=3):
     self.client = Client(app.config["SSH_HOST"], app.config["SSH_USER"],
                          app.config["SSH_PASSWORD"])
     self.timeout = timeout