本文整理汇总了Golang中github.com/openshift/geard/containers.Identifier.UnitNameFor方法的典型用法代码示例。如果您正苦于以下问题:Golang Identifier.UnitNameFor方法的具体用法?Golang Identifier.UnitNameFor怎么用?Golang Identifier.UnitNameFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openshift/geard/containers.Identifier
的用法示例。
在下文中一共展示了Identifier.UnitNameFor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: unitState
func (s *IntegrationTestSuite) unitState(id containers.Identifier) (string, string) {
props, err := s.sdconn.GetUnitProperties(id.UnitNameFor())
if props == nil || err != nil {
return "", ""
}
return props["ActiveState"].(string), props["SubState"].(string)
}
示例2: unitTimes
func (s *IntegrationTestSuite) unitTimes(id containers.Identifier) (inactiveStart time.Time, inactiveEnd time.Time, activeStart time.Time, activeEnd time.Time) {
props, err := s.sdconn.GetUnitProperties(id.UnitNameFor())
if props == nil || err != nil {
return
}
inactiveStart = time.Unix(int64(props["InactiveEnterTimestampMonotonic"].(uint64)), 0)
inactiveEnd = time.Unix(int64(props["InactiveExitTimestampMonotonic"].(uint64)), 0)
activeStart = time.Unix(int64(props["ActiveEnterTimestampMonotonic"].(uint64)), 0)
activeEnd = time.Unix(int64(props["ActiveExitTimestampMonotonic"].(uint64)), 0)
return
}
示例3: idleContainer
func (idler *Idler) idleContainer(id containers.Identifier) bool {
portPairs, err := containers.GetExistingPorts(id)
if err != nil {
fmt.Printf("idler.idleContainer: Error retrieving ports for container: %v\n", id)
return false
}
iptablePorts, err := iptables.GetIdlerRules(id, false)
if err != nil {
fmt.Printf("idler.idleContainer: Error retrieving ports from iptables: %v\n", id)
return false
}
shouldRecreateRules := false
for _, portPair := range portPairs {
extPort := strconv.Itoa(int(portPair.External))
shouldRecreateRules = shouldRecreateRules || !iptablePorts[extPort]
}
if !shouldRecreateRules {
return false
}
//TODO: Ask geard to idle container
f, err := os.Create(id.IdleUnitPathFor())
if err != nil {
fmt.Printf("idler.idleContainer: Could not create idle marker for %s: %v", id.UnitNameFor(), err)
return false
}
f.Close()
if err := systemd.Connection().StopUnitJob(id.UnitNameFor(), "fail"); err != nil {
fmt.Printf("idler.idleContainer: Could not stop container %s: %v", id.UnitNameFor(), err)
return false
}
iptables.IdleContainer(id, idler.hostIp)
return true
}
示例4: unidleContainer
func (idler *Idler) unidleContainer(id containers.Identifier, p netfilter.NFPacket) {
newChanId, wasAlreadyAssigned := idler.getAvailableWaiter(id)
if newChanId == 0 {
fmt.Println("unidle: Error while finding wait channel")
return
}
if !wasAlreadyAssigned {
//TODO: Ask geard to unidle container
if err := os.Remove(id.IdleUnitPathFor()); err != nil {
fmt.Printf("unidle: Could not remove idle marker for %s: %v", id.UnitNameFor(), err)
p.SetVerdict(netfilter.NF_ACCEPT)
return
}
if err := systemd.Connection().StartUnitJob(id.UnitNameFor(), "fail"); err != nil {
fmt.Printf("unidle: Could not start container %s: %v", id.UnitNameFor(), err)
p.SetVerdict(netfilter.NF_ACCEPT)
return
}
}
p.SetRequeueVerdict(newChanId)
}
示例5: activeUnitPathFor
func activeUnitPathFor(i containers.Identifier) string {
return filepath.Join("/etc/systemd/system/container-active.target.wants", i.UnitNameFor())
}
示例6: assertContainerState
func (s *IntegrationTestSuite) assertContainerState(c *chk.C, id containers.Identifier, expectedState ContainerState) {
var (
curState ContainerState
didStop bool
didRestart bool
ticker *time.Ticker
)
ticker = time.NewTicker(time.Second / 10)
defer ticker.Stop()
cInfo, err := s.sdconn.GetUnitProperties(id.UnitNameFor())
c.Assert(err, chk.IsNil)
switch cInfo["SubState"] {
case "running":
curState = CONTAINER_STARTED
case "dead", "failed", "stop-sigterm", "stop":
didStop = true
curState = CONTAINER_STOPPED
}
c.Logf("Current state: %v, interpreted as %v", cInfo["SubState"], curState)
if curState != expectedState {
for true {
select {
case <-ticker.C:
cInfo, err := s.sdconn.GetUnitProperties(id.UnitNameFor())
c.Assert(err, chk.IsNil)
switch cInfo["SubState"] {
case "running":
curState = CONTAINER_STARTED
if didStop {
didRestart = true
}
case "dead", "failed", "stop-sigterm", "stop":
didStop = true
curState = CONTAINER_STOPPED
}
c.Logf("Current state: %v, interpreted as %v", cInfo["SubState"], curState)
case <-time.After(CONTAINER_STATE_CHANGE_TIMEOUT):
c.Logf("%v %v", didStop, didRestart)
c.Log("Timed out during state change")
c.Assert(1, chk.Equals, 2)
}
if (curState == expectedState) || (expectedState == CONTAINER_RESTARTED && didRestart == true) {
break
}
}
}
switch {
case expectedState == CONTAINER_STOPPED:
for true {
select {
case <-ticker.C:
_, err := s.dockerClient.GetContainer(id.ContainerFor(), false)
if err != nil {
return
}
case <-time.After(DOCKER_STATE_CHANGE_TIMEOUT):
c.Log("Timed out waiting for docker container to stop")
c.FailNow()
}
}
case expectedState == CONTAINER_STARTED || expectedState == CONTAINER_RESTARTED:
for true {
select {
case <-ticker.C:
container, err := s.dockerClient.GetContainer(id.ContainerFor(), true)
if err != nil {
continue
}
c.Logf("Container state: %v. Info: %v", container.State.Running, container.State)
if container.State.Running {
return
}
case <-time.After(DOCKER_STATE_CHANGE_TIMEOUT):
c.Log("Timed out waiting for docker container to start")
c.FailNow()
}
}
}
}