func NewTopology(path string) (*Topology, error) { td, err := descriptions.NewTopologyDescription(path) if err != nil { return nil, err } mcluster, err := machine.NewCluster(td.GetMachineGlobalOptions()) if err != nil { return nil, err } clusterOpts := td.GetClusterOptions() driver := clusterOpts.String("driver") if driver == "" { return nil, fmt.Errorf("container cluster driver option missed.") } m, err := getMasterMachine(clusterOpts, mcluster, td) if err != nil { return nil, err } ccluster, err := cluster.NewCluster(driver, clusterOpts, m) if err != nil { return nil, err } t := &Topology{ machineCluster: mcluster, containerCluster: ccluster, description: td, } ccluster.RegisterEventHandler(TopologyEventsHandler, t) return t, nil }
func getContainerCluster(master *machine.Machine) *cluster.Cluster { m := make(map[string]string) // m["swarm-host"] = ":3376" m["swarm-image"] = "registry.intra.weibo.com/icycrystal4/swarm:latest" m["swam-discover"] = "consul://101.200.173.242:8500/orginal" options := options.Options{ Values: m, } cluster, err := cluster.NewCluster("swarm", &options, master) if err != nil { fmt.Printf("new cluster error:%s\n", err.Error()) os.Exit(0) } return cluster }