예제 #1
0
파일: idler.go 프로젝트: kraman/geard-idler
func (idler *Idler) idleContainer(id containers.Identifier) {
	portPairs, err := containers.GetExistingPorts(id)
	if err != nil {
		fmt.Printf("IDLE: Error retrieving ports for container: %v", id)
		return
	}

	iptablePorts, err := iptables.GetIdlerRules(id)
	if err != nil {
		fmt.Printf("IDLE: Error retrieving ports from iptables: %v", id)
		return
	}

	shouldRecreateRules := false
	for _, portPair := range portPairs {
		extPort := strconv.Itoa(int(portPair.External))
		shouldRecreateRules = shouldRecreateRules || !iptablePorts[extPort]
	}

	if !shouldRecreateRules {
		return
	}

	//TODO: Ask geard to idle container
	fmt.Printf("Stopping container %v\n", id)
	if err := systemd.Connection().StopUnitJob(id.UnitNameFor(), "fail"); err != nil {
		fmt.Printf("idle: Could not stop container %s: %v", id.UnitNameFor(), err)
		return
	}

	iptables.IdleContainer(id, idler.hostIp)
}
예제 #2
0
파일: rules.go 프로젝트: kraman/geard-idler
func UnidleContainer(id containers.Identifier, hostIp string) {
	portPairs, err := containers.GetExistingPorts(id)
	if err != nil {
		fmt.Printf("IDLE: Error retrieving ports for container: %v", id)
		return
	}

	for _, portPair := range portPairs {
		port := portPair.External
		runIptablesRules(false, hostIp, port.String(), id)
	}
}