Esempio n. 1
0
func (daemon *Daemon) AddService(job *engine.Job) error {
	var srvs []pod.UserService

	podId := job.Args[0]
	data := job.Args[1]

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

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

	json.Unmarshal([]byte(data), &srvs)
	if err != nil {
		return err
	}

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

	return servicediscovery.ApplyServices(vm, container, services)
}
Esempio n. 2
0
func (daemon *Daemon) AddService(podId, data string) error {
	var srvs []pod.UserService

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

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

	json.Unmarshal([]byte(data), &srvs)
	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
}
Esempio n. 3
0
func (daemon *Daemon) DeleteService(podId, data string) error {
	var srvs []pod.UserService
	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
	}

	err = json.Unmarshal([]byte(data), &srvs)
	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
}
Esempio n. 4
0
func (daemon *Daemon) UpdateService(job *engine.Job) error {
	var srv []pod.UserService

	podId := job.Args[0]
	data := job.Args[1]

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

	err = json.Unmarshal([]byte(data), &srv)
	if err != nil {
		return err
	}

	return servicediscovery.ApplyServices(vm, container, srv)
}
Esempio n. 5
0
func (daemon *Daemon) UpdateService(podId, data string) error {
	var srv []pod.UserService

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

	err = json.Unmarshal([]byte(data), &srv)
	if err != nil {
		return err
	}

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

	return nil
}