blob: b16cac8a34288dafdb55ecc56cd77a7212992666 [file] [log] [blame]
Yoshie Muranaka0b980db2020-10-06 09:24:14 -07001import api from '@/store/api';
2import i18n from '@/i18n';
3
4const FirmwareSingleImageStore = {
5 namespaced: true,
6 state: {
7 activeFirmware: {
8 version: '--',
9 id: null,
Derick Montague602e98a2020-10-21 16:20:00 -050010 location: null,
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070011 },
12 backupFirmware: {
13 version: '--',
14 id: null,
15 location: null,
Yoshie Muranaka6f712842021-02-04 11:23:03 -080016 status: null,
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070017 },
Derick Montague602e98a2020-10-21 16:20:00 -050018 applyTime: null,
Yoshie Muranaka7cc1fd42021-02-11 09:23:14 -080019 tftpAvailable: false,
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070020 },
21 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050022 systemFirmwareVersion: (state) => state.activeFirmware.version,
23 backupFirmwareVersion: (state) => state.backupFirmware.version,
24 backupFirmwareStatus: (state) => state.backupFirmware.status,
25 isRebootFromBackupAvailable: (state) =>
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070026 state.backupFirmware.id ? true : false,
Yoshie Muranaka7cc1fd42021-02-11 09:23:14 -080027 bmcFirmwareCurrentVersion: (state) => state.activeFirmware.version, //this getter is needed for the Overview page,
28 isTftpUploadAvailable: (state) => state.tftpAvailable,
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070029 },
30 mutations: {
31 setActiveFirmware: (state, { version, id, location }) => {
32 state.activeFirmware.version = version;
33 state.activeFirmware.id = id;
34 state.activeFirmware.location = location;
35 },
36 setBackupFirmware: (state, { version, id, location, status }) => {
37 state.backupFirmware.version = version;
38 state.backupFirmware.id = id;
39 state.backupFirmware.location = location;
40 state.backupFirmware.status = status;
41 },
Derick Montague602e98a2020-10-21 16:20:00 -050042 setApplyTime: (state, applyTime) => (state.applyTime = applyTime),
Yoshie Muranaka7cc1fd42021-02-11 09:23:14 -080043 setTftpUploadAvailable: (state, tftpAvailable) =>
44 (state.tftpAvailable = tftpAvailable),
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070045 },
46 actions: {
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070047 async getFirmwareInformation({ commit }) {
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070048 return await api
49 .get('/redfish/v1/Managers/bmc')
50 .then(({ data: { Links } }) => {
51 const currentLocation = Links.ActiveSoftwareImage['@odata.id'];
52 // Check SoftwareImages list for not ActiveSoftwareImage id
53 const backupLocation = Links.SoftwareImages.map(
Derick Montague602e98a2020-10-21 16:20:00 -050054 (item) => item['@odata.id']
55 ).find((location) => {
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070056 const id = location.split('/').pop();
57 const currentId = currentLocation.split('/').pop();
58 return id !== currentId;
59 });
60 return { currentLocation, backupLocation };
61 })
62 .then(async ({ currentLocation, backupLocation }) => {
63 const currentData = await api.get(currentLocation);
64 let backupData = {};
65
66 if (backupLocation) {
67 backupData = await api.get(backupLocation);
68 }
69
70 commit('setActiveFirmware', {
71 version: currentData?.data?.Version,
72 id: currentData?.data?.Id,
Derick Montague602e98a2020-10-21 16:20:00 -050073 location: currentData?.data?.['@odata.id'],
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070074 });
75 commit('setBackupFirmware', {
76 version: backupData.data?.Version,
77 id: backupData.data?.Id,
78 location: backupData.data?.['@odata.id'],
Yoshie Muranaka6f712842021-02-04 11:23:03 -080079 status: backupData.data?.Status?.Health,
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070080 });
81 })
Derick Montague602e98a2020-10-21 16:20:00 -050082 .catch((error) => console.log(error));
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070083 },
Yoshie Muranaka7cc1fd42021-02-11 09:23:14 -080084 getUpdateServiceSettings({ commit }) {
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070085 api
86 .get('/redfish/v1/UpdateService')
87 .then(({ data }) => {
88 const applyTime =
89 data.HttpPushUriOptions.HttpPushUriApplyTime.ApplyTime;
Yoshie Muranaka7cc1fd42021-02-11 09:23:14 -080090 const allowableActions =
91 data?.Actions?.['#UpdateService.SimpleUpdate']?.[
92 'TransferProtocol@Redfish.AllowableValues'
93 ];
94
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070095 commit('setApplyTime', applyTime);
Yoshie Muranaka7cc1fd42021-02-11 09:23:14 -080096 if (allowableActions.includes('TFTP')) {
97 commit('setTftpUploadAvailable', true);
98 }
Yoshie Muranaka0b980db2020-10-06 09:24:14 -070099 })
Derick Montague602e98a2020-10-21 16:20:00 -0500100 .catch((error) => console.log(error));
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700101 },
102 setApplyTimeImmediate({ commit }) {
103 const data = {
104 HttpPushUriOptions: {
105 HttpPushUriApplyTime: {
Derick Montague602e98a2020-10-21 16:20:00 -0500106 ApplyTime: 'Immediate',
107 },
108 },
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700109 };
110 return api
111 .patch('/redfish/v1/UpdateService', data)
112 .then(() => commit('setApplyTime', 'Immediate'))
Derick Montague602e98a2020-10-21 16:20:00 -0500113 .catch((error) => console.log(error));
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700114 },
115 async uploadFirmware({ state, dispatch }, image) {
116 if (state.applyTime !== 'Immediate') {
117 // ApplyTime must be set to Immediate before making
118 // request to update firmware
119 await dispatch('setApplyTimeImmediate');
120 }
121 return await api
122 .post('/redfish/v1/UpdateService', image, {
Derick Montague602e98a2020-10-21 16:20:00 -0500123 headers: { 'Content-Type': 'application/octet-stream' },
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700124 })
Derick Montague602e98a2020-10-21 16:20:00 -0500125 .catch((error) => {
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700126 console.log(error);
127 throw new Error(i18n.t('pageFirmware.toast.errorUploadAndReboot'));
128 });
129 },
Yoshie Muranaka6f712842021-02-04 11:23:03 -0800130 async uploadFirmwareTFTP({ state, dispatch }, fileAddress) {
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700131 const data = {
132 TransferProtocol: 'TFTP',
Yoshie Muranaka6f712842021-02-04 11:23:03 -0800133 ImageURI: fileAddress,
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700134 };
135 if (state.applyTime !== 'Immediate') {
136 // ApplyTime must be set to Immediate before making
137 // request to update firmware
138 await dispatch('setApplyTimeImmediate');
139 }
140 return await api
141 .post(
142 '/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate',
143 data
144 )
Derick Montague602e98a2020-10-21 16:20:00 -0500145 .catch((error) => {
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700146 console.log(error);
147 throw new Error(i18n.t('pageFirmware.toast.errorUploadAndReboot'));
148 });
149 },
150 async switchFirmwareAndReboot({ state }) {
151 const backupLoaction = state.backupFirmware.location;
152 const data = {
153 Links: {
154 ActiveSoftwareImage: {
Derick Montague602e98a2020-10-21 16:20:00 -0500155 '@odata.id': backupLoaction,
156 },
157 },
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700158 };
159 return await api
160 .patch('/redfish/v1/Managers/bmc', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500161 .catch((error) => {
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700162 console.log(error);
Yoshie Muranaka6f712842021-02-04 11:23:03 -0800163 throw new Error(
164 i18n.t('pageFirmware.singleFileUpload.toast.errorSwitchImages')
165 );
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700166 });
Derick Montague602e98a2020-10-21 16:20:00 -0500167 },
168 },
Yoshie Muranaka0b980db2020-10-06 09:24:14 -0700169};
170
171export default FirmwareSingleImageStore;