github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dws/cluster/requests.go (about) 1 package cluster 2 3 import ( 4 "log" 5 6 "github.com/huaweicloud/golangsdk" 7 ) 8 9 type PublicIpOpts struct { 10 EipID string `json:"eip_id,omitempty"` 11 PublicBindType string `json:"public_bind_type,omitempty"` 12 } 13 14 type CreateOpts struct { 15 Name string `json:"name" required:"true"` 16 NumberOfNode int `json:"number_of_node" required:"true"` 17 AvailabilityZone string `json:"availability_zone,omitempty"` 18 SubnetID string `json:"subnet_id" required:"true"` 19 UserPwd string `json:"user_pwd" required:"true"` 20 SecurityGroupID string `json:"security_group_id" required:"true"` 21 PublicIp *PublicIpOpts `json:"public_ip,omitempty"` 22 NodeType string `json:"node_type" required:"true"` 23 VpcID string `json:"vpc_id" required:"true"` 24 UserName string `json:"user_name" required:"true"` 25 Port int `json:"port,omitempty"` 26 } 27 28 type CreateOptsBuilder interface { 29 ToClusterCreateMap() (map[string]interface{}, error) 30 } 31 32 func (opts CreateOpts) ToClusterCreateMap() (map[string]interface{}, error) { 33 return golangsdk.BuildRequestBody(opts, "cluster") 34 } 35 36 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 37 b, err := opts.ToClusterCreateMap() 38 if err != nil { 39 r.Err = err 40 return 41 } 42 log.Printf("[DEBUG] create url:%q, body=%#v", createURL(c), b) 43 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 44 _, r.Err = c.Post(createURL(c), b, &r.Body, reqOpt) 45 return 46 } 47 48 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 49 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 50 return 51 } 52 53 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 54 reqOpt := &golangsdk.RequestOpts{ 55 OkCodes: []int{202}, 56 JSONBody: map[string]interface{}{ 57 "keep_last_manual_snapshot": 0, 58 }, 59 } 60 _, r.Err = c.Delete(resourceURL(c, id), reqOpt) 61 return 62 }