blob: e6df3fba449620263101f99c5e3040b5a7fa39d0 [file] [log] [blame]
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -07001import api from '@/store/api';
2import i18n from '@/i18n';
Dixsie Wolmersf65ee342020-01-22 19:47:56 -06003
4const FirmwareStore = {
5 namespaced: true,
6 state: {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -08007 bmcFirmware: [],
8 hostFirmware: [],
9 bmcActiveFirmwareId: null,
10 hostActiveFirmwareId: null,
Derick Montague602e98a2020-10-21 16:20:00 -050011 applyTime: null,
greenfil6b424f92023-03-10 10:47:41 +030012 httpPushUri: null,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080013 tftpAvailable: false,
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060014 },
15 getters: {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080016 isTftpUploadAvailable: (state) => state.tftpAvailable,
17 isSingleFileUploadEnabled: (state) => state.hostFirmware.length === 0,
18 activeBmcFirmware: (state) => {
19 return state.bmcFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080020 (firmware) => firmware.id === state.bmcActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080021 );
22 },
23 activeHostFirmware: (state) => {
24 return state.hostFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080025 (firmware) => firmware.id === state.hostActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080026 );
27 },
28 backupBmcFirmware: (state) => {
29 return state.bmcFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080030 (firmware) => firmware.id !== state.bmcActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080031 );
32 },
33 backupHostFirmware: (state) => {
34 return state.hostFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080035 (firmware) => firmware.id !== state.hostActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080036 );
37 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060038 },
39 mutations: {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080040 setActiveBmcFirmwareId: (state, id) => (state.bmcActiveFirmwareId = id),
41 setActiveHostFirmwareId: (state, id) => (state.hostActiveFirmwareId = id),
42 setBmcFirmware: (state, firmware) => (state.bmcFirmware = firmware),
43 setHostFirmware: (state, firmware) => (state.hostFirmware = firmware),
Derick Montague602e98a2020-10-21 16:20:00 -050044 setApplyTime: (state, applyTime) => (state.applyTime = applyTime),
greenfil6b424f92023-03-10 10:47:41 +030045 setHttpPushUri: (state, httpPushUri) => (state.httpPushUri = httpPushUri),
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080046 setTftpUploadAvailable: (state, tftpAvailable) =>
47 (state.tftpAvailable = tftpAvailable),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060048 },
49 actions: {
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070050 async getFirmwareInformation({ dispatch }) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080051 dispatch('getActiveHostFirmware');
52 dispatch('getActiveBmcFirmware');
53 return await dispatch('getFirmwareInventory');
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070054 },
Sean Zhang8841b7d2024-06-15 08:42:41 +030055 async getActiveBmcFirmware({ commit }) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080056 return api
Sean Zhang8841b7d2024-06-15 08:42:41 +030057 .get(`${await this.dispatch('global/getBmcPath')}`)
Yoshie Muranakad227f1c2020-10-06 13:46:58 -070058 .then(({ data: { Links } }) => {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080059 const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop();
60 commit('setActiveBmcFirmwareId', id);
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070061 })
Derick Montague602e98a2020-10-21 16:20:00 -050062 .catch((error) => console.log(error));
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070063 },
Sean Zhang8841b7d2024-06-15 08:42:41 +030064 async getActiveHostFirmware({ commit }) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080065 return api
Sean Zhang8841b7d2024-06-15 08:42:41 +030066 .get(`${await this.dispatch('global/getSystemPath')}/Bios`)
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070067 .then(({ data: { Links } }) => {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080068 const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop();
69 commit('setActiveHostFirmwareId', id);
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -070070 })
Derick Montague602e98a2020-10-21 16:20:00 -050071 .catch((error) => console.log(error));
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -070072 },
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080073 async getFirmwareInventory({ commit }) {
74 const inventoryList = await api
75 .get('/redfish/v1/UpdateService/FirmwareInventory')
76 .then(({ data: { Members = [] } = {} }) =>
Ed Tanous81323992024-02-27 11:26:24 -080077 Members.map((item) => api.get(item['@odata.id'])),
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080078 )
79 .catch((error) => console.log(error));
80 await api
81 .all(inventoryList)
82 .then((response) => {
83 const bmcFirmware = [];
84 const hostFirmware = [];
85 response.forEach(({ data }) => {
86 const firmwareType = data?.RelatedItem?.[0]?.['@odata.id']
87 .split('/')
88 .pop();
89 const item = {
90 version: data?.Version,
91 id: data?.Id,
92 location: data?.['@odata.id'],
93 status: data?.Status?.Health,
94 };
95 if (firmwareType === 'bmc') {
96 bmcFirmware.push(item);
97 } else if (firmwareType === 'Bios') {
98 hostFirmware.push(item);
99 }
100 });
101 commit('setBmcFirmware', bmcFirmware);
102 commit('setHostFirmware', hostFirmware);
103 })
104 .catch((error) => {
105 console.log(error);
106 });
107 },
108 getUpdateServiceSettings({ commit }) {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700109 api
110 .get('/redfish/v1/UpdateService')
111 .then(({ data }) => {
112 const applyTime =
113 data.HttpPushUriOptions.HttpPushUriApplyTime.ApplyTime;
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800114 const allowableActions =
115 data?.Actions?.['#UpdateService.SimpleUpdate']?.[
116 'TransferProtocol@Redfish.AllowableValues'
117 ];
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700118 commit('setApplyTime', applyTime);
greenfil6b424f92023-03-10 10:47:41 +0300119 const httpPushUri = data.HttpPushUri;
120 commit('setHttpPushUri', httpPushUri);
Derick Montaguef7cd5e02021-05-11 17:02:00 -0500121 if (allowableActions?.includes('TFTP')) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800122 commit('setTftpUploadAvailable', true);
123 }
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700124 })
Derick Montague602e98a2020-10-21 16:20:00 -0500125 .catch((error) => console.log(error));
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700126 },
Jagpal Singh Gillccb71f02024-06-18 15:21:08 -0700127 async uploadFirmware({ state }, image) {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700128 return await api
greenfil6b424f92023-03-10 10:47:41 +0300129 .post(state.httpPushUri, image, {
Derick Montague602e98a2020-10-21 16:20:00 -0500130 headers: { 'Content-Type': 'application/octet-stream' },
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700131 })
Derick Montague602e98a2020-10-21 16:20:00 -0500132 .catch((error) => {
Dixsie Wolmers46a87442020-02-26 15:26:30 -0600133 console.log(error);
Surya V603cfbf2024-07-11 15:19:46 +0530134 throw new Error(
135 i18n.global.t('pageFirmware.toast.errorUpdateFirmware'),
136 );
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700137 });
138 },
Jagpal Singh Gillccb71f02024-06-18 15:21:08 -0700139 async uploadFirmwareTFTP(fileAddress) {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700140 const data = {
141 TransferProtocol: 'TFTP',
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800142 ImageURI: fileAddress,
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700143 };
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700144 return await api
Gunnar Mills60713b02020-08-18 10:21:05 -0500145 .post(
146 '/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate',
Ed Tanous81323992024-02-27 11:26:24 -0800147 data,
Gunnar Mills60713b02020-08-18 10:21:05 -0500148 )
Derick Montague602e98a2020-10-21 16:20:00 -0500149 .catch((error) => {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700150 console.log(error);
Surya V603cfbf2024-07-11 15:19:46 +0530151 throw new Error(
152 i18n.global.t('pageFirmware.toast.errorUpdateFirmware'),
153 );
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700154 });
155 },
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800156 async switchBmcFirmwareAndReboot({ getters }) {
157 const backupLocation = getters.backupBmcFirmware.location;
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700158 const data = {
159 Links: {
160 ActiveSoftwareImage: {
Yoshie Muranaka1dedbdf2020-11-30 07:04:01 -0800161 '@odata.id': backupLocation,
Derick Montague602e98a2020-10-21 16:20:00 -0500162 },
163 },
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700164 };
165 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +0300166 .patch(`${await this.dispatch('global/getBmcPath')}`, data)
Derick Montague602e98a2020-10-21 16:20:00 -0500167 .catch((error) => {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700168 console.log(error);
Surya V603cfbf2024-07-11 15:19:46 +0530169 throw new Error(
170 i18n.global.t('pageFirmware.toast.errorSwitchImages'),
171 );
Dixsie Wolmers46a87442020-02-26 15:26:30 -0600172 });
Derick Montague602e98a2020-10-21 16:20:00 -0500173 },
174 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600175};
176
177export default FirmwareStore;