Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEST: Priv ip aws #698

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions api/openapi.gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
"instances": [
{
"detail": {
"publicdns": "",
"publicipv4": "10.0.0.88"
"privateipv4": "172.31.36.10",
"privateipv6": "",
"publicdns": "ec2-184-73-141-211.compute-1.amazonaws.com",
"publicipv4": "184.73.141.211"
},
"instance_id": "i-2324343212"
}
Expand Down Expand Up @@ -80,6 +82,8 @@
"instances": [
{
"detail": {
"privateipv4": "",
"privateipv6": "",
"publicdns": "",
"publicipv4": "10.0.0.88"
},
Expand Down Expand Up @@ -129,6 +133,8 @@
"instances": [
{
"detail": {
"privateipv4": "",
"privateipv6": "",
"publicdns": "",
"publicipv4": "10.0.0.88"
},
Expand Down Expand Up @@ -589,6 +595,12 @@
"properties": {
"detail": {
"properties": {
"private_ipv4": {
"type": "string"
},
"private_ipv6": {
"type": "string"
},
"public_dns": {
"type": "string"
},
Expand Down Expand Up @@ -705,6 +717,12 @@
"properties": {
"detail": {
"properties": {
"private_ipv4": {
"type": "string"
},
"private_ipv6": {
"type": "string"
},
"public_dns": {
"type": "string"
},
Expand Down Expand Up @@ -796,6 +814,12 @@
"properties": {
"detail": {
"properties": {
"private_ipv4": {
"type": "string"
},
"private_ipv6": {
"type": "string"
},
"public_dns": {
"type": "string"
},
Expand Down Expand Up @@ -1334,7 +1358,7 @@
"name": "GPL-3.0"
},
"title": "provisioning-api",
"version": "1.7.0"
"version": "1.8.0"
},
"openapi": "3.0.0",
"paths": {
Expand Down
24 changes: 21 additions & 3 deletions api/openapi.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ components:
detail:
type: object
properties:
private_ipv4:
type: string
private_ipv6:
type: string
public_dns:
type: string
public_ipv4:
Expand Down Expand Up @@ -121,6 +125,10 @@ components:
detail:
type: object
properties:
private_ipv4:
type: string
private_ipv6:
type: string
public_dns:
type: string
public_ipv4:
Expand Down Expand Up @@ -182,6 +190,10 @@ components:
detail:
type: object
properties:
private_ipv4:
type: string
private_ipv6:
type: string
public_dns:
type: string
public_ipv4:
Expand Down Expand Up @@ -619,8 +631,10 @@ components:
instance_type: t3.small
instances:
- detail:
publicdns: ""
publicipv4: 10.0.0.88
privateipv4: 172.31.36.10
privateipv6: ""
publicdns: ec2-184-73-141-211.compute-1.amazonaws.com
publicipv4: 184.73.141.211
instance_id: i-2324343212
launch_template_id: ""
name: my-instance
Expand Down Expand Up @@ -661,6 +675,8 @@ components:
instance_size: Basic_A0
instances:
- detail:
privateipv4: ""
privateipv6: ""
publicdns: ""
publicipv4: 10.0.0.88
instance_id: /subscriptions/4b9d213f-712f-4d17-a483-8a10bbe9df3a/resourceGroups/redhat-deployed/providers/Microsoft.Compute/images/composer-api-92ea98f8-7697-472e-80b1-7454fa0e7fa7
Expand Down Expand Up @@ -700,6 +716,8 @@ components:
image_id: 08a48fed-de87-40ab-a571-f64e30bd0aa8
instances:
- detail:
privateipv4: ""
privateipv6: ""
publicdns: ""
publicipv4: 10.0.0.88
instance_id: "3003942005876582747"
Expand Down Expand Up @@ -930,7 +948,7 @@ info:
description: Provisioning service API
license:
name: GPL-3.0
version: 1.7.0
version: 1.8.0
paths:
/availability_status/sources:
post:
Expand Down
2 changes: 1 addition & 1 deletion cmd/spec/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.0
1.8.0
5 changes: 3 additions & 2 deletions cmd/spec/example_reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ var AwsReservationResponsePayloadDoneExample = payloads.AWSReservationResponse{
PowerOff: false,
Instances: []payloads.InstanceResponse{
{InstanceID: "i-2324343212", Detail: models.ReservationInstanceDetail{
PublicDNS: "",
PublicIPv4: "10.0.0.88",
PublicDNS: "ec2-184-73-141-211.compute-1.amazonaws.com",
PublicIPv4: "184.73.141.211",
PrivateIPv4: "172.31.36.10",
}},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/clients/http/azure/create_vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *client) CreateVMs(ctx context.Context, vmParams clients.AzureInstancePa
return nil, err
}

vmDescriptions[i].PublicIPv4 = *publicIP.Properties.IPAddress
vmDescriptions[i].IPv4 = *publicIP.Properties.IPAddress

resumeTokens[i], err = c.BeginCreateVM(ctx, networkInterface, vmParams, vmName)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions internal/clients/http/ec2/ec2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,11 @@ func (c *ec2Client) parseDescribeInstances(respAWS *ec2.DescribeInstancesOutput)
list := make([]*clients.InstanceDescription, len(instances))
for i, instance := range instances {
list[i] = &clients.InstanceDescription{
ID: *instance.InstanceId,
PublicIPv4: ptr.FromOrEmpty(instance.PublicIpAddress),
PublicDNS: ptr.FromOrEmpty(instance.PublicDnsName),
ID: *instance.InstanceId,
IPv4: ptr.FromOrEmpty(instance.PublicIpAddress),
DNS: ptr.FromOrEmpty(instance.PublicDnsName),
PrivateIPv4: ptr.FromOrEmpty(instance.PrivateIpAddress),
PrivateIPv6: ptr.FromOrEmpty(instance.Ipv6Address),
}
}
return list, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/clients/http/gcp/gcp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (c *gcpClient) GetInstanceDescriptionByID(ctx context.Context, id, zone str
instanceDesc := clients.InstanceDescription{ID: instanceId}
for _, n := range instance.NetworkInterfaces {
if len(n.AccessConfigs) > 0 && n.AccessConfigs[0] != nil {
instanceDesc.PublicIPv4 = *n.AccessConfigs[0].NatIP
instanceDesc.IPv4 = *n.AccessConfigs[0].NatIP
break
}
}
Expand Down
14 changes: 10 additions & 4 deletions internal/clients/instance_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ type InstanceDescription struct {
// The id of the instance
ID string `json:"id,omitempty" yaml:"id"`

// The public ipv4 dns of the instance
PublicDNS string `json:"dns,omitempty" yaml:"dns"`
// The public IPv4 dns of the instance or empty when not available
DNS string `json:"dns,omitempty" yaml:"dns"`

// the public ipv4 of the instance
PublicIPv4 string `json:"ipv4,omitempty" yaml:"ipv4"`
// The public IPv4 of the instance or empty when not available
IPv4 string `json:"ipv4,omitempty" yaml:"ipv4"`

// The IPv4 of the instance or empty when not available
PrivateIPv4 string `json:"private_ipv4,omitempty" yaml:"private_ipv4"`

// The IPv6 of the instance or empty when not available
PrivateIPv6 string `json:"private_ipv6,omitempty" yaml:"private_ipv6"`
}
2 changes: 1 addition & 1 deletion internal/clients/stubs/azure_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (stub *AzureClientStub) CreateVMs(ctx context.Context, vmParams clients.Azu
return vmIds, err
}
vmIds[i].ID = string(instanceID)
vmIds[i].PublicIPv4 = fmt.Sprintf("198.51.100.%d", i+1)
vmIds[i].IPv4 = fmt.Sprintf("198.51.100.%d", i+1)
}

return vmIds, nil
Expand Down
6 changes: 3 additions & 3 deletions internal/clients/stubs/ec2_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ func (mock *EC2ClientStub) DescribeInstanceDetails(ctx context.Context, Instance
ip := "54.11.88.17"
return []*clients.InstanceDescription{
{
ID: id,
PublicDNS: dns,
PublicIPv4: ip,
ID: id,
DNS: dns,
IPv4: ip,
},
}, nil
}
2 changes: 1 addition & 1 deletion internal/clients/stubs/gcp_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (mock *GCPClientStub) Status(ctx context.Context) error {
func (mock *GCPClientStub) GetInstanceDescriptionByID(ctx context.Context, id, zone string) (*clients.InstanceDescription, error) {
for _, instanceID := range mock.Instances {
if ptr.From(instanceID) == id {
instanceDesc := &clients.InstanceDescription{ID: id, PublicIPv4: fmt.Sprintf("10.0.0.%v", ipCounter)}
instanceDesc := &clients.InstanceDescription{ID: id, IPv4: fmt.Sprintf("10.0.0.%v", ipCounter)}
ipCounter = ipCounter + 1
return instanceDesc, nil
}
Expand Down
6 changes: 4 additions & 2 deletions internal/dao/pgx/reservation_pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ func (x *reservationDao) CreateInstance(ctx context.Context, instance *models.Re
func (x *reservationDao) UpdateReservationInstance(ctx context.Context, reservationID int64, instance *clients.InstanceDescription) error {
query := `UPDATE reservation_instances SET detail = $3 WHERE reservation_id = $1 AND instance_id = $2`
detail := &models.ReservationInstanceDetail{
PublicIPv4: instance.PublicIPv4,
PublicDNS: instance.PublicDNS,
PublicIPv4: instance.IPv4,
PublicDNS: instance.DNS,
PrivateIPv4: instance.PrivateIPv4,
PrivateIPv6: instance.PrivateIPv6,
}
tag, err := db.Pool.Exec(ctx, query, reservationID, instance.ID, detail)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/dao/stubs/reservation_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (stub *reservationDaoStub) Cleanup(ctx context.Context) error {
func (stub *reservationDaoStub) UpdateReservationInstance(ctx context.Context, reservationID int64, instance *clients.InstanceDescription) error {
for _, instRes := range stub.instances[reservationID] {
if instRes.InstanceID == instance.ID {
instRes.Detail.PublicIPv4 = instance.PublicIPv4
instRes.Detail.PublicIPv4 = instance.IPv4
}
}
return nil
Expand Down
11 changes: 9 additions & 2 deletions internal/jobs/launch_instance_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,27 @@ func FetchInstancesDescriptionAWS(ctx context.Context, args *LaunchInstanceAWSTa
span.SetStatus(codes.Error, "cannot get list instances description")
return fmt.Errorf("cannot get list instances description: %w", errRetry)
}
logger.Trace().Msgf("AWS returned %d instance details", len(instancesDescriptionList))

if len(instancesDescriptionList) == 0 {
return ErrTryAgain
}

for _, instance := range instancesDescriptionList {
for i, instance := range instancesDescriptionList {
logger.Trace().Msgf("Instance id %s private IPv4:%s public IPv4:%s DNS:%s",
instancesIDList[i],
instance.PrivateIPv4,
instance.IPv4,
instance.DNS,
)
errRetry := rDao.UpdateReservationInstance(ctx, args.ReservationID, instance)
if errRetry != nil {
span.SetStatus(codes.Error, "cannot update instance description")
return fmt.Errorf("cannot update instance description: %w", errRetry)
}
}
return nil
}, 1000, 500, 500, 1000, 2000)
}, 500, 500, 1000, 1000, 2000)

if err != nil {
span.SetStatus(codes.Error, "giving up")
Expand Down
2 changes: 1 addition & 1 deletion internal/jobs/launch_instance_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func DoLaunchInstanceAzure(ctx context.Context, args *LaunchInstanceAzureTaskArg
ReservationID: args.ReservationID,
InstanceID: instanceDescription.ID,
Detail: models.ReservationInstanceDetail{
PublicIPv4: instanceDescription.PublicIPv4,
PublicIPv4: instanceDescription.IPv4,
},
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/jobs/launch_instance_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func FetchInstancesDescriptionGCP(ctx context.Context, args *LaunchInstanceGCPTa
return fmt.Errorf("cannot get instance description : %w", err)
}

if instanceDesc.PublicIPv4 == "" {
if instanceDesc.IPv4 == "" {
return ErrTryAgain
}

Expand Down
6 changes: 4 additions & 2 deletions internal/models/reservation_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ type AzureReservation struct {
}

type ReservationInstanceDetail struct {
PublicDNS string `json:"public_dns"`
PublicIPv4 string `json:"public_ipv4"`
PublicDNS string `json:"public_dns"`
PublicIPv4 string `json:"public_ipv4"`
PrivateIPv4 string `json:"private_ipv4"`
PrivateIPv6 string `json:"private_ipv6"`
}

type ReservationInstance struct {
Expand Down
4 changes: 3 additions & 1 deletion scripts/rest_examples/http-client.env.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"prefix": "api/provisioning/v1",
"identity": "eyJpZGVudGl0eSI6IHsidHlwZSI6ICJVc2VyIiwgImFjY291bnRfbnVtYmVyIjoiMTMiLCAiaW50ZXJuYWwiOnsib3JnX2lkIjoiMDAwMDEzIn19fQo=",
"source_id": "1",
"source_id_aws": "1",
"source_id_azure": "2",
"source_id_gcp": "3",
"pubkey_id": "1",
"region": "us-east-1",
"launch_template_id": "",
"reservation-get-id": "1",
"azure-source-id": "2",
"azure-resource-group": "redhat-deployed"
}
}
2 changes: 1 addition & 1 deletion scripts/rest_examples/reservation-create-aws.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ X-Rh-Identity: {{identity}}

{
"name": "amz-linux-us-east-1",
"source_id": "1",
"source_id": "{{source_id_aws}}",
"image_id": "ami-05fa00d4c63e32376",
"amount": 1,
"launch_template_id": "{{launch_template_id}}",
Expand Down
2 changes: 1 addition & 1 deletion scripts/rest_examples/reservation-create-azure.http
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ X-Rh-Identity: {{identity}}
{
"name": "azure-linux-us-east",
"location": "eastus_1",
"source_id": "{{azure-source-id}}",
"source_id": "{{source_id_azure}}",
"image_id": "composer-api-e7e1c242-4ce8-4d5e-a5d0-75720e91afca",
"amount": 1,
"instance_size": "Standard_B1ls",
Expand Down
2 changes: 1 addition & 1 deletion scripts/rest_examples/reservation-create-gcp.http
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ X-Rh-Identity: {{identity}}
{
"name_pattern": "gcp-linux-eu-west8-c",
"zone": "europe-west8-c",
"source_id": "3",
"source_id": "{{source_id_gcp}}",
"image_id": "https://www.googleapis.com/compute/v1/projects/rhel-cloud/global/images/rhel-9-v20230411",
"amount": 1,
"machine_type": "e2-micro",
Expand Down