Skip to content
Merged
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
108 changes: 88 additions & 20 deletions api/cib.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,57 +422,125 @@ func enrichPrimitiveMetadataWithCibValues(metadata *CrmResourceMetadata, resourc
}

for _, nv := range primitive.InstanceAttributes.NVPairs {
// search the parameter in InstanceAttributes
found := false
// First, search the parameter in the schema of InstanceAttributes
for i := range metadata.Parameters {
if nv.Name == metadata.Parameters[i].Name {
found = true
metadata.Parameters[i].Content.CibID = nv.ID
metadata.Parameters[i].Content.CibValue = nv.Value
break
}
}
if found == false {
// if not found --> extend the schema with the user parameter
unknownCustomInstanceAttribute := MetaParameter{
Name: nv.Name,
Content: ContentAttr{
CibID: nv.ID,
CibValue: nv.Value,
},
}
metadata.Parameters = append(metadata.Parameters, unknownCustomInstanceAttribute)
}
}

for _, nv := range primitive.MetaAttributes.NVPairs {
// search the parameter in MetaAttributes
found := false
// First, search the parameter in the schema of MetaAttributes
for i := range metadata.RscDefaults {
if nv.Name == metadata.RscDefaults[i].Name {
found = true
metadata.RscDefaults[i].Content.CibID = nv.ID
metadata.RscDefaults[i].Content.CibValue = nv.Value
break
}
}
if found == false {
// if not found --> extend the schema with the user parameter
unknownCustomMetaParameter := MetaParameter{
Name: nv.Name,
Content: ContentAttr{
CibID: nv.ID,
CibValue: nv.Value,
},
}
metadata.RscDefaults = append(metadata.RscDefaults, unknownCustomMetaParameter)
}
}

for _, op := range primitive.Operations {
// search action in Operations
found := false
// First, search the action in the schema of Operations
for i := range metadata.Actions {
if op.Name != metadata.Actions[i].Name {
continue
if op.Name == metadata.Actions[i].Name {
found = true
metadata.Actions[i].CibID = op.ID
for j := range metadata.Actions[i].OpDefaults {
switch metadata.Actions[i].OpDefaults[j].Name {
case "depth":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Depth
case "description":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Description
case "enabled":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Enabled
case "interval":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Interval
case "interval-origin":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.IntervalOrigin
case "on-fail":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.OnFail
case "record-pending":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.RecordPending
case "requires":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Requires
case "role":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Role
case "start-delay":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.StartDelay
case "timeout":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Timeout
}
}
break
}
metadata.Actions[i].CibID = op.ID
for j := range metadata.Actions[i].OpDefaults {
switch metadata.Actions[i].OpDefaults[j].Name {
}
if found == false {
/* it's a bad practice to have unsupported custom operation
* but the user knows it better. If it exists we preserve it
* i.e. if not found --> extend the schema with the user action */
unknownCustomAction := Action{
Name: op.Name,
CibID: op.ID,
OpDefaults: GetOpDefaults(),
}
for j := range unknownCustomAction.OpDefaults {
switch unknownCustomAction.OpDefaults[j].Name {
case "depth":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Depth
unknownCustomAction.OpDefaults[j].Content.CibValue = op.Depth
case "description":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Description
unknownCustomAction.OpDefaults[j].Content.CibValue = op.Description
case "enabled":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Enabled
unknownCustomAction.OpDefaults[j].Content.CibValue = op.Enabled
case "interval":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Interval
unknownCustomAction.OpDefaults[j].Content.CibValue = op.Interval
case "interval-origin":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.IntervalOrigin
unknownCustomAction.OpDefaults[j].Content.CibValue = op.IntervalOrigin
case "on-fail":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.OnFail
unknownCustomAction.OpDefaults[j].Content.CibValue = op.OnFail
case "record-pending":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.RecordPending
unknownCustomAction.OpDefaults[j].Content.CibValue = op.RecordPending
case "requires":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Requires
unknownCustomAction.OpDefaults[j].Content.CibValue = op.Requires
case "role":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Role
unknownCustomAction.OpDefaults[j].Content.CibValue = op.Role
case "start-delay":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.StartDelay
unknownCustomAction.OpDefaults[j].Content.CibValue = op.StartDelay
case "timeout":
metadata.Actions[i].OpDefaults[j].Content.CibValue = op.Timeout

unknownCustomAction.OpDefaults[j].Content.CibValue = op.Timeout
}
}
metadata.Actions = append(metadata.Actions, unknownCustomAction)
}
}

Expand Down
Loading