예제 #1
0
func printHostList(hostList []photon.Host, w io.Writer, c *cli.Context) error {
	if c.GlobalIsSet("non-interactive") {
		for _, host := range hostList {
			tag := strings.Trim(fmt.Sprint(host.Tags), "[]")
			scriptTag := strings.Replace(tag, " ", ",", -1)
			fmt.Printf("%s\t%s\t%s\t%s\n", host.ID, host.State, host.Address, scriptTag)
		}
	} else if c.GlobalString("output") != "" {
		utils.FormatObjects(hostList, w, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "ID\tState\tIP\tTags\n")
		for _, host := range hostList {
			fmt.Fprintf(w, "%s\t%v\t%s\t%s\n", host.ID, host.State, host.Address, strings.Trim(fmt.Sprint(host.Tags), "[]"))
		}
		err := w.Flush()
		if err != nil {
			return err
		}
		fmt.Printf("\nTotal: %d\n", len(hostList))
	}

	return nil
}
예제 #2
0
func printClusterList(clusterList []photon.Cluster, w io.Writer, c *cli.Context, summaryView bool) error {
	stateCount := make(map[string]int)
	for _, cluster := range clusterList {
		stateCount[cluster.State]++
	}

	if c.GlobalIsSet("non-interactive") {
		if !summaryView {
			for _, cluster := range clusterList {
				fmt.Printf("%s\t%s\t%s\t%s\t%d\n", cluster.ID, cluster.Name, cluster.Type, cluster.State, cluster.WorkerCount)
			}
		}
	} else if c.GlobalString("output") != "" {
		utils.FormatObjects(clusterList, w, c)
	} else {
		if !summaryView {
			w := new(tabwriter.Writer)
			w.Init(os.Stdout, 4, 4, 2, ' ', 0)
			fmt.Fprintf(w, "ID\tName\tType\tState\tWorker Count\n")
			for _, cluster := range clusterList {
				fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", cluster.ID, cluster.Name, cluster.Type, cluster.State, cluster.WorkerCount)
			}
			err := w.Flush()
			if err != nil {
				return err
			}
		}
		fmt.Printf("\nTotal: %d\n", len(clusterList))
		for key, value := range stateCount {
			fmt.Printf("%s: %d\n", key, value)
		}
	}

	return nil
}
예제 #3
0
// Prints out the output of tasks
func printTaskList(taskList []photon.Task, c *cli.Context) error {
	if c.GlobalIsSet("non-interactive") {
		for _, task := range taskList {
			fmt.Printf("%s\t%s\t%s\t%d\t%d\n", task.ID, task.State, task.Operation, task.StartedTime, task.EndTime-task.StartedTime)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(taskList, os.Stdout, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "\nTask\tStart Time\tDuration\n")

		for _, task := range taskList {
			var duration int64
			startTime := timestampToString(task.StartedTime)
			if task.EndTime-task.StartedTime > 0 {
				duration = (task.EndTime - task.StartedTime) / 1000
			} else {
				duration = 0
			}
			fmt.Fprintf(w, "%s\t%s\t%.2d:%.2d:%.2d\n", task.ID, startTime, duration/3600, (duration/60)%60, duration%60)
			err := w.Flush()
			if err != nil {
				return err
			}
			fmt.Printf("%s, %s\n", task.Operation, task.State)
		}
		if len(taskList) > 0 {
			fmt.Printf("\nYou can run 'photon task show <id>' for more information\n")
		}
		fmt.Printf("Total: %d\n", len(taskList))
	}

	return nil
}
예제 #4
0
// Retrieves a list of projects, returns an error if one occurred
func listProjects(c *cli.Context, w io.Writer) error {
	err := checkArgNum(c.Args(), 0, "project list [<options>]")
	if err != nil {
		return err
	}
	tenantName := c.String("tenant")

	client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
	if err != nil {
		return err
	}

	tenant, err := verifyTenant(tenantName)
	if err != nil {
		return err
	}

	projects, err := client.Esxclient.Tenants.GetProjects(tenant.ID, nil)
	if err != nil {
		return err
	}

	if c.GlobalIsSet("non-interactive") {
		for _, t := range projects.Items {
			limits := quotaLineItemListToString(t.ResourceTicket.Limits)
			usage := quotaLineItemListToString(t.ResourceTicket.Usage)
			fmt.Printf("%s\t%s\t%s\t%s\n", t.ID, t.Name, limits, usage)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(projects.Items, w, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "ID\tName\tLimit\tUsage\n")
		for _, t := range projects.Items {
			rt := t.ResourceTicket
			for i := 0; i < len(rt.Limits); i++ {
				if i == 0 {
					fmt.Fprintf(w, "%s\t%s\t%s %g %s\t%s %g %s\n", t.ID, t.Name,
						rt.Limits[i].Key, rt.Limits[i].Value, rt.Limits[i].Unit,
						rt.Usage[i].Key, rt.Usage[i].Value, rt.Usage[i].Unit)
				} else {
					fmt.Fprintf(w, "\t\t%s %g %s\t%s %g %s\n",
						rt.Limits[i].Key, rt.Limits[i].Value, rt.Limits[i].Unit,
						rt.Usage[i].Key, rt.Usage[i].Value, rt.Usage[i].Unit)
				}
			}
			for i := len(rt.Limits); i < len(rt.Usage); i++ {
				fmt.Fprintf(w, "\t\t\t%s %g %s\n", rt.Usage[i].Key, rt.Usage[i].Value, rt.Usage[i].Unit)
			}
		}
		err := w.Flush()
		if err != nil {
			return err
		}
		fmt.Printf("\nTotal projects: %d\n", len(projects.Items))
	}
	return nil
}
예제 #5
0
// Retrieves a list of flavors
func listFlavors(c *cli.Context, w io.Writer) error {
	err := checkArgNum(c.Args(), 0, "flavor list [<options>]")
	if err != nil {
		return err
	}
	client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
	if err != nil {
		return err
	}

	name := c.String("name")
	kind := c.String("kind")
	options := &photon.FlavorGetOptions{
		Name: name,
		Kind: kind,
	}

	flavors, err := client.Esxclient.Flavors.GetAll(options)
	if err != nil {
		return err
	}

	if c.GlobalIsSet("non-interactive") {
		for _, flavor := range flavors.Items {
			costs := quotaLineItemListToString(flavor.Cost)
			fmt.Printf("%s\t%s\t%s\t%s\n", flavor.ID, flavor.Name, flavor.Kind, costs)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(flavors.Items, w, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "ID\tName\tKind\tCost\n")
		for _, flavor := range flavors.Items {
			printQuotaList(w, flavor.Cost, flavor.ID, flavor.Name, flavor.Kind)
		}
		err = w.Flush()
		if err != nil {
			return err
		}
		fmt.Printf("Total: %d\n", len(flavors.Items))
	}

	return nil
}
// Retrieves a list of resource tickets, returns an error if one occurred
func listResourceTickets(c *cli.Context, w io.Writer) error {
	err := checkArgNum(c.Args(), 0, "resource-ticket list [<options>]")
	if err != nil {
		return err
	}
	tenantName := c.String("tenant")

	client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
	if err != nil {
		return err
	}

	tenant, err := verifyTenant(tenantName)
	if err != nil {
		return err
	}

	tickets, err := client.Esxclient.Tenants.GetResourceTickets(tenant.ID, nil)
	if err != nil {
		return err
	}

	if c.GlobalIsSet("non-interactive") {
		for _, t := range tickets.Items {
			limits := quotaLineItemListToString(t.Limits)
			fmt.Printf("%s\t%s\t%s\n", t.ID, t.Name, limits)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(tickets.Items, w, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "ID\tName\tLimit\n")
		for _, t := range tickets.Items {
			printQuotaList(w, t.Limits, t.ID, t.Name)
		}
		err := w.Flush()
		if err != nil {
			return err
		}
		fmt.Printf("\nTotal resource tickets: %d\n", len(tickets.Items))
	}
	return nil
}
예제 #7
0
func listNetworks(c *cli.Context, w io.Writer) error {
	err := checkArgNum(c.Args(), 0, "network list [<options>]")
	if err != nil {
		return err
	}
	client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
	if err != nil {
		return err
	}

	name := c.String("name")
	options := &photon.SubnetGetOptions{
		Name: name,
	}

	networks, err := client.Esxclient.Subnets.GetAll(options)
	if err != nil {
		return err
	}

	if c.GlobalIsSet("non-interactive") {
		for _, network := range networks.Items {
			fmt.Printf("%s\t%s\t%s\t%s\t%s\n", network.ID, network.Name, network.State, network.PortGroups, network.Description)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(networks.Items, w, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "ID\tName\tState\tPortGroups\tDescriptions\tIsDefault\n")
		for _, network := range networks.Items {
			fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%t\n", network.ID, network.Name, network.State, network.PortGroups,
				network.Description, network.IsDefault)
		}
		err = w.Flush()
		if err != nil {
			return err
		}
		fmt.Printf("Total: %d\n", len(networks.Items))
	}

	return nil
}
예제 #8
0
// Lists all images
func listImages(c *cli.Context, w io.Writer) error {
	err := checkArgNum(c.Args(), 0, "image list [<options>]")
	if err != nil {
		return err
	}
	client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
	if err != nil {
		return err
	}

	name := c.String("name")
	options := &photon.ImageGetOptions{
		Name: name,
	}
	images, err := client.Esxclient.Images.GetAll(options)
	if err != nil {
		return err
	}

	if c.GlobalIsSet("non-interactive") {
		for _, image := range images.Items {
			fmt.Printf("%s\t%s\t%s\t%d\t%s\t%s\t%s\n", image.ID, image.Name, image.State, image.Size,
				image.ReplicationType, image.ReplicationProgress, image.SeedingProgress)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(images.Items, w, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "ID\tName\tState\tSize(Byte)\tReplication_type\tReplicationProgress\tSeedingProgress\n")
		for _, image := range images.Items {
			fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%s\t%s\n", image.ID, image.Name, image.State, image.Size,
				image.ReplicationType, image.ReplicationProgress, image.SeedingProgress)
		}
		err = w.Flush()
		if err != nil {
			return err
		}
		fmt.Printf("\nTotal: %d\n", len(images.Items))
	}

	return nil
}
예제 #9
0
// Retrieves a list of tenants, returns an error if one occurred
func listTenants(c *cli.Context, w io.Writer) error {
	err := checkArgNum(c.Args(), 0, "tenant list")
	if err != nil {
		return err
	}
	client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
	if err != nil {
		return err
	}

	tenants, err := client.Esxclient.Tenants.GetAll()
	if err != nil {
		return err
	}

	if c.GlobalIsSet("non-interactive") {
		for _, tenant := range tenants.Items {
			fmt.Printf("%s\t%s\n", tenant.ID, tenant.Name)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(tenants.Items, w, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "ID\tName\n")
		for _, tenant := range tenants.Items {
			fmt.Fprintf(w, "%s\t%s\n", tenant.ID, tenant.Name)
		}
		err = w.Flush()
		if err != nil {
			return err
		}
		fmt.Printf("\nTotal: %d\n", len(tenants.Items))
	}

	return nil
}