diff --git a/src/bosh-alicloud-cpi/action/create_vm.go b/src/bosh-alicloud-cpi/action/create_vm.go index 2bb42e00..c5b9707d 100755 --- a/src/bosh-alicloud-cpi/action/create_vm.go +++ b/src/bosh-alicloud-cpi/action/create_vm.go @@ -42,11 +42,11 @@ type InstanceProps struct { AvailabilityZone string `json:"availability_zone"` InstanceName string `json:"instance_name"` InstanceType string `json:"instance_type"` - SlbServerGroupWeight int `json:"slb_server_group_weight"` - SlbServerGroupPort int `json:"slb_server_group_port"` + SlbServerGroupWeight json.Number `json:"slb_server_group_weight"` + SlbServerGroupPort json.Number `json:"slb_server_group_port"` SlbServerGroup []string `json:"slb_server_group"` Slbs []string `json:"slbs"` - SlbWeight int `json:"slb_weight"` + SlbWeight json.Number `json:"slb_weight"` Password string `json:"password"` KeyPairName string `json:"key_pair_name"` SecurityGroupIds []string `json:"security_group_ids"` @@ -357,16 +357,34 @@ func (a CreateVMMethod) updateInstance(instCid string, associatedDiskCIDs []apiv return bosherr.WrapErrorf(err, "bind eip %s to %s failed", eip, instCid) } } + slbWeight, err := instProps.SlbWeight.Int64() + if err != nil { + slbWeight = alicloud.DefaultSlbWeight + } else if slbWeight == 0 { + slbWeight = alicloud.DefaultSlbWeight + } for _, slb := range instProps.Slbs { - err := a.networks.BindSLB(instProps.Region, instCid, slb, instProps.SlbWeight) + err := a.networks.BindSLB(instProps.Region, instCid, slb, int(slbWeight)) if err != nil { return bosherr.WrapErrorf(err, "bind %s to slb %s failed ", instCid, slb) } } + slbServerGroupPort, err := instProps.SlbServerGroupPort.Int64() + if err != nil { + slbServerGroupPort = alicloud.DefaultSlbServerGroupPort + } else if slbServerGroupPort == 0 { + slbServerGroupPort = alicloud.DefaultSlbServerGroupPort + } + slbServerGroupWeight, err := instProps.SlbServerGroupWeight.Int64() + if err != nil { + slbServerGroupWeight = alicloud.DefaultSlbServerGroupWeight + } else if slbServerGroupWeight == 0 { + slbServerGroupWeight = alicloud.DefaultSlbServerGroupWeight + } for _, slbServerGroup := range instProps.SlbServerGroup { - err := a.networks.BindSlbServerGroup(instProps.Region, instCid, slbServerGroup, instProps.SlbServerGroupWeight, instProps.SlbServerGroupPort) + err := a.networks.BindSlbServerGroup(instProps.Region, instCid, slbServerGroup, int(slbServerGroupWeight), int(slbServerGroupPort)) if err != nil { - return bosherr.WrapErrorf(err, "bind %s to slbServerGroup %s failed,weight:%d,port:%d ", instCid, slbServerGroup, instProps.SlbServerGroupWeight, instProps.SlbServerGroupPort) + return bosherr.WrapErrorf(err, "bind %s to slbServerGroup %s failed,weight:%d,port:%d ", instCid, slbServerGroup, slbServerGroupWeight, slbServerGroupPort) } } return nil diff --git a/src/bosh-alicloud-cpi/alicloud/config.go b/src/bosh-alicloud-cpi/alicloud/config.go index 0598bdc5..75c73005 100644 --- a/src/bosh-alicloud-cpi/alicloud/config.go +++ b/src/bosh-alicloud-cpi/alicloud/config.go @@ -48,9 +48,12 @@ const ( WaitTimeout = time.Duration(600) * time.Second WaitInterval = time.Duration(5) * time.Second - DefaultEipWaitSeconds = 120 - BoshCPI = "Bosh-Alicloud-Cpi" - BoshCPIVersion = "1.0" + DefaultEipWaitSeconds = 120 + DefaultSlbWeight = 100 + BoshCPI = "Bosh-Alicloud-Cpi" + BoshCPIVersion = "1.0" + DefaultSlbServerGroupPort = 33333 + DefaultSlbServerGroupWeight = 100 ) type OpenApi struct { diff --git a/src/bosh-alicloud-cpi/alicloud/network_manager.go b/src/bosh-alicloud-cpi/alicloud/network_manager.go index e2cfd530..62ee0d8d 100644 --- a/src/bosh-alicloud-cpi/alicloud/network_manager.go +++ b/src/bosh-alicloud-cpi/alicloud/network_manager.go @@ -150,6 +150,9 @@ func (a NetworkManagerImpl) BindSlbServerGroup(region, instanceId string, slbSer if err != nil { return err } + if weight == 0 { + weight = DefaultSlbServerGroupWeight + } bytes, _ := json.Marshal([]SlbServerGroupBackendServerType{ {ServerId: instanceId, Weight: weight, Port: port}, }) @@ -173,7 +176,9 @@ func (a NetworkManagerImpl) BindSLB(region, instanceId string, slbId string, wei if err != nil { return err } - + if weight == 0 { + weight = DefaultSlbWeight + } bytes, _ := json.Marshal([]BackendServerType{ {ServerId: instanceId, Weight: weight}, }) diff --git a/src/bosh-alicloud-cpi/integration/config.go b/src/bosh-alicloud-cpi/integration/config.go index 41244669..95c9664f 100644 --- a/src/bosh-alicloud-cpi/integration/config.go +++ b/src/bosh-alicloud-cpi/integration/config.go @@ -27,18 +27,15 @@ var ( imageOssBucket = envOrDefault("CPI_STEMCELL_OSS_BUCKET", "") imageOssObject = envOrDefault("CPI_STEMCELL_OSS_OBJECT", "") - securityGroupId = os.Getenv("CPI_SECURITY_GROUP_ID") - vswitchId = os.Getenv("CPI_VSWITCH_ID") - internalIp = envOrDefault("CPI_INTERNAL_IP", "172.16.0.31") - internalCidr = envOrDefault("CPI_INTERNAL_CIDR", "172.16.0.0/24") - internalNetmask = envOrDefault("CPI_INTERNAL_NETMASK", "255.240.0.0") - internalGw = envOrDefault("CPI_INTERNAL_GW", "172.16.0.1") - slbId = envOrDefault("CPI_SLB_ID", "") - slbWeight = envOrDefault("CPI_SLB_WEIGHT", "100") - slbServerGroupId = envOrDefault("CPI_SLB_SERVER_GROUP_ID", "") - slbServerGroupPort = envOrDefault("CPI_SLB_SERVER_GROUP_PORT", "33333") - slbServerGroupWeight = envOrDefault("CPI_SLB_SERVER_GROUP_WEIGHT", "100") - externalIp = envOrDefault("CPI_EXTERNAL_IP", "") + securityGroupId = os.Getenv("CPI_SECURITY_GROUP_ID") + vswitchId = os.Getenv("CPI_VSWITCH_ID") + internalIp = envOrDefault("CPI_INTERNAL_IP", "172.16.0.31") + internalCidr = envOrDefault("CPI_INTERNAL_CIDR", "172.16.0.0/24") + internalNetmask = envOrDefault("CPI_INTERNAL_NETMASK", "255.240.0.0") + internalGw = envOrDefault("CPI_INTERNAL_GW", "172.16.0.1") + slbId = envOrDefault("CPI_SLB_ID", "") + slbServerGroupId = envOrDefault("CPI_SLB_SERVER_GROUP_ID", "") + externalIp = envOrDefault("CPI_EXTERNAL_IP", "") // spot spotStrategy = envOrDefault("CPI_SPOT_STRATEGY", "SpotWithPriceLimit") diff --git a/src/bosh-alicloud-cpi/integration/vm_test.go b/src/bosh-alicloud-cpi/integration/vm_test.go index 00a07094..cfd334d9 100644 --- a/src/bosh-alicloud-cpi/integration/vm_test.go +++ b/src/bosh-alicloud-cpi/integration/vm_test.go @@ -95,8 +95,6 @@ var _ = Describe("integration:vm", func() { "instance_name": "bosh-test-cpi-integration", "instance_type": "ecs.n4.small", "slb_server_group": ["${SLB_SERVER_GROUP_ID}"], - "slb_server_group_port": ${SLB_SERVER_GROUP_PORT}, - "slb_server_group_weight": ${SLB_SERVER_GROUP_WEIGHT}, "system_disk": { "size": "61_440", "category": "cloud_efficiency" @@ -134,8 +132,6 @@ var _ = Describe("integration:vm", func() { P("INTERNAL_NETMASK", internalNetmask). P("INTERNAL_GW", internalGw). P("SLB_SERVER_GROUP_ID", slbServerGroupId). - P("SLB_SERVER_GROUP_PORT", slbServerGroupPort). - P("SLB_SERVER_GROUP_WEIGHT", slbServerGroupWeight). ToBytes() r := caller.Run(in) @@ -240,7 +236,6 @@ var _ = Describe("integration:vm", func() { "instance_name": "bosh-test-cpi-integration", "instance_type": "ecs.n4.small", "slbs": ["${SLB_ID}"], - "slb_weight": ${SLB_WEIGHT}, "system_disk": { "size": "61_440", "category": "cloud_efficiency" @@ -278,7 +273,6 @@ var _ = Describe("integration:vm", func() { P("INTERNAL_NETMASK", internalNetmask). P("INTERNAL_GW", internalGw). P("SLB_ID", slbId). - P("SLB_WEIGHT", slbWeight). ToBytes() r := caller.Run(in)