Skip to content

Commit

Permalink
timeout 10 sec
Browse files Browse the repository at this point in the history
  • Loading branch information
arteck committed Jan 2, 2025
1 parent 7f39f58 commit 3f5f395
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 99 deletions.
47 changes: 25 additions & 22 deletions lib/proxmox.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ProxmoxUtils {

this.setNextUrlMain(0);

this.adapter.log.info(`Using Node: ${this.URL}`);
this.adapter.log.warn(`Using Proxmox API: ${this.URL}`);

this.responseCache = {};
this.sharedMap = {};
Expand All @@ -37,11 +37,14 @@ class ProxmoxUtils {
}

this.currentIpId++;

if (this.currentIpId == this.ipList.length) {
if (this.currentIpId === this.ipList.length) {
this.currentIpId = 0;
}

// if (this.ipList[this.currentIpId]) {
// this.currentIpId = 0;
// }

this.URL = `https://${this.ipList[this.currentIpId]}:${this.port}/api2/json`;
return this.URL;
}
Expand All @@ -56,7 +59,7 @@ class ProxmoxUtils {
if (this.responseCache['/nodes']) {
resolve(JSON.parse(JSON.stringify(this.responseCache['/nodes'])));
} else {
this._getData('/nodes', 'get', '', '', 'getNodes')
this._getData('/nodes', 'get')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache['/nodes'] = data.data;
Expand All @@ -75,7 +78,7 @@ class ProxmoxUtils {
if (useCache && this.responseCache[`/nodes/${node}/status`]) {
resolve(JSON.parse(JSON.stringify(this.responseCache[`/nodes/${node}/status`])));
} else {
this._getData(`/nodes/${node}/status`, 'get', '', '', 'getNodeStatus')
this._getData(`/nodes/${node}/status`, 'get')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache[`/nodes/${node}/status`] = data.data;
Expand All @@ -94,7 +97,7 @@ class ProxmoxUtils {
if (useCache && this.responseCache[`/nodes/${node}/disks/list`]) {
resolve(JSON.parse(JSON.stringify(this.responseCache[`/nodes/${node}/disks/list`])));
} else {
this._getData(`/nodes/${node}/disks/list`, 'get', '', '', 'getNodeDisks')
this._getData(`/nodes/${node}/disks/list`, 'get')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache[`/nodes/${node}/disks/list`] = data.data;
Expand All @@ -109,23 +112,23 @@ class ProxmoxUtils {
}

async getNodeDisksSmart(node, disk) {
return this._getData(`/nodes/${node}/disks/smart?disk=${disk}`, 'get', '', '', 'getNodeDisksSmart');
return this._getData(`/nodes/${node}/disks/smart?disk=${disk}`, 'get');
}

async getCephInformation() {
return this._getData(`/cluster/ceph/status`, 'get', '', '', 'getCephInformation');
return this._getData(`/cluster/ceph/status`, 'get', '', '', 'ceph');
}

async getHAStatusInformation() {
return this._getData(`/cluster/ha/status/current`, 'get', '', '', 'getHAStatusInformation');
return this._getData(`/cluster/ha/status/current`, 'get', '', '', 'ha');
}

async getClusterResources(useCache) {
return new Promise((resolve, reject) => {
if (useCache && this.responseCache['/cluster/resources']) {
resolve(JSON.parse(JSON.stringify(this.responseCache['/cluster/resources'])));
} else {
return this._getData('/cluster/resources', 'get', '', '', 'getClusterResources')
return this._getData('/cluster/resources', 'get')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache['/cluster/resources'] = data.data;
Expand All @@ -144,7 +147,7 @@ class ProxmoxUtils {
if (useCache && this.responseCache[`/nodes/${node}/${type}/${ID}/status/current`]) {
resolve(JSON.parse(JSON.stringify(this.responseCache[`/nodes/${node}/${type}/${ID}/status/current`])));
} else {
this._getData(`/nodes/${node}/${type}/${ID}/status/current`, 'get', '', '', 'ResourceStatus')
this._getData(`/nodes/${node}/${type}/${ID}/status/current`, 'get')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache[`/nodes/${node}/${type}/${ID}/status/current`] = data.data;
Expand Down Expand Up @@ -255,10 +258,10 @@ class ProxmoxUtils {
reject('STOPPED');
}

if (typeof data == 'undefined') {
if (typeof data === 'undefined') {
data = null;
}
if (typeof retry == 'undefined') {
if (typeof retry === 'undefined') {
retry = null;
}

Expand All @@ -270,7 +273,7 @@ class ProxmoxUtils {
baseURL: this.URL,
url: pathU,
data,
timeout: 5000, // only wait for 2s
timeout: 10000, // only wait for 2s
headers: {
CSRFPreventionToken: CSRF,
Cookie: TICKET,
Expand All @@ -287,11 +290,11 @@ class ProxmoxUtils {
this.communicationErrorCounter = 0;

if (response.status === 500 || response.status === 595 || response.status === 599) {
reject(response.status + ' - ' + JSON.stringify(response.data));
reject(response.status + ' - ' + response.data);
}

if (response.status === 401 && !retry) {
if (additional == undefined) {
if (additional == null) {
this.ticket(async () => {
// Retry with new ticket
this._getData(url, method, data, true).then(resolve).catch(reject);
Expand All @@ -303,26 +306,26 @@ class ProxmoxUtils {
}
})
.catch((_error) => {
if (additional == 'storage') {
this.adapter.log.error(`Check ${additional} -- Problem found.. storage is offline ??`);
} else {
if (additional != 'storage') {

this.adapter.log.warn(`${additional} -- Use Next Proxmox Node because of communication failure ${this.URL}${url}`);
this.adapter.log.warn(`${additional} -- Use Next Proxmox Host because of communication failure ${this.URL}${url}`);

this.communicationErrorCounter++;
// We experienced error the same as we have servers available, so no chance to retry another server
this.setNextUrlMain();

if (this.communicationErrorCounter >= this.ipList.length) {
// this.adapter.log.error(`Error received response from ${error.config.url}`);
this.setNextUrlMain(0);
this.communicationErrorCounter = 0;
}

this.ticket(async () => {
// Retry with new ticket
this._getData(url, method, data, true).then(resolve).catch(reject);
});
}
if (additional == 'storage') {
this.adapter.log.error(`Check ${additional} -- Problem found.. maybe offline `);
}
});
});
}
Expand Down
Loading

0 comments on commit 3f5f395

Please sign in to comment.