github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/maas/v1/task/requests.go (about) 1 package task 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{ 8 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 9 } 10 11 type CreateOpts struct { 12 SrcNode SrcNodeOpts `json:"src_node" required:"true"` 13 DstNode DstNodeOpts `json:"dst_node" required:"true"` 14 EnableKMS *bool `json:"enableKMS" required:"true"` 15 ThreadNum int `json:"thread_num" required:"true"` 16 Description string `json:"description,omitempty"` 17 SmnInfo *SmnInfoOpts `json:"smnInfo,omitempty"` 18 } 19 20 type SrcNodeOpts struct { 21 Region string `json:"region" required:"true"` 22 AK string `json:"ak" required:"true"` 23 SK string `json:"sk" required:"true"` 24 ObjectKey string `json:"object_key" required:"true"` 25 Bucket string `json:"bucket" required:"true"` 26 CloudType string `json:"cloud_type,omitempty"` 27 } 28 29 type DstNodeOpts struct { 30 Region string `json:"region" required:"true"` 31 AK string `json:"ak" required:"true"` 32 SK string `json:"sk" required:"true"` 33 ObjectKey string `json:"object_key,omitempty"` 34 Bucket string `json:"bucket" required:"true"` 35 } 36 37 type SmnInfoOpts struct { 38 TopicUrn string `json:"topicUrn" required:"true"` 39 Language string `json:"language,omitempty"` 40 TriggerConditions []string `json:"triggerConditions" required:"true"` 41 } 42 43 type CreateOptsBuilder interface { 44 ToTaskCreateMap() (map[string]interface{}, error) 45 } 46 47 func (opts CreateOpts) ToTaskCreateMap() (map[string]interface{}, error) { 48 return golangsdk.BuildRequestBody(opts, "") 49 } 50 51 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 52 b, err := opts.ToTaskCreateMap() 53 if err != nil { 54 r.Err = err 55 return 56 } 57 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}, 58 MoreHeaders: RequestOpts.MoreHeaders} 59 _, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt) 60 return 61 } 62 63 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 64 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}, 65 MoreHeaders: RequestOpts.MoreHeaders} 66 _, r.Err = c.Get(resourceURL(c, id), &r.Body, reqOpt) 67 return 68 } 69 70 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 71 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}, 72 MoreHeaders: RequestOpts.MoreHeaders} 73 _, r.Err = c.Delete(resourceURL(c, id), reqOpt) 74 return 75 }