| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 1 | import api from '@/store/api'; | 
| Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 2 | import i18n from '@/i18n'; | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 3 |  | 
|  | 4 | const SystemStore = { | 
|  | 5 | namespaced: true, | 
|  | 6 | state: { | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 7 | systems: [], | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 8 | }, | 
|  | 9 | getters: { | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 10 | systems: (state) => state.systems, | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 11 | }, | 
|  | 12 | mutations: { | 
|  | 13 | setSystemInfo: (state, data) => { | 
|  | 14 | const system = {}; | 
|  | 15 | system.assetTag = data.AssetTag; | 
|  | 16 | system.description = data.Description; | 
| Yoshie Muranaka | c687f10 | 2020-06-02 12:01:27 -0700 | [diff] [blame] | 17 | system.firmwareVersion = data.BiosVersion; | 
| Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 18 | system.hardwareType = data.Name; | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 19 | system.health = data.Status?.Health; | 
| Nikhil Ashoka | 18cde3c | 2022-01-05 22:21:24 +0530 | [diff] [blame] | 20 | system.totalSystemMemoryGiB = data.MemorySummary?.TotalSystemMemoryGiB; | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 21 | system.id = data.Id; | 
| SurenNeware | bbf896c | 2021-01-27 21:50:22 +0530 | [diff] [blame] | 22 | system.locationIndicatorActive = data.LocationIndicatorActive; | 
| Sneha Patel | 9f61234 | 2021-09-02 12:23:42 -0500 | [diff] [blame] | 23 | system.locationNumber = data.Location?.PartLocation?.ServiceLabel; | 
| Yoshie Muranaka | c687f10 | 2020-06-02 12:01:27 -0700 | [diff] [blame] | 24 | system.manufacturer = data.Manufacturer; | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 25 | system.memorySummaryHealth = data.MemorySummary?.Status.Health; | 
|  | 26 | system.memorySummaryHealthRollup = | 
|  | 27 | data.MemorySummary?.Status?.HealthRollup; | 
|  | 28 | system.memorySummaryState = data.MemorySummary?.Status?.State; | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 29 | system.model = data.Model; | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 30 | system.processorSummaryCount = data.ProcessorSummary?.Count; | 
| Nikhil Ashoka | 18cde3c | 2022-01-05 22:21:24 +0530 | [diff] [blame] | 31 | system.processorSummaryCoreCount = data.ProcessorSummary?.CoreCount; | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 32 | system.processorSummaryHealth = data.ProcessorSummary?.Status?.Health; | 
| Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 33 | system.processorSummaryHealthRoll = | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 34 | data.ProcessorSummary?.Status.HealthRollup; | 
|  | 35 | system.processorSummaryState = data.ProcessorSummary?.Status?.State; | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 36 | system.powerState = data.PowerState; | 
|  | 37 | system.serialNumber = data.SerialNumber; | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 38 | system.healthRollup = data.Status?.HealthRollup; | 
| Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 39 | system.subModel = data.SubModel; | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 40 | system.statusState = data.Status?.State; | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 41 | system.systemType = data.SystemType; | 
|  | 42 | state.systems = [system]; | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 43 | }, | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 44 | }, | 
|  | 45 | actions: { | 
|  | 46 | async getSystem({ commit }) { | 
|  | 47 | return await api | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 48 | .get('/redfish/v1') | 
|  | 49 | .then((response) => | 
|  | 50 | api.get(`${response.data.Systems['@odata.id']}/system`) | 
|  | 51 | ) | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 52 | .then(({ data }) => commit('setSystemInfo', data)) | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 53 | .catch((error) => console.log(error)); | 
|  | 54 | }, | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 55 | async changeIdentifyLedState({ commit }, ledState) { | 
|  | 56 | return await api | 
| Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 57 | .patch('/redfish/v1/Systems/system', { | 
|  | 58 | LocationIndicatorActive: ledState, | 
|  | 59 | }) | 
| Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 60 | .catch((error) => { | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 61 | commit('setSystemInfo', this.state.system.systems[0]); | 
| Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 62 | console.log('error', error); | 
|  | 63 | if (ledState) { | 
|  | 64 | throw new Error( | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 65 | i18n.t('pageInventory.toast.errorEnableIdentifyLed') | 
| Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 66 | ); | 
|  | 67 | } else { | 
|  | 68 | throw new Error( | 
| Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 69 | i18n.t('pageInventory.toast.errorDisableIdentifyLed') | 
| Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 70 | ); | 
|  | 71 | } | 
|  | 72 | }); | 
|  | 73 | }, | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 74 | }, | 
| Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 75 | }; | 
|  | 76 |  | 
|  | 77 | export default SystemStore; |