-
Notifications
You must be signed in to change notification settings - Fork 4
/
dhcp_server.go
129 lines (114 loc) · 3.42 KB
/
dhcp_server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// (C) Copyright 2022 Hewlett Packard Enterprise Development LP
package client
import (
"context"
"encoding/json"
"fmt"
consts "github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/common"
"github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/models"
)
const dhcpCompatibleVersion = "5.2.13"
type DhcpServerAPIService struct {
Client APIClientHandler
Cfg Configuration
}
func (lb *DhcpServerAPIService) CreateDhcpServer(
ctx context.Context,
serverID int,
request models.CreateNetworkDhcpServerRequest,
) (models.CreateNetworkDhcpServerResp, error) {
dhcpServerResp := models.CreateNetworkDhcpServerResp{}
dhcpServerAPI := &api{
compatibleVersion: dhcpCompatibleVersion,
method: "POST",
path: fmt.Sprintf("%s/%s/%d/%s",
consts.NetworksPath, consts.ServerPath,
serverID, consts.DhcpServerPath),
client: lb.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &dhcpServerResp)
},
}
err := dhcpServerAPI.do(ctx, request, nil)
return dhcpServerResp, err
}
func (lb *DhcpServerAPIService) UpdateDhcpServer(
ctx context.Context,
serverID int,
dhcpID int,
request models.CreateNetworkDhcpServerRequest,
) (models.CreateNetworkDhcpServerResp, error) {
dhcpServerResp := models.CreateNetworkDhcpServerResp{}
dhcpServerAPI := &api{
compatibleVersion: dhcpCompatibleVersion,
method: "PUT",
path: fmt.Sprintf("%s/%s/%d/%s/%d",
consts.NetworksPath, consts.ServerPath,
serverID, consts.DhcpServerPath, dhcpID),
client: lb.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &dhcpServerResp)
},
}
err := dhcpServerAPI.do(ctx, request, nil)
return dhcpServerResp, err
}
func (lb *DhcpServerAPIService) DeleteDhcpServer(
ctx context.Context,
serverID int,
dhcpID int,
) (models.SuccessOrErrorMessage, error) {
dhcpServerResp := models.SuccessOrErrorMessage{}
dhcpServerAPI := &api{
compatibleVersion: dhcpCompatibleVersion,
method: "DELETE",
path: fmt.Sprintf("%s/%s/%d/%s/%d",
consts.NetworksPath, consts.ServerPath,
serverID, consts.DhcpServerPath, dhcpID),
client: lb.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &dhcpServerResp)
},
}
err := dhcpServerAPI.do(ctx, nil, nil)
return dhcpServerResp, err
}
func (lb *DhcpServerAPIService) GetDhcpServers(
ctx context.Context,
serverID int,
) (models.GetNetworkDhcpServers, error) {
dhcpServerResp := models.GetNetworkDhcpServers{}
dhcpServerAPI := &api{
compatibleVersion: dhcpCompatibleVersion,
method: "GET",
path: fmt.Sprintf("%s/%s/%d/%s",
consts.NetworksPath, consts.ServerPath,
serverID, consts.DhcpServerPath),
client: lb.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &dhcpServerResp)
},
}
err := dhcpServerAPI.do(ctx, nil, nil)
return dhcpServerResp, err
}
func (lb *DhcpServerAPIService) GetSpecificDhcpServer(
ctx context.Context,
serverID int,
dhcpID int,
) (models.GetSpecificNetworkDhcpServer, error) {
dhcpServerResp := models.GetSpecificNetworkDhcpServer{}
dhcpServerAPI := &api{
compatibleVersion: dhcpCompatibleVersion,
method: "GET",
path: fmt.Sprintf("%s/%s/%d/%s/%d",
consts.NetworksPath, consts.ServerPath,
serverID, consts.DhcpServerPath, dhcpID),
client: lb.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &dhcpServerResp)
},
}
err := dhcpServerAPI.do(ctx, nil, nil)
return dhcpServerResp, err
}