def medialive_channel_mediaconnect_flow_ddb_items()

in source/msam/chalicelib/connections.py [0:0]


def medialive_channel_mediaconnect_flow_ddb_items():
    """
    Identify and format MediaLive channel outputs to MediaConnect flow for cache storage.
    """
    items = []
    try:
        # get medialive channels
        medialive_ch_cached = cache.cached_by_service("medialive-channel")
        # get mediaconnect flows
        mediaconnect_flows_cached = cache.cached_by_service("mediaconnect-flow")

        # only look for RTP destinations because EMX does not support UDP source
        for ml_channel in medialive_ch_cached:
            ml_channel_data = json.loads(ml_channel["data"])
            for destination in ml_channel_data["Destinations"]:
                for setting in destination["Settings"]:
                    ml_url = setting["Url"]
                    parsed_destination = urlparse(ml_url)
                    if parsed_destination.scheme == 'rtp':
                        dest_ip_port = parsed_destination.netloc
                        for flow in mediaconnect_flows_cached:
                            flow_data = json.loads(flow["data"])
                            # for each flow, process each source
                            for flow_source in flow_data["Sources"]:
                                if "Transport" in flow_source:
                                    if "rtp" in flow_source["Transport"]["Protocol"]:
                                        if dest_ip_port == flow_source["IngestIp"]+":"+str(flow_source["IngestPort"]):
                                            #add this connection
                                            config = {
                                                "from":
                                                ml_channel["arn"],
                                                "to":
                                                flow["arn"],
                                                "scheme": flow_source["Transport"]["Protocol"].upper()
                                            }
                                            print(config)
                                            items.append(
                                                connection_to_ddb_item(
                                                    ml_channel["arn"], flow["arn"],
                                                    "medialive-channel-mediaconnect-flow", config))
    except ClientError as error:
        print(error)
    return items