From 7b0e7b21bfcd242c30b93a0f0b29bc454a71fbec Mon Sep 17 00:00:00 2001 From: Mengling Ding Date: Mon, 9 Dec 2024 15:19:26 -0600 Subject: [PATCH] docs: update comments for the device name formatting --- services/discovery.go | 13 +++++-------- webui/src/components/Stores/ApplianceStore.ts | 6 +++--- webui/src/components/Stores/HostStore.ts | 7 ++++--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/services/discovery.go b/services/discovery.go index 0792286..442fef3 100644 --- a/services/discovery.go +++ b/services/discovery.go @@ -12,7 +12,7 @@ import ( "cfm/pkg/openapi" ) -// discoverDevices function to call the DiscoverDevices API +// DiscoverDevices function to call the DiscoverDevices API func DiscoverDevices(ctx context.Context, apiService openapi.DefaultAPIServicer, deviceType string) (openapi.ImplResponse, error) { resp, _ := apiService.DiscoverDevices(ctx, deviceType) if resp.Code >= 300 { @@ -36,7 +36,6 @@ func AddDiscoveredDevices(ctx context.Context, apiService openapi.DefaultAPIServ } // Add blades - // Convert data type bladeBodyBytes, ok := blades.Body.([]*openapi.DiscoveredDevice) if !ok { log.Fatalf("Response body is not []byte") @@ -47,10 +46,9 @@ func AddDiscoveredDevices(ctx context.Context, apiService openapi.DefaultAPIServ if !exist { newCredentials := *common.DefaultBladeCredentials newCredentials.IpAddress = bladeDevice.Address - //Assign the actual device name to customId - // Handle the device name to remove the tag local - deviceName := strings.SplitN(bladeDevice.Name, ".", 2)[0] + // Remove the .local suffix (e.g. blade device name: granite00.local) from the device name by splitting it with . and assign it to the customId + deviceName := strings.SplitN(bladeDevice.Name, ".", 2)[0] newCredentials.CustomId = deviceName applianceDatum.AddBladeDatum(&newCredentials) @@ -59,7 +57,6 @@ func AddDiscoveredDevices(ctx context.Context, apiService openapi.DefaultAPIServ } // Add cxl-hosts - // Convert data type hostBodyBytes, ok := hosts.Body.([]*openapi.DiscoveredDevice) if !ok { log.Fatalf("Response body is not []byte") @@ -69,8 +66,8 @@ func AddDiscoveredDevices(ctx context.Context, apiService openapi.DefaultAPIServ if !exist { newCredentials := *common.DefaultHostCredentials newCredentials.IpAddress = hostDevice.Address - //Assign the actual device name to customId - // Handle the device name to remove the tag local + + // Remove the .local suffix (e.g. host device name: host00.local) from the device name by splitting it with . and assign it to the customId deviceName := strings.SplitN(hostDevice.Name, ".", 2)[0] newCredentials.CustomId = deviceName diff --git a/webui/src/components/Stores/ApplianceStore.ts b/webui/src/components/Stores/ApplianceStore.ts index f8d2809..30e46c4 100644 --- a/webui/src/components/Stores/ApplianceStore.ts +++ b/webui/src/components/Stores/ApplianceStore.ts @@ -139,7 +139,7 @@ export const useApplianceStore = defineStore('appliance', { } } - //Handle the discovered device name, remove the tag local + // Format the device name, remove the .local suffix (e.g. blade device name: granite00.local) from the device name by splitting it with . for (var n = 0; n < this.discoveredBlades.length; n++) { this.discoveredBlades[n].name = this.discoveredBlades[n].name!.split('.')[0] } @@ -167,13 +167,13 @@ export const useApplianceStore = defineStore('appliance', { } } - // Add the new discovered blade to the default appliance let appliance = this.applianceIds.find(appliance => appliance.id === this.defaultApplianceId); - + // Remove the .local suffix (e.g. blade device name: granite00.local) from the device name by splitting it with . and assign it to the customId let deviceName = blade.name!.split('.')[0]; this.newBladeCredentials.customId = deviceName; this.newBladeCredentials.ipAddress = blade.address + ""; + // Add the new discovered blade to the default appliance const responseOfBlade = await defaultApi.bladesPost(this.defaultApplianceId, this.newBladeCredentials); if (responseOfBlade) { diff --git a/webui/src/components/Stores/HostStore.ts b/webui/src/components/Stores/HostStore.ts index 4207478..aec5531 100644 --- a/webui/src/components/Stores/HostStore.ts +++ b/webui/src/components/Stores/HostStore.ts @@ -102,7 +102,7 @@ export const useHostStore = defineStore('host', { } } - //Handle the discovered device name, remove the tag local + // Format the device name, remove the .local suffix (e.g. host device name: host00.local) from the device name by splitting it with . for (var n = 0; n < this.discoveredHosts.length; n++) { this.discoveredHosts[n].name = this.discoveredHosts[n].name!.split('.')[0] } @@ -116,14 +116,15 @@ export const useHostStore = defineStore('host', { async addDiscoveredHosts(host: DiscoveredDevice) { const defaultApi = new DefaultApi(undefined, API_BASE_PATH); - // Add all the new didcovered hosts + // Remove the .local suffix (e.g. host device name: host00.local) from the device name by splitting it with . and assign it to the customId let deviceName = host.name!.split('.')[0]; this.newHostCredentials.customId = deviceName; this.newHostCredentials.ipAddress = host.address + ""; + // Add the new didcovered host const responseOfHost = await defaultApi.hostsPost(this.newHostCredentials); - // Update the applianceIds and appliances + // Update the hostIds and hosts if (responseOfHost) { const response = { id: responseOfHost.data.id, ipAddress: responseOfHost.data.ipAddress, status: responseOfHost.data.status } this.hosts.push(responseOfHost.data);