func (this *CloudFoundryController) Post() { model := this.GetString("model") erros := make([]error, 0) switch model { case utils.CloudFoundryProperties: cloudFoundryProperties = entity.NewCloudFoundryProperties( this.GetString("name"), this.GetString("uuid"), this.GetString("floatingIp"), this.GetString("systemDomain"), this.GetString("systemDomainOrg")) id, err := this.GetInt64("id", 0) if err == nil { cloudFoundryProperties.Id = id } this.CommitData(cloudFoundryProperties) case utils.NetWorks: iaas := this.GetString("iaasVsersion") // use default MicroBOSH vip privateNetWorks = entity.NewNetWorks(this.GetString("private-name"), this.GetString("private-netWorkName"), this.GetString("private-netType"), this.GetString("private-netId"), this.GetString("private-cidr"), this.GetString("private-dns"), mi.NetWork.Vip, this.GetString("private-reservedIp"), this.GetString("private-staticIp")) //rebuild netWorksMap = make(map[string]entity.NetWorks) netWorksMap[utils.Net_Private] = privateNetWorks if iaas == defaultVersion { publicNetWorks = entity.NewNetWorks(this.GetString("public-name"), this.GetString("public-netWorkName"), this.GetString("public-netType"), this.GetString("public-netId"), this.GetString("public-cidr"), "", "", "", this.GetString("public-staticIp")) } else { publicNetWorks = entity.NewFloatingNetWork(cf.CloudFoundryProperties.FloatingIp) } netWorksMap[utils.Net_Public] = publicNetWorks compilation = cf.Compilation compilation.DefaultNetWork = privateNetWorks.Name this.CommitData(compilation) for key, _ := range resourcesPoolsMap { resourcesPoolsMap[key].DefaultNetWork = privateNetWorks.Name } this.CommitData(resourcesPoolsMap) this.CommitData(netWorksMap) case utils.Compilation: workers, _ := this.GetInt("workers", 6) if workers <= 0 { workers = 6 } compilation = entity.NewCompilation(this.GetString("instanceType"), this.GetString("availabilityZone"), workers, this.GetString("defaultNetWork")) id, err := this.GetInt64("id", 0) if err == nil { compilation.Id = id } this.CommitData(compilation) case utils.ResourcesPools: arrName := this.GetStrings("name") arrInstanceType := this.GetStrings("instanceType") arrAvailabilityZone := this.GetStrings("availabilityZone") arrDefaultNetWork := this.GetStrings("defaultNetWork") arrSize := this.GetStrings("size") resourcesPoolsMap = make([]entity.ResourcesPools, 0) for index, value := range arrName { size, _ := strconv.Atoi(arrSize[index]) if size <= 0 { size = 1 } addResourcesPool := entity.NewResourcesPools(value, arrInstanceType[index], arrAvailabilityZone[index], arrDefaultNetWork[index], size, ) if index == 0 { resourcesPool = addResourcesPool } resourcesPoolsMap = append(resourcesPoolsMap, addResourcesPool) } this.CommitData(resourcesPoolsMap) case utils.CloudFoundryJobs: iPFactory := utils.NewIPFactory() ipArr := utils.SpliteIPs(privateNetWorks.StaticIp) success, iperr := iPFactory.InitFactory(ipArr[0], ipArr[1]) if iperr != nil { erros = append(erros, iperr) } for key, value := range cloudFoundryJobsMap { value.Name = this.GetString(key + "_name") instance, _ := this.GetInt(key+"_instances", 1) if instance <= 0 { instance = 1 } value.ResourcesPool = this.GetString(key + "_resourcesPool_select") if success { assignaIP, assignaerr := iPFactory.AssignaIP2Job(key, instance) if assignaerr == nil { value.StaticIp = assignaIP value.Instances = instance } else { erros = append(erros, fmt.Errorf("Assign IP for Job : %s , Errors: %s", key, assignaerr)) } } cloudFoundryJobsMap[key] = value } this.CommitData(cloudFoundryJobsMap) for index, value := range resourcesPoolsMap { poolsize := 0 for _, v := range cloudFoundryJobsMap { if value.Name == v.ResourcesPool { poolsize = poolsize + 1*v.Instances //fixed instance sum } } value.Size = poolsize resourcesPoolsMap[index] = value } this.CommitData(resourcesPoolsMap) case utils.Properties: property := properties.JobProperties for key, val := range property { val.Name = key val.Value = this.GetString(key) property[key] = val } properties.JobProperties = property this.CommitData(properties) default: erros = append(erros, fmt.Errorf("Unknow model %s", model)) } if len(erros) != 0 { this.Data["MessageErr"] = fmt.Sprintf("Errors: %s", erros) } this.Get() }
// value.Update() // result[key] = value // } // cf.NetWorks = result // case []entity.ResourcesPools: // result, _ = entity.UpdateResourcePools(result) // cf.ResourcesPools = result // default: // this.Data["MessageErr"] = fmt.Sprintf("Unknow type %s", reflect.TypeOf(data)) // } } var ( cloudFoundryProperties = entity.NewCloudFoundryProperties("cf-release", "57cfc863-786d-4495-bb97-86d2f650a038", "192.168.133.102", "ccipaas.net", "cci") compilation = entity.NewCompilation("flavor_91", "zone2", 6, privateNetWorks.Name) privateNetWorks = entity.NewNetWorks("cf1", utils.Net_Private, "manual", "8bb21e6e-dc6a-409c-82d0-a110fb3c9fe1", "192.168.129.0/24", "10.10.170.2", "192.168.133.108", "192.168.129.1 - 192.168.129.99", "192.168.129.100 - 192.168.129.126") publicNetWorks = entity.NewNetWorks("public", utils.Net_Public,