def horton_delete_identities_and_containers(self, save_manifest_file): init(autoreset=True) print(Fore.GREEN + "Deleting Devices/Modules/Containers in IotHub and Docker from: {}".format(save_manifest_file)) deployment_json = self.get_deployment_model_json(save_manifest_file) hub_connect_string = self.get_env_connect_string() helper = Helper(hub_connect_string) try: identity_json = deployment_json['containers'] for containers in identity_json: container_json = identity_json[containers] container_name = container_json['name'] self.delete_container(container_name) except: print(Fore.RED + "Exception Processing HortonManifest Containers: " + save_manifest_file, file=sys.stderr) traceback.print_exc() sys.exit(-1) try: identity_json = deployment_json['identities'] for azure_device in identity_json: device_json = identity_json[azure_device] objectType = device_json['objectType'] if objectType in ["iothub_device", "iotedge_device"]: device_id = device_json['deviceId'] print("deleting device {}".format(device_id)) helper.try_delete_device(device_id) except: print(Fore.RED + "Exception Processing HortonManifest Identities: " + save_manifest_file, file=sys.stderr) traceback.print_exc() sys.exit(-1) return True
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")