# Pcddebugger Utility

## PCDdebugger

PCDdebugger is a command-line Python script designed to simplify and accelerate the troubleshooting process for **PCD Virtualization** environments. It automates the collection of diagnostic information for various services and resources, consolidating the output into a structured directory for easy analysis and sharing.

## Features

* **Comprehensive Data Collection:** Gathers detailed information for key PCD resources including VMs (Nova), images (Glance), networks (Neutron), ports, volumes (Cinder), stacks (Heat), and users (Keystone).
* **Kubernetes Integration:** Performs a complete MySQL dump from a specified Kubernetes namespace, essential for debugging control plane issues.
* **Dependency Traversal:** Automatically discovers and collects data for resources related to a specified VM, such as its ports, volumes, network, subnets, image, and flavor.
* **Organized Output:** Saves all collected data into a timestamped directory, with subfolders for each service, making the information easy to navigate.
* **Archive Option:** Includes a --zip flag to automatically create a compressed archive of the collected data, ready for sharing.

## Prerequisites

Before running the script, ensure the following are installed and configured on your machine:

* **pcd client:** Authenticated and configured to connect to your PCD cloud. (**Ensure your rc file is sourced**).
* **kubectl:** Authenticated and configured to connect to your Kubernetes cluster. (This is required only in case of mysql dump)

## Installation

{% stepper %}
{% step %}

### Mac-OS

* Download the binary:

{% code title="Command" %}

```bash
curl -LO https://github.com/platform9/PCDDebugger/releases/download/v2.0.1/PCDdebugger-v2.0.1-macos
```

{% endcode %}

* Rename the binary file (Optional):

{% code title="Command" %}

```bash
mv PCDdebugger-v2.0.1-macos PCDdebugger
```

{% endcode %}

* Make the script executable:

{% code title="Command" %}

```bash
chmod +x ./PCDdebugger
```

{% endcode %}

* To run PCDdebugger from any directory, move it to a location in your system's PATH (Optional):

{% code title="Command" %}

```bash
sudo mv PCDdebugger /usr/local/bin/
```

{% endcode %}

{% hint style="info" %}
Mac-OS will ask to allow the permission to run the PCDDebugger binary. Allow it from the System Settings → Privacy and Security.
{% endhint %}
{% endstep %}

{% step %}

### Linux

* Download the binary:

{% code title="Command" %}

```bash
curl -LO https://github.com/platform9/PCDDebugger/releases/download/v2.0.1/PCDdebugger-v2.0.1-linux
```

{% endcode %}

* Rename the binary file (Optional):

{% code title="Command" %}

```bash
mv PCDdebugger-v2.0.1-linux PCDdebugger
```

{% endcode %}

* Make the binary executable:

{% code title="Command" %}

```bash
chmod +x PCDdebugger
```

{% endcode %}

* To run PCDdebugger from any directory, move it to a location in your system's PATH (Optional):

{% code title="Command" %}

```bash
sudo mv PCDdebugger /usr/local/bin/
```

{% endcode %}
{% endstep %}

{% step %}

### Windows

* Download the binary:

{% code title="Powershell" %}

```powershell
curl -L https://github.com/platform9/PCDDebugger/releases/download/v2.0.1/PCDdebugger-v2.0.1-windows.exe -o PCDdebugger.exe
```

{% endcode %}

* Place it in a folder (example): Move the downloaded `PCDdebugger.exe` file to a memorable location, for example, C:\Tools.
* (Optional) Add to PATH so you can run it from any command prompt:
  1. Search for "Edit the system environment variables" in the Start Menu.
  2. Click the "Environment Variables..." button.
  3. Under "System variables", find and select the Path variable, then click "Edit...".
  4. Click "New" and add the path to the folder (e.g., C:\Tools).
  5. Click OK on all windows to save.
* Run `PCDdebugger.exe` from PowerShell or Command Prompt.
  {% endstep %}
  {% endstepper %}

## Usage

The basic command structure is:

{% tabs %}
{% tab title="command" %}
{% code title="Command" %}

```bash
./PCDdebugger [RESOURCE_FLAG] [OPTIONS] [--insecure]
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
The "--insecure" parameter is mandatory if SSL is not configured; otherwise it will throw an "SSL Certificate" error.
{% endhint %}

### Examples

* Collect all information for a specific VM (gathers the VM, its ports, volumes, network, subnets, image, and flavor):

{% code title="Command" %}

```bash
./PCDdebugger --vm <VM_UUID>
```

{% endcode %}

* Collect details for a specific Glance image:

{% code title="Command" %}

```bash
./PCDdebugger --image <IMAGE_UUID>
```

{% endcode %}

* Collect details for a Neutron network and its subnets:

{% code title="Command" %}

```bash
./PCDdebugger --network <NETWORK_UUID>
```

{% endcode %}

* Perform a MySQL dump from a Kubernetes cluster (requires --namespace):

{% code title="Command" %}

```bash
./PCDdebugger --mysql-dump --namespace <WORKLOAD_REGION>
```

{% endcode %}

{% hint style="info" %}
The "--mysql-dump" parameter can only be run on the Self Hosted PCD Virtualization.
{% endhint %}

* Combine multiple flags and create a zip archive:

{% code title="Command" %}

```bash
./PCDdebugger --vm <VM_UUID> --mysql-dump --namespace <K8S_NAMESPACE> --zip
```

{% endcode %}

* Specify a custom output directory and create a zip archive:

{% code title="Command" %}

```bash
./PCDdebugger --vm <VM_UUID> --output <PATH_TO_DIRECTORY> --zip
```

{% endcode %}

Example:

{% code title="Command" %}

```bash
./PCDdebugger --vm aa1bb1cc3-dd4ee5ff6-gg7hh8-ii9jj10kk --output /tmp --zip
```

{% endcode %}

Command-Line Flags:

* `--vm <ID_OR_NAME>`: Collect details for a specific Nova VM and its related resources.
* `--image <ID_OR_NAME>`: Collect details for a specific Glance image.
* `--network <ID_OR_NAME>`: Collect details for a specific Neutron network and its subnets.
* `--port <ID_OR_NAME>`: Collect details for a specific Neutron port.
* `--volume <ID_OR_NAME>`: Collect details for a specific Cinder volume.
* `--stack <ID_OR_NAME>`: Collect details for a specific Heat stack.
* `--user <ID_OR_NAME>`: Collect details for a specific Keystone user.
* `--mysql-dump`: Perform a MySQL dump of all databases. **Requires** `--namespace`.
* `--namespace <NAMESPACE>`: The Kubernetes namespace to use for the MySQL dump.
* `--output <DIRECTORY>`: Specify a custom directory for the output files.
* `--zip`: Compress the final output directory into a `.zip` file.
* `--help`: Show the help message and exit.

{% hint style="info" %}
All output is saved to a directory named PCDdebugger- by default.
{% endhint %}

## Additional Information

For more details, visit the GitHub page: <https://github.com/platform9/PCDDebugger>
