-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: use metal-go for device reads (data source and resource) #291
Conversation
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #291 +/- ##
==========================================
- Coverage 60.11% 60.04% -0.08%
==========================================
Files 99 99
Lines 20045 20033 -12
==========================================
- Hits 12051 12028 -23
- Misses 7691 7696 +5
- Partials 303 309 +6
☔ View full report in Codecov by Sentry. |
equinix/data_source_metal_device.go
Outdated
d.Set("state", device.State) | ||
d.Set("billing_cycle", device.BillingCycle) | ||
d.Set("ipxe_script_url", device.IPXEScriptURL) | ||
d.Set("always_pxe", device.AlwaysPXE) | ||
d.Set("ipxe_script_url", device.IpxeScriptUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little changes like these in properties between Packngo and MetalGo make me wonder if we have the 'better' pattern in one project or the other.
If "ID", "PXE", "IP", "BGP", "SSH", "MAC", "CIDR", or "URL" is preferable, the codegen in metal-go could take that route with initialisms support (OpenAPITools/openapi-generator#4833 has an associated stale/open PR). (ID isn't capitalized for the same reason, but perhaps we prefer it that way)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If/when the generator has broad support for defining acronyms/initialisms, it may be worth looking into proper capitalization of those. At the moment, the camel-casing is consistent across metal-go
, metal-java
, and metal-python
, so I'd be hesitant to add a bunch of post-patches in one of those (or, even worse, maintain equivalent post-patches for all of them) to change that.
Casing decisions for model names are driven by the spec, and I think that's where we could use more consistency; here's an example where BGP is capitalized differently because of the spec:
- https://github.com/equinix-labs/metal-go/blob/7e28dc6f080125526593528336c15de56e0e99bf/metal/v1/model_bgp_session.go
- https://github.com/equinix-labs/metal-go/blob/7e28dc6f080125526593528336c15de56e0e99bf/metal/v1/model_bgp_session_input.go
At this point, I'd probably lean towards camel-casing acronyms & initialisms in model names in the spec since that's what the generator would do for property names that contain the same acronyms & initialisms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like initialism may be fixed.
OpenAPITools/openapi-generator#15083
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added equinix-labs/metal-go#112 to investigate the reservedWordsMapping
and see if it supports initialisms without introducing unintended side effects. Given that casing for initialisms is a stylistic issue rather than a functional one, I think it would be ok to adopt metal-go in this project without waiting for the results of that SDK investigation.
It's worth exploring wether we have good access to response headers and a generic method of adding any response Sunset and Deprecation headers to the TF log as warnings. https://developer.hashicorp.com/terraform/tutorials/providers/provider-debug#update-error-messages |
893394f
to
43e0318
Compare
metal-go
for the device and BGP neighbors data sources
metal-go
for the device and BGP neighbors data sources
This PR has been upgraded to |
This adds a metal-go client to the terraform provider. The metal-go client can be gradually adopted by Metal resources and data sources in this provider to enable the eventual deprecation of packngo. An example of using this client to interact with the Metal API can be found in #291.
This adds a metal-go client to the terraform provider. The metal-go client can be gradually adopted by Metal resources and data sources in this provider to enable the eventual deprecation of packngo. An example of using this client to interact with the Metal API can be found in #291.
This should be rebased now that #353 is merged. |
This adds a metal-go client to the terraform provider. The metal-go client can be gradually adopted by Metal resources and data sources in this provider to enable the eventual deprecation of packngo. An example of using this client to interact with the Metal API can be found in #291.
This adds a metal-go client to the terraform provider. The metal-go client can be gradually adopted by Metal resources and data sources in this provider to enable the eventual deprecation of packngo. An example of using this client to interact with the Metal API can be found in equinix#291.
ni.Host = *ip.Address | ||
ni.IPv4SubnetSize = int(*ip.Cidr) | ||
ni.PublicIPv4 = *ip.Address | ||
if ip.GetManagement() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is replacing pointer dereferences with Get...()
calls for better protection against nil pointer errors.
ni.PublicIPv6 = ip.Address | ||
} | ||
func getNetworkType(device *metalv1.Device) (*string, error) { | ||
pgDevice := packngo.Device{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NetworkType
device attribute exposed by packngo
is not an API-provided attribute; this serves as a shim so we can use the packngo
logic to calculate NetworkType
. We could instead either duplicate the complete packngo
logic here or copy it into metal-go
, but my understanding is that NetworkType
is not something we want to keep around anyway, so this shim is designed to get us through the SDK transition and then be eliminated when packngo
is no longer used in the provider.
"type": p.Type, | ||
"mac": p.Data.MAC, | ||
"bonded": p.Data.Bonded, | ||
"name": p.GetName(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with getNetworkInfo
, this change replaces the innards of getPorts
with those of getPortsMetalGo
while also updating the function to use Get...()
helpers, since those helpers more closely match the behavior of the packngo
implementation.
🐛 in E2E:
|
Missed a conversion from pointer derefs to values when collapsing the duplicate helpers; it has been fixed. |
This updates the device data source to use `metal-go` instead of `packngo`. As part of this migration, the device data source gains the new `sos_hostname` attribute which enables customers to reduce their reliance on the deprecated `facility` attribute, which was previously necessary in order to compute the SOS hostname for a device.
This reverts commit a26f1b945d5f089dd9cac7b086e5ca75e579abe2.
func findDeviceByHostname(devices *metalv1.DeviceList, hostname string) (*metalv1.Device, error) { | ||
results := make([]metalv1.Device, 0) | ||
for _, d := range devices.GetDevices() { | ||
if *d.Hostname == hostname { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: presumably this will never be null in a returned devices list, so this should be fine. GetHostname()
is an option.
This updates the device data source to use
metal-go
instead ofpackngo
and also updates the device resource to usemetal-go
for read operations. As part of this migration, the device data source
and resource gain the new
sos_hostname
attribute which enablescustomers to reduce their reliance on the deprecated
facility
attribute,which was previously necessary in order to compute the SOS hostname
for a device.