Idempotent / conditional vbx.customize ["storagectl"] ??

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Idempotent / conditional vbx.customize ["storagectl"] ??

Malcolm Cowe
Hi,

I want to be able to conditionally add a controller to a VirtualBox VM using the cusotmize feature, as follows:

vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]

This works for first time boot, but errors out when reloading the VM without destroying it first. So far, the only workaround that seems to work is to test for the existence of a storage device that is attached to this controller (or, in fact, any VDI disk created by Vagrant using vbx.customize), so the logic looks something like this:

if not(File.exist?("#{vdisk_root}/disk1.vdi"))
    vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]
end

However, the disk in this case is shared between two VMs, so if I provision the nodes one at a time, the first node will be created correctly, but the second node will not get the additional controller (because the VDI file exists), and the provisioning will fail. If I provision both nodes at once, there's no issue, which is okay as a workaround, but not ideal.

Is there a way to test whether or not the target VM has previously been provisioned or is a new install? I've tried some simple hacks to flag a build, but they don't work because of the "outside-in" flow of logic. I'm really trying to avoid having to write a plugin or some other invasive and high maintenance workaround, since I am new to Vagrant and to Ruby.

I'm really looking for something testable and reasonably portable that would only exist after a VM has been provisioned for the first time.

Any advice gratefully received.

Malcolm.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/79d89249-424f-4fa8-9621-9668a39a17a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Idempotent / conditional vbx.customize ["storagectl"] ??

Alvaro Miranda Aguilera
Hello
You can create a control file for each node, and use that for your work.

pseudo code.

if file doesn't exists
  do the sata thing
  create the file
end


in ruby would be.


unless File.file?("node1.txt")
  vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]
  File.open("node1.txt", "w") {|f| f.write("node1")}
end 

Alvaro.


On Wed, May 10, 2017 at 2:54 AM, Malcolm Cowe <[hidden email]> wrote:
Hi,

I want to be able to conditionally add a controller to a VirtualBox VM using the cusotmize feature, as follows:

vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]

This works for first time boot, but errors out when reloading the VM without destroying it first. So far, the only workaround that seems to work is to test for the existence of a storage device that is attached to this controller (or, in fact, any VDI disk created by Vagrant using vbx.customize), so the logic looks something like this:

if not(File.exist?("#{vdisk_root}/disk1.vdi"))
    vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]
end

However, the disk in this case is shared between two VMs, so if I provision the nodes one at a time, the first node will be created correctly, but the second node will not get the additional controller (because the VDI file exists), and the provisioning will fail. If I provision both nodes at once, there's no issue, which is okay as a workaround, but not ideal.

Is there a way to test whether or not the target VM has previously been provisioned or is a new install? I've tried some simple hacks to flag a build, but they don't work because of the "outside-in" flow of logic. I'm really trying to avoid having to write a plugin or some other invasive and high maintenance workaround, since I am new to Vagrant and to Ruby.

I'm really looking for something testable and reasonably portable that would only exist after a VM has been provisioned for the first time.

Any advice gratefully received.

Malcolm.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/79d89249-424f-4fa8-9621-9668a39a17a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0ey%3DJekRPRKEOJk1CyRi9wYoJwoEE-Zu4-i1x_yjkt9Cnw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Idempotent / conditional vbx.customize ["storagectl"] ??

Malcolm Cowe
Hi,

Thanks for the pointer. I had tried something similar, but using an "if" statement and found that the file was being created before the vbx.customize step was executed... I shall review and try your approach.

Malcolm.

On Wednesday, 10 May 2017 17:38:03 UTC+10, Alvaro Miranda Aguilera wrote:
Hello
You can create a control file for each node, and use that for your work.

pseudo code.

if file doesn't exists
  do the sata thing
  create the file
end


in ruby would be.


unless File.file?("node1.txt")
  vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]
  File.open("node1.txt", "w") {|f| f.write("node1")}
end 

Alvaro.


On Wed, May 10, 2017 at 2:54 AM, Malcolm Cowe <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="I5hapvILCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mal...@...> wrote:
Hi,

I want to be able to conditionally add a controller to a VirtualBox VM using the cusotmize feature, as follows:

vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]

This works for first time boot, but errors out when reloading the VM without destroying it first. So far, the only workaround that seems to work is to test for the existence of a storage device that is attached to this controller (or, in fact, any VDI disk created by Vagrant using vbx.customize), so the logic looks something like this:

if not(File.exist?("#{vdisk_root}/disk1.vdi"))
    vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]
end

However, the disk in this case is shared between two VMs, so if I provision the nodes one at a time, the first node will be created correctly, but the second node will not get the additional controller (because the VDI file exists), and the provisioning will fail. If I provision both nodes at once, there's no issue, which is okay as a workaround, but not ideal.

Is there a way to test whether or not the target VM has previously been provisioned or is a new install? I've tried some simple hacks to flag a build, but they don't work because of the "outside-in" flow of logic. I'm really trying to avoid having to write a plugin or some other invasive and high maintenance workaround, since I am new to Vagrant and to Ruby.

I'm really looking for something testable and reasonably portable that would only exist after a VM has been provisioned for the first time.

Any advice gratefully received.

Malcolm.

--
This mailing list is governed under the HashiCorp Community Guidelines - <a href="https://www.hashicorp.com/community-guidelines.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.hashicorp.com%2Fcommunity-guidelines.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGHa_CaKfZaJiwbkUndUQbVGlQCDw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.hashicorp.com%2Fcommunity-guidelines.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGHa_CaKfZaJiwbkUndUQbVGlQCDw&#39;;return true;">https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: <a href="https://github.com/mitchellh/vagrant/issues" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHxcA5DuHlQlPInMi_k1Pz4pMNqNw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHxcA5DuHlQlPInMi_k1Pz4pMNqNw&#39;;return true;">https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="I5hapvILCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">vagrant-up+...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/vagrant-up/79d89249-424f-4fa8-9621-9668a39a17a2%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/vagrant-up/79d89249-424f-4fa8-9621-9668a39a17a2%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/vagrant-up/79d89249-424f-4fa8-9621-9668a39a17a2%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/vagrant-up/79d89249-424f-4fa8-9621-9668a39a17a2%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.



--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/e8dff84e-72ab-43fc-9403-4763a618ac98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.