josenk / terraform-provider-esxi

Terraform-provider-esxi plugin
GNU General Public License v3.0
543 stars 154 forks source link

[add] pull upload mode on guest creation #171

Closed jremerich closed 1 year ago

jremerich commented 2 years ago

the flag --pullUploadMode enables ESXi host download the image directly without download on terraform machine and send to it after.

This mode improves my provision time in 87%. I execute terraform through a VPN connection.

This flag depends that ESXi version >= 6.7 and OVFTool >= 4.4.1, so I did some version checks to avoid compatibility problems.

hardoverflow commented 2 years ago

Hi everyone. How is the state of the feature and how can we support?

jremerich commented 2 years ago

Hi! I don't think that it needs more implementation, just the merge. I'm wainting for this, too!

josenk commented 2 years ago

Checking this out...

josenk commented 2 years ago

This implementation is failing for me right now. I set ovf_source to an online Ubuntu image (which works without --pullUploadMode) ovf_source = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.ova"

I get the following error from ovftool after a few seconds:

│ Error: There was an ovftool Error: Opening OVA source: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.ova
│ The manifest validates
│ Opening VI target: vi://user@192.168.1.XXX:443//
│ Warning:
│  - Line 128: No space left for device '9' on parent controller '3'.
│  - Line 115: Unable to parse 'enableMPTSupport' for attribute 'key' on element 'Config'.
│ Deploying to VI: vi://root@192.168.1.195:443//
│ Error: Message is: HTTP communication could not be completed with status 404,
│ Fault cause: vim.fault.HttpFault
│
│ Completed with errors
│
│ exit status 1

Also note, I'm using USB to boot. I monitor disk usage on the esxi host and I do not notice any increase in disk space while ovftool is doing it's work...

1) I have no idea if it's a false message, or if esxi is trying to temporarily trying to store the image on the low capacity USB boot device??? 2) Do you have official documentation of this command line argument?

jremerich commented 2 years ago

Unfortunately I couldn't find the official documentation, only this link: https://williamlam.com/2020/10/ovftool-4-4-1-upload-ovf-ova-from-url-using-upcoming-pull-mechanism.html

Your error looks be just low space left on disk. As http responses has Content-Length header, maybe ovftool check it before really starts download process

Without --pullUploadMode the ova file is downloaded to local disk and then processed by ovftool to remote esxi.

josenk commented 2 years ago

I don't think it's a good idea to use undocumented command line arguments.

Also, I suspect that I do not have enough disk space to complete the download to my boot disk... I use a small (but supported) USB drive as the esxi boot disk. The command is most likely storing a temp file there.

Since that command line argument is undocumented and it does not work with all configurations, I don't think it's a good idea to use it as its implemented in this pr.

If you REALLY want or need this option, I will consider an alternative pr. I think this should work pretty easily... Add a new provider option called "esxi_ovftool_options", the default will be an empty string. Then anyone can add this or any special ovftool option they require.

An example provider block would look something like this.

 provider "esxi" {
  esxi_hostname = var.esxi_hostname
  esxi_hostport = var.esxi_hostport
  esxi_hostssl  = var.esxi_hostssl
  esxi_username = var.esxi_username
  esxi_password = var.esxi_password
  esxi_ovftool_options = "--pullUploadMode"
}

New provider options are appended here: https://github.com/josenk/terraform-provider-esxi/blob/master/esxi/provider.go#L51 You may want to look at how esxi_hostssl port was added. (esxi_hostssl)

jremerich commented 2 years ago

your idea sounds good to me.