Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions openstack/csbs/v1/policies/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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:"-"`
Expand Down Expand Up @@ -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"`
Expand All @@ -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
Expand All @@ -127,7 +160,7 @@ func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error {
}
}

*r = OperationDefinitionResp(s.tmp)
*r = CreateOperationDefinitionResp(s.tmp)

switch s.MaxBackups {
case "":
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -213,8 +255,12 @@ type commonResult struct {
golangsdk.Result
}

type cuResult struct {
golangsdk.Result
}

type CreateResult struct {
commonResult
cuResult
}

type GetResult struct {
Expand All @@ -226,7 +272,7 @@ type DeleteResult struct {
}

type UpdateResult struct {
commonResult
cuResult
}

type ListResult struct {
Expand Down
4 changes: 2 additions & 2 deletions openstack/csbs/v1/policies/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down