From 0f7e7f5e159a04de5cb7bc5949a20141bf92989b Mon Sep 17 00:00:00 2001 From: Carlos Lapao Date: Thu, 21 Nov 2024 10:18:31 +0000 Subject: [PATCH] Refresh ip only running vms (#66) * Add always run scripts - Added the ability to set a post_processor_script to always run on update - Fixed some issues where in some cases the update would but the vm in the wrong state - Fixed an issue where some errors would bring a nil pointer - Added an option to wait for network before querying to the datasource vm - Added a retry mechanism to attempt to get the internal ip on create/update * fix the documentation * Refresh ip only when vms are running - Added a fix to only check for ip changes when VMs are running --- CHANGELOG.md | 2 +- internal/clone_vm/resource.go | 14 ++++++++++++++ internal/remoteimage/resource.go | 14 ++++++++++++++ internal/vagrantbox/resource.go | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeeb1cf..77e843e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,4 +15,4 @@ FEATURES: - Fixed some bugs - Added the ability to register a deployment with a orchestrator - Added the ability to run prlctl commands -- Added the ability to run a script on destroy +- Added the ability to run a script on destroy it diff --git a/internal/clone_vm/resource.go b/internal/clone_vm/resource.go index c28db52..a93fcd3 100644 --- a/internal/clone_vm/resource.go +++ b/internal/clone_vm/resource.go @@ -340,6 +340,13 @@ func (r *CloneVmResource) Create(ctx context.Context, req resource.CreateRequest externalIp = refreshVm.HostExternalIpAddress internalIp = refreshVm.InternalIpAddress } + + if refreshVm.State != "running" { + externalIp = refreshVm.HostExternalIpAddress + internalIp = "-" + break + } + if internalIp != "" { time.Sleep(5 * time.Second) break @@ -687,6 +694,13 @@ func (r *CloneVmResource) Update(ctx context.Context, req resource.UpdateRequest externalIp = refreshVm.HostExternalIpAddress internalIp = refreshVm.InternalIpAddress } + + if refreshVm.State != "running" { + externalIp = refreshVm.HostExternalIpAddress + internalIp = "-" + break + } + if internalIp != "" { time.Sleep(5 * time.Second) break diff --git a/internal/remoteimage/resource.go b/internal/remoteimage/resource.go index 9b1e912..5629ab0 100644 --- a/internal/remoteimage/resource.go +++ b/internal/remoteimage/resource.go @@ -378,6 +378,13 @@ func (r *RemoteVmResource) Create(ctx context.Context, req resource.CreateReques externalIp = refreshVm.HostExternalIpAddress internalIp = refreshVm.InternalIpAddress } + + if refreshVm.State != "running" { + externalIp = refreshVm.HostExternalIpAddress + internalIp = "-" + break + } + if internalIp != "" { time.Sleep(5 * time.Second) break @@ -755,6 +762,13 @@ func (r *RemoteVmResource) Update(ctx context.Context, req resource.UpdateReques externalIp = refreshVm.HostExternalIpAddress internalIp = refreshVm.InternalIpAddress } + + if refreshVm.State != "running" { + externalIp = refreshVm.HostExternalIpAddress + internalIp = "-" + break + } + if internalIp != "" { time.Sleep(5 * time.Second) break diff --git a/internal/vagrantbox/resource.go b/internal/vagrantbox/resource.go index c3be0e5..135aa5b 100644 --- a/internal/vagrantbox/resource.go +++ b/internal/vagrantbox/resource.go @@ -322,6 +322,13 @@ func (r *VagrantBoxResource) Create(ctx context.Context, req resource.CreateRequ externalIp = refreshVm.HostExternalIpAddress internalIp = refreshVm.InternalIpAddress } + + if refreshVm.State != "running" { + externalIp = refreshVm.HostExternalIpAddress + internalIp = "-" + break + } + if internalIp != "" { time.Sleep(5 * time.Second) break @@ -667,6 +674,13 @@ func (r *VagrantBoxResource) Update(ctx context.Context, req resource.UpdateRequ externalIp = refreshVm.HostExternalIpAddress internalIp = refreshVm.InternalIpAddress } + + if refreshVm.State != "running" { + externalIp = refreshVm.HostExternalIpAddress + internalIp = "-" + break + } + if internalIp != "" { time.Sleep(5 * time.Second) break