github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dcs/v2/whitelists/Put.go (about) 1 package whitelists 2 3 import ( 4 "strings" 5 6 "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 8 ) 9 10 // WhitelistOpts is a struct that contains all the parameters. 11 type WhitelistOpts struct { 12 // enable or disable the whitelists 13 Enable *bool `json:"enable_whitelist" required:"true"` 14 // list of whitelist groups 15 Groups []WhitelistGroupOpts `json:"whitelist" required:"true"` 16 } 17 18 // WhitelistGroupOpts is a struct that contains all the whitelist parameters. 19 type WhitelistGroupOpts struct { 20 // the group name 21 GroupName string `json:"group_name" required:"true"` 22 // list of IP address or range 23 IPList []string `json:"ip_list" required:"true"` 24 } 25 26 // Put an instance whitelist with given parameters. 27 func Put(client *golangsdk.ServiceClient, id string, opts WhitelistOpts) (err error) { 28 b, err := build.RequestBody(opts, "") 29 if err != nil { 30 return 31 } 32 33 url := client.ServiceURL("instance", id, "whitelist") 34 _, err = client.Put(strings.Replace(url, "v1.0", "v2", 1), b, nil, &golangsdk.RequestOpts{ 35 OkCodes: []int{204}, 36 }) 37 return 38 }