func networkList(client *contrail.Client, flagSet *flag.FlagSet) { var parent_id string if !networkListOpts.allTenants { var err error parent_id, err = config.GetProjectId( client, networkCommonOpts.project, networkCommonOpts.project_id) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } networkList, err := config.NetworkList(client, parent_id, networkListOpts.detail) if err != nil { fmt.Fprint(os.Stderr, err) os.Exit(1) } if networkListOpts.brief || networkListOpts.detail { var tmpl string if networkListOpts.detail { tmpl = networkShowDetail } else { tmpl = networkShowBrief } t := template.Must(template.New("network-list").Parse(tmpl)) for _, n := range networkList { t.Execute(os.Stdout, n) } } else { // terse format (wide line) writer := new(tabwriter.Writer) writer.Init(os.Stdout, 0, 0, 1, ' ', 0) fmt.Fprintln(writer, "Network\tUuid\tSubnets") for _, n := range networkList { fmt.Fprintf(writer, "%s\t%s\t%s\n", n.Name, n.Uuid, strings.Join(n.Subnets, ", ")) } writer.Flush() } }
// List all the policies under a specific project (or all projects if // all-tenants is specified. func policyList(client *contrail.Client, flagSet *flag.FlagSet) { var projectId string if !policyListOpts.allTenants { var err error projectId, err = config.GetProjectId( client, policyCommonOpts.project, policyCommonOpts.projectId) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } if policyListOpts.detail { policyListDetail(client, projectId) } else { policyListTerse(client, projectId) } }
func networkCreate(client *contrail.Client, flagSet *flag.FlagSet) { if flagSet.NArg() < 1 { flagSet.Usage() os.Exit(2) } name := flagSet.Args()[0] parent_id, err := config.GetProjectId( client, networkCommonOpts.project, networkCommonOpts.project_id) if err != nil { fmt.Fprint(os.Stderr, err) os.Exit(1) } if len(networkCreateOpts.subnet) > 0 { config.CreateNetworkWithSubnet(client, parent_id, name, networkCreateOpts.subnet) } else { config.CreateNetwork(client, parent_id, name) } }