Metadata-Version: 2.4
Name: aos-virt-unit
Version: 1.0.0
Summary: AosEdge virtual unit / host VM deployment tooling
Author: EPAM Systems Inc.
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: azure-core>=1.39.0
Requires-Dist: azure-identity>=1.25.3
Requires-Dist: azure-mgmt-compute>=37.2.0
Requires-Dist: azure-mgmt-network>=30.2.0
Requires-Dist: azure-mgmt-resource>=25.0.0
Requires-Dist: boto3>=1.42.84
Requires-Dist: botocore>=1.42.84
Requires-Dist: paramiko>=4.0.0
Requires-Dist: psutil>=7.2.2
Requires-Dist: pycdlib>=1.14.0
Requires-Dist: PyYAML>=6.0.3
Requires-Dist: requests>=2.33.1
Requires-Dist: tomli>=2.0.1; python_version < "3.11"
Dynamic: license-file

<h1 align="center">AosEdge VM Infrastructure</h1>

<p align="center">
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue" alt="license: Apache 2.0"></a>
  <img src="https://img.shields.io/badge/platform-Linux%20%7C%20Windows-lightgrey" alt="platform: Linux | Windows">
  <img src="https://img.shields.io/badge/arch-x86__64%20%7C%20aarch64-brightgreen" alt="arch: x86_64 | aarch64">
</p>

## Introduction

Deploy AosEdge host VMs and AosEdge units from one CLI tool.

## Features

Manage host VMs and units on VirtualBox, AWS, or Azure. Deploy and provision with `aos-virt-unit`; run `cleanup` when needed.

---

## Prerequisites

| Requirement | Applies to                                                                                                                                                          |
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Python 3.10+ | Every deployment                                                                                                                                                    |
| SSH key pair `AosEdge_key` / `AosEdge_key.pub` in `~/.ssh/` (Linux) or `%USERPROFILE%\.ssh\` (Windows) | Every deployment                                                                                                                                                    |
| Packer 1.12+ on `PATH` | Every deployment (builds host images)                                                                                                                               |
| `aos-prov` + OEM cert `~/.aos/security/aos-user-oem.p12` (Linux) or `%USERPROFILE%\.aos\security\aos-user-oem.p12` (Windows) | AosCloud provisioning — [Set up your host](https://docs.aosedge.tech/docs/quick-start/set-up/), [get access](https://docs.aosedge.tech/docs/quick-start/get-access) |
| VirtualBox 7.1.10+ | VirtualBox deployments                                                                                                                                              |
| AWS account + credentials | AWS deployments                                                                                                                                                     |
| Azure CLI + subscription | Azure deployments                                                                                                                                                   |

---

## How to deploy

### 1. Set up the Aos SDK environment

Follow [Set up your host](https://docs.aosedge.tech/docs/quick-start/set-up/). That guide creates the SDK venv and installs CLI tools (including `aos-prov`).

### 2. Install `aos-virt-unit`

Install this tool into the same venv:

**Linux:**
```bash
~/.aos/venv/bin/pip install aos-virt-unit
```

**Windows (PowerShell):**
```powershell
& "$env:USERPROFILE\.aos\venv\Scripts\pip.exe" install aos-virt-unit
```

Later steps use the same venv binaries by full path (no need to activate the venv).

### 3. Create a project

Pick a folder where you want this deployment to live, `cd` there, then run `init`:

**Linux:**
```bash
cd ~/my-aos-deployment
~/.aos/venv/bin/aos-virt-unit init
```

**Windows (PowerShell):**
```powershell
cd "$env:USERPROFILE\my-aos-deployment"
& "$env:USERPROFILE\.aos\venv\Scripts\aos-virt-unit.exe" init
```

That folder becomes your project — everything for this deployment stays in it:

```text
./
├── config.yaml      # edit before deploy (step 4)
└── artifacts/       # logs and images (filled in by deploy)
```

Use the same folder for `deploy` and `cleanup`.

### 4. Edit `config.yaml`

`init` creates `config.yaml` from the default example template [`config.example.yaml`](src/aos_virt_unit/resources/config.example.yaml) (multi-provider sample). The example below shows one local VirtualBox deployment (main + secondary unit nodes) with AosCloud registration. Adjust or add more entries under `deployments` as needed.

**Example `config.yaml`:**

```yaml
unit_config: &unit_config
  unit:
    node_configs:
      - name: main
        cpu: 1
        mem: 3G
        ip: 10.0.0.100
        uefi: true
        image: "main.qcow2"
        arch: "amd64"
      - name: secondary
        cpu: 1
        mem: 3G
        uefi: true
        image: "secondary.qcow2"
        arch: "amd64"

aos_core_images: &aos_core_images
  url: https://github.com/aosedge/meta-aos-vm/releases/download/v5.2.2/aos-vm-image-qemux86-64-5.2.2.tar.xz

virtualbox: &virtualbox
  build_vm:
    url:   # optional; leave empty to build with Packer, or set an HTTPS .vmdk URL to skip Packer
    name: build_vm
    cpu: 2
    ram: 2GB
    ubuntu_image_url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.ova
  host_vm:
    cpu: 4
    ram: 10GB
    disk: 20GB

run:
  type: sequential
  max_workers: 1
  fail_handling_mode: continue

deployments:
  - deployment_name: "my-local-host"
    deployment_type: virtualbox
    provider_config: *virtualbox
    aos_core_images: *aos_core_images
    unit_config: *unit_config
    provision_unit: true
```

For AWS or Azure, change `deployment_type` and `provider_config`, set cloud IDs/regions in `config.yaml`, and complete [cloud credentials](#cloud-credentials-aws-and-azure) before `deploy`. Full templates: [`config.example.yaml`](src/aos_virt_unit/resources/config.example.yaml). Field reference: [Config reference](#config-reference).

### 5. Before deploy

**VirtualBox:** leave enough disk space under `artifacts/`. VT-x/AMD-V in firmware is optional; enabling CPU virtualization can improve performance for unit QEMU nodes on the host VM.

**AWS or Azure:** [Cloud credentials](#cloud-credentials-aws-and-azure) and matching fields in `config.yaml`.

### 6. Deploy

**Linux:**
```bash
~/.aos/venv/bin/aos-virt-unit deploy
```

**Windows (PowerShell):**
```powershell
& "$env:USERPROFILE\.aos\venv\Scripts\aos-virt-unit.exe" deploy
```

The tool builds or reuses the host image, starts the host VM, downloads the unit image archive (`.tar.xz`), starts unit nodes, and provisions.

### 7. Clean up (if needed)

**Linux:**
```bash
~/.aos/venv/bin/aos-virt-unit cleanup virtualbox --single-host-vm
```

**Windows (PowerShell):**
```powershell
& "$env:USERPROFILE\.aos\venv\Scripts\aos-virt-unit.exe" cleanup virtualbox --single-host-vm
```

Run from the same directory as `deploy`. Other providers:

**Linux:**
```bash
~/.aos/venv/bin/aos-virt-unit cleanup aws --all
~/.aos/venv/bin/aos-virt-unit cleanup azure --deployment-name <name>
~/.aos/venv/bin/aos-virt-unit cleanup
```

**Windows (PowerShell):**
```powershell
& "$env:USERPROFILE\.aos\venv\Scripts\aos-virt-unit.exe" cleanup aws --all
& "$env:USERPROFILE\.aos\venv\Scripts\aos-virt-unit.exe" cleanup azure --deployment-name <name>
& "$env:USERPROFILE\.aos\venv\Scripts\aos-virt-unit.exe" cleanup
```

Add `--force` to skip the confirmation prompt on any platform.

---

<a id="cloud-credentials-aws-and-azure"></a>

## Cloud credentials (AWS and Azure)

<a id="cloud-credentials-aws"></a>

### AWS (example)

**Linux:**
```bash
export AWS_ACCESS_KEY_ID="your-access-key-id"
export AWS_SECRET_ACCESS_KEY="your-secret-access-key"
export AWS_DEFAULT_REGION="eu-central-1"
aws sts get-caller-identity
```

**Windows (PowerShell):**
```powershell
$env:AWS_ACCESS_KEY_ID     = "your-access-key-id"
$env:AWS_SECRET_ACCESS_KEY = "your-secret-access-key"
$env:AWS_DEFAULT_REGION    = "eu-central-1"
aws sts get-caller-identity
```

<a id="cloud-credentials-azure"></a>

### Azure (example)

The Azure CLI commands are identical on both platforms:

```bash
az login
az account set --subscription "<SUBSCRIPTION_ID>"
az account show
```

`<SUBSCRIPTION_ID>` must match `subscription_id` in `config.yaml` for your `azure` deployment.

---

<a id="config-reference"></a>

## Config reference

`config.yaml` at the project root; optional YAML anchors (`&name`, `*name`). Authoritative sample: [`config.example.yaml`](src/aos_virt_unit/resources/config.example.yaml).

### Layout (overview)

```yaml
unit_config: &unit_config
  unit:
    node_configs: [ ... ]

aos_core_images: &aos_core_images
  url: <https URL to unit .tar.xz>

virtualbox: &virtualbox
  build_vm: { ... }
  host_vm: { ... }

aws: &aws
  region: ...
  key_pair_name: ...
  # ...

azure: &azure
  subscription_id: ...
  # ...

run:
  type: sequential        # sequential | parallel
  max_workers: 1
  fail_handling_mode: continue   # continue | fail-fast

deployments:
  - deployment_name: "..."
    deployment_type: virtualbox | aws | azure
    provider_config: *virtualbox
    aos_core_images: *aos_core_images
    unit_config: *unit_config
    provision_unit: true | false
```

### `run`

How `deploy` processes the `deployments` list. This is not the CLI command name and not `artifacts/run.log`. Defaults if omitted: `sequential`, `max_workers: 1`, `continue`.

| Field | Required | Description |
|-------|----------|-------------|
| `type` | no | `sequential` or `parallel`. |
| `max_workers` | no | Maximum deployments in parallel when `type` is `parallel`; integer ≥ 1. |
| `fail_handling_mode` | no | `continue` or `fail-fast`. |

### `deployments`

Each item = one host VM + one unit.

| Field | Required | Description |
|-------|----------|-------------|
| `deployment_name` | yes | Host label (EC2 name, Azure computer name, etc.). Azure: ≤ 64 chars; no spaces or these characters among others: `_ \ | ; : ' " , < > / ?`. |
| `deployment_type` | yes | `virtualbox`, `aws`, or `azure`. |
| `provider_config` | yes | Provider block — see [virtualbox](#provider-virtualbox), [aws](#provider-aws), [azure](#provider-azure). |
| `aos_core_images.url` | yes | HTTPS `.tar.xz` of unit QEMU images ([meta-aos-vm](https://github.com/aosedge/meta-aos-vm) releases). |
| `unit_config` | yes | `unit.node_configs` — see [`unit_config`](#unit_config). |
| `provision_unit` | yes | `true`: needs `aos-prov` and OEM cert. `false`: host + unit only, no AosCloud registration. |

<a id="unit_config"></a>

### `unit_config`

| Field | Required | Description |
|-------|----------|-------------|
| `name` | yes | Node name; on host often `<name>.aos-unit`. |
| `image` | yes | QEMU image file name. |
| `arch` | yes | `arm64`, `amd64`, or `x86_64`; same family per deployment. |
| `cpu` | yes | vCPUs for the node. |
| `mem` / `ram` | yes | e.g. `3G`, `2GB`. |
| `ip` | no | Main node only (for now). Default `10.0.0.100`. Omit on secondary. |
| `uefi` | yes | `true` for typical [meta-aos-vm](https://github.com/aosedge/meta-aos-vm) qcow2 disks. |

<a id="provider-virtualbox"></a>

### Provider: `virtualbox`

| Field | Required | Description |
|-------|----------|-------------|
| `build_vm.name` | yes | Packer build name (shared across VirtualBox deployments). |
| `build_vm.cpu` / `ram` | yes | Build VM size. |
| `build_vm.ubuntu_image_url` | yes | Ubuntu OVA/cloud image URL. |
| `build_vm.url` | no | Pre-built `.vmdk` HTTPS URL — skips Packer if set. Leave empty to build with Packer. |
| `host_vm.cpu` | yes | Integer or `max` (all host cores). |
| `host_vm.ram` / `disk` | yes | Host VM resources. |

<a id="provider-aws"></a>

### Provider: `aws`

| Field | Required | Description |
|-------|----------|-------------|
| `region` | yes | AWS region. |
| `key_pair_name` | yes | EC2 key name in `region`. |
| `ami_version` | yes | AMI reuse label. |
| `architecture` | yes | `arm64` or `amd64` / `x86_64`. |
| `instance_type_arm` / `instance_type_amd` | yes | Nested-capable types recommended for QEMU units. |

<a id="provider-azure"></a>

### Provider: `azure`

| Field | Required | Description |
|-------|----------|-------------|
| `subscription_id` | yes | Subscription GUID. |
| `location` | yes | Region. |
| `managed_image_resource_group_name` | yes | Gallery RG; `""` reuses `resource_group_name`. |
| `shared_image_gallery_name` | yes | Gallery name (no hyphens). |
| `resource_group_name` | yes | Host VM / network RG. |
| `network_security_group_name` | yes | NSG name. |
| `security_rule_name` / `priority` | yes | Unique per shared RG. |
| `virtual_network_name` / `address_prefix` | yes | VNet. |
| `subnet_name` / `address_prefix` | yes | Subnet. |
| `public_ip_address_name` | yes | Public IP. |
| `network_interface_name` | yes | NIC. |
| `vm_size_arm` / `vm_size_amd` | yes | Nested-capable SKUs for QEMU. |
| `image_arm` / `image_amd` | yes | Marketplace `publisher:offer:sku:version`. |
| `az_image_disk` | yes | Packer builder disk (≥ `30GB` for Jammy). |
| `host_vm_image_version` | yes | `Major.Minor.Patch` (e.g. `1.0.0`). |
| `architecture` | yes | `arm64` or `amd64`. |

---

## Troubleshooting

Logs (paths are printed when `deploy` starts):

| Log | Contents |
|-----|----------|
| `artifacts/run.log` | Whole run |
| `artifacts/deployments/<deployment_name>/run.log` | One deployment |

| Symptom | What to check |
|---------|----------------|
| `deploy` failed or unclear errors | Logs above — start with `artifacts/run.log`, then the deployment's `…/run.log`. |
| Wrong AWS account / API denied | [AWS credentials](#cloud-credentials-aws); `aws sts get-caller-identity`; check `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_DEFAULT_REGION` (PowerShell: `$env:AWS_*`). |
| Azure auth / subscription | [Azure credentials](#cloud-credentials-azure); `az account show`, `subscription_id`. |
| VirtualBox / Packer not found | `VBoxManage --version`, `packer version`, check `PATH` / `$env:PATH`. |
| SSH failures | Key at `~/.ssh/AosEdge_key` (Linux) or `%USERPROFILE%\.ssh\AosEdge_key` (Windows), `key_pair_name` (AWS), NSG/firewall. |
| `aos-prov` / certificate | [Get access](https://docs.aosedge.tech/docs/quick-start/get-access); check `provision_unit` and cert path. |
| `deploy` touches unexpected providers | Check every entry under `deployments` in `config.yaml` — `deploy` runs them all. |

---

## Support

- [AosEdge Documentation](https://docs.aosedge.tech/)
- [Get access / AosCloud](https://docs.aosedge.tech/docs/quick-start/get-access)
- [aos_vm_infra_assets](https://github.com/aosedge/aos_vm_infra_assets)

---
