示例#1
0
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)
}
示例#2
0
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
}