From 8d78a967e369ed3614a6bd5a9b337765686606b1 Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 11 Dec 2024 15:18:04 +0000 Subject: [PATCH] Add esxIpAddress to server We add a new field `esxIpAddress` to the server model. This field is an outlier - it does not fit cleanly into a declarative model. The field is used as part of an `add-hypervisor-server` RPC-style call. It is not part of (and never will be part of) the newly created server's attributes. My understanding is that `esxIpAddress` will typically be set to something like an ephemeral DHCP address that exists only when a server is first racked. Once add-hypervisor-server has completed, the newly created server's IP address will have been changed to the `hypervisor_host.hypervisor_host_ip` value. This value will be returned as `hypervisorHost.hypervisorHostIp` in subsequent http GET requests to the relevant `/servers/` endpoint. The `esxIpAddress` value will be retained as part of the terraform configuration for the server, however once a server has been created this value is no longer of interest. --- examples/main.tf | 1 + internal/resources/server/resource.go | 8 ++++++++ internal/simulator/fixtures/servers/create/post.json | 2 +- test/server/server_test.go | 10 ++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/examples/main.tf b/examples/main.tf index a657a1f..d86bf37 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -42,6 +42,7 @@ resource "hpegl_pc_server" "test" { } server_network = [ { + esx_ip_address = "10.0.0.88" data_ip_infos = [ { ip_address = "16.182.105.217" diff --git a/internal/resources/server/resource.go b/internal/resources/server/resource.go index 051a94c..9d44bfc 100644 --- a/internal/resources/server/resource.go +++ b/internal/resources/server/resource.go @@ -106,6 +106,8 @@ func parseNetworksToPostFormat(dataP *ServerModel) ( NewV1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetwork() net.SetDataIpInfos(dataIps) net.SetIloMgmtIpInfo(iloIPInfos) + esxIPAddress := serverNetwork.EsxIpAddress.ValueString() + net.SetEsxIpAddress(&esxIPAddress) postRequestNetworks = []privatecloudbusiness. V1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetworkable{net} @@ -352,6 +354,12 @@ func doRead( // TODO: (API) Add esxRootCredentialId when FF-31524 is addressed // TODO: (API) Add iloAdminCredentialId when FF-31525 is addressed + + // Note: esxIpAddress is an outlier: it is part of an RPC-style + // call. It only exists for the duration of the add-hypervisor-server + // operation, and is never used again. It does not fit cleanly into + // terraform's declarative model. We will never be able to read this + // value back from the server. } func doCreate( diff --git a/internal/simulator/fixtures/servers/create/post.json b/internal/simulator/fixtures/servers/create/post.json index 75252b9..5c725cf 100644 --- a/internal/simulator/fixtures/servers/create/post.json +++ b/internal/simulator/fixtures/servers/create/post.json @@ -1 +1 @@ - {"esxRootCredentialId":"cccfcad1-85b7-4162-b16e-f7cadc2c46b5","hypervisorClusterId":"acd4daea-e5e3-5f35-8be3-ce4a4b6d946c","iloAdminCredentialId":"dddfcad1-85b7-4162-b16e-f7cadc2c46b5","serverNetwork":[{"dataIpInfos":[{"ipAddress":"16.182.105.217"}],"iloMgmtIpInfo":{"gateway":"16.182.104.1","ipAddress":"16.182.105.216","subnetMask":"255.255.248.0"}}]} + {"esxRootCredentialId":"cccfcad1-85b7-4162-b16e-f7cadc2c46b5","hypervisorClusterId":"acd4daea-e5e3-5f35-8be3-ce4a4b6d946c","iloAdminCredentialId":"dddfcad1-85b7-4162-b16e-f7cadc2c46b5","serverNetwork":[{"esxIpAddress":"10.0.0.88","dataIpInfos":[{"ipAddress":"16.182.105.217"}],"iloMgmtIpInfo":{"gateway":"16.182.104.1","ipAddress":"16.182.105.216","subnetMask":"255.255.248.0"}}]} diff --git a/test/server/server_test.go b/test/server/server_test.go index 63a3b81..502a04e 100644 --- a/test/server/server_test.go +++ b/test/server/server_test.go @@ -90,6 +90,7 @@ func TestAccServerResource(t *testing.T) { } server_network = [ { + esx_ip_address = "10.0.0.88" data_ip_infos = [ { ip_address = "16.182.105.217" @@ -138,6 +139,10 @@ func TestAccServerResource(t *testing.T) { "hpegl_pc_server.test", "hypervisor_host.hypervisor_host_ip", ), + resource.TestCheckResourceAttrSet( + "hpegl_pc_server.test", + "server_network.0.esx_ip_address", + ), checkUUIDAttr("hpegl_pc_server.test", "id"), checkUUIDAttr("hpegl_pc_server.test", "system_id"), checkUUIDAttr("hpegl_pc_server.test", "esx_root_credential_id"), @@ -213,6 +218,11 @@ func TestAccServerResource(t *testing.T) { "hypervisor_host.hypervisor_host_ip", "16.182.105.217", ), + resource.TestCheckResourceAttr( + "hpegl_pc_server.test", + "server_network.0.esx_ip_address", + "10.0.0.88", + ), ) }