-
Notifications
You must be signed in to change notification settings - Fork 112
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
Computername fix #334
Computername fix #334
Changes from 18 commits
6585559
e247d25
cf1e7c2
be6790f
6f4c5cb
c73d402
261d142
c431d43
414b3bf
8b03ab8
36c5487
db01eec
331e895
a85d555
d7004b3
6d9cba1
f2360e6
1923d9c
92ad8a5
cada317
ec66094
d828656
de3977f
34fbd10
4b41cf4
cb4dff1
15a3d8f
ffc3573
c2e1914
d63b7bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ func resourceVcdVAppVm() *schema.Resource { | |
Required: true, | ||
ForceNew: true, | ||
}, | ||
"computer_name": &schema.Schema{ | ||
dataclouder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"org": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
|
@@ -88,6 +92,8 @@ func resourceVcdVAppVm() *schema.Resource { | |
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: anyValueWarningValidator(true, | ||
"With next version `name` as computer name won't be set together with `initscript`. Please use `computer_name`."), | ||
dataclouder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"metadata": { | ||
Type: schema.TypeMap, | ||
|
@@ -309,15 +315,32 @@ func resourceVcdVAppVmCreate(d *schema.ResourceData, meta interface{}) error { | |
} | ||
} | ||
|
||
// for back compatibility we allow to set computer name from `name` if computer_name isn't provided | ||
var computerName string | ||
if cName, ok := d.GetOk("computer_name"); ok { | ||
computerName = cName.(string) | ||
} else { | ||
computerName = d.Get("name").(string) | ||
} | ||
|
||
if initScript, ok := d.GetOk("initscript"); ok { | ||
task, err := vm.RunCustomizationScript(d.Get("name").(string), initScript.(string)) | ||
task, err := vm.RunCustomizationScript(computerName, initScript.(string)) | ||
if err != nil { | ||
return fmt.Errorf("error with init script setting: %#v", err) | ||
} | ||
err = task.WaitTaskCompletion() | ||
if err != nil { | ||
return fmt.Errorf(errorCompletingTask, err) | ||
} | ||
} else { | ||
task, err := vm.Customize(computerName, "", false) | ||
if err != nil { | ||
return fmt.Errorf("error with applying computer name: %#v", err) | ||
} | ||
err = task.WaitTaskCompletion() | ||
if err != nil { | ||
return fmt.Errorf(errorCompletingTask, err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is about the whole 318:343 approach. As it is right now, we're mixing the old behaviour with the new one, but I believe we should be prioritising new behaviour and leaving the old logic intact. In other words, we can simplify as follows:
So, if the user defines the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget we need to leave There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With current API, to change computer_name you have to provide initscript - what's why it's implemented as it is now. In general all logic is left - no previous behaviour is removed - it works as it was working. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @lvirbalas is right. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, for this case I added change |
||
} | ||
|
||
if _, ok := d.GetOk("guest_properties"); ok { | ||
|
@@ -554,11 +577,11 @@ func resourceVcdVAppVmUpdateExecute(d *schema.ResourceData, meta interface{}) er | |
} | ||
|
||
if d.HasChange("memory") || d.HasChange("cpus") || d.HasChange("cpu_cores") || d.HasChange("power_on") || d.HasChange("disk") || | ||
d.HasChange("expose_hardware_virtualization") || d.HasChange("network") { | ||
d.HasChange("expose_hardware_virtualization") || d.HasChange("network") || d.HasChange("computer_name") { | ||
|
||
log.Printf("[TRACE] VM %s has changes: memory(%t), cpus(%t), cpu_cores(%t), power_on(%t), disk(%t), expose_hardware_virtualization(%t), network(%t)", | ||
log.Printf("[TRACE] VM %s has changes: memory(%t), cpus(%t), cpu_cores(%t), power_on(%t), disk(%t), expose_hardware_virtualization(%t), network(%t), computer_name(%t)", | ||
vm.VM.Name, d.HasChange("memory"), d.HasChange("cpus"), d.HasChange("cpu_cores"), d.HasChange("power_on"), d.HasChange("disk"), | ||
d.HasChange("expose_hardware_virtualization"), d.HasChange("network")) | ||
d.HasChange("expose_hardware_virtualization"), d.HasChange("network"), d.HasChange("computer_name")) | ||
|
||
// If customization is not requested then a simple shutdown is enough | ||
if vmStatusBeforeUpdate != "POWERED_OFF" && !customizationNeeded { | ||
|
@@ -657,6 +680,18 @@ func resourceVcdVAppVmUpdateExecute(d *schema.ResourceData, meta interface{}) er | |
} | ||
} | ||
|
||
// we pass init script, to not override with empty one | ||
if d.HasChange("computer_name") { | ||
task, err := vm.Customize(d.Get("computer_name").(string), d.Get("initscript").(string), false) | ||
if err != nil { | ||
return fmt.Errorf("error with udpating computer name: %#v", err) | ||
} | ||
err = task.WaitTaskCompletion() | ||
if err != nil { | ||
return fmt.Errorf(errorCompletingTask, err) | ||
} | ||
} | ||
|
||
} | ||
|
||
// If the VM was powered off during update but it has to be powered off | ||
|
@@ -803,7 +838,7 @@ func resourceVcdVAppVmRead(d *schema.ResourceData, meta interface{}) error { | |
return fmt.Errorf("error getting VM : %#v", err) | ||
} | ||
|
||
d.Set("name", vm.VM.Name) | ||
_ = d.Set("name", vm.VM.Name) | ||
|
||
// Read either new or deprecated networks configuration based on which are used | ||
switch { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.