From 19467d28f6253c9100ec498de92efb6a7c97ffd9 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Thu, 14 Mar 2019 17:52:41 +0800 Subject: [PATCH 1/5] Update CSBS policy --- openstack/csbs/v1/policies/results.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openstack/csbs/v1/policies/results.go b/openstack/csbs/v1/policies/results.go index d679f0e1f..eba294f10 100644 --- a/openstack/csbs/v1/policies/results.go +++ b/openstack/csbs/v1/policies/results.go @@ -2,7 +2,6 @@ package policies import ( "encoding/json" - "strconv" "time" @@ -36,9 +35,9 @@ type ScheduledOperationResp struct { } type OperationDefinitionResp struct { - MaxBackups int `json:"-"` - RetentionDurationDays int `json:"-"` - Permanent bool `json:"-"` + 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"` } @@ -91,6 +90,7 @@ func (r *TriggerPropertiesResp) UnmarshalJSON(b []byte) error { return err } +/* // UnmarshalJSON helps to unmarshal OperationDefinitionResp fields into needed values. func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error { type tmp OperationDefinitionResp @@ -161,6 +161,7 @@ func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error { return err } +*/ // Extract will get the backup policies object from the commonResult func (r commonResult) Extract() (*BackupPolicy, error) { From 7df20771064935c9a87a17e5cfe0efa22bfb4c28 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Thu, 14 Mar 2019 18:38:15 +0800 Subject: [PATCH 2/5] Fix tests --- openstack/csbs/v1/policies/testing/fixtures.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openstack/csbs/v1/policies/testing/fixtures.go b/openstack/csbs/v1/policies/testing/fixtures.go index 50dbe2b74..e73d98cec 100644 --- a/openstack/csbs/v1/policies/testing/fixtures.go +++ b/openstack/csbs/v1/policies/testing/fixtures.go @@ -27,7 +27,7 @@ var getResponse = ` "name": "default" }, "operation_definition": { - "max_backups": "20", + "max_backups": 20, "provider_id": "fc4d5750-22e7-4798-8a46-f48f62c4c1da", "plan_id": "5af626d2-19b9-4dc4-8e95-ddba008318b3" }, @@ -110,7 +110,7 @@ var createResponse = ` "name": "default" }, "operation_definition": { - "max_backups": "20", + "max_backups": 20, "provider_id": "fc4d5750-22e7-4798-8a46-f48f62c4c1da", "plan_id": "5af626d2-19b9-4dc4-8e95-ddba008318b3" }, @@ -184,10 +184,10 @@ var updateResponse = ` } }, "operation_definition": { - "max_backups": "20", + "max_backups": 20, "provider_id": "fc4d5750-22e7-4798-8a46-f48f62c4c1da", "plan_id": "5af626d2-19b9-4dc4-8e95-ddba008318b3", - "retention_duration_days": "-1" + "retention_duration_days": -1 }, "operation_type": "backup", "id": "b70c712d-f48b-43f7-9a0f-3bab86d59149", @@ -233,7 +233,7 @@ var listResponse = ` "name": "default" }, "operation_definition": { - "max_backups": "5", + "max_backups": 5, "provider_id": "fc4d5750-22e7-4798-8a46-f48f62c4c1da", "plan_id": "4d1ce19b-d681-4e44-a87e-c44eb9bfc4c7" }, From bb848fe209c54b3e6c9f71cca5bfb4a99e611579 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Fri, 15 Mar 2019 15:42:36 +0800 Subject: [PATCH 3/5] Fix create/update response --- openstack/csbs/v1/policies/results.go | 54 +++++++++++++++++-- .../csbs/v1/policies/testing/fixtures.go | 4 +- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/openstack/csbs/v1/policies/results.go b/openstack/csbs/v1/policies/results.go index eba294f10..6cf986644 100644 --- a/openstack/csbs/v1/policies/results.go +++ b/openstack/csbs/v1/policies/results.go @@ -9,6 +9,20 @@ 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"` @@ -34,6 +48,17 @@ 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"` @@ -42,6 +67,14 @@ type OperationDefinitionResp struct { ProviderId string `json:"provider_id"` } +type CreateOperationDefinitionResp struct { + MaxBackups int `json:"-"` + RetentionDurationDays int `json:"-"` + Permanent bool `json:"-"` + PlanId string `json:"plan_id"` + ProviderId string `json:"provider_id"` +} + type TriggerResp struct { Properties TriggerPropertiesResp `json:"properties"` Name string `json:"name"` @@ -90,9 +123,8 @@ func (r *TriggerPropertiesResp) UnmarshalJSON(b []byte) error { return err } -/* // UnmarshalJSON helps to unmarshal OperationDefinitionResp fields into needed values. -func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error { +func (r *CreateOperationDefinitionResp) UnmarshalJSON(b []byte) error { type tmp OperationDefinitionResp var s struct { tmp @@ -161,7 +193,6 @@ func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error { return err } -*/ // Extract will get the backup policies object from the commonResult func (r commonResult) Extract() (*BackupPolicy, error) { @@ -173,6 +204,15 @@ 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 { @@ -214,8 +254,12 @@ type commonResult struct { golangsdk.Result } +type cuResult struct { + golangsdk.Result +} + type CreateResult struct { - commonResult + cuResult } type GetResult struct { @@ -227,7 +271,7 @@ type DeleteResult struct { } type UpdateResult struct { - commonResult + cuResult } type ListResult struct { diff --git a/openstack/csbs/v1/policies/testing/fixtures.go b/openstack/csbs/v1/policies/testing/fixtures.go index e73d98cec..a7d5d6e28 100644 --- a/openstack/csbs/v1/policies/testing/fixtures.go +++ b/openstack/csbs/v1/policies/testing/fixtures.go @@ -110,7 +110,7 @@ var createResponse = ` "name": "default" }, "operation_definition": { - "max_backups": 20, + "max_backups": "20", "provider_id": "fc4d5750-22e7-4798-8a46-f48f62c4c1da", "plan_id": "5af626d2-19b9-4dc4-8e95-ddba008318b3" }, @@ -184,7 +184,7 @@ var updateResponse = ` } }, "operation_definition": { - "max_backups": 20, + "max_backups": "20", "provider_id": "fc4d5750-22e7-4798-8a46-f48f62c4c1da", "plan_id": "5af626d2-19b9-4dc4-8e95-ddba008318b3", "retention_duration_days": -1 From 24b7816ca478f321582a2db52a0459a7802c497b Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Fri, 15 Mar 2019 16:13:45 +0800 Subject: [PATCH 4/5] Fix code issue --- openstack/csbs/v1/policies/results.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openstack/csbs/v1/policies/results.go b/openstack/csbs/v1/policies/results.go index 6cf986644..2dc83f9b9 100644 --- a/openstack/csbs/v1/policies/results.go +++ b/openstack/csbs/v1/policies/results.go @@ -2,6 +2,7 @@ package policies import ( "encoding/json" + "strconv" "time" @@ -125,7 +126,7 @@ 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 OperationDefinitionResp + type tmp CreateOperationDefinitionResp var s struct { tmp MaxBackups string `json:"max_backups"` @@ -149,7 +150,7 @@ func (r *CreateOperationDefinitionResp) UnmarshalJSON(b []byte) error { if err != nil { return err } - *r = OperationDefinitionResp(s.tmp) + *r = CreateOperationDefinitionResp(s.tmp) r.MaxBackups = s.MaxBackups r.RetentionDurationDays = s.RetentionDurationDays r.Permanent = s.Permanent @@ -159,7 +160,7 @@ func (r *CreateOperationDefinitionResp) UnmarshalJSON(b []byte) error { } } - *r = OperationDefinitionResp(s.tmp) + *r = CreateOperationDefinitionResp(s.tmp) switch s.MaxBackups { case "": From df277462b1b22ba13eb8998910ff476ce6427c26 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Fri, 15 Mar 2019 16:56:00 +0800 Subject: [PATCH 5/5] Fix format issue --- openstack/csbs/v1/policies/results.go | 22 +++++++++---------- .../csbs/v1/policies/testing/fixtures.go | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openstack/csbs/v1/policies/results.go b/openstack/csbs/v1/policies/results.go index 2dc83f9b9..af28fc6ff 100644 --- a/openstack/csbs/v1/policies/results.go +++ b/openstack/csbs/v1/policies/results.go @@ -11,17 +11,17 @@ import ( ) 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"` + 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 { diff --git a/openstack/csbs/v1/policies/testing/fixtures.go b/openstack/csbs/v1/policies/testing/fixtures.go index a7d5d6e28..8692336fe 100644 --- a/openstack/csbs/v1/policies/testing/fixtures.go +++ b/openstack/csbs/v1/policies/testing/fixtures.go @@ -187,7 +187,7 @@ var updateResponse = ` "max_backups": "20", "provider_id": "fc4d5750-22e7-4798-8a46-f48f62c4c1da", "plan_id": "5af626d2-19b9-4dc4-8e95-ddba008318b3", - "retention_duration_days": -1 + "retention_duration_days": "-1" }, "operation_type": "backup", "id": "b70c712d-f48b-43f7-9a0f-3bab86d59149",