diff --git a/api/openapi.gen.json b/api/openapi.gen.json index 64d45f3b..d1b2023d 100644 --- a/api/openapi.gen.json +++ b/api/openapi.gen.json @@ -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" } @@ -80,6 +82,8 @@ "instances": [ { "detail": { + "privateipv4": "", + "privateipv6": "", "publicdns": "", "publicipv4": "10.0.0.88" }, @@ -129,6 +133,8 @@ "instances": [ { "detail": { + "privateipv4": "", + "privateipv6": "", "publicdns": "", "publicipv4": "10.0.0.88" }, @@ -589,6 +595,12 @@ "properties": { "detail": { "properties": { + "private_ipv4": { + "type": "string" + }, + "private_ipv6": { + "type": "string" + }, "public_dns": { "type": "string" }, @@ -705,6 +717,12 @@ "properties": { "detail": { "properties": { + "private_ipv4": { + "type": "string" + }, + "private_ipv6": { + "type": "string" + }, "public_dns": { "type": "string" }, @@ -796,6 +814,12 @@ "properties": { "detail": { "properties": { + "private_ipv4": { + "type": "string" + }, + "private_ipv6": { + "type": "string" + }, "public_dns": { "type": "string" }, @@ -1334,7 +1358,7 @@ "name": "GPL-3.0" }, "title": "provisioning-api", - "version": "1.7.0" + "version": "1.8.0" }, "openapi": "3.0.0", "paths": { diff --git a/api/openapi.gen.yaml b/api/openapi.gen.yaml index c8e42f9d..eeb61231 100644 --- a/api/openapi.gen.yaml +++ b/api/openapi.gen.yaml @@ -44,6 +44,10 @@ components: detail: type: object properties: + private_ipv4: + type: string + private_ipv6: + type: string public_dns: type: string public_ipv4: @@ -121,6 +125,10 @@ components: detail: type: object properties: + private_ipv4: + type: string + private_ipv6: + type: string public_dns: type: string public_ipv4: @@ -182,6 +190,10 @@ components: detail: type: object properties: + private_ipv4: + type: string + private_ipv6: + type: string public_dns: type: string public_ipv4: @@ -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 @@ -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 @@ -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" @@ -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: diff --git a/cmd/spec/VERSION b/cmd/spec/VERSION index bd8bf882..27f9cd32 100644 --- a/cmd/spec/VERSION +++ b/cmd/spec/VERSION @@ -1 +1 @@ -1.7.0 +1.8.0 diff --git a/cmd/spec/example_reservation.go b/cmd/spec/example_reservation.go index 58ae19aa..937aaa99 100644 --- a/cmd/spec/example_reservation.go +++ b/cmd/spec/example_reservation.go @@ -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", }}, }, } diff --git a/internal/clients/http/azure/create_vms.go b/internal/clients/http/azure/create_vms.go index 0c5d838d..4b6067b0 100644 --- a/internal/clients/http/azure/create_vms.go +++ b/internal/clients/http/azure/create_vms.go @@ -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 { diff --git a/internal/clients/http/ec2/ec2_client.go b/internal/clients/http/ec2/ec2_client.go index 8a756f43..88c5eee6 100644 --- a/internal/clients/http/ec2/ec2_client.go +++ b/internal/clients/http/ec2/ec2_client.go @@ -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 diff --git a/internal/clients/http/gcp/gcp_client.go b/internal/clients/http/gcp/gcp_client.go index 0b2e1d21..9fea6c74 100644 --- a/internal/clients/http/gcp/gcp_client.go +++ b/internal/clients/http/gcp/gcp_client.go @@ -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 } } diff --git a/internal/clients/instance_description.go b/internal/clients/instance_description.go index 76fb9ddb..ba5b8543 100644 --- a/internal/clients/instance_description.go +++ b/internal/clients/instance_description.go @@ -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"` } diff --git a/internal/clients/stubs/azure_stub.go b/internal/clients/stubs/azure_stub.go index fa7a79ec..ccae65d3 100644 --- a/internal/clients/stubs/azure_stub.go +++ b/internal/clients/stubs/azure_stub.go @@ -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 diff --git a/internal/clients/stubs/ec2_stub.go b/internal/clients/stubs/ec2_stub.go index c9c5cc57..d9405a2a 100644 --- a/internal/clients/stubs/ec2_stub.go +++ b/internal/clients/stubs/ec2_stub.go @@ -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 } diff --git a/internal/clients/stubs/gcp_stub.go b/internal/clients/stubs/gcp_stub.go index 738d9320..7ca9bc2a 100644 --- a/internal/clients/stubs/gcp_stub.go +++ b/internal/clients/stubs/gcp_stub.go @@ -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 } diff --git a/internal/dao/pgx/reservation_pgx.go b/internal/dao/pgx/reservation_pgx.go index 84cea996..f0b69c82 100644 --- a/internal/dao/pgx/reservation_pgx.go +++ b/internal/dao/pgx/reservation_pgx.go @@ -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 { diff --git a/internal/dao/stubs/reservation_dao.go b/internal/dao/stubs/reservation_dao.go index 407b2f4e..cc0eadf2 100644 --- a/internal/dao/stubs/reservation_dao.go +++ b/internal/dao/stubs/reservation_dao.go @@ -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 diff --git a/internal/jobs/launch_instance_aws.go b/internal/jobs/launch_instance_aws.go index a8f8ffa3..e3d63dd7 100644 --- a/internal/jobs/launch_instance_aws.go +++ b/internal/jobs/launch_instance_aws.go @@ -308,12 +308,19 @@ 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") @@ -321,7 +328,7 @@ func FetchInstancesDescriptionAWS(ctx context.Context, args *LaunchInstanceAWSTa } } return nil - }, 1000, 500, 500, 1000, 2000) + }, 500, 500, 1000, 1000, 2000) if err != nil { span.SetStatus(codes.Error, "giving up") diff --git a/internal/jobs/launch_instance_azure.go b/internal/jobs/launch_instance_azure.go index 9e69d2c5..1e99efc2 100644 --- a/internal/jobs/launch_instance_azure.go +++ b/internal/jobs/launch_instance_azure.go @@ -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 { diff --git a/internal/jobs/launch_instance_gcp.go b/internal/jobs/launch_instance_gcp.go index 23319e3c..81e1728a 100644 --- a/internal/jobs/launch_instance_gcp.go +++ b/internal/jobs/launch_instance_gcp.go @@ -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 } diff --git a/internal/models/reservation_model.go b/internal/models/reservation_model.go index c8b56e5b..2dbd28df 100644 --- a/internal/models/reservation_model.go +++ b/internal/models/reservation_model.go @@ -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 { diff --git a/scripts/rest_examples/http-client.env.json b/scripts/rest_examples/http-client.env.json index 766f7cbb..b595eb36 100644 --- a/scripts/rest_examples/http-client.env.json +++ b/scripts/rest_examples/http-client.env.json @@ -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" } } diff --git a/scripts/rest_examples/reservation-create-aws.http b/scripts/rest_examples/reservation-create-aws.http index a5b530e0..5d4afcae 100644 --- a/scripts/rest_examples/reservation-create-aws.http +++ b/scripts/rest_examples/reservation-create-aws.http @@ -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}}", diff --git a/scripts/rest_examples/reservation-create-azure.http b/scripts/rest_examples/reservation-create-azure.http index 008ae68c..b7c618e7 100644 --- a/scripts/rest_examples/reservation-create-azure.http +++ b/scripts/rest_examples/reservation-create-azure.http @@ -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", diff --git a/scripts/rest_examples/reservation-create-gcp.http b/scripts/rest_examples/reservation-create-gcp.http index 5c120f41..d89b77b7 100644 --- a/scripts/rest_examples/reservation-create-gcp.http +++ b/scripts/rest_examples/reservation-create-gcp.http @@ -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",