當前位置: 首頁>>代碼示例>>Golang>>正文


Golang containers.Identifier類代碼示例

本文整理匯總了Golang中github.com/openshift/geard/containers.Identifier的典型用法代碼示例。如果您正苦於以下問題:Golang Identifier類的具體用法?Golang Identifier怎麽用?Golang Identifier使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Identifier類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
開發者ID:jhadvig,項目名稱:geard,代碼行數:7,代碼來源:integration_test.go

示例2: assertContainerRestarts

func (s *IntegrationTestSuite) assertContainerRestarts(c *chk.C, id containers.Identifier) {
	isStarted := func() bool {
		active, sub := s.unitState(id)
		if active == "active" {
			return true
		}
		if active == "deactivating" || active == "activating" {
			return false
		}
		c.Errorf("Unit %s restart failed (%s) in unexpected state %s", id, active, sub)
		c.FailNow()
		return false
	}

	if !until(CONTAINER_STATE_CHANGE_TIMEOUT, CONTAINER_CHECK_INTERVAL, isStarted) {
		active, sub := s.unitState(id)
		c.Errorf("Timeout during restart of %s, never got back to 'active' state (%s/%s)", id, active, sub)
		c.FailNow()
	}

	container, err := s.dockerClient.GetContainer(id.ContainerFor(), false)
	if err != nil {
		c.Error("Can't check container "+id, err)
		c.FailNow()
	}
	if !container.State.Running {
		c.Logf("Container %s exists, but is not running - race condition %+v", id, container.State)
	}
}
開發者ID:smarterclayton,項目名稱:geard,代碼行數:29,代碼來源:integration_test.go

示例3: getContainerPid

func (s *IntegrationTestSuite) getContainerPid(id containers.Identifier) int {
	container, err := s.dockerClient.InspectContainer(id.ContainerFor())
	if err != nil {
		return 0
	}
	return container.State.Pid
}
開發者ID:jhadvig,項目名稱:geard,代碼行數:7,代碼來源:integration_test.go

示例4: switchnsExec

func switchnsExec(args []string) {
	var err error

	client, err := docker.GetConnection("unix:///var/run/docker.sock")
	if err != nil {
		fmt.Printf("Unable to connect to server\n")
		os.Exit(3)
	}

	uid := os.Getuid()

	if uid == 0 {
		runCommandInContainer(client, containerName, args, envs)
	} else {
		var u *user.User
		var containerId containers.Identifier

		if u, err = user.LookupId(strconv.Itoa(uid)); err != nil {
			fmt.Printf("Couldn't lookup uid %s\n", uid)
			os.Exit(2)
		}

		if containerId, err = containers.NewIdentifierFromUser(u); err != nil {
			fmt.Printf("Couldn't get identifier from user: %v\n", u)
			os.Exit(2)
		}
		runCommandInContainer(client, containerId.ContainerFor(), []string{"/bin/sh", "-l"}, []string{})
	}
}
開發者ID:jcantrill,項目名稱:geard,代碼行數:29,代碼來源:main.go

示例5: GetSocketActivation

func GetSocketActivation(id containers.Identifier) (bool, string, error) {
	var err error
	var existing *os.File
	if existing, err = os.Open(id.UnitPathFor()); err != nil {
		return false, "disabled", err
	}

	defer existing.Close()
	return readSocketActivationFromUnitFile(existing)
}
開發者ID:jcantrill,項目名稱:geard,代碼行數:10,代碼來源:socket_activation.go

示例6: 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
}
開發者ID:jhadvig,項目名稱:geard,代碼行數:11,代碼來源:integration_test.go

示例7: SetUnitStartOnBoot

func SetUnitStartOnBoot(i containers.Identifier, active bool) error {
	if active {
		if err := os.Symlink(i.UnitPathFor(), activeUnitPathFor(i)); err != nil && !os.IsExist(err) {
			return err
		}
	} else {
		if err := os.Remove(activeUnitPathFor(i)); err != nil && !os.IsNotExist(err) {
			return err
		}
	}
	return nil
}
開發者ID:jcantrill,項目名稱:geard,代碼行數:12,代碼來源:state.go

示例8: assertContainerStarts

func (s *IntegrationTestSuite) assertContainerStarts(c *chk.C, id containers.Identifier) {
	active, _ := s.unitState(id)
	switch active {
	case "active":
		return
	case "activating":
		break
	default:
		c.Errorf("Container %s failed to start - %s", id, active)
		c.FailNow()
		return
	}

	isRunning := func() bool {
		active, sub := s.unitState(id)
		if active == "active" {
			return true
		}
		if active == "activating" {
			return false
		}
		c.Errorf("Unit %s start failed with state %s", id, sub)
		c.FailNow()
		return false
	}

	if !until(TimeoutContainerStateChange, time.Second/20, isRunning) {
		c.Errorf("Timeout during start of %s, never got to 'active' state", id)
		c.FailNow()
	}

	// Docker does not immediately return container status - possibly due to races inside of the
	// daemon
	failed := false
	isContainerUp := func() bool {
		done, err := isContainerAvailable(s.dockerClient, id.ContainerFor())
		if err != nil {
			failed = true
			c.Error("Docker couldn't return container info", err)
			c.FailNow()
		}
		return done
	}

	if !until(TimeoutDockerWait, IntervalHttpCheck, isContainerUp) {
		if !failed {
			c.Errorf("Docker never reported the container running %s", id)
		}
		c.FailNow()
	}
}
開發者ID:jhadvig,項目名稱:geard,代碼行數:51,代碼來源:integration_test.go

示例9: assertContainerStarts

func (s *IntegrationTestSuite) assertContainerStarts(c *chk.C, id containers.Identifier) {
	active, _ := s.unitState(id)
	switch active {
	case "active":
		return
	case "activating":
		break
	default:
		c.Errorf("Container %s failed to start - %s", id, active)
		c.FailNow()
		return
	}

	isRunning := func() bool {
		active, sub := s.unitState(id)
		if active == "active" {
			return true
		}
		if active == "activating" {
			return false
		}
		c.Errorf("Unit %s start failed with state %s", id, sub)
		c.FailNow()
		return false
	}

	if !until(CONTAINER_STATE_CHANGE_TIMEOUT, time.Second/20, isRunning) {
		c.Errorf("Timeout during start of %s, never got to 'active' state", id)
		c.FailNow()
	}

	container, err := s.dockerClient.GetContainer(id.ContainerFor(), false)
	if err != nil {
		c.Error("Can't check container "+id, err)
		c.FailNow()
	}
	if !container.State.Running {
		c.Logf("Container %s exists, but is not running - race condition %+v", id, container.State)
		//c.Errorf("Container %s is not running %+v", id, container)
		//c.FailNow()
	}
}
開發者ID:smarterclayton,項目名稱:geard,代碼行數:42,代碼來源:integration_test.go

示例10: switchnsExec

func switchnsExec(cmd *cobra.Command, args []string) {
	var err error

	uid := os.Getuid()

	if uid == 0 {
		runCommand(containerName, args, envs)
	} else {
		var u *user.User
		var containerId containers.Identifier

		if u, err = user.LookupId(strconv.Itoa(uid)); err != nil {
			os.Exit(2)
		}

		if containerId, err = containers.NewIdentifierFromUser(u); err != nil {
			os.Exit(2)
		}
		runCommand(containerId.ContainerFor(), []string{"/bin/bash", "-l"}, []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"})
	}
}
開發者ID:roacobb,項目名稱:geard,代碼行數:21,代碼來源:main.go

示例11: assertContainerRestarts

func (s *IntegrationTestSuite) assertContainerRestarts(c *chk.C, id containers.Identifier) {
	isStarted := func() bool {
		active, sub := s.unitState(id)
		if active == "active" {
			return true
		}
		if active == "deactivating" || active == "activating" {
			return false
		}
		c.Errorf("Unit %s restart failed (%s) in unexpected state %s", id, active, sub)
		c.FailNow()
		return false
	}

	if !until(TimeoutContainerStateChange, IntervalContainerCheck, isStarted) {
		active, sub := s.unitState(id)
		c.Errorf("Timeout during restart of %s, never got back to 'active' state (%s/%s)", id, active, sub)
		c.FailNow()
	}

	// Docker does not immediately return container status - possibly due to races inside of the
	// daemon
	failed := false
	isContainerUp := func() bool {
		done, err := isContainerAvailable(s.dockerClient, id.ContainerFor())
		if err != nil {
			failed = true
			c.Error("Docker couldn't return container info", err)
			c.FailNow()
		}
		return done
	}

	if !until(TimeoutDockerWait, IntervalHttpCheck, isContainerUp) {
		if !failed {
			c.Errorf("Docker never reported the container running %s", id)
		}
		c.FailNow()
	}
}
開發者ID:jhadvig,項目名稱:geard,代碼行數:40,代碼來源:integration_test.go

示例12: switchnsExec

func switchnsExec(args []string) {
	var err error

	uid := os.Getuid()

	if uid == 0 {
		runCommandInContainer(containerName, args, envs)
	} else {
		var u *user.User
		var containerId containers.Identifier

		if u, err = user.LookupId(strconv.Itoa(uid)); err != nil {
			fmt.Printf("Couldn't lookup uid %s\n", uid)
			os.Exit(2)
		}

		if containerId, err = containers.NewIdentifierFromUser(u); err != nil {
			fmt.Printf("Couldn't get identifier from user: %v\n", u)
			os.Exit(2)
		}
		runCommandInContainer(containerId.ContainerFor(), []string{"/bin/bash", "-l"}, []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"})
	}
}
開發者ID:smarterclayton,項目名稱:geard,代碼行數:23,代碼來源:main.go

示例13: createUser

func createUser(id containers.Identifier) error {
	cmd := exec.Command("/usr/sbin/useradd", id.LoginFor(), "-m", "-d", id.HomePath(), "-c", "Container user")
	if out, err := cmd.CombinedOutput(); err != nil {
		log.Println(out)
		return err
	}
	selinux.RestoreCon(id.HomePath(), true)
	return nil
}
開發者ID:hguemar,項目名稱:geard,代碼行數:9,代碼來源:support.go

示例14: assertContainerStops

func (s *IntegrationTestSuite) assertContainerStops(c *chk.C, id containers.Identifier, allowFail bool) {
	active, _ := s.unitState(id)
	switch active {
	case "active", "activating":
		c.Errorf("Container %s stop not properly queued, service is still active - %s", id, active)
		c.FailNow()
		return
	}

	isStopped := func() bool {
		active, sub := s.unitState(id)
		if active == "inactive" {
			return true
		}
		if allowFail && active == "failed" {
			return true
		}
		if active == "deactivating" {
			return false
		}
		c.Errorf("Unit %s stop failed (%s) with state %s", id, active, sub)
		c.FailNow()
		return false
	}

	if !until(TimeoutContainerStateChange, IntervalContainerCheck, isStopped) {
		c.Errorf("Timeout during start of %s, never got to 'inactive' state", id)
		c.FailNow()
	}

	_, err := s.dockerClient.InspectContainer(id.ContainerFor())
	if err == nil {
		c.Errorf("Container %s is still active in docker, should be stopped and removed", id.ContainerFor())
		c.FailNow()
	}
}
開發者ID:jhadvig,項目名稱:geard,代碼行數:36,代碼來源:integration_test.go

示例15: InitPostStart

func InitPostStart(dockerSocket string, id containers.Identifier) error {
	var (
		u         *user.User
		container *dc.Container
		err       error
		d         *docker.DockerClient
	)

	if u, err = user.Lookup(id.LoginFor()); err == nil {
		if err := ssh.GenerateAuthorizedKeysFor(u, true, false); err != nil {
			log.Print(err.Error())
		}
	} else {
		log.Print(err.Error())
	}

	if d, err = docker.GetConnection(dockerSocket); err != nil {
		return err
	}

	if file, err := os.Open(id.NetworkLinksPathFor()); err == nil {
		defer file.Close()

		const ContainerInterval = time.Second / 3
		const ContainerWait = time.Second * 12
		for i := 0; i < int(ContainerWait/ContainerInterval); i++ {
			if container, err = d.GetContainer(id.ContainerFor(), true); err != nil {
				return err
			}
			if container.State.Running {
				break
			} else {
				log.Printf("Waiting for container to run.")
				time.Sleep(ContainerInterval)
			}
		}

		pid, err := d.ChildProcessForContainer(container)
		if err != nil {
			return err
		}
		if pid < 2 {
			return errors.New("support: child PID is not correct")
		}
		log.Printf("Updating network namespaces for %d", pid)
		if err := updateNamespaceNetworkLinks(pid, file); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:hguemar,項目名稱:geard,代碼行數:52,代碼來源:support.go


注:本文中的github.com/openshift/geard/containers.Identifier類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。