Update topology to include tag

Tag can be used to specify the sub-shape for the given node.

Signed-off-by: Akash Srivastava <akash.srivastava@openebs.io>
This commit is contained in:
Akash Srivastava
2018-09-25 18:22:37 +05:30
parent fdd3c4f147
commit ea9ad0a1e6
7 changed files with 44 additions and 0 deletions

View File

@@ -44,6 +44,7 @@ const (
Cylinder = "cylinder"
DottedCylinder = "dottedcylinder"
StorageSheet = "sheet"
Camera = "camera"
// Used when counting the number of containers
ContainersKey = "containers"

View File

@@ -10,6 +10,7 @@ import (
// in the Node struct.
type Topology struct {
Shape string `json:"shape,omitempty"`
Tag string `json:"tag,omitempty"`
Label string `json:"label,omitempty"`
LabelPlural string `json:"label_plural,omitempty"`
Nodes Nodes `json:"nodes"`
@@ -32,6 +33,7 @@ func MakeTopology() Topology {
func (t Topology) WithMetadataTemplates(other MetadataTemplates) Topology {
return Topology{
Shape: t.Shape,
Tag: t.Tag,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
@@ -47,6 +49,7 @@ func (t Topology) WithMetadataTemplates(other MetadataTemplates) Topology {
func (t Topology) WithMetricTemplates(other MetricTemplates) Topology {
return Topology{
Shape: t.Shape,
Tag: t.Tag,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
@@ -62,6 +65,7 @@ func (t Topology) WithMetricTemplates(other MetricTemplates) Topology {
func (t Topology) WithTableTemplates(other TableTemplates) Topology {
return Topology{
Shape: t.Shape,
Tag: t.Tag,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
@@ -76,6 +80,22 @@ func (t Topology) WithTableTemplates(other TableTemplates) Topology {
func (t Topology) WithShape(shape string) Topology {
return Topology{
Shape: shape,
Tag: t.Tag,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
Controls: t.Controls.Copy(),
MetadataTemplates: t.MetadataTemplates.Copy(),
MetricTemplates: t.MetricTemplates.Copy(),
TableTemplates: t.TableTemplates.Copy(),
}
}
// WithTag sets the tag of nodes from this topology, returning a new topology.
func (t Topology) WithTag(tag string) Topology {
return Topology{
Shape: t.Shape,
Tag: tag,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
@@ -90,6 +110,7 @@ func (t Topology) WithShape(shape string) Topology {
func (t Topology) WithLabel(label, labelPlural string) Topology {
return Topology{
Shape: t.Shape,
Tag: t.Tag,
Label: label,
LabelPlural: labelPlural,
Nodes: t.Nodes.Copy(),
@@ -130,6 +151,7 @@ func (t Topology) GetShape() string {
func (t Topology) Copy() Topology {
return Topology{
Shape: t.Shape,
Tag: t.Tag,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
@@ -151,8 +173,13 @@ func (t Topology) Merge(other Topology) Topology {
if label == "" {
label, labelPlural = other.Label, other.LabelPlural
}
tag := t.Tag
if tag == "" {
tag = other.Tag
}
return Topology{
Shape: shape,
Tag: tag,
Label: label,
LabelPlural: labelPlural,
Nodes: t.Nodes.Merge(other.Nodes),
@@ -171,6 +198,9 @@ func (t *Topology) UnsafeMerge(other Topology) {
if t.Label == "" {
t.Label, t.LabelPlural = other.Label, other.LabelPlural
}
if t.Tag == "" {
t.Tag = other.Tag
}
t.Nodes.UnsafeMerge(other.Nodes)
t.Controls = t.Controls.Merge(other.Controls)
t.MetadataTemplates = t.MetadataTemplates.Merge(other.MetadataTemplates)