Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Pull network info from NETWORK_LIST json in resourceview #30

Merged
merged 4 commits into from
Sep 16, 2019
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ example.tf
terraform.tfplan
terraform.tfstate
terraform.tfvars
build.cmd
bin/
modules-dev/
/pkg/
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ require (
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c // indirect
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20170412085702-cf52904a3cf0
)

67 changes: 40 additions & 27 deletions sdk/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,46 @@ type DeploymentResource struct {

// DeploymentResourceData - view of the resources/machines in a deployment
type DeploymentResourceData struct {
Memory int `json:"MachineMemory,omitempty"`
CPU int `json:"MachineCPU,omitempty"`
IPAddress string `json:"ip_address,omitempty"`
Storage int `json:"MachineStorage,omitempty"`
MachineInterfaceType string `json:"MachineInterfaceType,omitempty"`
MachineName string `json:"MachineName,omitempty"`
MachineGuestOperatingSystem string `json:"MachineGuestOperatingSystem,omitempty"`
MachineDestructionDate string `json:"MachineDestructionDate,omitempty"`
MachineGroupName string `json:"MachineGroupName,omitempty"`
MachineBlueprintName string `json:"MachineBlueprintName,omitempty"`
MachineReservationName string `json:"MachineReservationName,omitempty"`
MachineType string `json:"MachineType,omitempty"`
MachineID string `json:"machineId,omitempty"`
MachineExpirationDate string `json:"MachineExpirationDate,omitempty"`
Component string `json:"Component,omitempty"`
Expire bool `json:"Expire,omitempty"`
Reconfigure bool `json:"Reconfigure,omitempty"`
Reset bool `json:"Reset,omitempty"`
Reboot bool `json:"Reboot,omitempty"`
PowerOff bool `json:"PowerOff,omitempty"`
Destroy bool `json:"Destroy,omitempty"`
Shutdown bool `json:"Shutdown,omitempty"`
Suspend bool `json:"Suspend,omitempty"`
Reprovision bool `json:"Reprovision,omitempty"`
ChangeLease bool `json:"ChangeLease,omitempty"`
ChangeOwner bool `json:"ChangeOwner,omitempty"`
CreateSnapshot bool `json:"CreateSnapshot,omitempty"`
Memory int `json:"MachineMemory,omitempty"`
CPU int `json:"MachineCPU,omitempty"`
IPAddress string `json:"ip_address,omitempty"`
Storage int `json:"MachineStorage,omitempty"`
MachineInterfaceType string `json:"MachineInterfaceType,omitempty"`
MachineName string `json:"MachineName,omitempty"`
MachineGuestOperatingSystem string `json:"MachineGuestOperatingSystem,omitempty"`
MachineDestructionDate string `json:"MachineDestructionDate,omitempty"`
MachineGroupName string `json:"MachineGroupName,omitempty"`
MachineBlueprintName string `json:"MachineBlueprintName,omitempty"`
MachineReservationName string `json:"MachineReservationName,omitempty"`
MachineType string `json:"MachineType,omitempty"`
MachineID string `json:"machineId,omitempty"`
MachineExpirationDate string `json:"MachineExpirationDate,omitempty"`
Component string `json:"Component,omitempty"`
Expire bool `json:"Expire,omitempty"`
Reconfigure bool `json:"Reconfigure,omitempty"`
Reset bool `json:"Reset,omitempty"`
Reboot bool `json:"Reboot,omitempty"`
PowerOff bool `json:"PowerOff,omitempty"`
Destroy bool `json:"Destroy,omitempty"`
Shutdown bool `json:"Shutdown,omitempty"`
Suspend bool `json:"Suspend,omitempty"`
Reprovision bool `json:"Reprovision,omitempty"`
ChangeLease bool `json:"ChangeLease,omitempty"`
ChangeOwner bool `json:"ChangeOwner,omitempty"`
CreateSnapshot bool `json:"CreateSnapshot,omitempty"`
Networks []NWDetails `json:"NETWORK_LIST,omitempty"`
}

//Networks Related structs
//
type NWDetails struct {
ComponentTypeId string `json:"componentTypeId,omitempty"`
NetworkAddressInfo NetworkInfo `json:"data,omitempty"`
}
type NetworkInfo struct {
IPAddress string `json:"NETWORK_ADDRESS,omitempty"`
MACAddress string `json:"NETWORK_MAC_ADDRESS,omitempty"`
Name string `json:"NETWORK_NAME,omitempty"`
}

// ResourceActions - Retrieves the resources that were provisioned as a result of a given request.
Expand Down
3 changes: 2 additions & 1 deletion sdk/vra7_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
MachineDestructionDate = "destruction_date"
MachineReconfigure = "reconfigure"
MachinePowerOff = "power_off"
Networks = "NETWORK_LIST"
ComponentTypeId = "componentTypeId"

InProgress = "IN_PROGRESS"
Successful = "SUCCESSFUL"
Expand Down Expand Up @@ -196,7 +198,6 @@ func (c *APIClient) GetRequestResourceView(catalogRequestID string) (*RequestRes
if respErr != nil {
return nil, respErr
}

var response RequestResourceView
unmarshallErr := utils.UnmarshalJSON(resp.Body, &response)
if unmarshallErr != nil {
Expand Down
11 changes: 10 additions & 1 deletion vra7/resource_vra7_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -366,10 +367,18 @@ func resourceVra7DeploymentRead(d *schema.ResourceData, meta interface{}) error
dataVals[sdk.MachineID] = resourceData.MachineID
dataVals[sdk.MachineGroupName] = resourceData.MachineGroupName
dataVals[sdk.MachineDestructionDate] = resourceData.MachineDestructionDate
// Handle Network Info
for idx, netDetails := range resourceData.Networks {
log.Info("The Network list value is for idx %i = %+v", idx, netDetails)
networkIndexName := "Network" + strconv.Itoa(idx)
dataVals[networkIndexName+".IPAddress"] = netDetails.NetworkAddressInfo.IPAddress
dataVals[networkIndexName+".MACAddress"] = netDetails.NetworkAddressInfo.MACAddress
dataVals[networkIndexName+".Name"] = netDetails.NetworkAddressInfo.Name
}

}
}
resourceConfiguration, _ := d.Get("resource_configuration").(map[string]interface{})

resourceConfiguration, changed := utils.UpdateResourceConfigurationMap(resourceConfiguration, resourceDataMap)

if changed {
Expand Down