コード例 #1
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
}
コード例 #2
0
// Lists all the hosts associated with the deployment
func listDeploymentVms(c *cli.Context, w io.Writer) error {
	id, err := getDeploymentId(c)
	if err != nil {
		return err
	}

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

	vms, err := client.Esxclient.Deployments.GetVms(id)
	if err != nil {
		return err
	}

	if utils.NeedsFormatting(c) {
		utils.FormatObjects(vms, w, c)
	} else {
		err = printVMList(vms.Items, os.Stdout, c, false)
		if err != nil {
			return err
		}
	}

	return nil
}
コード例 #3
0
ファイル: vms.go プロジェクト: toliaqat/photon-controller
func listVMNetworks(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 1)
	if err != nil {
		return err
	}

	id := c.Args().First()

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

	networks, err := getVMNetworks(id, c)
	if err != nil {
		return err
	}

	if !utils.NeedsFormatting(c) {
		err = printVMNetworks(networks, c.GlobalIsSet("non-interactive"))
		if err != nil {
			return err
		}
	} else {
		utils.FormatObjects(networks, w, c)
	}
	return nil
}
コード例 #4
0
ファイル: vms.go プロジェクト: toliaqat/photon-controller
// Retrieves tasks for VM
func getVMTasks(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 1)
	if err != nil {
		return err
	}

	id := c.Args().First()
	state := c.String("state")

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

	options := &photon.TaskGetOptions{
		State: state,
	}

	taskList, err := client.Esxclient.VMs.GetTasks(id, options)
	if err != nil {
		return err
	}

	if !utils.NeedsFormatting(c) {
		err = printTaskList(taskList.Items, c)
		if err != nil {
			return err
		}
	} else {
		utils.FormatObjects(taskList, w, c)
	}

	return nil
}
コード例 #5
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
}
コード例 #6
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
}
コード例 #7
0
// Retrieves a list of projects, returns an error if one occurred
func listProjects(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}
	tenantName := c.String("tenant")

	client.Esxclient, err = client.GetClient(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
}
コード例 #8
0
func printClusterVMs(vms []photon.VM, w io.Writer, c *cli.Context) (err error) {
	clusterVMs := []ClusterVM{}
	for _, vm := range vms {
		ipAddr := "-"
		networks, err := getVMNetworks(vm.ID, c)
		if err != nil {
			continue
		}
		for _, nt := range networks {
			network := nt.(map[string]interface{})
			if val, ok := network["network"]; !ok || val == nil {
				continue
			}
			if val, ok := network["ipAddress"]; ok && val != nil {
				ipAddr = val.(string)
				break
			}
		}
		clusterVM := ClusterVM{
			vm,
			ipAddr,
		}
		clusterVMs = append(clusterVMs, clusterVM)

	}

	if c.GlobalIsSet("non-interactive") {
		fmt.Printf("%d\n", len(vms))
		for _, clusterVM := range clusterVMs {
			fmt.Printf("%s\t%s\t%s\n", clusterVM.ClusterVM.ID,
				clusterVM.ClusterVM.Name, clusterVM.IPAddress)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(clusterVMs, w, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "VM ID\tVM Name\tVM IP\n")
		for _, clusterVM := range clusterVMs {
			fmt.Fprintf(w, "%s\t%s\t%s\n", clusterVM.ClusterVM.ID,
				clusterVM.ClusterVM.Name, clusterVM.IPAddress)
		}
		err := w.Flush()
		if err != nil {
			return err
		}
	}
	return nil
}
コード例 #9
0
ファイル: flavors.go プロジェクト: toliaqat/photon-controller
// Retrieves a list of flavors
func listFlavors(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}
	client.Esxclient, err = client.GetClient(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
}
コード例 #10
0
ファイル: vms.go プロジェクト: toliaqat/photon-controller
// Retrieves a list of VMs, returns an error if one occurred
func listVMs(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}

	tenantName := c.String("tenant")
	projectName := c.String("project")
	summaryView := c.IsSet("summary")

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

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

	tenant, err := verifyTenant(tenantName)
	if err != nil {
		return err
	}
	project, err := verifyProject(tenant.ID, projectName)
	if err != nil {
		return err
	}

	vmList, err := client.Esxclient.Projects.GetVMs(project.ID, options)
	if err != nil {
		return err
	}

	if !utils.NeedsFormatting(c) {
		err = printVMList(vmList.Items, os.Stdout, c, summaryView)
	} else {
		utils.FormatObjects(vmList, w, c)
	}
	if err != nil {
		return err
	}

	return nil
}
コード例 #11
0
// Retrieves a list of resource tickets, returns an error if one occurred
func listResourceTickets(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}
	tenantName := c.String("tenant")

	client.Esxclient, err = client.GetClient(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
}
コード例 #12
0
func listPhysicalNetworks(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}
	client.Esxclient, err = client.GetClient(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\tDescription\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
}
コード例 #13
0
ファイル: images.go プロジェクト: toliaqat/photon-controller
// Lists all images
func listImages(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}
	client.Esxclient, err = client.GetClient(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
}
コード例 #14
0
// Retrieves a list of deployments
func listDeployments(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}

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

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

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

	return nil
}
コード例 #15
0
// Retrieves a list of availability zones, returns an error if one occurred
func listAvailabilityZones(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}
	client.Esxclient, err = client.GetClient(c)
	if err != nil {
		return err
	}

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

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

	return nil
}
コード例 #16
0
ファイル: disks.go プロジェクト: toliaqat/photon-controller
// Retrieves a list of disk, returns an error if one occurred
func listDisks(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}
	tenantName := c.String("tenant")
	projectName := c.String("project")
	summaryView := c.IsSet("summary")

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

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

	tenant, err := verifyTenant(tenantName)
	if err != nil {
		return err
	}
	project, err := verifyProject(tenant.ID, projectName)
	if err != nil {
		return err
	}

	diskList, err := client.Esxclient.Projects.GetDisks(project.ID, options)
	if err != nil {
		return err
	}

	if utils.NeedsFormatting(c) {
		utils.FormatObjects(diskList, w, c)
		return nil
	}

	stateCount := make(map[string]int)
	for _, disk := range diskList.Items {
		stateCount[disk.State]++
	}

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

	return nil
}
コード例 #17
0
func listVirtualNetworks(c *cli.Context, w io.Writer) error {
	err := checkArgCount(c, 0)
	if err != nil {
		return err
	}
	client.Esxclient, err = client.GetClient(c)
	if err != nil {
		return err
	}

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

	projectId := c.String("projectId")
	if len(projectId) == 0 {
		tenant, err := verifyTenant("")
		if err != nil {
			return err
		}

		project, err := verifyProject(tenant.ID, "")
		if err != nil {
			return err
		}

		projectId = project.ID
	}

	networks, err := client.Esxclient.VirtualSubnets.GetAll(projectId, 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\t%t\t%s\t%s\t%s\t%s\t%s\t%s\n", network.ID, network.Name, network.State,
				network.Description, network.RoutingType, network.IsDefault, network.Cidr, network.LowIpDynamic,
				network.HighIpDynamic, network.LowIpStatic, network.HighIpStatic, network.ReservedIpList)
		}
	} 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\tDescriptions\tRoutingType\tIsDefault\tCIDR\tLowDynamicIP\tHighDynamicIP"+
			"\tLowStaticIP\tHighStaticIP\tReservedIpList\n")
		for _, network := range networks.Items {
			fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%t\t%s\t%s\t%s\t%s\t%s\t%s\n", network.ID, network.Name, network.State,
				network.Description, network.RoutingType, network.IsDefault, network.Cidr, network.LowIpDynamic,
				network.HighIpDynamic, network.LowIpStatic, network.HighIpStatic, network.ReservedIpList)
		}
		err = w.Flush()
		if err != nil {
			return err
		}
		fmt.Printf("Total: %d\n", len(networks.Items))
	}

	return nil
}