Exemplo n.º 1
0
//XXX test with multiple containers of same definition!
func AssembleTable(typ string) ([]Parts, error) {

	typ = strings.TrimSuffix(typ, "s") // :(
	// []*ContainerName
	contsR := util.ErisContainersByType(typ, false) //running
	contsE := util.ErisContainersByType(typ, true)  //existing

	if len(contsE) == 0 && len(contsR) == 0 {
		return []Parts{}, nil
	}

	var myTable []Parts
	addedAlready := make(map[string]bool)

	for _, name := range contsR {
		part, _ := makePartFromContainer(name.FullName)
		addedAlready[part.ShortName] = true //has to come after because short name needed
		part.Running = true
		myTable = append(myTable, part)
	}

	for _, name := range contsE {
		part, _ := makePartFromContainer(name.FullName)
		if addedAlready[part.ShortName] == true {
			continue
		} else {
			part.Running = false
			myTable = append(myTable, part)
		}
	}
	return myTable, nil
}
Exemplo n.º 2
0
func PrintTableReport(typ string, running bool) error {
	logger.Debugf("PrintTableReport Initialized =>\t%s:%v\n", typ, running)
	conts := util.ErisContainersByType(typ, running)
	if len(conts) == 0 {
		return nil
	}

	var head string
	if typ == "chain" {
		head, _ = util.GetHead()
	}

	table := tablewriter.NewWriter(config.GlobalConfig.Writer)
	table.SetHeader([]string{"SERVICE NAME", "CONTAINER NAME", "TYPE", "CONTAINER #", "PORTS"})
	for _, c := range conts {
		n, _ := PrintLineByContainerName(c.FullName)
		if typ == "chain" {
			if n[0] == head {
				n[0] = fmt.Sprintf("**  %s", n[0]) // TODO: colorize this when we settle on a lib
			}
		}
		table.Append(n)
	}

	// Styling
	table.SetBorder(false)
	table.SetCenterSeparator(" ")
	table.SetColumnSeparator(" ")
	table.SetRowSeparator("-")
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.Render()
	return nil
}
Exemplo n.º 3
0
// FindContainer returns true if the container with a given
// short name, type, number, and status exists.
func FindContainer(name, t string, n int, running bool) bool {
	containers := util.ErisContainersByType(t, !running)

	for _, c := range containers {
		if c.ShortName == name && c.Number == n {
			return true
		}
	}
	return false
}
Exemplo n.º 4
0
func PrintTableReport(typ string, existing, all bool) (string, error) {
	log.WithField("type", typ).Debug("Table report initialized")

	var conts []*util.ContainerName
	if !all {
		conts = util.ErisContainersByType(typ, existing)
	}
	// "MACHINE" is placeholder
	header := []string{"NAME", "MACHINE", "RUNNING", "CONTAINER NAME", "PORTS"}
	if err := util.CheckParts(header); err != nil {
		log.Error(err) // err is silenced by some funcs
		return "", err
	}

	buf := new(bytes.Buffer)
	table := tablewriter.NewWriter(buf)
	//name set by logger instead
	table.SetHeader(header)

	if all { //get all the things
		parts, _ := AssembleTable(typ)
		for _, p := range parts {
			table.Append(formatLine(p))
		}
	} else {
		for _, c := range conts {
			n, _ := PrintLineByContainerName(c.FullName, existing)
			if typ == "chain" {
				head, _ := util.GetHead()
				if n[0] == head {
					n[0] = fmt.Sprintf("**  %s", n[0])
				}
			}
			table.Append(n)
		}
	}

	// Styling
	table.SetBorder(false)
	table.SetCenterSeparator(" ")
	table.SetColumnSeparator(" ")
	table.SetRowSeparator("-")
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.Render()

	return buf.String(), nil
}
Exemplo n.º 5
0
func PrintTableReport(typ string, running bool) error {
	logger.Debugf("PrintTableReport Initialized =>\t%s:%v\n", typ, running)
	conts := util.ErisContainersByType(typ, running)
	if len(conts) == 0 {
		return nil
	}

	table := tablewriter.NewWriter(util.GlobalConfig.Writer)
	table.SetHeader([]string{"SERVICE NAME", "CONTAINER NAME", "TYPE", "CONTAINER #", "PORTS"})
	for _, c := range conts {
		n, _ := PrintLineByContainerName(c.FullName)
		table.Append(n)
	}

	// Styling
	table.SetBorder(false)
	table.SetCenterSeparator(" ")
	table.SetColumnSeparator(" ")
	table.SetRowSeparator("-")
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.Render()
	return nil
}