Skip to content

Commit

Permalink
Refresh ip only running vms (#66)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cjlapao authored Nov 21, 2024
1 parent 05594a1 commit 0f7e7f5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions internal/clone_vm/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions internal/remoteimage/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions internal/vagrantbox/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0f7e7f5

Please sign in to comment.