func (p *Resource) ProviderGetHandler(req *restful.Request, resp *restful.Response) { logrus.Infof("ProviderGetHandler is called!") x_auth_token := req.HeaderParameter("X-Auth-Token") objectId := req.PathParameter(ParamID) // cluster, code, err := services.GetClusterService().QueryById(objectId, x_auth_token) provider, errorCode, err := services.GetProviderService().QueryById(objectId, x_auth_token) if err != nil { response.WriteStatusError(errorCode, err, resp) return } logrus.Debugf("provider is %v", provider) res := response.QueryStruct{Success: true, Data: provider} resp.WriteEntity(res) return }
func (p *Resource) ProviderCreateHandler(req *restful.Request, resp *restful.Response) { logrus.Infof("ProviderCreateHandler is called!") x_auth_token := req.HeaderParameter("X-Auth-Token") // Stub an acluster to be populated from the body provider := entity.IaaSProvider{} err := json.NewDecoder(req.Request.Body).Decode(&provider) if err != nil { logrus.Errorf("convert body to provider failed, error is %v", err) response.WriteStatusError(services.COMMON_ERROR_INVALIDATE, err, resp) return } newProvider, code, err := services.GetProviderService().Create(provider, x_auth_token) if err != nil { response.WriteStatusError(code, err, resp) return } res := response.QueryStruct{Success: true, Data: newProvider} resp.WriteEntity(res) return }