From 6bbedf70380b177fc0dd2e0cb4af67665493425c Mon Sep 17 00:00:00 2001 From: byron-oc Date: Wed, 7 Dec 2022 16:35:58 +0000 Subject: [PATCH 1/4] add create/list/delete active-active regions aws --- service/subscriptions/model.go | 48 ++++++++++++++++++++++++++++++++ service/subscriptions/service.go | 37 +++++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/service/subscriptions/model.go b/service/subscriptions/model.go index a8e1fee..50c8706 100644 --- a/service/subscriptions/model.go +++ b/service/subscriptions/model.go @@ -186,6 +186,21 @@ func (o CreateVPCPeering) String() string { return internal.ToString(o) } +type CreateActiveActiveVPCPeering struct { + SourceRegion *string `json:"sourceRegion,omitempty"` + DestinationRegion *string `json:"destinationRegion,omitempty"` + AWSAccountID *string `json:"awsAccountId,omitempty"` + VPCId *string `json:"vpcId,omitempty"` + VPCCidrs []*string `json:"vpcCidrs,omitempty"` + Provider *string `json:"provider,omitempty"` + VPCProjectUID *string `json:"vpcProjectUid,omitempty"` + VPCNetworkName *string `json:"vpcNetworkName,omitempty"` +} + +func (o CreateActiveActiveVPCPeering) String() string { + return internal.ToString(o) +} + type listVpcPeering struct { Peerings []*VPCPeering `json:"peerings"` } @@ -209,6 +224,39 @@ func (o VPCPeering) String() string { return internal.ToString(o) } +type listActiveActiveVpcPeering struct { + SubscriptionId *int `json:"subscriptionId,omitempty"` + Regions []*ActiveActiveVpcRegion `json:"regions,omitempty"` +} + +type ActiveActiveVpcRegion struct { + ID *int `json:"id,omitempty"` + Region *string `json:"region,omitempty"` + VPCPeerings []*ActiveActiveVPCPeering `json:"vpcPeerings,omitempty"` +} + +type ActiveActiveVPCPeering struct { + ID *int `json:"id,omitempty"` + Status *string `json:"status,omitempty"` + RegionId *int `json:"regionId,omitempty"` + RegionName *string `json:"regionName,omitempty"` + AWSAccountID *string `json:"awsAccountId,omitempty"` + AWSPeeringID *string `json:"awsPeeringUid,omitempty"` + VPCId *string `json:"vpcUid,omitempty"` + VPCCidrs []*string `json:"vpcCidrs,omitempty"` + GCPProjectUID *string `json:"projectUid,omitempty"` + NetworkName *string `json:"networkName,omitempty"` + RedisProjectUID *string `json:"redisProjectUid,omitempty"` + RedisNetworkName *string `json:"redisNetworkName,omitempty"` + CloudPeeringID *string `json:"cloudPeeringId,omitempty"` + SourceRegion *string `json:"sourceRegion,omitempty"` + DestinationRegion *string `json:"destinationRegion,omitempty"` +} + +func (o ActiveActiveVPCPeering) String() string { + return internal.ToString(o) +} + type listSubscriptionResponse struct { Subscriptions []*Subscription `json:"subscriptions"` } diff --git a/service/subscriptions/service.go b/service/subscriptions/service.go index c8c8fc8..9b27274 100644 --- a/service/subscriptions/service.go +++ b/service/subscriptions/service.go @@ -170,6 +170,24 @@ func (a *API) ListVPCPeering(ctx context.Context, id int) ([]*VPCPeering, error) return peering.Peerings, nil } +func (a *API) ListActiveActiveVPCPeering(ctx context.Context, id int) ([]*ActiveActiveVpcRegion, error) { + var task taskResponse + err := a.client.Get(ctx, fmt.Sprintf("get peerings for subscription %d", id), fmt.Sprintf("/subscriptions/%d/regions/peerings/", id), &task) + if err != nil { + return nil, wrap404Error(id, err) + } + + a.logger.Printf("Waiting for subscription %d peering details to be retrieved", id) + + var peering listActiveActiveVpcPeering + err = a.task.WaitForResource(ctx, *task.ID, &peering) + if err != nil { + return nil, err + } + + return peering.Regions, nil +} + // CreateVPCPeering creates a new VPC peering from the subscription VPC and returns the identifier of the VPC peering. func (a *API) CreateVPCPeering(ctx context.Context, id int, create CreateVPCPeering) (int, error) { var task taskResponse @@ -188,7 +206,7 @@ func (a *API) CreateVPCPeering(ctx context.Context, id int, create CreateVPCPeer return id, nil } -func (a *API) CreateActiveActiveVPCPeering(ctx context.Context, id int, create CreateVPCPeering) (int, error) { +func (a *API) CreateActiveActiveVPCPeering(ctx context.Context, id int, create CreateActiveActiveVPCPeering) (int, error) { var task taskResponse err := a.client.Post(ctx, fmt.Sprintf("create peering for subscription %d", id), fmt.Sprintf("/subscriptions/%d/regions/peerings/", id), create, &task) if err != nil { @@ -223,6 +241,23 @@ func (a *API) DeleteVPCPeering(ctx context.Context, subscription int, peering in return nil } +func (a *API) DeleteActiveActiveVPCPeering(ctx context.Context, subscription int, peering int) error { + var task taskResponse + err := a.client.Delete(ctx, fmt.Sprintf("deleting peering %d for subscription %d", peering, subscription), fmt.Sprintf("/subscriptions/%d/regions/peerings/%d", subscription, peering), &task) + if err != nil { + return err + } + + a.logger.Printf("Waiting for peering %d for subscription %d to be deleted", peering, subscription) + + err = a.task.Wait(ctx, *task.ID) + if err != nil { + return err + } + + return nil +} + func wrap404Error(id int, err error) error { if v, ok := err.(*internal.HTTPError); ok && v.StatusCode == http.StatusNotFound { return &NotFound{id: id} From 61c214c106b8f3426a9ddd955bef8afb0d688ebd Mon Sep 17 00:00:00 2001 From: byron-oc Date: Thu, 22 Dec 2022 11:41:51 +0000 Subject: [PATCH 2/4] wip --- service/subscriptions/model.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/service/subscriptions/model.go b/service/subscriptions/model.go index 50c8706..bf034f3 100644 --- a/service/subscriptions/model.go +++ b/service/subscriptions/model.go @@ -230,9 +230,9 @@ type listActiveActiveVpcPeering struct { } type ActiveActiveVpcRegion struct { - ID *int `json:"id,omitempty"` - Region *string `json:"region,omitempty"` - VPCPeerings []*ActiveActiveVPCPeering `json:"vpcPeerings,omitempty"` + ID *int `json:"id,omitempty"` + SourceRegion *string `json:"region,omitempty"` + VPCPeerings []*ActiveActiveVPCPeering `json:"vpcPeerings,omitempty"` } type ActiveActiveVPCPeering struct { @@ -244,8 +244,8 @@ type ActiveActiveVPCPeering struct { AWSPeeringID *string `json:"awsPeeringUid,omitempty"` VPCId *string `json:"vpcUid,omitempty"` VPCCidrs []*string `json:"vpcCidrs,omitempty"` - GCPProjectUID *string `json:"projectUid,omitempty"` - NetworkName *string `json:"networkName,omitempty"` + GCPProjectUID *string `json:"vpcProjectUid,omitempty"` + NetworkName *string `json:"vpcNetworkName,omitempty"` RedisProjectUID *string `json:"redisProjectUid,omitempty"` RedisNetworkName *string `json:"redisNetworkName,omitempty"` CloudPeeringID *string `json:"cloudPeeringId,omitempty"` From f23d278d2f07d9eb7d1a819e5e8e6f4fd1350fe8 Mon Sep 17 00:00:00 2001 From: Ben Gesoff Date: Mon, 9 Jan 2023 19:06:58 +0000 Subject: [PATCH 3/4] fix: read `vpcCidr` from API response for active-active peering --- service/subscriptions/model.go | 1 + service/subscriptions/service.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/service/subscriptions/model.go b/service/subscriptions/model.go index bf034f3..8e0f82c 100644 --- a/service/subscriptions/model.go +++ b/service/subscriptions/model.go @@ -244,6 +244,7 @@ type ActiveActiveVPCPeering struct { AWSPeeringID *string `json:"awsPeeringUid,omitempty"` VPCId *string `json:"vpcUid,omitempty"` VPCCidrs []*string `json:"vpcCidrs,omitempty"` + VPCCidr *string `json:"vpcCidr,omitempty"` GCPProjectUID *string `json:"vpcProjectUid,omitempty"` NetworkName *string `json:"vpcNetworkName,omitempty"` RedisProjectUID *string `json:"redisProjectUid,omitempty"` diff --git a/service/subscriptions/service.go b/service/subscriptions/service.go index 9b27274..7af3dfa 100644 --- a/service/subscriptions/service.go +++ b/service/subscriptions/service.go @@ -185,6 +185,15 @@ func (a *API) ListActiveActiveVPCPeering(ctx context.Context, id int) ([]*Active return nil, err } + // add vpcCidr to vpcCidrs slice if it exists + for i, region := range peering.Regions { + for j, vpcPeering := range region.VPCPeerings { + if vpcPeering.VPCCidr != nil { + peering.Regions[i].VPCPeerings[j].VPCCidrs = append(peering.Regions[i].VPCPeerings[j].VPCCidrs, vpcPeering.VPCCidr) + } + } + } + return peering.Regions, nil } From a022dac87deee8e10054e469b7cff7389fac1622 Mon Sep 17 00:00:00 2001 From: Ben Gesoff Date: Tue, 10 Jan 2023 16:31:25 +0000 Subject: [PATCH 4/4] feat: add `deploymentType` field to subscriptions --- service/subscriptions/model.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/subscriptions/model.go b/service/subscriptions/model.go index 8e0f82c..9b30135 100644 --- a/service/subscriptions/model.go +++ b/service/subscriptions/model.go @@ -109,6 +109,7 @@ type Subscription struct { ID *int `json:"id,omitempty"` Name *string `json:"name,omitempty"` Status *string `json:"status,omitempty"` + DeploymentType *string `json:"deploymentType,omitempty"` PaymentMethod *string `json:"paymentMethodType,omitempty"` PaymentMethodID *int `json:"paymentMethodId,omitempty"` MemoryStorage *string `json:"memoryStorage,omitempty"` @@ -298,4 +299,7 @@ const ( VPCPeeringStatusPendingAcceptance = "pending-acceptance" // Failed value of the `Status` field in `VPCPeering` VPCPeeringStatusFailed = "failed" + + SubscriptionDeploymentTypeSingleRegion = "single-region" + SubscriptionDeploymentTypeActiveActive = "active-active" )