From adb95b27df2d2bf63bb884c89c33f20b1ff810fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Sat, 29 Dec 2018 20:42:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0vendor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/cloudcommon/version/doc.go | 1 + pkg/compute/service/service.go | 2 +- pkg/util/openstack/disk.go | 14 +++++++------- pkg/util/openstack/instance.go | 22 ++++------------------ pkg/util/openstack/openstack.go | 10 +++++++--- pkg/util/openstack/shell/doc.go | 1 + pkg/util/openstack/snapshot.go | 8 ++++---- pkg/util/openstack/storagecache.go | 3 ++- pkg/util/openstack/vpc.go | 18 +++++++++--------- 9 files changed, 36 insertions(+), 43 deletions(-) create mode 100644 pkg/cloudcommon/version/doc.go create mode 100644 pkg/util/openstack/shell/doc.go diff --git a/pkg/cloudcommon/version/doc.go b/pkg/cloudcommon/version/doc.go new file mode 100644 index 0000000000..315032e76c --- /dev/null +++ b/pkg/cloudcommon/version/doc.go @@ -0,0 +1 @@ +package version // import "yunion.io/x/onecloud/pkg/cloudcommon/version" diff --git a/pkg/compute/service/service.go b/pkg/compute/service/service.go index e5158a3f4c..048f5ef7ed 100644 --- a/pkg/compute/service/service.go +++ b/pkg/compute/service/service.go @@ -4,7 +4,7 @@ import ( "os" "time" - "yunion.io/x/onecloud/pkg/compute/skus" + _ "github.com/go-sql-driver/mysql" "yunion.io/x/log" diff --git a/pkg/util/openstack/disk.go b/pkg/util/openstack/disk.go index 1dc6d9db3a..952833b0a4 100644 --- a/pkg/util/openstack/disk.go +++ b/pkg/util/openstack/disk.go @@ -73,16 +73,16 @@ type SDisk struct { Attachments []Attachment Links []Link - AvailabilityZone string - //os-vol-host-attr:host difleming@lvmdriver-1#lvmdriver-1 + AvailabilityZone string + Host string `json:"os-vol-host-attr:host"` Encrypted bool ReplicationStatus string SnapshotID string Size int UserID string - //os-vol-tenant-attr:tenant_id bab7d5c60cd041a0a36f7c4b6e1dd978 - //os-vol-mig-status-attr:migstat null, - Metadata Metadata + TenantID string `json:"os-vol-tenant-attr:tenant_id"` + Migstat string `json:"os-vol-mig-status-attr:migstat"` + Metadata Metadata Status string Description string @@ -90,8 +90,8 @@ type SDisk struct { SourceVolid string ConsistencygroupID string VolumeImageMetadata VolumeImageMetadata - //os-vol-mig-status-attr:name_id null, - Bootable bool + NameID string `json:"os-vol-mig-status-attr:name_id"` + Bootable bool //CreatedAt time.Time VolumeType string } diff --git a/pkg/util/openstack/instance.go b/pkg/util/openstack/instance.go index e65888eb8a..8afcad4d23 100644 --- a/pkg/util/openstack/instance.go +++ b/pkg/util/openstack/instance.go @@ -2,7 +2,6 @@ package openstack import ( "context" - "encoding/json" "fmt" "time" @@ -151,11 +150,7 @@ func (region *SRegion) GetInstances(zoneName string, hostName string) ([]SInstan return nil, err } instances, result := []SInstance{}, []SInstance{} - servers, err := resp.Get("servers") - if err != nil { - return nil, err - } - if err := json.Unmarshal([]byte(servers.String()), &instances); err != nil { + if err := resp.Unmarshal(&instances, "servers"); err != nil { return nil, err } for i := 0; i < len(instances); i++ { @@ -174,12 +169,8 @@ func (region *SRegion) GetInstance(instanceId string) (*SInstance, error) { if err != nil { return nil, err } - server, err := resp.Get("server") - if err != nil { - return nil, err - } instance := &SInstance{} - return instance, json.Unmarshal([]byte(server.String()), instance) + return instance, resp.Unmarshal(instance, "server") } func (instance *SInstance) GetMetadata() *jsonutils.JSONDict { @@ -242,12 +233,7 @@ func (instance *SInstance) fetchFlavor() error { return err } instance.flavor = &SFlavor{} - flavor, err := resp.Get("flavor") - if err != nil { - log.Errorf("fetch instance %s flavor error: %v", instance.Name, err) - return err - } - return json.Unmarshal([]byte(flavor.String()), instance.flavor) + return resp.Unmarshal(instance.flavor, "flavor") } func (instance *SInstance) GetInstanceType() string { @@ -367,7 +353,7 @@ func (instance *SInstance) Refresh() error { if err != nil { return err } - return json.Unmarshal([]byte(jsonutils.Marshal(new).String()), instance) + return jsonutils.Update(instance, new) } func (instance *SInstance) UpdateVM(ctx context.Context, name string) error { diff --git a/pkg/util/openstack/openstack.go b/pkg/util/openstack/openstack.go index ab0e61c041..77b4ad9779 100644 --- a/pkg/util/openstack/openstack.go +++ b/pkg/util/openstack/openstack.go @@ -1,6 +1,7 @@ package openstack import ( + "context" "fmt" "net/http" "strings" @@ -10,6 +11,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/util/httputils" ) const ( @@ -63,12 +65,14 @@ func (cli *SOpenStackClient) Request(region, service, method string, url string, if len(microversion) > 0 { header.Set("X-Openstack-Nova-API-Version", microversion) } - session := cli.client.NewSession(region, "", "internal", cli.tokenCredential, "") - return session.JSONRequest(service, "", method, url, header, body) + ctx := context.Background() + session := cli.client.NewSession(ctx, region, "", "internal", cli.tokenCredential, "") + return session.JSONRequest(service, "", httputils.THttpMethod(method), url, header, body) } func (cli *SOpenStackClient) getVersion(region string, service string) (string, string, error) { - session := cli.client.NewSession(region, "", "internal", cli.tokenCredential, "") + ctx := context.Background() + session := cli.client.NewSession(ctx, region, "", "internal", cli.tokenCredential, "") uri, err := session.GetServiceURL(service, "internal") if err != nil { return "", "", err diff --git a/pkg/util/openstack/shell/doc.go b/pkg/util/openstack/shell/doc.go new file mode 100644 index 0000000000..c8ca56136f --- /dev/null +++ b/pkg/util/openstack/shell/doc.go @@ -0,0 +1 @@ +package shell // import "yunion.io/x/onecloud/pkg/util/openstack/shell" diff --git a/pkg/util/openstack/snapshot.go b/pkg/util/openstack/snapshot.go index 15999d880c..090aa76d94 100644 --- a/pkg/util/openstack/snapshot.go +++ b/pkg/util/openstack/snapshot.go @@ -27,10 +27,10 @@ type SSnapshot struct { Status string Metadata Metadata - //os-extended-snapshot-attributes:progress 100% - Name string - UserID string - //os-extended-snapshot-attributes:project_id bab7d5c60cd041a0a36f7c4b6e1dd978 + Progress string `json:"os-extended-snapshot-attributes:progress"` + Name string + UserID string + ProjectID string `json:"os-extended-snapshot-attributes:project_id"` //CreatedAt time.Time Size int32 diff --git a/pkg/util/openstack/storagecache.go b/pkg/util/openstack/storagecache.go index 6747cab66d..65f5a03a10 100644 --- a/pkg/util/openstack/storagecache.go +++ b/pkg/util/openstack/storagecache.go @@ -1,6 +1,7 @@ package openstack import ( + "context" "fmt" "yunion.io/x/jsonutils" @@ -68,7 +69,7 @@ func (cache *SStoragecache) GetPath() string { return "" } -func (cache *SStoragecache) UploadImage(userCred mcclient.TokenCredential, imageId string, osArch, osType, osDist, osVersion string, extId string, isForce bool) (string, error) { +func (cache *SStoragecache) UploadImage(ctx context.Context, userCred mcclient.TokenCredential, imageId string, osArch, osType, osDist, osVersion string, extId string, isForce bool) (string, error) { return "", cloudprovider.ErrNotImplemented } diff --git a/pkg/util/openstack/vpc.go b/pkg/util/openstack/vpc.go index 513527affb..fccd10a52e 100644 --- a/pkg/util/openstack/vpc.go +++ b/pkg/util/openstack/vpc.go @@ -37,15 +37,15 @@ type SVpc struct { ProjectID string QosPolicyID string RevisionNumber int - //router:external bool - Shared bool - Status string - Subnets []string - TenantID string - UpdatedAt time.Time - VlanTransparent bool - Fescription string - IsDefault bool + External bool `json:"router:external"` + Shared bool + Status string + Subnets []string + TenantID string + UpdatedAt time.Time + VlanTransparent bool + Fescription string + IsDefault bool } func (vpc *SVpc) GetMetadata() *jsonutils.JSONDict {