-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclusterUtil.js
66 lines (64 loc) · 2.08 KB
/
clusterUtil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict'
var prism = require('nutanix_prism')
const creds = {
username:'user',
password:'Password'
}
module.exports.getHosts = function(thisCluster) {
return new Promise ((resolve, reject) => {
thisCluster.children = []
let opts = {
creds: creds,
ip: thisCluster.externalIP
}
prism.host.get(opts)
.then(hosts => {
getHostNetwork(hosts.entities, thisCluster)
.then(resolve)
.catch(reject)
})
.catch(reject)
})
}
function getHostNetwork(hosts, thisCluster) {
return new Promise ((resolve, reject) => {
let hostCounter = 0
let hostLength = hosts.length
for (var host in hosts) {
let thisHost = hosts[host]
let thisChildIndex = thisCluster.children.push({
name: thisHost.hypervisorAddress,
children: []
}) - 1
let opts = {
creds: creds,
ip: thisCluster.externalIP,
serviceVMId: thisHost.serviceVMId
}
prism.host.nics(opts)
.then(hostNics => {
for (var nic in hostNics) {
let mac = hostNics[nic].macAddress.toLowerCase()
thisCluster.children[thisChildIndex].children.push({
name: thisCluster.name + ' - ' + thisHost.hypervisorAddress + ' - ' + hostNics[nic].name,
macAddress: mac
})
}
if(checkDone()) {
resolve(thisCluster)
}
})
.catch(err => {
if(checkDone()) {
console.log('ERROR while getting host nics: ' + externalIP + ' with err: ' + err)
reject('ERROR while getting host nics: ' + externalIP + ' with err: ' + err)
}
})
}
function checkDone() {
hostCounter++
if(hostCounter == hostLength) { return true }
else { return false }
}
})
}