vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
149 stars 33 forks source link

[FEATURE] No option for xenstoredata #261

Closed ravager-dk closed 4 months ago

ravager-dk commented 9 months ago

Although the XAPI supports xenstoredata there is no such option in the provider for VMs. Request add option like:

resource "xenorchestra_vm" VM" { affinity_host = data.xenorchestra_host.host.id count = length(var.ip) cpus = 2 disk { attached = true name_label = VM${count.index + 1}-Disk0" size = 20000000000 sr_id = data.xenorchestra_sr.local_storage.id } template = data.xenorchestra_template.mytemplate.id exp_nested_hvm = false memory_max = 2147483648 name_description = "Virtual Appliance" name_label = "VM${count.index + 1}" network { attached = true

device = 0

network_id = data.xenorchestra_network.MyNet.id

} cdrom { id = resource.xenorchestra_vdi.iso[count.index].id } vga = "cirrus" videoram = 4 xenstoredata = { "vm-data/whatever" = "Testdata" } }

ravager-dk commented 9 months ago

@ddelnano I have an attempt at this in my fork currently, but my knowledge of the API we are hitting on the xenorchestra server is limited, So I am not actually entirely sure where to look up the format in that source code. Perhaps you know?

ddelnano commented 9 months ago

@ravager-dk the API is self describing with the xo-cli. If you run xo-cli --list-commands you will see most of the arguments exposed.

ddelnano@ddelnano-desktop:~$ xo-cli --list-commands | grep vm.create
vm.create [affinityHost=<string>] [bootAfterCreate=<boolean>] [cloudConfig=<string>] [networkConfig=<string>] [coreOs=<boolean>] [clone=<boolean>] [coresPerSocket=<string|number>] [resourceSet=<string>] [destroyCloudConfigVdiAfterBoot=<boolean>] [installation=<object>] [vgpuType=<string>] [gpuGroup=<string>] name_label=<string> [name_description=<string>] [pv_args=<string>] [share=<boolean>] template=<string> [VIFs=<array>] [VDIs=<array>] [existingDisks=<object>] [hvmBootFirmware=<string>] [copyHostBiosStrings=<boolean>] *=<unknown type>

Xenstoredata is not part of that today, so that would need to be a feature request for the vatesfr/xen-orchestra project. It looks like there was some discussion on https://github.com/vatesfr/xen-orchestra/issues/2003 and the decision was that cloudinit was a more standard interface to provide boot configuration.

Could you explain more about how you intend to use xenstore? Have you evaluated cloudinit for your use case?

ravager-dk commented 9 months ago

@ddelnano thanks for the info. I had not seen that xo-cli could be used to gather the API info. I was looking through the xen-orchestra source and found several references to xenstoredata in there, so I assumed it was OK. The problem I have is that when deploying Netscaler VPX's the only supported way to auto provision the IP information is via xenstoredata - https://support.citrix.com/article/CTX128236/how-to-autoprovision-netscaler-vpx-on-xenserver

My only other option is to switch to the xenserver provider instead, which has this option communicating directly with the xenserver. I would however prefer some degree of feature parity between xenorchestra and xenserver. I don't need it in the UI of xenorchestra, just in the API.

ravager-dk commented 8 months ago

This depends a bit on the strategy of #263. Xenstore data for Netscaler VMs does not take effect if the VM is running. There are several ways to implement it. One strategy would be to not set start the VM on creation if xenstore data param is set, then do a VM.set and then VM.start. What do you think @ddelnano ?

ddelnano commented 4 months ago

@ravager-dk this functionality will be available in v0.28.0. I'll be making that release tomorrow once our main build's nightly job succeeds

ravager-dk commented 4 months ago

@ravager-dk this functionality will be available in v0.28.0. I'll be making that release tomorrow once our main build's nightly job succeeds

Awesome. Looking forward to removing a remote_exec performing this manually through ssh.

ddelnano commented 4 months ago

One thing to note is that XO is managing some xenstore data behind the scenes. The terraform provider does not attempt to hide these hidden pieces of config. You will either need to track these key, value pairs in your code or ignore them. The new docs mention this, but just wanted to share that example.

ddelnano commented 4 months ago

v0.28.0 is now available.

ravager-dk commented 4 months ago

Finally had a chance to verify it today. It works like a charm. Good job @ddelnano

ddelnano commented 4 months ago

Thanks for letting me know it suits your needs and is working!