Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/update_resource_…
Browse files Browse the repository at this point in the history
…status_in_webui
  • Loading branch information
Meng-20 committed Dec 10, 2024
2 parents 7c313d6 + 401c2c0 commit d4b6d41
Show file tree
Hide file tree
Showing 7 changed files with 588 additions and 482 deletions.
26 changes: 18 additions & 8 deletions cmd/cfm-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,27 @@ func main() {
defaultRedfishController := redfishapi.NewDefaultAPIController(defaultRedfishService)
api.AddRedfishRouter(ctx, router, defaultRedfishController)

// Discover devices before loading datastore
bladeDevices, errBlade := services.DiscoverDevices(ctx, defaultApiService, "blade")
hostDevices, errHost := services.DiscoverDevices(ctx, defaultApiService, "cxl-host")
// Add the discovered devices into datastore
if errBlade == nil && errHost == nil {
services.AddDiscoveredDevices(ctx, defaultApiService, bladeDevices, hostDevices)
}

// Load datastore
datastore.DStore().Restore()
data := datastore.DStore().GetDataStore()

// Check if there are any devices in the data store
bladeExist := len(data.ApplianceData) != 0
hostExist := len(data.HostData) != 0

// If there are no devices in the data store, do discovery, otherwise skip
if !bladeExist && !hostExist {
// Discover devices before loading datastore
bladeDevices, errBlade := services.DiscoverDevices(ctx, defaultApiService, "blade")
hostDevices, errHost := services.DiscoverDevices(ctx, defaultApiService, "cxl-host")
// Add the discovered devices into datastore
if errBlade == nil && errHost == nil {
services.AddDiscoveredDevices(ctx, defaultApiService, bladeDevices, hostDevices)
}
// Update data
data = datastore.DStore().GetDataStore()
}

datastore.ReloadDataStore(ctx, defaultApiService, data)

// Set up CORS middleware (for webui)
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var DefaultBladeCredentials = &openapi.Credentials{
Port: 443,
Insecure: true,
Protocol: "https",
CustomId: "Discoverd_Blade_",
CustomId: "",
}

var DefaultHostCredentials = &openapi.Credentials{
Expand All @@ -38,5 +38,5 @@ var DefaultHostCredentials = &openapi.Credentials{
Port: 8082,
Insecure: true,
Protocol: "http",
CustomId: "Discoverd_Host_",
CustomId: "",
}
17 changes: 10 additions & 7 deletions services/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package services
import (
"fmt"
"log"
"strings"

"golang.org/x/net/context"

Expand All @@ -11,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 @@ -35,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 @@ -46,16 +46,17 @@ func AddDiscoveredDevices(ctx context.Context, apiService openapi.DefaultAPIServ
if !exist {
newCredentials := *common.DefaultBladeCredentials
newCredentials.IpAddress = bladeDevice.Address
//Assign the actual ipAddress to customId to ensure its uniqueness
newCredentials.CustomId = newCredentials.CustomId + bladeDevice.Address

// 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)
datastore.DStore().Store()
}
}

// Add cxl-hosts
// Convert data type
hostBodyBytes, ok := hosts.Body.([]*openapi.DiscoveredDevice)
if !ok {
log.Fatalf("Response body is not []byte")
Expand All @@ -65,8 +66,10 @@ func AddDiscoveredDevices(ctx context.Context, apiService openapi.DefaultAPIServ
if !exist {
newCredentials := *common.DefaultHostCredentials
newCredentials.IpAddress = hostDevice.Address
//Assign the actual ipAddress to customId to ensure its uniqueness
newCredentials.CustomId = newCredentials.CustomId + hostDevice.Address

// 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

datastore.DStore().GetDataStore().AddHostDatum(&newCredentials)
datastore.DStore().Store()
Expand Down
4 changes: 2 additions & 2 deletions webui/src/components/Appliance/Memory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
</template>

<script>
import { computed, ref, watchEffect } from "vue";
import { computed } from "vue";
import { useBladeMemoryStore } from "../Stores/BladeMemoryStore";
import { useBladePortStore } from "../Stores/BladePortStore";
import { useBladeResourceStore } from "../Stores/BladeResourceStore";
Expand Down Expand Up @@ -568,4 +568,4 @@ export default {
};
},
};
</script>
</script>
6 changes: 3 additions & 3 deletions webui/src/components/Dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
style="margin-bottom: 40px"
variant="tonal"
>
Click to discover new devices</v-btn
Discover new devices</v-btn
>
</v-col>
</v-row>
Expand Down Expand Up @@ -323,7 +323,7 @@ export default {
if (this.selectedBlades.length === 0) {
console.log("No blades selected.");
} else {
for (var i = 0; i < this.selectedBlades.length; i++) {
for (let i = 0; i < this.selectedBlades.length; i++) {
try {
const newAddedBlade = await applianceStore.addDiscoveredBlades(
this.selectedBlades[i]
Expand All @@ -341,7 +341,7 @@ export default {
if (this.selectedHosts.length === 0) {
console.log("No hosts selected.");
} else {
for (var i = 0; i < this.selectedHosts.length; i++) {
for (let i = 0; i < this.selectedHosts.length; i++) {
try {
const newAddedHost = await hostStore.addDiscoveredHosts(
this.selectedHosts[i]
Expand Down
Loading

0 comments on commit d4b6d41

Please sign in to comment.