New class link to handle links between components and possible errors
This commit is contained in:
@@ -14,17 +14,38 @@ type Link struct {
|
||||
// Use ResourceObject parameter to process certain components type differently
|
||||
// and Id's to identify each component as a node in an oriented graph
|
||||
|
||||
func NewLink(src ResourceObject, srcId string, dst ResourceObject, dstId string) (link Link) {
|
||||
// In the case of DCLink we choose to always consider the DC as the destination
|
||||
// in order to facilitate some logic
|
||||
|
||||
func NewLink(src ResourceObject, srcId string, dst ResourceObject, dstId string) (link Link) {
|
||||
link.Source = srcId
|
||||
link.Destination = dstId
|
||||
|
||||
// If the link is between a DC and a component make sure that the DC is destination
|
||||
// and if the component is computing, update the DataCenterID
|
||||
|
||||
if (src.getRtype() == rtype.DATACENTER || dst.getRtype() == rtype.DATACENTER){
|
||||
var linked ResourceObject
|
||||
|
||||
link.DCLink = true
|
||||
|
||||
if src.getRtype() == rtype.DATACENTER {
|
||||
linked = dst
|
||||
} else {
|
||||
linked = src
|
||||
}
|
||||
|
||||
if( link.DCLink && src.getRtype() == rtype.DATACENTER){
|
||||
link.Destination = srcId
|
||||
link.Source = dstId
|
||||
}
|
||||
|
||||
if (linked.getRtype() == rtype.COMPUTING){
|
||||
linked.(*ComputingObject).DataCenterID = link.Destination
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user