/
post_devices_deviceid_interfaces_vlan_operation.go
259 lines (220 loc) · 7.23 KB
/
post_devices_deviceid_interfaces_vlan_operation.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// Code generated by go-swagger; DO NOT EDIT.
package cli
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"github.com/byxorna/nycmesh-tool/generated/go/uisp/client/devices"
"github.com/byxorna/nycmesh-tool/generated/go/uisp/models"
"github.com/go-openapi/swag"
"github.com/spf13/cobra"
)
// makeOperationDevicesPostDevicesDeviceidInterfacesVlanCmd returns a cmd to handle operation postDevicesDeviceidInterfacesVlan
func makeOperationDevicesPostDevicesDeviceidInterfacesVlanCmd() (*cobra.Command, error) {
cmd := &cobra.Command{
Use: "postDevicesDeviceidInterfacesVlan",
Short: ``,
RunE: runOperationDevicesPostDevicesDeviceidInterfacesVlan,
}
if err := registerOperationDevicesPostDevicesDeviceidInterfacesVlanParamFlags(cmd); err != nil {
return nil, err
}
return cmd, nil
}
// runOperationDevicesPostDevicesDeviceidInterfacesVlan uses cmd flags to call endpoint api
func runOperationDevicesPostDevicesDeviceidInterfacesVlan(cmd *cobra.Command, args []string) error {
appCli, err := makeClient(cmd, args)
if err != nil {
return err
}
// retrieve flag values from cmd and fill params
params := devices.NewPostDevicesDeviceidInterfacesVlanParams()
if err, _ := retrieveOperationDevicesPostDevicesDeviceidInterfacesVlanBodyFlag(params, "", cmd); err != nil {
return err
}
if err, _ := retrieveOperationDevicesPostDevicesDeviceidInterfacesVlanDeviceIDFlag(params, "", cmd); err != nil {
return err
}
if dryRun {
logDebugf("dry-run flag specified. Skip sending request.")
return nil
}
// make request and then print result
msgStr, err := parseOperationDevicesPostDevicesDeviceidInterfacesVlanResult(appCli.Devices.PostDevicesDeviceidInterfacesVlan(params, nil))
if err != nil {
return err
}
if !debug {
fmt.Println(msgStr)
}
return nil
}
// registerOperationDevicesPostDevicesDeviceidInterfacesVlanParamFlags registers all flags needed to fill params
func registerOperationDevicesPostDevicesDeviceidInterfacesVlanParamFlags(cmd *cobra.Command) error {
if err := registerOperationDevicesPostDevicesDeviceidInterfacesVlanBodyParamFlags("", cmd); err != nil {
return err
}
if err := registerOperationDevicesPostDevicesDeviceidInterfacesVlanDeviceIDParamFlags("", cmd); err != nil {
return err
}
return nil
}
func registerOperationDevicesPostDevicesDeviceidInterfacesVlanBodyParamFlags(cmdPrefix string, cmd *cobra.Command) error {
var bodyFlagName string
if cmdPrefix == "" {
bodyFlagName = "body"
} else {
bodyFlagName = fmt.Sprintf("%v.body", cmdPrefix)
}
_ = cmd.PersistentFlags().String(bodyFlagName, "", "Optional json string for [body]. ")
// add flags for body
if err := registerModelModel97Flags(0, "model97", cmd); err != nil {
return err
}
return nil
}
func registerOperationDevicesPostDevicesDeviceidInterfacesVlanDeviceIDParamFlags(cmdPrefix string, cmd *cobra.Command) error {
deviceIdDescription := `Required. `
var deviceIdFlagName string
if cmdPrefix == "" {
deviceIdFlagName = "deviceId"
} else {
deviceIdFlagName = fmt.Sprintf("%v.deviceId", cmdPrefix)
}
var deviceIdFlagDefault string
_ = cmd.PersistentFlags().String(deviceIdFlagName, deviceIdFlagDefault, deviceIdDescription)
return nil
}
func retrieveOperationDevicesPostDevicesDeviceidInterfacesVlanBodyFlag(m *devices.PostDevicesDeviceidInterfacesVlanParams, cmdPrefix string, cmd *cobra.Command) (error, bool) {
retAdded := false
if cmd.Flags().Changed("body") {
// Read body string from cmd and unmarshal
bodyValueStr, err := cmd.Flags().GetString("body")
if err != nil {
return err, false
}
bodyValue := models.Model97{}
if err := json.Unmarshal([]byte(bodyValueStr), &bodyValue); err != nil {
return fmt.Errorf("cannot unmarshal body string in models.Model97: %v", err), false
}
m.Body = &bodyValue
}
bodyValueModel := m.Body
if swag.IsZero(bodyValueModel) {
bodyValueModel = &models.Model97{}
}
err, added := retrieveModelModel97Flags(0, bodyValueModel, "model97", cmd)
if err != nil {
return err, false
}
if added {
m.Body = bodyValueModel
}
if dryRun && debug {
bodyValueDebugBytes, err := json.Marshal(m.Body)
if err != nil {
return err, false
}
logDebugf("Body dry-run payload: %v", string(bodyValueDebugBytes))
}
retAdded = retAdded || added
return nil, retAdded
}
func retrieveOperationDevicesPostDevicesDeviceidInterfacesVlanDeviceIDFlag(m *devices.PostDevicesDeviceidInterfacesVlanParams, cmdPrefix string, cmd *cobra.Command) (error, bool) {
retAdded := false
if cmd.Flags().Changed("deviceId") {
var deviceIdFlagName string
if cmdPrefix == "" {
deviceIdFlagName = "deviceId"
} else {
deviceIdFlagName = fmt.Sprintf("%v.deviceId", cmdPrefix)
}
deviceIdFlagValue, err := cmd.Flags().GetString(deviceIdFlagName)
if err != nil {
return err, false
}
m.DeviceID = deviceIdFlagValue
}
return nil, retAdded
}
// parseOperationDevicesPostDevicesDeviceidInterfacesVlanResult parses request result and return the string content
func parseOperationDevicesPostDevicesDeviceidInterfacesVlanResult(resp0 *devices.PostDevicesDeviceidInterfacesVlanOK, respErr error) (string, error) {
if respErr != nil {
var iResp0 interface{} = respErr
resp0, ok := iResp0.(*devices.PostDevicesDeviceidInterfacesVlanOK)
if ok {
if !swag.IsZero(resp0) && !swag.IsZero(resp0.Payload) {
msgStr, err := json.Marshal(resp0.Payload)
if err != nil {
return "", err
}
return string(msgStr), nil
}
}
var iResp1 interface{} = respErr
resp1, ok := iResp1.(*devices.PostDevicesDeviceidInterfacesVlanBadRequest)
if ok {
if !swag.IsZero(resp1) && !swag.IsZero(resp1.Payload) {
msgStr, err := json.Marshal(resp1.Payload)
if err != nil {
return "", err
}
return string(msgStr), nil
}
}
var iResp2 interface{} = respErr
resp2, ok := iResp2.(*devices.PostDevicesDeviceidInterfacesVlanUnauthorized)
if ok {
if !swag.IsZero(resp2) && !swag.IsZero(resp2.Payload) {
msgStr, err := json.Marshal(resp2.Payload)
if err != nil {
return "", err
}
return string(msgStr), nil
}
}
var iResp3 interface{} = respErr
resp3, ok := iResp3.(*devices.PostDevicesDeviceidInterfacesVlanForbidden)
if ok {
if !swag.IsZero(resp3) && !swag.IsZero(resp3.Payload) {
msgStr, err := json.Marshal(resp3.Payload)
if err != nil {
return "", err
}
return string(msgStr), nil
}
}
var iResp4 interface{} = respErr
resp4, ok := iResp4.(*devices.PostDevicesDeviceidInterfacesVlanNotFound)
if ok {
if !swag.IsZero(resp4) && !swag.IsZero(resp4.Payload) {
msgStr, err := json.Marshal(resp4.Payload)
if err != nil {
return "", err
}
return string(msgStr), nil
}
}
var iResp5 interface{} = respErr
resp5, ok := iResp5.(*devices.PostDevicesDeviceidInterfacesVlanInternalServerError)
if ok {
if !swag.IsZero(resp5) && !swag.IsZero(resp5.Payload) {
msgStr, err := json.Marshal(resp5.Payload)
if err != nil {
return "", err
}
return string(msgStr), nil
}
}
return "", respErr
}
if !swag.IsZero(resp0) && !swag.IsZero(resp0.Payload) {
msgStr, err := json.Marshal(resp0.Payload)
if err != nil {
return "", err
}
return string(msgStr), nil
}
return "", nil
}