Skip to content
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
82 changes: 53 additions & 29 deletions gen/utils/data/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/CiscoDevNet/terraform-provider-aci/v2/gen/utils"
"github.com/CiscoDevNet/terraform-provider-aci/v2/internal/provider"
)

type Class struct {
Expand All @@ -21,8 +20,9 @@ type Class struct {
ClassDefinition ClassDefinition
// Deprecated resources include a warning the resource and datasource schemas.
Deprecated bool
// The APIC versions in which the class is deprecated.
DeprecatedVersions []VersionRange
// The deprecated APIC versions for the class.
// Used to indicate versions where the class is deprecated but still functional.
DeprecatedVersions *Versions
// Documentation specific information for the class.
Documentation ClassDocumentation
// List of all identifying properties of the class.
Expand Down Expand Up @@ -64,10 +64,8 @@ type Class struct {
// The relative name (RN) format of the class, ex "tn-{name}".
RnFormat string
// The supported APIC versions for the class.
// Each version range is separated by a comma, ex "4.2(7f)-4.2(7w),5.2(1g)-".
// The first version is the minimum version and the second version is the maximum version.
// A dash at the end of a range (ex. 4.2(7f)-) indicates that the class is supported from the first version to the latest version.
Versions []VersionRange
// Parsed from the "versions" field in the meta file (e.g., "1.0(1e)-", "4.2(7f)-4.2(7w),5.2(1g)-").
SupportedVersions *Versions
}

type PlatformTypeEnum int
Expand Down Expand Up @@ -133,18 +131,6 @@ type ClassDocumentation struct {
Warnings []string
}

type VersionRange struct {
// The maximum version of the range.
// This is the second version of the range.
// The version is in the format "4.2(7w)".
// A dash at the end of a range (ex. 4.2(7f)-) indicates that the class is supported from the first version to the latest version.
Max provider.Version
// The minimum version of the range.
// This is the first version of the range.
// The version is in the format "4.2(7f)".
Min provider.Version
}

func NewClass(className string, ds *DataStore) (*Class, error) {
genLogger.Trace(fmt.Sprintf("Creating new class struct with class name: %s.", className))

Expand Down Expand Up @@ -214,8 +200,10 @@ func (c *Class) setClassData(ds *DataStore) error {
// TODO: add placeholder function for Deprecated
c.setDeprecated()

// TODO: add placeholder function for DeprecatedVersions
c.setDeprecatedVersions()
err = c.setDeprecatedVersions()
if err != nil {
return err
}

// TODO: add function to set Documentation
c.setDocumentation()
Expand Down Expand Up @@ -256,8 +244,10 @@ func (c *Class) setClassData(ds *DataStore) error {
// TODO: add function to set RnFormat
c.setRnFormat()

// TODO: add function to set Versions
c.setVersions()
err = c.setSupportedVersions()
if err != nil {
return err
}

genLogger.Debug(fmt.Sprintf("Successfully set class data for class '%s'.", c.Name))
return nil
Expand Down Expand Up @@ -324,10 +314,25 @@ func (c *Class) setDeprecated() {
genLogger.Debug(fmt.Sprintf("Successfully set Deprecated for class '%s'.", c.Name))
}

func (c *Class) setDeprecatedVersions() {
// Determine the APIC versions in which the class is deprecated.
func (c *Class) setDeprecatedVersions() error {
// Determine the deprecated APIC versions for the class from the definition file.
genLogger.Debug(fmt.Sprintf("Setting DeprecatedVersions for class '%s'.", c.Name))
genLogger.Debug(fmt.Sprintf("Successfully set DeprecatedVersions for class '%s'.", c.Name))

// DeprecatedVersions is only set from the definition file (meta file doesn't support this yet).
metaVersions := c.ClassDefinition.DeprecatedVersions
if metaVersions == "" {
genLogger.Debug(fmt.Sprintf("No DeprecatedVersions specified for class '%s'.", c.Name))
return nil
}

versions, err := NewVersions(metaVersions)
if err != nil {
return fmt.Errorf("failed to parse deprecated versions for class '%s': %w", c.Name, err)
}
c.DeprecatedVersions = versions

genLogger.Debug(fmt.Sprintf("Successfully set DeprecatedVersions for class '%s'. Versions: '%s'", c.Name, c.DeprecatedVersions))
return nil
}

func (c *Class) setDocumentation() {
Expand Down Expand Up @@ -511,10 +516,29 @@ func (c *Class) setRnFormat() {
genLogger.Debug(fmt.Sprintf("Successfully set RnFormat for class '%s'.", c.Name))
}

func (c *Class) setVersions() {
func (c *Class) setSupportedVersions() error {
// Determine the supported APIC versions for the class.
genLogger.Debug(fmt.Sprintf("Setting Versions for class '%s'.", c.Name))
genLogger.Debug(fmt.Sprintf("Successfully set Versions for class '%s'.", c.Name))
genLogger.Debug(fmt.Sprintf("Setting SupportedVersions for class '%s'.", c.Name))

// Initialize with versions from ClassDefinition, if not defined set the versions from meta file.
metaVersions := c.ClassDefinition.SupportedVersions
if metaVersions == "" {
metaVersions, _ = c.MetaFileContent["versions"].(string)
}

// When versions are not specified error to force users to add versions.
if metaVersions == "" {
return fmt.Errorf("versions not specified for class '%s': add versions to the class definition file", c.Name)
}

versions, err := NewVersions(metaVersions)
if err != nil {
return fmt.Errorf("failed to parse versions for class '%s': %w", c.Name, err)
}
c.SupportedVersions = versions

genLogger.Debug(fmt.Sprintf("Successfully set SupportedVersions for class '%s'. Versions: '%s'", c.Name, c.SupportedVersions))
return nil
}

func getRelationshipResourceName(ds *DataStore, toClass string) string {
Expand Down
Loading
Loading