示例#1
0
func createServicePorts() {
	service := "pippo"
	port1 := "50100"
	port2 := "50200"
	portRange1, _ := utils.GetCompleteRange("50100-50103")
	portRange2, _ := utils.GetCompleteRange("50200-50201")
	status1 := PortStatus{
		Available: portRange1,
	}
	status2 := PortStatus{
		Available: portRange2,
	}
	portStatus := map[string]PortStatus{
		port1: status1,
		port2: status2,
	}
	servicePorts := Ports{
		Status:        portStatus,
		LastAssigned:  make(map[string][]string),
		LastRequested: make(map[string]string),
	}
	resources.Network.ServicePorts[service] = servicePorts

}
示例#2
0
func InitializeServiceAvailablePorts(name string, ports map[string]string) {
	defer runtime.Gosched()
	mutex_port.Lock()

	servicePorts := resources.Network.ServicePorts[name]

	for guest, host := range ports {
		servicePorts.LastAssigned = make(map[string][]string)
		servicePorts.Status = make(map[string]PortStatus)

		hostRange, err := utils.GetCompleteRange(host)
		if err != nil {
			log.WithFields(log.Fields{
				"err":     err,
				"service": name,
				"guest":   guest,
				"host":    host,
			}).Warnln("Cannot compute host port range for guest port")
		}

		status := PortStatus{
			Available: hostRange,
			Occupied:  []string{},
		}

		servicePorts.Status[guest] = status
	}
	resources.Network.ServicePorts[name] = servicePorts

	mutex_port.Unlock()

	log.WithFields(log.Fields{
		"service": name,
		"ports":   ports,
	}).Debugln("Initialed service ports")
}