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

Prevent dynamic memory #230

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- This changelog

### Changed
- Memory settings to be static on VM creation

## [0.0.1] - 2023-06-28


[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/0.0.1...HEAD
[0.0.1]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/0.0.1
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@exonet/DevOps
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Terraform Provider for Xen Orchestra

This is a terraform provider for [Xen Orchestra](https://github.com/vatesfr/xen-orchestra).
This is a terraform provider for [Xen Orchestra](https://github.com/vatesfr/xen-orchestra) forked from [terra-farm/terraform-provider-xenorchestra](https://github.com/terra-farm/terraform-provider-xenorchestra).

## Docs

Expand Down
16 changes: 15 additions & 1 deletion client/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ func (c *Client) CreateVm(vmReq Vm, createTime time.Duration) (*Vm, error) {
"cpuWeight": nil,
"CPUs": vmReq.CPUs.Number,
"memoryMax": vmReq.Memory.Static[1],
"memoryMin": vmReq.Memory.Static[1],
"memoryStatic": vmReq.Memory.Static[1],
"existingDisks": existingDisks,
// TODO: (#145) Uncomment this once issues with secure_boot have been figured out
// "secureBoot": vmReq.SecureBoot,
Expand Down Expand Up @@ -323,7 +325,7 @@ func (c *Client) UpdateVm(vmReq Vm) (*Vm, error) {
"auto_poweron": vmReq.AutoPoweron,
"high_availability": vmReq.HA, // valid options are best-effort, restart, ''
"CPUs": vmReq.CPUs.Number,
"memoryMax": vmReq.Memory.Static[1],
"memoryStaticMax": vmReq.Memory.Static[1],
"expNestedHvm": vmReq.ExpNestedHvm,
"startDelay": vmReq.StartDelay,
// TODO: These need more investigation before they are implemented
Expand All @@ -339,6 +341,12 @@ func (c *Client) UpdateVm(vmReq Vm) (*Vm, error) {
// coresPerSocket is null or a number of cores per socket. Putting an invalid value doesn't seem to cause an error :(
}

memorySet := map[string]interface{}{
"id": vmReq.Id,
"memoryMin": vmReq.Memory.Static[1],
"memoryMax": vmReq.Memory.Static[1],
}

videoram := vmReq.Videoram.Value
if videoram != 0 {
params["videoram"] = videoram
Expand Down Expand Up @@ -384,6 +392,12 @@ func (c *Client) UpdateVm(vmReq Vm) (*Vm, error) {
return nil, err
}

// Change the dynamic memory settings after the static has been applied
memoryErr := c.Call("vm.set", memorySet, &success)
if memoryErr != nil {
return nil, memoryErr
}

// TODO: This is a poor way to ensure that terraform will see the updated
// attributes after calling vm.set. Need to investigate a better way to detect this.
time.Sleep(25 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion xoa/resource_xenorchestra_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ func resourceVmUpdate(d *schema.ResourceData, m interface{}) error {
haltForUpdates = true
}

if _, nMemoryMax := d.GetChange("memory_max"); d.HasChange("memory_max") && nMemoryMax.(int) > vm.Memory.Static[1] {
if d.HasChange("memory_max") {
haltForUpdates = true
}

Expand Down