Skip to content

Commit

Permalink
fix host import
Browse files Browse the repository at this point in the history
  • Loading branch information
tangbin committed Jul 22, 2020
1 parent ce9646f commit 2794c84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 19 additions & 7 deletions pkg/apigateway/handler/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func (mh *MiscHandler) DoBatchHostRegister(ctx context.Context, w http.ResponseW
}

paramKeys := []string{}
i1 := 0
i2 := 0
i1 := -1
i2 := -1
for i, title := range rows[0] {
switch title {
case HOST_MAC:
Expand Down Expand Up @@ -209,17 +209,29 @@ func (mh *MiscHandler) DoBatchHostRegister(ctx context.Context, w http.ResponseW
hosts := bytes.Buffer{}
for _, row := range rows[1:] {
var e *httputils.JSONClientError
if row[i1] == row[i2] || utils.IsInStringArray(row[i1], ips) {
e = httperrors.NewDuplicateIdError("ip", row[i1])
} else if utils.IsInStringArray(row[i2], ips) {
e = httperrors.NewDuplicateIdError("ip", row[i2])
if i1 >= 0 && len(row[i1]) > 0 {
i1Ip := fmt.Sprintf("%d-%s", i1, row[i1])
if utils.IsInStringArray(i1Ip, ips) {
e = httperrors.NewDuplicateIdError("ip", row[i1])
} else {
ips = append(ips, i1Ip)
}
}

if i2 >= 0 && len(row[i2]) > 0 {
i2Ip := fmt.Sprintf("%d-%s", i2, row[i2])
if utils.IsInStringArray(i2Ip, ips) {
e = httperrors.NewDuplicateIdError("ip", row[i2])
} else {
ips = append(ips, i2Ip)
}
}

if e != nil {
httperrors.JsonClientError(w, e)
return
} else {
ips = append(ips, row[i1], row[i2])

}

hosts.WriteString(strings.Join(row, ",") + "\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ func NewElbHealthCheckManager(regionId string, projectId string, signer auth.Sig
}

func (self *SElbHealthCheckManager) Delete(id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
return self.DeleteInContextWithSpec(self.ctx, id, "",nil, params, "")
}
return self.DeleteInContextWithSpec(self.ctx, id, "", nil, params, "")
}

0 comments on commit 2794c84

Please sign in to comment.