Skip to content

Commit

Permalink
Modify the data type and restore the default value
Browse files Browse the repository at this point in the history
  • Loading branch information
chushenmeshile committed Jan 5, 2021
1 parent eafa814 commit 8750c4a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
31 changes: 25 additions & 6 deletions src/bosh-alicloud-cpi/action/create_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bosh-alicloud-cpi/registry"
"encoding/json"
"fmt"
"strconv"
"strings"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
Expand Down Expand Up @@ -42,11 +43,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 string `json:"slb_server_group_weight"`
SlbServerGroupPort string `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"`
Expand Down Expand Up @@ -357,16 +358,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 := strconv.Atoi(instProps.SlbServerGroupPort)
if err != nil {
slbServerGroupPort = alicloud.DefaultSlbServerGroupProt
} else if slbServerGroupPort == 0 {
slbServerGroupPort = alicloud.DefaultSlbServerGroupProt
}
slbServerGroupWeight, err := strconv.Atoi(instProps.SlbServerGroupWeight)
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, slbServerGroupWeight, 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
Expand Down
9 changes: 6 additions & 3 deletions src/bosh-alicloud-cpi/alicloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
DefaultSlbServerGroupProt = 33333
DefaultSlbServerGroupWeight = 100
)

type OpenApi struct {
Expand Down
7 changes: 6 additions & 1 deletion src/bosh-alicloud-cpi/alicloud/network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
})
Expand All @@ -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},
})
Expand Down
21 changes: 9 additions & 12 deletions src/bosh-alicloud-cpi/integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 0 additions & 6 deletions src/bosh-alicloud-cpi/integration/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8750c4a

Please sign in to comment.