Skip to content

Commit 2eb2952

Browse files
author
Gianluca Cannata
committed
remove VPC subnets and routes API endpoints
The subnets and routes endpoints under /v2/vpc/networks/{id}/subnets are not ready for the VPC API. This removes all related client methods, tests, and documentation while keeping the underlying types in network.go intact.
1 parent 48cc0df commit 2eb2952

File tree

3 files changed

+0
-339
lines changed

3 files changed

+0
-339
lines changed

doc/vpc.md

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ VPC (Virtual Private Cloud) is the product umbrella containing networking-relate
77
The VPC methods provide a unified namespace for all VPC-related features:
88

99
- **Networks** - Private networks for instances to connect to
10-
- **Subnets** - Subnets within private networks
1110
- **Firewalls** - Firewall rules for network security
1211
- **DNS** - DNS domains and records management
1312
- **Load Balancers** - Load balancer configuration
@@ -180,114 +179,6 @@ fmt.Printf("Result: %s\n", resp.Result)
180179

181180
---
182181

183-
## VPC Subnets
184-
185-
Subnets within private networks.
186-
187-
### ListVPCSubnets
188-
189-
Lists all subnets for a private network.
190-
191-
```go
192-
subnets, err := client.ListVPCSubnets("network-id")
193-
if err != nil {
194-
log.Fatal(err)
195-
}
196-
197-
for _, subnet := range subnets {
198-
fmt.Printf("Subnet: %s (ID: %s)\n", subnet.Name, subnet.ID)
199-
}
200-
```
201-
202-
### GetVPCSubnet
203-
204-
Gets a specific subnet by ID.
205-
206-
```go
207-
subnet, err := client.GetVPCSubnet("network-id", "subnet-id")
208-
if err != nil {
209-
log.Fatal(err)
210-
}
211-
212-
fmt.Printf("Subnet: %s, Status: %s\n", subnet.Name, subnet.Status)
213-
```
214-
215-
### FindVPCSubnet
216-
217-
Finds a subnet by either part of the ID or part of the name.
218-
219-
```go
220-
subnet, err := client.FindVPCSubnet("my-subnet", "network-id")
221-
if err != nil {
222-
log.Fatal(err)
223-
}
224-
225-
fmt.Printf("Found: %s\n", subnet.Name)
226-
```
227-
228-
### CreateVPCSubnet
229-
230-
Creates a new subnet for a private network.
231-
232-
```go
233-
config := civogo.SubnetConfig{
234-
Name: "my-subnet",
235-
}
236-
237-
subnet, err := client.CreateVPCSubnet("network-id", config)
238-
if err != nil {
239-
log.Fatal(err)
240-
}
241-
242-
fmt.Printf("Created subnet: %s\n", subnet.ID)
243-
```
244-
245-
### AttachVPCSubnetToInstance
246-
247-
Attaches a subnet to an instance by creating a route.
248-
249-
```go
250-
route := &civogo.CreateRoute{
251-
ResourceID: "instance-id",
252-
ResourceType: "instance",
253-
}
254-
255-
result, err := client.AttachVPCSubnetToInstance("network-id", "subnet-id", route)
256-
if err != nil {
257-
log.Fatal(err)
258-
}
259-
260-
fmt.Printf("Route created: %s\n", result.ID)
261-
```
262-
263-
### DetachVPCSubnetFromInstance
264-
265-
Detaches a subnet from an instance.
266-
267-
```go
268-
resp, err := client.DetachVPCSubnetFromInstance("network-id", "subnet-id")
269-
if err != nil {
270-
log.Fatal(err)
271-
}
272-
273-
fmt.Printf("Result: %s\n", resp.Result)
274-
```
275-
276-
### DeleteVPCSubnet
277-
278-
Deletes a subnet.
279-
280-
```go
281-
resp, err := client.DeleteVPCSubnet("network-id", "subnet-id")
282-
if err != nil {
283-
log.Fatal(err)
284-
}
285-
286-
fmt.Printf("Result: %s\n", resp.Result)
287-
```
288-
289-
---
290-
291182
## VPC Firewalls
292183

293184
Firewall management for network security.

vpc.go

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -174,121 +174,6 @@ func (c *Client) UpdateVPCNetwork(id string, nc NetworkConfig) (*NetworkResult,
174174
return result, nil
175175
}
176176

177-
// =============================================================================
178-
// VPC Subnets - /v2/vpc/networks/{network_id}/subnets
179-
// =============================================================================
180-
181-
// GetVPCSubnet gets a subnet with ID using VPC API path
182-
func (c *Client) GetVPCSubnet(networkID, subnetID string) (*Subnet, error) {
183-
resp, err := c.SendGetRequest(fmt.Sprintf("/v2/vpc/networks/%s/subnets/%s", networkID, subnetID))
184-
if err != nil {
185-
return nil, decodeError(err)
186-
}
187-
188-
subnet := Subnet{}
189-
err = json.NewDecoder(bytes.NewReader(resp)).Decode(&subnet)
190-
return &subnet, err
191-
}
192-
193-
// ListVPCSubnets lists all subnets for a private network using VPC API path
194-
func (c *Client) ListVPCSubnets(networkID string) ([]Subnet, error) {
195-
resp, err := c.SendGetRequest(fmt.Sprintf("/v2/vpc/networks/%s/subnets", networkID))
196-
if err != nil {
197-
return nil, decodeError(err)
198-
}
199-
200-
subnets := make([]Subnet, 0)
201-
if err := json.NewDecoder(bytes.NewReader(resp)).Decode(&subnets); err != nil {
202-
return nil, err
203-
}
204-
205-
return subnets, nil
206-
}
207-
208-
// CreateVPCSubnet creates a new subnet for a private network using VPC API path
209-
func (c *Client) CreateVPCSubnet(networkID string, subnet SubnetConfig) (*Subnet, error) {
210-
body, err := c.SendPostRequest(fmt.Sprintf("/v2/vpc/networks/%s/subnets", networkID), subnet)
211-
if err != nil {
212-
return nil, decodeError(err)
213-
}
214-
215-
var result = &Subnet{}
216-
if err := json.NewDecoder(bytes.NewReader(body)).Decode(result); err != nil {
217-
return nil, err
218-
}
219-
220-
return result, nil
221-
}
222-
223-
// FindVPCSubnet finds a subnet by either part of the ID or part of the name using VPC API path
224-
func (c *Client) FindVPCSubnet(search, networkID string) (*Subnet, error) {
225-
subnets, err := c.ListVPCSubnets(networkID)
226-
if err != nil {
227-
return nil, decodeError(err)
228-
}
229-
230-
exactMatch := false
231-
partialMatchesCount := 0
232-
result := Subnet{}
233-
234-
for _, value := range subnets {
235-
if value.Name == search || value.ID == search {
236-
exactMatch = true
237-
result = value
238-
} else if strings.Contains(value.Name, search) || strings.Contains(value.ID, search) {
239-
if !exactMatch {
240-
result = value
241-
partialMatchesCount++
242-
}
243-
}
244-
}
245-
246-
if exactMatch || partialMatchesCount == 1 {
247-
return &result, nil
248-
} else if partialMatchesCount > 1 {
249-
err := fmt.Errorf("unable to find %s because there were multiple matches", search)
250-
return nil, MultipleMatchesError.wrap(err)
251-
} else {
252-
err := fmt.Errorf("unable to find %s, zero matches", search)
253-
return nil, ZeroMatchesError.wrap(err)
254-
}
255-
}
256-
257-
// AttachVPCSubnetToInstance attaches a subnet to an instance using VPC API path
258-
func (c *Client) AttachVPCSubnetToInstance(networkID, subnetID string, route *CreateRoute) (*Route, error) {
259-
resp, err := c.SendPostRequest(fmt.Sprintf("/v2/vpc/networks/%s/subnets/%s/routes", networkID, subnetID), route)
260-
if err != nil {
261-
return nil, decodeError(err)
262-
}
263-
264-
var result = &Route{}
265-
if err := json.NewDecoder(bytes.NewReader(resp)).Decode(result); err != nil {
266-
return nil, err
267-
}
268-
269-
return result, nil
270-
}
271-
272-
// DetachVPCSubnetFromInstance detaches a subnet from an instance using VPC API path
273-
func (c *Client) DetachVPCSubnetFromInstance(networkID, subnetID string) (*SimpleResponse, error) {
274-
resp, err := c.SendDeleteRequest(fmt.Sprintf("/v2/vpc/networks/%s/subnets/%s/routes", networkID, subnetID))
275-
if err != nil {
276-
return nil, decodeError(err)
277-
}
278-
279-
return c.DecodeSimpleResponse(resp)
280-
}
281-
282-
// DeleteVPCSubnet deletes a subnet using VPC API path
283-
func (c *Client) DeleteVPCSubnet(networkID, subnetID string) (*SimpleResponse, error) {
284-
resp, err := c.SendDeleteRequest(fmt.Sprintf("/v2/vpc/networks/%s/subnets/%s", networkID, subnetID))
285-
if err != nil {
286-
return nil, decodeError(err)
287-
}
288-
289-
return c.DecodeSimpleResponse(resp)
290-
}
291-
292177
// =============================================================================
293178
// VPC Firewalls - /v2/vpc/firewalls
294179
// =============================================================================

vpc_test.go

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -262,121 +262,6 @@ func TestDeleteVPCNetwork(t *testing.T) {
262262
}
263263
}
264264

265-
// =============================================================================
266-
// VPC Subnets Tests
267-
// =============================================================================
268-
269-
func TestGetVPCSubnet(t *testing.T) {
270-
client, server, _ := NewClientForTesting(map[string]string{
271-
"/v2/vpc/networks/12345/subnets/6789": `{"network_id": "12345", "id": "6789", "name": "test-subnet"}`,
272-
})
273-
defer server.Close()
274-
275-
got, err := client.GetVPCSubnet("12345", "6789")
276-
if err != nil {
277-
t.Errorf("Request returned an error: %s", err)
278-
return
279-
}
280-
if got.Name != "test-subnet" {
281-
t.Errorf("Expected %s, got %s", "test-subnet", got.Name)
282-
}
283-
}
284-
285-
func TestFindVPCSubnet(t *testing.T) {
286-
client, server, _ := NewClientForTesting(map[string]string{
287-
"/v2/vpc/networks/12345/subnets": `[
288-
{
289-
"id": "6789",
290-
"name": "test-subnet",
291-
"network_id": "12345"
292-
},
293-
{
294-
"id": "67890",
295-
"name": "test-subnet-2",
296-
"network_id": "12345"
297-
}
298-
]`,
299-
})
300-
defer server.Close()
301-
302-
got, _ := client.FindVPCSubnet("6789", "12345")
303-
if got.ID != "6789" {
304-
t.Errorf("Expected %s, got %s", "6789", got.ID)
305-
}
306-
307-
got, _ = client.FindVPCSubnet("test-subnet-2", "12345")
308-
if got.ID != "67890" {
309-
t.Errorf("Expected %s, got %s", "67890", got.ID)
310-
}
311-
}
312-
313-
func TestCreateVPCSubnet(t *testing.T) {
314-
client, server, _ := NewClientForTesting(map[string]string{
315-
"/v2/vpc/networks/12345/subnets": `{"id": "76cc107f-fbef-4e2b-b97f-f5d34f4075d3","network_id": "12345","name": "test-subnet","status": "success"}`,
316-
})
317-
defer server.Close()
318-
319-
subnet := SubnetConfig{
320-
Name: "test-subnet",
321-
}
322-
323-
got, err := client.CreateVPCSubnet("12345", subnet)
324-
if err != nil {
325-
t.Errorf("Request returned an error: %s", err)
326-
return
327-
}
328-
329-
expected := &Subnet{
330-
ID: "76cc107f-fbef-4e2b-b97f-f5d34f4075d3",
331-
Name: "test-subnet",
332-
NetworkID: "12345",
333-
Status: "success",
334-
}
335-
336-
if !reflect.DeepEqual(got, expected) {
337-
t.Errorf("Expected %+v, got %+v", expected, got)
338-
}
339-
}
340-
341-
func TestListVPCSubnets(t *testing.T) {
342-
client, server, _ := NewClientForTesting(map[string]string{
343-
"/v2/vpc/networks/12345/subnets": `[{
344-
"id": "6789",
345-
"name": "test-subnet",
346-
"network_id": "12345"
347-
}]`,
348-
})
349-
defer server.Close()
350-
got, err := client.ListVPCSubnets("12345")
351-
352-
if err != nil {
353-
t.Errorf("Request returned an error: %s", err)
354-
return
355-
}
356-
expected := []Subnet{{ID: "6789", Name: "test-subnet", NetworkID: "12345"}}
357-
if !reflect.DeepEqual(got, expected) {
358-
t.Errorf("Expected %+v, got %+v", expected, got)
359-
}
360-
}
361-
362-
func TestDeleteVPCSubnet(t *testing.T) {
363-
client, server, _ := NewClientForTesting(map[string]string{
364-
"/v2/vpc/networks/12345/subnets/6789": `{"result": "success"}`,
365-
})
366-
defer server.Close()
367-
368-
got, err := client.DeleteVPCSubnet("12345", "6789")
369-
if err != nil {
370-
t.Errorf("Request returned an error: %s", err)
371-
return
372-
}
373-
374-
expected := &SimpleResponse{Result: "success"}
375-
if !reflect.DeepEqual(got, expected) {
376-
t.Errorf("Expected %+v, got %+v", expected, got)
377-
}
378-
}
379-
380265
// =============================================================================
381266
// VPC Firewalls Tests
382267
// =============================================================================

0 commit comments

Comments
 (0)