当前位置: 首页>>代码示例>>Golang>>正文


Golang Unit.Status方法代码示例

本文整理汇总了Golang中github.com/tsuru/tsuru/provision.Unit.Status方法的典型用法代码示例。如果您正苦于以下问题:Golang Unit.Status方法的具体用法?Golang Unit.Status怎么用?Golang Unit.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/tsuru/tsuru/provision.Unit的用法示例。


在下文中一共展示了Unit.Status方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: collectUnit

func collectUnit(container container, units chan<- provision.Unit, wg *sync.WaitGroup) {
	defer wg.Done()
	unit := provision.Unit{
		Name:    container.ID,
		AppName: container.AppName,
		Type:    container.Type,
	}
	if container.Status == "error" {
		unit.Status = provision.StatusDown
		units <- unit
		return
	}
	if container.Status == "running" {
		unit.Ip = container.HostAddr
		ip, hostPort, err := container.networkInfo()
		if err == nil &&
			(hostPort != container.HostPort || ip != container.IP) {
			err = fixContainer(&container, ip, hostPort)
			if err != nil {
				log.Errorf("error on fix container hostport for [container %s]", container.ID)
				return
			}
		}
		addr := strings.Replace(container.getAddress(), "http://", "", 1)
		conn, err := net.Dial("tcp", addr)
		if err != nil {
			unit.Status = provision.StatusUnreachable
		} else {
			conn.Close()
			unit.Status = provision.StatusStarted
		}
		log.Debugf("collected data for [container %s] - [app %s]", container.ID, container.AppName)
		units <- unit
	}
}
开发者ID:rochacon,项目名称:tsuru,代码行数:35,代码来源:collector.go

示例2: TestContainerAsUnit

func (s *S) TestContainerAsUnit(c *check.C) {
	app := provisiontest.NewFakeApp("myapp", "python", 1)
	expected := provision.Unit{
		ID:          "c-id",
		AppName:     "myapp",
		Type:        "python",
		Ip:          "192.168.50.4",
		Status:      provision.StatusBuilding,
		ProcessName: "web",
		Address:     &url.URL{Scheme: "http", Host: "192.168.50.4:8080"},
	}
	container := Container{
		ID:          "c-id",
		HostAddr:    "192.168.50.4",
		HostPort:    "8080",
		ProcessName: "web",
	}
	got := container.AsUnit(app)
	c.Assert(got, check.DeepEquals, expected)
	container.Type = "ruby"
	container.Status = provision.StatusStarted.String()
	got = container.AsUnit(app)
	expected.Status = provision.StatusStarted
	expected.Type = "ruby"
	c.Assert(got, check.DeepEquals, expected)
}
开发者ID:kgrvamsi,项目名称:tsuru,代码行数:26,代码来源:container_test.go

示例3: collectStatus

func (p *JujuProvisioner) collectStatus() ([]provision.Unit, error) {
	out, err := p.getOutput()
	if err != nil {
		return nil, err
	}
	var units []provision.Unit
	for name, service := range out.Services {
		for unitName, u := range service.Units {
			machine := out.Machines[u.Machine]
			unit := provision.Unit{
				Name:       unitName,
				AppName:    name,
				Machine:    u.Machine,
				InstanceId: machine.InstanceID,
				Ip:         machine.IPAddress,
			}
			typeRegexp := regexp.MustCompile(`^(local:)?(\w+)/(\w+)-\d+$`)
			matchs := typeRegexp.FindStringSubmatch(service.Charm)
			if len(matchs) > 3 {
				unit.Type = matchs[3]
			}
			unit.Status = unitStatus(machine, u, unit)
			units = append(units, unit)
		}
	}
	p.saveBootstrapMachine(out.Machines[0])
	return units, err
}
开发者ID:rochacon,项目名称:tsuru,代码行数:28,代码来源:collector.go


注:本文中的github.com/tsuru/tsuru/provision.Unit.Status方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。