github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/dns/requests.go (about) 1 package dns 2 3 import ( 4 "net/url" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" 8 "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" 9 "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" 10 ) 11 12 // PortListOptsExt adds the DNS options to the base port ListOpts. 13 type PortListOptsExt struct { 14 ports.ListOptsBuilder 15 16 DNSName string `q:"dns_name"` 17 } 18 19 // ToPortListQuery adds the DNS options to the base port list options. 20 func (opts PortListOptsExt) ToPortListQuery() (string, error) { 21 q, err := gophercloud.BuildQueryString(opts.ListOptsBuilder) 22 if err != nil { 23 return "", err 24 } 25 26 params := q.Query() 27 28 if opts.DNSName != "" { 29 params.Add("dns_name", opts.DNSName) 30 } 31 32 q = &url.URL{RawQuery: params.Encode()} 33 return q.String(), err 34 } 35 36 // PortCreateOptsExt adds port DNS options to the base ports.CreateOpts. 37 type PortCreateOptsExt struct { 38 // CreateOptsBuilder is the interface options structs have to satisfy in order 39 // to be used in the main Create operation in this package. 40 ports.CreateOptsBuilder 41 42 // Set DNS name to the port 43 DNSName string `json:"dns_name,omitempty"` 44 } 45 46 // ToPortCreateMap casts a CreateOpts struct to a map. 47 func (opts PortCreateOptsExt) ToPortCreateMap() (map[string]interface{}, error) { 48 base, err := opts.CreateOptsBuilder.ToPortCreateMap() 49 if err != nil { 50 return nil, err 51 } 52 53 port := base["port"].(map[string]interface{}) 54 55 if opts.DNSName != "" { 56 port["dns_name"] = opts.DNSName 57 } 58 59 return base, nil 60 } 61 62 // PortUpdateOptsExt adds DNS options to the base ports.UpdateOpts 63 type PortUpdateOptsExt struct { 64 // UpdateOptsBuilder is the interface options structs have to satisfy in order 65 // to be used in the main Update operation in this package. 66 ports.UpdateOptsBuilder 67 68 // Set DNS name to the port 69 DNSName *string `json:"dns_name,omitempty"` 70 } 71 72 // ToPortUpdateMap casts an UpdateOpts struct to a map. 73 func (opts PortUpdateOptsExt) ToPortUpdateMap() (map[string]interface{}, error) { 74 base, err := opts.UpdateOptsBuilder.ToPortUpdateMap() 75 if err != nil { 76 return nil, err 77 } 78 79 port := base["port"].(map[string]interface{}) 80 81 if opts.DNSName != nil { 82 port["dns_name"] = *opts.DNSName 83 } 84 85 return base, nil 86 } 87 88 // FloatingIPCreateOptsExt adds floating IP DNS options to the base floatingips.CreateOpts. 89 type FloatingIPCreateOptsExt struct { 90 // CreateOptsBuilder is the interface options structs have to satisfy in order 91 // to be used in the main Create operation in this package. 92 floatingips.CreateOptsBuilder 93 94 // Set DNS name to the floating IPs 95 DNSName string `json:"dns_name,omitempty"` 96 97 // Set DNS domain to the floating IPs 98 DNSDomain string `json:"dns_domain,omitempty"` 99 } 100 101 // ToFloatingIPCreateMap casts a CreateOpts struct to a map. 102 func (opts FloatingIPCreateOptsExt) ToFloatingIPCreateMap() (map[string]interface{}, error) { 103 base, err := opts.CreateOptsBuilder.ToFloatingIPCreateMap() 104 if err != nil { 105 return nil, err 106 } 107 108 floatingip := base["floatingip"].(map[string]interface{}) 109 110 if opts.DNSName != "" { 111 floatingip["dns_name"] = opts.DNSName 112 } 113 114 if opts.DNSDomain != "" { 115 floatingip["dns_domain"] = opts.DNSDomain 116 } 117 118 return base, nil 119 } 120 121 // NetworkCreateOptsExt adds network DNS options to the base networks.CreateOpts. 122 type NetworkCreateOptsExt struct { 123 // CreateOptsBuilder is the interface options structs have to satisfy in order 124 // to be used in the main Create operation in this package. 125 networks.CreateOptsBuilder 126 127 // Set DNS domain to the network 128 DNSDomain string `json:"dns_domain,omitempty"` 129 } 130 131 // ToNetworkCreateMap casts a CreateOpts struct to a map. 132 func (opts NetworkCreateOptsExt) ToNetworkCreateMap() (map[string]interface{}, error) { 133 base, err := opts.CreateOptsBuilder.ToNetworkCreateMap() 134 if err != nil { 135 return nil, err 136 } 137 138 network := base["network"].(map[string]interface{}) 139 140 if opts.DNSDomain != "" { 141 network["dns_domain"] = opts.DNSDomain 142 } 143 144 return base, nil 145 } 146 147 // NetworkUpdateOptsExt adds network DNS options to the base networks.UpdateOpts 148 type NetworkUpdateOptsExt struct { 149 // UpdateOptsBuilder is the interface options structs have to satisfy in order 150 // to be used in the main Update operation in this package. 151 networks.UpdateOptsBuilder 152 153 // Set DNS domain to the network 154 DNSDomain *string `json:"dns_domain,omitempty"` 155 } 156 157 // ToNetworkUpdateMap casts an UpdateOpts struct to a map. 158 func (opts NetworkUpdateOptsExt) ToNetworkUpdateMap() (map[string]interface{}, error) { 159 base, err := opts.UpdateOptsBuilder.ToNetworkUpdateMap() 160 if err != nil { 161 return nil, err 162 } 163 164 network := base["network"].(map[string]interface{}) 165 166 if opts.DNSDomain != nil { 167 network["dns_domain"] = *opts.DNSDomain 168 } 169 170 return base, nil 171 }