diff --git a/openstack/csbs/v1/policies/results.go b/openstack/csbs/v1/policies/results.go index d679f0e1f..af28fc6ff 100644 --- a/openstack/csbs/v1/policies/results.go +++ b/openstack/csbs/v1/policies/results.go @@ -10,6 +10,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"` @@ -35,7 +49,26 @@ 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:"-"` @@ -92,8 +125,8 @@ func (r *TriggerPropertiesResp) UnmarshalJSON(b []byte) error { } // UnmarshalJSON helps to unmarshal OperationDefinitionResp fields into needed values. -func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error { - type tmp OperationDefinitionResp +func (r *CreateOperationDefinitionResp) UnmarshalJSON(b []byte) error { + type tmp CreateOperationDefinitionResp var s struct { tmp MaxBackups string `json:"max_backups"` @@ -117,7 +150,7 @@ func (r *OperationDefinitionResp) 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 @@ -127,7 +160,7 @@ func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error { } } - *r = OperationDefinitionResp(s.tmp) + *r = CreateOperationDefinitionResp(s.tmp) switch s.MaxBackups { case "": @@ -172,6 +205,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 { @@ -213,8 +255,12 @@ type commonResult struct { golangsdk.Result } +type cuResult struct { + golangsdk.Result +} + type CreateResult struct { - commonResult + cuResult } type GetResult struct { @@ -226,7 +272,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 50dbe2b74..8692336fe 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" }, @@ -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" },