Beispiel #1
0
func cmdGetVDC(cmd *cobra.Command, args []string) {
	initConfig(cmd, "goair_vcd", true, map[string]FlagValue{})
	client, err := authenticatevcd(false)
	if err != nil {
		log.Fatalf("failed authenticating: %s", err)
	}

	links, err := govcloudair.GetOrgVdc(client, &client.VCDORGHREF)
	if err != nil {
		log.Fatalf("error Getting OrgVdcs: %s", err)
	}

	yamlOutput, err := yaml.Marshal(&links)
	if err != nil {
		log.Fatalf("error marshaling: %s", err)
	}
	fmt.Println(string(yamlOutput))
}
Beispiel #2
0
func cmdUseVDC(cmd *cobra.Command, args []string) {
	initConfig(cmd, "goair_vcd", true, map[string]FlagValue{
		"vdchref": {vdchref, true, false, ""},
		"vdcname": {vdcname, true, false, "vdchref"},
	})
	client, err := authenticatevcd(false)
	if err != nil {
		log.Fatalf("failed authenticating: %s", err)
	}

	links, err := govcloudair.GetOrgVdc(client, &client.VCDORGHREF)

	useLink := types.Link{}
	for _, link := range links {
		if (viper.GetString("vdchref") != "" && link.HREF == viper.GetString("vdchref")) ||
			(viper.GetString("vdcname") != "" && link.Name == viper.GetString("vdcname")) {
			useLink = link
			break
		}
	}

	if useLink.Name != "" {
		err = clue.EncodeGobFile("goair_compute", clue.UseValue{
			VarMap: map[string]string{
				"vdchref":       useLink.HREF,
				"VCDToken":      client.VCDToken,
				"VCDAuthHeader": client.VCDAuthHeader,
				"orghref":       client.VCDORGHREF.String(),
			},
		})

		yamlOutput, err := yaml.Marshal(&useLink)
		if err != nil {
			log.Fatalf("error marshaling: %s", err)
		}
		fmt.Println(string(yamlOutput))

	} else {
		log.Fatalf("Failed to find VDC %v%v", vdcname, vdchref)
	}
}