Initial version

Extracted from paultyng/terraform-provider-unifi@ef25893f14
This commit is contained in:
Paul Tyng
2020-01-10 14:31:12 -05:00
commit 435ecf9d6f
135 changed files with 6973 additions and 0 deletions

57
unifi/network.go Normal file
View File

@@ -0,0 +1,57 @@
package unifi
import (
"encoding/json"
"fmt"
)
func (n *Network) UnmarshalJSON(b []byte) error {
type Alias Network
aux := &struct {
VLAN json.Number `json:"vlan"`
*Alias
}{
Alias: (*Alias)(n),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return err
}
n.VLAN = 0
if aux.VLAN.String() != "" {
vlan, err := aux.VLAN.Int64()
if err != nil {
return err
}
n.VLAN = int(vlan)
}
return nil
}
func (c *Client) DeleteNetwork(site, id, name string) error {
err := c.do("DELETE", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), struct {
Name string `json:"name"`
}{
Name: name,
}, nil)
if err != nil {
return err
}
return nil
}
func (c *Client) ListNetwork(site string) ([]Network, error) {
return c.listNetwork(site)
}
func (c *Client) GetNetwork(site, id string) (*Network, error) {
return c.getNetwork(site, id)
}
func (c *Client) CreateNetwork(site string, d *Network) (*Network, error) {
return c.createNetwork(site, d)
}
func (c *Client) UpdateNetwork(site string, d *Network) (*Network, error) {
return c.updateNetwork(site, d)
}