Beispiel #1
0
func NewOpenContrailMapper(g *graph.Graph, r *graph.Node) *OpenContrailMapper {
	host := config.GetConfig().GetString("opencontrail.host")
	port := config.GetConfig().GetInt("opencontrail.port")
	if host == "" {
		host = "localhost"
	}
	if port == 0 {
		port = 8085
	}

	mapper := &OpenContrailMapper{graph: g, root: r, agentHost: host, agentPort: port}
	mapper.nodeUpdaterChan = make(chan graph.Identifier, 500)
	g.AddEventListener(mapper)
	return mapper
}
Beispiel #2
0
func NewNeutronMapper(g *graph.Graph, wsClient *shttp.WSAsyncClient, authURL, username, password, tenantName, regionName, domainName string, availability gophercloud.Availability) (*NeutronMapper, error) {
	mapper := &NeutronMapper{graph: g, wsClient: wsClient}

	opts := gophercloud.AuthOptions{
		IdentityEndpoint: authURL,
		Username:         username,
		Password:         password,
		TenantName:       tenantName,
		DomainName:       domainName,
		AllowReauth:      true,
	}

	provider, err := openstack.AuthenticatedClient(opts)
	if err != nil {
		return nil, err
	}

	client, err := openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
		Name:         "neutron",
		Region:       regionName,
		Availability: availability,
	})
	if err != nil {
		return nil, err
	}
	mapper.client = client

	// Create a cache with a default expiration time of 5 minutes, and which
	// purges expired items every 30 seconds
	expire := config.GetConfig().GetInt("cache.expire")
	cleanup := config.GetConfig().GetInt("cache.cleanup")
	mapper.cache = cache.New(time.Duration(expire)*time.Second, time.Duration(cleanup)*time.Second)
	mapper.nodeUpdaterChan = make(chan graph.Identifier, 500)

	g.AddEventListener(mapper)

	return mapper, nil
}
Beispiel #3
0
func NewFabricProbe(g *graph.Graph) *FabricProbe {
	fb := &FabricProbe{
		Graph: g,
		links: make(map[*graph.Node]fabricLink),
	}

	g.AddEventListener(fb)

	fb.Graph.Lock()
	defer fb.Graph.Unlock()

	list := config.GetConfig().GetStringSlice("agent.topology.fabric")
	for _, link := range list {
		pc := strings.Split(link, "->")
		if len(pc) != 2 {
			logging.GetLogger().Errorf("FabricProbe link definition should have two endpoint: %s", link)
			continue
		}

		parentDef := strings.TrimSpace(pc[0])
		childDef := strings.TrimSpace(pc[1])

		if strings.HasPrefix(parentDef, "local/") {
			logging.GetLogger().Error("FabricProbe doesn't support local node as parent node")
			continue
		}

		if strings.HasPrefix(childDef, "local/") {
			// Fabric Node to Local Node
			childDef = strings.TrimPrefix(childDef, "local/")

			parentNode, err := fb.addFabricNodeFromDef(parentDef)
			if err != nil {
				logging.GetLogger().Error(err.Error())
				continue
			}

			_, childMetadata, err := nodeDefToMetadata(childDef)
			if err != nil {
				logging.GetLogger().Error(err.Error())
				continue
			}

			// queue it as the local doesn't exist at start
			fb.links[parentNode] = fabricLink{metadata: childMetadata}
		} else {
			// Fabric Node to Fabric Node
			node1, err := fb.addFabricNodeFromDef(parentDef)
			if err != nil {
				logging.GetLogger().Error(err.Error())
				continue
			}

			node2, err := fb.addFabricNodeFromDef(childDef)
			if err != nil {
				logging.GetLogger().Error(err.Error())
				continue
			}

			if !fb.Graph.AreLinked(node1, node2) {
				fb.Graph.Link(node1, node2, graph.Metadata{"RelationType": "layer2", "Type": "fabric"})
			}
		}
	}

	return fb
}