diff --git a/service/subscriptions/model.go b/service/subscriptions/model.go index a8e1fee..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"` @@ -186,6 +187,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 +225,40 @@ 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"` + SourceRegion *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"` + VPCCidr *string `json:"vpcCidr,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"` + 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"` } @@ -249,4 +299,7 @@ const ( VPCPeeringStatusPendingAcceptance = "pending-acceptance" // Failed value of the `Status` field in `VPCPeering` VPCPeeringStatusFailed = "failed" + + SubscriptionDeploymentTypeSingleRegion = "single-region" + SubscriptionDeploymentTypeActiveActive = "active-active" ) diff --git a/service/subscriptions/service.go b/service/subscriptions/service.go index c8c8fc8..7af3dfa 100644 --- a/service/subscriptions/service.go +++ b/service/subscriptions/service.go @@ -170,6 +170,33 @@ 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 + } + + // 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 +} + // 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 +215,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 +250,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}