github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/cbr/v3/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/internal/extract" 7 ) 8 9 type CreateOpts struct { 10 // Name specifies the policy name. The value consists of 1 to 64 characters 11 // and can contain only letters, digits, underscores (_), and hyphens (-). 12 Name string `json:"name"` 13 // OperationDefinition - scheduling configuration 14 OperationDefinition *PolicyODCreate `json:"operation_definition"` 15 // Enabled - whether to enable the policy, default: true 16 Enabled *bool `json:"enabled,omitempty"` 17 // OperationType - policy type 18 OperationType OperationType `json:"operation_type"` 19 // Trigger - time rule for the policy execution 20 Trigger *Trigger `json:"trigger"` 21 } 22 23 type Trigger struct { 24 Properties TriggerProperties `json:"properties"` 25 } 26 27 type TriggerProperties struct { 28 // Pattern - Scheduling policy of the scheduler. Can't be empty. 29 Pattern []string `json:"pattern"` 30 } 31 32 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Policy, error) { 33 b, err := build.RequestBody(opts, "policy") 34 if err != nil { 35 return nil, err 36 } 37 38 raw, err := client.Post(client.ServiceURL("policies"), b, nil, &golangsdk.RequestOpts{ 39 OkCodes: []int{200}, 40 }) 41 if err != nil { 42 return nil, err 43 } 44 45 var res Policy 46 err = extract.IntoStructPtr(raw.Body, &res, "policy") 47 return &res, err 48 }