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

Some refactoring on how provider metadata is handled #102

Merged
merged 8 commits into from
Aug 1, 2023

Conversation

rsjostrand-hpe
Copy link
Contributor

@rsjostrand-hpe rsjostrand-hpe commented Jul 31, 2023

Summary and Scope

Performed some refactoring with how ProviderMetadata is handled.

  • There is a top level structure in the CSM package called Metadata that is composed of the Node and Cabinet structures.
    • Removed CSM hardware structure as it basically became csm.Metadata
  • Renamed ProviderProperties to ProviderMetadata to align naming.
  • Created enums for all supported provider metadata keys.
  • There is always nil or map[string]interface{} in provider metadata. There are no structs ever
    • Added DecodeProviderMetadata and EncodeProviderMetadata to csm package. GetProviderMetadata and GetProviderMetadataT were removed.
    • Calls to mapstructure in the cmd package were replaced with csm.DecodeProviderMetadata.-
  • inventory.Hardware changes
    • Removed top level fields Role/SubRole/Alias from the inventory.Hardware structure, as they are duplicated with the provider metadata.
    • Added SetProviderMetadata method to inventory.Hardware
    • Change type of ProviderProperties/ProviderMetadata to map[Provider]ProviderMetadataRaw to force the type usage for this field.
  • Created pointers package to help with dealing with pointer values.

Heavily relying on the automated testing provided by make test to verify things are ok after the refractor.

Here is what a cabinet looks like in the canidb. Notice how Provider metadata is under a different key, and that the Cabinet properties are namespaced under CSM:

{
  "ID": "fcbf7a07-c0a1-4f0c-a0ba-b126a1d78786",
  "Type": "Cabinet",
  "DeviceTypeSlug": "hpe-ex2000",
  "Vendor": "HPE",
  "Model": "EX2000",
  "Status": "staged",
  "ProviderMetadata": {
    "csm": {
      "Cabinet": {
        "HMNVlan": 3006
      }
    }
  },
  "Parent": "abcdef12-3456-2789-abcd-ef1234567890",
  "Children": [
    "40b53fec-bcb2-4b9c-b18c-3b4db7862bfa",
    "72dbfa6d-9b92-43bd-b2e2-d7eb4f70d1a8",
    "e278bbb6-2cab-4ba4-a91d-3a402c83f924"
  ],
  "LocationPath": [
    {
      "HardwareType": "System",
      "Ordinal": 0
    },
    {
      "HardwareType": "Cabinet",
      "Ordinal": 9006
    }
  ],
  "LocationOrdinal": 9006
}

Risks and Mitigations

@rsjostrand-hpe rsjostrand-hpe marked this pull request as ready for review July 31, 2023 21:57
Copy link
Collaborator

@jacobsalmela jacobsalmela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool. I like how it reduces the Hardware type, too. Nice work!

…refactor

Changed csv import and export to work with the new metadata
@jacobsalmela jacobsalmela merged commit fe61108 into main Aug 1, 2023
4 checks passed
@jacobsalmela jacobsalmela deleted the provider-metadata-refactor branch August 1, 2023 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants