-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
68 lines (59 loc) · 1.29 KB
/
utils.js
File metadata and controls
68 lines (59 loc) · 1.29 KB
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
67
68
var randomString = require('random-string')
var randomNumber = require('random-number')
var bytes = require('bytes')
var tags = [
'google',
'aws',
'digitalocean',
'gateway',
'worker',
'database',
'api',
'iot'
]
var engines = [
'docker:4243'
]
var memory = [
'500MB',
'1GB',
'2GB',
'7GB'
]
var cpus = [
{
'model': 'Intel(R) Xeon(R) CPU @ 2.60GHz',
'speed': 2600
}
]
function randomInt(min, max) {
return randomNumber({
min: min,
max: max,
integer: true
})
}
function randomFromArray(arr, process) {
process = process || function(i) { return i }
return process(arr[Math.floor(Math.random() * arr.length)])
}
function randomsFromArray(arr, num, process) {
return Array.apply(null, { length: num }).map(function() {
return randomFromArray(arr, process)
})
}
function randomExampleNode(opts) {
var port = randomNumber({ min: 1000, max: 5000, integer: true })
var path = randomString()
return {
'hostname' : randomString(),
'swarm' : randomString(),
'engines' : [randomFromArray(engines)],
'tags' : randomsFromArray(tags, randomInt(1,3)),
'memory' : randomFromArray(memory, bytes),
'cpus' : randomsFromArray(cpus, randomInt(1,3))
}
}
module.exports = {
randomExampleNode: randomExampleNode
}