Example #1
0
def deploy_separate_bigdata():
    if request.method == "GET":
        """
            get获取所有的物理磁盘、排除当前移动硬盘
        """
        headers = GetModel.get_auth_header()
        return json.dumps({"data": ClearAwCloud(headers).get_sds_partitions(), "code": 0})
Example #2
0
def get_node_info():
    """
    获取所有的node节点信息 
    :return:
    """
    if GetModel.deploy_type() == 'kvm':
        headers = GetModel.get_auth_header()
        return json.dumps({"code": 0, "data": ClearAwCloud(headers).get_node_info()})
    else:
        return json.dumps({"code": 0, "data": Panacube().get_node()})
Example #3
0
def verify_ip():
    """
    验证ip是否可用
    :return:
    """
    ip = request.args.get("ip")
    network_id = request.args.get("network_id")
    model.update_or_create('network_id', network_id)
    model.update_or_create('kvm_ip', ip)
    data = ClearAwCloud(GetModel.get_auth_header()).get_network_card(ip, network_id)
    return json.dumps({"code": 0, "data": data})
Example #4
0
def accept_info():
    """
    获取获取2.0或者3.0的账号密码 -> GET获取外部网络信息
    # {
    #     "awcloud_ip": "",
    #     "username": "******",
    #     "password": "******",
    #     "panacube_ip": 3
    # }
    :return:
    """
    if request.method == "GET":
        r_data = ClearAwCloud(GetModel.get_auth_header()).get_external_network()
        if 'code' in r_data:
            return json.dumps({'code': 1})
        return json.dumps({'data': r_data, 'code': 0})

    r_data = request.json
    model.update_or_create('panacube', r_data)
    return json.dumps({"code": 0, 'message': 'Successful'})
Example #5
0
def kvm_image_upload():
    """
    上传panacube镜像  需要2.0的账号密码
    :return:
    """
    id2 = ClearAwCloud(GetModel.get_auth_header()).upload_image(
        PathDir.image_path(None), 'panacube3.0')
    q.put({
        "type": "镜像上传",
        "size": "上传大小",
        "speed": "conducting",
        "percentage": "{}".format(generate_random(4, 15))
    })
    current_app.logger.info('upload kvm image: {}'.format(id2))
    model.update_or_create('panacube_img_id', id2['id'])
    q.put({
        "type": "镜像上传",
        "size": "上传大小",
        "speed": "conducting",
        "percentage": "{}".format(generate_random(16, 32))
    })
Example #6
0
def update_storage_image():
    """
    更新智能存储镜像
    :return:
    """
    q.put({
        "type": "镜像上传",
        "size": "上传大小",
        "speed": "conducting",
        "percentage": "{}".format(generate_random(1, 6))
    })
    if GetModel.deploy_type() == 'kvm':
        awcloud = ClearAwCloud(GetModel.get_auth_header())
        q.put({
            "type": "镜像上传",
            "size": "上传大小",
            "speed": "conducting",
            "percentage": "{}".format(generate_random(17, 36))
        })
        image_obj = awcloud.upload_image(PathDir.image_path())
        print '上传的镜像信息: %s' % image_obj
        image_id = image_obj['id']
        q.put({
            "type": "镜像上传",
            "size": "上传大小",
            "speed": "conducting",
            "percentage": "{}".format(generate_random(38, 52))
        })
        model.update_or_create('storage_img_id', image_id)
        q.put({
            "type": "镜像上传",
            "size": "上传大小",
            "speed": "conducting",
            "percentage": "{}".format(generate_random(57, 78))
        })
        f = l = 79
        while True:
            resp = awcloud.update_image_info(image_id)
            f += 4
            l += 10
            if l >= 90:
                q.put({
                    "type": "镜像上传",
                    "size": "上传大小",
                    "speed": "conducting",
                    "percentage": "{}".format(generate_random(f, l))
                })
            else:
                f -= 2
                l -= 3
                q.put({
                    "type": "镜像上传",
                    "size": "上传大小",
                    "speed": "conducting",
                    "percentage": "{}".format(generate_random(f, l))
                })
            if resp.get('status') != 415:
                if resp['code'] == '0':
                    current_app.logger.info(
                        'update storage image property successful')
                else:
                    current_app.logger.info(
                        'update storage image property fail')
                break
            else:
                time.sleep(2)
        os.system("sh {set_tag} {openstack} {id}".format(
            set_tag=PathDir.tag_shell_path(),
            openstack=PathDir.openstack(),
            id=image_id))
    else:
        awcloud = ClearAwCloud(GetModel.get_auth_header())
        q.put({
            "type": "镜像上传",
            "size": "上传大小",
            "speed": "conducting",
            "percentage": "23"
        })
        model.update_or_create('awcloud_ip', GetModel.awcloud_ip())
        q.put({
            "type": "镜像上传",
            "size": "上传大小",
            "speed": "conducting",
            "percentage": "48"
        })
        image_id = awcloud.upload_image(PathDir.image_path()).get('id')
        q.put({
            "type": "镜像上传",
            "size": "上传大小",
            "speed": "conducting",
            "percentage": "{}".format(generate_random(56, 88))
        })
        model.update_or_create('storage_img_id', image_id)
        while True:
            resp = awcloud.update_image_info(image_id)
            if resp.get('status') != 415:
                if resp['code'] == '0':
                    current_app.logger.info(
                        'update storage image property successful')
                else:
                    current_app.logger.info(
                        'update storage image property fail')
                break
            else:
                time.sleep(2)
        os.system("sh {set_tag} {openstack} {id}".format(
            set_tag=PathDir.tag_shell_path(),
            openstack=PathDir.openstack(),
            id=image_id))
    from app_projects.deploy.get_config import move_storage_code
    storage_code_name = move_storage_code()
    node_list = os.popen("consul members | awk '{ print $1 }'").read().split(
        '\n')[1:-1]
    for item in node_list:
        os.system("scp -r /var/deploy/%s %s:/usr/local/udsafe/%s" %
                  (storage_code_name, item, storage_code_name))
        q.put({
            "type": "镜像上传",
            "size": "上传大小",
            "speed": "conducting",
            "percentage": "{}".format(generate_random(89, 96))
        })
Example #7
0
def deploy_kvm(update=False):
    """
    部署虚拟机
    :return:
    """
    print update, '正在执行操作'
    if update is False:
        panacube_ip = GetModel.kvm_ip()
    else:
        with open('/usr/local/udsafe/automatedkvm.txt', 'r') as f:
            panacube_ip = f.read()

    if update is False:
        awcloud_obj = ClearAwCloud(GetModel.get_auth_header())
        q.put({
            "type": "云主机部署",
            "speed": "conducting",
            "percentage": "{}".format(generate_random(33, 37))
        })
        res_data = awcloud_obj.run()  # 创建云主机
        if res_data['code'] != u'0':
            return json.dumps({"code": 1, 'message': res_data['message']})

    # 替换配置文件ip
    if update is True:
        parent_speed = 98
        _type = '云主机升级'
    else:
        parent_speed = 86
        _type = '云主机部署'

    q.put({
        "type": _type,
        "speed": "conducting",
        "percentage": "{}".format(generate_random(81, 86))
    })
    is_docker = get_cmd("cat {} | grep 'IS_DOCKER = ' | grep -v os".format(
        PathDir.local_settings())).split('=')[-1]
    os.system("""sed -i "s/{}/ {}/" {file}""".format(
        is_docker, "False", file=PathDir.local_settings()))

    saas_ip = get_cmd("cat {} | grep 'SAAS_IP = ' | grep -v os".format(
        PathDir.local_settings())).split('= ')[-1]
    os.system("""sed -i "s/{}/{}/" {file} | grep -v os""".format(
        saas_ip,
        "\\'{}\\'".format(GetModel.awcloud_ip()),
        file=PathDir.local_settings()))

    mysql_ip = get_cmd("cat {} | grep 'MYSQL_IP = ' | grep -v open".format(
        PathDir.local_settings()))
    os.system(
        """sed -i "s/{}/    MYSQL_IP = {}/" {file} | grep -v os""".format(
            mysql_ip,
            "\\'{}\\'".format(panacube_ip),
            file=PathDir.local_settings()))

    mysql_port = get_cmd("cat {} | grep 'MYSQL_PORT = ' | grep -v os".format(
        PathDir.local_settings())).split('= ')[-1]
    os.system("""sed -i "s/{}/{}/" {file}""".format(
        mysql_port, 3306, file=PathDir.local_settings()))
    if update is False:
        cloud_id = res_data.get('data').get('data')[0]
        f = l = 86
        while True:
            if l >= 97:
                f -= 7
                l -= 15
            else:
                f += 7
                l += 15
            if l == f:
                f -= 3
            d = generate_random(f, l)
            if d > parent_speed:
                parent_speed = d
            if parent_speed > 100:
                parent_speed = 98
            q.put({
                "type": "云主机部署",
                "speed": "conducting",
                "percentage": "{}".format(parent_speed)
            })
            current_app.logger.info('正在等待虚拟机启动')
            if awcloud_obj.get_cloud_status(cloud_id) is True:
                current_app.logger.info('虚拟机启动成功')
                break
            time.sleep(3)

    chmod_id_rsa = 'chmod 600 {id_rsa}'.format(id_rsa=PathDir.panacube_idrsa())
    os.system(chmod_id_rsa)
    # 添加mysql配置文件
    # append_mariadb = mariadb_con.format(id_rsa=PathDir.panacube_idrsa(), panacube_ip=panacube_ip)
    # os.system(append_mariadb)
    copy_panacube = "scp -i {id_rsa} -r {project_path} root@{panacube_ip}:/home/udsafe/".format(
        id_rsa=PathDir.panacube_idrsa(),
        project_path=PathDir.project_path(),
        panacube_ip=panacube_ip)
    time.sleep(60)
    os.system(copy_panacube)
    # 重启mariadb
    os.system(
        restart_mariadb.format(id_rsa=PathDir.panacube_idrsa(),
                               panacube_ip=panacube_ip))
    # 更新数据库
    os.system(
        update_db.format(id_rsa=PathDir.panacube_idrsa(),
                         panacube_ip=panacube_ip,
                         sql_name=config.get('pancube_sql')['sql_name']))
    if 'TrueOS' in get_all_path()['bigdataPath']:
        gateway_system = 'FreeBSD'
    else:
        gateway_system = 'CentOS'
    # os.system(del_param_name.format(id_rsa=PathDir.panacube_idrsa(), panacube_ip=panacube_ip))
    os.system(
        set_bigdata_type.format(id_rsa=PathDir.panacube_idrsa(),
                                panacube_ip=panacube_ip,
                                gateway_system=gateway_system))
    print '更新3.0 packages安装包'
    os.system(
        update_pip_packages.format(id_rsa=PathDir.panacube_idrsa(),
                                   panacube_ip=panacube_ip))
    print 'pip 安装结束'
    # 重启服务
    os.system(
        restart_supervisord_all.format(id_rsa=PathDir.panacube_idrsa(),
                                       panacube_ip=panacube_ip))
    # if update is False:
    # 更新数据库
    # os.system(update_db.format(id_rsa=PathDir.panacube_idrsa(), panacube_ip=panacube_ip))
    if update is False:
        # 添加消息推送
        push_message()
        # 添加大数据配置
        push_bigdata_db()