def update_yaml(nfs_server, volume_directory, dir_path, pods, pods_dict, node_dict):
    host_ip = get_host_ip()
    sys.path.append(dir_path)
    import yaml_utils
    if re.search("live\d+", str(pods)):
        print("\n\033[0;31;40mThe live video playlist URL are below:\033[0m")
    for pod in pods:
        node_name = pods_dict[pod]["node"]
        node = node_dict[node_name]
        limit_cpu = 2 * float(pods_dict[pod]["cpu"]) if 2 * float(
            pods_dict[pod]["cpu"]) < node["cpu"] else node["cpu"] - 1
        limit_memory = 2 * int(pods_dict[pod]["memory"]) if 2 * int(
            pods_dict[pod]["memory"]) < node["memory"] else node["memory"] - 1

        yaml_file = os.path.join(dir_path, re.match(
            "([A-Za-z]+)\d*$", pod).group(1) + "-service-deployment.yaml")
        data = yaml_utils.load_yaml_file(yaml_file)
        data = yaml_utils.update_resource_quotas(
            data, pods_dict[pod]["cpu"], limit_cpu, pods_dict[pod]["memory"], limit_memory)
        data = yaml_utils.update_nodeSelector(data, node_name)

        if pod == "cdn":
            data = yaml_utils.add_volumeMounts(data, True)
            data = yaml_utils.add_volumes(
                data, nfs_server, True, volume_directory)

            node_port = 38080 
            service_file = dir_path + "/cdn-service-service.yaml"
            service_data = yaml_utils.load_yaml_file(service_file)
            service_data = yaml_utils.set_nodePort(service_data, node_port)
            yaml_utils.dump_yaml_file(service_data, service_file)

        if re.search("((vod)|(live))\d+", pod):
            data = yaml_utils.update_imageName(
                data, pods_dict[pod]["mode"].lower(), True if re.search("vod\d+", pod) else False)
            data = yaml_utils.add_volumeMounts(data, False)
            data = yaml_utils.add_volumes(
                data, nfs_server, False, volume_directory)
            data = yaml_utils.update_service_name(
                data, pod + "-service")
            yaml_file = os.path.join(dir_path, pod + "-service-deployment.yaml")

            if re.search("live\d", pod):
                live_args = {
                    'input_video': pods_dict[pod]["input"], "output_dict": {}}
                codec_dict = {"AVC": "libx264",
                              "HEVC": "libsvt_hevc", "AV1": "libsvt_av1"}
                for num in range(4):
                    if pods_dict[pod].get("transcode" + str(num), None) and pods_dict[pod]["transcode" + str(num)].get("protocol", None) and pods_dict[pod]["transcode" + str(num)].get("resolution", None) and pods_dict[pod]["transcode" + str(num)].get("bitrate", None) and pods_dict[pod]["transcode" + str(num)].get("codec", None) and pods_dict[pod]["transcode" + str(num)].get("output", None):
                        live_args["output_dict"][pods_dict[pod]["transcode" + str(num)]["output"] + "_" + re.search("live(\d+)", pod).group(1) + "_" + str(num)] = [pods_dict[pod]["transcode" + str(
                            num)]["protocol"].lower(), pods_dict[pod]["transcode" + str(num)]["resolution"], pods_dict[pod]["transcode" + str(num)]["bitrate"], codec_dict[pods_dict[pod]["transcode" + str(num)]["codec"]]]
                        print("\033[0;31;40mhttps://%s/%s/%s/index.%s\033[0m" % (host_ip, pods_dict[pod]["transcode" + str(num)]["protocol"].lower(), pods_dict[pod]["transcode" + str(num)]
                                                                                 ["output"] + "_" + re.search("live(\d+)", pod).group(1) + "_" + str(num), "m3u8" if pods_dict[pod]["transcode" + str(num)]["protocol"].lower() == "hls" else "mpd"))
                data = yaml_utils.update_command(
                    data, pods_dict[pod]["mode"].lower(), live_args)

        yaml_utils.dump_yaml_file(data, yaml_file)

    subprocess.call("rm -rf %s/vod-service-deployment.yaml" % dir_path, shell=True)
    subprocess.call("rm -rf %s/live-service-deployment.yaml" % dir_path, shell=True)
Esempio n. 2
0
def configure_trancode_service(yaml_file, service_name):
    global live_args_list

    data = yaml_utils.load_yaml_file(yaml_file)
    data = yaml_utils.add_volumeMounts(data, False)
    data = yaml_utils.add_volumes(data, nfs_server, False, volume_directory)
    i = 0

    while True:
        if len(hw_node_name_list) > 0:
            image_name = input("Please choose the transcode mode of the " + service_name + " ([hw]: hardware is for E3/VCA2 or [sw]: software is for E5): ")
            while True:
                if image_name.lower() == "sw" or  image_name.lower() == "hw":
                    break
                else:
                    image_name = input("Please choose the transcode mode of the " + service_name + " again ([hw]: hardware is for E3/VCA2 or [sw]: software is for E5): ")
        else:
            image_name = "sw"
        node_name = input_node_name(service_name, image_name.lower())

        data = yaml_utils.update_imageName(data, image_name.lower(), False if (service_name == "live-transcode-service") else True)
        data = yaml_utils.update_nodeSelector(data, node_name)
        if service_name == "live-transcode-service":
            deploy_type = input("Do you need to deploy live-transcode-service by customizing parameters([y] or [n]): ")
            while True:
                if deploy_type.lower() == "y":
                    deploy_type = "manual"
                    break
                elif deploy_type.lower() == "n":
                    deploy_type = "auto"
                    break
                else:
                    deploy_type = input("Input error, do you need to deploy live-transcode-service by customizing parameters([y] or [n]): ")
            live_args_list.append(configure_live_transcode_args(deploy_type, image_name.lower()))
            data = yaml_utils.update_command(data, image_name.lower(), i, live_args_list)

        data = yaml_utils.update_service_name(data, service_name + "-" + str(i))
        fileName = yaml_file.rsplit("0")[0] + str(i) + "-deployment.yaml"
        yaml_utils.dump_yaml_file(data, fileName)

        i += 1
        create_node = input("Do you still need to deploy the " + str(i + 1) +  " " + service_name + "? ([y] or [n]): ")
        while True:
            if create_node.lower() == "y" or create_node.lower() == "n":
                break
            else:
                create_node = input("Input error, Do you still need to deploy the " + str(i + 1) + " " + service_name + "? ([y] or [n]): ")
        if create_node.lower() == "n":
            break
Esempio n. 3
0
#redis
node_name = input_node_name("redis-service")

yaml_file = sys.argv[1] + "/redis-service-deployment.yaml"
data = yaml_utils.load_yaml_file(yaml_file)
data = yaml_utils.update_nodeSelector(data, node_name)
yaml_utils.dump_yaml_file(data, yaml_file)

# cdn
node_name = input_node_name("cdn-service")

yaml_file = sys.argv[1] + "/cdn-service-deployment.yaml"
data = yaml_utils.load_yaml_file(yaml_file)
data = yaml_utils.update_nodeSelector(data, node_name)
data = yaml_utils.add_volumeMounts(data, True)
data = yaml_utils.add_volumes(data, nfs_server, True, volume_directory)
yaml_utils.dump_yaml_file(data, yaml_file)

node_port = 443
yaml_file = sys.argv[1] + "/cdn-service-service.yaml"
data = yaml_utils.load_yaml_file(yaml_file)
data = yaml_utils.set_nodePort(data, node_port)
yaml_utils.dump_yaml_file(data, yaml_file)

#vod transcode
yaml_file = sys.argv[1] + "/vod-transcode-service-0-deployment.yaml"
deploy_transcode_cluster("vod")

#live transcode
yaml_file = sys.argv[1] + "/live-transcode-service-0-deployment.yaml"
live_args_list = []
Esempio n. 4
0
yaml_file = sys.argv[1] + "/kafka-init-deployment.yaml"
data = yaml_utils.load_yaml_file(yaml_file)

#database
node_name = input_node_name("database")

yaml_file = sys.argv[1] + "/database-deployment.yaml"
data = yaml_utils.load_yaml_file(yaml_file)

# cdn
node_name = input_node_name("cdn")

yaml_file = sys.argv[1] + "/cdn-deployment.yaml"
data = yaml_utils.load_yaml_file(yaml_file)
yaml_utils.add_volumeMounts(data, yaml_file, "cdn")
yaml_utils.add_volumes(data, yaml_file, nfs_server, "cdn", adi_directory)

#video-analytic-ffmpeg
node_name = input_node_name("video-analytic-ffmpeg")

yaml_file = sys.argv[1] + "/video-analytic-ffmpeg-deployment.yaml"
data = yaml_utils.load_yaml_file(yaml_file)

#video-analytic-gstreamer
node_name = input_node_name("video-analytic-gstreamer")

yaml_file = sys.argv[1] + "/video-analytic-gstreamer-deployment.yaml"
data = yaml_utils.load_yaml_file(yaml_file)

#ad-transcode
node_name = input_node_name("ad-transcode")
# kafka
node_name = input_node_name("kafka")

yaml_file = sys.argv[1] + "/kafka-service-deployment.yaml"
data = yaml_utils.load_yaml_file(yaml_file)
yaml_utils.update_nodeSelector(data, yaml_file, node_name)

# cdn
node_name = input_node_name("cdn")

yaml_file = sys.argv[1] + "/cdn-service-deployment.yaml"
data = yaml_utils.load_yaml_file(yaml_file)
yaml_utils.update_nodeSelector(data, yaml_file, node_name)
yaml_utils.add_volumeMounts(data, yaml_file, True)
yaml_utils.add_volumes(data, yaml_file, nfs_server, True, cdn_directory)

node_port = 443

yaml_file = sys.argv[1] + "/cdn-service-service.yaml"
data = yaml_utils.load_yaml_file(yaml_file)
yaml_utils.set_nodePort(data, yaml_file, node_port)

#vod transcode
node_name = input_node_name("vod transcode")

image_name = input(
    "Please choose the transcode mode of the vod transcode server ([hw]: hardware is for E3/VCA2 or [sw]: software is for E5):"
)
while True:
    if image_name.lower() == "sw" or image_name.lower() == "hw":
def update_yaml(nfs_server, volume_directory, dir_path, pods, pods_dict,
                node_dict, trans_cfg_dict):
    host_ip = get_host_ip()
    sys.path.append(dir_path)
    import yaml_utils
    if re.search("live\d+", str(pods)):
        print("\n\033[0;31;40mThe live video playlist URL are below:\033[0m")
    for pod in pods:
        node_name = pods_dict[pod]["node"]
        node = node_dict[node_name]
        limit_cpu = 2 * float(pods_dict[pod]["cpu"]) if 2 * float(
            pods_dict[pod]["cpu"]) < node["cpu"] else node["cpu"] - 1
        limit_memory = 2 * int(pods_dict[pod]["memory"]) if 2 * int(
            pods_dict[pod]["memory"]) < node["memory"] else node["memory"] - 1

        yaml_file = os.path.join(
            dir_path,
            re.match("([A-Za-z]+)\d*$", pod).group(1) +
            "-service-deployment.yaml")
        data = yaml_utils.load_yaml_file(yaml_file)
        data = yaml_utils.update_resource_quotas(data, pods_dict[pod]["cpu"],
                                                 limit_cpu,
                                                 pods_dict[pod]["memory"],
                                                 limit_memory)
        data = yaml_utils.update_nodeSelector(data, node_name)

        if pod == "cdn":
            data = yaml_utils.add_volumeMounts(data, True)
            data = yaml_utils.add_volumes(data, nfs_server, True,
                                          volume_directory)

            node_port = 443
            service_file = dir_path + "/cdn-service-service.yaml"
            service_data = yaml_utils.load_yaml_file(service_file)
            service_data = yaml_utils.set_nodePort(service_data, node_port)
            yaml_utils.dump_yaml_file(service_data, service_file)

        if re.search("((vod)|(live))\d+", pod):
            data = yaml_utils.update_imageName(
                data, pods_dict[pod]["mode"].lower(),
                True if re.search("vod\d+", pod) else False)
            data = yaml_utils.add_volumeMounts(data, False)
            data = yaml_utils.add_volumes(data, nfs_server, False,
                                          volume_directory)
            data = yaml_utils.update_service_name(data, pod + "-service")
            yaml_file = os.path.join(dir_path,
                                     pod + "-service-deployment.yaml")

            if re.search("live\d", pod):
                live_args = {
                    'input_video': pods_dict[pod]["input"],
                    "output_dict": {}
                }
                if trans_cfg_dict[pod]['hwaccel'] == 'false':
                    if trans_cfg_dict[pod]['protocol'] == 'DASH':
                        if trans_cfg_dict[pod][
                                'encoder_type'] == 'AVC' or trans_cfg_dict[pod][
                                    'encoder_type'] == 'HEVC' or trans_cfg_dict[
                                        pod]['encoder_type'] == 'AV1':
                            codec_dict = {
                                "AVC": "libx264",
                                "HEVC": "libsvt_hevc",
                                "AV1": "libsvt_av1"
                            }
                        else:
                            print(
                                "Error: Only support AVC/HEVC/AV1! Please input correct encoder_type in transcode.cfg ("
                                + pod + ")")
                            os._exit()
                    elif trans_cfg_dict[pod]['protocol'] == 'HLS':
                        if trans_cfg_dict[pod][
                                'encoder_type'] == 'AVC' or trans_cfg_dict[
                                    pod]['encoder_type'] == 'HEVC':
                            codec_dict = {
                                "AVC": "libx264",
                                "HEVC": "libsvt_hevc"
                            }
                        else:
                            print(
                                "Error: Only support AVC/HEVC! Please input correct encoder_type in transcode.cfg ("
                                + pod + ")")
                            os._exit()
                    else:
                        print(
                            "Error: Please input correct protocol(HLS/DASH) in transcode.cfg ("
                            + pod + ")")
                        os._exit()
                elif trans_cfg_dict[pod]['hwaccel'] == 'true':
                    if trans_cfg_dict[pod][
                            'encoder_type'] == 'AVC' or trans_cfg_dict[pod][
                                'encoder_type'] == 'HEVC':
                        codec_dict = {
                            "AVC": "h264_vaapi",
                            "HEVC": "hevc_vaapi"
                        }
                    else:
                        print(
                            "Error: Only support AVC/HEVC! Please input correct encoder_type in transcode.cfg ("
                            + pod + ")")
                        os._exit()
                for num in range(4):
                    if pods_dict[pod].get(
                            "transcode" + str(num), None
                    ) and pods_dict[pod]["transcode" + str(num)].get(
                            "protocol", None
                    ) and pods_dict[pod]["transcode" + str(num)].get(
                            "resolution", None) and pods_dict[pod][
                                "transcode" + str(num)].get(
                                    "bitrate", None) and pods_dict[pod][
                                        "transcode" + str(num)].get(
                                            "codec", None) and pods_dict[pod][
                                                "transcode" + str(num)].get(
                                                    "output", None):

                        live_args["output_dict"][
                            pods_dict[pod]["transcode" + str(num)]["output"] +
                            "_" + re.search("live(\d+)", pod).group(1) + "_" +
                            str(num)] = [
                                pods_dict[pod]["transcode" +
                                               str(num)]["protocol"].lower(),
                                pods_dict[pod]["transcode" +
                                               str(num)]["resolution"],
                                pods_dict[pod]["transcode" +
                                               str(num)]["bitrate"],
                                codec_dict[pods_dict[pod]["transcode" +
                                                          str(num)]["codec"]],
                                pods_dict[pod]["transcode" +
                                               str(num)]["framerate"],
                                pods_dict[pod]["transcode" + str(num)]["gop"],
                                pods_dict[pod]["transcode" +
                                               str(num)]["maxbFrames"],
                                pods_dict[pod]["transcode" +
                                               str(num)]["refsNum"],
                                pods_dict[pod]["transcode" +
                                               str(num)]["preset"]
                            ]

                        print(
                            "\033[0;31;40mhttps://%s/%s/%s/index.%s\033[0m" %
                            (host_ip,
                             pods_dict[pod]["transcode" +
                                            str(num)]["protocol"].lower(),
                             pods_dict[pod]["transcode" + str(num)]["output"] +
                             "_" + re.search("live(\d+)", pod).group(1) + "_" +
                             str(num),
                             "m3u8" if pods_dict[pod]["transcode" + str(num)]
                             ["protocol"].lower() == "hls" else "mpd"))
                data = yaml_utils.update_command(
                    data, pods_dict[pod]["mode"].lower(), live_args)

        yaml_utils.dump_yaml_file(data, yaml_file)

    subprocess.call("rm -rf %s/vod-service-deployment.yaml" % dir_path,
                    shell=True)
    subprocess.call("rm -rf %s/live-service-deployment.yaml" % dir_path,
                    shell=True)