예제 #1
0
func (s *SkynetDaemon) cleanupHost(daemonUUID string) (err error) {
	sm := skynet.GetServiceManager()
	c := skynet.Criteria{}

	c.AddHost(s.Service.ServiceInfo.ServiceAddr.IPAddress)

	var instances []skynet.ServiceInfo
	instances, err = sm.ListInstances(&c)

	if err != nil {
		return
	}

	for _, i := range instances {
		if i.UUID != daemonUUID {
			sm.Remove(i)
		}
	}

	return
}
예제 #2
0
파일: cli.go 프로젝트: carriercomm/sky-1
func tabCompleter(line string) []string {
	cmds := make([]string, 0)

	opts := make([]string, 0)

	if strings.HasPrefix(line, "reset") {
		filters := []string{
			"reset hosts",
			"reset instance",
			"reset region",
			"reset registered",
			"reset service",
			"reset version",
			"reset config",
		}

		for _, cmd := range filters {
			if strings.HasPrefix(cmd, line) {
				opts = append(opts, cmd)
			}
		}
	} else if strings.HasPrefix(line, "host") {
		cmds = make([]string, 0)

		for _, host := range getHosts(&skynet.Criteria{}) {
			if !exists(criteria.Hosts, host) {
				cmds = append(cmds, "host "+host)
			}
		}
	} else if strings.HasPrefix(line, "instance") {
		cmds = make([]string, 0)

		for _, instance := range getInstances(&skynet.Criteria{}) {
			if !exists(criteria.Instances, instance.UUID) {
				cmds = append(cmds, "instance "+instance.UUID)
			}
		}
	} else if strings.HasPrefix(line, "region") {
		cmds = make([]string, 0)

		for _, region := range getRegions(&skynet.Criteria{}) {
			if !exists(criteria.Regions, region) {
				cmds = append(cmds, "region "+region)
			}
		}
	} else if serviceRegex.MatchString(line) {
		cmds = make([]string, 0)
		matches := serviceRegex.FindAllStringSubmatch(line, -1)
		name := matches[0][1]

		c := new(skynet.Criteria)
		c.Services = []skynet.ServiceCriteria{skynet.ServiceCriteria{Name: name}}

		for _, version := range getVersions(c) {
			cmds = append(cmds, "service "+name+":"+version)
		}
	} else if strings.HasPrefix(line, "service") {
		cmds = make([]string, 0)

		for _, service := range getServices(&skynet.Criteria{}) {
			cmds = append(cmds, "service "+service)
		}
	} else if strings.HasPrefix(line, "registered") {
		cmds = []string{"registered true", "registered false"}
	} else if strings.HasPrefix(line, "log") {
		cmds = append([]string{"log DEBUG", "log TRACE", "log INFO", "log WARN", "log FATAL", "log PANIC"})
	} else if strings.HasPrefix(line, "daemon log") {
		cmds = append([]string{"daemon log DEBUG", "daemon log TRACE", "daemon log INFO", "daemon log WARN", "daemon log FATAL", "log PANIC"})
	} else if strings.HasPrefix(line, "daemon") {
		cmds = append([]string{"daemon log", "daemon stop"})
	} else {
		cmds = SupportedCliCommands
	}

	for _, cmd := range cmds {
		if strings.HasPrefix(cmd, line) {
			opts = append(opts, cmd)
		}
	}

	return opts
}