Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Seagate/cfm into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Meng-20 committed Dec 17, 2024
2 parents 4faa226 + 52c8637 commit cb5f02a
Show file tree
Hide file tree
Showing 12 changed files with 678 additions and 551 deletions.
93 changes: 47 additions & 46 deletions api/cfm-openapi.yaml

Large diffs are not rendered by default.

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
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ require (
github.com/rs/cors v1.11.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/zcalusic/sysinfo v1.1.0
golang.org/x/crypto v0.23.0
golang.org/x/crypto v0.31.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/net v0.25.0
k8s.io/klog/v2 v2.130.1
)

require github.com/godbus/dbus/v5 v5.0.4 // indirect
require github.com/godbus/dbus/v5 v5.0.4

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand All @@ -33,7 +31,6 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand All @@ -43,8 +40,8 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
18 changes: 6 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
github.com/Seagate/cxl-lib v1.3.2 h1:HcoT4XSCm/tAn/Fo7IW/BY8etVuL7udCOjXToByTcWY=
github.com/Seagate/cxl-lib v1.3.2/go.mod h1:hFfwklF68YS2y1RVgxGMQ6gNoXeof4jHEH4MNUmMYYQ=
github.com/Seagate/cxl-lib v1.3.3 h1:uiyi/1eOhKEbt4yO9wVZ/ieslOhe1xXgm4HPBN5Ko1g=
github.com/Seagate/cxl-lib v1.3.3/go.mod h1:hFfwklF68YS2y1RVgxGMQ6gNoXeof4jHEH4MNUmMYYQ=
github.com/Seagate/cxl-lib v1.3.4 h1:Poo3FLbsgtPuQchCIHK1CtyMeLTLiJO53cvKSOMaY0Q=
github.com/Seagate/cxl-lib v1.3.4/go.mod h1:hFfwklF68YS2y1RVgxGMQ6gNoXeof4jHEH4MNUmMYYQ=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down Expand Up @@ -87,16 +83,16 @@ go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand All @@ -105,7 +101,5 @@ gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
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
2 changes: 1 addition & 1 deletion webui/src/components/Appliance/ComposeMemoryButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export default {
const bladeResourceStore = useBladeResourceStore();
const bladePortStore = useBladePortStore();

await bladeResourceStore.fetchMemoryResources(
await bladeResourceStore.updateMemoryResourcesStatus(
this.associatedApplianceId,
this.bladeId
);
Expand Down
8 changes: 4 additions & 4 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 @@ -434,7 +434,7 @@ export default {
this.selectedMemoryRegion.memoryApplianceId,
this.selectedMemoryRegion.memoryBladeId
);
await bladeResourceStore.fetchMemoryResources(
await bladeResourceStore.updateMemoryResourcesStatus(
this.selectedMemoryRegion.memoryApplianceId,
this.selectedMemoryRegion.memoryBladeId
);
Expand Down Expand Up @@ -477,7 +477,7 @@ export default {
const bladeResourceStore = useBladeResourceStore();
const bladePortStore = useBladePortStore();

await bladeResourceStore.fetchMemoryResources(
await bladeResourceStore.updateMemoryResourcesStatus(
this.selectedMemoryRegion.memoryApplianceId,
this.selectedMemoryRegion.memoryBladeId
);
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 cb5f02a

Please sign in to comment.