phsm opened a new pull request, #11061:
URL: https://github.com/apache/cloudstack/pull/11061
### Description
This PR adds `<metadata>` section to the domain XML of the virtual machine.
<!--- Describe your changes in DETAIL - And how has behaviour functionally
changed. -->
It is useful when the additional instance info is needed from within the
compute host,
for example to use it with a monitoring exporter that would label the
virtual machine with the additional information.
The method that generates the metadata object is defined in the
`HypervisorGuruBase` class as protected, so it can be used in all its children
classes. Currently I've only used it in the `KVMGuru` because I do not have any
other hypervisor kind to test this on.
Additionally, some dead code that looks to be half-finished, was removed,
namely
LibvirtVMDef.java: `public class MetadataDef` and the references to it.
Kindly check this part, perhaps I accidentally remove something that was
obscurely used by something.
Fixes: #6695
<!-- For new features, provide link to FS, dev ML discussion etc. -->
<!-- In case of bug fix, the expected and actual behaviours, steps to
reproduce. -->
<!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be
closed when this PR gets merged -->
<!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" -->
<!-- Fixes: # -->
<!---
*******************************************************************************
-->
<!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE
DOCUMENTATION. -->
<!--- PLEASE PUT AN 'X' in only **ONE** box -->
<!---
*******************************************************************************
-->
### Types of changes
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
- [ ] build/CI
- [ ] test (unit or integration test code)
### Feature/Enhancement Scale or Bug Severity
#### Feature/Enhancement Scale
- [ ] Major
- [x] Minor
#### Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [ ] Major
- [ ] Minor
- [ ] Trivial
### Screenshots (if appropriate):
The metadata has the following format:
```xml
<metadata>
<cloudstack:instance
xmlns:cloudstack="http://cloudstack.apache.org/instance">
<cloudstack:zone
uuid="e2b3416d-d21a-4907-8865-a3caeeae6a82">ZoneName</cloudstack:zone>
<cloudstack:pod
uuid="962722db-62eb-4ad4-8485-254d87c3050c">PodName</cloudstack:pod>
<cloudstack:cluster
uuid="aff7c9e2-aba8-4e8e-bcec-425d1c5e08ee">clusterName</cloudstack:cluster>
<cloudstack:name>testname</cloudstack:name>
<cloudstack:internal_name>i-64-320-VM</cloudstack:internal_name>
<cloudstack:display_name>testdisplayname</cloudstack:display_name>
<cloudstack:uuid>365622ff-5902-4c7b-beda-1790f99162f9</cloudstack:uuid>
<cloudstack:service_offering>
<cloudstack:name>serviceOfferingName</cloudstack:name>
<cloudstack:cpu>2</cloudstack:cpu>
<cloudstack:memory>4096</cloudstack:memory>
<cloudstack:host_tags>
<cloudstack:tag>hosttag1</cloudstack:tag>
<cloudstack:tag>hosttag2</cloudstack:tag>
</cloudstack:host_tags>
</cloudstack:service_offering>
<cloudstack:created_at>2025-06-19T13:13:43</cloudstack:created_at>
<cloudstack:started_at>2025-06-19T13:17:08</cloudstack:started_at>
<cloudstack:owner>
<cloudstack:domain
uuid="06fe1128-8252-11ef-8f6c-00163e3b404b">ROOT</cloudstack:domain>
<cloudstack:account
uuid="04c2e6cd-eb39-4619-9dbb-670fe27f2807">PrjAcct-test-1</cloudstack:account>
<cloudstack:project
uuid="0c437d02-7429-47b4-b5a4-19fb4bb452ff">test</cloudstack:project>
</cloudstack:owner>
<cloudstack:resource_tags/>
</cloudstack:instance>
</metadata>
```
### How Has This Been Tested?
I specifically put an emphasis on compatibility with the previous versions,
so having a mgmt server with this feature/agent without this feature and vice
versa will not crash the VM startup.
These are the tests that I preformed:
Both the Mgmt servers and the Nodes contain this patch:
- Start a VM on a random host: works
- Start a VM on a specific host: works
- Start a VM with and without resource tags: works, the resource_tags
becomes an empty array `<cloudstack:resource_tags/>`
- Start a VM with and without service offering host tags: works, the
host_tags becomes an empty array `<cloudstack:host_tags/>`
- VM does not belong to a project: works, the project becomes empty
`<cloudstack:project uuid=""/>`
- VM belongs to a project: works, the project info is shown.
- Livemigrate a VM with metadata between the hosts having this patch: works
Mgmt server contains the patch, the node does not contain the patch:
- Start a VM: works, the metadata section is absent
- Migrate a VM from a non-patched host to a patched host: works, the
metadata is abesnt on the destination domain XML (because it is only formed
during the VM start)
- Migrate a VM from a patched host to a non-patched host: works, the
metadata is present on the destination domain XML
Mgmt server does not contain the patch, the host contains the patch:
- Start a VM: works, the metadata section is absent because
createMetadataDef() returns null, and createVMFromSpec() does not try to append
add this component to the LibvirtVMDef object.
- Migrate a VM from a patched host to a non-patched host, and then migrate
back: works
<!-- Please describe in detail how you tested your changes. -->
<!-- Include details of your testing environment, and the tests you ran to
-->
#### How did you try to break this feature and the system with this change?
I specifically checked for the empty values in my tests: service offering
without tags, no resource tags, no project etc as those look to be the most
dangerous parts.
Plus, the code checks for null value everywhere, and uses "unknown" default
value when null is occurred.
<!-- see how your change affects other areas of the code, etc. -->
<!-- Please read the
[CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
document -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]