/
api_devices.go
180 lines (156 loc) · 5.38 KB
/
api_devices.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
/*
* Metal API
*
* This is the API for Equinix Metal. The API allows you to programmatically interact with all of your Equinix Metal resources, including devices, networks, addresses, organizations, projects, and your user account. The official API docs are hosted at <https://metal.equinix.com/developers/api>.
*
* API version: 1.0.0
* Contact: support@equinixmetal.com
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package startapi
import (
"context"
"github.com/gin-gonic/gin"
metal "github.com/haozheng95/eqx-gin-server/metal/v1"
"log"
"net/http"
)
// CreateBgpSession - Create a BGP session
func CreateBgpSession(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// CreateDevice - Create a device
func CreateDevice(c *gin.Context) {
id := c.Param("id")
var body *metal.CreateDeviceRequestOneOf
if err := c.BindJSON(&body); err != nil {
if !ErrorCheck(err, nil, c) {
return
}
}
//var privateIpv4SubnetSize float32 = 28
//this.PrivateIpv4SubnetSize = &privateIpv4SubnetSize
//var publicIpv4SubnetSize float32 = 31
//this.PublicIpv4SubnetSize = &publicIpv4SubnetSize
respDevice, r, err := apiClient.DevicesApi.FindProjectDevices(context.Background(), id).Execute()
if !ErrorCheck(err, r, c) {
return
}
if len(respDevice.Devices) >= 3 {
hostIPs := make([]string, 3)
for i, device := range respDevice.Devices {
log.Println("i=", i)
for j, ip := range device.IpAddresses {
log.Println("j=", j)
log.Println("ip.Address=", ip.GetAddress())
log.Println("ip.GetPublic=", ip.GetPublic())
if ip.GetPublic() && IsIPv4(ip.GetAddress()) {
addAuthorizedKeys(ip.GetAddress(), body)
hostIPs = append(hostIPs, ip.GetAddress())
continue
}
}
}
c.JSON(http.StatusInsufficientStorage, gin.H{"msg": "The number of created instances reached the upper limit. We have added your public keys to the following hosts so you can log in to them directly as root " + arrayToString(hostIPs)})
return
}
resp, r, err := apiClient.DevicesApi.CreateDevice(context.Background(), id).CreateDeviceRequest(metal.CreateDeviceRequestOneOfAsCreateDeviceRequest(body)).Execute()
if !ErrorCheck(err, r, c) {
return
}
c.JSON(http.StatusOK, resp)
}
// CreateIPAssignment - Create an ip assignment
func CreateIPAssignment(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// DeleteDevice - Delete the device
func DeleteDevice(c *gin.Context) {
id := c.Param("id")
r, err := apiClient.DevicesApi.DeleteDevice(context.Background(), id).ForceDelete(true).Execute()
if !ErrorCheck(err, r, c) {
return
}
c.JSON(http.StatusOK, gin.H{"resp": "delete success"})
}
// FindBgpSessions - Retrieve all BGP sessions
func FindBgpSessions(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// FindDeviceById - Retrieve a device
func FindDeviceById(c *gin.Context) {
id := c.Param("id")
resp, r, err := apiClient.DevicesApi.FindDeviceById(context.Background(), id).Include(include).Exclude(exclude).Execute()
if !ErrorCheck(err, r, c) {
return
}
c.JSON(http.StatusOK, resp)
}
// FindDeviceCustomdata - Retrieve the custom metadata of an instance
func FindDeviceCustomdata(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// FindDeviceMetadataByID - Retrieve metadata
func FindDeviceMetadataByID(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// FindDeviceUserdataByID - Retrieve userdata
func FindDeviceUserdataByID(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// FindIPAssignmentCustomdata - Retrieve the custom metadata of an IP Assignment
func FindIPAssignmentCustomdata(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// FindIPAssignments - Retrieve all ip assignments
func FindIPAssignments(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// FindInstanceBandwidth - Retrieve an instance bandwidth
func FindInstanceBandwidth(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// FindOrganizationDevices - Retrieve all devices of an organization
func FindOrganizationDevices(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// FindProjectDevices - Retrieve all devices of a project
func FindProjectDevices(c *gin.Context) {
id := c.Param("id")
resp, r, err := apiClient.DevicesApi.FindProjectDevices(context.Background(), id).Execute()
//page := int32(1) // int32 | Page to return (optional) (default to 1)
//perPage := int32(10) // int32 | Items returned per page (optional) (default to 10)
//resp, r, err := apiClient.DevicesApi.FindProjectDevices(context.Background(), id).Page(page).PerPage(perPage).Execute()
if !ErrorCheck(err, r, c) {
return
}
c.JSON(http.StatusOK, resp)
}
// FindTraffic - Retrieve device traffic
func FindTraffic(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// GetBgpNeighborData - Retrieve BGP neighbor data for this device
func GetBgpNeighborData(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// PerformAction - Perform an action
func PerformAction(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
// UpdateDevice - Update the device
func UpdateDevice(c *gin.Context) {
id := c.Param("id") // string | Device UUID
var body *metal.UpdateDeviceRequest // UpdateDeviceRequest | Facility to update
if err := c.BindJSON(&body); err != nil {
// DO SOMETHING WITH THE ERROR
if !ErrorCheck(err, nil, c) {
return
}
}
resp, r, err := apiClient.DevicesApi.UpdateDevice(context.Background(), id).UpdateDeviceRequest(*body).Execute()
if !ErrorCheck(err, r, c) {
return
}
c.JSON(http.StatusOK, resp)
}