def set_config_yaml():
    iothub_service_helper = IoTHubServiceHelper(
        settings.iothub.connection_string)
    settings.iotedge.connection_string = iothub_service_helper.get_device_connection_string(
        settings.iotedge.device_id)

    print("updating config.yaml to insert connection string")
    config_file = ConfigFile()
    config_file.contents["provisioning"][
        "device_connection_string"] = settings.iotedge.connection_string

    if ("IOTEDGE_DEBUG_LOG" in os.environ
            and os.environ["IOTEDGE_DEBUG_LOG"].lower() == "true"):
        print(
            "IOTEDGE_DEBUG_LOG is set. setting edgeAgent RuntimeLogLevel to debug"
        )
        config_file.contents["agent"]["env"]["RuntimeLogLevel"] = "debug"
    else:
        print(
            "IOTEDGE_DEBUG_LOG is not set. clearing edgeAgent RuntimeLogLevel")
        if "RuntimeLogLevel" in config_file.contents["agent"]["env"]:
            del config_file.contents["agent"]["env"]["RuntimeLogLevel"]

    config_file.save()
    settings.save()
    print("config.yaml updated")
Beispiel #2
0
def populate_credentials():
    iothub_service_helper = IoTHubServiceHelper(
        settings.iothub.connection_string)

    if settings.iotedge.device_id:
        settings.iotedge.ca_cert_base64 = get_edge_ca_cert_base64()

    for device in (settings.leaf_device, settings.test_device):
        if device.device_id:
            if device.connection_type.startswith("connection_string"):
                device.connection_string = iothub_service_helper.get_device_connection_string(
                    device.device_id)
                if device.connection_type.endswith("_with_edge_gateway"):
                    device.connection_string += ";GatewayHostName={}".format(
                        settings.iotedge.hostname)
                print("Added connection string for {} device {}".format(
                    device.name, device.device_id))

    for module in (settings.test_module, settings.friend_module):
        if module.device_id and module.module_id:

            if (module.connection_type.startswith("connection_string")
                    or module.connection_type == "environment"):
                module.connection_string = iothub_service_helper.get_module_connection_string(
                    module.device_id, module.module_id)
                if (module.connection_type.endswith("_with_edge_gateway")
                        or module.connection_type == "environment"):
                    module.connection_string += ";GatewayHostName={}".format(
                        settings.iotedge.hostname)

                print("Added connection string for {} module {},{}".format(
                    module.name, module.device_id, module.module_id))
    settings.save()