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")
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")
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")