예제 #1
0
파일: command.go 프로젝트: jmptrader/beacon
func (c *Command) registerInstance(etcdClient *etcd.Client, container *docker.Container, hostIp, prefix string) error {
	log.WithFields(log.Fields{
		"id": container.ID,
	}).Debugln("start to register instance.")
	exportList, ok := container.NetworkSettings.Ports[docker.Port(c.Listen+"/tcp")]
	if !ok || len(exportList) < 1 {
		return errors.New("the port to listen not found")
	}
	instance := &register.Instance{
		Name:    container.ID,
		Service: c.Service,
		Backend: c.Backend,
		Cluster: c.Cluster,
		Proto:   c.Proto,
		Ip:      hostIp,
		Prefix:  prefix,
		Listen:  exportList[0].HostPort,
	}
	return register.AddInstance(etcdClient, instance)
}
예제 #2
0
파일: add.go 프로젝트: jmptrader/beacon
func add(c *cli.Context, client *etcd.Client) {
	instance := &reg.Instance{
		Name:    c.String("name"),
		Service: c.String("service"),
		Backend: c.String("backend"),
		Proto:   c.String("proto"),
		Cluster: c.String("cluster"),
		Ip:      c.String("host"),
		Listen:  c.String("port"),
		Prefix:  c.GlobalString("prefix"),
	}
	if err := reg.AddInstance(client, instance); err != nil {
		log.Fatalln(err.Error())
	}
	log.WithFields(log.Fields{
		"name":    instance.Name,
		"service": instance.Service,
		"backend": instance.Backend,
	}).Infoln("register a new instance.")
}