Esempio n. 1
0
func list(cmd *cli.Cmd) error {
	resp, err := cmd.Client.List(context.Background(), &pb.None{})
	if err != nil {
		return err
	}

	// create the table
	table := termtables.CreateTable()

	table.AddHeaders("UUID", "Name", "State")

	for _, container := range resp.Containers {
		var pod *schema.PodManifest
		if err := json.Unmarshal(container.Manifest, &pod); err != nil {
			return err
		}
		var appName string
		for _, app := range pod.Apps {
			appName = app.Name.String()
			break
		}
		table.AddRow(container.Uuid, appName, container.State.String())
	}
	fmt.Printf("%s", table.Render())
	return nil
}
Esempio n. 2
0
//Main is the entry point to parse benchmarks
//not intended for use in libraries, but has to be exported to ensure the tool can be called via 'pb'
func Main() {

	reader := bufio.NewReader(os.Stdin)
	quit := make(chan bool)
	go loading(quit)

	for {
		text, err := reader.ReadBytes('\n')
		if err != nil {
			if err != io.EOF {
				panic(err)
			}
			break
		}
		lines = append(lines, text)
	}
	close(quit)

	if len(lines) == 0 {
		os.Exit(0)
	}

	bench = newBenchmark(lines)

	table = termtables.CreateTable()
	table.Style.Alignment = termtables.AlignRight
	addTableHeader(table)
	addTableBody(table)

	fmt.Print("\r \n")
	fmt.Println(table.Render())
	fmt.Println(footer())
}
Esempio n. 3
0
func (_ Test) TermTables() {
	table := termtables.CreateTable()
	table.AddHeaders("Name", "Age")
	table.AddRow("John", "30")
	table.AddRow("Sam", 18)
	table.AddRow("Julie", 20.14)

	e.InfoLog.Println("\n", table.Render())
}
Esempio n. 4
0
//GetTrail returns events captured in cloudtrail
func GetTrail(key, value string) {
	resp := lookupInstanceTrail(key, value)
	events := parseCloudtrailEvents(resp)

	table := termtables.CreateTable()
	table.AddHeaders("EventID", "ResourceID", "Username", "EventName")
	for _, event := range events {
		table.AddRow(event.eventID, event.resourceID, event.username, event.eventName)
	}
	fmt.Println(table.Render())
}
Esempio n. 5
0
//GetVolumesFormatted retrieve all volumes
func GetVolumesFormatted(detached bool) {
	log.Debug("Creating Output Table for all volumes")
	table := termtables.CreateTable()
	table.AddHeaders("Name", "State", "WRK", "Size", "Attachments", "Volume ID")
	data := parseVolumeData(getAllVolumes(), detached)
	if data != nil {
		for _, row := range data {
			table.AddRow(row.Name, row.State, row.Wrk, row.Size, row.Attached, row.VolumeId)
		}
	}
	fmt.Println(table.Render())
}
Esempio n. 6
0
//GetTrail returns events captured in cloudtrail
func GetTrail(key, value, format string) {
	resp := lookupInstanceTrail(key, value)
	events := parseCloudtrailEvents(resp)
	if format == "table" {
		table := termtables.CreateTable()
		table.AddHeaders("EventID", "ResourceID", "Username", "EventName")
		for _, event := range events {
			table.AddRow(event.EventID, event.ResourceID, event.Username, event.EventName)
		}
		fmt.Println(table.Render())
	} else {
		js("events", events)
	}
}
Esempio n. 7
0
//GetInstancesFormatted retrieve all instances in the subnet
func GetInstancesFormatted(envname string) {
	log.Debug("Creating Output Table for all instances data in the subnet")
	table := termtables.CreateTable()
	table.AddHeaders("Name", "State", "WRK", "Launched By", "Instance Type", "Instance ID")
	subnetID := getSubnetIDByTag("Name", envname)
	if subnetID != "" {
		instances := getAllInstancesInSubnet(subnetID)
		data := parseInstancesData(instances)
		if data != nil {
			for _, row := range data {
				table.AddRow(row.name, row.instanceState, row.instanceWrk, row.launchedBy, row.instanceType, row.instancesID)
			}
		}
	}
	fmt.Println(table.Render())
}
Esempio n. 8
0
func fileInfoTable(info decoder.Info) string {
	table := termtables.CreateTable()
	table.UTF8Box()
	table.AddTitle("FILE INFO")
	for _, comment := range info.Comments {
		parts := strings.Split(comment, "=")
		if row := table.AddRow(parts[0]); len(parts) > 1 {
			row.AddCell(parts[1])
		}
	}
	if len(info.Comments) > 0 {
		table.AddSeparator()
	}
	table.AddRow("Bitstream", fmt.Sprintf("%d channel, %.1fHz", info.Channels, info.SampleRate))
	table.AddRow("Encoded by", info.Vendor)
	return table.Render()
}
Esempio n. 9
0
func CallGetAllProjects(username, password, bamboo_url string) {
	cred := new(credentials)

	cred.baseurl = bamboo_url
	cred.username = username
	cred.password = password

	allProjects := getAllProjects(*cred)
	table := termtables.CreateTable()
	table.AddHeaders("Name", "Key", "Link")
	if len(allProjects) != 0 {
		for _, proj := range allProjects {
			table.AddRow(proj.Name, proj.Key, proj.Link.Href)
		}
	}
	fmt.Println(table.Render())
}
Esempio n. 10
0
func CallGetAllBranches(username, password, bamboo_url, plan_key string) {
	cred := new(credentials)

	cred.baseurl = bamboo_url
	cred.username = username
	cred.password = password

	allBranches := getAllBranches(*cred, plan_key)
	table := termtables.CreateTable()
	table.AddHeaders("Name", "Enabled", "Key", "Link")
	if len(allBranches.AllBranch) != 0 {
		for _, br := range allBranches.AllBranch {
			table.AddRow(br.Shortname, br.Enabled, br.Key, br.Link.Href)
		}
	}
	fmt.Println(table.Render())
}
Esempio n. 11
0
func CallGetAllPlansInProject(username, password, bamboo_url, project_name string) {
	cred := new(credentials)

	cred.baseurl = bamboo_url
	cred.username = username
	cred.password = password

	allPlans := getAllPlansInProject(*cred, project_name)
	table := termtables.CreateTable()
	table.AddHeaders("Name", "Key", "Active", "Building", "Stages", "Branches", "Link")
	if len(allPlans.Plans) != 0 {
		for _, pl := range allPlans.Plans {
			table.AddRow(pl.BuildName, pl.Key, pl.IsActive, pl.IsBuilding, pl.Stages.Size, pl.Branches.Size, pl.Link.Href)
		}
	}
	fmt.Println(table.Render())
}
Esempio n. 12
0
//GetSubnetsFormatted retrieve all subnet in a region and format it
func GetSubnetsFormatted(format string) {
	log.Debug("Creating Output Table for Subnets Data")

	subnets := getAllSubnets()
	data := parseSubnetsData(subnets)
	if format == "table" {
		table := termtables.CreateTable()
		table.AddHeaders("Name", "CIDR Block", "WRK", "Subnet Id")
		if data != nil {
			for _, row := range data {
				table.AddRow(row.SubnetName, row.CidrBlock, row.SubnetWrk, row.SubnetID)
			}
		}

		fmt.Println(table.Render())
	} else {
		js("subnets", data)
	}

}
Esempio n. 13
0
//UpdateEnvTags updates tag with a value for all objects in subnet
func UpdateEnvTags(tagname, tagvalue, envname string) {
	log.Debug("Updating tags in all objects in subnet")
	subnetID := getSubnetIDByTag("Name", envname)
	instances := getAllInstancesInSubnet(subnetID)
	parsedData := parseInstancesData(instances)
	resources := make([]*string, 0, 20)
	resources = append(resources, &subnetID)
	for _, data := range parsedData {
		resources = append(resources, aws.String(data.instancesID))
		for _, volume := range data.volumes {
			resources = append(resources, aws.String(volume))
		}
	}
	table := termtables.CreateTable()
	table.AddHeaders("Updating Resources")
	for _, resource := range resources {
		table.AddRow(*resource)
	}
	fmt.Println(table.Render())
	updateTag(tagname, tagvalue, resources)
	GetInstancesFormatted(envname)
}
Esempio n. 14
0
func getSubnetIDByTag(tagname, tagvalue string) (subnetID string) {
	ec2client := getec2client()
	params := &ec2.DescribeSubnetsInput{
		Filters: []*ec2.Filter{
			{
				Name: aws.String("tag:" + tagname),
				Values: []*string{
					aws.String(tagvalue),
				},
			},
		},
	}

	resp, err := ec2client.DescribeSubnets(params)

	if err != nil {
		log.Error("Error calling DescribeSubnets")
		return subnetID
	}
	subnets := resp.Subnets
	if subnets == nil {
		log.Error("Cannot find subnet with the tag name/value")
		return subnetID
	} else if len(subnets) > 1 {
		log.Error("More than one subnet with the tag exists")
		table := termtables.CreateTable()
		table.AddHeaders("Subnet Id", "CIDR Block", tagname)

		for _, subnet := range subnets {
			table.AddRow(*subnet.SubnetId, *subnet.CidrBlock, tagvalue)
		}
		log.Error(table.Render())
		log.Error("Returning the first subnet in the list")
	} else {
		subnet := resp.Subnets[0]
		subnetID = *subnet.SubnetId
	}
	return subnetID
}
Esempio n. 15
0
//GetSubnetsFormatted retrieve all subnet in a region and format it
func GetSubnetsFormatted(format string) {
	log.Debug("Creating Output Table for Subnets Data")
	table := termtables.CreateTable()
	table.AddHeaders("Name", "CIDR Block", "WRK", "Subnet Id")

	subnets := getAllSubnets()
	data := parseSubnetsData(subnets)
	if format == "table" {
		if data != nil {
			for _, row := range data {
				table.AddRow(row.SubnetName, row.CidrBlock, row.SubnetWrk, row.SubnetID)
			}
		}

		fmt.Println(table.Render())
	} else { // only json otherwise
		fmt.Println("{ subnets: ")
		js, _ := json.MarshalIndent(data, "  ", "  ")
		fmt.Println(string(js))
		fmt.Println("}")
	}

}
Esempio n. 16
0
// inspect and print out details of disposable versions for a given application
func inspect(eb *elasticbeanstalk.ElasticBeanstalk, appName string, duration int) []*elasticbeanstalk.ApplicationVersionDescription {
	applicationVersionResp, err := eb.DescribeApplicationVersions(&elasticbeanstalk.DescribeApplicationVersionsInput{ApplicationName: &appName})

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			fmt.Println(err.Error())
		}
		os.Exit(1)
	}

	environmentResp, err := eb.DescribeEnvironments(&elasticbeanstalk.DescribeEnvironmentsInput{ApplicationName: &appName})

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			fmt.Println(err.Error())
		}
		os.Exit(1)
	}

	var disposableVersions = make([]*elasticbeanstalk.ApplicationVersionDescription, 0)

	var buffer bytes.Buffer

	buffer.WriteString(fmt.Sprintf("Application Name: %s\n", appName))
	buffer.WriteString(fmt.Sprintf("Total version: %d\n", len(applicationVersionResp.ApplicationVersions)))

	table := termtables.CreateTable()

	table.AddHeaders("Version Label", "Date Created", "Environment")

	for _, version := range applicationVersionResp.ApplicationVersions {
		var found bool = false
		for _, environment := range environmentResp.Environments {
			if *version.VersionLabel == *environment.VersionLabel {
				table.AddRow(*version.VersionLabel, version.DateCreated, *environment.EnvironmentName)
				found = true
			}
		}

		if !found {
			if time.Now().After(version.DateCreated.AddDate(0, 0, duration)) {
				disposableVersions = append(disposableVersions, version)
				table.AddRow(*version.VersionLabel, version.DateCreated, "*Disposable*")
			} else {
				table.AddRow(*version.VersionLabel, version.DateCreated, "Not disposable")
			}
		}
	}

	buffer.WriteString(table.Render())
	buffer.WriteString(fmt.Sprintf("Disposable version count: %d\n", len(disposableVersions)))

	fmt.Println(buffer.String())

	return disposableVersions
}