From 1800684e546e60baf08effca41cc95a49ada1003 Mon Sep 17 00:00:00 2001 From: kpdhulipala Date: Fri, 9 Feb 2024 12:09:27 -0800 Subject: [PATCH 1/3] project id filter on get accounts --- client.go | 9 +++++---- internal/api/account.go | 15 ++++++++------- rest_account.go | 11 ++++++----- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/client.go b/client.go index ee51f85..6e2483d 100644 --- a/client.go +++ b/client.go @@ -230,10 +230,11 @@ func (e UpdateError) Error() string { // Account describes Network Edge customer account details type Account struct { - Name *string - Number *string - Status *string - UCMID *string + Name *string + Number *string + Status *string + UCMID *string + ProjectID *string } // Device describes Network Edge device diff --git a/internal/api/account.go b/internal/api/account.go index 37f63ac..8eb6b77 100644 --- a/internal/api/account.go +++ b/internal/api/account.go @@ -1,15 +1,16 @@ package api -//AccountResponse describes response to Network Edge -//billing account query +// AccountResponse describes response to Network Edge +// billing account query type AccountResponse struct { Accounts []Account `json:"accounts,omitempty"` } -//Account describes Network Edge billing account +// Account describes Network Edge billing account type Account struct { - Name *string `json:"accountName,omitempty"` - Number *string `json:"accountNumber,omitempty"` - UCMID *string `json:"accountUcmId,omitempty"` - Status *string `json:"accountStatus,omitempty"` + Name *string `json:"accountName,omitempty"` + Number *string `json:"accountNumber,omitempty"` + UCMID *string `json:"accountUcmId,omitempty"` + Status *string `json:"accountStatus,omitempty"` + ProjectID *string `json:"projectId,omitempty"` } diff --git a/rest_account.go b/rest_account.go index 1320834..ed61a2a 100644 --- a/rest_account.go +++ b/rest_account.go @@ -7,7 +7,7 @@ import ( "github.com/equinix/ne-go/internal/api" ) -//GetAccounts retrieves accounts and their details for a given metro code using Network Edge API +// GetAccounts retrieves accounts and their details for a given metro code using Network Edge API func (c RestClient) GetAccounts(metroCode string) ([]Account, error) { path := "/ne/v1/accounts/" + url.PathEscape(metroCode) respBody := api.AccountResponse{} @@ -23,10 +23,11 @@ func mapAccountsAPIToDomain(apiAccounts []api.Account) []Account { transformed := make([]Account, len(apiAccounts)) for i := range apiAccounts { transformed[i] = Account{ - Name: apiAccounts[i].Name, - Number: apiAccounts[i].Number, - UCMID: apiAccounts[i].UCMID, - Status: apiAccounts[i].Status, + Name: apiAccounts[i].Name, + Number: apiAccounts[i].Number, + UCMID: apiAccounts[i].UCMID, + Status: apiAccounts[i].Status, + ProjectID: apiAccounts[i].ProjectID, } } return transformed From 928bf72d79313eed86a53a93fe5f0687e5d704ce Mon Sep 17 00:00:00 2001 From: kpdhulipala Date: Fri, 9 Feb 2024 12:14:58 -0800 Subject: [PATCH 2/3] assertion for proj id --- rest_account_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/rest_account_test.go b/rest_account_test.go index 7126f1c..70b70c1 100644 --- a/rest_account_test.go +++ b/rest_account_test.go @@ -38,4 +38,5 @@ func verifyAccount(t *testing.T, apiAccount api.Account, account Account) { assert.Equal(t, apiAccount.Number, account.Number, "Account Number matches") assert.Equal(t, apiAccount.Status, account.Status, "Account Status matches") assert.Equal(t, apiAccount.UCMID, account.UCMID, "Account UCMID matches") + assert.Equal(t, apiAccount.ProjectID, account.ProjectID, "ProjectID matches") } From d1eab1b8f6f45695ad11abd8beb4b1a3d15da9b1 Mon Sep 17 00:00:00 2001 From: kpdhulipala Date: Fri, 16 Feb 2024 21:29:00 -0800 Subject: [PATCH 3/3] Added support to send diverse device uuid in Create Single Device --- client.go | 88 +++++++++++++------------ internal/api/device.go | 145 +++++++++++++++++++++-------------------- rest_device.go | 3 + rest_device_test.go | 48 +++++++------- 4 files changed, 147 insertions(+), 137 deletions(-) diff --git a/client.go b/client.go index 6e2483d..6580210 100644 --- a/client.go +++ b/client.go @@ -239,49 +239,51 @@ type Account struct { // Device describes Network Edge device type Device struct { - UUID *string - Name *string - TypeCode *string - Status *string - LicenseStatus *string - MetroCode *string - IBX *string - Region *string - Throughput *int - ThroughputUnit *string - HostName *string - PackageCode *string - Version *string - IsBYOL *bool - LicenseToken *string - LicenseFile *string - CloudInitFile *string - LicenseFileID *string - CloudInitFileID *string - ACLTemplateUUID *string - MgmtAclTemplateUuid *string - SSHIPAddress *string - SSHIPFqdn *string - AccountNumber *string - Notifications []string - PurchaseOrderNumber *string - RedundancyType *string - RedundantUUID *string - TermLength *int - AdditionalBandwidth *int - OrderReference *string - InterfaceCount *int - CoreCount *int - IsSelfManaged *bool - Connectivity *string - WanInterfaceId *string - Interfaces []DeviceInterface - VendorConfiguration map[string]string - UserPublicKey *DeviceUserPublicKey - ASN *int - ZoneCode *string - ClusterDetails *ClusterDetails - ProjectID *string + UUID *string + Name *string + TypeCode *string + Status *string + LicenseStatus *string + MetroCode *string + IBX *string + Region *string + Throughput *int + ThroughputUnit *string + HostName *string + PackageCode *string + Version *string + IsBYOL *bool + LicenseToken *string + LicenseFile *string + CloudInitFile *string + LicenseFileID *string + CloudInitFileID *string + ACLTemplateUUID *string + MgmtAclTemplateUuid *string + SSHIPAddress *string + SSHIPFqdn *string + AccountNumber *string + Notifications []string + PurchaseOrderNumber *string + RedundancyType *string + RedundantUUID *string + TermLength *int + AdditionalBandwidth *int + OrderReference *string + InterfaceCount *int + CoreCount *int + IsSelfManaged *bool + Connectivity *string + WanInterfaceId *string + Interfaces []DeviceInterface + VendorConfiguration map[string]string + UserPublicKey *DeviceUserPublicKey + ASN *int + ZoneCode *string + ClusterDetails *ClusterDetails + ProjectID *string + DiverseFromDeviceUUID *string + DiverseFromDeviceName *string } // DeviceInterface describes Network Edge device interface diff --git a/internal/api/device.go b/internal/api/device.go index f3b2d3b..494d468 100644 --- a/internal/api/device.go +++ b/internal/api/device.go @@ -2,81 +2,84 @@ package api // Device describes network edge device type Device struct { - UUID *string `json:"uuid,omitempty"` - Name *string `json:"name,omitempty"` - DeviceTypeCode *string `json:"deviceTypeCode,omitempty"` - Status *string `json:"status,omitempty"` - LicenseStatus *string `json:"licenseStatus,omitempty"` - MetroCode *string `json:"metroCode,omitempty"` - IBX *string `json:"ibx,omitempty"` - Region *string `json:"region,omitempty"` - Throughput *int `json:"throughput,omitempty,string"` - ThroughputUnit *string `json:"throughputUnit,omitempty"` - HostName *string `json:"hostName,omitempty"` - PackageCode *string `json:"packageCode,omitempty"` - Version *string `json:"version,omitempty"` - LicenseToken *string `json:"licenseToken,omitempty"` - LicenseType *string `json:"licenseType,omitempty"` - LicenseFileID *string `json:"licenseFileId,omitempty"` - CloudInitFileID *string `json:"CloudInitFileId,omitempty"` - ACLTemplateUUID *string `json:"aclTemplateUuid,omitempty"` - MgmtAclTemplateUUID *string `json:"mgmtAclTemplateUuid,omitempty"` - SSHIPAddress *string `json:"sshIpAddress,omitempty"` - SSHIPFqdn *string `json:"sshIpFqdn,omitempty"` - AccountNumber *string `json:"accountNumber,omitempty"` - Notifications []string `json:"notifications,omitempty"` - PurchaseOrderNumber *string `json:"purchaseOrderNumber,omitempty"` - RedundancyType *string `json:"redundancyType,omitempty"` - RedundantUUID *string `json:"redundantUuid,omitempty"` - TermLength *int `json:"termLength,omitempty"` - AdditionalBandwidth *int `json:"additionalBandwidth,omitempty"` - OrderReference *string `json:"orderReference,omitempty"` - InterfaceCount *int `json:"interfaceCount,omitempty"` - Core *DeviceCoreInformation `json:"core,omitempty"` - DeviceManagementType *string `json:"deviceManagementType,omitempty"` - SshInterfaceID *string `json:"sshInterfaceId,omitempty"` - Interfaces []DeviceInterface `json:"interfaces,omitempty"` - VendorConfig map[string]string `json:"vendorConfig,omitempty"` - UserPublicKey *DeviceUserPublicKey `json:"userPublicKey,omitempty"` - ASN *int `json:"asn,omitempty"` - ZoneCode *string `json:"zoneCode,omitempty"` - ClusterDetails *ClusterDetails `json:"clusterDetails,omitempty"` - Connectivity *string `json:"connectivity,omitempty"` - ProjectID *string `json:"projectId,omitempty"` + UUID *string `json:"uuid,omitempty"` + Name *string `json:"name,omitempty"` + DeviceTypeCode *string `json:"deviceTypeCode,omitempty"` + Status *string `json:"status,omitempty"` + LicenseStatus *string `json:"licenseStatus,omitempty"` + MetroCode *string `json:"metroCode,omitempty"` + IBX *string `json:"ibx,omitempty"` + Region *string `json:"region,omitempty"` + Throughput *int `json:"throughput,omitempty,string"` + ThroughputUnit *string `json:"throughputUnit,omitempty"` + HostName *string `json:"hostName,omitempty"` + PackageCode *string `json:"packageCode,omitempty"` + Version *string `json:"version,omitempty"` + LicenseToken *string `json:"licenseToken,omitempty"` + LicenseType *string `json:"licenseType,omitempty"` + LicenseFileID *string `json:"licenseFileId,omitempty"` + CloudInitFileID *string `json:"CloudInitFileId,omitempty"` + ACLTemplateUUID *string `json:"aclTemplateUuid,omitempty"` + MgmtAclTemplateUUID *string `json:"mgmtAclTemplateUuid,omitempty"` + SSHIPAddress *string `json:"sshIpAddress,omitempty"` + SSHIPFqdn *string `json:"sshIpFqdn,omitempty"` + AccountNumber *string `json:"accountNumber,omitempty"` + Notifications []string `json:"notifications,omitempty"` + PurchaseOrderNumber *string `json:"purchaseOrderNumber,omitempty"` + RedundancyType *string `json:"redundancyType,omitempty"` + RedundantUUID *string `json:"redundantUuid,omitempty"` + TermLength *int `json:"termLength,omitempty"` + AdditionalBandwidth *int `json:"additionalBandwidth,omitempty"` + OrderReference *string `json:"orderReference,omitempty"` + InterfaceCount *int `json:"interfaceCount,omitempty"` + Core *DeviceCoreInformation `json:"core,omitempty"` + DeviceManagementType *string `json:"deviceManagementType,omitempty"` + SshInterfaceID *string `json:"sshInterfaceId,omitempty"` + Interfaces []DeviceInterface `json:"interfaces,omitempty"` + VendorConfig map[string]string `json:"vendorConfig,omitempty"` + UserPublicKey *DeviceUserPublicKey `json:"userPublicKey,omitempty"` + ASN *int `json:"asn,omitempty"` + ZoneCode *string `json:"zoneCode,omitempty"` + ClusterDetails *ClusterDetails `json:"clusterDetails,omitempty"` + Connectivity *string `json:"connectivity,omitempty"` + ProjectID *string `json:"projectId,omitempty"` + DiverseFromDeviceUUID *string `json:"diverseFromDeviceUuid,omitempty"` + DiverseFromDeviceName *string `json:"diverseFromDeviceName,omitempty"` } // DeviceRequest describes network edge device creation request type DeviceRequest struct { - Throughput *int `json:"throughput,omitempty,string"` - ThroughputUnit *string `json:"throughputUnit,omitempty"` - MetroCode *string `json:"metroCode,omitempty"` - DeviceTypeCode *string `json:"deviceTypeCode,omitempty"` - TermLength *string `json:"termLength,omitempty"` - LicenseMode *string `json:"licenseMode,omitempty"` - LicenseToken *string `json:"licenseToken,omitempty"` - LicenseFileID *string `json:"licenseFileId,omitempty"` - CloudInitFileID *string `json:"cloudInitFileId,omitempty"` - PackageCode *string `json:"packageCode,omitempty"` - VirtualDeviceName *string `json:"virtualDeviceName,omitempty"` - Notifications []string `json:"notifications,omitempty"` - HostNamePrefix *string `json:"hostNamePrefix,omitempty"` - OrderReference *string `json:"orderReference,omitempty"` - PurchaseOrderNumber *string `json:"purchaseOrderNumber,omitempty"` - AccountNumber *string `json:"accountNumber,omitempty"` - Version *string `json:"version,omitempty"` - InterfaceCount *int `json:"interfaceCount,omitempty"` - DeviceManagementType *string `json:"deviceManagementType,omitempty"` - SshInterfaceId *string `json:"sshInterfaceId,omitempty"` - Core *int `json:"core,omitempty"` - AdditionalBandwidth *int `json:"additionalBandwidth,omitempty,string"` - ACLTemplateUUID *string `json:"aclTemplateUuid,omitempty"` - MgmtAclTemplateUUID *string `json:"mgmtAclTemplateUuid,omitempty"` - VendorConfig map[string]string `json:"vendorConfig,omitempty"` - UserPublicKey *DeviceUserPublicKeyRequest `json:"userPublicKey,omitempty"` - Secondary *SecondaryDeviceRequest `json:"secondary,omitempty"` - ClusterDetails *ClusterDetailsRequest `json:"clusterDetails,omitempty"` - Connectivity *string `json:"connectivity,omitempty"` - ProjectID *string `json:"projectId,omitempty"` + Throughput *int `json:"throughput,omitempty,string"` + ThroughputUnit *string `json:"throughputUnit,omitempty"` + MetroCode *string `json:"metroCode,omitempty"` + DeviceTypeCode *string `json:"deviceTypeCode,omitempty"` + TermLength *string `json:"termLength,omitempty"` + LicenseMode *string `json:"licenseMode,omitempty"` + LicenseToken *string `json:"licenseToken,omitempty"` + LicenseFileID *string `json:"licenseFileId,omitempty"` + CloudInitFileID *string `json:"cloudInitFileId,omitempty"` + PackageCode *string `json:"packageCode,omitempty"` + VirtualDeviceName *string `json:"virtualDeviceName,omitempty"` + Notifications []string `json:"notifications,omitempty"` + HostNamePrefix *string `json:"hostNamePrefix,omitempty"` + OrderReference *string `json:"orderReference,omitempty"` + PurchaseOrderNumber *string `json:"purchaseOrderNumber,omitempty"` + AccountNumber *string `json:"accountNumber,omitempty"` + Version *string `json:"version,omitempty"` + InterfaceCount *int `json:"interfaceCount,omitempty"` + DeviceManagementType *string `json:"deviceManagementType,omitempty"` + SshInterfaceId *string `json:"sshInterfaceId,omitempty"` + Core *int `json:"core,omitempty"` + AdditionalBandwidth *int `json:"additionalBandwidth,omitempty,string"` + ACLTemplateUUID *string `json:"aclTemplateUuid,omitempty"` + MgmtAclTemplateUUID *string `json:"mgmtAclTemplateUuid,omitempty"` + VendorConfig map[string]string `json:"vendorConfig,omitempty"` + UserPublicKey *DeviceUserPublicKeyRequest `json:"userPublicKey,omitempty"` + Secondary *SecondaryDeviceRequest `json:"secondary,omitempty"` + ClusterDetails *ClusterDetailsRequest `json:"clusterDetails,omitempty"` + Connectivity *string `json:"connectivity,omitempty"` + ProjectID *string `json:"projectId,omitempty"` + DiverseFromDeviceUUID *string `json:"diverseFromDeviceUuid,omitempty"` } // SecondaryDeviceRequest describes secondary device part of device creation request diff --git a/rest_device.go b/rest_device.go index a826554..b18a653 100644 --- a/rest_device.go +++ b/rest_device.go @@ -264,6 +264,8 @@ func mapDeviceAPIToDomain(apiDevice api.Device) *Device { device.ASN = apiDevice.ASN device.ZoneCode = apiDevice.ZoneCode device.ClusterDetails = mapDeviceClusterDetailsAPIToDomain(apiDevice.ClusterDetails) + device.DiverseFromDeviceUUID = apiDevice.DiverseFromDeviceUUID + device.DiverseFromDeviceName = apiDevice.DiverseFromDeviceName return &device } @@ -405,6 +407,7 @@ func createDeviceRequest(device Device) api.DeviceRequest { req.VendorConfig = device.VendorConfiguration req.UserPublicKey = mapDeviceUserPublicKeyDomainToAPI(device.UserPublicKey) req.ClusterDetails = mapDeviceClusterDetailsDomainToAPI(device.ClusterDetails) + req.DiverseFromDeviceUUID = device.DiverseFromDeviceUUID return req } diff --git a/rest_device_test.go b/rest_device_test.go index e4cda06..32738fc 100644 --- a/rest_device_test.go +++ b/rest_device_test.go @@ -15,29 +15,30 @@ import ( ) var testDevice = Device{ - AdditionalBandwidth: Int(100), - TypeCode: String("PA-VM"), - HostName: String("myhostSRmy"), - IsBYOL: Bool(true), - LicenseToken: String("somelicensetokenaaaaazzzzz"), - LicenseFileID: String("8d180057-8309-4c59-b645-f630f010ad43"), - CloudInitFileID: String("9318885d-4b8c-48a5-9aa4-24387834ebae"), - MetroCode: String("SV"), - Notifications: []string{"test1@example.com", "test2@example.com"}, - PackageCode: String("VM100"), - TermLength: Int(24), - ProjectID: String("68ccfd49-39b1-478e-957a-67c72f719d7a"), - Throughput: Int(1), - ThroughputUnit: String("Gbps"), - Name: String("PaloAltoSRmy"), - ACLTemplateUUID: String("4792d9ab-b8aa-49cc-8fe2-b56ced6c9c2f"), - AccountNumber: String("1777643"), - OrderReference: String("orderRef"), - PurchaseOrderNumber: String("PO123456789"), - InterfaceCount: Int(10), - CoreCount: Int(2), - Version: String("10.09.05"), - IsSelfManaged: Bool(true), + AdditionalBandwidth: Int(100), + TypeCode: String("PA-VM"), + HostName: String("myhostSRmy"), + IsBYOL: Bool(true), + LicenseToken: String("somelicensetokenaaaaazzzzz"), + LicenseFileID: String("8d180057-8309-4c59-b645-f630f010ad43"), + CloudInitFileID: String("9318885d-4b8c-48a5-9aa4-24387834ebae"), + MetroCode: String("SV"), + Notifications: []string{"test1@example.com", "test2@example.com"}, + PackageCode: String("VM100"), + TermLength: Int(24), + ProjectID: String("68ccfd49-39b1-478e-957a-67c72f719d7a"), + DiverseFromDeviceUUID: String("ed7891bd-15b4-4f72-ac56-d96cfdacddcc"), + Throughput: Int(1), + ThroughputUnit: String("Gbps"), + Name: String("PaloAltoSRmy"), + ACLTemplateUUID: String("4792d9ab-b8aa-49cc-8fe2-b56ced6c9c2f"), + AccountNumber: String("1777643"), + OrderReference: String("orderRef"), + PurchaseOrderNumber: String("PO123456789"), + InterfaceCount: Int(10), + CoreCount: Int(2), + Version: String("10.09.05"), + IsSelfManaged: Bool(true), VendorConfiguration: map[string]string{ "serialNumber": "12312312", "controller1": "1.1.1.1", @@ -503,6 +504,7 @@ func verifyDeviceRequest(t *testing.T, device Device, req api.DeviceRequest) { termLengthStr := strconv.Itoa(*device.TermLength) assert.Equal(t, &termLengthStr, req.TermLength, "TermLength matches") assert.Equal(t, device.ProjectID, req.ProjectID, "Project Id matches") + assert.Equal(t, device.DiverseFromDeviceUUID, req.DiverseFromDeviceUUID, "Diverse from Device UUID matches") if *device.IsBYOL { assert.Equal(t, DeviceLicenseModeBYOL, StringValue(req.LicenseMode), "LicenseMode matches") } else {