示例#1
0
func (daemon *Daemon) GetServices(podId string) ([]pod.UserService, error) {
	vm, container, err := daemon.GetServiceContainerInfo(podId)
	if err != nil {
		return nil, err
	}

	services, err := servicediscovery.GetServices(vm, container)
	if err != nil {
		return nil, err
	}

	return services, nil
}
示例#2
0
func (daemon *Daemon) AddService(podId string, srvs []pod.UserService) error {
	vm, container, err := daemon.GetServiceContainerInfo(podId)
	if err != nil {
		return err
	}

	services, err := servicediscovery.GetServices(vm, container)
	if err != nil {
		return err
	}

	for _, s := range srvs {
		services = append(services, s)
	}

	if err := servicediscovery.ApplyServices(vm, container, services); err != nil {
		return err
	}

	return nil
}
示例#3
0
func (daemon *Daemon) DeleteService(podId string, srvs []pod.UserService) error {
	var services []pod.UserService
	var services2 []pod.UserService
	var found int = 0

	vm, container, err := daemon.GetServiceContainerInfo(podId)
	if err != nil {
		return err
	}

	services, err = servicediscovery.GetServices(vm, container)
	if err != nil {
		return err
	}

	for _, s := range services {
		shouldRemain := true
		for _, srv := range srvs {
			if s.ServiceIP == srv.ServiceIP && s.ServicePort == srv.ServicePort {
				shouldRemain = false
				found = 1
				break
			}
		}

		if shouldRemain {
			services2 = append(services2, s)
		}
	}

	if found == 0 {
		return fmt.Errorf("Pod %s doesn't use this service", podId)
	}

	if err := servicediscovery.ApplyServices(vm, container, services2); err != nil {
		return err
	}

	return nil
}