From c3f9424aeea62b04ca303d84022a8264c4bea150 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Wed, 10 Jul 2019 14:45:27 +0800 Subject: [PATCH] Make CSBS policy to be compatible with multi type of responses --- openstack/csbs/v1/policies/results.go | 58 +++------------------------ 1 file changed, 6 insertions(+), 52 deletions(-) diff --git a/openstack/csbs/v1/policies/results.go b/openstack/csbs/v1/policies/results.go index af28fc6ff..d679f0e1f 100644 --- a/openstack/csbs/v1/policies/results.go +++ b/openstack/csbs/v1/policies/results.go @@ -10,20 +10,6 @@ import ( "github.com/huaweicloud/golangsdk/pagination" ) -type CreateBackupPolicy struct { - CreatedAt time.Time `json:"-"` - Description string `json:"description"` - ID string `json:"id"` - Name string `json:"name"` - Parameters PolicyParam `json:"parameters"` - ProjectId string `json:"project_id"` - ProviderId string `json:"provider_id"` - Resources []Resource `json:"resources"` - ScheduledOperations []CreateScheduledOperationResp `json:"scheduled_operations"` - Status string `json:"status"` - Tags []ResourceTag `json:"tags"` -} - type BackupPolicy struct { CreatedAt time.Time `json:"-"` Description string `json:"description"` @@ -49,26 +35,7 @@ type ScheduledOperationResp struct { TriggerID string `json:"trigger_id"` } -type CreateScheduledOperationResp struct { - Description string `json:"description"` - Enabled bool `json:"enabled"` - Name string `json:"name"` - OperationType string `json:"operation_type"` - OperationDefinition CreateOperationDefinitionResp `json:"operation_definition"` - Trigger TriggerResp `json:"trigger"` - ID string `json:"id"` - TriggerID string `json:"trigger_id"` -} - type OperationDefinitionResp struct { - MaxBackups int `json:"max_backups"` - RetentionDurationDays int `json:"retention_duration_days"` - Permanent bool `json:"permanent"` - PlanId string `json:"plan_id"` - ProviderId string `json:"provider_id"` -} - -type CreateOperationDefinitionResp struct { MaxBackups int `json:"-"` RetentionDurationDays int `json:"-"` Permanent bool `json:"-"` @@ -125,8 +92,8 @@ func (r *TriggerPropertiesResp) UnmarshalJSON(b []byte) error { } // UnmarshalJSON helps to unmarshal OperationDefinitionResp fields into needed values. -func (r *CreateOperationDefinitionResp) UnmarshalJSON(b []byte) error { - type tmp CreateOperationDefinitionResp +func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error { + type tmp OperationDefinitionResp var s struct { tmp MaxBackups string `json:"max_backups"` @@ -150,7 +117,7 @@ func (r *CreateOperationDefinitionResp) UnmarshalJSON(b []byte) error { if err != nil { return err } - *r = CreateOperationDefinitionResp(s.tmp) + *r = OperationDefinitionResp(s.tmp) r.MaxBackups = s.MaxBackups r.RetentionDurationDays = s.RetentionDurationDays r.Permanent = s.Permanent @@ -160,7 +127,7 @@ func (r *CreateOperationDefinitionResp) UnmarshalJSON(b []byte) error { } } - *r = CreateOperationDefinitionResp(s.tmp) + *r = OperationDefinitionResp(s.tmp) switch s.MaxBackups { case "": @@ -205,15 +172,6 @@ func (r commonResult) Extract() (*BackupPolicy, error) { return s.BackupPolicy, err } -func (r cuResult) Extract() (*CreateBackupPolicy, error) { - var s struct { - BackupPolicy *CreateBackupPolicy `json:"policy"` - } - - err := r.ExtractInto(&s) - return s.BackupPolicy, err -} - // BackupPolicyPage is the page returned by a pager when traversing over a // collection of backup policies. type BackupPolicyPage struct { @@ -255,12 +213,8 @@ type commonResult struct { golangsdk.Result } -type cuResult struct { - golangsdk.Result -} - type CreateResult struct { - cuResult + commonResult } type GetResult struct { @@ -272,7 +226,7 @@ type DeleteResult struct { } type UpdateResult struct { - cuResult + commonResult } type ListResult struct {