Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make 'sizes'in MiB, GiB, TiB #203

Open
TheFrisianClause opened this issue Jun 13, 2022 · 3 comments
Open

Make 'sizes'in MiB, GiB, TiB #203

TheFrisianClause opened this issue Jun 13, 2022 · 3 comments

Comments

@TheFrisianClause
Copy link

Currently I am setting up the sizes of my memory and disk(s), and when I used the terraform provider for lets say vSphere. I had to adjust the sizes in either MiB, GiB or TiB. But in Xenorchestra I have to put everything in 'Bytes'. Why is that?

Is there a way to add support for MiB, GiB and TiB?

@4censord
Copy link
Contributor

Currently I am setting up the sizes of my memory and disk(s), and when I
used the terraform provider for lets say vSphere. I had to adjust the
sizes in either MiB, GiB or TiB.

Two possibilitys:

  • The Vsphere provider implements those
  • Vsphere supports them natively

But in Xenorchestra I have to put everything in 'Bytes'. Why is that?

The Xen-orchestra apis expect bytes, so it was the natural choice.

Is there a way to add support for MiB, GiB and TiB?

Neither HCL [0] nor terraform [1] implement support for those directly.

So for supporting different measurements i see three ways:

  • Change all values to expect (Mib/GiB/TiB)
    This is not backwards compatible.
  • additionally provide
    size_gb attributes
    memory_max_gb attributes
  • add (or find) a datasource to convert (Mib/GiB/TiB) to bytes

something like this:

data "convert_size" "10GiB" {
	count = 10
	unit = "GiB"
}
data "convert_size" "8GiB" {
	count = 8
	unit = "GiB"
}

resource "xenorchestra_vm" "vm" {
	memory_max = data.convert_size.8GiB.bytes
	disk {
		size             = data.convert_size.10GiB.bytes
	}
}

@ddelnano
Copy link
Collaborator

ddelnano commented Jul 6, 2022

It seems that Hashicorp sentinel supports something similar to this. Unfortunately that is only an enterprise feature.

I would prefer the data source or similar route because I don't think introducing a backwards incompatible change or additional resource arguments is worth the inconvenience. I also believe that this data source doesn't need to be contained within this provider since it's more generic than that.

Another interim solution would be to define local variables and reference those to do the multiplication for you.

locals {
  kib = 1024
  mib = 1024 * kib
  gib = 1024 * mib
}

resource "xenorchestra_vm" "vm" {
	memory_max = data.convert_size.8GiB.bytes
	disk {
		size  = 10 * local.gib
	}
}

I tried searching terraform's issue tracker to see if it was possible for a provider to export "constants" or something similar to the locals above. I'd like to research if the community is doing anything there as well.

@TheFrisianClause
Copy link
Author

Yeah I understand the points of you guys. But look at it from a persons perspective. I for instance have to continually grab an calculator to see for example how much 1024 MiB is in bytes. While in for instance vSphere or Telmate I can define the amount in MiB (even this would be a huge improvement). It's just time consuming to continually look for how many bytes a certain amount of KiB, MiB, GiB or TiB is, if you know where I am coming from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants