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

add hypervisor server: ilo networking #74

Closed
wants to merge 1 commit 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
5 changes: 5 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ resource "hpegl_pc_server" "test" {
hypervisor_cluster_id = "acd4daea-e5e3-5f35-8be3-ce4a4b6d946c"
hypervisor_host_ip = "16.182.105.217"
}
ilo_network_info = {
ilo_ip = "16.182.105.216"
gateway = "16.182.104.1"
subnet_mask = "255.255.248.0"
}
server_network = [
{
data_ip_infos = [
Expand Down
111 changes: 63 additions & 48 deletions internal/resources/server/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
tfpath "github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

Expand All @@ -38,52 +37,78 @@ type Resource struct {
// input configuration and returns a slice of server network data which can be
// used in a POST request to the PCBe API to create a new server
// TODO: (API) Issue FF-31496 will prevent this from working currently.
func parseNetworksToPostFormat(serverNetworks basetypes.ListValue) (
func parseNetworksToPostFormat(dataP *ServerModel) (
[]privatecloudbusiness.
V1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetworkable,
error,
) {
var postRequestNetworks []privatecloudbusiness.
V1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetworkable

serverNetworks := (*dataP).ServerNetwork
if serverNetworks.IsNull() {
msg := "server network list is null"

return nil, errors.New(msg)

}

networks := serverNetworks.Elements()
for _, network := range networks {
serverNetwork, ok := network.(ServerNetworkValue)
if !ok {
msg := "server network element is not a ServerNetworkValue"

return nil, errors.New(msg)
}

infos := serverNetwork.DataIpInfos.Elements()
if len(infos) != 1 {
msg := "server network must be an array of length 1"

return nil, errors.New(msg)
}

dataIPInfosValue, ok := infos[0].(DataIpInfosValue)
if !ok {
msg := "data ip info element is not a DataIpInfosValue"

return nil, errors.New(msg)
}

ip := dataIPInfosValue.IpAddress.ValueString()
net := privatecloudbusiness.
NewV1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetwork()
dataIPInfos := privatecloudbusiness.
NewV1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetwork_dataIpInfos()
dataIPInfos.SetIpAddress(&ip)
dataIps := []privatecloudbusiness.
V1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetwork_dataIpInfosable{
dataIPInfos,
}
net.SetDataIpInfos(dataIps)
postRequestNetworks = []privatecloudbusiness.
V1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetworkable{net}
if len(networks) != 1 {
msg := "server network list should be of length 1"

return nil, errors.New(msg)
}

serverNetwork, ok := networks[0].(ServerNetworkValue)
if !ok {
msg := "server network element is not a ServerNetworkValue"

return nil, errors.New(msg)
}

infos := serverNetwork.DataIpInfos.Elements()
if len(infos) != 1 {
msg := "server network must be an array of length 1"

return nil, errors.New(msg)
}

dataIPInfosValue, ok := infos[0].(DataIpInfosValue)
if !ok {
msg := "data ip info element is not a DataIpInfosValue"

return nil, errors.New(msg)
}

ip := dataIPInfosValue.IpAddress.ValueString()
dataIPInfos := privatecloudbusiness.
NewV1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetwork_dataIpInfos()
dataIPInfos.SetIpAddress(&ip)
dataIps := []privatecloudbusiness.
V1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetwork_dataIpInfosable{
dataIPInfos,
}

iloIPInfos := privatecloudbusiness.NewV1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetwork_iloMgmtIpInfo()

iloIP := (*dataP).IloNetworkInfo.IloIp.ValueString()
iloIPInfos.SetIpAddress(&iloIP)

iloSubnetMask := (*dataP).IloNetworkInfo.SubnetMask.ValueString()
iloIPInfos.SetSubnetMask(&iloSubnetMask)

iloGateway := (*dataP).IloNetworkInfo.Gateway.ValueString()
iloIPInfos.SetGateway(&iloGateway)

net := privatecloudbusiness.
NewV1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetwork()
net.SetDataIpInfos(dataIps)
net.SetIloMgmtIpInfo(iloIPInfos)

postRequestNetworks = []privatecloudbusiness.
V1beta1SystemsItemAddHypervisorServersPostRequestBody_serverNetworkable{net}

return postRequestNetworks, nil
}

Expand Down Expand Up @@ -338,16 +363,6 @@ func doCreate(
esxRootCredentialID := (*dataP).EsxRootCredentialId.ValueString()
systemID := (*dataP).SystemId.ValueString()
iloAdminCredentialID := (*dataP).IloAdminCredentialId.ValueString()
serverNetworks := (*dataP).ServerNetwork
if serverNetworks.IsNull() {
(*diagsP).AddError(
"error adding hypervisor server",
"server network list is null",
)

return

}
prc := privatecloudbusiness.
V1beta1SystemsItemAddHypervisorServersRequestBuilderPostRequestConfiguration{}
prb := privatecloudbusiness.
Expand All @@ -356,7 +371,7 @@ func doCreate(
prb.SetIloAdminCredentialId(&iloAdminCredentialID)
prb.SetHypervisorClusterId(&hciClusterUUID)

postRequestNetworks, err := parseNetworksToPostFormat(serverNetworks)
postRequestNetworks, err := parseNetworksToPostFormat(dataP)
if err != nil {
(*diagsP).AddError(
"error adding hypervisor server",
Expand Down
Loading
Loading