github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/autoscaling/v1/lifecyclehooks/requests.go (about) 1 package lifecyclehooks 2 3 import "github.com/huaweicloud/golangsdk" 4 5 // CreateOpts is a struct which will be used to create a lifecycle hook. 6 type CreateOpts struct { 7 // The lifecycle hook name. 8 // The name contains only letters, digits, underscores (_), and hyphens (-), and cannot exceed 32 characters. 9 Name string `json:"lifecycle_hook_name" required:"true"` 10 // The lifecycle hook type. 11 // INSTANCE_TERMINATING: The hook suspends the instance when the instance is terminated. 12 // INSTANCE_LAUNCHING: The hook suspends the instance when the instance is started. 13 Type string `json:"lifecycle_hook_type" required:"true"` 14 // The default lifecycle hook callback operation: ABANDON and CONTINUE. 15 // By default, this operation is performed when the timeout duration expires. 16 DefaultResult string `json:"default_result,omitempty"` 17 // The lifecycle hook timeout duration, which ranges from 300 to 86400 in the unit of second. 18 // The default value is 3600. 19 Timeout int `json:"default_timeout,omitempty"` 20 // The unique topic in SMN. 21 // This parameter specifies a notification object for a lifecycle hook. 22 NotificationTopicURN string `json:"notification_topic_urn" required:"true"` 23 // The customized notification, which contains no more than 256 characters in length. 24 // The message cannot contain the following characters: <>&'(). 25 NotificationMetadata string `json:"notification_metadata,omitempty"` 26 } 27 28 // CreateOptsBuilder is an interface by which can serialize the create parameters. 29 type CreateOptsBuilder interface { 30 ToLifecycleHookCreateMap() (map[string]interface{}, error) 31 } 32 33 func (opts CreateOpts) ToLifecycleHookCreateMap() (map[string]interface{}, error) { 34 return golangsdk.BuildRequestBody(opts, "") 35 } 36 37 // Create is a method which can be able to access to create the hook of autoscaling service. 38 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder, groupID string) (r CreateResult) { 39 b, err := opts.ToLifecycleHookCreateMap() 40 if err != nil { 41 r.Err = err 42 return 43 } 44 45 _, r.Err = client.Post(rootURL(client, groupID), b, &r.Body, &golangsdk.RequestOpts{ 46 OkCodes: []int{200}, 47 }) 48 return 49 } 50 51 // Get is a method to obtains the hook detail of autoscaling service. 52 func Get(client *golangsdk.ServiceClient, groupID, hookName string) (r GetResult) { 53 _, r.Err = client.Get(resourceURL(client, groupID, hookName), &r.Body, nil) 54 return 55 } 56 57 // List is a method to obtains a hook array of the autoscaling service. 58 func List(client *golangsdk.ServiceClient, groupID string) (r ListResult) { 59 _, r.Err = client.Get(listURL(client, groupID), &r.Body, nil) 60 return 61 } 62 63 // UpdateOpts is a struct which will be used to update the existing hook. 64 type UpdateOpts struct { 65 // The lifecycle hook type 66 Type string `json:"lifecycle_hook_type,omitempty"` 67 // The default lifecycle hook callback operation: ABANDON and CONTINUE. 68 // By default, this operation is performed when the timeout duration expires. 69 DefaultResult string `json:"default_result,omitempty"` 70 // The lifecycle hook timeout duration, which ranges from 300 to 86400 in the unit of second. 71 // The default value is 3600. 72 Timeout int `json:"default_timeout,omitempty"` 73 // The unique topic in SMN. 74 // This parameter specifies a notification object for a lifecycle hook. 75 NotificationTopicURN string `json:"notification_topic_urn,omitempty"` 76 // The customized notification, which contains no more than 256 characters in length. 77 // The message cannot contain the following characters: <>&'(). 78 NotificationMetadata string `json:"notification_metadata,omitempty"` 79 } 80 81 // CreateOptsBuilder is an interface by which can serialize the create parameters 82 type UpdateOptsBuilder interface { 83 ToLifecycleHookUpdateMap() (map[string]interface{}, error) 84 } 85 86 func (opts UpdateOpts) ToLifecycleHookUpdateMap() (map[string]interface{}, error) { 87 return golangsdk.BuildRequestBody(opts, "") 88 } 89 90 // Update is a method which can be able to access to udpate the existing hook of the autoscaling service. 91 func Update(client *golangsdk.ServiceClient, opts UpdateOptsBuilder, groupID, hookName string) (r UpdateResult) { 92 b, err := opts.ToLifecycleHookUpdateMap() 93 if err != nil { 94 r.Err = err 95 return 96 } 97 98 _, r.Err = client.Put(resourceURL(client, groupID, hookName), b, &r.Body, &golangsdk.RequestOpts{ 99 OkCodes: []int{200}, 100 }) 101 return 102 } 103 104 //Delete is a method which can be able to access to delete the existing hook of the autoscaling service. 105 func Delete(client *golangsdk.ServiceClient, groupID, hookName string) (r DeleteResult) { 106 _, r.Err = client.Delete(resourceURL(client, groupID, hookName), nil) 107 return 108 }