github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/csbs/v1/policies/Create.go (about)

     1  package policies
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
     7  )
     8  
     9  // CreateOpts contains the options for create a Backup Policy. This object is passed to policies.Create().
    10  type CreateOpts struct {
    11  	// Backup policy description
    12  	// The value consists of 0 to 255 characters and must not contain a greater-than sign (>) or less-than sign (<).
    13  	Description string `json:"description,omitempty"`
    14  	// Backup policy name
    15  	// The value consists of 1 to 255 characters and can contain only letters, digits, underscores (_), and hyphens (-).
    16  	Name string `json:"name" required:"true"`
    17  	// Backup parameters
    18  	// For details, see Table 2-24.
    19  	Parameters PolicyParam `json:"parameters" required:"true"`
    20  	// Backup provider ID, which specifies whether the backup object is a server or disk.
    21  	// This parameter has a fixed value. For CSBS, the value is fc4d5750-22e7-4798-8a46-f48f62c4c1da.
    22  	ProviderId string `json:"provider_id" required:"true"`
    23  	// Backup object list. The list can be blank.
    24  	// For details, see Table 2-25.
    25  	Resources []Resource `json:"resources" required:"true"`
    26  	// Scheduling period
    27  	ScheduledOperations []ScheduledOperation `json:"scheduled_operations" required:"true"`
    28  	// Tag list
    29  	// This list cannot be an empty list.
    30  	// The list can contain up to 10 keys.
    31  	// Keys in this list must be unique.
    32  	Tags []tags.ResourceTag `json:"tags,omitempty"`
    33  }
    34  
    35  type PolicyParam struct {
    36  	// General backup policy parameters, which are blank by default
    37  	Common interface{} `json:"common,omitempty"`
    38  }
    39  
    40  type ScheduledOperation struct {
    41  	// Scheduling period description
    42  	// The value consists of 0 to 255 characters and must not contain a greater-than sign (>) or less-than sign (<).
    43  	Description string `json:"description,omitempty"`
    44  	// Whether the backup policy is enabled
    45  	// If it is set to true, automatic scheduling is enabled. If it is set to false, automatic scheduling is disabled but you can execute the policy manually.
    46  	Enabled bool `json:"enabled"`
    47  	// Whether the backup policy is enabled
    48  	// If it is set to true, automatic scheduling is enabled. If it is set to false, automatic scheduling is disabled but you can execute the policy manually.
    49  	Name string `json:"name,omitempty"`
    50  	// Operation type, which can be backup
    51  	// Enumeration values: backup
    52  	OperationType string `json:"operation_type" required:"true"`
    53  	// Scheduling period parameters
    54  	OperationDefinition OperationDefinition `json:"operation_definition" required:"true"`
    55  	// Scheduling policy
    56  	Trigger Trigger `json:"trigger" required:"true"`
    57  	// Response: Scheduling period ID
    58  	ID string `json:"id,omitempty"`
    59  	// Response: Scheduler ID
    60  	TriggerID string `json:"trigger_id,omitempty"`
    61  }
    62  
    63  type OperationDefinition struct {
    64  	// Maximum number of backups that can be automatically created for a backup object.
    65  	// The value can be -1 or ranges from 0 to 99999. If the value is set to -1,
    66  	// the backups will not be cleared even though the configured retained backup quantity limit is exceeded.
    67  	MaxBackups *int `json:"max_backups,omitempty"`
    68  	// Duration of retaining a backup, in days. The value can be -1 or ranges from 0 to 99999.
    69  	// If the value is set to -1, backups will not be cleared even though the configured retention duration is exceeded.
    70  	RetentionDurationDays int `json:"retention_duration_days,omitempty"`
    71  	// Whether backups are permanently retained. false: no. true: yes
    72  	Permanent bool `json:"permanent" required:"true"`
    73  	// Backup policy ID
    74  	PlanId string `json:"plan_id,omitempty"`
    75  	// Backup provider ID, which specifies whether the backup object is a server or disk.
    76  	// This parameter has a fixed value. For CSBS, the value is fc4d5750-22e7-4798-8a46-f48f62c4c1da.
    77  	ProviderId string `json:"provider_id,omitempty"`
    78  	// Specifies the maximum number of retained daily backups. The latest backup of each day is saved in the long term.
    79  	// This parameter can be effective together with the maximum number of retained backups specified by max_backups.
    80  	// If this parameter is configured, timezone is mandatory.
    81  	DayBackups int `json:"day_backups,omitempty"`
    82  	// Specifies the maximum number of retained weekly backups. The latest backup of each week is saved in the long term.
    83  	// This parameter can be effective together with the maximum number of retained backups specified by max_backups.
    84  	// If this parameter is configured, timezone is mandatory.
    85  	WeekBackups int `json:"week_backups,omitempty"`
    86  	// Specifies the maximum number of retained monthly backups. The latest backup of each month is saved in the long term.
    87  	// This parameter can be effective together with the maximum number of retained backups specified by max_backups.
    88  	// If this parameter is configured, timezone is mandatory.
    89  	MonthBackups int `json:"month_backups,omitempty"`
    90  	// Specifies the maximum number of retained yearly backups. The latest backup of each year is saved in the long term.
    91  	// This parameter can be effective together with the maximum number of retained backups specified by max_backups.
    92  	// If this parameter is configured, timezone is mandatory.
    93  	YearBackups int `json:"year_backups,omitempty"`
    94  	// Time zone where the user is located, for example, UTC+08:00. Set this parameter only
    95  	// after you have configured any of the parameters day_backups, week_backups, month_backups, and year_backups.
    96  	TimeZone string `json:"timezone,omitempty"`
    97  }
    98  
    99  type Trigger struct {
   100  	// Scheduler properties
   101  	Properties TriggerProperties `json:"properties" required:"true"`
   102  	// Response: Scheduler name
   103  	Name string `json:"name,omitempty"`
   104  	// Response: Scheduler ID
   105  	ID string `json:"id,omitempty"`
   106  	// Response: Scheduling type. The value is fixed at time.
   107  	Type string `json:"type,omitempty"`
   108  }
   109  
   110  type TriggerProperties struct {
   111  	// Scheduling policy of the scheduler. The value consists of a maximum of 10,240 characters.
   112  	// The scheduling policy complies with iCalendar RFC 2445, but it supports only four parameters,
   113  	// which are FREQ, BYDAY, BYHOUR, and BYMINUTE. FREQ can be set only to WEEKLY or DAILY.
   114  	// BYDAY can be set to MO, TU, WE, TH, FR, SA, or SU (seven days of a week).
   115  	// BYHOUR ranges from 0 to 23 hours. BYMINUTE ranges from 0 to 59 minutes.
   116  	// The scheduling interval cannot be less than 1 hour. A maximum of 24 time points are allowed in a day.
   117  	Pattern string `json:"pattern" required:"true"`
   118  	// Response: Scheduler start time, for example, 2017-04-18T01:21:52
   119  	StartTime string `json:"start_time,omitempty"`
   120  	// Response: Scheduler type
   121  	Format string `json:"format,omitempty"`
   122  }
   123  
   124  // Create will create a new backup policy based on the values in CreateOpts. To extract
   125  // the Backup object from the response, call the Extract method on the CreateResult.
   126  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*BackupPolicy, error) {
   127  	b, err := build.RequestBody(opts, "policy")
   128  	if err != nil {
   129  		return nil, err
   130  	}
   131  
   132  	// POST https://{endpoint}/v1/{project_id}/policies
   133  	raw, err := client.Post(client.ServiceURL("policies"), b, nil, &golangsdk.RequestOpts{
   134  		OkCodes: []int{200},
   135  	})
   136  	return extra(err, raw)
   137  }