Skip to content

Commit

Permalink
outscale_oapi: add virtual_gateway resource
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Jutteau <[email protected]>
  • Loading branch information
jerome-jutteau committed Nov 5, 2021
1 parent 0d2d27f commit 8cf36d4
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions internal/providers/outscale_oapi/outscale_oapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const typeNet = "net"
const typeImage = "image"
const typeSnapshot = "snapshot"
const typeVpnConnection = "vpn_connection"
const typeVirtualGateway = "virtual_gateway"

type OutscaleOAPI struct {
client *osc.APIClient
Expand Down Expand Up @@ -89,6 +90,7 @@ func Types() []ObjectType {
typeImage,
typeSnapshot,
typeVpnConnection,
typeVirtualGateway,
}
return object_types
}
Expand Down Expand Up @@ -137,6 +139,7 @@ func (provider *OutscaleOAPI) Objects() Objects {
objects[typeImage] = provider.getImages()
objects[typeSnapshot] = provider.getSnapshots()
objects[typeVpnConnection] = provider.getVpnConnections()
objects[typeVirtualGateway] = provider.getVirtualGateways()
return objects
}

Expand All @@ -155,6 +158,7 @@ func (provider *OutscaleOAPI) Delete(objects Objects) {
provider.deleteSubnets(objects[typeSubnet])
provider.deleteNets(objects[typeNet])
provider.deleteVpnConnections(objects[typeVpnConnection])
provider.deleteVirtualGateways(objects[typeVirtualGateway])
}

func newAPICache() apiCache {
Expand Down Expand Up @@ -873,3 +877,46 @@ func (provider *OutscaleOAPI) deleteVpnConnections(vpnConnections []Object) {
}
}
}

func (provider *OutscaleOAPI) getVirtualGateways() []Object {
virtualGateways := make([]Object, 0)
read, httpRes, err := provider.client.VirtualGatewayApi.ReadVirtualGateways(provider.context).
ReadVirtualGatewaysRequest(osc.ReadVirtualGatewaysRequest{}).
Execute()
if err != nil {
fmt.Fprint(os.Stderr, "Error while reading virtual gateways: ")
if httpRes != nil {
fmt.Fprintln(os.Stderr, httpRes.Status)
}
return virtualGateways
}
for _, virtualGateway := range *read.VirtualGateways {
switch *virtualGateway.State {
case "pending", "available":
virtualGateways = append(virtualGateways, *virtualGateway.VirtualGatewayId)
}
}
return virtualGateways
}

func (provider *OutscaleOAPI) deleteVirtualGateways(virtualGateways []Object) {
if len(virtualGateways) == 0 {
return
}
for _, virtualGateway := range virtualGateways {
fmt.Printf("Deleting virtual gateway %s... ", virtualGateway)
deletionOpts := osc.DeleteVirtualGatewayRequest{VirtualGatewayId: virtualGateway}
_, httpRes, err := provider.client.VirtualGatewayApi.
DeleteVirtualGateway(provider.context).
DeleteVirtualGatewayRequest(deletionOpts).
Execute()
if err != nil {
fmt.Fprint(os.Stderr, "Error while deleting virtual gateway: ")
if httpRes != nil {
fmt.Fprintln(os.Stderr, httpRes.Status)
}
} else {
fmt.Println("OK")
}
}
}

0 comments on commit 8cf36d4

Please sign in to comment.