func main() { var t toscalib.ServiceTemplateDefinition err := t.Parse(os.Stdin) if err != nil { log.Fatal(err) } // Creates a new graph g := gographviz.NewGraph() g.AddAttr("", "rankdir", "LR") g.SetName("G") g.SetDir(true) e := toscaexec.GeneratePlaybook(t) for i, p := range e.Index { g.AddNode("G", fmt.Sprintf("%v", i), map[string]string{ "id": fmt.Sprintf("\"%v\"", i), "label": fmt.Sprintf("\"%v|%v\"", p.NodeTemplate.Name, p.OperationName), "shape": "\"record\"", }) } l := e.AdjacencyMatrix.Dim() for r := 0; r < l; r++ { for c := 0; c < l; c++ { if e.AdjacencyMatrix.At(r, c) == 1 { g.AddEdge(fmt.Sprintf("%v", r), fmt.Sprintf("%v", c), true, nil) } } } log.Println("here") s := g.String() fmt.Println(s) /* d, _ := yaml.Marshal(e) fmt.Println(string(d)) */ /* for i, n := range e.Index { log.Printf("[%v] %v:%v -> %v %v", i, n.NodeTemplate.Name, n.OperationName, n.NodeTemplate.Interfaces[n.InterfaceName].Operations[n.OperationName].Implementation, n.NodeTemplate.Interfaces[n.InterfaceName].Operations[n.OperationName].Inputs, ) } */ }
func main() { var t toscalib.ServiceTemplateDefinition var v orchestrator.Graph flag.Parse() if toscaFilename == "" { flag.PrintDefaults() return } if inputFilename == "" { log.Warning("No input file passed as argument, using default values") } inputs, err := getInputs(inputFilename) r, err := os.Open(toscaFilename) if err != nil { log.Fatal(err) } defer r.Close() // Change the CWD to deal correctly with the imports of the TOSCA file os.Chdir(filepath.Dir(toscaFilename)) err = t.Parse(r) if err != nil { log.Fatal(err) } for i, _ := range t.TopologyTemplate.Inputs { if val, ok := inputs[i]; ok { t.TopologyTemplate.Inputs[i] = toscalib.PropertyDefinition{ Value: val.Value, } } } log.Println(t.TopologyTemplate.Inputs) v = togorch(t, []string{"create", "configure", "start"}) for _, n := range v.Nodes { log.WithFields(logrus.Fields{ "Name": n.Name, "Artifact": n.Artifact, "Args": n.Args, "Outputs": n.Outputs, }).Info("") } res, _ := json.MarshalIndent(v, " ", " ") fmt.Printf("%s\n", string(res)) }