Пример #1
0
def remove_edgehub_device():
    print("Removing edgehub device")
    if "IOTHUB_E2E_CONNECTION_STRING" not in os.environ:
        print(
            "ERROR: Iothub connection string not set in IOTHUB_E2E_CONNECTION_STRING environment variable."
        )
        sys.exit(1)
    service_connection_string = os.environ["IOTHUB_E2E_CONNECTION_STRING"]

    config_file = ConfigFile()
    device_connection_string = config_file.contents["provisioning"][
        "device_connection_string"]

    if device_connection_string:
        cn = connection_string_to_dictionary(device_connection_string)
        old_edgehub_device_id = cn["DeviceId"]
        old_edgehub_leaf_device = "{}_leaf_device".format(
            old_edgehub_device_id)
        helper = Helper(service_connection_string)
        if helper.try_delete_device(old_edgehub_device_id):
            print("deleted {}".format(old_edgehub_device_id))
        if helper.try_delete_device(old_edgehub_leaf_device):
            print("deleted {}".format(old_edgehub_leaf_device))

        print("updating config.yaml to remove strings")
        config_file.contents["provisioning"]["device_connection_string"] = ""

        config_file.save()
        print("config.yaml updated")

        print("edgehub test devices removed")
    else:
        print("no devices to remove")
def verifyEnvironmentVariables():
    if "IOTHUB_E2E_CONNECTION_STRING" not in os.environ:
        print(
            "ERROR: Iothub connection string not set in IOTHUB_E2E_CONNECTION_STRING environment variable."
        )
        sys.exit(1)

    if not (
        "IOTHUB_E2E_EDGEHUB_DEVICE_ID" in os.environ
        and "IOTHUB_E2E_EDGEHUB_DNS_NAME" in os.environ
    ):
        try:
            config_file = ConfigFile()
            device_connection_string = config_file.contents["provisioning"][
                "device_connection_string"
            ]
            if "DeviceId=" in device_connection_string:
                os.environ[
                    "IOTHUB_E2E_EDGEHUB_DEVICE_ID"
                ] = connectionStringToDictionary(device_connection_string)["DeviceId"]
            os.environ["IOTHUB_E2E_EDGEHUB_DNS_NAME"] = config_file.contents["hostname"]

        except FileNotFoundError:
            raise Exception(
                "config.yaml not found.  You need to set IOTHUB_E2E_EDGEHUB_DEVICE_ID and IOTHUB_E2E_EDGEHUB_DNS_NAME if you're not running on your edgeHub host"
            )
Пример #3
0
def get_edge_device_id():
    config_file = ConfigFile()
    device_connection_string = config_file.contents["provisioning"][
        "device_connection_string"]

    if device_connection_string:
        return connection_string_to_dictionary(
            device_connection_string)["DeviceId"]
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")
Пример #5
0
def ensure_edge_environment_variables():
    get_service_connection_string()

    if not ("IOTHUB_E2E_EDGEHUB_DEVICE_ID" in os.environ
            and "IOTHUB_E2E_EDGEHUB_DNS_NAME" in os.environ):
        os.environ["IOTHUB_E2E_EDGEHUB_DNS_NAME"] = get_computer_name()
        try:
            config_file = ConfigFile()
            device_connection_string = config_file.contents["provisioning"][
                "device_connection_string"]
            if "DeviceId=" in device_connection_string:
                os.environ[
                    "IOTHUB_E2E_EDGEHUB_DEVICE_ID"] = connection_string_to_dictionary(
                        device_connection_string)["DeviceId"]

        except FileNotFoundError:
            raise Exception(
                "config.yaml not found.  You need to set IOTHUB_E2E_EDGEHUB_DEVICE_ID and IOTHUB_E2E_EDGEHUB_DNS_NAME if you're not running on your edgeHub host"
            )
verifyEnvironmentVariables()

if "IOTHUB_E2E_CONNECTION_STRING" not in os.environ:
    print(
        "ERROR: Iothub connection string not set in IOTHUB_E2E_CONNECTION_STRING environment variable."
    )
    sys.exit(1)

service_connection_string = os.environ["IOTHUB_E2E_CONNECTION_STRING"]

if "IOTHUB_E2E_EDGEHUB_DEVICE_ID" in os.environ:
    old_edgehub_device_id = os.environ["IOTHUB_E2E_EDGEHUB_DEVICE_ID"]
    old_edgehub_leaf_device = "{}_leaf_device".format(old_edgehub_device_id)
    helper = Helper(service_connection_string)
    if helper.try_delete_device(old_edgehub_device_id):
        print("deleted {}".format(old_edgehub_device_id))
    if helper.try_delete_device(old_edgehub_leaf_device):
        print("deleted {}".format(old_edgehub_leaf_device))

    print("updating config.yaml to remove strings")
    config_file = ConfigFile()
    config_file.contents["provisioning"]["device_connection_string"] = ""

    config_file.save()
    print("config.yaml updated")

    print("edgehub test devices removed")
else:
    print("no devices to remove")
Пример #7
0
host = connection_string_to_sas_token(service_connection_string)["host"]
print("Creating new device on hub {}".format(host))

if "IOTHUB_E2E_EDGEHUB_DEVICE_ID" in os.environ:
    old_edgehub_device_id = os.environ["IOTHUB_E2E_EDGEHUB_DEVICE_ID"].lower()
    old_edgehub_leaf_device = "{}_leaf_device".format(old_edgehub_device_id)
    helper = Helper(service_connection_string)
    if helper.try_delete_device(old_edgehub_device_id):
        print("deleted {}".format(old_edgehub_device_id))
    if helper.try_delete_device(old_edgehub_leaf_device):
        print("deleted {}".format(old_edgehub_leaf_device))
hub = createNewHubInstance(service_connection_string)
hub.deployModules("friend,node")

print("updating config.yaml to insert connection string")
config_file = ConfigFile()
config_file.contents["provisioning"][
    "device_connection_string"] = hub.edge_hub_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()
print("config.yaml updated")