diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index d922348b4c..173a66bbbc 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -1705,7 +1705,7 @@ func (self *SNetwork) validateUpdateData(ctx context.Context, userCred mcclient. if input.GuestIpMask != nil { maskLen64 := int64(*input.GuestIpMask) - if !isValidMaskLen(maskLen64) { + if !self.isManaged() && !isValidMaskLen(maskLen64) { return input, httperrors.NewInputParameterError("Invalid masklen %d", maskLen64) } masklen = int8(maskLen64) diff --git a/pkg/multicloud/nutanix/nutanix.go b/pkg/multicloud/nutanix/nutanix.go index 3d957cd52d..2c958f8b1e 100644 --- a/pkg/multicloud/nutanix/nutanix.go +++ b/pkg/multicloud/nutanix/nutanix.go @@ -118,8 +118,11 @@ func (self *SNutanixClient) getBaseDomainV0_8() string { return self._getBaseDomain(NUTANIX_VERSION_V0_8) } -func (cli *SNutanixClient) getDefaultClient() *http.Client { +func (cli *SNutanixClient) getDefaultClient(timeout time.Duration) *http.Client { client := httputils.GetDefaultClient() + if timeout > 0 { + client = httputils.GetTimeoutClient(timeout) + } proxy := func(req *http.Request) (*url.URL, error) { req.SetBasicAuth(cli.username, cli.password) if cli.cpcfg.ProxyFunc != nil { @@ -323,17 +326,43 @@ func (self *SNutanixClient) GetSubAccounts() ([]cloudprovider.SSubAccount, error } func (self *SNutanixClient) jsonRequest(method httputils.THttpMethod, url string, body jsonutils.JSONObject) (jsonutils.JSONObject, error) { - client := self.getDefaultClient() + client := self.getDefaultClient(time.Duration(0)) return _jsonRequest(client, method, url, nil, body, self.debug) } +type sNutanixError struct { + DetailedMessage string + Message string + ErrorCode struct { + Code int + HelpUrl string + } +} + +func (self *sNutanixError) Error() string { + return jsonutils.Marshal(self).String() +} + +func (self *sNutanixError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error { + if body != nil { + body.Unmarshal(self) + } + if self.ErrorCode.Code == 1202 { + return errors.Wrapf(cloudprovider.ErrNotFound, self.Error()) + } + return self +} + func _jsonRequest(cli *http.Client, method httputils.THttpMethod, url string, header http.Header, body jsonutils.JSONObject, debug bool) (jsonutils.JSONObject, error) { - _, resp, err := httputils.JSONRequest(cli, context.Background(), method, url, header, body, debug) + client := httputils.NewJsonClient(cli) + req := httputils.NewJsonRequest(method, url, nil) + ne := &sNutanixError{} + _, resp, err := client.Send(context.Background(), req, ne, debug) return resp, err } func (self *SNutanixClient) rawRequest(method httputils.THttpMethod, url string, header http.Header, body io.Reader) (jsonutils.JSONObject, error) { - client := self.getDefaultClient() + client := self.getDefaultClient(time.Hour * 5) _resp, err := _rawRequest(client, method, url, header, body, false) _, resp, err := httputils.ParseJSONResponse("", _resp, err, self.debug) return resp, err