Skip to content

Commit

Permalink
Replace fixed paths with response from API
Browse files Browse the repository at this point in the history
Currently, the Redfish request used fixed URIs, modify the code to use
the BMC and System paths got from response of API calls.
For CertificateStore, since it was using the URL for constant variable
assignment, changed the constant CERTIFICATE_TYPES to method call.

Change-Id: I330b7272083e3e6993aae5705aae170b8e9a4659
Signed-off-by: Sean Zhang <xiazhang@nvidia.com>
  • Loading branch information
seanzhangseu authored and Gunnar Mills committed Jun 25, 2024
1 parent ccb71f0 commit 8841b7d
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 116 deletions.
26 changes: 23 additions & 3 deletions src/store/modules/GlobalStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,39 @@ const GlobalStore = {
},
},
actions: {
async getBmcPath() {
const serviceRoot = await api
.get('/redfish/v1')
.catch((error) => console.log(error));
let bmcPath = serviceRoot.data?.ManagerProvidingService?.['@odata.id'];
if (!bmcPath) {
const managers = await api
.get('/redfish/v1/Managers')
.catch((error) => console.log(error));
bmcPath = managers.data?.Members?.[0]?.['@odata.id'];
}
return bmcPath;
},
async getSystemPath() {
const systems = await api
.get('/redfish/v1/Systems')
.catch((error) => console.log(error));
let systemPath = systems.data?.Members?.[0]?.['@odata.id'];
return systemPath;
},
async getBmcTime({ commit }) {
return await api
.get('/redfish/v1/Managers/bmc')
.get(`${await this.dispatch('global/getBmcPath')}`)
.then((response) => {
const bmcDateTime = response.data.DateTime;
const date = new Date(bmcDateTime);
commit('setBmcTime', date);
})
.catch((error) => console.log(error));
},
getSystemInfo({ commit }) {
async getSystemInfo({ commit }) {
api
.get('/redfish/v1/Systems/system')
.get(`${await this.dispatch('global/getSystemPath')}`)
.then(
({
data: {
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/HardwareStatus/BmcStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const BmcStore = {
actions: {
async getBmcInfo({ commit }) {
return await api
.get('/redfish/v1/Managers/bmc')
.get(`${await this.dispatch('global/getBmcPath')}`)
.then(({ data }) => commit('setBmcInfo', data))
.catch((error) => console.log(error));
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/HardwareStatus/MemoryStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const MemoryStore = {
actions: {
async getDimms({ commit }) {
return await api
.get('/redfish/v1/Systems/system/Memory')
.get(`${await this.dispatch('global/getSystemPath')}/Memory`)
.then(({ data: { Members } }) => {
const promises = Members.map((item) => api.get(item['@odata.id']));
return api.all(promises);
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/HardwareStatus/ProcessorStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const ProcessorStore = {
actions: {
async getProcessorsInfo({ commit }) {
return await api
.get('/redfish/v1/Systems/system/Processors')
.get(`${await this.dispatch('global/getSystemPath')}/Processors`)
.then(({ data: { Members = [] } }) =>
Members.map((member) => api.get(member['@odata.id'])),
)
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/HardwareStatus/ServerLedStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ServerLedStore = {
actions: {
async getIndicatorLedActiveState({ commit }) {
return await api
.get('/redfish/v1/Systems/system')
.get(`${await this.dispatch('global/getSystemPath')}`)
.then((response) => {
commit(
'setIndicatorLedActiveState',
Expand All @@ -29,7 +29,7 @@ const ServerLedStore = {
async saveIndicatorLedActiveState({ commit }, payload) {
commit('setIndicatorLedActiveState', payload);
return await api
.patch('/redfish/v1/Systems/system', {
.patch(`${await this.dispatch('global/getSystemPath')}`, {
LocationIndicatorActive: payload,
})
.catch((error) => {
Expand Down
7 changes: 2 additions & 5 deletions src/store/modules/HardwareStatus/SystemStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@ const SystemStore = {
actions: {
async getSystem({ commit }) {
return await api
.get('/redfish/v1')
.then((response) =>
api.get(`${response.data.Systems['@odata.id']}/system`),
)
.get(`${await this.dispatch('global/getSystemPath')}`)
.then(({ data }) => commit('setSystemInfo', data))
.catch((error) => console.log(error));
},
async changeIdentifyLedState({ commit }, ledState) {
return await api
.patch('/redfish/v1/Systems/system', {
.patch(`${await this.dispatch('global/getSystemPath')}`, {
LocationIndicatorActive: ledState,
})
.then(() => {
Expand Down
14 changes: 5 additions & 9 deletions src/store/modules/Logs/DumpsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ const DumpsStore = {
actions: {
async getBmcDumpEntries() {
return api
.get('/redfish/v1/')
.then((response) => api.get(response.data.Managers['@odata.id']))
.then((response) => api.get(`${response.data['@odata.id']}/bmc`))
.get(`${await this.dispatch('global/getBmcPath')}`)
.then((response) => api.get(response.data.LogServices['@odata.id']))
.then((response) => api.get(`${response.data['@odata.id']}/Dump`))
.then((response) => api.get(response.data.Entries['@odata.id']))
.catch((error) => console.log(error));
},
async getSystemDumpEntries() {
return api
.get('/redfish/v1/')
.then((response) => api.get(response.data.Systems['@odata.id']))
.then((response) => api.get(`${response.data['@odata.id']}/system`))
.get(`${await this.dispatch('global/getSystemPath')}`)
.then((response) => api.get(response.data.LogServices['@odata.id']))
.then((response) => api.get(`${response.data['@odata.id']}/Dump`))
.then((response) => api.get(response.data.Entries['@odata.id']))
Expand All @@ -56,7 +52,7 @@ const DumpsStore = {
async createBmcDump() {
return await api
.post(
'/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData',
`${await this.dispatch('global/getBmcPath')}/LogServices/Dump/Actions/LogService.CollectDiagnosticData`,
{
DiagnosticDataType: 'Manager',
OEMDiagnosticDataType: '',
Expand All @@ -70,7 +66,7 @@ const DumpsStore = {
async createSystemDump() {
return await api
.post(
'/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData',
`${await this.dispatch('global/getSystemPath')}/LogServices/Dump/Actions/LogService.CollectDiagnosticData`,
{
DiagnosticDataType: 'OEM',
OEMDiagnosticDataType: 'System',
Expand Down Expand Up @@ -123,7 +119,7 @@ const DumpsStore = {
const totalDumpCount = state.allDumps.length;
return await api
.post(
'/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog',
`${await this.dispatch('global/getBmcPath')}/LogServices/Dump/Actions/LogService.ClearLog`,
)
.then(() => {
commit('setAllDumps', []);
Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/Logs/EventLogStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const EventLogStore = {
actions: {
async getEventLogData({ commit }) {
return await api
.get('/redfish/v1/Systems/system/LogServices/EventLog/Entries')
.get(
`${await this.dispatch('global/getSystemPath')}/LogServices/EventLog/Entries`,
)
.then(({ data: { Members = [] } = {} }) => {
const eventLogs = Members.map((log) => {
const {
Expand Down Expand Up @@ -79,7 +81,7 @@ const EventLogStore = {
async deleteAllEventLogs({ dispatch }, data) {
return await api
.post(
'/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog',
`${await this.dispatch('global/getSystemPath')}/LogServices/EventLog/Actions/LogService.ClearLog`,
)
.then(() => dispatch('getEventLogData'))
.then(() => i18n.tc('pageEventLogs.toast.successDelete', data.length))
Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/Logs/PostCodeLogsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const PostCodeLogsStore = {
actions: {
async getPostCodesLogData({ commit }) {
return await api
.get('/redfish/v1/Systems/system/LogServices/PostCodes/Entries')
.get(
`${await this.dispatch('global/getSystemPath')}/LogServices/PostCodes/Entries`,
)
.then(({ data: { Members = [] } = {} }) => {
const postCodeLogs = Members.map((log) => {
const { Created, MessageArgs, AdditionalDataURI } = log;
Expand All @@ -37,7 +39,7 @@ const PostCodeLogsStore = {
async deleteAllPostCodeLogs({ dispatch }, data) {
return await api
.post(
'/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog',
`${await this.dispatch('global/getSystemPath')}/LogServices/PostCodes/Actions/LogService.ClearLog`,
)
.then(() => dispatch('getPostCodesLogData'))
.then(() =>
Expand Down
9 changes: 6 additions & 3 deletions src/store/modules/Operations/BootSettingsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const BootSettingsStore = {
actions: {
async getBootSettings({ commit }) {
return await api
.get('/redfish/v1/Systems/system')
.get(`${await this.dispatch('global/getSystemPath')}`)
.then(({ data: { Boot } }) => {
commit(
'setBootSourceOptions',
Expand All @@ -43,7 +43,10 @@ const BootSettingsStore = {
})
.catch((error) => console.log(error));
},
saveBootSettings({ commit, dispatch }, { bootSource, overrideEnabled }) {
async saveBootSettings(
{ commit, dispatch },
{ bootSource, overrideEnabled },
) {
const data = { Boot: {} };
data.Boot.BootSourceOverrideTarget = bootSource;

Expand All @@ -56,7 +59,7 @@ const BootSettingsStore = {
}

return api
.patch('/redfish/v1/Systems/system', data)
.patch(`${await this.dispatch('global/getSystemPath')}`, data)
.then((response) => {
// If request success, commit the values
commit('setBootSource', data.Boot.BootSourceOverrideTarget);
Expand Down
18 changes: 12 additions & 6 deletions src/store/modules/Operations/ControlStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ControlStore = {
actions: {
async getLastPowerOperationTime({ commit }) {
return await api
.get('/redfish/v1/Systems/system')
.get(`${await this.dispatch('global/getSystemPath')}`)
.then((response) => {
const lastReset = response.data.LastResetTime;
if (lastReset) {
Expand All @@ -61,9 +61,9 @@ const ControlStore = {
})
.catch((error) => console.log(error));
},
getLastBmcRebootTime({ commit }) {
async getLastBmcRebootTime({ commit }) {
return api
.get('/redfish/v1/Managers/bmc')
.get(`${await this.dispatch('global/getBmcPath')}`)
.then((response) => {
const lastBmcReset = response.data.LastResetTime;
const lastBmcRebootTime = new Date(lastBmcReset);
Expand All @@ -74,7 +74,10 @@ const ControlStore = {
async rebootBmc({ dispatch }) {
const data = { ResetType: 'GracefulRestart' };
return await api
.post('/redfish/v1/Managers/bmc/Actions/Manager.Reset', data)
.post(
`${await this.dispatch('global/getBmcPath')}/Actions/Manager.Reset`,
data,
)
.then(() => dispatch('getLastBmcRebootTime'))
.then(() => i18n.t('pageRebootBmc.toast.successRebootStart'))
.catch((error) => {
Expand Down Expand Up @@ -117,10 +120,13 @@ const ControlStore = {
commit('setOperationInProgress', false);
dispatch('getLastPowerOperationTime');
},
serverPowerChange({ commit }, data) {
async serverPowerChange({ commit }, data) {
commit('setOperationInProgress', true);
api
.post('/redfish/v1/Systems/system/Actions/ComputerSystem.Reset', data)
.post(
`${await this.dispatch('global/getSystemPath')}/Actions/ComputerSystem.Reset`,
data,
)
.catch((error) => {
console.log(error);
commit('setOperationInProgress', false);
Expand Down
13 changes: 9 additions & 4 deletions src/store/modules/Operations/FactoryResetStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ const FactoryResetStore = {
actions: {
async resetToDefaults() {
return await api
.post('/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults', {
ResetType: 'ResetAll',
})
.post(
`${await this.dispatch('global/getBmcPath')}/Actions/Manager.ResetToDefaults`,
{
ResetType: 'ResetAll',
},
)
.then(() => i18n.t('pageFactoryReset.toast.resetToDefaultsSuccess'))
.catch((error) => {
console.log('Factory Reset: ', error);
Expand All @@ -19,7 +22,9 @@ const FactoryResetStore = {
},
async resetBios() {
return await api
.post('/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios')
.post(
`${await this.dispatch('global/getSystemPath')}/Bios/Actions/Bios.ResetBios`,
)
.then(() => i18n.t('pageFactoryReset.toast.resetBiosSuccess'))
.catch((error) => {
console.log('Factory Reset: ', error);
Expand Down
10 changes: 5 additions & 5 deletions src/store/modules/Operations/FirmwareStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ const FirmwareStore = {
dispatch('getActiveBmcFirmware');
return await dispatch('getFirmwareInventory');
},
getActiveBmcFirmware({ commit }) {
async getActiveBmcFirmware({ commit }) {
return api
.get('/redfish/v1/Managers/bmc')
.get(`${await this.dispatch('global/getBmcPath')}`)
.then(({ data: { Links } }) => {
const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop();
commit('setActiveBmcFirmwareId', id);
})
.catch((error) => console.log(error));
},
getActiveHostFirmware({ commit }) {
async getActiveHostFirmware({ commit }) {
return api
.get('/redfish/v1/Systems/system/Bios')
.get(`${await this.dispatch('global/getSystemPath')}/Bios`)
.then(({ data: { Links } }) => {
const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop();
commit('setActiveHostFirmwareId', id);
Expand Down Expand Up @@ -159,7 +159,7 @@ const FirmwareStore = {
},
};
return await api
.patch('/redfish/v1/Managers/bmc', data)
.patch(`${await this.dispatch('global/getBmcPath')}`, data)
.catch((error) => {
console.log(error);
throw new Error(i18n.t('pageFirmware.toast.errorSwitchImages'));
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/Operations/KeyClearStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const KeyClearStore = {
};
return await api
.patch(
'/redfish/v1/Systems/system/Bios/Settings',
`${await this.dispatch('global/getSystemPath')}/Bios/Settings`,
selectedKeyForClearing,
)
.then(() => i18n.t('pageKeyClear.toast.selectedKeyClearedSuccess'))
Expand Down
6 changes: 3 additions & 3 deletions src/store/modules/Operations/VirtualMediaStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const VirtualMediaStore = {
}

return await api
.get('/redfish/v1/Managers/bmc/VirtualMedia')
.get(`${await this.dispatch('global/getBmcPath')}/VirtualMedia`)
.then((response) =>
response.data.Members.map(
(virtualMedia) => virtualMedia['@odata.id'],
Expand Down Expand Up @@ -95,7 +95,7 @@ const VirtualMediaStore = {
async mountImage(_, { id, data }) {
return await api
.post(
`/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.InsertMedia`,
`${await this.dispatch('global/getBmcPath')}/VirtualMedia/${id}/Actions/VirtualMedia.InsertMedia`,
data,
)
.catch((error) => {
Expand All @@ -106,7 +106,7 @@ const VirtualMediaStore = {
async unmountImage(_, id) {
return await api
.post(
`/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.EjectMedia`,
`${await this.dispatch('global/getBmcPath')}/VirtualMedia/${id}/Actions/VirtualMedia.EjectMedia`,
)
.catch((error) => {
console.log('Unmount image:', error);
Expand Down
Loading

0 comments on commit 8841b7d

Please sign in to comment.