diff --git a/equinix/data_source_metal_device.go b/equinix/data_source_metal_device.go index 0566f0d2f..22b619d46 100644 --- a/equinix/data_source_metal_device.go +++ b/equinix/data_source_metal_device.go @@ -276,7 +276,7 @@ func dataSourceMetalDeviceRead(ctx context.Context, d *schema.ResourceData, meta if device.HardwareReservation != nil { d.Set("hardware_reservation_id", device.HardwareReservation.GetId()) } - networkType, err := getNetworkTypeMetalGo(device) + networkType, err := getNetworkType(device) if err != nil { return fmt.Errorf("[ERR] Error computing network type for device (%s): %s", d.Id(), err) } @@ -290,7 +290,7 @@ func dataSourceMetalDeviceRead(ctx context.Context, d *schema.ResourceData, meta keyIDs = append(keyIDs, path.Base(k.Href)) } d.Set("ssh_key_ids", keyIDs) - networkInfo := getNetworkInfoMetalGo(device.IpAddresses) + networkInfo := getNetworkInfo(device.IpAddresses) sort.SliceStable(networkInfo.Networks, func(i, j int) bool { famI := networkInfo.Networks[i]["family"].(int32) @@ -305,7 +305,7 @@ func dataSourceMetalDeviceRead(ctx context.Context, d *schema.ResourceData, meta d.Set("access_private_ipv4", networkInfo.PrivateIPv4) d.Set("access_public_ipv6", networkInfo.PublicIPv6) - ports := getPortsMetalGo(device.NetworkPorts) + ports := getPorts(device.NetworkPorts) d.Set("ports", ports) d.SetId(device.GetId()) diff --git a/equinix/helpers_device.go b/equinix/helpers_device.go index fd37d88f7..6d452fbfb 100644 --- a/equinix/helpers_device.go +++ b/equinix/helpers_device.go @@ -69,7 +69,7 @@ type NetworkInfo struct { PrivateIPv4 string } -func getNetworkInfoMetalGo(ips []metalv1.IPAssignment) NetworkInfo { +func getNetworkInfo(ips []metalv1.IPAssignment) NetworkInfo { ni := NetworkInfo{Networks: make([]map[string]interface{}, 0, 1)} for _, ip := range ips { network := map[string]interface{}{ @@ -99,37 +99,7 @@ func getNetworkInfoMetalGo(ips []metalv1.IPAssignment) NetworkInfo { return ni } -func getNetworkInfo(ips []*packngo.IPAddressAssignment) NetworkInfo { - ni := NetworkInfo{Networks: make([]map[string]interface{}, 0, 1)} - for _, ip := range ips { - network := map[string]interface{}{ - "address": ip.Address, - "gateway": ip.Gateway, - "family": ip.AddressFamily, - "cidr": ip.CIDR, - "public": ip.Public, - } - ni.Networks = append(ni.Networks, network) - - // Initial device IPs are fixed and marked as "Management" - if ip.Management { - if ip.AddressFamily == 4 { - if ip.Public { - ni.Host = ip.Address - ni.IPv4SubnetSize = ip.CIDR - ni.PublicIPv4 = ip.Address - } else { - ni.PrivateIPv4 = ip.Address - } - } else { - ni.PublicIPv6 = ip.Address - } - } - } - return ni -} - -func getNetworkTypeMetalGo(device *metalv1.Device) (*string, error) { +func getNetworkType(device *metalv1.Device) (*string, error) { pgDevice := packngo.Device{} res, err := device.MarshalJSON() if err == nil { @@ -153,7 +123,7 @@ func getNetworkRank(family int, public bool) int { return 3 } -func getPortsMetalGo(ps []metalv1.Port) []map[string]interface{} { +func getPorts(ps []metalv1.Port) []map[string]interface{} { ret := make([]map[string]interface{}, 0, 1) for _, p := range ps { port := map[string]interface{}{ @@ -168,21 +138,6 @@ func getPortsMetalGo(ps []metalv1.Port) []map[string]interface{} { return ret } -func getPorts(ps []packngo.Port) []map[string]interface{} { - ret := make([]map[string]interface{}, 0, 1) - for _, p := range ps { - port := map[string]interface{}{ - "name": p.Name, - "id": p.ID, - "type": p.Type, - "mac": p.Data.MAC, - "bonded": p.Data.Bonded, - } - ret = append(ret, port) - } - return ret -} - func hwReservationStateRefreshFunc(client *packngo.Client, reservationId, instanceId string) retry.StateRefreshFunc { return func() (interface{}, string, error) { r, _, err := client.HardwareReservations.Get(reservationId, &packngo.GetOptions{Includes: []string{"device"}}) @@ -284,7 +239,7 @@ func ipAddressSchema() *schema.Resource { } func getDeviceMap(device metalv1.Device) map[string]interface{} { - networkInfo := getNetworkInfoMetalGo(device.IpAddresses) + networkInfo := getNetworkInfo(device.IpAddresses) sort.SliceStable(networkInfo.Networks, func(i, j int) bool { famI := int(*networkInfo.Networks[i]["family"].(*int32)) famJ := int(*networkInfo.Networks[j]["family"].(*int32)) @@ -296,7 +251,7 @@ func getDeviceMap(device metalv1.Device) map[string]interface{} { for _, k := range device.SshKeys { keyIDs = append(keyIDs, path.Base(k.GetHref())) } - ports := getPortsMetalGo(device.NetworkPorts) + ports := getPorts(device.NetworkPorts) return map[string]interface{}{ "hostname": device.GetHostname(), @@ -319,5 +274,6 @@ func getDeviceMap(device metalv1.Device) map[string]interface{} { "network": networkInfo.Networks, "ssh_key_ids": keyIDs, "ports": ports, + "sos_hostname": device.GetSos(), } } diff --git a/equinix/resource_metal_device.go b/equinix/resource_metal_device.go index 17522d7b2..756dadc26 100644 --- a/equinix/resource_metal_device.go +++ b/equinix/resource_metal_device.go @@ -27,7 +27,6 @@ var ( var ( deviceCommonIncludes = []string{"project", "metro", "facility", "hardware_reservation"} - deviceReadOptions = &packngo.GetOptions{Includes: deviceCommonIncludes} ) func resourceMetalDevice() *schema.Resource { @@ -664,7 +663,7 @@ func resourceMetalDeviceRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("deployed_hardware_reservation_id", device.HardwareReservation.GetId()) } - networkType, err := getNetworkTypeMetalGo(device) + networkType, err := getNetworkType(device) if err != nil { return fmt.Errorf("[ERR] Error computing network type for device (%s): %s", d.Id(), err) } @@ -689,7 +688,7 @@ func resourceMetalDeviceRead(ctx context.Context, d *schema.ResourceData, meta i keyIDs = append(keyIDs, path.Base(k.Href)) } d.Set("ssh_key_ids", keyIDs) - networkInfo := getNetworkInfoMetalGo(device.IpAddresses) + networkInfo := getNetworkInfo(device.IpAddresses) sort.SliceStable(networkInfo.Networks, func(i, j int) bool { famI := networkInfo.Networks[i]["family"].(int32) @@ -704,7 +703,7 @@ func resourceMetalDeviceRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("access_private_ipv4", networkInfo.PrivateIPv4) d.Set("access_public_ipv6", networkInfo.PublicIPv6) - ports := getPortsMetalGo(device.NetworkPorts) + ports := getPorts(device.NetworkPorts) d.Set("ports", ports) if networkInfo.Host != "" {