Skip to content

Commit

Permalink
consolidate helper functions that were duplicated across PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Oct 5, 2023
1 parent 247addc commit 116d404
Showing 1 changed file with 18 additions and 63 deletions.
81 changes: 18 additions & 63 deletions equinix/helpers_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,26 @@ func getNetworkInfoMetalGo(ips []metalv1.IPAssignment) 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,
"address": ip.GetAddress(),
"gateway": ip.GetGateway(),
"family": ip.GetAddressFamily(),
"cidr": ip.GetCidr(),
"public": ip.GetPublic(),
}
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 = int(*ip.Cidr)
ni.PublicIPv4 = *ip.Address
if ip.GetManagement() {
if ip.GetAddressFamily() == 4 {
if ip.GetPublic() {
ni.Host = ip.GetAddress()
ni.IPv4SubnetSize = int(ip.GetCidr())
ni.PublicIPv4 = ip.GetAddress()
} else {
ni.PrivateIPv4 = *ip.Address
ni.PrivateIPv4 = ip.GetAddress()
}
} else {
ni.PublicIPv6 = *ip.Address
ni.PublicIPv6 = ip.GetAddress()
}
}
}
Expand Down Expand Up @@ -141,36 +141,6 @@ func getNetworkTypeMetalGo(device *metalv1.Device) (*string, error) {
return nil, err
}

func getNetworkInfoMetalGo(ips []metalv1.IPAssignment) NetworkInfo {
ni := NetworkInfo{Networks: make([]map[string]interface{}, 0, 1)}
for _, ip := range ips {
network := map[string]interface{}{
"address": ip.GetAddress(),
"gateway": ip.GetGateway(),
"family": ip.GetAddressFamily(),
"cidr": ip.GetCidr(),
"public": ip.GetPublic(),
}
ni.Networks = append(ni.Networks, network)

// Initial device IPs are fixed and marked as "Management"
if ip.GetManagement() {
if ip.GetAddressFamily() == 4 {
if ip.GetPublic() {
ni.Host = ip.GetAddress()
ni.IPv4SubnetSize = int(ip.GetCidr())
ni.PublicIPv4 = ip.GetAddress()
} else {
ni.PrivateIPv4 = ip.GetAddress()
}
} else {
ni.PublicIPv6 = ip.GetAddress()
}
}
}
return ni
}

func getNetworkRank(family int, public bool) int {
switch {
case family == 4 && public:
Expand All @@ -187,11 +157,11 @@ func getPortsMetalGo(ps []metalv1.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,
"name": p.GetName(),
"id": p.GetId(),
"type": p.GetType(),
"mac": p.Data.GetMac(),
"bonded": p.Data.GetBonded(),
}
ret = append(ret, port)
}
Expand All @@ -213,21 +183,6 @@ func getPorts(ps []packngo.Port) []map[string]interface{} {
return ret
}

func getPortsMetalGo(ps []metalv1.Port) []map[string]interface{} {
ret := make([]map[string]interface{}, 0, 1)
for _, p := range ps {
port := map[string]interface{}{
"name": p.GetName(),
"id": p.GetId(),
"type": p.GetType(),
"mac": p.Data.GetMac(),
"bonded": p.Data.GetBonded(),
}
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"}})
Expand Down

0 comments on commit 116d404

Please sign in to comment.