Skip to content

Commit

Permalink
docs: update comments for the device name formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Meng-20 committed Dec 9, 2024
1 parent b12367b commit 7b0e7b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
13 changes: 5 additions & 8 deletions services/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions webui/src/components/Stores/ApplianceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions webui/src/components/Stores/HostStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand All @@ -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);
Expand Down

0 comments on commit 7b0e7b2

Please sign in to comment.