huawei: client: add SBaseManager.SetHttpClient()

This commit is contained in:
Yousong Zhou
2020-03-22 19:36:44 +08:00
parent 604b58204e
commit b59208b24e
2 changed files with 55 additions and 8 deletions
+51 -8
View File
@@ -15,6 +15,8 @@
package client
import (
"net/http"
"yunion.io/x/onecloud/pkg/multicloud/huawei/client/auth"
"yunion.io/x/onecloud/pkg/multicloud/huawei/client/auth/credentials"
"yunion.io/x/onecloud/pkg/multicloud/huawei/client/modules"
@@ -81,9 +83,55 @@ type Client struct {
CloudEye *modules.SCloudEyeManager
}
func (self *Client) Init() error {
// 从环境变量中初始化client
return nil
func (self *Client) SetHttpClient(httpClient *http.Client) {
self.Servers.SetHttpClient(httpClient)
self.ServersV2.SetHttpClient(httpClient)
self.NovaServers.SetHttpClient(httpClient)
self.Snapshots.SetHttpClient(httpClient)
self.OsSnapshots.SetHttpClient(httpClient)
self.Images.SetHttpClient(httpClient)
self.OpenStackImages.SetHttpClient(httpClient)
self.Projects.SetHttpClient(httpClient)
self.Regions.SetHttpClient(httpClient)
self.Zones.SetHttpClient(httpClient)
self.Vpcs.SetHttpClient(httpClient)
self.Eips.SetHttpClient(httpClient)
self.Elasticcache.SetHttpClient(httpClient)
self.DcsAvailableZone.SetHttpClient(httpClient)
self.Disks.SetHttpClient(httpClient)
self.Domains.SetHttpClient(httpClient)
self.Keypairs.SetHttpClient(httpClient)
self.Elb.SetHttpClient(httpClient)
self.ElbBackend.SetHttpClient(httpClient)
self.ElbBackendGroup.SetHttpClient(httpClient)
self.ElbListeners.SetHttpClient(httpClient)
self.ElbCertificates.SetHttpClient(httpClient)
self.ElbHealthCheck.SetHttpClient(httpClient)
self.ElbL7policies.SetHttpClient(httpClient)
self.ElbPolicies.SetHttpClient(httpClient)
self.ElbWhitelist.SetHttpClient(httpClient)
self.Orders.SetHttpClient(httpClient)
self.SecurityGroupRules.SetHttpClient(httpClient)
self.SecurityGroups.SetHttpClient(httpClient)
self.NovaSecurityGroups.SetHttpClient(httpClient)
self.Subnets.SetHttpClient(httpClient)
self.Users.SetHttpClient(httpClient)
self.Interface.SetHttpClient(httpClient)
self.Jobs.SetHttpClient(httpClient)
self.Balances.SetHttpClient(httpClient)
self.Bandwidths.SetHttpClient(httpClient)
self.Port.SetHttpClient(httpClient)
self.Flavors.SetHttpClient(httpClient)
self.VpcRoutes.SetHttpClient(httpClient)
self.SNatRules.SetHttpClient(httpClient)
self.DNatRules.SetHttpClient(httpClient)
self.NatGateways.SetHttpClient(httpClient)
self.DBInstance.SetHttpClient(httpClient)
self.DBInstanceBackup.SetHttpClient(httpClient)
self.DBInstanceFlavor.SetHttpClient(httpClient)
self.DBInstanceJob.SetHttpClient(httpClient)
self.Traces.SetHttpClient(httpClient)
self.CloudEye.SetHttpClient(httpClient)
}
func (self *Client) InitWithOptions(regionId, projectId string, credential auth.Credential) error {
@@ -167,11 +215,6 @@ func (self *Client) initManagers() {
self.init = true
}
// todo: init from envrioment
func NewClient() (*Client, error) {
return nil, nil
}
func NewClientWithAccessKey(regionId, projectId, accessKey, secretKey string, debug bool) (*Client, error) {
c := &Client{debug: debug}
err := c.InitWithAccessKey(regionId, projectId, accessKey, secretKey)
@@ -62,6 +62,10 @@ func (self *SBaseManager) GetColumns() []string {
return self.columns
}
func (self *SBaseManager) SetHttpClient(httpClient *http.Client) {
self.httpClient = httpClient
}
func (self *SBaseManager) _list(request requests.IRequest, responseKey string) (*responses.ListResult, error) {
_, body, err := self.jsonRequest(request)
if err != nil {