Compare commits
1308 Commits
xo-server/
...
xo-server/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3989bfa832 | ||
|
|
740e1ccd5b | ||
|
|
bc03f2ed17 | ||
|
|
4b5cb86d87 | ||
|
|
b877d6088b | ||
|
|
26cfd439e1 | ||
|
|
eafcf66f4d | ||
|
|
a8fad8193b | ||
|
|
ca695c38cd | ||
|
|
6e0f98a809 | ||
|
|
8901d3ce64 | ||
|
|
2641966285 | ||
|
|
09dc2265fe | ||
|
|
a1fa139ef1 | ||
|
|
df26a500c4 | ||
|
|
a465218ba3 | ||
|
|
1ead6eb916 | ||
|
|
44fe1b31ba | ||
|
|
0856d3d5c9 | ||
|
|
f6b74ea836 | ||
|
|
e0cef71700 | ||
|
|
19d1f70458 | ||
|
|
43c103e436 | ||
|
|
6ff4f096a3 | ||
|
|
d8d82441c3 | ||
|
|
4f489e1854 | ||
|
|
9ab275df5d | ||
|
|
66c1754eb8 | ||
|
|
e67bab1f5c | ||
|
|
ceb6667112 | ||
|
|
cafba0b361 | ||
|
|
3e4efcf297 | ||
|
|
4ccadac148 | ||
|
|
6e148c18b0 | ||
|
|
75f849982e | ||
|
|
8722ef45ac | ||
|
|
b347c78a8c | ||
|
|
88ae24855a | ||
|
|
356884ea53 | ||
|
|
51fba21dd6 | ||
|
|
6aa5d608bf | ||
|
|
21ad2c5744 | ||
|
|
dea1163159 | ||
|
|
c4c2e8cf74 | ||
|
|
5883c35cf3 | ||
|
|
4d2719a424 | ||
|
|
7cf2d0d01c | ||
|
|
5a08b512a7 | ||
|
|
aa6ff6cd64 | ||
|
|
89421d292c | ||
|
|
55c6515bac | ||
|
|
5db6f6a58c | ||
|
|
eeedf6ab28 | ||
|
|
3758cd207b | ||
|
|
c15ede6239 | ||
|
|
e54e31e059 | ||
|
|
8c573aa8e4 | ||
|
|
654559086c | ||
|
|
b0d9679568 | ||
|
|
87fdaf7fa7 | ||
|
|
bb3a365166 | ||
|
|
2be183d980 | ||
|
|
c6dc846838 | ||
|
|
1142f1d59a | ||
|
|
126c470979 | ||
|
|
d679dc3e8b | ||
|
|
d5422dfe89 | ||
|
|
d64237b4f2 | ||
|
|
7b7e4942f2 | ||
|
|
e4c343a587 | ||
|
|
1a8ae21478 | ||
|
|
dd37a5b584 | ||
|
|
eec340e6c0 | ||
|
|
c2fb5ba1f0 | ||
|
|
36d7e17b86 | ||
|
|
5a1dc49428 | ||
|
|
47caf54772 | ||
|
|
6af50a8c44 | ||
|
|
1b27407970 | ||
|
|
4da6306c67 | ||
|
|
f950b7a725 | ||
|
|
930cf9ed04 | ||
|
|
744016e752 | ||
|
|
2fb4e907df | ||
|
|
ef2a815e52 | ||
|
|
33a81d4f3c | ||
|
|
4911df0bf9 | ||
|
|
2b612b5db7 | ||
|
|
bfe81b52ef | ||
|
|
26f6a4beb9 | ||
|
|
52e9c3053a | ||
|
|
908d1f1ec8 | ||
|
|
6a1120f95b | ||
|
|
2a2780c25c | ||
|
|
7d4152197b | ||
|
|
9c742600ff | ||
|
|
a035bf132a | ||
|
|
b989d157a0 | ||
|
|
261587511b | ||
|
|
ff798801fb | ||
|
|
9b4aab0d19 | ||
|
|
6e42cf9952 | ||
|
|
4c3a8ca312 | ||
|
|
a63eb48f03 | ||
|
|
d0214f805e | ||
|
|
d736bd6501 | ||
|
|
2ce4a11e0a | ||
|
|
e5ab8fe3e4 | ||
|
|
657b74a084 | ||
|
|
dfee98b66b | ||
|
|
f65b9f695e | ||
|
|
4056385cd3 | ||
|
|
96d56d43bc | ||
|
|
eba8f95e58 | ||
|
|
7e2da1ff93 | ||
|
|
b7b7e81468 | ||
|
|
0c7768f5d2 | ||
|
|
8fe6a56dfc | ||
|
|
7b9dae980d | ||
|
|
b59ba6b7bb | ||
|
|
8cdee4d173 | ||
|
|
c9ed5fbe00 | ||
|
|
e698e89968 | ||
|
|
02f198d42c | ||
|
|
61d2d0263b | ||
|
|
ed477e99a8 | ||
|
|
1449be8d66 | ||
|
|
28902d8747 | ||
|
|
d534592479 | ||
|
|
b2f6ea9116 | ||
|
|
8bf38bb29b | ||
|
|
9c6a78b678 | ||
|
|
850199d7fc | ||
|
|
4282928960 | ||
|
|
356dd89d9f | ||
|
|
7dd2391e5a | ||
|
|
e0093f236a | ||
|
|
8c5c32268a | ||
|
|
b61ccc1af1 | ||
|
|
7caf0e40f4 | ||
|
|
a16508db10 | ||
|
|
81bff342b9 | ||
|
|
49d41a76a0 | ||
|
|
b1732b3298 | ||
|
|
9372cdb6c7 | ||
|
|
1d8e54b83e | ||
|
|
30c5600271 | ||
|
|
9f7e5c3a9a | ||
|
|
37c9342717 | ||
|
|
8827f8e940 | ||
|
|
58334bf4a1 | ||
|
|
b898a6702c | ||
|
|
6d78a810b9 | ||
|
|
8fc4eb8cdf | ||
|
|
b3fac0c56f | ||
|
|
0b063b1f5e | ||
|
|
480f05e676 | ||
|
|
1ac8af34ec | ||
|
|
34ff8b0f02 | ||
|
|
77c3684e28 | ||
|
|
93038ea838 | ||
|
|
46348f7cba | ||
|
|
ccc0e45daf | ||
|
|
46ca03b017 | ||
|
|
1bfe3197a5 | ||
|
|
4d2617fe68 | ||
|
|
92e289f9da | ||
|
|
a8c7558a77 | ||
|
|
c756e7ecbe | ||
|
|
1998c56e84 | ||
|
|
2ed55b1616 | ||
|
|
0c8d456fd3 | ||
|
|
9e4924caf6 | ||
|
|
7f391a5860 | ||
|
|
5c7249c8fc | ||
|
|
932d00133d | ||
|
|
32a371bf13 | ||
|
|
5d0622d2cf | ||
|
|
9ab9155bf0 | ||
|
|
86a1ed6d46 | ||
|
|
b3c9936d74 | ||
|
|
21b4d7cf11 | ||
|
|
4ec07f9ff8 | ||
|
|
b7c89d6f64 | ||
|
|
0eb168ec70 | ||
|
|
8ac1a66e93 | ||
|
|
301da3662a | ||
|
|
e474946cb7 | ||
|
|
9a0ca1ebb2 | ||
|
|
520f7b2a77 | ||
|
|
c0b3b3aab8 | ||
|
|
d499332ce3 | ||
|
|
19ce06e0bb | ||
|
|
ea6ff4224e | ||
|
|
871d1f8632 | ||
|
|
77ce2ff6d1 | ||
|
|
6383104796 | ||
|
|
b99b4159c8 | ||
|
|
8bedb1f3b9 | ||
|
|
dc85804a27 | ||
|
|
42a31e512a | ||
|
|
2be7388696 | ||
|
|
bc5b00781b | ||
|
|
313e2b3de6 | ||
|
|
0bbd002060 | ||
|
|
5e785266a5 | ||
|
|
5870769e7d | ||
|
|
79b80dcd07 | ||
|
|
6f6e547e6c | ||
|
|
352c9357df | ||
|
|
1ba4641641 | ||
|
|
60e0047285 | ||
|
|
235e7c143c | ||
|
|
522d6eed92 | ||
|
|
9d1d6ea4c5 | ||
|
|
0afd506a41 | ||
|
|
9dfb837e3f | ||
|
|
4ab63b569f | ||
|
|
8d390d256d | ||
|
|
4eec5e06fc | ||
|
|
e4063b1ba8 | ||
|
|
0c3227cf8e | ||
|
|
7bed200bf5 | ||
|
|
4f763e2109 | ||
|
|
75167fb65b | ||
|
|
675588f780 | ||
|
|
2d6f94edd8 | ||
|
|
247c66ef4b | ||
|
|
1076fac40f | ||
|
|
14a4a415a2 | ||
|
|
524355b59c | ||
|
|
36fe49f3f5 | ||
|
|
c0c0af9b14 | ||
|
|
d1e472d482 | ||
|
|
c80e43ad0d | ||
|
|
fdd395e2b6 | ||
|
|
e094437168 | ||
|
|
2ee0be7466 | ||
|
|
2784a7cc92 | ||
|
|
b09f998d6c | ||
|
|
bdeb5895f6 | ||
|
|
3944b8aaee | ||
|
|
6e66cffb92 | ||
|
|
57092ee788 | ||
|
|
70e9e1c706 | ||
|
|
9662b8fbee | ||
|
|
9f66421ae7 | ||
|
|
50584c2e50 | ||
|
|
7be4e1901a | ||
|
|
b47146de45 | ||
|
|
97b229b2c7 | ||
|
|
6bb5bb9403 | ||
|
|
8c4b8271d8 | ||
|
|
69291c0574 | ||
|
|
2dc073dcd6 | ||
|
|
1894cb35d2 | ||
|
|
cd37420b07 | ||
|
|
55cb6b39db | ||
|
|
89d13b2285 | ||
|
|
1b64b0468a | ||
|
|
085fb83294 | ||
|
|
edd606563f | ||
|
|
fb804e99f0 | ||
|
|
1707cbcb54 | ||
|
|
6d6a630c31 | ||
|
|
ff2990e8e5 | ||
|
|
d679aff0fb | ||
|
|
603a444905 | ||
|
|
a002958448 | ||
|
|
cb4bc37424 | ||
|
|
0fc6f917e6 | ||
|
|
ec0d012b24 | ||
|
|
2cd4b171a1 | ||
|
|
0cb6906c4d | ||
|
|
4c19b93c30 | ||
|
|
6165f1b405 | ||
|
|
37a4221e43 | ||
|
|
9831b222b5 | ||
|
|
7b6f44fb74 | ||
|
|
399f4d0ea3 | ||
|
|
26a668a875 | ||
|
|
bf96262b6e | ||
|
|
1155fa1fe9 | ||
|
|
1875d31731 | ||
|
|
6f855fd14e | ||
|
|
08e392bb46 | ||
|
|
66d63e0546 | ||
|
|
7ee56fe8bc | ||
|
|
669d04ee48 | ||
|
|
cb1b37326e | ||
|
|
7bb73bee67 | ||
|
|
7286ddc338 | ||
|
|
7d1f9e33fe | ||
|
|
63c676ebfe | ||
|
|
fcaf6b7923 | ||
|
|
9f347a170a | ||
|
|
2f7cd4426d | ||
|
|
854f256470 | ||
|
|
5d0b40f752 | ||
|
|
27a2853ee8 | ||
|
|
67f6b80312 | ||
|
|
016037adc1 | ||
|
|
70d5c1034d | ||
|
|
ed6fb8754f | ||
|
|
6d08a9b11c | ||
|
|
cf6aa7cf79 | ||
|
|
6c4e57aae0 | ||
|
|
d08a04959c | ||
|
|
2762f74ce5 | ||
|
|
6ebcf6eec5 | ||
|
|
25b78fb7e1 | ||
|
|
670dd2dd96 | ||
|
|
1baf04f786 | ||
|
|
ce05b7a041 | ||
|
|
290cc146c8 | ||
|
|
db4d46a584 | ||
|
|
8ed2e51dde | ||
|
|
33702c09a6 | ||
|
|
45aeca3753 | ||
|
|
deae7dfb4d | ||
|
|
2af043ebdd | ||
|
|
e121295735 | ||
|
|
7c1c405a64 | ||
|
|
5d7c95a34d | ||
|
|
504c934fc9 | ||
|
|
81b0223f73 | ||
|
|
6d1e410bfd | ||
|
|
26c5c6152d | ||
|
|
d83bf0ebaf | ||
|
|
5adfe9a552 | ||
|
|
883f461dc7 | ||
|
|
8595ebc258 | ||
|
|
2bd31f4560 | ||
|
|
6df85ecadd | ||
|
|
07829918e4 | ||
|
|
b0d400b6eb | ||
|
|
706cb895ad | ||
|
|
45bf539b3c | ||
|
|
0923981f8d | ||
|
|
b0ac14363d | ||
|
|
5d346aba37 | ||
|
|
124cb15ebe | ||
|
|
a244ab898d | ||
|
|
3c551590eb | ||
|
|
10e30cccbc | ||
|
|
806a6b86a2 | ||
|
|
9719fdf5cc | ||
|
|
6d8764f8cb | ||
|
|
d9fd9cb408 | ||
|
|
7710ec0aba | ||
|
|
c97bd78cd0 | ||
|
|
728c5aa86e | ||
|
|
83d68ca293 | ||
|
|
47d7561db4 | ||
|
|
7d993e8319 | ||
|
|
1d1a597b22 | ||
|
|
23082f9300 | ||
|
|
ea1a7f9376 | ||
|
|
1796c7bab8 | ||
|
|
65ad76479a | ||
|
|
422db04ec8 | ||
|
|
d12f60fe37 | ||
|
|
194c1c991c | ||
|
|
3e8e2222c1 | ||
|
|
1620327a33 | ||
|
|
b1131e3667 | ||
|
|
db0250ac08 | ||
|
|
0a6b605760 | ||
|
|
81ac2375e5 | ||
|
|
6bcaca6cd7 | ||
|
|
ec8375252e | ||
|
|
766aa1762f | ||
|
|
5165e0a54c | ||
|
|
a2f7ad627e | ||
|
|
1176c162d4 | ||
|
|
a4880cd017 | ||
|
|
383bdce416 | ||
|
|
7cc300dd83 | ||
|
|
687809db9d | ||
|
|
1127ec3a90 | ||
|
|
a797edfae9 | ||
|
|
938e106252 | ||
|
|
a0eb9caaa2 | ||
|
|
442f53d45e | ||
|
|
68de1ca248 | ||
|
|
e16061141e | ||
|
|
64cbe3d209 | ||
|
|
ebdc6376d8 | ||
|
|
68335123a1 | ||
|
|
25b18f4ef8 | ||
|
|
9ad615b0ff | ||
|
|
12eaceb032 | ||
|
|
3263511b72 | ||
|
|
75cae8c647 | ||
|
|
9991ef624c | ||
|
|
489e9fce27 | ||
|
|
0655628073 | ||
|
|
9460822529 | ||
|
|
d02358ac0d | ||
|
|
366237a625 | ||
|
|
2f2da18994 | ||
|
|
ecd30db215 | ||
|
|
1980854f6f | ||
|
|
7d4f006c25 | ||
|
|
b697be2383 | ||
|
|
143e53c43f | ||
|
|
6dde1ade01 | ||
|
|
d4de391ac5 | ||
|
|
af15f4bc6a | ||
|
|
d4ace24caa | ||
|
|
c5ab47fa66 | ||
|
|
d60051b629 | ||
|
|
22ff330ee7 | ||
|
|
dd62bef66d | ||
|
|
e7feb99f8d | ||
|
|
6358accece | ||
|
|
9ce8a24eea | ||
|
|
4d0673f489 | ||
|
|
fbe1e6a7d5 | ||
|
|
4ed02ca501 | ||
|
|
af245ed9fe | ||
|
|
fc86a3e882 | ||
|
|
f9109edcf1 | ||
|
|
ec100e1a91 | ||
|
|
746c5f4a79 | ||
|
|
b2611728a1 | ||
|
|
fc6cc4234d | ||
|
|
7706c1cb63 | ||
|
|
4d7a07220c | ||
|
|
436875f7dc | ||
|
|
21c6f53ecc | ||
|
|
5472be8b72 | ||
|
|
d22542fcf3 | ||
|
|
1d8341eb27 | ||
|
|
1897a7ada3 | ||
|
|
a048698c66 | ||
|
|
f891e57f4a | ||
|
|
fcc590e48a | ||
|
|
9a02a2a65b | ||
|
|
536a6c5c60 | ||
|
|
86a6871ee8 | ||
|
|
6046045151 | ||
|
|
9c3ddd4ba4 | ||
|
|
6c9f55c1d7 | ||
|
|
5bec3d7dcd | ||
|
|
a4c309efe8 | ||
|
|
4e22a208dd | ||
|
|
ff9e77118e | ||
|
|
6c6dfa9ac4 | ||
|
|
d60d5207d8 | ||
|
|
8c0ae892f5 | ||
|
|
f570492a11 | ||
|
|
cc447304f5 | ||
|
|
8f8c6366e3 | ||
|
|
3b13bcb098 | ||
|
|
df60784b51 | ||
|
|
bae3122bb5 | ||
|
|
0770aef4bf | ||
|
|
c198350bfa | ||
|
|
a2ed388777 | ||
|
|
f6670c699a | ||
|
|
5fa4c95480 | ||
|
|
5b8608c186 | ||
|
|
bb75d42ede | ||
|
|
b4b6def07a | ||
|
|
b305700987 | ||
|
|
40232b7eb1 | ||
|
|
67ff666db4 | ||
|
|
5960fd4fe0 | ||
|
|
f8b28c519c | ||
|
|
ee1105b6dd | ||
|
|
4778274c97 | ||
|
|
d7ecb32238 | ||
|
|
744306fc50 | ||
|
|
11bbb8ed4d | ||
|
|
b5092a4444 | ||
|
|
e2442c07a9 | ||
|
|
6f924d4e83 | ||
|
|
faf1508914 | ||
|
|
7eb8152835 | ||
|
|
8f45905831 | ||
|
|
4ba2ffce5b | ||
|
|
ffb3659ef5 | ||
|
|
6dec07d562 | ||
|
|
afb22f3279 | ||
|
|
f2f369db64 | ||
|
|
635c76db93 | ||
|
|
5f50f1928d | ||
|
|
32c9ed1dc2 | ||
|
|
0536926a1f | ||
|
|
3959c98479 | ||
|
|
2ce5735676 | ||
|
|
71741e144e | ||
|
|
f2e64cdd5e | ||
|
|
afaa5d5e9e | ||
|
|
d82861727d | ||
|
|
90f0795416 | ||
|
|
9efbe7771c | ||
|
|
a75caac13d | ||
|
|
279d0d20ea | ||
|
|
332ba96d34 | ||
|
|
3f6e5b7606 | ||
|
|
94703492fd | ||
|
|
df78117617 | ||
|
|
909b9480e4 | ||
|
|
21762ac1aa | ||
|
|
412bc175b4 | ||
|
|
dc0eb76e88 | ||
|
|
2695941a3c | ||
|
|
3506be1a70 | ||
|
|
cbf4786b39 | ||
|
|
8dbf334208 | ||
|
|
60ba5fbc72 | ||
|
|
c3ace0c44f | ||
|
|
8eceb90e63 | ||
|
|
4754e19e83 | ||
|
|
a0559d0dc9 | ||
|
|
8d03ce19b0 | ||
|
|
2470d851e9 | ||
|
|
df99f5c0a5 | ||
|
|
36f5084c52 | ||
|
|
b77d3f123d | ||
|
|
3c14405155 | ||
|
|
c10b0afaa8 | ||
|
|
3f7a2d6bfb | ||
|
|
f2a0d56e01 | ||
|
|
0736cc8414 | ||
|
|
53240d40a0 | ||
|
|
4137dd7cc8 | ||
|
|
8907290d27 | ||
|
|
401dc1cb10 | ||
|
|
a6b5d26f56 | ||
|
|
eb55cba34a | ||
|
|
b0b41d984e | ||
|
|
947f64e32d | ||
|
|
24ccbfa9b6 | ||
|
|
8110acb795 | ||
|
|
7473aede60 | ||
|
|
6f204f721b | ||
|
|
7b0e08094a | ||
|
|
322e1a75b9 | ||
|
|
a0806d98a1 | ||
|
|
182897d971 | ||
|
|
f90a639fcc | ||
|
|
d95d7208a2 | ||
|
|
bbac8ffe64 | ||
|
|
801a649fb1 | ||
|
|
7c09ceecfd | ||
|
|
8c4954fb9b | ||
|
|
fbe892105b | ||
|
|
584e1bb847 | ||
|
|
c437ab282e | ||
|
|
42a100d138 | ||
|
|
65807bf35d | ||
|
|
2995f48ede | ||
|
|
d452702aef | ||
|
|
f8ed9c7357 | ||
|
|
9143120177 | ||
|
|
fd3b1bee92 | ||
|
|
bff42954d1 | ||
|
|
6b74fd6a02 | ||
|
|
0547cebfe2 | ||
|
|
caefdf4300 | ||
|
|
a59df15994 | ||
|
|
33304eb8d9 | ||
|
|
eb21a1bfb3 | ||
|
|
ce0333b0a7 | ||
|
|
25a1b53a91 | ||
|
|
6aba73f970 | ||
|
|
6406bb7fb6 | ||
|
|
2458107903 | ||
|
|
628f9bd9b5 | ||
|
|
2d791571d5 | ||
|
|
ed57127a79 | ||
|
|
6d9bcff8e1 | ||
|
|
8126cd1879 | ||
|
|
ab34c2261c | ||
|
|
6953f65970 | ||
|
|
52073e79fa | ||
|
|
8e3484bb17 | ||
|
|
7110da8a36 | ||
|
|
7ffd6ded51 | ||
|
|
5e04547ecf | ||
|
|
7cbe5f64ce | ||
|
|
47ed78031a | ||
|
|
fd3d24b834 | ||
|
|
c2f607b452 | ||
|
|
b1328bb6e2 | ||
|
|
2a02583e27 | ||
|
|
cfb49f9136 | ||
|
|
5f20091f24 | ||
|
|
a37b8e35a1 | ||
|
|
84c980c3ea | ||
|
|
5823057b41 | ||
|
|
024a9b1763 | ||
|
|
0425780cd3 | ||
|
|
20734dc7f3 | ||
|
|
0574c58f16 | ||
|
|
31e3117190 | ||
|
|
f780ba2c5a | ||
|
|
f125b593bf | ||
|
|
baee4e185d | ||
|
|
ca8476d466 | ||
|
|
757bf82a78 | ||
|
|
644887f727 | ||
|
|
563b643461 | ||
|
|
0e4a6fd2e1 | ||
|
|
d452bf1f1c | ||
|
|
126828a813 | ||
|
|
03dc6fb73a | ||
|
|
3653e89714 | ||
|
|
318dd14e42 | ||
|
|
2d13844b5d | ||
|
|
b777b7432a | ||
|
|
6f91c225c2 | ||
|
|
c355e9ca4a | ||
|
|
4514ea8123 | ||
|
|
a9a1472cb7 | ||
|
|
250b0eee28 | ||
|
|
5cd7527937 | ||
|
|
57ebd5bb7a | ||
|
|
c18a697d6b | ||
|
|
ad40b72508 | ||
|
|
3a72e5910d | ||
|
|
8f3eb65a05 | ||
|
|
700cd83ff5 | ||
|
|
0c27881eaf | ||
|
|
f7fdc6acd2 | ||
|
|
2c5f844edc | ||
|
|
a253de43c5 | ||
|
|
dbaf67a986 | ||
|
|
5175d06e37 | ||
|
|
651a27b558 | ||
|
|
fd41f8def6 | ||
|
|
208ea04fd5 | ||
|
|
5ee83a1af9 | ||
|
|
901c7704f4 | ||
|
|
c6f7290f92 | ||
|
|
5368eda98b | ||
|
|
7b9be209c8 | ||
|
|
cee05fea7c | ||
|
|
b87acb47e2 | ||
|
|
cb192bf9ea | ||
|
|
16351ba7f3 | ||
|
|
96ba128942 | ||
|
|
76c8d4af25 | ||
|
|
3ea2b3cc00 | ||
|
|
0df0936022 | ||
|
|
4fc11a7fd3 | ||
|
|
8c509271a6 | ||
|
|
67d5b63ef9 | ||
|
|
4f999511a6 | ||
|
|
cfbf239175 | ||
|
|
1aedf9bb07 | ||
|
|
c2d4423720 | ||
|
|
c2f7a2620c | ||
|
|
6f0cda34b4 | ||
|
|
1a472fdf1f | ||
|
|
0551f61228 | ||
|
|
b900adfddd | ||
|
|
0e339daef5 | ||
|
|
5f5733e8b9 | ||
|
|
1372050a7b | ||
|
|
1960951c5e | ||
|
|
bc070407c7 | ||
|
|
0172ee0b6b | ||
|
|
2953bc6bb8 | ||
|
|
c0ed3a9e3c | ||
|
|
5456e4fe75 | ||
|
|
867a1e960e | ||
|
|
48dc68c3fe | ||
|
|
2c719f326b | ||
|
|
201f92eb93 | ||
|
|
46f055b216 | ||
|
|
08305e679b | ||
|
|
e9e0b70199 | ||
|
|
441d784027 | ||
|
|
558956bf55 | ||
|
|
0d8250a3ac | ||
|
|
dc1f5826f8 | ||
|
|
06fb06829b | ||
|
|
bbf52d2611 | ||
|
|
f55a6617e9 | ||
|
|
3bd273fbdd | ||
|
|
1b64a543f1 | ||
|
|
97b07f7d42 | ||
|
|
ebb472b8f6 | ||
|
|
1a2ef6479e | ||
|
|
876c63fe80 | ||
|
|
32236962f5 | ||
|
|
ba66af922f | ||
|
|
28b9bbe54f | ||
|
|
bf6bd7cbdc | ||
|
|
ddcb2468a6 | ||
|
|
f048b58935 | ||
|
|
09f6200c2e | ||
|
|
354692fb06 | ||
|
|
2c5858c2e0 | ||
|
|
1f41fd0436 | ||
|
|
e0bbefdfae | ||
|
|
bc6fbb2797 | ||
|
|
b579cf8128 | ||
|
|
a94ed014b7 | ||
|
|
0db991b668 | ||
|
|
347ced6942 | ||
|
|
5d7a775b2b | ||
|
|
df732ab4bf | ||
|
|
31cd3953d6 | ||
|
|
4666b13892 | ||
|
|
37d7ddb4b0 | ||
|
|
3abbaeb44b | ||
|
|
847ea49042 | ||
|
|
779068c2ee | ||
|
|
140cd6882d | ||
|
|
2e295c2391 | ||
|
|
596b0995f4 | ||
|
|
b61fe97893 | ||
|
|
209aa2ebe6 | ||
|
|
c03a0e857e | ||
|
|
2854d698e6 | ||
|
|
944163be0e | ||
|
|
269a9eaff0 | ||
|
|
7f9c49cbc4 | ||
|
|
2b6bfeeb15 | ||
|
|
fa9742bc92 | ||
|
|
472e419abc | ||
|
|
169d11387b | ||
|
|
e59ac6d947 | ||
|
|
e193b45562 | ||
|
|
1ac34f810e | ||
|
|
e65e5c6e5f | ||
|
|
af6365c76a | ||
|
|
8c672b23b5 | ||
|
|
3b53f5ac11 | ||
|
|
ccdc744748 | ||
|
|
261f0b4bf0 | ||
|
|
495b59c2e5 | ||
|
|
d6e1c13c39 | ||
|
|
f7f13b9e07 | ||
|
|
62564d747f | ||
|
|
1d5d59c4c0 | ||
|
|
e8380b8a12 | ||
|
|
c304d9cc62 | ||
|
|
aad4ebf287 | ||
|
|
6c2f48181c | ||
|
|
480b6ff7d6 | ||
|
|
4bdd6f972c | ||
|
|
6674d8456a | ||
|
|
d1478ff694 | ||
|
|
cb20d46b74 | ||
|
|
9dd2538043 | ||
|
|
f25136a512 | ||
|
|
03eb56ad2a | ||
|
|
2508840701 | ||
|
|
6e098f5a4f | ||
|
|
31b33406fd | ||
|
|
7ab7c763ed | ||
|
|
06258e757a | ||
|
|
5919b43a21 | ||
|
|
7d4b9521e7 | ||
|
|
f9d2fd7997 | ||
|
|
bdbc20c3c6 | ||
|
|
69d6d03714 | ||
|
|
f40e1e55b0 | ||
|
|
b9082ed838 | ||
|
|
4edfefa9a2 | ||
|
|
0f98ee5407 | ||
|
|
7fdf119873 | ||
|
|
3c054e6ea1 | ||
|
|
98899ece72 | ||
|
|
2061a006d0 | ||
|
|
5496c2d7fd | ||
|
|
d6b862a4a9 | ||
|
|
d581f8a852 | ||
|
|
3a593ee35a | ||
|
|
415d34fdaa | ||
|
|
7d28191bb5 | ||
|
|
e2c7693370 | ||
|
|
f17ff02f4d | ||
|
|
225043e01d | ||
|
|
56f78349f8 | ||
|
|
8839d4f55a | ||
|
|
2562aec1d2 | ||
|
|
db2361be84 | ||
|
|
d08fcbfef3 | ||
|
|
7601b93e65 | ||
|
|
1103ec40e0 | ||
|
|
af32c7e3db | ||
|
|
170918eb3b | ||
|
|
a91e615a8d | ||
|
|
cc92c26fe3 | ||
|
|
937135db32 | ||
|
|
01366558b4 | ||
|
|
b0dbd54ea4 | ||
|
|
f113915307 | ||
|
|
0a3c3d9bb1 | ||
|
|
ba2e005c3e | ||
|
|
b9ea52d65f | ||
|
|
f1e328d333 | ||
|
|
23f1965398 | ||
|
|
fc82f185cb | ||
|
|
56b25f373f | ||
|
|
1ac6add122 | ||
|
|
91b1a903f9 | ||
|
|
a8d6654ef5 | ||
|
|
63093b1be6 | ||
|
|
60abe8f37e | ||
|
|
7ba3909aa1 | ||
|
|
eecdba2d05 | ||
|
|
7bdc005aa7 | ||
|
|
d46703fdc4 | ||
|
|
e4aa85f603 | ||
|
|
233124ef50 | ||
|
|
36a3012de2 | ||
|
|
2b4ee96ed7 | ||
|
|
85a2afd55c | ||
|
|
6cd0d8456a | ||
|
|
7750a0a773 | ||
|
|
a5364b9257 | ||
|
|
e0e7b1406d | ||
|
|
38b67a0002 | ||
|
|
18dd4f8a52 | ||
|
|
879f9b4ea9 | ||
|
|
3db0dda67a | ||
|
|
ed9ee15b90 | ||
|
|
44ff85e8e9 | ||
|
|
cb07e9ba11 | ||
|
|
bfe05ce5fc | ||
|
|
64ee23cec0 | ||
|
|
c022d3c4a4 | ||
|
|
69c764301f | ||
|
|
2f777daef6 | ||
|
|
a10bf7330e | ||
|
|
782bb5967d | ||
|
|
aeb2f55f0d | ||
|
|
ae68749b1b | ||
|
|
a3c25d56a0 | ||
|
|
d2b9cc8df9 | ||
|
|
2027daa75c | ||
|
|
f3493a08bd | ||
|
|
f3963269ae | ||
|
|
ae2212c245 | ||
|
|
3a19ac4c93 | ||
|
|
666f546cf0 | ||
|
|
464f57d7da | ||
|
|
2a192f33a1 | ||
|
|
9ca2674261 | ||
|
|
24bc91dc0c | ||
|
|
cf2d5b502f | ||
|
|
61450ef602 | ||
|
|
78f1d1738e | ||
|
|
9f595cf5f7 | ||
|
|
25b8e49975 | ||
|
|
d40086cd13 | ||
|
|
8f9d8d93b9 | ||
|
|
1080c10004 | ||
|
|
866aeca220 | ||
|
|
121b3afc61 | ||
|
|
e8406b04b4 | ||
|
|
8e7fe81806 | ||
|
|
852807b5d7 | ||
|
|
9928d47fa2 | ||
|
|
412a1bd62a | ||
|
|
b290520951 | ||
|
|
dde677b6d3 | ||
|
|
75030847bd | ||
|
|
e7b9cb76bc | ||
|
|
e96c4c0dd3 | ||
|
|
b553b3fa50 | ||
|
|
c6fb924b8f | ||
|
|
b13844c4a6 | ||
|
|
ab6c83a3fc | ||
|
|
7e0a97973f | ||
|
|
6a8a79bba5 | ||
|
|
4a0c58c50a | ||
|
|
eb0c963332 | ||
|
|
023fe82932 | ||
|
|
2e1a06c7bf | ||
|
|
8b6961d40c | ||
|
|
53351877da | ||
|
|
522445894e | ||
|
|
550351bb16 | ||
|
|
328adbb56f | ||
|
|
44a36bbba3 | ||
|
|
4cc4adeda6 | ||
|
|
c14e6f2a63 | ||
|
|
cfcb2d54d8 | ||
|
|
010d60e504 | ||
|
|
eabde07ff6 | ||
|
|
be19ad5f2a | ||
|
|
d1d0816961 | ||
|
|
7be7170504 | ||
|
|
478272f515 | ||
|
|
09af6958c8 | ||
|
|
adb3a2b64e | ||
|
|
1ee7e842dc | ||
|
|
b080a57406 | ||
|
|
7c017e345a | ||
|
|
4b91343155 | ||
|
|
02a3df8ad0 | ||
|
|
6a7080f4ee | ||
|
|
4547042577 | ||
|
|
0e39eea7f8 | ||
|
|
1e5aefea63 | ||
|
|
02c4f333b0 | ||
|
|
1e8fc4020b | ||
|
|
f969701ac1 | ||
|
|
b236243857 | ||
|
|
39edc64922 | ||
|
|
f22ece403f | ||
|
|
f5423bb314 | ||
|
|
b1e5945ebe | ||
|
|
76b5be8171 | ||
|
|
804bca2041 | ||
|
|
10602b47b4 | ||
|
|
8d7c522596 | ||
|
|
3ac455c5a7 | ||
|
|
2b19a459df | ||
|
|
41ba2d9bf6 | ||
|
|
a7b5eb69d3 | ||
|
|
67c209bb5e | ||
|
|
a6d436d9ea | ||
|
|
652c784e13 | ||
|
|
a0a3b7a158 | ||
|
|
789f51bd2a | ||
|
|
c2f1a74f96 | ||
|
|
a9ed7a3f3b | ||
|
|
b348e88a5f | ||
|
|
1615395866 | ||
|
|
e483abcad0 | ||
|
|
12b6760f6e | ||
|
|
6fde6d7eac | ||
|
|
a7ef891217 | ||
|
|
8f22dfe87b | ||
|
|
2dc7fab39a | ||
|
|
74cb2e3c63 | ||
|
|
6e763a58f1 | ||
|
|
a8e72ed410 | ||
|
|
fcdfd5f936 | ||
|
|
f1faa463c1 | ||
|
|
a0f4952b54 | ||
|
|
bd82ded07d | ||
|
|
016e17dedb | ||
|
|
5cd3e1b368 | ||
|
|
b2b39458da | ||
|
|
556bbe394d | ||
|
|
07288b3f26 | ||
|
|
90f79b7708 | ||
|
|
e220786a20 | ||
|
|
f16b993294 | ||
|
|
c241bea3bf | ||
|
|
084654cd3c | ||
|
|
d21742afb6 | ||
|
|
b5259384e8 | ||
|
|
bf78ad9fbe | ||
|
|
ab3577c369 | ||
|
|
6efb90c94e | ||
|
|
cbcc400eb4 | ||
|
|
15aec7da7e | ||
|
|
46535e4f56 | ||
|
|
e3f945c079 | ||
|
|
04239c57fe | ||
|
|
ad4439ed55 | ||
|
|
9fe3ef430f | ||
|
|
ff30773097 | ||
|
|
f7531d1e18 | ||
|
|
658008ab64 | ||
|
|
b089d63112 | ||
|
|
ee9b1b7f57 | ||
|
|
cd0fc8176f | ||
|
|
8e291e3e46 | ||
|
|
e3024076cd | ||
|
|
6105874abc | ||
|
|
1855f7829d | ||
|
|
456e8bd9c0 | ||
|
|
d5f2efac26 | ||
|
|
21e692623c | ||
|
|
80e9589af5 | ||
|
|
b2b9ae0677 | ||
|
|
63122905e6 | ||
|
|
f99b6f4646 | ||
|
|
39090c2a22 | ||
|
|
76baa8c791 | ||
|
|
74e4b9d6d2 | ||
|
|
bbfc5039f7 | ||
|
|
b2fd694483 | ||
|
|
b03f38ff22 | ||
|
|
fe48811047 | ||
|
|
bd9396b031 | ||
|
|
f0497ec16d | ||
|
|
7e9e179fa7 | ||
|
|
de62464ad8 | ||
|
|
f6911ca195 | ||
|
|
aec09ed8d2 | ||
|
|
51a983e460 | ||
|
|
0eb46e29c7 | ||
|
|
5ee11c7b6b | ||
|
|
b55accd76f | ||
|
|
fef2be1bc7 | ||
|
|
0b3858f91d | ||
|
|
d07ea1b337 | ||
|
|
7e2dbc7358 | ||
|
|
c676f08a7c | ||
|
|
92f24b5728 | ||
|
|
0254e71435 | ||
|
|
2972fc5814 | ||
|
|
975c96217c | ||
|
|
c30c1848bc | ||
|
|
94615d3b36 | ||
|
|
37a00f0d16 | ||
|
|
0dbe70f5af | ||
|
|
7584374b0b | ||
|
|
71ca51dc1a | ||
|
|
aa81e72e45 | ||
|
|
9954bb9c15 | ||
|
|
e5c0250423 | ||
|
|
135799ed5e | ||
|
|
22c3b57960 | ||
|
|
7054dd74a4 | ||
|
|
d4f1e52ef6 | ||
|
|
76a44459cf | ||
|
|
a5590b090c | ||
|
|
74c9a57070 | ||
|
|
06e283e070 | ||
|
|
8ab2ca3f24 | ||
|
|
0eb949ba39 | ||
|
|
be35693814 | ||
|
|
1e5f13795c | ||
|
|
cca2265633 | ||
|
|
0f0d1ac370 | ||
|
|
d52d4ac183 | ||
|
|
841220fd01 | ||
|
|
ca5e10784b | ||
|
|
712319974b | ||
|
|
067a6d01bc | ||
|
|
27825f9e2e | ||
|
|
425eb115dc | ||
|
|
0a5ce55e2b | ||
|
|
dbc8ed9d4c | ||
|
|
e31e990684 | ||
|
|
8618f56481 | ||
|
|
a39fc4667e | ||
|
|
4c369e240b | ||
|
|
4e291d01d4 | ||
|
|
b32fce46cb | ||
|
|
d1fcd45aac | ||
|
|
ebdb92c708 | ||
|
|
112909d35b | ||
|
|
c6e2c559f1 | ||
|
|
cf8613886a | ||
|
|
39c25c2001 | ||
|
|
9c9721ade5 | ||
|
|
4b8abe4ce8 | ||
|
|
33dfaba276 | ||
|
|
dd8bbcf358 | ||
|
|
cc3e4369ed | ||
|
|
548355fce6 | ||
|
|
a4e0e6544b | ||
|
|
62067e0801 | ||
|
|
5eb40d2299 | ||
|
|
53990a531b | ||
|
|
d799aea3c4 | ||
|
|
9af86cbba2 | ||
|
|
6fbfece4ff | ||
|
|
d56cca7873 | ||
|
|
fa1096a6ba | ||
|
|
16ff721331 | ||
|
|
798ee9dc46 | ||
|
|
bc17c60305 | ||
|
|
432688d577 | ||
|
|
da8d4b47f1 | ||
|
|
ed1e2e2449 | ||
|
|
b9744b4688 | ||
|
|
2f328f8f37 | ||
|
|
ffefd7e50b | ||
|
|
c2445f8a7c | ||
|
|
54d44079cc | ||
|
|
87f089a12c | ||
|
|
aa2172e4db | ||
|
|
0a33e94e79 | ||
|
|
fada54abae | ||
|
|
802641b719 | ||
|
|
1da93829d4 | ||
|
|
9e7acbc49a | ||
|
|
318765d40b | ||
|
|
94ba20dfa1 | ||
|
|
2ad3dc4a32 | ||
|
|
eef940dd7c | ||
|
|
1b5fc12ac1 | ||
|
|
c1c7b8dfcd | ||
|
|
d4510c2afe | ||
|
|
f241f073a3 | ||
|
|
26a6c72611 | ||
|
|
51cee7804b | ||
|
|
52228430f1 | ||
|
|
4fcd45d8a4 | ||
|
|
ea5736947d | ||
|
|
6b5f36fb7e | ||
|
|
b328d6d95f | ||
|
|
2e06921bf8 | ||
|
|
fd95e2d711 | ||
|
|
490e253b79 | ||
|
|
8a10f5cd52 | ||
|
|
5cebcc2424 | ||
|
|
7663b89289 | ||
|
|
d0d1f9e3c0 | ||
|
|
4433760e37 | ||
|
|
b63fcd2254 | ||
|
|
eb2aa352ef | ||
|
|
ec95f198ec | ||
|
|
f166e480f1 | ||
|
|
2051f0486c | ||
|
|
f33fc5d730 | ||
|
|
1603df3503 | ||
|
|
6055ac182b | ||
|
|
4678f60adf | ||
|
|
b48521950e | ||
|
|
45da6fb39f | ||
|
|
1604d327da | ||
|
|
98b2b325a1 | ||
|
|
55b3def630 | ||
|
|
1b5f6bd3eb | ||
|
|
3472b85345 | ||
|
|
1c6ae53656 | ||
|
|
a84a56f611 | ||
|
|
69751aa415 | ||
|
|
9ef0337807 | ||
|
|
a3fdd274c3 | ||
|
|
f069c02153 | ||
|
|
ad0d14c517 | ||
|
|
a72da79743 | ||
|
|
6bc35217d9 | ||
|
|
c526e9ac8f | ||
|
|
3dfebcadc1 | ||
|
|
693af532a2 | ||
|
|
4bac57fcd1 | ||
|
|
59291fcac2 | ||
|
|
1f21b202a5 | ||
|
|
b3ca02a166 | ||
|
|
2462f8f87e | ||
|
|
18268acc1f | ||
|
|
44f4423a9d | ||
|
|
37250a6f48 | ||
|
|
fd97541417 | ||
|
|
dba3e30d02 | ||
|
|
5962283ad3 | ||
|
|
cdd705831b | ||
|
|
a1a7c5e4bb | ||
|
|
c1e9061568 | ||
|
|
90ee04de57 | ||
|
|
cd24cfbe5c | ||
|
|
5b05668a30 | ||
|
|
a2eca9589f | ||
|
|
a2adbb19bd | ||
|
|
012e5c09ed | ||
|
|
5f33aa7fd4 | ||
|
|
7ea2204dfd | ||
|
|
be8cadf5ac | ||
|
|
fc7192c748 | ||
|
|
5c6b6b3919 | ||
|
|
87553ac685 | ||
|
|
384f396bbb | ||
|
|
d40560bd49 | ||
|
|
67952ca246 | ||
|
|
4ddbefb147 | ||
|
|
edabc17ac9 | ||
|
|
c7e8211fae | ||
|
|
dc3f07dd52 | ||
|
|
fae6a5cfb4 | ||
|
|
cafd225797 | ||
|
|
bf77d2973e | ||
|
|
dfd8133431 | ||
|
|
e9d78b8990 | ||
|
|
13532cdffb | ||
|
|
c17620efb7 | ||
|
|
d3b5b1080f | ||
|
|
e4b0c23bb9 | ||
|
|
6c24fb6d79 | ||
|
|
bd93551c13 | ||
|
|
dc0799a56b | ||
|
|
e1fca1520b | ||
|
|
c72f3b8efb | ||
|
|
afcd172a94 | ||
|
|
5957700699 | ||
|
|
451d023e81 | ||
|
|
64d166cebf | ||
|
|
51b067def7 | ||
|
|
de25e8dd6f | ||
|
|
39ac291ba2 | ||
|
|
722d26c5b9 | ||
|
|
0346760a75 | ||
|
|
a2015143f8 | ||
|
|
071d99a7b4 | ||
|
|
e6d8e063c9 | ||
|
|
29526144c9 | ||
|
|
b88bcafddd | ||
|
|
78d844d693 | ||
|
|
49310b53e9 | ||
|
|
4684487ff8 | ||
|
|
89250205dc | ||
|
|
9039919b03 | ||
|
|
df16803f11 | ||
|
|
48327cf5f8 | ||
|
|
2ead125b9d | ||
|
|
23807f11f9 | ||
|
|
cad666d07f | ||
|
|
a0b11051e1 | ||
|
|
b6e6fb9de2 | ||
|
|
4172fd8aff | ||
|
|
d60df6ca69 | ||
|
|
f9ba7377eb | ||
|
|
5d3c47b8ae | ||
|
|
ef9cc860a9 | ||
|
|
5a1ec8aa74 | ||
|
|
ac435f3699 | ||
|
|
0374dec79c | ||
|
|
41b6bf38c4 | ||
|
|
ddba251449 | ||
|
|
bf76e47648 | ||
|
|
5a3ad35bdd | ||
|
|
7da18274ad | ||
|
|
9b66ae05eb | ||
|
|
d407964625 | ||
|
|
bc254d5a8d | ||
|
|
1d9128a650 | ||
|
|
a1f2e9e4e2 | ||
|
|
8c8188c24f | ||
|
|
e42eaf73b8 | ||
|
|
fbd8552c0b | ||
|
|
daa26b2e1e | ||
|
|
18473e6819 | ||
|
|
a51d6b9a74 | ||
|
|
706871c12a | ||
|
|
16c49e965c | ||
|
|
f29e867441 | ||
|
|
4a5f6d8393 | ||
|
|
39e3025077 | ||
|
|
9ee293816d | ||
|
|
b3c1397753 | ||
|
|
93d63538bb | ||
|
|
09c28d2311 | ||
|
|
5b8ed496db | ||
|
|
27b4cf743e | ||
|
|
95938a65b6 | ||
|
|
70780fc4ef | ||
|
|
21d265d12f | ||
|
|
788526d6eb | ||
|
|
a7203e9a17 | ||
|
|
eff50daae4 | ||
|
|
7612db15e0 | ||
|
|
0731ee473d | ||
|
|
3a6a76fe19 | ||
|
|
edb0509194 | ||
|
|
1806be1fd7 | ||
|
|
7769f25869 | ||
|
|
f6e5743f20 | ||
|
|
1ef6196de6 | ||
|
|
75ceee23ec | ||
|
|
38f2372ee8 | ||
|
|
b58826da6e | ||
|
|
2c05e606c7 | ||
|
|
92f1c080c4 | ||
|
|
8f79699e84 | ||
|
|
e7b3e28f76 | ||
|
|
123677b6c6 | ||
|
|
f393c7173c | ||
|
|
0abfb9f1e4 | ||
|
|
379771a5c1 | ||
|
|
2f4a76b3fa | ||
|
|
7d82e199b7 | ||
|
|
de693a08ad | ||
|
|
923091ca62 | ||
|
|
cb65ddedb6 | ||
|
|
7aa75539c9 | ||
|
|
a1a7cf59b3 | ||
|
|
f572cb5f3e | ||
|
|
8f1a31ad13 | ||
|
|
dcf63e3da2 | ||
|
|
153dca8137 | ||
|
|
db97787b15 | ||
|
|
7148fec6e1 | ||
|
|
db6d48f8ca | ||
|
|
6d87a1a604 | ||
|
|
5c414fc7b4 | ||
|
|
127f4446ae | ||
|
|
49a49e2a2c | ||
|
|
8b9389b468 | ||
|
|
ee17336d64 | ||
|
|
2b768d2fb5 | ||
|
|
4fc63010d4 | ||
|
|
3311ded843 | ||
|
|
135c2e7a71 | ||
|
|
a3a8f600b6 | ||
|
|
23643b99e2 | ||
|
|
764a334952 | ||
|
|
6f163f2d01 | ||
|
|
aae65f8235 | ||
|
|
764ea571eb | ||
|
|
aef719b574 | ||
|
|
73e52e625b | ||
|
|
a967588fe1 | ||
|
|
72e530f062 | ||
|
|
a0b422f99e | ||
|
|
6b92f30324 | ||
|
|
464cfe701c | ||
|
|
070fa03108 | ||
|
|
51abeabb33 | ||
|
|
74b0697da1 |
15
.babelrc
15
.babelrc
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"comments": false,
|
||||
"compact": true,
|
||||
"optional": [
|
||||
// This options are experimental for now and may (will) break the
|
||||
// code.
|
||||
// "minification.deadCodeElimination",
|
||||
// "minification.inlineExpressions",
|
||||
|
||||
"es7.asyncFunctions",
|
||||
"es7.decorators",
|
||||
"es7.functionBind",
|
||||
"runtime"
|
||||
]
|
||||
}
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,5 +1,11 @@
|
||||
/.nyc_output/
|
||||
/dist/
|
||||
/node_modules/
|
||||
/src/api/index.js
|
||||
/src/xapi/mixins/index.js
|
||||
/src/xo-mixins/index.js
|
||||
|
||||
npm-debug.log
|
||||
npm-debug.log.*
|
||||
|
||||
.xo-server.*
|
||||
|
||||
93
.jshintrc
93
.jshintrc
@@ -1,93 +0,0 @@
|
||||
{
|
||||
// Julien Fontanet JSHint configuration
|
||||
// https://gist.github.com/julien-f/8095615
|
||||
//
|
||||
// Changes from defaults:
|
||||
// - all enforcing options (except `++` & `--`) enabled
|
||||
// - single quotes
|
||||
// - indentation set to 2 instead of 4
|
||||
// - almost all relaxing options disabled
|
||||
// - environments are set to Node.js
|
||||
//
|
||||
// See http://jshint.com/docs/ for more details
|
||||
|
||||
"maxerr" : 50, // {int} Maximum error before stopping
|
||||
|
||||
// Enforcing
|
||||
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
|
||||
"camelcase" : true, // true: Identifiers must be in camelCase
|
||||
"curly" : true, // true: Require {} for every new block or scope
|
||||
"eqeqeq" : true, // true: Require triple equals (===) for comparison
|
||||
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
|
||||
"freeze" : true, // true: Prohibit overwriting prototypes of native objects (Array, Date, ...)
|
||||
"immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
|
||||
"indent" : 2, // {int} Number of spaces to use for indentation
|
||||
"latedef" : true, // true: Require variables/functions to be defined before being used
|
||||
"newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
|
||||
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
|
||||
"noempty" : true, // true: Prohibit use of empty blocks
|
||||
"nonbsp" : true, // true: Prohibit use of non breakable spaces
|
||||
"nonew" : true, // true: Prohibit use of constructors for side-effects (without assignment)
|
||||
"plusplus" : false, // true: Prohibit use of `++` & `--`
|
||||
"quotmark" : "single", // Quotation mark consistency:
|
||||
// false : do nothing (default)
|
||||
// true : ensure whatever is used is consistent
|
||||
// "single" : require single quotes
|
||||
// "double" : require double quotes
|
||||
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
|
||||
"unused" : true, // true: Require all defined variables be used
|
||||
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
|
||||
"maxcomplexity" : 7, // {int} Max cyclomatic complexity per function
|
||||
"maxdepth" : 3, // {int} Max depth of nested blocks (within functions)
|
||||
"maxlen" : 80, // {int} Max number of characters per line
|
||||
"maxparams" : 4, // {int} Max number of formal params allowed per function
|
||||
"maxstatements" : 20, // {int} Max number statements per function
|
||||
|
||||
// Relaxing
|
||||
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
|
||||
"boss" : false, // true: Tolerate assignments where comparisons would be expected
|
||||
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
|
||||
"eqnull" : false, // true: Tolerate use of `== null`
|
||||
"esnext" : true, // true: Allow ES.next (ES6) syntax (ex: `const`)
|
||||
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
|
||||
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
|
||||
"funcscope" : false, // true: Tolerate defining variables inside control statements
|
||||
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
|
||||
"iterator" : false, // true: Tolerate using the `__iterator__` property
|
||||
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
|
||||
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
|
||||
"laxcomma" : false, // true: Tolerate comma-first style coding
|
||||
"loopfunc" : false, // true: Tolerate functions being defined in loops
|
||||
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
|
||||
// (ex: `for each`, multiple try/catch, function expression…)
|
||||
"multistr" : false, // true: Tolerate multi-line strings
|
||||
"notypeof" : false, // true: Tolerate typeof comparison with unknown values.
|
||||
"proto" : false, // true: Tolerate using the `__proto__` property
|
||||
"scripturl" : false, // true: Tolerate script-targeted URLs
|
||||
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
|
||||
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
|
||||
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
|
||||
"validthis" : false, // true: Tolerate using this in a non-constructor function
|
||||
"noyield" : false, // true: Tolerate generators without yields
|
||||
|
||||
// Environments
|
||||
"browser" : false, // Web Browser (window, document, etc)
|
||||
"browserify" : false, // Browserify (node.js code in the browser)
|
||||
"couch" : false, // CouchDB
|
||||
"devel" : false, // Development/debugging (alert, confirm, etc)
|
||||
"dojo" : false, // Dojo Toolkit
|
||||
"jquery" : false, // jQuery
|
||||
"mocha" : false, // mocha
|
||||
"mootools" : false, // MooTools
|
||||
"node" : true, // Node.js
|
||||
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
|
||||
"phantom" : false, // PhantomJS
|
||||
"prototypejs" : false, // Prototype and Scriptaculous
|
||||
"rhino" : false, // Rhino
|
||||
"worker" : false, // Web Workers
|
||||
"wsh" : false, // Windows Scripting Host
|
||||
"yui" : false, // Yahoo User Interface
|
||||
|
||||
// Custom Globals
|
||||
"globals" : {} // additional predefined global variables
|
||||
}
|
||||
3
.mention-bot
Normal file
3
.mention-bot
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"userBlacklist": [ "greenkeeper", "Wescoeur" ]
|
||||
}
|
||||
10
.npmignore
Normal file
10
.npmignore
Normal file
@@ -0,0 +1,10 @@
|
||||
/examples/
|
||||
example.js
|
||||
example.js.map
|
||||
*.example.js
|
||||
*.example.js.map
|
||||
|
||||
/test/
|
||||
/tests/
|
||||
*.spec.js
|
||||
*.spec.js.map
|
||||
9
.travis.yml
Normal file
9
.travis.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- stable
|
||||
- 6
|
||||
- 4
|
||||
|
||||
# Use containers.
|
||||
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
||||
sudo: false
|
||||
3
ISSUE_TEMPLATE.md
Normal file
3
ISSUE_TEMPLATE.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# ALL ISSUES SHOULD BE CREATED IN XO-WEB'S TRACKER!
|
||||
|
||||
https://github.com/vatesfr/xo-web/issues
|
||||
@@ -11,6 +11,7 @@ It contains all the logic of XO and handles:
|
||||
- users authentication and authorizations (work in progress);
|
||||
- a JSON-RPC based interface for XO clients (i.e. [XO-Web](https://github.com/vatesfr/xo-web)).
|
||||
|
||||
[](https://travis-ci.org/vatesfr/xo-server)
|
||||
[](https://david-dm.org/vatesfr/xo-server)
|
||||
[](https://david-dm.org/vatesfr/xo-server#info=devDependencies)
|
||||
|
||||
@@ -18,7 +19,7 @@ ___
|
||||
|
||||
## Installation
|
||||
|
||||
Manual install procedure is [available here](https://github.com/vatesfr/xo/blob/master/doc/installation/README.md#installation).
|
||||
Manual install procedure is [available here](https://xen-orchestra.com/docs/from_the_sources.html).
|
||||
|
||||
## Compilation
|
||||
|
||||
@@ -36,6 +37,4 @@ $ npm run dev
|
||||
|
||||
## How to report a bug?
|
||||
|
||||
If you are certain the bug is exclusively related to XO-Server, you may use the [bugtracker of this repository](https://github.com/vatesfr/xo-server/issues).
|
||||
|
||||
Otherwise, please consider using the [bugtracker of the general repository](https://github.com/vatesfr/xo/issues).
|
||||
All bug reports should go into the [bugtracker of xo-web](https://github.com/vatesfr/xo-web/issues).
|
||||
|
||||
29
better-stacks.js
Normal file
29
better-stacks.js
Normal file
@@ -0,0 +1,29 @@
|
||||
Error.stackTraceLimit = 100
|
||||
|
||||
// Removes internal modules.
|
||||
try {
|
||||
var sep = require('path').sep
|
||||
|
||||
require('stack-chain').filter.attach(function (_, frames) {
|
||||
var filtered = frames.filter(function (frame) {
|
||||
var name = frame && frame.getFileName()
|
||||
|
||||
return (
|
||||
// has a filename
|
||||
name &&
|
||||
|
||||
// contains a separator (no internal modules)
|
||||
name.indexOf(sep) !== -1
|
||||
)
|
||||
})
|
||||
|
||||
// depd (used amongst other by express requires at least 3 frames
|
||||
// in the stack.
|
||||
return filtered.length > 2
|
||||
? filtered
|
||||
: frames
|
||||
})
|
||||
} catch (_) {}
|
||||
|
||||
// Source maps.
|
||||
try { require('julien-f-source-map-support/register') } catch (_) {}
|
||||
@@ -4,4 +4,28 @@
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// Better stack traces if possible.
|
||||
require('../better-stacks')
|
||||
|
||||
// Use Bluebird for all promises as it provides better performance and
|
||||
// less memory usage.
|
||||
global.Promise = require('bluebird')
|
||||
|
||||
// Make unhandled rejected promises visible.
|
||||
process.on('unhandledRejection', function (reason) {
|
||||
console.warn('[Warn] Possibly unhandled rejection:', reason && reason.stack || reason)
|
||||
})
|
||||
|
||||
;(function (EE) {
|
||||
var proto = EE.prototype
|
||||
var emit = proto.emit
|
||||
proto.emit = function patchedError (event, error) {
|
||||
if (event === 'error' && !this.listenerCount(event)) {
|
||||
return console.warn('[Warn] Unhandled error event:', error && error.stack || error)
|
||||
}
|
||||
|
||||
return emit.apply(this, arguments)
|
||||
}
|
||||
})(require('events').EventEmitter)
|
||||
|
||||
require('exec-promise')(require('../'))
|
||||
|
||||
10
bin/xo-server-logs
Executable file
10
bin/xo-server-logs
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// Better stack traces if possible.
|
||||
require('../better-stacks')
|
||||
|
||||
require('exec-promise')(require('../dist/logs-cli').default)
|
||||
40
config.json
Normal file
40
config.json
Normal file
@@ -0,0 +1,40 @@
|
||||
// Vendor config: DO NOT TOUCH!
|
||||
//
|
||||
// See sample.config.yaml to override.
|
||||
{
|
||||
"http": {
|
||||
"listen": [
|
||||
{
|
||||
"port": 80
|
||||
}
|
||||
],
|
||||
"mounts": {},
|
||||
|
||||
// Ciphers to use.
|
||||
//
|
||||
// These are the default ciphers in Node 4.2.6, we are setting
|
||||
// them explicitly for older Node versions.
|
||||
"ciphers": "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA",
|
||||
|
||||
// Tell Node to respect the cipher order.
|
||||
"honorCipherOrder": true,
|
||||
|
||||
// Specify to use at least TLSv1.1.
|
||||
// See: https://github.com/certsimple/minimum-tls-version
|
||||
"secureOptions": 117440512
|
||||
},
|
||||
"datadir": "/var/lib/xo-server/data",
|
||||
|
||||
// Should users be created on first sign in?
|
||||
//
|
||||
// Necessary for external authentication providers.
|
||||
"createUserOnFirstSignin": true,
|
||||
|
||||
// Whether API logs should contains the full request/response on
|
||||
// errors.
|
||||
//
|
||||
// This is disabled by default for performance (lots of data) and
|
||||
// security concerns (avoiding sensitive data in the logs) but can
|
||||
// be turned for investigation by the administrator.
|
||||
"verboseApiLogsOnErrors": false
|
||||
}
|
||||
23
gulpfile.js
23
gulpfile.js
@@ -7,25 +7,28 @@ var gulp = require('gulp')
|
||||
var babel = require('gulp-babel')
|
||||
var coffee = require('gulp-coffee')
|
||||
var plumber = require('gulp-plumber')
|
||||
var rimraf = require('rimraf')
|
||||
var sourceMaps = require('gulp-sourcemaps')
|
||||
var watch = require('gulp-watch')
|
||||
|
||||
var join = require('path').join
|
||||
|
||||
// ===================================================================
|
||||
|
||||
var SRC_DIR = __dirname + '/src'
|
||||
var DIST_DIR = __dirname + '/dist'
|
||||
var SRC_DIR = join(__dirname, 'src')
|
||||
var DIST_DIR = join(__dirname, 'dist')
|
||||
|
||||
var PRODUCTION = process.argv.indexOf('--production') !== -1
|
||||
|
||||
// ===================================================================
|
||||
|
||||
function src (patterns) {
|
||||
return PRODUCTION ?
|
||||
gulp.src(patterns, {
|
||||
return PRODUCTION
|
||||
? gulp.src(patterns, {
|
||||
base: SRC_DIR,
|
||||
cwd: SRC_DIR
|
||||
}) :
|
||||
watch(patterns, {
|
||||
})
|
||||
: watch(patterns, {
|
||||
base: SRC_DIR,
|
||||
cwd: SRC_DIR,
|
||||
ignoreInitial: false,
|
||||
@@ -36,6 +39,10 @@ function src (patterns) {
|
||||
|
||||
// ===================================================================
|
||||
|
||||
gulp.task(function clean (cb) {
|
||||
rimraf(DIST_DIR, cb)
|
||||
})
|
||||
|
||||
gulp.task(function buildCoffee () {
|
||||
return src('**/*.coffee')
|
||||
.pipe(sourceMaps.init())
|
||||
@@ -51,7 +58,7 @@ gulp.task(function buildCoffee () {
|
||||
})
|
||||
|
||||
gulp.task(function buildEs6 () {
|
||||
return src('**/*.js')
|
||||
return src([ '**/*.js', '!*.spec.js' ])
|
||||
.pipe(sourceMaps.init())
|
||||
.pipe(babel())
|
||||
.pipe(sourceMaps.write('.'))
|
||||
@@ -60,4 +67,4 @@ gulp.task(function buildEs6 () {
|
||||
|
||||
// ===================================================================
|
||||
|
||||
gulp.task('build', gulp.parallel('buildCoffee', 'buildEs6'))
|
||||
gulp.task('build', gulp.series('clean', gulp.parallel('buildCoffee', 'buildEs6')))
|
||||
|
||||
7
index.js
7
index.js
@@ -4,11 +4,8 @@
|
||||
|
||||
// Enable xo logs by default.
|
||||
if (process.env.DEBUG === undefined) {
|
||||
process.env.DEBUG = 'app-conf,xen-api,xo:*'
|
||||
process.env.DEBUG = 'app-conf,xo:*,-xo:api'
|
||||
}
|
||||
|
||||
// Enable source maps support for traces.
|
||||
require('source-map-support').install()
|
||||
|
||||
// Import the real main module.
|
||||
module.exports = require('./dist')
|
||||
module.exports = require('./dist').default
|
||||
|
||||
225
package.json
225
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xo-server",
|
||||
"version": "4.0.3-alpha.2",
|
||||
"version": "5.7.2",
|
||||
"license": "AGPL-3.0",
|
||||
"description": "Server part of Xen-Orchestra",
|
||||
"keywords": [
|
||||
@@ -11,103 +11,170 @@
|
||||
],
|
||||
"homepage": "http://github.com/vatesfr/xo-server/",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vatesfr/xo-server/issues"
|
||||
},
|
||||
"author": "Julien Fontanet <julien.fontanet@vates.fr>",
|
||||
"preferGlobal": true,
|
||||
"files": [
|
||||
"bin/",
|
||||
"dist/",
|
||||
"index.js"
|
||||
],
|
||||
"directories": {
|
||||
"bin": "bin"
|
||||
"url": "https://github.com/vatesfr/xo-web/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/vatesfr/xo-server.git"
|
||||
},
|
||||
"author": "Julien Fontanet <julien.fontanet@vates.fr>",
|
||||
"preferGlobal": true,
|
||||
"files": [
|
||||
"better-stacks.js",
|
||||
"bin/",
|
||||
"dist/",
|
||||
"config.json",
|
||||
"index.js",
|
||||
"signin.pug"
|
||||
],
|
||||
"directories": {
|
||||
"bin": "bin"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"app-conf": "^0.3.4",
|
||||
"babel-runtime": "^5",
|
||||
"base64url": "1.0.4",
|
||||
"blocked": "^1.1.0",
|
||||
"bluebird": "^2.9.14",
|
||||
"connect": "^3.3.5",
|
||||
"debug": "^2.1.3",
|
||||
"event-to-promise": "^0.3.2",
|
||||
"exec-promise": "^0.5.1",
|
||||
"fs-promise": "^0.3.1",
|
||||
"got": "^3.2.0",
|
||||
"graceful-fs": "^3.0.6",
|
||||
"hashy": "~0.4.2",
|
||||
"http-server-plus": "^0.5.1",
|
||||
"human-format": "^0.3.0",
|
||||
"js-yaml": "^3.2.7",
|
||||
"json-rpc-peer": "^0.9.2",
|
||||
"json-rpc-protocol": "^0.9.0",
|
||||
"@marsaud/smb2-promise": "^0.2.1",
|
||||
"@nraynaud/struct-fu": "^1.0.1",
|
||||
"app-conf": "^0.4.1",
|
||||
"archiver": "^1.3.0",
|
||||
"arp-a": "^0.5.1",
|
||||
"babel-runtime": "^6.23.0",
|
||||
"base64url": "^2.0.0",
|
||||
"bind-property-descriptor": "^0.0.0",
|
||||
"blocked": "^1.2.1",
|
||||
"bluebird": "^3.5.0",
|
||||
"body-parser": "^1.17.1",
|
||||
"connect-flash": "^0.1.1",
|
||||
"cookie": "^0.3.1",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"cron": "^1.2.1",
|
||||
"d3-time-format": "^2.0.5",
|
||||
"debug": "^2.6.3",
|
||||
"decorator-synchronized": "^0.2.3",
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
"event-to-promise": "^0.8.0",
|
||||
"exec-promise": "^0.6.1",
|
||||
"execa": "^0.6.3",
|
||||
"express": "^4.15.2",
|
||||
"express-session": "^1.15.1",
|
||||
"fatfs": "^0.10.4",
|
||||
"from2": "^2.3.0",
|
||||
"fs-extra": "^2.1.2",
|
||||
"fs-promise": "^2.0.1",
|
||||
"golike-defer": "^0.0.0",
|
||||
"hashy": "~0.6.1",
|
||||
"helmet": "^3.5.0",
|
||||
"highland": "^2.10.5",
|
||||
"http-proxy": "^1.16.2",
|
||||
"http-server-plus": "^0.8.0",
|
||||
"human-format": "^0.8.0",
|
||||
"is-my-json-valid": "^2.16.0",
|
||||
"is-redirect": "^1.0.0",
|
||||
"js-yaml": "^3.8.2",
|
||||
"json-rpc-peer": "^0.13.1",
|
||||
"json5": "^0.5.1",
|
||||
"julien-f-source-map-support": "0.0.0",
|
||||
"julien-f-unzip": "^0.2.1",
|
||||
"lodash.assign": "^3.0.0",
|
||||
"lodash.bind": "^3.0.0",
|
||||
"lodash.difference": "^3.2.0",
|
||||
"lodash.endswith": "^3.0.2",
|
||||
"lodash.filter": "^3.1.0",
|
||||
"lodash.find": "^3.0.0",
|
||||
"lodash.findindex": "^3.0.0",
|
||||
"lodash.foreach": "^3.0.1",
|
||||
"lodash.has": "^3.0.0",
|
||||
"lodash.includes": "^3.1.1",
|
||||
"lodash.isarray": "^3.0.0",
|
||||
"lodash.isempty": "^3.0.0",
|
||||
"lodash.isfunction": "^3.0.1",
|
||||
"lodash.isobject": "^3.0.0",
|
||||
"lodash.isstring": "^3.0.0",
|
||||
"lodash.keys": "^3.0.4",
|
||||
"lodash.map": "^3.0.0",
|
||||
"lodash.pick": "^3.0.0",
|
||||
"lodash.result": "^3.0.0",
|
||||
"lodash.startswith": "^3.0.1",
|
||||
"kindof": "^2.0.0",
|
||||
"level": "^1.6.0",
|
||||
"level-party": "^3.0.4",
|
||||
"level-sublevel": "^6.6.1",
|
||||
"leveldown": "^1.6.0",
|
||||
"lodash": "^4.17.4",
|
||||
"make-error": "^1",
|
||||
"multikey-hash": "^1.0.1",
|
||||
"proxy-http-request": "0.1.0",
|
||||
"redis": "^0.12.1",
|
||||
"request": "^2.53.0",
|
||||
"require-tree": "~1.0.1",
|
||||
"schema-inspector": "^1.5.1",
|
||||
"serve-static": "^1.9.2",
|
||||
"source-map-support": "^0.3.1",
|
||||
"then-redis": "~1.3.0",
|
||||
"ws": "~0.7.1",
|
||||
"xen-api": "^0.5.4",
|
||||
"xml2js": "~0.4.6",
|
||||
"xo-collection": "^0.3.2"
|
||||
"micromatch": "^2.3.11",
|
||||
"minimist": "^1.2.0",
|
||||
"moment-timezone": "^0.5.11",
|
||||
"ms": "^1.0.0",
|
||||
"multikey-hash": "^1.0.4",
|
||||
"ndjson": "^1.5.0",
|
||||
"parse-pairs": "^0.2.2",
|
||||
"partial-stream": "0.0.0",
|
||||
"passport": "^0.3.2",
|
||||
"passport-local": "^1.0.0",
|
||||
"pretty-format": "^19.0.0",
|
||||
"promise-toolbox": "^0.8.2",
|
||||
"proxy-agent": "^2.0.0",
|
||||
"pug": "^2.0.0-beta11",
|
||||
"redis": "^2.7.1",
|
||||
"schema-inspector": "^1.6.8",
|
||||
"semver": "^5.3.0",
|
||||
"serve-static": "^1.12.1",
|
||||
"split-lines": "^1.1.0",
|
||||
"stack-chain": "^1.3.7",
|
||||
"tar-stream": "^1.5.2",
|
||||
"through2": "^2.0.3",
|
||||
"tmp": "^0.0.31",
|
||||
"uuid": "^3.0.1",
|
||||
"ws": "^2.2.2",
|
||||
"xen-api": "^0.10.0-2",
|
||||
"xml2js": "~0.4.17",
|
||||
"xo-acl-resolver": "^0.2.3",
|
||||
"xo-collection": "^0.4.1",
|
||||
"xo-common": "^0.1.1",
|
||||
"xo-remote-parser": "^0.3",
|
||||
"xo-vmdk-to-vhd": "0.0.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^3.1.9",
|
||||
"chai": "~2.1.2",
|
||||
"babel-eslint": "^7.2.1",
|
||||
"babel-plugin-lodash": "^3.2.11",
|
||||
"babel-plugin-transform-decorators-legacy": "^1.3.4",
|
||||
"babel-plugin-transform-runtime": "^6.23.0",
|
||||
"babel-preset-env": "^1.2.2",
|
||||
"babel-preset-stage-0": "^6.22.0",
|
||||
"dependency-check": "^2.8.0",
|
||||
"gulp": "git://github.com/gulpjs/gulp#4.0",
|
||||
"gulp-babel": "^5",
|
||||
"gulp-coffee": "^2.3.1",
|
||||
"gulp-plumber": "^1.0.0",
|
||||
"gulp-sourcemaps": "^1.5.1",
|
||||
"gulp-watch": "^4.2.2",
|
||||
"in-publish": "^1.1.1",
|
||||
"mocha": "^2.2.1",
|
||||
"node-inspector": "^0.10.1",
|
||||
"sinon": "^1.14.1",
|
||||
"standard": "^4.0.0"
|
||||
"gulp-babel": "^6",
|
||||
"gulp-coffee": "^2.3.4",
|
||||
"gulp-plumber": "^1.1.0",
|
||||
"gulp-sourcemaps": "^2.4.1",
|
||||
"gulp-watch": "^4.3.11",
|
||||
"husky": "^0.13.2",
|
||||
"index-modules": "^0.3.0",
|
||||
"jest": "^19.0.2",
|
||||
"rimraf": "^2.6.1",
|
||||
"standard": "^9.0.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp build --production",
|
||||
"commitmsg": "npm test",
|
||||
"dev": "gulp build",
|
||||
"lint": "standard",
|
||||
"prepublish": "in-publish && npm run build || in-install",
|
||||
"dev-test": "jest --bail --watch",
|
||||
"posttest": "standard && dependency-check -i constant-stream ./package.json",
|
||||
"prebuild": "index-modules src/api src/xapi/mixins src/xo-mixins",
|
||||
"predev": "npm run prebuild",
|
||||
"prepublish": "npm run build",
|
||||
"start": "node bin/xo-server",
|
||||
"test": "mocha 'dist/**/*.spec.js'"
|
||||
"test": "jest"
|
||||
},
|
||||
"babel": {
|
||||
"plugins": [
|
||||
"lodash",
|
||||
"transform-decorators-legacy",
|
||||
"transform-runtime"
|
||||
],
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
{
|
||||
"targets": {
|
||||
"node": 4
|
||||
}
|
||||
}
|
||||
],
|
||||
"stage-0"
|
||||
]
|
||||
},
|
||||
"jest": {
|
||||
"roots": [
|
||||
"<rootDir>/src"
|
||||
],
|
||||
"testRegex": "\\.spec\\.js$"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"dist/**"
|
||||
"dist"
|
||||
],
|
||||
"parser": "babel-eslint"
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
# Example XO-Server configuration.
|
||||
# BE *VERY* CAREFUL WHEN EDITING!
|
||||
# YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
|
||||
# visit http://www.yamllint.com/ to validate this file as needed
|
||||
|
||||
#=====================================================================
|
||||
|
||||
# Example XO-Server configuration.
|
||||
#
|
||||
# This file is automatically looking for at the following places:
|
||||
# - `$HOME/.config/xo-server/config.yaml`
|
||||
# - `/etc/xo-server/config.yaml`
|
||||
#
|
||||
# The first entries have priority.
|
||||
|
||||
#
|
||||
# Note: paths are relative to the configuration file.
|
||||
|
||||
#=====================================================================
|
||||
@@ -43,16 +49,17 @@ http:
|
||||
|
||||
# Hosts & ports on which to listen.
|
||||
#
|
||||
# By default, the server listens on 0.0.0.0:80.
|
||||
# By default, the server listens on [::]:80.
|
||||
listen:
|
||||
# Basic HTTP.
|
||||
-
|
||||
# Address on which the server is listening on.
|
||||
#
|
||||
# Sets it to '127.0.0.1' to listen only on the local host.
|
||||
# Sets it to 'localhost' for IP to listen only on the local host.
|
||||
#
|
||||
# Default: '0.0.0.0' (all addresses)
|
||||
#hostname: '127.0.0.1'
|
||||
# Default: all IPv6 addresses if available, otherwise all IPv4
|
||||
# addresses.
|
||||
#hostname: 'localhost'
|
||||
|
||||
# Port on which the server is listening on.
|
||||
#
|
||||
@@ -66,17 +73,26 @@ http:
|
||||
#socket: './http.sock'
|
||||
|
||||
# Basic HTTPS.
|
||||
#
|
||||
# You can find the list of possible options there https://nodejs.org/docs/latest/api/tls.html#tls.createServer
|
||||
# -
|
||||
# # The only difference is the presence of the certificate and the
|
||||
# # key.
|
||||
|
||||
# #
|
||||
# #hostname: '127.0.0.1'
|
||||
# port: 443
|
||||
|
||||
# # File containing the certificate (PEM format).
|
||||
#
|
||||
# # If a chain of certificates authorities is needed, you may bundle
|
||||
# # them directly in the certificate.
|
||||
# #
|
||||
# # Note: the order of certificates does matter, your certificate
|
||||
# # should come first followed by the certificate of the above
|
||||
# # certificate authority up to the root.
|
||||
# #
|
||||
# # Default: undefined
|
||||
# certificate: './certificate.pem'
|
||||
# cert: './certificate.pem'
|
||||
|
||||
# # File containing the private key (PEM format).
|
||||
# #
|
||||
@@ -86,6 +102,10 @@ http:
|
||||
# # Default: undefined
|
||||
# key: './key.pem'
|
||||
|
||||
# If set to true, all HTTP traffic will be redirected to the first
|
||||
# HTTPs configuration.
|
||||
#redirectToHttps: true
|
||||
|
||||
# List of files/directories which will be served.
|
||||
mounts:
|
||||
#'/': '/path/to/xo-web/dist/'
|
||||
@@ -94,11 +114,36 @@ http:
|
||||
proxies:
|
||||
# '/any/url': 'http://localhost:54722'
|
||||
|
||||
# HTTP proxy configuration used by xo-server to fetch resources on the
|
||||
# Internet.
|
||||
#
|
||||
# See: https://github.com/TooTallNate/node-proxy-agent#maps-proxy-protocols-to-httpagent-implementations
|
||||
#httpProxy: 'http://jsmith:qwerty@proxy.lan:3128'
|
||||
|
||||
#=====================================================================
|
||||
|
||||
# Connection to the Redis server.
|
||||
redis:
|
||||
# Syntax: tcp://[db[:password]@]hostname[:port]
|
||||
# Unix sockets can be used
|
||||
#
|
||||
# Default: tcp://localhost:6379
|
||||
#uri: ''
|
||||
# Default: undefined
|
||||
#socket: /var/run/redis/redis.sock
|
||||
|
||||
# Syntax: redis://[db[:password]@]hostname[:port][/db-number]
|
||||
#
|
||||
# Default: redis://localhost:6379/0
|
||||
#uri: redis://redis.company.lan/42
|
||||
|
||||
# List of aliased commands.
|
||||
#
|
||||
# See http://redis.io/topics/security#disabling-of-specific-commands
|
||||
#renameCommands:
|
||||
# del: '3dda29ad-3015-44f9-b13b-fa570de92489'
|
||||
# srem: '3fd758c9-5610-4e9d-a058-dbf4cb6d8bf0'
|
||||
|
||||
|
||||
# Directory containing the database of XO.
|
||||
# Currently used for logs.
|
||||
#
|
||||
# Default: '/var/lib/xo-server/data'
|
||||
#datadir: '/var/lib/xo-server/data'
|
||||
|
||||
50
signin.pug
Normal file
50
signin.pug
Normal file
@@ -0,0 +1,50 @@
|
||||
doctype html
|
||||
html
|
||||
head
|
||||
meta(charset = 'utf-8')
|
||||
meta(http-equiv = 'X-UA-Compatible' content = 'IE=edge,chrome=1')
|
||||
meta(name = 'viewport' content = 'width=device-width, initial-scale=1.0')
|
||||
title Xen Orchestra
|
||||
meta(name = 'author' content = 'Vates SAS')
|
||||
link(rel = 'stylesheet' href = 'index.css')
|
||||
body(style = 'display: flex; height: 100vh;')
|
||||
div(style = 'margin: auto; width: 20em;')
|
||||
div.mb-2(style = 'display: flex;')
|
||||
img(src = 'assets/logo.png' style = 'margin: auto;')
|
||||
h2.text-xs-center.mb-2 Xen Orchestra
|
||||
form(action = 'signin/local' method = 'post')
|
||||
fieldset
|
||||
if error
|
||||
p.text-danger #{error}
|
||||
.input-group.mb-1
|
||||
span.input-group-addon
|
||||
i.xo-icon-user.fa-fw
|
||||
input.form-control(
|
||||
name = 'username'
|
||||
type = 'text'
|
||||
placeholder = 'Username'
|
||||
required
|
||||
)
|
||||
.input-group.mb-1
|
||||
span.input-group-addon
|
||||
i.fa.fa-key.fa-fw
|
||||
input.form-control(
|
||||
name = 'password'
|
||||
type = 'password'
|
||||
placeholder = 'Password'
|
||||
required
|
||||
)
|
||||
.checkbox
|
||||
label
|
||||
input(
|
||||
name = 'remember-me'
|
||||
type = 'checkbox'
|
||||
)
|
||||
|
|
||||
| Remember me
|
||||
div
|
||||
button.btn.btn-block.btn-info
|
||||
i.fa.fa-sign-in
|
||||
| Sign in
|
||||
each label, id in strategies
|
||||
div: a(href = 'signin/' + id) Sign in with #{label}
|
||||
@@ -1,51 +0,0 @@
|
||||
import {JsonRpcError} from 'json-rpc-protocol'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// Export standard JSON-RPC errors.
|
||||
export {
|
||||
InvalidJson,
|
||||
InvalidParameters,
|
||||
InvalidRequest,
|
||||
MethodNotFound
|
||||
} from 'json-rpc-protocol'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export class NotImplemented extends JsonRpcError {
|
||||
constructor () {
|
||||
super('not implemented', 0)
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export class NoSuchObject extends JsonRpcError {
|
||||
constructor (id, type) {
|
||||
super('no such object', 1, {id, type})
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export class Unauthorized extends JsonRpcError {
|
||||
constructor () {
|
||||
super('not authenticated or not enough permissions', 2)
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export class InvalidCredential extends JsonRpcError {
|
||||
constructor () {
|
||||
super('invalid credential', 3)
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export class AlreadyAuthenticated extends JsonRpcError {
|
||||
constructor () {
|
||||
super('already authenticated', 4)
|
||||
}
|
||||
}
|
||||
318
src/api.js
318
src/api.js
@@ -1,318 +0,0 @@
|
||||
import createDebug from 'debug'
|
||||
const debug = createDebug('xo:api')
|
||||
|
||||
import assign from 'lodash.assign'
|
||||
import Bluebird from 'bluebird'
|
||||
import forEach from 'lodash.foreach'
|
||||
import getKeys from 'lodash.keys'
|
||||
import isFunction from 'lodash.isfunction'
|
||||
import map from 'lodash.map'
|
||||
import requireTree from 'require-tree'
|
||||
import schemaInspector from 'schema-inspector'
|
||||
|
||||
import {
|
||||
InvalidParameters,
|
||||
MethodNotFound,
|
||||
NoSuchObject,
|
||||
Unauthorized
|
||||
} from './api-errors'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// FIXME: this function is specific to XO and should not be defined in
|
||||
// this file.
|
||||
function checkPermission (method) {
|
||||
/* jshint validthis: true */
|
||||
|
||||
const {permission} = method
|
||||
|
||||
// No requirement.
|
||||
if (permission === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
const {user} = this
|
||||
if (!user) {
|
||||
throw new Unauthorized()
|
||||
}
|
||||
|
||||
// The only requirement is login.
|
||||
if (!permission) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!user.hasPermission(permission)) {
|
||||
throw new Unauthorized()
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function checkParams (method, params) {
|
||||
const schema = method.params
|
||||
if (!schema) {
|
||||
return
|
||||
}
|
||||
|
||||
const result = schemaInspector.validate({
|
||||
type: 'object',
|
||||
properties: schema
|
||||
}, params)
|
||||
|
||||
if (!result.valid) {
|
||||
throw new InvalidParameters(result.error)
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// Forward declaration.
|
||||
let checkAuthorization
|
||||
|
||||
function authorized () {}
|
||||
// function forbiddden () {
|
||||
// // We don't care about an error object.
|
||||
// /* eslint no-throw-literal: 0 */
|
||||
// throw null
|
||||
// }
|
||||
function checkMemberAuthorization (member) {
|
||||
return function (userId, object, permission) {
|
||||
const memberObject = this.getObject(object[member])
|
||||
return checkAuthorization.call(this, userId, memberObject, permission)
|
||||
}
|
||||
}
|
||||
|
||||
const checkAuthorizationByTypes = {
|
||||
// Objects of these types do not requires any authorization.
|
||||
'network': authorized,
|
||||
'VM-template': authorized,
|
||||
|
||||
message: checkMemberAuthorization('$object'),
|
||||
|
||||
task: checkMemberAuthorization('$host'),
|
||||
|
||||
VBD: checkMemberAuthorization('VDI'),
|
||||
|
||||
// Access to a VDI is granted if the user has access to the
|
||||
// containing SR or to a linked VM.
|
||||
VDI (userId, vdi, permission) {
|
||||
// Check authorization for each of the connected VMs.
|
||||
const promises = map(this.getObjects(vdi.$VBDs, 'VBD'), vbd => {
|
||||
const vm = this.getObject(vbd.VM, 'VM')
|
||||
return checkAuthorization.call(this, userId, vm, permission)
|
||||
})
|
||||
|
||||
// Check authorization for the containing SR.
|
||||
const sr = this.getObject(vdi.$SR, 'SR')
|
||||
promises.push(checkAuthorization.call(this, userId, sr, permission))
|
||||
|
||||
// We need at least one success
|
||||
return Bluebird.any(promises)
|
||||
},
|
||||
|
||||
VIF (userId, vif, permission) {
|
||||
const network = this.getObject(vif.$network)
|
||||
const vm = this.getObject(vif.$VM)
|
||||
|
||||
return Bluebird.any([
|
||||
checkAuthorization.call(this, userId, network, permission),
|
||||
checkAuthorization.call(this, userId, vm, permission)
|
||||
])
|
||||
},
|
||||
|
||||
'VM-snapshot': checkMemberAuthorization('$snapshot_of')
|
||||
}
|
||||
|
||||
function throwIfFail (success) {
|
||||
if (!success) {
|
||||
// We don't care about an error object.
|
||||
/* eslint no-throw-literal: 0 */
|
||||
throw null
|
||||
}
|
||||
}
|
||||
|
||||
function defaultCheckAuthorization (userId, object, permission) {
|
||||
return this.hasPermission(userId, object.id, permission).then(throwIfFail)
|
||||
}
|
||||
|
||||
checkAuthorization = Bluebird.method(function (userId, object, permission) {
|
||||
const fn = checkAuthorizationByTypes[object.type] || defaultCheckAuthorization
|
||||
return fn.call(this, userId, object, permission)
|
||||
})
|
||||
|
||||
function resolveParams (method, params) {
|
||||
const resolve = method.resolve
|
||||
if (!resolve) {
|
||||
return params
|
||||
}
|
||||
|
||||
const {user} = this
|
||||
if (!user) {
|
||||
throw new Unauthorized()
|
||||
}
|
||||
|
||||
const userId = user.get('id')
|
||||
const isAdmin = this.user.hasPermission('admin')
|
||||
|
||||
const promises = []
|
||||
forEach(resolve, ([param, types, permission = 'administrate'], key) => {
|
||||
const id = params[param]
|
||||
if (id === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
const object = this.getObject(params[param], types)
|
||||
|
||||
// This parameter has been handled, remove it.
|
||||
delete params[param]
|
||||
|
||||
// Register this new value.
|
||||
params[key] = object
|
||||
|
||||
if (!isAdmin) {
|
||||
promises.push(checkAuthorization.call(this, userId, object, permission))
|
||||
}
|
||||
})
|
||||
|
||||
return Bluebird.all(promises).catch(() => {
|
||||
throw new Unauthorized()
|
||||
}).return(params)
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
function getMethodsInfo () {
|
||||
const methods = {}
|
||||
|
||||
forEach(this.api._methods, function (method, name) {
|
||||
this[name] = assign({}, {
|
||||
description: method.description,
|
||||
params: method.params || {},
|
||||
permission: method.permission
|
||||
})
|
||||
}, methods)
|
||||
|
||||
return methods
|
||||
}
|
||||
getMethodsInfo.description = 'returns the signatures of all available API methods'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
const getVersion = () => '0.1'
|
||||
getVersion.description = 'API version (unstable)'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function listMethods () {
|
||||
return getKeys(this.api._methods)
|
||||
}
|
||||
listMethods.description = 'returns the name of all available API methods'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function methodSignature ({method: name}) {
|
||||
const method = this.api.getMethod(name)
|
||||
|
||||
if (!method) {
|
||||
throw new NoSuchObject()
|
||||
}
|
||||
|
||||
// Return an array for compatibility with XML-RPC.
|
||||
return [
|
||||
// XML-RPC require the name of the method.
|
||||
assign({ name }, {
|
||||
description: method.description,
|
||||
params: method.params || {},
|
||||
permission: method.permission
|
||||
})
|
||||
]
|
||||
}
|
||||
methodSignature.description = 'returns the signature of an API method'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class Api {
|
||||
constructor ({context} = {}) {
|
||||
this._methods = Object.create(null)
|
||||
this.context = context
|
||||
|
||||
this.addMethods({
|
||||
system: {
|
||||
getMethodsInfo,
|
||||
getVersion,
|
||||
listMethods,
|
||||
methodSignature
|
||||
}
|
||||
})
|
||||
|
||||
// FIXME: this too is specific to XO and should be moved out of this file.
|
||||
this.addMethods(requireTree('./api'))
|
||||
}
|
||||
|
||||
addMethod (name, method) {
|
||||
this._methods[name] = method
|
||||
}
|
||||
|
||||
addMethods (methods) {
|
||||
let base = ''
|
||||
forEach(methods, function addMethod (method, name) {
|
||||
name = base + name
|
||||
|
||||
if (isFunction(method)) {
|
||||
this.addMethod(name, method)
|
||||
return
|
||||
}
|
||||
|
||||
const oldBase = base
|
||||
base = name + '.'
|
||||
forEach(method, addMethod, this)
|
||||
base = oldBase
|
||||
}, this)
|
||||
}
|
||||
|
||||
async call (session, name, params) {
|
||||
debug('%s(...)', name)
|
||||
|
||||
const method = this.getMethod(name)
|
||||
if (!method) {
|
||||
throw new MethodNotFound(name)
|
||||
}
|
||||
|
||||
const context = Object.create(this.context)
|
||||
context.api = this // Used by system.*().
|
||||
context.session = session
|
||||
|
||||
// FIXME: too coupled with XO.
|
||||
// Fetch and inject the current user.
|
||||
const userId = session.get('user_id', undefined)
|
||||
if (userId) {
|
||||
context.user = await context._getUser(userId)
|
||||
}
|
||||
|
||||
await checkPermission.call(context, method)
|
||||
checkParams(method, params)
|
||||
|
||||
await resolveParams.call(context, method, params)
|
||||
try {
|
||||
let result = await method.call(context, params)
|
||||
|
||||
// If nothing was returned, consider this operation a success
|
||||
// and return true.
|
||||
if (result === undefined) {
|
||||
result = true
|
||||
}
|
||||
|
||||
debug('%s(...) → %s', name, typeof result)
|
||||
|
||||
return result
|
||||
} catch (error) {
|
||||
debug('Error: %s(...) → %s', name, error)
|
||||
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
getMethod (name) {
|
||||
return this._methods[name]
|
||||
}
|
||||
}
|
||||
0
src/api/.index-modules
Normal file
0
src/api/.index-modules
Normal file
@@ -1,5 +1,5 @@
|
||||
export async function get () {
|
||||
return await this.getAllAcls()
|
||||
return /* await */ this.getAllAcls()
|
||||
}
|
||||
|
||||
get.permission = 'admin'
|
||||
@@ -8,13 +8,13 @@ get.description = 'get existing ACLs'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function getCurrent () {
|
||||
return await this.getAclsForUser(this.session.get('user_id'))
|
||||
export async function getCurrentPermissions () {
|
||||
return /* await */ this.getPermissionsForUser(this.session.get('user_id'))
|
||||
}
|
||||
|
||||
getCurrent.permission = ''
|
||||
getCurrentPermissions.permission = ''
|
||||
|
||||
getCurrent.description = 'get existing ACLs concerning current user'
|
||||
getCurrentPermissions.description = 'get (explicit) permissions by object for the current user'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
|
||||
98
src/api/backup.js
Normal file
98
src/api/backup.js
Normal file
@@ -0,0 +1,98 @@
|
||||
import archiver from 'archiver'
|
||||
import { basename } from 'path'
|
||||
import { format } from 'json-rpc-peer'
|
||||
import { forEach } from 'lodash'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export function list ({ remote }) {
|
||||
return this.listVmBackups(remote)
|
||||
}
|
||||
|
||||
list.permission = 'admin'
|
||||
list.params = {
|
||||
remote: { type: 'string' }
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function scanDisk ({ remote, disk }) {
|
||||
return this.scanDiskBackup(remote, disk)
|
||||
}
|
||||
|
||||
scanDisk.permission = 'admin'
|
||||
scanDisk.params = {
|
||||
remote: { type: 'string' },
|
||||
disk: { type: 'string' }
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function scanFiles ({ remote, disk, partition, path }) {
|
||||
return this.scanFilesInDiskBackup(remote, disk, partition, path)
|
||||
}
|
||||
|
||||
scanFiles.permission = 'admin'
|
||||
scanFiles.params = {
|
||||
remote: { type: 'string' },
|
||||
disk: { type: 'string' },
|
||||
partition: { type: 'string', optional: true },
|
||||
path: { type: 'string' }
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function handleFetchFiles (req, res, { remote, disk, partition, paths, format: archiveFormat }) {
|
||||
this.fetchFilesInDiskBackup(remote, disk, partition, paths).then(files => {
|
||||
res.setHeader('content-disposition', 'attachment')
|
||||
res.setHeader('content-type', 'application/octet-stream')
|
||||
|
||||
const nFiles = paths.length
|
||||
|
||||
// Send lone file directly
|
||||
if (nFiles === 1) {
|
||||
files[0].pipe(res)
|
||||
return
|
||||
}
|
||||
|
||||
const archive = archiver(archiveFormat)
|
||||
archive.on('error', error => {
|
||||
console.error(error)
|
||||
res.end(format.error(0, error))
|
||||
})
|
||||
|
||||
forEach(files, file => {
|
||||
archive.append(file, { name: basename(file.path) })
|
||||
})
|
||||
archive.finalize()
|
||||
|
||||
archive.pipe(res)
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
res.writeHead(500)
|
||||
res.end(format.error(0, error))
|
||||
})
|
||||
}
|
||||
|
||||
export async function fetchFiles ({ format = 'zip', ...params }) {
|
||||
const fileName = params.paths.length > 1
|
||||
? `restore_${new Date().toJSON()}.${format}`
|
||||
: basename(params.paths[0])
|
||||
|
||||
return this.registerHttpRequest(handleFetchFiles, { ...params, format }, {
|
||||
suffix: encodeURI(`/${fileName}`)
|
||||
}).then(url => ({ $getFrom: url }))
|
||||
}
|
||||
|
||||
fetchFiles.permission = 'admin'
|
||||
fetchFiles.params = {
|
||||
remote: { type: 'string' },
|
||||
disk: { type: 'string' },
|
||||
format: { type: 'string', optional: true },
|
||||
partition: { type: 'string', optional: true },
|
||||
paths: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
minLength: 1
|
||||
}
|
||||
}
|
||||
@@ -3,29 +3,38 @@ import {parseSize} from '../utils'
|
||||
// ===================================================================
|
||||
|
||||
export async function create ({name, size, sr}) {
|
||||
const xapi = this.getXAPI(sr)
|
||||
|
||||
const ref = await xapi.call('VDI.create', {
|
||||
const vdi = await this.getXapi(sr).createVdi(parseSize(size), {
|
||||
name_label: name,
|
||||
other_config: {},
|
||||
read_only: false,
|
||||
sharable: false,
|
||||
SR: sr.ref,
|
||||
type: 'user',
|
||||
virtual_size: String(parseSize(size))
|
||||
sr: sr._xapiId
|
||||
})
|
||||
|
||||
return (await xapi.call('VDI.get_record', ref)).uuid
|
||||
return vdi.$id
|
||||
}
|
||||
|
||||
create.description = 'create a new disk on a SR'
|
||||
|
||||
create.params = {
|
||||
name: { type: 'string' },
|
||||
size: { type: 'string' },
|
||||
size: { type: ['integer', 'string'] },
|
||||
sr: { type: 'string' }
|
||||
}
|
||||
|
||||
create.resolve = {
|
||||
sr: ['sr', 'SR', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function resize ({ vdi, size }) {
|
||||
await this.getXapi(vdi).resizeVdi(vdi._xapiId, parseSize(size))
|
||||
}
|
||||
|
||||
resize.description = 'resize an existing VDI'
|
||||
|
||||
resize.params = {
|
||||
id: { type: 'string' },
|
||||
size: { type: ['integer', 'string'] }
|
||||
}
|
||||
|
||||
resize.resolve = {
|
||||
vdi: ['id', ['VDI', 'VDI-snapshot'], 'administrate']
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
export async function register ({vm}) {
|
||||
await this.getXAPI(vm).registerDockerContainer(vm.id)
|
||||
await this.getXapi(vm).registerDockerContainer(vm._xapiId)
|
||||
}
|
||||
register.permission = 'admin'
|
||||
|
||||
register.description = 'Register the VM for Docker management'
|
||||
|
||||
register.params = {
|
||||
@@ -16,10 +14,8 @@ register.resolve = {
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
export async function deregister ({vm}) {
|
||||
await this.getXAPI(vm).unregisterDockerContainer(vm.id)
|
||||
await this.getXapi(vm).unregisterDockerContainer(vm._xapiId)
|
||||
}
|
||||
deregister.permission = 'admin'
|
||||
|
||||
deregister.description = 'Deregister the VM for Docker management'
|
||||
|
||||
deregister.params = {
|
||||
@@ -33,28 +29,26 @@ deregister.resolve = {
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
export async function start ({vm, container}) {
|
||||
await this.getXAPI(vm).startDockerContainer(vm.id, container)
|
||||
await this.getXapi(vm).startDockerContainer(vm._xapiId, container)
|
||||
}
|
||||
|
||||
export async function stop ({vm, container}) {
|
||||
await this.getXAPI(vm).stopDockerContainer(vm.id, container)
|
||||
await this.getXapi(vm).stopDockerContainer(vm._xapiId, container)
|
||||
}
|
||||
|
||||
export async function restart ({vm, container}) {
|
||||
await this.getXAPI(vm).restartDockerContainer(vm.id, container)
|
||||
await this.getXapi(vm).restartDockerContainer(vm._xapiId, container)
|
||||
}
|
||||
|
||||
export async function pause ({vm, container}) {
|
||||
await this.getXAPI(vm).pauseDockerContainer(vm.id, container)
|
||||
await this.getXapi(vm).pauseDockerContainer(vm._xapiId, container)
|
||||
}
|
||||
|
||||
export async function unpause ({vm, container}) {
|
||||
await this.getXAPI(vm).unpauseDockerContainer(vm.id, container)
|
||||
await this.getXapi(vm).unpauseDockerContainer(vm._xapiId, container)
|
||||
}
|
||||
|
||||
for (let fn of [start, stop, restart, pause, unpause]) {
|
||||
fn.permission = 'admin'
|
||||
|
||||
fn.params = {
|
||||
vm: { type: 'string' },
|
||||
container: { type: 'string' }
|
||||
|
||||
@@ -27,14 +27,11 @@ delete_.params = {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function getAll () {
|
||||
return await this._groups.get()
|
||||
return /* await */ this.getAllGroups()
|
||||
}
|
||||
|
||||
delete_.description = 'returns all the existing group'
|
||||
delete_.permission = 'admin'
|
||||
delete_.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
getAll.description = 'returns all the existing group'
|
||||
getAll.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,29 +1,32 @@
|
||||
$debug = (require 'debug') 'xo:api:vm'
|
||||
$find = require 'lodash.find'
|
||||
$findIndex = require 'lodash.findindex'
|
||||
$forEach = require 'lodash.foreach'
|
||||
$request = require('bluebird').promisify(require('request'))
|
||||
endsWith = require 'lodash.endswith'
|
||||
startsWith = require 'lodash.startswith'
|
||||
$find = require 'lodash/find'
|
||||
$findIndex = require 'lodash/findIndex'
|
||||
$forEach = require 'lodash/forEach'
|
||||
endsWith = require 'lodash/endsWith'
|
||||
startsWith = require 'lodash/startsWith'
|
||||
{coroutine: $coroutine} = require 'bluebird'
|
||||
{parseXml} = require '../utils'
|
||||
{format} = require 'json-rpc-peer'
|
||||
{
|
||||
extractProperty,
|
||||
mapToArray,
|
||||
parseXml
|
||||
} = require '../utils'
|
||||
|
||||
#=====================================================================
|
||||
|
||||
set = $coroutine (params) ->
|
||||
{host} = params
|
||||
xapi = @getXAPI host
|
||||
set = ({
|
||||
host,
|
||||
|
||||
for param, field of {
|
||||
'name_label'
|
||||
'name_description'
|
||||
'enabled'
|
||||
}
|
||||
continue unless param of params
|
||||
# TODO: use camel case.
|
||||
name_label: nameLabel,
|
||||
name_description: nameDescription
|
||||
}) ->
|
||||
return @getXapi(host).setHostProperties(host._xapiId, {
|
||||
nameLabel,
|
||||
nameDescription
|
||||
})
|
||||
|
||||
yield xapi.call "host.set_#{field}", host.ref, params[param]
|
||||
|
||||
return true
|
||||
set.description = 'changes the properties of an host'
|
||||
|
||||
set.params =
|
||||
id: type: 'string'
|
||||
@@ -33,9 +36,6 @@ set.params =
|
||||
name_description:
|
||||
type: 'string'
|
||||
optional: true
|
||||
enabled:
|
||||
type: 'boolean'
|
||||
optional: true
|
||||
|
||||
set.resolve = {
|
||||
host: ['id', 'host', 'administrate'],
|
||||
@@ -45,16 +45,19 @@ exports.set = set
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
restart = $coroutine ({host}) ->
|
||||
xapi = @getXAPI host
|
||||
# FIXME: set force to false per default when correctly implemented in
|
||||
# UI.
|
||||
restart = ({host, force = true}) ->
|
||||
return @getXapi(host).rebootHost(host._xapiId, force)
|
||||
|
||||
yield xapi.call 'host.disable', host.ref
|
||||
yield xapi.call 'host.reboot', host.ref
|
||||
|
||||
return true
|
||||
restart.description = 'restart the host'
|
||||
|
||||
restart.params = {
|
||||
id: { type: 'string' }
|
||||
id: { type: 'string' },
|
||||
force: {
|
||||
type: 'boolean',
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
|
||||
restart.resolve = {
|
||||
@@ -65,19 +68,17 @@ exports.restart = restart
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
restartAgent = $coroutine ({host}) ->
|
||||
xapi = @getXAPI host
|
||||
restartAgent = ({host}) ->
|
||||
return @getXapi(host).restartHostAgent(host._xapiId)
|
||||
|
||||
yield xapi.call 'host.restart_agent', host.ref
|
||||
|
||||
return true
|
||||
restartAgent.description = 'restart the Xen agent on the host'
|
||||
|
||||
restartAgent.params = {
|
||||
id: { type: 'string' }
|
||||
}
|
||||
|
||||
restartAgent.resolve = {
|
||||
host: ['id', 'host', 'operate'],
|
||||
host: ['id', 'host', 'administrate'],
|
||||
}
|
||||
|
||||
# TODO camel case
|
||||
@@ -85,12 +86,10 @@ exports.restart_agent = restartAgent
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
start = $coroutine ({host}) ->
|
||||
xapi = @getXAPI host
|
||||
start = ({host}) ->
|
||||
return @getXapi(host).powerOnHost(host._xapiId)
|
||||
|
||||
yield xapi.call 'host.power_on', host.ref
|
||||
|
||||
return true
|
||||
start.description = 'start the host'
|
||||
|
||||
start.params = {
|
||||
id: { type: 'string' }
|
||||
@@ -104,13 +103,10 @@ exports.start = start
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
stop = $coroutine ({host}) ->
|
||||
xapi = @getXAPI host
|
||||
stop = ({host}) ->
|
||||
return @getXapi(host).shutdownHost(host._xapiId)
|
||||
|
||||
yield xapi.call 'host.disable', host.ref
|
||||
yield xapi.call 'host.shutdown', host.ref
|
||||
|
||||
return true
|
||||
stop.description = 'stop the host'
|
||||
|
||||
stop.params = {
|
||||
id: { type: 'string' }
|
||||
@@ -124,12 +120,10 @@ exports.stop = stop
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
detach = $coroutine ({host}) ->
|
||||
xapi = @getXAPI host
|
||||
detach = ({host}) ->
|
||||
return @getXapi(host).ejectHostFromPool(host._xapiId)
|
||||
|
||||
yield xapi.call 'pool.eject', host.ref
|
||||
|
||||
return true
|
||||
detach.description = 'eject the host of a pool'
|
||||
|
||||
detach.params = {
|
||||
id: { type: 'string' }
|
||||
@@ -143,12 +137,10 @@ exports.detach = detach
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
enable = $coroutine ({host}) ->
|
||||
xapi = @getXAPI host
|
||||
enable = ({host}) ->
|
||||
return @getXapi(host).enableHost(host._xapiId)
|
||||
|
||||
yield xapi.call 'host.enable', host.ref
|
||||
|
||||
return true
|
||||
enable.description = 'enable to create VM on the host'
|
||||
|
||||
enable.params = {
|
||||
id: { type: 'string' }
|
||||
@@ -162,12 +154,10 @@ exports.enable = enable
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
disable = $coroutine ({host}) ->
|
||||
xapi = @getXAPI host
|
||||
disable = ({host}) ->
|
||||
return @getXapi(host).disableHost(host._xapiId)
|
||||
|
||||
yield xapi.call 'host.disable', host.ref
|
||||
|
||||
return true
|
||||
disable.description = 'disable to create VM on the hsot'
|
||||
|
||||
disable.params = {
|
||||
id: { type: 'string' }
|
||||
@@ -179,49 +169,13 @@ disable.resolve = {
|
||||
|
||||
exports.disable = disable
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
createNetwork = $coroutine ({host, name, description, pif, mtu, vlan}) ->
|
||||
xapi = @getXAPI host
|
||||
|
||||
description = description ? 'Created with Xen Orchestra'
|
||||
|
||||
network_ref = yield xapi.call 'network.create', {
|
||||
name_label: name,
|
||||
name_description: description,
|
||||
MTU: mtu ? '1500'
|
||||
other_config: {}
|
||||
}
|
||||
|
||||
if pif?
|
||||
vlan = vlan ? '0'
|
||||
pif = @getObject pif, 'PIF'
|
||||
yield xapi.call 'pool.create_VLAN_from_PIF', pif.ref, network_ref, vlan
|
||||
|
||||
return true
|
||||
|
||||
createNetwork.params = {
|
||||
host: { type: 'string' }
|
||||
name: { type: 'string' }
|
||||
description: { type: 'string', optional: true }
|
||||
pif: { type: 'string', optional: true }
|
||||
mtu: { type: 'string', optional: true }
|
||||
vlan: { type: 'string', optional: true }
|
||||
}
|
||||
|
||||
createNetwork.resolve = {
|
||||
host: ['host', 'host', 'administrate'],
|
||||
}
|
||||
createNetwork.permission = 'admin'
|
||||
exports.createNetwork = createNetwork
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Returns an array of missing new patches in the host
|
||||
# Returns an empty array if up-to-date
|
||||
# Throws an error if the host is not running the latest XS version
|
||||
|
||||
listMissingPatches = ({host}) ->
|
||||
return @getXAPI(host).listMissingPoolPatchesOnHost(host.id)
|
||||
return @getXapi(host).listMissingPoolPatchesOnHost(host._xapiId)
|
||||
|
||||
listMissingPatches.params = {
|
||||
host: { type: 'string' }
|
||||
@@ -233,10 +187,14 @@ listMissingPatches.resolve = {
|
||||
|
||||
exports.listMissingPatches = listMissingPatches
|
||||
|
||||
listMissingPatches.description = 'return an array of missing new patches in the host'
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
installPatch = ({host, patch: patchUuid}) ->
|
||||
return @getXAPI(host).installPoolPatchOnHost(patchUuid, host.id)
|
||||
return @getXapi(host).installPoolPatchOnHost(patchUuid, host._xapiId)
|
||||
|
||||
installPatch.description = 'install a patch on an host'
|
||||
|
||||
installPatch.params = {
|
||||
host: { type: 'string' }
|
||||
@@ -251,89 +209,51 @@ exports.installPatch = installPatch
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
installAllPatches = ({host}) ->
|
||||
return @getXapi(host).installAllPoolPatchesOnHost(host._xapiId)
|
||||
|
||||
stats = $coroutine ({host}) ->
|
||||
installAllPatches.description = 'install all the missing patches on a host'
|
||||
|
||||
xapi = @getXAPI host
|
||||
installAllPatches.params = {
|
||||
host: { type: 'string' }
|
||||
}
|
||||
|
||||
[response, body] = yield $request {
|
||||
method: 'get'
|
||||
rejectUnauthorized: false
|
||||
url: 'https://'+host.address+'/host_rrd?session_id='+xapi.sessionId
|
||||
}
|
||||
installAllPatches.resolve = {
|
||||
host: ['host', 'host', 'administrate']
|
||||
}
|
||||
|
||||
if response.statusCode isnt 200
|
||||
throw new Error('Cannot fetch the RRDs')
|
||||
exports.installAllPatches = installAllPatches
|
||||
|
||||
json = parseXml(body)
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
# Find index of needed objects for getting their values after
|
||||
cpusIndexes = []
|
||||
pifsIndexes = []
|
||||
memoryFreeIndex = []
|
||||
memoryIndex = []
|
||||
loadIndex = []
|
||||
index = 0
|
||||
emergencyShutdownHost = ({host}) ->
|
||||
return @getXapi(host).emergencyShutdownHost(host._xapiId)
|
||||
|
||||
$forEach(json.rrd.ds, (value, i) ->
|
||||
if /^cpu[0-9]+$/.test(value.name)
|
||||
cpusIndexes.push(i)
|
||||
else if startsWith(value.name, 'pif_eth') && endsWith(value.name, '_tx')
|
||||
pifsIndexes.push(i)
|
||||
else if startsWith(value.name, 'pif_eth') && endsWith(value.name, '_rx')
|
||||
pifsIndexes.push(i)
|
||||
else if startsWith(value.name, 'loadavg')
|
||||
loadIndex.push(i)
|
||||
else if startsWith(value.name, 'memory_free_kib')
|
||||
memoryFreeIndex.push(i)
|
||||
else if startsWith(value.name, 'memory_total_kib')
|
||||
memoryIndex.push(i)
|
||||
emergencyShutdownHost.description = 'suspend all VMs and shutdown host'
|
||||
|
||||
return
|
||||
)
|
||||
emergencyShutdownHost.params = {
|
||||
host: { type: 'string' }
|
||||
}
|
||||
|
||||
memoryFree = []
|
||||
memoryUsed = []
|
||||
memory = []
|
||||
load = []
|
||||
cpus = []
|
||||
pifs = []
|
||||
date = [] #TODO
|
||||
baseDate = json.rrd.lastupdate
|
||||
dateStep = json.rrd.step
|
||||
numStep = json.rrd.rra[0].database.row.length - 1
|
||||
emergencyShutdownHost.resolve = {
|
||||
host: ['host', 'host', 'administrate']
|
||||
}
|
||||
|
||||
$forEach json.rrd.rra[0].database.row, (n, key) ->
|
||||
memoryFree.push(Math.round(parseInt(n.v[memoryFreeIndex])))
|
||||
memoryUsed.push(Math.round(parseInt(n.v[memoryIndex])-(n.v[memoryFreeIndex])))
|
||||
memory.push(parseInt(n.v[memoryIndex]))
|
||||
load.push(n.v[loadIndex])
|
||||
date.push(baseDate - (dateStep * (numStep - key)))
|
||||
# build the multi dimensional arrays
|
||||
$forEach cpusIndexes, (value, key) ->
|
||||
cpus[key] ?= []
|
||||
cpus[key].push(n.v[value]*100)
|
||||
return
|
||||
$forEach pifsIndexes, (value, key) ->
|
||||
pifs[key] ?= []
|
||||
pifs[key].push(if n.v[value] == 'NaN' then null else n.v[value]) # * (if key % 2 then -1 else 1))
|
||||
return
|
||||
return
|
||||
exports.emergencyShutdownHost = emergencyShutdownHost
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
# the final object
|
||||
return {
|
||||
memoryFree: memoryFree
|
||||
memoryUsed: memoryUsed
|
||||
memory: memory
|
||||
date: date
|
||||
cpus: cpus
|
||||
pifs: pifs
|
||||
load: load
|
||||
}
|
||||
stats = ({host, granularity}) ->
|
||||
return @getXapiHostStats(host, granularity)
|
||||
|
||||
stats.description = 'returns statistic of the host'
|
||||
|
||||
stats.params = {
|
||||
host: { type: 'string' }
|
||||
host: { type: 'string' },
|
||||
granularity: {
|
||||
type: 'string',
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
|
||||
stats.resolve = {
|
||||
@@ -341,3 +261,45 @@ stats.resolve = {
|
||||
}
|
||||
|
||||
exports.stats = stats;
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
handleInstallSupplementalPack = $coroutine (req, res, { hostId }) ->
|
||||
xapi = @getXapi(hostId)
|
||||
|
||||
# Timeout seems to be broken in Node 4.
|
||||
# See https://github.com/nodejs/node/issues/3319
|
||||
req.setTimeout(43200000) # 12 hours
|
||||
req.length = req.headers['content-length']
|
||||
|
||||
try
|
||||
yield xapi.installSupplementalPack(req, { hostId })
|
||||
res.end(format.response(0))
|
||||
catch e
|
||||
res.writeHead(500)
|
||||
res.end(format.error(0, new Error(e.message)))
|
||||
|
||||
return
|
||||
|
||||
installSupplementalPack = $coroutine ({host}) ->
|
||||
return {
|
||||
$sendTo: yield @registerHttpRequest(handleInstallSupplementalPack, { hostId: host.id })
|
||||
}
|
||||
|
||||
installSupplementalPack.description = 'installs supplemental pack from ISO file'
|
||||
|
||||
installSupplementalPack.params = {
|
||||
host: { type: 'string' }
|
||||
}
|
||||
|
||||
installSupplementalPack.resolve = {
|
||||
host: ['host', 'host', 'admin']
|
||||
}
|
||||
|
||||
exports.installSupplementalPack = installSupplementalPack;
|
||||
|
||||
#=====================================================================
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
})
|
||||
|
||||
44
src/api/ip-pool.js
Normal file
44
src/api/ip-pool.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import { unauthorized } from 'xo-common/api-errors'
|
||||
|
||||
export function create (props) {
|
||||
return this.createIpPool(props)
|
||||
}
|
||||
|
||||
create.permission = 'admin'
|
||||
create.description = 'Creates a new ipPool'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function delete_ ({ id }) {
|
||||
return this.deleteIpPool(id)
|
||||
}
|
||||
export { delete_ as delete }
|
||||
|
||||
delete_.permission = 'admin'
|
||||
delete_.description = 'Delete an ipPool'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function getAll (params) {
|
||||
const { user } = this
|
||||
|
||||
if (!user) {
|
||||
throw unauthorized()
|
||||
}
|
||||
|
||||
return this.getAllIpPools(user.permission === 'admin'
|
||||
? params && params.userId
|
||||
: user.id
|
||||
)
|
||||
}
|
||||
|
||||
getAll.description = 'List all ipPools'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function set ({ id, ...props }) {
|
||||
return this.updateIpPool(id, props)
|
||||
}
|
||||
|
||||
set.permission = 'admin'
|
||||
set.description = 'Allow to modify an existing ipPool'
|
||||
110
src/api/job.js
Normal file
110
src/api/job.js
Normal file
@@ -0,0 +1,110 @@
|
||||
// FIXME so far, no acls for jobs
|
||||
|
||||
export async function getAll () {
|
||||
return /* await */ this.getAllJobs()
|
||||
}
|
||||
|
||||
getAll.permission = 'admin'
|
||||
getAll.description = 'Gets all available jobs'
|
||||
|
||||
export async function get (id) {
|
||||
return /* await */ this.getJob(id)
|
||||
}
|
||||
|
||||
get.permission = 'admin'
|
||||
get.description = 'Gets an existing job'
|
||||
get.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export async function create ({job}) {
|
||||
if (!job.userId) {
|
||||
job.userId = this.session.get('user_id')
|
||||
}
|
||||
|
||||
return (await this.createJob(job)).id
|
||||
}
|
||||
|
||||
create.permission = 'admin'
|
||||
create.description = 'Creates a new job from description object'
|
||||
create.params = {
|
||||
job: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
userId: {type: 'string', optional: true},
|
||||
name: {type: 'string', optional: true},
|
||||
timeout: {type: 'number', optional: true},
|
||||
type: {type: 'string'},
|
||||
key: {type: 'string'},
|
||||
method: {type: 'string'},
|
||||
paramsVector: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: {type: 'string'},
|
||||
items: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object'
|
||||
}
|
||||
}
|
||||
},
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function set ({job}) {
|
||||
await this.updateJob(job)
|
||||
}
|
||||
|
||||
set.permission = 'admin'
|
||||
set.description = 'Modifies an existing job from a description object'
|
||||
set.params = {
|
||||
job: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {type: 'string'},
|
||||
name: {type: 'string', optional: true},
|
||||
timeout: {type: ['number', 'null'], optional: true},
|
||||
type: {type: 'string', optional: true},
|
||||
key: {type: 'string', optional: true},
|
||||
method: {type: 'string', optional: true},
|
||||
paramsVector: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: {type: 'string'},
|
||||
items: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object'
|
||||
}
|
||||
}
|
||||
},
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function delete_ ({id}) {
|
||||
await this.removeJob(id)
|
||||
}
|
||||
|
||||
delete_.permission = 'admin'
|
||||
delete_.description = 'Deletes an existing job'
|
||||
delete_.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export {delete_ as delete}
|
||||
|
||||
export async function runSequence ({idSequence}) {
|
||||
await this.runJobSequence(idSequence)
|
||||
}
|
||||
|
||||
runSequence.permission = 'admin'
|
||||
runSequence.description = 'Runs jobs sequentially, in the provided order'
|
||||
runSequence.params = {
|
||||
idSequence: {type: 'array', items: {type: 'string'}}
|
||||
}
|
||||
38
src/api/log.js
Normal file
38
src/api/log.js
Normal file
@@ -0,0 +1,38 @@
|
||||
export async function get ({namespace}) {
|
||||
const logger = await this.getLogger(namespace)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const logs = {}
|
||||
|
||||
logger.createReadStream()
|
||||
.on('data', (data) => {
|
||||
logs[data.key] = data.value
|
||||
})
|
||||
.on('end', () => {
|
||||
resolve(logs)
|
||||
})
|
||||
.on('error', reject)
|
||||
})
|
||||
}
|
||||
|
||||
get.description = 'returns logs list for one namespace'
|
||||
get.params = {
|
||||
namespace: { type: 'string' }
|
||||
}
|
||||
get.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
async function delete_ ({namespace, id}) {
|
||||
const logger = await this.getLogger(namespace)
|
||||
logger.del(id)
|
||||
}
|
||||
|
||||
delete_.description = 'deletes one or several logs from a namespace'
|
||||
delete_.params = {
|
||||
id: { type: [ 'array', 'string' ] },
|
||||
namespace: { type: 'string' }
|
||||
}
|
||||
delete_.permission = 'admin'
|
||||
|
||||
export {delete_ as delete}
|
||||
@@ -1,5 +1,5 @@
|
||||
async function delete_ ({message}) {
|
||||
await this.getXAPI(message).call('message.destroy', message.ref)
|
||||
async function delete_ ({ message }) {
|
||||
await this.getXapi(message).call('message.destroy', message._xapiRef)
|
||||
}
|
||||
export {delete_ as delete}
|
||||
|
||||
|
||||
119
src/api/network.js
Normal file
119
src/api/network.js
Normal file
@@ -0,0 +1,119 @@
|
||||
import { mapToArray } from '../utils'
|
||||
|
||||
export function getBondModes () {
|
||||
return ['balance-slb', 'active-backup', 'lacp']
|
||||
}
|
||||
|
||||
export async function create ({ pool, name, description, pif, mtu = 1500, vlan = 0 }) {
|
||||
return this.getXapi(pool).createNetwork({
|
||||
name,
|
||||
description,
|
||||
pifId: pif && this.getObject(pif, 'PIF')._xapiId,
|
||||
mtu: +mtu,
|
||||
vlan: +vlan
|
||||
})
|
||||
}
|
||||
|
||||
create.params = {
|
||||
pool: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
description: { type: 'string', optional: true },
|
||||
pif: { type: 'string', optional: true },
|
||||
mtu: { type: ['integer', 'string'], optional: true },
|
||||
vlan: { type: ['integer', 'string'], optional: true }
|
||||
}
|
||||
|
||||
create.resolve = {
|
||||
pool: ['pool', 'pool', 'administrate']
|
||||
}
|
||||
create.permission = 'admin'
|
||||
|
||||
// =================================================================
|
||||
|
||||
export async function createBonded ({ pool, name, description, pifs, mtu = 1500, mac, bondMode }) {
|
||||
return this.getXapi(pool).createBondedNetwork({
|
||||
name,
|
||||
description,
|
||||
pifIds: mapToArray(pifs, pif =>
|
||||
this.getObject(pif, 'PIF')._xapiId
|
||||
),
|
||||
mtu: +mtu,
|
||||
mac,
|
||||
bondMode
|
||||
})
|
||||
}
|
||||
|
||||
createBonded.params = {
|
||||
pool: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
description: { type: 'string', optional: true },
|
||||
pifs: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
mtu: { type: ['integer', 'string'], optional: true },
|
||||
// RegExp since schema-inspector does not provide a param check based on an enumeration
|
||||
bondMode: { type: 'string', pattern: new RegExp(`^(${getBondModes().join('|')})$`) }
|
||||
}
|
||||
|
||||
createBonded.resolve = {
|
||||
pool: ['pool', 'pool', 'administrate']
|
||||
}
|
||||
createBonded.permission = 'admin'
|
||||
createBonded.description = 'Create a bonded network. bondMode can be balance-slb, active-backup or lacp'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export async function set ({
|
||||
network,
|
||||
|
||||
name_description: nameDescription,
|
||||
name_label: nameLabel,
|
||||
defaultIsLocked,
|
||||
id
|
||||
}) {
|
||||
await this.getXapi(network).setNetworkProperties(network._xapiId, {
|
||||
nameDescription,
|
||||
nameLabel,
|
||||
defaultIsLocked
|
||||
})
|
||||
}
|
||||
|
||||
set.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
name_label: {
|
||||
type: 'string',
|
||||
optional: true
|
||||
},
|
||||
name_description: {
|
||||
type: 'string',
|
||||
optional: true
|
||||
},
|
||||
defaultIsLocked: {
|
||||
type: 'boolean',
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
|
||||
set.resolve = {
|
||||
network: ['id', 'network', 'administrate']
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
|
||||
export async function delete_ ({ network }) {
|
||||
return this.getXapi(network).deleteNetwork(network._xapiId)
|
||||
}
|
||||
export {delete_ as delete}
|
||||
|
||||
delete_.params = {
|
||||
id: { type: 'string' }
|
||||
}
|
||||
|
||||
delete_.resolve = {
|
||||
network: ['id', 'network', 'administrate']
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
async function delete_ ({PBD}) {
|
||||
// TODO: check if PBD is attached before
|
||||
await this.getXAPI(PBD).call('PBD.destroy', PBD.ref)
|
||||
await this.getXapi(PBD).call('PBD.destroy', PBD._xapiRef)
|
||||
}
|
||||
export {delete_ as delete}
|
||||
|
||||
@@ -20,9 +20,8 @@ delete_.resolve = {
|
||||
// ===================================================================
|
||||
// Disconnect
|
||||
|
||||
export async function disconnect ({PBD}) {
|
||||
// TODO: check if PBD is attached before
|
||||
await this.getXAPI(PBD).call('PBD.unplug', PBD.ref)
|
||||
export async function disconnect ({ pbd }) {
|
||||
return this.getXapi(pbd).unplugPbd(pbd._xapiId)
|
||||
}
|
||||
|
||||
disconnect.params = {
|
||||
@@ -30,7 +29,7 @@ disconnect.params = {
|
||||
}
|
||||
|
||||
disconnect.resolve = {
|
||||
PBD: ['id', 'PBD', 'administrate']
|
||||
pbd: ['id', 'PBD', 'administrate']
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
@@ -38,7 +37,7 @@ disconnect.resolve = {
|
||||
|
||||
export async function connect ({PBD}) {
|
||||
// TODO: check if PBD is attached before
|
||||
await this.getXAPI(PBD).call('PBD.plug', PBD.ref)
|
||||
await this.getXapi(PBD).call('PBD.plug', PBD._xapiRef)
|
||||
}
|
||||
|
||||
connect.params = {
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
// TODO: too low level, move into host.
|
||||
|
||||
import { IPV4_CONFIG_MODES, IPV6_CONFIG_MODES } from '../xapi'
|
||||
|
||||
export function getIpv4ConfigurationModes () {
|
||||
return IPV4_CONFIG_MODES
|
||||
}
|
||||
|
||||
export function getIpv6ConfigurationModes () {
|
||||
return IPV6_CONFIG_MODES
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Delete
|
||||
|
||||
async function delete_ ({PIF}) {
|
||||
async function delete_ ({pif}) {
|
||||
// TODO: check if PIF is attached before
|
||||
await this.getXAPI(PIF).call('PIF.destroy', PIF.ref)
|
||||
await this.getXapi(pif).call('PIF.destroy', pif._xapiRef)
|
||||
}
|
||||
export {delete_ as delete}
|
||||
|
||||
@@ -12,15 +24,15 @@ delete_.params = {
|
||||
}
|
||||
|
||||
delete_.resolve = {
|
||||
PIF: ['id', 'PIF', 'administrate']
|
||||
pif: ['id', 'PIF', 'administrate']
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Disconnect
|
||||
|
||||
export async function disconnect ({PIF}) {
|
||||
export async function disconnect ({pif}) {
|
||||
// TODO: check if PIF is attached before
|
||||
await this.getXAPI(PIF).call('PIF.unplug', PIF.ref)
|
||||
await this.getXapi(pif).call('PIF.unplug', pif._xapiRef)
|
||||
}
|
||||
|
||||
disconnect.params = {
|
||||
@@ -28,14 +40,14 @@ disconnect.params = {
|
||||
}
|
||||
|
||||
disconnect.resolve = {
|
||||
PIF: ['id', 'PIF', 'administrate']
|
||||
pif: ['id', 'PIF', 'administrate']
|
||||
}
|
||||
// ===================================================================
|
||||
// Connect
|
||||
|
||||
export async function connect ({PIF}) {
|
||||
export async function connect ({pif}) {
|
||||
// TODO: check if PIF is attached before
|
||||
await this.getXAPI(PIF).call('PIF.plug', PIF.ref)
|
||||
await this.getXapi(pif).call('PIF.plug', pif._xapiRef)
|
||||
}
|
||||
|
||||
connect.params = {
|
||||
@@ -43,5 +55,39 @@ connect.params = {
|
||||
}
|
||||
|
||||
connect.resolve = {
|
||||
PIF: ['id', 'PIF', 'administrate']
|
||||
pif: ['id', 'PIF', 'administrate']
|
||||
}
|
||||
// ===================================================================
|
||||
// Reconfigure IP
|
||||
|
||||
export async function reconfigureIp ({ pif, mode = 'DHCP', ip, netmask, gateway, dns }) {
|
||||
await this.getXapi(pif).call('PIF.reconfigure_ip', pif._xapiRef, mode, ip, netmask, gateway, dns)
|
||||
}
|
||||
|
||||
reconfigureIp.params = {
|
||||
id: { type: 'string', optional: true },
|
||||
mode: { type: 'string', optional: true },
|
||||
ip: { type: 'string', optional: true },
|
||||
netmask: { type: 'string', optional: true },
|
||||
gateway: { type: 'string', optional: true },
|
||||
dns: { type: 'string', optional: true }
|
||||
}
|
||||
|
||||
reconfigureIp.resolve = {
|
||||
pif: ['id', 'PIF', 'administrate']
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export async function editPif ({ pif, vlan }) {
|
||||
await this.getXapi(pif).editPif(pif._xapiId, { vlan })
|
||||
}
|
||||
|
||||
editPif.params = {
|
||||
id: { type: 'string' },
|
||||
vlan: { type: ['integer', 'string'] }
|
||||
}
|
||||
|
||||
editPif.resolve = {
|
||||
pif: ['id', 'PIF', 'administrate']
|
||||
}
|
||||
|
||||
125
src/api/plugin.js
Normal file
125
src/api/plugin.js
Normal file
@@ -0,0 +1,125 @@
|
||||
export async function get () {
|
||||
return /* await */ this.getPlugins()
|
||||
}
|
||||
|
||||
get.description = 'returns a list of all installed plugins'
|
||||
|
||||
get.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function configure ({ id, configuration }) {
|
||||
await this.configurePlugin(id, configuration)
|
||||
}
|
||||
|
||||
configure.description = 'sets the configuration of a plugin'
|
||||
|
||||
configure.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
configuration: {}
|
||||
}
|
||||
|
||||
configure.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function disableAutoload ({ id }) {
|
||||
await this.disablePluginAutoload(id)
|
||||
}
|
||||
|
||||
disableAutoload.description = ''
|
||||
|
||||
disableAutoload.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
disableAutoload.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function enableAutoload ({ id }) {
|
||||
await this.enablePluginAutoload(id)
|
||||
}
|
||||
|
||||
enableAutoload.description = 'enables a plugin, allowing it to be loaded'
|
||||
|
||||
enableAutoload.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
enableAutoload.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function load ({ id }) {
|
||||
await this.loadPlugin(id)
|
||||
}
|
||||
|
||||
load.description = 'loads a plugin'
|
||||
|
||||
load.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
load.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function unload ({ id }) {
|
||||
await this.unloadPlugin(id)
|
||||
}
|
||||
|
||||
unload.description = 'unloads a plugin'
|
||||
|
||||
unload.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
unload.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function purgeConfiguration ({ id }) {
|
||||
await this.purgePluginConfiguration(id)
|
||||
}
|
||||
|
||||
purgeConfiguration.description = 'removes a plugin configuration'
|
||||
|
||||
purgeConfiguration.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
purgeConfiguration.permission = 'admin'
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
export async function test ({ id, data }) {
|
||||
await this.testPlugin(id, data)
|
||||
}
|
||||
|
||||
test.description = 'Test a plugin with its current configuration'
|
||||
|
||||
test.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
data: {
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
|
||||
test.permission = 'admin'
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
129
src/api/pool.js
129
src/api/pool.js
@@ -1,10 +1,18 @@
|
||||
import { format } from 'json-rpc-peer'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export async function set (params) {
|
||||
const {pool} = params
|
||||
delete params.pool
|
||||
export async function set ({
|
||||
pool,
|
||||
|
||||
await this.getXAPI(pool).setPoolProperties(params)
|
||||
// TODO: use camel case.
|
||||
name_description: nameDescription,
|
||||
name_label: nameLabel
|
||||
}) {
|
||||
await this.getXapi(pool).setPoolProperties({
|
||||
nameDescription,
|
||||
nameLabel
|
||||
})
|
||||
}
|
||||
|
||||
set.params = {
|
||||
@@ -27,8 +35,27 @@ set.resolve = {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function setDefaultSr ({ sr }) {
|
||||
await this.hasPermissions(this.user.id, [ [ sr.$pool, 'administrate' ] ])
|
||||
|
||||
await this.getXapi(sr).setDefaultSr(sr._xapiId)
|
||||
}
|
||||
|
||||
setDefaultSr.permission = '' // signed in
|
||||
|
||||
setDefaultSr.params = {
|
||||
sr: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
setDefaultSr.resolve = {
|
||||
sr: ['sr', 'SR']
|
||||
}
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function installPatch ({pool, patch: patchUuid}) {
|
||||
await this.getXAPI(pool).installPoolPatchOnAllHosts(patchUuid)
|
||||
await this.getXapi(pool).installPoolPatchOnAllHosts(patchUuid)
|
||||
}
|
||||
|
||||
installPatch.params = {
|
||||
@@ -43,18 +70,35 @@ installPatch.params = {
|
||||
installPatch.resolve = {
|
||||
pool: ['pool', 'pool', 'administrate']
|
||||
}
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function installAllPatches ({ pool }) {
|
||||
await this.getXapi(pool).installAllPoolPatchesOnAllHosts()
|
||||
}
|
||||
|
||||
installAllPatches.params = {
|
||||
pool: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
installAllPatches.resolve = {
|
||||
pool: ['pool', 'pool', 'administrate']
|
||||
}
|
||||
|
||||
installAllPatches.description = 'Install automatically all patches for every hosts of a pool'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
async function handlePatchUpload (req, res, {pool}) {
|
||||
const {headers: {['content-length']: contentLength}} = req
|
||||
const contentLength = req.headers['content-length']
|
||||
if (!contentLength) {
|
||||
res.writeHead(411)
|
||||
res.end('Content length is mandatory')
|
||||
return
|
||||
}
|
||||
|
||||
await this.getXAPI(pool).uploadPoolPatch(req, contentLength)
|
||||
await this.getXapi(pool).uploadPoolPatch(req, contentLength)
|
||||
}
|
||||
|
||||
export async function uploadPatch ({pool}) {
|
||||
@@ -75,3 +119,74 @@ uploadPatch.resolve = {
|
||||
//
|
||||
// TODO: remove when no longer used in xo-web
|
||||
export {uploadPatch as patch}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function mergeInto ({ source, target, force }) {
|
||||
await this.mergeXenPools(source._xapiId, target._xapiId, force)
|
||||
}
|
||||
|
||||
mergeInto.params = {
|
||||
force: { type: 'boolean', optional: true },
|
||||
source: { type: 'string' },
|
||||
target: { type: 'string' }
|
||||
}
|
||||
|
||||
mergeInto.resolve = {
|
||||
source: ['source', 'pool', 'administrate'],
|
||||
target: ['target', 'pool', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function getLicenseState ({pool}) {
|
||||
return this.getXapi(pool).call(
|
||||
'pool.get_license_state',
|
||||
pool._xapiId.$ref
|
||||
)
|
||||
}
|
||||
|
||||
getLicenseState.params = {
|
||||
pool: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
getLicenseState.resolve = {
|
||||
pool: ['pool', 'pool', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
async function handleInstallSupplementalPack (req, res, { poolId }) {
|
||||
const xapi = this.getXapi(poolId)
|
||||
|
||||
// Timeout seems to be broken in Node 4.
|
||||
// See https://github.com/nodejs/node/issues/3319
|
||||
req.setTimeout(43200000) // 12 hours
|
||||
req.length = req.headers['content-length']
|
||||
|
||||
try {
|
||||
await xapi.installSupplementalPackOnAllHosts(req)
|
||||
res.end(format.response(0))
|
||||
} catch (e) {
|
||||
res.writeHead(500)
|
||||
res.end(format.error(0, new Error(e.message)))
|
||||
}
|
||||
}
|
||||
|
||||
export async function installSupplementalPack ({ pool }) {
|
||||
return {
|
||||
$sendTo: await this.registerHttpRequest(handleInstallSupplementalPack, { poolId: pool.id })
|
||||
}
|
||||
}
|
||||
|
||||
installSupplementalPack.description = 'installs supplemental pack from ISO file on all hosts'
|
||||
|
||||
installSupplementalPack.params = {
|
||||
pool: { type: 'string' }
|
||||
}
|
||||
|
||||
installSupplementalPack.resolve = {
|
||||
pool: ['pool', 'pool', 'admin']
|
||||
}
|
||||
|
||||
72
src/api/remote.js
Normal file
72
src/api/remote.js
Normal file
@@ -0,0 +1,72 @@
|
||||
export async function getAll () {
|
||||
return this.getAllRemotes()
|
||||
}
|
||||
|
||||
getAll.permission = 'admin'
|
||||
getAll.description = 'Gets all existing fs remote points'
|
||||
|
||||
export async function get ({id}) {
|
||||
return this.getRemote(id)
|
||||
}
|
||||
|
||||
get.permission = 'admin'
|
||||
get.description = 'Gets an existing fs remote point'
|
||||
get.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export async function test ({id}) {
|
||||
return this.testRemote(id)
|
||||
}
|
||||
|
||||
test.permission = 'admin'
|
||||
test.description = 'Performs a read/write matching test on a remote point'
|
||||
test.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export async function list ({id}) {
|
||||
return this.listRemoteBackups(id)
|
||||
}
|
||||
|
||||
list.permission = 'admin'
|
||||
list.description = 'Lists the files found in a remote point'
|
||||
list.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export async function create ({name, url}) {
|
||||
return this.createRemote({name, url})
|
||||
}
|
||||
|
||||
create.permission = 'admin'
|
||||
create.description = 'Creates a new fs remote point'
|
||||
create.params = {
|
||||
name: {type: 'string'},
|
||||
url: {type: 'string'}
|
||||
}
|
||||
|
||||
export async function set ({id, name, url, enabled}) {
|
||||
await this.updateRemote(id, {name, url, enabled})
|
||||
}
|
||||
|
||||
set.permission = 'admin'
|
||||
set.description = 'Modifies an existing fs remote point'
|
||||
set.params = {
|
||||
id: {type: 'string'},
|
||||
name: {type: 'string', optional: true},
|
||||
url: {type: 'string', optional: true},
|
||||
enabled: {type: 'boolean', optional: true}
|
||||
}
|
||||
|
||||
async function delete_ ({id}) {
|
||||
await this.removeRemote(id)
|
||||
}
|
||||
|
||||
delete_.permission = 'admin'
|
||||
delete_.description = 'Deletes an existing fs remote point'
|
||||
delete_.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export {delete_ as delete}
|
||||
240
src/api/resource-set.js
Normal file
240
src/api/resource-set.js
Normal file
@@ -0,0 +1,240 @@
|
||||
import {
|
||||
unauthorized
|
||||
} from 'xo-common/api-errors'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export function create ({ name, subjects, objects, limits }) {
|
||||
return this.createResourceSet(name, subjects, objects, limits)
|
||||
}
|
||||
|
||||
create.permission = 'admin'
|
||||
|
||||
create.params = {
|
||||
name: {
|
||||
type: 'string'
|
||||
},
|
||||
subjects: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
},
|
||||
objects: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
},
|
||||
limits: {
|
||||
type: 'object',
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function delete_ ({ id }) {
|
||||
return this.deleteResourceSet(id)
|
||||
}
|
||||
export { delete_ as delete }
|
||||
|
||||
delete_.permission = 'admin'
|
||||
|
||||
delete_.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function set ({ id, name, subjects, objects, ipPools, limits }) {
|
||||
return this.updateResourceSet(id, {
|
||||
limits,
|
||||
name,
|
||||
objects,
|
||||
ipPools,
|
||||
subjects
|
||||
})
|
||||
}
|
||||
|
||||
set.permission = 'admin'
|
||||
|
||||
set.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
optional: true
|
||||
},
|
||||
subjects: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
},
|
||||
objects: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
},
|
||||
ipPools: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
},
|
||||
limits: {
|
||||
type: 'object',
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function get ({ id }) {
|
||||
return this.getResourceSet(id)
|
||||
}
|
||||
|
||||
get.permission = 'admin'
|
||||
|
||||
get.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function getAll () {
|
||||
const { user } = this
|
||||
if (!user) {
|
||||
throw unauthorized()
|
||||
}
|
||||
|
||||
return this.getAllResourceSets(user.id)
|
||||
}
|
||||
|
||||
getAll.description = 'Get the list of all existing resource set'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function addObject ({ id, object }) {
|
||||
return this.addObjectToResourceSet(object, id)
|
||||
}
|
||||
|
||||
addObject.permission = 'admin'
|
||||
|
||||
addObject.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
object: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function removeObject ({ id, object }) {
|
||||
return this.removeObjectFromResourceSet(object, id)
|
||||
}
|
||||
|
||||
removeObject.permission = 'admin'
|
||||
|
||||
removeObject.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
object: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function addSubject ({ id, subject }) {
|
||||
return this.addSubjectToResourceSet(subject, id)
|
||||
}
|
||||
|
||||
addSubject.permission = 'admin'
|
||||
|
||||
addSubject.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
subject: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function removeSubject ({ id, subject }) {
|
||||
return this.removeSubjectFromResourceSet(subject, id)
|
||||
}
|
||||
|
||||
removeSubject.permission = 'admin'
|
||||
|
||||
removeSubject.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
subject: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function addLimit ({ id, limitId, quantity }) {
|
||||
return this.addLimitToResourceSet(limitId, quantity, id)
|
||||
}
|
||||
|
||||
addLimit.permission = 'admin'
|
||||
|
||||
addLimit.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
limitId: {
|
||||
type: 'string'
|
||||
},
|
||||
quantity: {
|
||||
type: 'integer'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function removeLimit ({ id, limitId }) {
|
||||
return this.removeLimitFromResourceSet(limitId, id)
|
||||
}
|
||||
|
||||
removeLimit.permission = 'admin'
|
||||
|
||||
removeLimit.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
limitId: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function recomputeAllLimits () {
|
||||
return this.recomputeResourceSetsLimits()
|
||||
}
|
||||
|
||||
recomputeAllLimits.permission = 'admin'
|
||||
recomputeAllLimits.description = 'Recompute manually the current resource set usage'
|
||||
@@ -1,3 +1,5 @@
|
||||
export async function getAll () {
|
||||
return await this.getRoles()
|
||||
return /* await */ this.getRoles()
|
||||
}
|
||||
|
||||
getAll.description = 'Returns the list of all existing roles'
|
||||
|
||||
57
src/api/schedule.js
Normal file
57
src/api/schedule.js
Normal file
@@ -0,0 +1,57 @@
|
||||
// FIXME so far, no acls for schedules
|
||||
|
||||
export async function getAll () {
|
||||
return /* await */ this.getAllSchedules()
|
||||
}
|
||||
|
||||
getAll.permission = 'admin'
|
||||
getAll.description = 'Gets all existing schedules'
|
||||
|
||||
export async function get (id) {
|
||||
return /* await */ this.getSchedule(id)
|
||||
}
|
||||
|
||||
get.permission = 'admin'
|
||||
get.description = 'Gets an existing schedule'
|
||||
get.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export async function create ({ jobId, cron, enabled, name, timezone }) {
|
||||
return /* await */ this.createSchedule(this.session.get('user_id'), { job: jobId, cron, enabled, name, timezone })
|
||||
}
|
||||
|
||||
create.permission = 'admin'
|
||||
create.description = 'Creates a new schedule'
|
||||
create.params = {
|
||||
jobId: {type: 'string'},
|
||||
cron: {type: 'string'},
|
||||
enabled: {type: 'boolean', optional: true},
|
||||
name: {type: 'string', optional: true}
|
||||
}
|
||||
|
||||
export async function set ({ id, jobId, cron, enabled, name, timezone }) {
|
||||
await this.updateSchedule(id, { job: jobId, cron, enabled, name, timezone })
|
||||
}
|
||||
|
||||
set.permission = 'admin'
|
||||
set.description = 'Modifies an existing schedule'
|
||||
set.params = {
|
||||
id: {type: 'string'},
|
||||
jobId: {type: 'string', optional: true},
|
||||
cron: {type: 'string', optional: true},
|
||||
enabled: {type: 'boolean', optional: true},
|
||||
name: {type: 'string', optional: true}
|
||||
}
|
||||
|
||||
async function delete_ ({id}) {
|
||||
await this.removeSchedule(id)
|
||||
}
|
||||
|
||||
delete_.permission = 'admin'
|
||||
delete_.description = 'Deletes an existing schedule'
|
||||
delete_.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export {delete_ as delete}
|
||||
30
src/api/scheduler.js
Normal file
30
src/api/scheduler.js
Normal file
@@ -0,0 +1,30 @@
|
||||
export async function enable ({id}) {
|
||||
const schedule = await this.getSchedule(id)
|
||||
schedule.enabled = true
|
||||
await this.updateSchedule(id, schedule)
|
||||
}
|
||||
|
||||
enable.permission = 'admin'
|
||||
enable.description = 'Enables a schedule to run it\'s job as scheduled'
|
||||
enable.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export async function disable ({id}) {
|
||||
const schedule = await this.getSchedule(id)
|
||||
schedule.enabled = false
|
||||
await this.updateSchedule(id, schedule)
|
||||
}
|
||||
|
||||
disable.permission = 'admin'
|
||||
disable.description = 'Disables a schedule'
|
||||
disable.params = {
|
||||
id: {type: 'string'}
|
||||
}
|
||||
|
||||
export function getScheduleTable () {
|
||||
return this.scheduleTable
|
||||
}
|
||||
|
||||
disable.permission = 'admin'
|
||||
disable.description = 'Get a map of existing schedules enabled/disabled state'
|
||||
@@ -1,18 +1,21 @@
|
||||
import {coroutine} from 'bluebird'
|
||||
|
||||
// ===================================================================
|
||||
import {
|
||||
noop,
|
||||
pCatch
|
||||
} from '../utils'
|
||||
|
||||
export async function add ({
|
||||
label,
|
||||
host,
|
||||
username,
|
||||
password,
|
||||
readOnly,
|
||||
autoConnect = true
|
||||
}) {
|
||||
const server = await this.registerXenServer({host, username, password})
|
||||
const server = await this.registerXenServer({label, host, username, password, readOnly})
|
||||
|
||||
if (autoConnect) {
|
||||
// Connect asynchronously, ignore any error.
|
||||
this.connectXenServer(server.id).catch(() => {})
|
||||
// Connect asynchronously, ignore any errors.
|
||||
this.connectXenServer(server.id)::pCatch(noop)
|
||||
}
|
||||
|
||||
return server.id
|
||||
@@ -23,6 +26,10 @@ add.description = 'register a new Xen server'
|
||||
add.permission = 'admin'
|
||||
|
||||
add.params = {
|
||||
label: {
|
||||
optional: true,
|
||||
type: 'string'
|
||||
},
|
||||
host: {
|
||||
type: 'string'
|
||||
},
|
||||
@@ -41,7 +48,7 @@ add.params = {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function remove ({id}) {
|
||||
this.unregisterXenServer(id)
|
||||
await this.unregisterXenServer(id)
|
||||
}
|
||||
|
||||
remove.description = 'unregister a Xen server'
|
||||
@@ -58,15 +65,9 @@ remove.params = {
|
||||
|
||||
// TODO: remove this function when users are integrated to the main
|
||||
// collection.
|
||||
export const getAll = coroutine(function * () {
|
||||
const servers = yield this._servers.get()
|
||||
|
||||
for (let i = 0, n = servers.length; i < n; ++i) {
|
||||
servers[i] = this.getServerPublicProperties(servers[i])
|
||||
}
|
||||
|
||||
return servers
|
||||
})
|
||||
export function getAll () {
|
||||
return this.getAllXenServers()
|
||||
}
|
||||
|
||||
getAll.description = 'returns all the registered Xen server'
|
||||
|
||||
@@ -74,11 +75,11 @@ getAll.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function set ({id, host, username, password}) {
|
||||
await this.updateXenServer(id, {host, username, password})
|
||||
export async function set ({id, label, host, username, password, readOnly}) {
|
||||
await this.updateXenServer(id, {label, host, username, password, readOnly})
|
||||
}
|
||||
|
||||
set.description = 'changes the propeorties of a Xen server'
|
||||
set.description = 'changes the properties of a Xen server'
|
||||
|
||||
set.permission = 'admin'
|
||||
|
||||
@@ -86,6 +87,10 @@ set.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
label: {
|
||||
type: 'string',
|
||||
optional: true
|
||||
},
|
||||
host: {
|
||||
type: 'string',
|
||||
optional: true
|
||||
@@ -103,6 +108,7 @@ set.params = {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function connect ({id}) {
|
||||
this.updateXenServer(id, {enabled: true})::pCatch(noop)
|
||||
await this.connectXenServer(id)
|
||||
}
|
||||
|
||||
@@ -119,6 +125,7 @@ connect.params = {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function disconnect ({id}) {
|
||||
this.updateXenServer(id, {enabled: false})::pCatch(noop)
|
||||
await this.disconnectXenServer(id)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
import {deprecate} from 'util'
|
||||
|
||||
import {InvalidCredential, AlreadyAuthenticated} from '../api-errors'
|
||||
import { getUserPublicProperties } from '../utils'
|
||||
import {invalidCredentials} from 'xo-common/api-errors'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export async function signIn (credentials) {
|
||||
if (this.session.has('user_id')) {
|
||||
throw new AlreadyAuthenticated()
|
||||
}
|
||||
|
||||
const user = await this.authenticateUser(credentials)
|
||||
if (!user) {
|
||||
throw new InvalidCredential()
|
||||
throw invalidCredentials()
|
||||
}
|
||||
this.session.set('user_id', user.get('id'))
|
||||
this.session.set('user_id', user.id)
|
||||
|
||||
return this.getUserPublicProperties(user)
|
||||
return getUserPublicProperties(user)
|
||||
}
|
||||
|
||||
signIn.description = 'sign in'
|
||||
@@ -53,9 +50,9 @@ signOut.permission = ''
|
||||
export async function getUser () {
|
||||
const userId = this.session.get('user_id')
|
||||
|
||||
return userId === undefined ?
|
||||
null :
|
||||
this.getUserPublicProperties(await this.getUser(userId))
|
||||
return userId === undefined
|
||||
? null
|
||||
: getUserPublicProperties(await this.getUser(userId))
|
||||
}
|
||||
|
||||
getUser.description = 'return the currently connected user'
|
||||
|
||||
255
src/api/sr.js
255
src/api/sr.js
@@ -1,13 +1,23 @@
|
||||
import forEach from 'lodash.foreach'
|
||||
import {ensureArray, parseXml} from '../utils'
|
||||
import { asInteger } from '../xapi/utils'
|
||||
import {
|
||||
ensureArray,
|
||||
forEach,
|
||||
parseXml
|
||||
} from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export async function set (params) {
|
||||
const {sr} = params
|
||||
delete params.sr
|
||||
export async function set ({
|
||||
sr,
|
||||
|
||||
await this.getXAPI(sr).setSrProperties(sr.id, params)
|
||||
// TODO: use camel case.
|
||||
name_description: nameDescription,
|
||||
name_label: nameLabel
|
||||
}) {
|
||||
await this.getXapi(sr).setSrProperties(sr._xapiId, {
|
||||
nameDescription,
|
||||
nameLabel
|
||||
})
|
||||
}
|
||||
|
||||
set.params = {
|
||||
@@ -24,8 +34,8 @@ set.resolve = {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function scan ({SR}) {
|
||||
await this.getXAPI(SR).call('SR.scan', SR.ref)
|
||||
export async function scan ({ SR }) {
|
||||
await this.getXapi(SR).call('SR.scan', SR._xapiRef)
|
||||
}
|
||||
|
||||
scan.params = {
|
||||
@@ -39,8 +49,16 @@ scan.resolve = {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// TODO: find a way to call this "delete" and not destroy
|
||||
export async function destroy ({SR}) {
|
||||
await this.getXAPI(SR).call('SR.destroy', SR.ref)
|
||||
export async function destroy ({ sr }) {
|
||||
const xapi = this.getXapi(sr)
|
||||
if (sr.SR_type === 'xosan') {
|
||||
const config = xapi.xo.getData(sr, 'xosan_config')
|
||||
// we simply forget because the hosted disks are been destroyed with the VMs
|
||||
await xapi.forgetSr(sr._xapiId)
|
||||
await Promise.all(config.nodes.map(node => xapi.deleteVm(node.vm.id, true)))
|
||||
return xapi.deleteNetwork(config.network)
|
||||
}
|
||||
await xapi.destroySr(sr._xapiId)
|
||||
}
|
||||
|
||||
destroy.params = {
|
||||
@@ -48,13 +66,13 @@ destroy.params = {
|
||||
}
|
||||
|
||||
destroy.resolve = {
|
||||
SR: ['id', 'SR', 'administrate']
|
||||
sr: ['id', 'SR', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function forget ({SR}) {
|
||||
await this.getXAPI(SR).call('SR.forget', SR.ref)
|
||||
export async function forget ({ SR }) {
|
||||
await this.getXapi(SR).forgetSr(SR._xapiId)
|
||||
}
|
||||
|
||||
forget.params = {
|
||||
@@ -67,31 +85,67 @@ forget.resolve = {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function connectAllPbds ({ SR }) {
|
||||
await this.getXapi(SR).connectAllSrPbds(SR._xapiId)
|
||||
}
|
||||
|
||||
connectAllPbds.params = {
|
||||
id: { type: 'string' }
|
||||
}
|
||||
|
||||
connectAllPbds.resolve = {
|
||||
SR: ['id', 'SR', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function disconnectAllPbds ({ SR }) {
|
||||
await this.getXapi(SR).disconnectAllSrPbds(SR._xapiId)
|
||||
}
|
||||
|
||||
disconnectAllPbds.params = {
|
||||
id: { type: 'string' }
|
||||
}
|
||||
|
||||
disconnectAllPbds.resolve = {
|
||||
SR: ['id', 'SR', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function createIso ({
|
||||
host,
|
||||
nameLabel,
|
||||
nameDescription,
|
||||
path
|
||||
path,
|
||||
type,
|
||||
user,
|
||||
password
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
// FIXME: won't work for IPv6
|
||||
// Detect if NFS or local path for ISO files
|
||||
const deviceConfig = {location: path}
|
||||
if (path.indexOf(':') === -1) { // not NFS share
|
||||
// TODO: legacy will be removed in XAPI soon by FileSR
|
||||
const deviceConfig = {}
|
||||
if (type === 'local') {
|
||||
deviceConfig.legacy_mode = 'true'
|
||||
} else if (type === 'smb') {
|
||||
path = path.replace(/\\/g, '/')
|
||||
deviceConfig.type = 'cifs'
|
||||
deviceConfig.username = user
|
||||
deviceConfig.cifspassword = password
|
||||
}
|
||||
|
||||
deviceConfig.location = path
|
||||
|
||||
const srRef = await xapi.call(
|
||||
'SR.create',
|
||||
host.ref,
|
||||
host._xapiRef,
|
||||
deviceConfig,
|
||||
'0', // SR size 0 because ISO
|
||||
nameLabel,
|
||||
nameDescription,
|
||||
'iso', // SR type ISO
|
||||
'iso', // SR content type ISO
|
||||
true,
|
||||
type !== 'local',
|
||||
{}
|
||||
)
|
||||
|
||||
@@ -103,7 +157,10 @@ createIso.params = {
|
||||
host: { type: 'string' },
|
||||
nameLabel: { type: 'string' },
|
||||
nameDescription: { type: 'string' },
|
||||
path: { type: 'string' }
|
||||
path: { type: 'string' },
|
||||
type: { type: 'string' },
|
||||
user: { type: 'string', optional: true },
|
||||
password: { type: 'string', optional: true }
|
||||
}
|
||||
|
||||
createIso.resolve = {
|
||||
@@ -123,7 +180,7 @@ export async function createNfs ({
|
||||
serverPath,
|
||||
nfsVersion
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
const deviceConfig = {
|
||||
server,
|
||||
@@ -137,7 +194,7 @@ export async function createNfs ({
|
||||
|
||||
const srRef = await xapi.call(
|
||||
'SR.create',
|
||||
host.ref,
|
||||
host._xapiRef,
|
||||
deviceConfig,
|
||||
'0',
|
||||
nameLabel,
|
||||
@@ -165,6 +222,51 @@ createNfs.resolve = {
|
||||
host: ['host', 'host', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// HBA SR
|
||||
|
||||
// This functions creates an HBA SR
|
||||
|
||||
export async function createHba ({
|
||||
host,
|
||||
nameLabel,
|
||||
nameDescription,
|
||||
scsiId
|
||||
}) {
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
const deviceConfig = {
|
||||
scsiId
|
||||
}
|
||||
|
||||
const srRef = await xapi.call(
|
||||
'SR.create',
|
||||
host._xapiRef,
|
||||
deviceConfig,
|
||||
'0',
|
||||
nameLabel,
|
||||
nameDescription,
|
||||
'lvmoohba', // SR LVM over HBA
|
||||
'user', // recommended by Citrix
|
||||
true,
|
||||
{}
|
||||
)
|
||||
|
||||
const sr = await xapi.call('SR.get_record', srRef)
|
||||
return sr.uuid
|
||||
}
|
||||
|
||||
createHba.params = {
|
||||
host: { type: 'string' },
|
||||
nameLabel: { type: 'string' },
|
||||
nameDescription: { type: 'string' },
|
||||
scsiId: { type: 'string' }
|
||||
}
|
||||
|
||||
createHba.resolve = {
|
||||
host: ['host', 'host', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Local LVM SR
|
||||
|
||||
@@ -176,7 +278,7 @@ export async function createLvm ({
|
||||
nameDescription,
|
||||
device
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
const deviceConfig = {
|
||||
device
|
||||
@@ -184,7 +286,7 @@ export async function createLvm ({
|
||||
|
||||
const srRef = await xapi.call(
|
||||
'SR.create',
|
||||
host.ref,
|
||||
host._xapiRef,
|
||||
deviceConfig,
|
||||
'0',
|
||||
nameLabel,
|
||||
@@ -218,7 +320,7 @@ export async function probeNfs ({
|
||||
host,
|
||||
server
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
const deviceConfig = {
|
||||
server
|
||||
@@ -229,7 +331,7 @@ export async function probeNfs ({
|
||||
try {
|
||||
await xapi.call(
|
||||
'SR.probe',
|
||||
host.ref,
|
||||
host._xapiRef,
|
||||
deviceConfig,
|
||||
'nfs',
|
||||
{}
|
||||
@@ -264,6 +366,55 @@ probeNfs.resolve = {
|
||||
host: ['host', 'host', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// This function helps to detect all HBA devices on the host
|
||||
|
||||
export async function probeHba ({
|
||||
host
|
||||
}) {
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
let xml
|
||||
|
||||
try {
|
||||
await xapi.call(
|
||||
'SR.probe',
|
||||
host._xapiRef,
|
||||
'type',
|
||||
{}
|
||||
)
|
||||
|
||||
throw new Error('the call above should have thrown an error')
|
||||
} catch (error) {
|
||||
if (error.code !== 'SR_BACKEND_FAILURE_107') {
|
||||
throw error
|
||||
}
|
||||
|
||||
xml = parseXml(error.params[2])
|
||||
}
|
||||
|
||||
const hbaDevices = []
|
||||
forEach(ensureArray(xml.Devlist.BlockDevice), hbaDevice => {
|
||||
hbaDevices.push({
|
||||
hba: hbaDevice.hba.trim(),
|
||||
path: hbaDevice.path.trim(),
|
||||
scsciId: hbaDevice.SCSIid.trim(),
|
||||
size: hbaDevice.size.trim(),
|
||||
vendor: hbaDevice.vendor.trim()
|
||||
})
|
||||
})
|
||||
|
||||
return hbaDevices
|
||||
}
|
||||
|
||||
probeHba.params = {
|
||||
host: { type: 'string' }
|
||||
}
|
||||
|
||||
probeHba.resolve = {
|
||||
host: ['host', 'host', 'administrate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// ISCSI SR
|
||||
|
||||
@@ -281,7 +432,7 @@ export async function createIscsi ({
|
||||
chapUser,
|
||||
chapPassword
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
const deviceConfig = {
|
||||
target,
|
||||
@@ -297,12 +448,12 @@ export async function createIscsi ({
|
||||
|
||||
// if we give another port than default iSCSI
|
||||
if (port) {
|
||||
deviceConfig.port = port
|
||||
deviceConfig.port = asInteger(port)
|
||||
}
|
||||
|
||||
const srRef = await xapi.call(
|
||||
'SR.create',
|
||||
host.ref,
|
||||
host._xapiRef,
|
||||
deviceConfig,
|
||||
'0',
|
||||
nameLabel,
|
||||
@@ -322,7 +473,7 @@ createIscsi.params = {
|
||||
nameLabel: { type: 'string' },
|
||||
nameDescription: { type: 'string' },
|
||||
target: { type: 'string' },
|
||||
port: { type: 'integer', optional: true},
|
||||
port: { type: 'integer', optional: true },
|
||||
targetIqn: { type: 'string' },
|
||||
scsiId: { type: 'string' },
|
||||
chapUser: { type: 'string', optional: true },
|
||||
@@ -344,7 +495,7 @@ export async function probeIscsiIqns ({
|
||||
chapUser,
|
||||
chapPassword
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
const deviceConfig = {
|
||||
target: targetIp
|
||||
@@ -358,7 +509,7 @@ export async function probeIscsiIqns ({
|
||||
|
||||
// if we give another port than default iSCSI
|
||||
if (port) {
|
||||
deviceConfig.port = port
|
||||
deviceConfig.port = asInteger(port)
|
||||
}
|
||||
|
||||
let xml
|
||||
@@ -366,7 +517,7 @@ export async function probeIscsiIqns ({
|
||||
try {
|
||||
await xapi.call(
|
||||
'SR.probe',
|
||||
host.ref,
|
||||
host._xapiRef,
|
||||
deviceConfig,
|
||||
'lvmoiscsi',
|
||||
{}
|
||||
@@ -421,7 +572,7 @@ export async function probeIscsiLuns ({
|
||||
chapUser,
|
||||
chapPassword
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
const deviceConfig = {
|
||||
target: targetIp,
|
||||
@@ -436,7 +587,7 @@ export async function probeIscsiLuns ({
|
||||
|
||||
// if we give another port than default iSCSI
|
||||
if (port) {
|
||||
deviceConfig.port = port
|
||||
deviceConfig.port = asInteger(port)
|
||||
}
|
||||
|
||||
let xml
|
||||
@@ -444,7 +595,7 @@ export async function probeIscsiLuns ({
|
||||
try {
|
||||
await xapi.call(
|
||||
'SR.probe',
|
||||
host.ref,
|
||||
host._xapiRef,
|
||||
deviceConfig,
|
||||
'lvmoiscsi',
|
||||
{}
|
||||
@@ -476,7 +627,7 @@ export async function probeIscsiLuns ({
|
||||
probeIscsiLuns.params = {
|
||||
host: { type: 'string' },
|
||||
target: { type: 'string' },
|
||||
port: { type: 'integer', optional: true},
|
||||
port: { type: 'integer', optional: true },
|
||||
targetIqn: { type: 'string' },
|
||||
chapUser: { type: 'string', optional: true },
|
||||
chapPassword: { type: 'string', optional: true }
|
||||
@@ -499,7 +650,7 @@ export async function probeIscsiExists ({
|
||||
chapUser,
|
||||
chapPassword
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
const deviceConfig = {
|
||||
target: targetIp,
|
||||
@@ -515,15 +666,15 @@ export async function probeIscsiExists ({
|
||||
|
||||
// if we give another port than default iSCSI
|
||||
if (port) {
|
||||
deviceConfig.port = port
|
||||
deviceConfig.port = asInteger(port)
|
||||
}
|
||||
|
||||
const xml = parseXml(await xapi.call('SR.probe', host.ref, deviceConfig, 'lvmoiscsi', {}))
|
||||
const xml = parseXml(await xapi.call('SR.probe', host._xapiRef, deviceConfig, 'lvmoiscsi', {}))
|
||||
|
||||
const srs = []
|
||||
forEach(ensureArray(xml['SRlist'].SR), sr => {
|
||||
// get the UUID of SR connected to this LUN
|
||||
srs.push({uuid: sr.UUID.trim()})
|
||||
srs.push({ uuid: sr.UUID.trim() })
|
||||
})
|
||||
|
||||
return srs
|
||||
@@ -550,22 +701,22 @@ probeIscsiExists.resolve = {
|
||||
export async function probeNfsExists ({
|
||||
host,
|
||||
server,
|
||||
serverPath,
|
||||
serverPath
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
const deviceConfig = {
|
||||
server,
|
||||
serverpath: serverPath
|
||||
}
|
||||
|
||||
const xml = parseXml(await xapi.call('SR.probe', host.ref, deviceConfig, 'nfs', {}))
|
||||
const xml = parseXml(await xapi.call('SR.probe', host._xapiRef, deviceConfig, 'nfs', {}))
|
||||
|
||||
const srs = []
|
||||
|
||||
forEach(ensureArray(xml['SRlist'].SR), sr => {
|
||||
// get the UUID of SR connected to this LUN
|
||||
srs.push({uuid: sr.UUID.trim()})
|
||||
srs.push({ uuid: sr.UUID.trim() })
|
||||
})
|
||||
|
||||
return srs
|
||||
@@ -589,9 +740,9 @@ export async function reattach ({
|
||||
uuid,
|
||||
nameLabel,
|
||||
nameDescription,
|
||||
type,
|
||||
type
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
if (type === 'iscsi') {
|
||||
type = 'lvmoiscsi' // the internal XAPI name
|
||||
@@ -632,9 +783,9 @@ export async function reattachIso ({
|
||||
uuid,
|
||||
nameLabel,
|
||||
nameDescription,
|
||||
type,
|
||||
type
|
||||
}) {
|
||||
const xapi = this.getXAPI(host)
|
||||
const xapi = this.getXapi(host)
|
||||
|
||||
if (type === 'iscsi') {
|
||||
type = 'lvmoiscsi' // the internal XAPI name
|
||||
|
||||
67
src/api/system.js
Normal file
67
src/api/system.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import forEach from 'lodash/forEach'
|
||||
import getKeys from 'lodash/keys'
|
||||
import moment from 'moment-timezone'
|
||||
|
||||
import { noSuchObject } from 'xo-common/api-errors'
|
||||
import { version as xoServerVersion } from '../../package.json'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export function getMethodsInfo () {
|
||||
const methods = {}
|
||||
|
||||
forEach(this.apiMethods, (method, name) => {
|
||||
methods[name] = {
|
||||
description: method.description,
|
||||
params: method.params || {},
|
||||
permission: method.permission
|
||||
}
|
||||
})
|
||||
|
||||
return methods
|
||||
}
|
||||
getMethodsInfo.description = 'returns the signatures of all available API methods'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export const getServerTimezone = (tz => () => tz)(moment.tz.guess())
|
||||
getServerTimezone.description = 'return the timezone server'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export const getServerVersion = () => xoServerVersion
|
||||
getServerVersion.description = 'return the version of xo-server'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export const getVersion = () => '0.1'
|
||||
getVersion.description = 'API version (unstable)'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function listMethods () {
|
||||
return getKeys(this.apiMethods)
|
||||
}
|
||||
listMethods.description = 'returns the name of all available API methods'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function methodSignature ({method: name}) {
|
||||
const method = this.apiMethods[name]
|
||||
|
||||
if (!method) {
|
||||
throw noSuchObject()
|
||||
}
|
||||
|
||||
// Return an array for compatibility with XML-RPC.
|
||||
return [
|
||||
// XML-RPC require the name of the method.
|
||||
{
|
||||
name,
|
||||
description: method.description,
|
||||
params: method.params || {},
|
||||
permission: method.permission
|
||||
}
|
||||
]
|
||||
}
|
||||
methodSignature.description = 'returns the signature of an API method'
|
||||
31
src/api/tag.js
Normal file
31
src/api/tag.js
Normal file
@@ -0,0 +1,31 @@
|
||||
export async function add ({tag, object}) {
|
||||
await this.getXapi(object).addTag(object._xapiId, tag)
|
||||
}
|
||||
|
||||
add.description = 'add a new tag to an object'
|
||||
|
||||
add.resolve = {
|
||||
object: ['id', null, 'administrate']
|
||||
}
|
||||
|
||||
add.params = {
|
||||
tag: { type: 'string' },
|
||||
id: { type: 'string' }
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function remove ({tag, object}) {
|
||||
await this.getXapi(object).removeTag(object._xapiId, tag)
|
||||
}
|
||||
|
||||
remove.description = 'remove an existing tag from an object'
|
||||
|
||||
remove.resolve = {
|
||||
object: ['id', null, 'administrate']
|
||||
}
|
||||
|
||||
remove.params = {
|
||||
tag: { type: 'string' },
|
||||
id: { type: 'string' }
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
export async function cancel ({task}) {
|
||||
await this.getXAPI(task).call('task.cancel', task.ref)
|
||||
await this.getXapi(task).call('task.cancel', task._xapiRef)
|
||||
}
|
||||
|
||||
cancel.params = {
|
||||
@@ -13,7 +13,7 @@ cancel.resolve = {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function destroy ({task}) {
|
||||
await this.getXAPI(task).call('task.destroy', task.ref)
|
||||
await this.getXapi(task).call('task.destroy', task._xapiRef)
|
||||
}
|
||||
|
||||
destroy.params = {
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
import {delay} from 'bluebird'
|
||||
export function getPermissionsForUser ({ userId }) {
|
||||
return this.getPermissionsForUser(userId)
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
getPermissionsForUser.permission = 'admin'
|
||||
|
||||
export function hasPermission ({userId, objectId, permission}) {
|
||||
return this.hasPermission(userId, objectId, permission)
|
||||
getPermissionsForUser.params = {
|
||||
userId: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function hasPermission ({ userId, objectId, permission }) {
|
||||
return this.hasPermissions(userId, [
|
||||
[ objectId, permission ]
|
||||
])
|
||||
}
|
||||
|
||||
hasPermission.permission = 'admin'
|
||||
@@ -23,7 +35,11 @@ hasPermission.params = {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function wait ({duration, returnValue}) {
|
||||
return delay(returnValue, +duration)
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve(returnValue)
|
||||
}, +duration)
|
||||
})
|
||||
}
|
||||
|
||||
wait.params = {
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
import {Unauthorized} from '../api-errors'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// TODO: Prevent token connections from creating tokens.
|
||||
// TODO: Token permission.
|
||||
export async function create () {
|
||||
// The user MUST not be signed with a token
|
||||
if (this.session.has('token_id')) {
|
||||
throw new Unauthorized()
|
||||
}
|
||||
|
||||
const userId = this.session.get('user_id')
|
||||
return (await this.createAuthenticationToken({userId})).id
|
||||
}
|
||||
@@ -19,6 +11,7 @@ create.permission = '' // sign in
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// TODO: an user should be able to delete its own tokens.
|
||||
async function delete_ ({token: id}) {
|
||||
await this.deleteAuthenticationToken(id)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import map from 'lodash.map'
|
||||
|
||||
import {InvalidParameters} from '../api-errors'
|
||||
import {invalidParameters} from 'xo-common/api-errors'
|
||||
import { getUserPublicProperties, mapToArray } from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@@ -15,7 +14,7 @@ create.permission = 'admin'
|
||||
create.params = {
|
||||
email: { type: 'string' },
|
||||
password: { type: 'string' },
|
||||
permission: { type: 'string', optional: true}
|
||||
permission: { type: 'string', optional: true }
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
@@ -23,7 +22,7 @@ create.params = {
|
||||
// Deletes an existing user.
|
||||
async function delete_ ({id}) {
|
||||
if (id === this.session.get('user_id')) {
|
||||
throw new InvalidParameters('an user cannot delete itself')
|
||||
throw invalidParameters('a user cannot delete itself')
|
||||
}
|
||||
|
||||
await this.deleteUser(id)
|
||||
@@ -46,10 +45,10 @@ delete_.params = {
|
||||
// collection.
|
||||
export async function getAll () {
|
||||
// Retrieves the users.
|
||||
const users = await this._users.get()
|
||||
const users = await this.getAllUsers()
|
||||
|
||||
// Filters out private properties.
|
||||
return map(users, this.getUserPublicProperties)
|
||||
return mapToArray(users, getUserPublicProperties)
|
||||
}
|
||||
|
||||
getAll.description = 'returns all the existing users'
|
||||
@@ -58,17 +57,43 @@ getAll.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function set ({id, email, password, permission}) {
|
||||
await this.updateUser(id, {email, password, permission})
|
||||
export async function set ({id, email, password, permission, preferences}) {
|
||||
const isAdmin = this.user && this.user.permission === 'admin'
|
||||
if (isAdmin) {
|
||||
if (permission && id === this.session.get('user_id')) {
|
||||
throw invalidParameters('a user cannot change its own permission')
|
||||
}
|
||||
} else if (email || password || permission) {
|
||||
throw invalidParameters('this properties can only changed by an administrator')
|
||||
}
|
||||
|
||||
await this.updateUser(id, {email, password, permission, preferences})
|
||||
}
|
||||
|
||||
set.description = 'changes the properties of an existing user'
|
||||
|
||||
set.permission = 'admin'
|
||||
set.permission = ''
|
||||
|
||||
set.params = {
|
||||
id: { type: 'string' },
|
||||
email: { type: 'string', optional: true },
|
||||
password: { type: 'string', optional: true },
|
||||
permission: { type: 'string', optional: true }
|
||||
permission: { type: 'string', optional: true },
|
||||
preferences: { type: 'object', optional: true }
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function changePassword ({oldPassword, newPassword}) {
|
||||
const id = this.session.get('user_id')
|
||||
await this.changeUserPassword(id, oldPassword, newPassword)
|
||||
}
|
||||
|
||||
changePassword.description = 'change password after checking old password (user function)'
|
||||
|
||||
changePassword.permission = ''
|
||||
|
||||
changePassword.params = {
|
||||
oldPassword: {type: 'string'},
|
||||
newPassword: {type: 'string'}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#=====================================================================
|
||||
|
||||
delete_ = $coroutine ({vbd}) ->
|
||||
xapi = @getXAPI vbd
|
||||
xapi = @getXapi vbd
|
||||
|
||||
# TODO: check if VBD is attached before
|
||||
yield xapi.call 'VBD.destroy', vbd.ref
|
||||
yield xapi.call 'VBD.destroy', vbd._xapiRef
|
||||
|
||||
return true
|
||||
|
||||
@@ -25,12 +25,9 @@ exports.delete = delete_
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
disconnect = $coroutine ({vbd}) ->
|
||||
xapi = @getXAPI vbd
|
||||
|
||||
# TODO: check if VBD is attached before
|
||||
yield xapi.call 'VBD.unplug_force', vbd.ref
|
||||
|
||||
return true
|
||||
xapi = @getXapi vbd
|
||||
yield xapi.disconnectVbd(vbd._xapiRef)
|
||||
return
|
||||
|
||||
disconnect.params = {
|
||||
id: { type: 'string' }
|
||||
@@ -45,12 +42,9 @@ exports.disconnect = disconnect
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
connect = $coroutine ({vbd}) ->
|
||||
xapi = @getXAPI vbd
|
||||
|
||||
# TODO: check if VBD is attached before
|
||||
yield xapi.call 'VBD.plug', vbd.ref
|
||||
|
||||
return true
|
||||
xapi = @getXapi vbd
|
||||
yield xapi.connectVbd(vbd._xapiRef)
|
||||
return
|
||||
|
||||
connect.params = {
|
||||
id: { type: 'string' }
|
||||
@@ -66,19 +60,19 @@ exports.connect = connect
|
||||
|
||||
set = $coroutine (params) ->
|
||||
{vbd} = params
|
||||
xapi = @getXAPI vbd
|
||||
xapi = @getXapi vbd
|
||||
|
||||
{ref} = vbd
|
||||
{ _xapiRef: ref } = vbd
|
||||
|
||||
# VBD position
|
||||
if 'position' of params
|
||||
yield xapi.call 'VBD.set_userdevice', ref, params.position
|
||||
yield xapi.call 'VBD.set_userdevice', ref, String(params.position)
|
||||
|
||||
set.params = {
|
||||
# Identifier of the VBD to update.
|
||||
id: { type: 'string' }
|
||||
|
||||
position: { type: 'string', optional: true }
|
||||
position: { type: ['string', 'number'], optional: true }
|
||||
|
||||
}
|
||||
|
||||
@@ -87,3 +81,29 @@ set.resolve = {
|
||||
}
|
||||
|
||||
exports.set = set
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
setBootable = $coroutine ({vbd, bootable}) ->
|
||||
xapi = @getXapi vbd
|
||||
{ _xapiRef: ref } = vbd
|
||||
|
||||
yield xapi.call 'VBD.set_bootable', ref, bootable
|
||||
return
|
||||
|
||||
setBootable.params = {
|
||||
vbd: { type: 'string' }
|
||||
bootable: { type: 'boolean' }
|
||||
}
|
||||
|
||||
setBootable.resolve = {
|
||||
vbd: ['vbd', 'VBD', 'administrate'],
|
||||
}
|
||||
|
||||
exports.setBootable = setBootable
|
||||
|
||||
#=====================================================================
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
})
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
# FIXME: rename to disk.*
|
||||
|
||||
$isArray = require 'lodash.isarray'
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
{coroutine: $coroutine} = require 'bluebird'
|
||||
|
||||
{format} = require 'json-rpc-peer'
|
||||
{invalidParameters} = require 'xo-common/api-errors'
|
||||
{isArray: $isArray, parseSize} = require '../utils'
|
||||
{JsonRpcError} = require 'json-rpc-peer'
|
||||
|
||||
#=====================================================================
|
||||
|
||||
delete_ = $coroutine ({vdi}) ->
|
||||
xapi = @getXAPI vdi
|
||||
yield @getXapi(vdi).deleteVdi(vdi._xapiId)
|
||||
|
||||
# TODO: check if VDI is attached before
|
||||
yield xapi.call 'VDI.destroy', vdi.ref
|
||||
|
||||
return true
|
||||
return
|
||||
|
||||
delete_.params = {
|
||||
id: { type: 'string' },
|
||||
}
|
||||
|
||||
delete_.resolve = {
|
||||
vdi: ['id', 'VDI', 'administrate'],
|
||||
vdi: ['id', ['VDI', 'VDI-snapshot'], 'administrate'],
|
||||
}
|
||||
|
||||
exports.delete = delete_
|
||||
@@ -31,21 +29,19 @@ exports.delete = delete_
|
||||
# FIXME: human readable strings should be handled.
|
||||
set = $coroutine (params) ->
|
||||
{vdi} = params
|
||||
xapi = @getXAPI vdi
|
||||
xapi = @getXapi vdi
|
||||
|
||||
{ref} = vdi
|
||||
{_xapiRef: ref} = vdi
|
||||
|
||||
# Size.
|
||||
if 'size' of params
|
||||
{size} = params
|
||||
size = parseSize(params.size)
|
||||
|
||||
if size < vdi.size
|
||||
@throw(
|
||||
'INVALID_SIZE'
|
||||
"cannot set new size below the current size (#{vdi.size})"
|
||||
throw invalidParameters(
|
||||
"cannot set new size (#{size}) below the current size (#{vdi.size})"
|
||||
)
|
||||
|
||||
yield xapi.call 'VDI.resize_online', ref, "#{size}"
|
||||
yield xapi.resizeVdi(ref, size)
|
||||
|
||||
# Other fields.
|
||||
for param, fields of {
|
||||
@@ -68,11 +64,11 @@ set.params = {
|
||||
name_description: { type: 'string', optional: true }
|
||||
|
||||
# size of VDI
|
||||
size: { type: 'integer', optional: true }
|
||||
size: { type: ['integer', 'string'], optional: true }
|
||||
}
|
||||
|
||||
set.resolve = {
|
||||
vdi: ['id', 'VDI', 'administrate'],
|
||||
vdi: ['id', ['VDI', 'VDI-snapshot'], 'administrate'],
|
||||
}
|
||||
|
||||
exports.set = set
|
||||
@@ -80,10 +76,9 @@ exports.set = set
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
migrate = $coroutine ({vdi, sr}) ->
|
||||
xapi = @getXAPI vdi
|
||||
xapi = @getXapi vdi
|
||||
|
||||
# TODO: check if VDI is attached before
|
||||
yield xapi.call 'VDI.pool_migrate', vdi.ref, sr.ref, {}
|
||||
yield xapi.moveVdi(vdi._xapiRef, sr._xapiRef)
|
||||
|
||||
return true
|
||||
|
||||
@@ -93,8 +88,14 @@ migrate.params = {
|
||||
}
|
||||
|
||||
migrate.resolve = {
|
||||
vdi: ['id', 'VDI', 'administrate'],
|
||||
vdi: ['id', ['VDI', 'VDI-snapshot'], 'administrate'],
|
||||
sr: ['sr_id', 'SR', 'administrate'],
|
||||
}
|
||||
|
||||
exports.migrate = migrate
|
||||
|
||||
#=====================================================================
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
})
|
||||
|
||||
108
src/api/vif.js
108
src/api/vif.js
@@ -1,6 +1,20 @@
|
||||
import {
|
||||
diffItems,
|
||||
noop,
|
||||
pCatch
|
||||
} from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// TODO: move into vm and rename to removeInterface
|
||||
async function delete_ ({vif}) {
|
||||
// TODO: check if VIF is attached before
|
||||
await this.getXAPI(vif).call('VIF.destroy', vif.ref)
|
||||
this.allocIpAddresses(
|
||||
vif.id,
|
||||
null,
|
||||
vif.allowedIpv4Addresses.concat(vif.allowedIpv6Addresses)
|
||||
)::pCatch(noop)
|
||||
|
||||
await this.getXapi(vif).deleteVif(vif._xapiId)
|
||||
}
|
||||
export {delete_ as delete}
|
||||
|
||||
@@ -14,9 +28,10 @@ delete_.resolve = {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// TODO: move into vm and rename to disconnectInterface
|
||||
export async function disconnect ({vif}) {
|
||||
// TODO: check if VIF is attached before
|
||||
await this.getXAPI(vif).call('VIF.unplug_force', vif.ref)
|
||||
await this.getXapi(vif).disconnectVif(vif._xapiId)
|
||||
}
|
||||
|
||||
disconnect.params = {
|
||||
@@ -28,10 +43,10 @@ disconnect.resolve = {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// TODO: move into vm and rename to connectInterface
|
||||
export async function connect ({vif}) {
|
||||
// TODO: check if VIF is attached before
|
||||
await this.getXAPI(vif).call('VIF.plug', vif.ref)
|
||||
await this.getXapi(vif).connectVif(vif._xapiId)
|
||||
}
|
||||
|
||||
connect.params = {
|
||||
@@ -41,3 +56,86 @@ connect.params = {
|
||||
connect.resolve = {
|
||||
vif: ['id', 'VIF', 'operate']
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function set ({
|
||||
vif,
|
||||
network,
|
||||
mac,
|
||||
allowedIpv4Addresses,
|
||||
allowedIpv6Addresses,
|
||||
attached
|
||||
}) {
|
||||
const oldIpAddresses = vif.allowedIpv4Addresses.concat(vif.allowedIpv6Addresses)
|
||||
const newIpAddresses = []
|
||||
{
|
||||
const { push } = newIpAddresses
|
||||
push.apply(newIpAddresses, allowedIpv4Addresses || vif.allowedIpv4Addresses)
|
||||
push.apply(newIpAddresses, allowedIpv6Addresses || vif.allowedIpv6Addresses)
|
||||
}
|
||||
|
||||
if (network || mac) {
|
||||
const xapi = this.getXapi(vif)
|
||||
|
||||
const vm = xapi.getObject(vif.$VM)
|
||||
mac == null && (mac = vif.MAC)
|
||||
network = xapi.getObject((network && network.id) || vif.$network)
|
||||
attached == null && (attached = vif.attached)
|
||||
|
||||
await this.allocIpAddresses(vif.id, null, oldIpAddresses)
|
||||
await xapi.deleteVif(vif._xapiId)
|
||||
|
||||
// create new VIF with new parameters
|
||||
const newVif = await xapi.createVif(vm.$id, network.$id, {
|
||||
mac,
|
||||
currently_attached: attached,
|
||||
ipv4_allowed: newIpAddresses
|
||||
})
|
||||
|
||||
await this.allocIpAddresses(newVif.$id, newIpAddresses)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const [ addAddresses, removeAddresses ] = diffItems(
|
||||
newIpAddresses,
|
||||
oldIpAddresses
|
||||
)
|
||||
await this.allocIpAddresses(
|
||||
vif.id,
|
||||
addAddresses,
|
||||
removeAddresses
|
||||
)
|
||||
|
||||
return this.getXapi(vif).editVif(vif._xapiId, {
|
||||
ipv4Allowed: allowedIpv4Addresses,
|
||||
ipv6Allowed: allowedIpv6Addresses
|
||||
})
|
||||
}
|
||||
|
||||
set.params = {
|
||||
id: { type: 'string' },
|
||||
network: { type: 'string', optional: true },
|
||||
mac: { type: 'string', optional: true },
|
||||
allowedIpv4Addresses: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
},
|
||||
allowedIpv6Addresses: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
},
|
||||
attached: { type: 'boolean', optional: true }
|
||||
}
|
||||
|
||||
set.resolve = {
|
||||
vif: ['id', 'VIF', 'operate'],
|
||||
network: ['network', 'network', 'operate']
|
||||
}
|
||||
|
||||
1461
src/api/vm.coffee
1461
src/api/vm.coffee
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,50 @@
|
||||
import { streamToBuffer } from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export function clean () {
|
||||
return this.clean()
|
||||
}
|
||||
|
||||
clean.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function exportConfig () {
|
||||
return {
|
||||
$getFrom: await this.registerHttpRequest((req, res) => {
|
||||
res.writeHead(200, 'OK', {
|
||||
'content-disposition': 'attachment'
|
||||
})
|
||||
|
||||
return this.exportConfig()
|
||||
},
|
||||
undefined,
|
||||
{ suffix: '/config.json' })
|
||||
}
|
||||
}
|
||||
|
||||
exportConfig.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function getAllObjects () {
|
||||
return this.getObjects()
|
||||
}
|
||||
|
||||
getAllObjects.permission = ''
|
||||
getAllObjects.description = 'Returns all XO objects'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function importConfig () {
|
||||
return {
|
||||
$sendTo: await this.registerHttpRequest(async (req, res) => {
|
||||
await this.importConfig(JSON.parse(await streamToBuffer(req)))
|
||||
|
||||
res.end('config successfully imported')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
importConfig.permission = 'admin'
|
||||
|
||||
478
src/api/xosan.js
Normal file
478
src/api/xosan.js
Normal file
@@ -0,0 +1,478 @@
|
||||
import arp from 'arp-a'
|
||||
import createLogger from 'debug'
|
||||
import defer from 'golike-defer'
|
||||
import execa from 'execa'
|
||||
import fromPairs from 'lodash/fromPairs'
|
||||
import fs from 'fs-promise'
|
||||
import map from 'lodash/map'
|
||||
import splitLines from 'split-lines'
|
||||
import {
|
||||
filter,
|
||||
includes
|
||||
} from 'lodash'
|
||||
|
||||
import {
|
||||
noop,
|
||||
pCatch,
|
||||
pFromCallback,
|
||||
splitFirst
|
||||
} from '../utils'
|
||||
|
||||
const debug = createLogger('xo:xosan')
|
||||
|
||||
const SSH_KEY_FILE = 'id_rsa_xosan'
|
||||
const NETWORK_PREFIX = '172.31.100.'
|
||||
|
||||
const XOSAN_VM_SYSTEM_DISK_SIZE = 10 * 1024 * 1024 * 1024
|
||||
const XOSAN_DATA_DISK_USEAGE_RATIO = 0.99
|
||||
const XOSAN_MAX_DISK_SIZE = 2093050 * 1024 * 1024 // a bit under 2To
|
||||
|
||||
const CURRENTLY_CREATING_SRS = {}
|
||||
|
||||
export async function getVolumeInfo ({ sr }) {
|
||||
const xapi = this.getXapi(sr)
|
||||
const giantIPtoVMDict = {}
|
||||
const data = xapi.xo.getData(sr, 'xosan_config')
|
||||
if (!data || !data.nodes) {
|
||||
return null
|
||||
}
|
||||
const nodes = data.nodes
|
||||
nodes.forEach(conf => {
|
||||
giantIPtoVMDict[conf.vm.ip] = xapi.getObject(conf.vm.id)
|
||||
})
|
||||
const oneHostAndVm = nodes[0]
|
||||
const resultCmd = await remoteSsh(xapi, {
|
||||
host: xapi.getObject(oneHostAndVm.host),
|
||||
address: oneHostAndVm.vm.ip
|
||||
}, 'gluster volume info xosan')
|
||||
const result = resultCmd['stdout']
|
||||
|
||||
/*
|
||||
Volume Name: xosan
|
||||
Type: Disperse
|
||||
Volume ID: 1d4d0e57-8b6b-43f9-9d40-c48be1df7548
|
||||
Status: Started
|
||||
Snapshot Count: 0
|
||||
Number of Bricks: 1 x (2 + 1) = 3
|
||||
Transport-type: tcp
|
||||
Bricks:
|
||||
Brick1: 192.168.0.201:/bricks/brick1/xosan1
|
||||
Brick2: 192.168.0.202:/bricks/brick1/xosan1
|
||||
Brick3: 192.168.0.203:/bricks/brick1/xosan1
|
||||
Options Reconfigured:
|
||||
client.event-threads: 16
|
||||
server.event-threads: 16
|
||||
performance.client-io-threads: on
|
||||
nfs.disable: on
|
||||
performance.readdir-ahead: on
|
||||
transport.address-family: inet
|
||||
features.shard: on
|
||||
features.shard-block-size: 64MB
|
||||
network.remote-dio: enable
|
||||
cluster.eager-lock: enable
|
||||
performance.io-cache: off
|
||||
performance.read-ahead: off
|
||||
performance.quick-read: off
|
||||
performance.stat-prefetch: on
|
||||
performance.strict-write-ordering: off
|
||||
cluster.server-quorum-type: server
|
||||
cluster.quorum-type: auto
|
||||
*/
|
||||
const info = fromPairs(
|
||||
splitLines(result.trim()).map(line =>
|
||||
splitFirst(line, ':').map(val => val.trim())
|
||||
)
|
||||
)
|
||||
|
||||
const getNumber = item => +item.substr(5)
|
||||
const brickKeys = filter(Object.keys(info), key => key.match(/^Brick[1-9]/)).sort((i1, i2) => getNumber(i1) - getNumber(i2))
|
||||
|
||||
// expected brickKeys : [ 'Brick1', 'Brick2', 'Brick3' ]
|
||||
info['Bricks'] = brickKeys.map(key => {
|
||||
const ip = info[key].split(':')[0]
|
||||
return { config: info[key], ip: ip, vm: giantIPtoVMDict[ip] }
|
||||
})
|
||||
const entry = await pFromCallback(cb => arp.table(cb))
|
||||
if (entry) {
|
||||
const brick = info['Bricks'].find(element => element.config.split(':')[0] === entry.ip)
|
||||
if (brick) {
|
||||
brick.mac = entry.mac
|
||||
}
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
getVolumeInfo.description = 'info on gluster volume'
|
||||
getVolumeInfo.permission = 'admin'
|
||||
|
||||
getVolumeInfo.params = {
|
||||
sr: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
getVolumeInfo.resolve = {
|
||||
sr: ['sr', 'SR', 'administrate']
|
||||
}
|
||||
function floor2048 (value) {
|
||||
return 2048 * Math.floor(value / 2048)
|
||||
}
|
||||
|
||||
async function copyVm (xapi, originalVm, params) {
|
||||
return { vm: await xapi.copyVm(originalVm, params.sr), params }
|
||||
}
|
||||
|
||||
async function prepareGlusterVm (xapi, vmAndParam, xosanNetwork, increaseDataDisk = true) {
|
||||
let vm = vmAndParam.vm
|
||||
// refresh the object so that sizes are correct
|
||||
const params = vmAndParam.params
|
||||
const ip = params.xenstore_data['vm-data/ip']
|
||||
const sr = xapi.getObject(params.sr.$id)
|
||||
await xapi._waitObjectState(sr.$id, sr => Boolean(sr.$PBDs))
|
||||
const host = sr.$PBDs[0].$host
|
||||
const firstVif = vm.$VIFs[0]
|
||||
if (xosanNetwork.$id !== firstVif.$network.$id) {
|
||||
await xapi.call('VIF.move', firstVif.$ref, xosanNetwork.$ref)
|
||||
}
|
||||
await xapi.editVm(vm, {
|
||||
name_label: params.name_label,
|
||||
name_description: params.name_description
|
||||
})
|
||||
await xapi.call('VM.set_xenstore_data', vm.$ref, params.xenstore_data)
|
||||
if (increaseDataDisk) {
|
||||
const dataDisk = vm.$VBDs.map(vbd => vbd.$VDI).find(vdi => vdi && vdi.name_label === 'xosan_data')
|
||||
const srFreeSpace = sr.physical_size - sr.physical_utilisation
|
||||
// we use a percentage because it looks like the VDI overhead is proportional
|
||||
const newSize = floor2048((srFreeSpace + dataDisk.virtual_size) * XOSAN_DATA_DISK_USEAGE_RATIO)
|
||||
await xapi._resizeVdi(dataDisk, Math.min(newSize, XOSAN_MAX_DISK_SIZE))
|
||||
}
|
||||
await xapi.startVm(vm)
|
||||
debug('waiting for boot of ', ip)
|
||||
// wait until we find the assigned IP in the networks, we are just checking the boot is complete
|
||||
const vmIsUp = vm => Boolean(vm.$guest_metrics && includes(vm.$guest_metrics.networks, ip))
|
||||
vm = await xapi._waitObjectState(vm.$id, vmIsUp)
|
||||
debug('booted ', ip)
|
||||
return { address: ip, host, vm }
|
||||
}
|
||||
|
||||
async function callPlugin (xapi, host, command, params) {
|
||||
debug('calling plugin', host.address, command)
|
||||
return JSON.parse(await xapi.call('host.call_plugin', host.$ref, 'xosan.py', command, params))
|
||||
}
|
||||
|
||||
async function remoteSsh (xapi, hostAndAddress, cmd) {
|
||||
const result = await callPlugin(xapi, hostAndAddress.host, 'run_ssh', {
|
||||
destination: 'root@' + hostAndAddress.address,
|
||||
cmd: cmd
|
||||
})
|
||||
if (result.exit !== 0) {
|
||||
throw new Error('ssh error: ' + JSON.stringify(result))
|
||||
}
|
||||
debug(result)
|
||||
return result
|
||||
}
|
||||
|
||||
async function setPifIp (xapi, pif, address) {
|
||||
await xapi.call('PIF.reconfigure_ip', pif.$ref, 'Static', address, '255.255.255.0', NETWORK_PREFIX + '1', '')
|
||||
}
|
||||
|
||||
const createNetworkAndInsertHosts = defer.onFailure(async function ($onFailure, xapi, pif, vlan) {
|
||||
let hostIpLastNumber = 1
|
||||
const xosanNetwork = await xapi.createNetwork({
|
||||
name: 'XOSAN network',
|
||||
description: 'XOSAN network',
|
||||
pifId: pif._xapiId,
|
||||
mtu: 9000,
|
||||
vlan: +vlan
|
||||
})
|
||||
$onFailure(() => xapi.deleteNetwork(xosanNetwork)::pCatch(noop))
|
||||
await Promise.all(xosanNetwork.$PIFs.map(pif => setPifIp(xapi, pif, NETWORK_PREFIX + (hostIpLastNumber++))))
|
||||
|
||||
return xosanNetwork
|
||||
})
|
||||
async function getOrCreateSshKey (xapi) {
|
||||
let sshKey = xapi.xo.getData(xapi.pool, 'xosan_ssh_key')
|
||||
|
||||
if (!sshKey) {
|
||||
const readKeys = async () => {
|
||||
sshKey = {
|
||||
private: await fs.readFile(SSH_KEY_FILE, 'ascii'),
|
||||
public: await fs.readFile(SSH_KEY_FILE + '.pub', 'ascii')
|
||||
}
|
||||
xapi.xo.setData(xapi.pool, 'xosan_ssh_key', sshKey)
|
||||
}
|
||||
|
||||
try {
|
||||
await readKeys()
|
||||
} catch (e) {
|
||||
await execa('ssh-keygen', ['-q', '-f', SSH_KEY_FILE, '-t', 'rsa', '-b', '4096', '-N', ''])
|
||||
await readKeys()
|
||||
}
|
||||
}
|
||||
|
||||
return sshKey
|
||||
}
|
||||
async function configureGluster (redundancy, ipAndHosts, xapi, firstIpAndHost, glusterType, arbiter = null) {
|
||||
const configByType = {
|
||||
replica_arbiter: {
|
||||
creation: 'replica 3 arbiter 1',
|
||||
extra: []
|
||||
},
|
||||
replica: {
|
||||
creation: 'replica ' + redundancy + ' ',
|
||||
extra: ['gluster volume set xosan cluster.data-self-heal on']
|
||||
},
|
||||
disperse: {
|
||||
creation: 'disperse ' + ipAndHosts.length + ' redundancy ' + redundancy + ' ',
|
||||
extra: []
|
||||
}
|
||||
}
|
||||
let brickVms = arbiter ? ipAndHosts.concat(arbiter) : ipAndHosts
|
||||
for (let i = 1; i < brickVms.length; i++) {
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster peer probe ' + brickVms[i].address)
|
||||
}
|
||||
const creation = configByType[glusterType].creation
|
||||
const volumeCreation = 'gluster volume create xosan ' + creation +
|
||||
' ' + brickVms.map(ipAndHost => (ipAndHost.address + ':/bricks/xosan/xosandir')).join(' ')
|
||||
debug('creating volume: ', volumeCreation)
|
||||
await remoteSsh(xapi, firstIpAndHost, volumeCreation)
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan network.remote-dio enable')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan cluster.eager-lock enable')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan performance.io-cache off')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan performance.read-ahead off')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan performance.quick-read off')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan performance.strict-write-ordering off')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan client.event-threads 8')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan server.event-threads 8')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan performance.io-thread-count 64')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan performance.stat-prefetch on')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan features.shard on')
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume set xosan features.shard-block-size 512MB')
|
||||
for (const confChunk of configByType[glusterType].extra) {
|
||||
await remoteSsh(xapi, firstIpAndHost, confChunk)
|
||||
}
|
||||
await remoteSsh(xapi, firstIpAndHost, 'gluster volume start xosan')
|
||||
}
|
||||
|
||||
export const createSR = defer.onFailure(async function ($onFailure, { template, pif, vlan, srs, glusterType, redundancy }) {
|
||||
if (!this.requestResource) {
|
||||
throw new Error('requestResource is not a function')
|
||||
}
|
||||
|
||||
if (srs.length < 1) {
|
||||
return // TODO: throw an error
|
||||
}
|
||||
|
||||
let vmIpLastNumber = 101
|
||||
const xapi = this.getXapi(srs[0])
|
||||
if (CURRENTLY_CREATING_SRS[xapi.pool.$id]) {
|
||||
throw new Error('createSR is already running for this pool')
|
||||
}
|
||||
|
||||
CURRENTLY_CREATING_SRS[xapi.pool.$id] = true
|
||||
try {
|
||||
const xosanNetwork = await createNetworkAndInsertHosts(xapi, pif, vlan)
|
||||
$onFailure(() => xapi.deleteNetwork(xosanNetwork)::pCatch(noop))
|
||||
const sshKey = await getOrCreateSshKey(xapi)
|
||||
const srsObjects = map(srs, srId => xapi.getObject(srId))
|
||||
|
||||
const vmParameters = map(srs, srId => {
|
||||
const sr = xapi.getObject(srId)
|
||||
const host = sr.$PBDs[0].$host
|
||||
return {
|
||||
sr,
|
||||
host,
|
||||
name_label: `XOSAN - ${sr.name_label} - ${host.name_label}`,
|
||||
name_description: 'Xosan VM storing data on volume ' + sr.name_label,
|
||||
// the values of the xenstore_data object *have* to be string, don't forget.
|
||||
xenstore_data: {
|
||||
'vm-data/hostname': 'XOSAN' + sr.name_label,
|
||||
'vm-data/sshkey': sshKey.public,
|
||||
'vm-data/ip': NETWORK_PREFIX + (vmIpLastNumber++),
|
||||
'vm-data/mtu': String(xosanNetwork.MTU),
|
||||
'vm-data/vlan': String(vlan)
|
||||
}
|
||||
}
|
||||
})
|
||||
await Promise.all(vmParameters.map(vmParam => callPlugin(xapi, vmParam.host, 'receive_ssh_keys', {
|
||||
private_key: sshKey.private,
|
||||
public_key: sshKey.public,
|
||||
force: 'true'
|
||||
})))
|
||||
|
||||
const firstVM = await xapi.importVm(
|
||||
await this.requestResource('xosan', template.id, template.version),
|
||||
{ srId: vmParameters[0].sr.$ref, type: 'xva' }
|
||||
)
|
||||
$onFailure(() => xapi.deleteVm(firstVM, true)::pCatch(noop))
|
||||
await xapi.editVm(firstVM, {
|
||||
autoPoweron: true
|
||||
})
|
||||
const copiedVms = await Promise.all(vmParameters.slice(1).map(param => copyVm(xapi, firstVM, param)))
|
||||
// TODO: Promise.all() is certainly not the right operation to execute all the given promises whether they fulfill or reject.
|
||||
$onFailure(() => Promise.all(copiedVms.map(vm => xapi.deleteVm(vm.vm, true)))::pCatch(noop))
|
||||
const vmsAndParams = [{
|
||||
vm: firstVM,
|
||||
params: vmParameters[0]
|
||||
}].concat(copiedVms)
|
||||
let arbiter = null
|
||||
if (srs.length === 2) {
|
||||
const sr = vmParameters[0].sr
|
||||
const arbiterConfig = {
|
||||
sr: sr,
|
||||
host: vmParameters[0].host,
|
||||
name_label: vmParameters[0].name_label + ' arbiter',
|
||||
name_description: 'Xosan VM storing data on volume ' + sr.name_label,
|
||||
xenstore_data: {
|
||||
'vm-data/hostname': 'XOSAN' + sr.name_label + '_arb',
|
||||
'vm-data/sshkey': sshKey.public,
|
||||
'vm-data/ip': NETWORK_PREFIX + (vmIpLastNumber++),
|
||||
'vm-data/mtu': String(xosanNetwork.MTU),
|
||||
'vm-data/vlan': String(vlan)
|
||||
}
|
||||
}
|
||||
const arbiterVm = await copyVm(xapi, firstVM, arbiterConfig)
|
||||
$onFailure(() => xapi.deleteVm(arbiterVm.vm, true)::pCatch(noop))
|
||||
arbiter = await prepareGlusterVm(xapi, arbiterVm, xosanNetwork, false)
|
||||
}
|
||||
const ipAndHosts = await Promise.all(map(vmsAndParams, vmAndParam => prepareGlusterVm(xapi, vmAndParam, xosanNetwork)))
|
||||
const firstIpAndHost = ipAndHosts[0]
|
||||
await configureGluster(redundancy, ipAndHosts, xapi, firstIpAndHost, glusterType, arbiter)
|
||||
debug('xosan gluster volume started')
|
||||
const config = { server: firstIpAndHost.address + ':/xosan', backupserver: ipAndHosts[1].address }
|
||||
const xosanSr = await xapi.call('SR.create', srsObjects[0].$PBDs[0].$host.$ref, config, 0, 'XOSAN', 'XOSAN', 'xosan', '', true, {})
|
||||
if (arbiter) {
|
||||
ipAndHosts.push(arbiter)
|
||||
}
|
||||
// we just forget because the cleanup actions will be executed before.
|
||||
$onFailure(() => xapi.forgetSr(xosanSr)::pCatch(noop))
|
||||
await xapi.xo.setData(xosanSr, 'xosan_config', {
|
||||
nodes: ipAndHosts.map(param => ({
|
||||
host: param.host.$id,
|
||||
vm: { id: param.vm.$id, ip: param.address }
|
||||
})),
|
||||
network: xosanNetwork.$id
|
||||
})
|
||||
} finally {
|
||||
delete CURRENTLY_CREATING_SRS[xapi.pool.$id]
|
||||
}
|
||||
})
|
||||
|
||||
createSR.description = 'create gluster VM'
|
||||
createSR.permission = 'admin'
|
||||
createSR.params = {
|
||||
srs: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
pif: {
|
||||
type: 'string'
|
||||
},
|
||||
vlan: {
|
||||
type: 'string'
|
||||
},
|
||||
glusterType: {
|
||||
type: 'string'
|
||||
},
|
||||
redundancy: {
|
||||
type: 'number'
|
||||
}
|
||||
}
|
||||
|
||||
createSR.resolve = {
|
||||
srs: ['sr', 'SR', 'administrate'],
|
||||
pif: ['pif', 'PIF', 'administrate']
|
||||
}
|
||||
|
||||
export function checkSrIsBusy ({ poolId }) {
|
||||
return !!CURRENTLY_CREATING_SRS[poolId]
|
||||
}
|
||||
checkSrIsBusy.description = 'checks if there is a xosan SR curently being created on the given pool id'
|
||||
checkSrIsBusy.permission = 'admin'
|
||||
checkSrIsBusy.params = { poolId: { type: 'string' } }
|
||||
|
||||
const POSSIBLE_CONFIGURATIONS = {}
|
||||
POSSIBLE_CONFIGURATIONS[2] = [{ layout: 'replica_arbiter', redundancy: 3, capacity: 1 }]
|
||||
POSSIBLE_CONFIGURATIONS[3] = [
|
||||
{ layout: 'disperse', redundancy: 1, capacity: 2 },
|
||||
{ layout: 'replica', redundancy: 3, capacity: 1 }]
|
||||
POSSIBLE_CONFIGURATIONS[4] = [{ layout: 'replica', redundancy: 2, capacity: 1 }]
|
||||
POSSIBLE_CONFIGURATIONS[5] = [{ layout: 'disperse', redundancy: 1, capacity: 4 }]
|
||||
POSSIBLE_CONFIGURATIONS[6] = [
|
||||
{ layout: 'disperse', redundancy: 2, capacity: 4 },
|
||||
{ layout: 'replica', redundancy: 2, capacity: 3 },
|
||||
{ layout: 'replica', redundancy: 3, capacity: 2 }]
|
||||
POSSIBLE_CONFIGURATIONS[7] = [{ layout: 'disperse', redundancy: 3, capacity: 4 }]
|
||||
POSSIBLE_CONFIGURATIONS[8] = [{ layout: 'replica', redundancy: 2, capacity: 4 }]
|
||||
POSSIBLE_CONFIGURATIONS[9] = [
|
||||
{ layout: 'disperse', redundancy: 1, capacity: 8 },
|
||||
{ layout: 'replica', redundancy: 3, capacity: 3 }]
|
||||
POSSIBLE_CONFIGURATIONS[10] = [
|
||||
{ layout: 'disperse', redundancy: 2, capacity: 8 },
|
||||
{ layout: 'replica', redundancy: 2, capacity: 5 }]
|
||||
POSSIBLE_CONFIGURATIONS[11] = [{ layout: 'disperse', redundancy: 3, capacity: 8 }]
|
||||
POSSIBLE_CONFIGURATIONS[12] = [
|
||||
{ layout: 'disperse', redundancy: 4, capacity: 8 },
|
||||
{ layout: 'replica', redundancy: 2, capacity: 6 }]
|
||||
POSSIBLE_CONFIGURATIONS[13] = [{ layout: 'disperse', redundancy: 5, capacity: 8 }]
|
||||
POSSIBLE_CONFIGURATIONS[14] = [
|
||||
{ layout: 'disperse', redundancy: 6, capacity: 8 },
|
||||
{ layout: 'replica', redundancy: 2, capacity: 7 }]
|
||||
POSSIBLE_CONFIGURATIONS[15] = [
|
||||
{ layout: 'disperse', redundancy: 7, capacity: 8 },
|
||||
{ layout: 'replica', redundancy: 3, capacity: 5 }]
|
||||
POSSIBLE_CONFIGURATIONS[16] = [{ layout: 'replica', redundancy: 2, capacity: 8 }]
|
||||
|
||||
export async function computeXosanPossibleOptions ({ lvmSrs }) {
|
||||
const count = lvmSrs.length
|
||||
const configurations = POSSIBLE_CONFIGURATIONS[count]
|
||||
if (!configurations) {
|
||||
return null
|
||||
}
|
||||
if (count > 0) {
|
||||
const xapi = this.getXapi(lvmSrs[0])
|
||||
const srs = map(lvmSrs, srId => xapi.getObject(srId))
|
||||
const srSizes = map(srs, sr => sr.physical_size - sr.physical_utilisation)
|
||||
const minSize = Math.min.apply(null, srSizes)
|
||||
const brickSize = (minSize - XOSAN_VM_SYSTEM_DISK_SIZE) * XOSAN_DATA_DISK_USEAGE_RATIO
|
||||
return configurations.map(conf => ({ ...conf, availableSpace: brickSize * conf.capacity }))
|
||||
}
|
||||
}
|
||||
|
||||
computeXosanPossibleOptions.params = {
|
||||
lvmSrs: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
export async function downloadAndInstallXosanPack ({ id, version, pool }) {
|
||||
if (!this.requestResource) {
|
||||
throw new Error('requestResource is not a function')
|
||||
}
|
||||
|
||||
const xapi = this.getXapi(pool.id)
|
||||
const res = await this.requestResource('xosan', id, version)
|
||||
|
||||
return xapi.installSupplementalPackOnAllHosts(res)
|
||||
}
|
||||
|
||||
downloadAndInstallXosanPack.description = 'Register a resource via cloud plugin'
|
||||
|
||||
downloadAndInstallXosanPack.params = {
|
||||
id: { type: 'string' },
|
||||
version: { type: 'string' },
|
||||
pool: { type: 'string' }
|
||||
}
|
||||
|
||||
downloadAndInstallXosanPack.resolve = {
|
||||
pool: ['pool', 'pool', 'administrate']
|
||||
}
|
||||
|
||||
downloadAndInstallXosanPack.permission = 'admin'
|
||||
@@ -1,15 +1,16 @@
|
||||
import Bluebird from 'bluebird'
|
||||
import isArray from 'lodash.isarray'
|
||||
import isObject from 'lodash.isobject'
|
||||
import Model from './model'
|
||||
import {BaseError} from 'make-error'
|
||||
import {EventEmitter} from 'events'
|
||||
import {mapInPlace} from './utils'
|
||||
import {
|
||||
isArray,
|
||||
isObject,
|
||||
map
|
||||
} from './utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export class ModelAlreadyExists extends BaseError {
|
||||
constructor (id) {
|
||||
constructor (id) {
|
||||
super('this model already exists: ' + id)
|
||||
}
|
||||
}
|
||||
@@ -32,19 +33,14 @@ export default class Collection extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
constructor () {
|
||||
super()
|
||||
}
|
||||
|
||||
add (models, opts) {
|
||||
async add (models, opts) {
|
||||
const array = isArray(models)
|
||||
if (!array) {
|
||||
models = [models]
|
||||
|
||||
}
|
||||
|
||||
const {Model} = this
|
||||
mapInPlace(models, model => {
|
||||
map(models, model => {
|
||||
if (!(model instanceof Model)) {
|
||||
model = new Model(model)
|
||||
}
|
||||
@@ -56,56 +52,56 @@ export default class Collection extends EventEmitter {
|
||||
}
|
||||
|
||||
return model.properties
|
||||
})
|
||||
}, models)
|
||||
|
||||
return Bluebird.try(this._add, [models, opts], this).then(models => {
|
||||
this.emit('add', models)
|
||||
models = await this._add(models, opts)
|
||||
this.emit('add', models)
|
||||
|
||||
return array ? models : new this.Model(models[0])
|
||||
})
|
||||
return array
|
||||
? models
|
||||
: new this.Model(models[0])
|
||||
}
|
||||
|
||||
first (properties) {
|
||||
async first (properties) {
|
||||
if (!isObject(properties)) {
|
||||
properties = (properties !== undefined) ?
|
||||
{ id: properties } :
|
||||
{}
|
||||
properties = (properties !== undefined)
|
||||
? { id: properties }
|
||||
: {}
|
||||
}
|
||||
|
||||
return Bluebird.try(this._first, [properties], this).then(
|
||||
model => model && new this.Model(model)
|
||||
)
|
||||
const model = await this._first(properties)
|
||||
return model && new this.Model(model)
|
||||
}
|
||||
|
||||
get (properties) {
|
||||
async get (properties) {
|
||||
if (!isObject(properties)) {
|
||||
properties = (properties !== undefined) ?
|
||||
{ id: properties } :
|
||||
{}
|
||||
properties = (properties !== undefined)
|
||||
? { id: properties }
|
||||
: {}
|
||||
}
|
||||
|
||||
return Bluebird.try(this._get, [properties], this)
|
||||
return /* await */ this._get(properties)
|
||||
}
|
||||
|
||||
remove (ids) {
|
||||
async remove (ids) {
|
||||
if (!isArray(ids)) {
|
||||
ids = [ids]
|
||||
}
|
||||
|
||||
return Bluebird.try(this._remove, [ids], this).then(() => {
|
||||
this.emit('remove', ids)
|
||||
return true
|
||||
})
|
||||
await this._remove(ids)
|
||||
|
||||
this.emit('remove', ids)
|
||||
return true
|
||||
}
|
||||
|
||||
update (models) {
|
||||
async update (models) {
|
||||
const array = isArray(models)
|
||||
if (!isArray(models)) {
|
||||
models = [models]
|
||||
}
|
||||
|
||||
const {Model} = this
|
||||
mapInPlace(models, model => {
|
||||
map(models, model => {
|
||||
if (!(model instanceof Model)) {
|
||||
// TODO: Problems, we may be mixing in some default
|
||||
// properties which will overwrite existing ones.
|
||||
@@ -127,13 +123,14 @@ export default class Collection extends EventEmitter {
|
||||
}
|
||||
|
||||
return model.properties
|
||||
})
|
||||
}, models)
|
||||
|
||||
return Bluebird.try(this._update, [models], this).then(models => {
|
||||
this.emit('update', models)
|
||||
models = await this._update(models)
|
||||
this.emit('update', models)
|
||||
|
||||
return array ? models : new this.Model(models[0])
|
||||
})
|
||||
return array
|
||||
? models
|
||||
: new this.Model(models[0])
|
||||
}
|
||||
|
||||
// Methods to override in implementations.
|
||||
@@ -165,9 +162,11 @@ export default class Collection extends EventEmitter {
|
||||
return this.first(properties).then(model => model != null)
|
||||
}
|
||||
|
||||
_first (properties) {
|
||||
return Bluebird.try(this.get, [properties], this).then(
|
||||
models => models.length ? models[0] : null
|
||||
)
|
||||
async _first (properties) {
|
||||
const models = await this.get(properties)
|
||||
|
||||
return models.length
|
||||
? models[0]
|
||||
: null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import Bluebird, {coroutine} from 'bluebird'
|
||||
import Collection, {ModelAlreadyExists} from '../collection'
|
||||
import difference from 'lodash.difference'
|
||||
import filter from 'lodash.filter'
|
||||
import forEach from 'lodash.foreach'
|
||||
import getKey from 'lodash.keys'
|
||||
import isEmpty from 'lodash.isempty'
|
||||
import map from 'lodash.map'
|
||||
import thenRedis from 'then-redis'
|
||||
import difference from 'lodash/difference'
|
||||
import filter from 'lodash/filter'
|
||||
import getKey from 'lodash/keys'
|
||||
import {createClient as createRedisClient} from 'redis'
|
||||
import {v4 as generateUuid} from 'uuid'
|
||||
|
||||
import {
|
||||
forEach,
|
||||
isEmpty,
|
||||
mapToArray,
|
||||
promisifyAll
|
||||
} from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////
|
||||
// Data model:
|
||||
@@ -30,13 +36,13 @@ export default class Redis extends Collection {
|
||||
connection,
|
||||
indexes = [],
|
||||
prefix,
|
||||
uri = 'tcp://localhost:6379',
|
||||
uri
|
||||
}) {
|
||||
super()
|
||||
|
||||
this.indexes = indexes
|
||||
this.prefix = prefix
|
||||
this.redis = connection || thenRedis.createClient(uri)
|
||||
this.redis = promisifyAll(connection || createRedisClient(uri))
|
||||
}
|
||||
|
||||
_extract (ids) {
|
||||
@@ -44,7 +50,7 @@ export default class Redis extends Collection {
|
||||
const {redis} = this
|
||||
|
||||
const models = []
|
||||
return Bluebird.map(ids, id => {
|
||||
return Promise.all(mapToArray(ids, id => {
|
||||
return redis.hgetall(prefix + id).then(model => {
|
||||
// If empty, consider it a no match.
|
||||
if (isEmpty(model)) {
|
||||
@@ -56,22 +62,22 @@ export default class Redis extends Collection {
|
||||
|
||||
models.push(model)
|
||||
})
|
||||
}).return(models)
|
||||
})).then(() => models)
|
||||
}
|
||||
|
||||
_add (models, {replace = false} = {}) {
|
||||
// TODO: remove “replace” which is a temporary measure, implement
|
||||
// “set()” instead.
|
||||
|
||||
const {indexes, prefix, redis, idPrefix = ''} = this
|
||||
const {indexes, prefix, redis} = this
|
||||
|
||||
return Bluebird.map(models, coroutine(function * (model) {
|
||||
return Promise.all(mapToArray(models, async model => {
|
||||
// Generate a new identifier if necessary.
|
||||
if (model.id === undefined) {
|
||||
model.id = idPrefix + String(yield redis.incr(prefix + '_id'))
|
||||
model.id = generateUuid()
|
||||
}
|
||||
|
||||
const success = yield redis.sadd(prefix + '_ids', model.id)
|
||||
const success = await redis.sadd(prefix + '_ids', model.id)
|
||||
|
||||
// The entry already exists an we are not in replace mode.
|
||||
if (!success && !replace) {
|
||||
@@ -90,8 +96,10 @@ export default class Redis extends Collection {
|
||||
params.push(name, value)
|
||||
})
|
||||
|
||||
const key = `${prefix}:${model.id}`
|
||||
const promises = [
|
||||
redis.hmset(prefix + ':' + model.id, ...params)
|
||||
redis.del(key),
|
||||
redis.hmset(key, ...params)
|
||||
]
|
||||
|
||||
// Update indexes.
|
||||
@@ -105,7 +113,7 @@ export default class Redis extends Collection {
|
||||
promises.push(redis.sadd(key, model.id))
|
||||
})
|
||||
|
||||
yield Bluebird.all(promises)
|
||||
await Promise.all(promises)
|
||||
|
||||
return model
|
||||
}))
|
||||
@@ -123,10 +131,9 @@ export default class Redis extends Collection {
|
||||
if (id !== undefined) {
|
||||
delete properties.id
|
||||
return this._extract([id]).then(models => {
|
||||
return (models.length && !isEmpty(properties)) ?
|
||||
filter(models) :
|
||||
models
|
||||
|
||||
return (models.length && !isEmpty(properties))
|
||||
? filter(models)
|
||||
: models
|
||||
})
|
||||
}
|
||||
|
||||
@@ -138,21 +145,25 @@ export default class Redis extends Collection {
|
||||
throw new Error('fields not indexed: ' + unfit.join())
|
||||
}
|
||||
|
||||
const keys = map(properties, (value, index) => prefix + '_' + index + ':' + value)
|
||||
const keys = mapToArray(properties, (value, index) => `${prefix}_${index}:${value}`)
|
||||
return redis.sinter(...keys).then(ids => this._extract(ids))
|
||||
}
|
||||
|
||||
_remove (ids) {
|
||||
if (isEmpty(ids)) {
|
||||
return
|
||||
}
|
||||
|
||||
const {prefix, redis} = this
|
||||
|
||||
// TODO: handle indexes.
|
||||
|
||||
return Bluebird.all([
|
||||
return Promise.all([
|
||||
// Remove the identifiers from the main index.
|
||||
redis.srem(prefix + '_ids', ...ids),
|
||||
|
||||
// Remove the models.
|
||||
redis.del(map(ids, id => prefix + ':' + id))
|
||||
redis.del(mapToArray(ids, id => `${prefix}:${id}`))
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import {EventEmitter} from 'events'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// const noop = () => {}
|
||||
import {createRawObject, noop} from './utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@@ -10,13 +8,13 @@ export default class Connection extends EventEmitter {
|
||||
constructor () {
|
||||
super()
|
||||
|
||||
this._data = Object.create(null)
|
||||
this._data = createRawObject()
|
||||
}
|
||||
|
||||
// Close the connection.
|
||||
close () {
|
||||
// Prevent errors when the connection is closed more than once.
|
||||
// this.close = noop
|
||||
this.close = noop
|
||||
|
||||
this.emit('close')
|
||||
}
|
||||
|
||||
@@ -1,69 +1,33 @@
|
||||
import bind from 'lodash.bind'
|
||||
import { getBoundPropertyDescriptor } from 'bind-property-descriptor'
|
||||
|
||||
import {
|
||||
isArray,
|
||||
isFunction
|
||||
} from './utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const {defineProperty} = Object
|
||||
const {
|
||||
defineProperties,
|
||||
getOwnPropertyDescriptor
|
||||
} = Object
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// See: https://github.com/jayphelps/core-decorators.js#autobind
|
||||
export function autobind (target, key, {
|
||||
configurable,
|
||||
enumerable,
|
||||
value: fn,
|
||||
writable
|
||||
}) {
|
||||
return {
|
||||
configurable,
|
||||
enumerable,
|
||||
|
||||
get () {
|
||||
const bounded = bind(fn, this)
|
||||
|
||||
defineProperty(this, key, {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
value: bounded,
|
||||
writable: true
|
||||
})
|
||||
|
||||
return bounded
|
||||
},
|
||||
set (newValue) {
|
||||
if (this === target) {
|
||||
// New value directly set on the prototype.
|
||||
delete this[key]
|
||||
this[key] = newValue
|
||||
} else {
|
||||
// New value set on a child object.
|
||||
|
||||
// Cannot use assignment because it will call the setter on
|
||||
// the prototype.
|
||||
defineProperty(this, key, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: newValue,
|
||||
writable: true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// Debounce decorator for methods.
|
||||
//
|
||||
// See: https://github.com/wycats/javascript-decorators
|
||||
export const debounce = (duration) => (target, name, descriptor) => {
|
||||
const {value: fn} = descriptor
|
||||
//
|
||||
// TODO: make it work for single functions.
|
||||
export const debounce = duration => (target, name, descriptor) => {
|
||||
const fn = descriptor.value
|
||||
|
||||
// This symbol is used to store the related data directly on the
|
||||
// current object.
|
||||
const s = Symbol()
|
||||
const s = Symbol(`debounced ${name} data`)
|
||||
|
||||
function debounced () {
|
||||
let data = this[s] || (this[s] = {
|
||||
const data = this[s] || (this[s] = {
|
||||
lastCall: 0,
|
||||
wrapper: null
|
||||
})
|
||||
@@ -80,8 +44,132 @@ export const debounce = (duration) => (target, name, descriptor) => {
|
||||
}
|
||||
return data.wrapper()
|
||||
}
|
||||
debounced.reset = (obj) => { delete obj[s] }
|
||||
debounced.reset = obj => { delete obj[s] }
|
||||
|
||||
descriptor.value = debounced
|
||||
return descriptor
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
const _ownKeys = (
|
||||
(typeof Reflect !== 'undefined' && Reflect.ownKeys) ||
|
||||
(({
|
||||
getOwnPropertyNames: names,
|
||||
getOwnPropertySymbols: symbols
|
||||
}) => symbols
|
||||
? obj => names(obj).concat(symbols(obj))
|
||||
: names
|
||||
)(Object)
|
||||
)
|
||||
|
||||
const _isIgnoredProperty = name => (
|
||||
name[0] === '_' ||
|
||||
name === 'constructor'
|
||||
)
|
||||
|
||||
const _IGNORED_STATIC_PROPERTIES = {
|
||||
__proto__: null,
|
||||
|
||||
arguments: true,
|
||||
caller: true,
|
||||
length: true,
|
||||
name: true,
|
||||
prototype: true
|
||||
}
|
||||
const _isIgnoredStaticProperty = name => _IGNORED_STATIC_PROPERTIES[name]
|
||||
|
||||
export const mixin = MixIns => Class => {
|
||||
if (!isArray(MixIns)) {
|
||||
MixIns = [ MixIns ]
|
||||
}
|
||||
|
||||
const { name } = Class
|
||||
|
||||
// Copy properties of plain object mix-ins to the prototype.
|
||||
{
|
||||
const allMixIns = MixIns
|
||||
MixIns = []
|
||||
const { prototype } = Class
|
||||
const descriptors = { __proto__: null }
|
||||
for (const MixIn of allMixIns) {
|
||||
if (isFunction(MixIn)) {
|
||||
MixIns.push(MixIn)
|
||||
continue
|
||||
}
|
||||
|
||||
for (const prop of _ownKeys(MixIn)) {
|
||||
if (prop in prototype) {
|
||||
throw new Error(`${name}#${prop} is already defined`)
|
||||
}
|
||||
|
||||
(
|
||||
descriptors[prop] = getOwnPropertyDescriptor(MixIn, prop)
|
||||
).enumerable = false // Object methods are enumerable but class methods are not.
|
||||
}
|
||||
}
|
||||
defineProperties(prototype, descriptors)
|
||||
}
|
||||
|
||||
function Decorator (...args) {
|
||||
const instance = new Class(...args)
|
||||
|
||||
for (const MixIn of MixIns) {
|
||||
const { prototype } = MixIn
|
||||
const mixinInstance = new MixIn(instance)
|
||||
const descriptors = { __proto__: null }
|
||||
for (const prop of _ownKeys(prototype)) {
|
||||
if (_isIgnoredProperty(prop)) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (prop in instance) {
|
||||
throw new Error(`${name}#${prop} is already defined`)
|
||||
}
|
||||
|
||||
descriptors[prop] = getBoundPropertyDescriptor(
|
||||
prototype,
|
||||
prop,
|
||||
mixinInstance
|
||||
)
|
||||
}
|
||||
defineProperties(instance, descriptors)
|
||||
}
|
||||
|
||||
return instance
|
||||
}
|
||||
|
||||
// Copy original and mixed-in static properties on Decorator class.
|
||||
const descriptors = { __proto__: null }
|
||||
for (const prop of _ownKeys(Class)) {
|
||||
let descriptor
|
||||
if (!(
|
||||
// Special properties are not defined...
|
||||
_isIgnoredStaticProperty(prop) &&
|
||||
|
||||
// if they already exist...
|
||||
(descriptor = getOwnPropertyDescriptor(Decorator, prop)) &&
|
||||
|
||||
// and are not configurable.
|
||||
!descriptor.configurable
|
||||
)) {
|
||||
descriptors[prop] = getOwnPropertyDescriptor(Class, prop)
|
||||
}
|
||||
}
|
||||
for (const MixIn of MixIns) {
|
||||
for (const prop of _ownKeys(MixIn)) {
|
||||
if (_isIgnoredStaticProperty(prop)) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (prop in descriptors) {
|
||||
throw new Error(`${name}.${prop} is already defined`)
|
||||
}
|
||||
|
||||
descriptors[prop] = getOwnPropertyDescriptor(MixIn, prop)
|
||||
}
|
||||
}
|
||||
defineProperties(Decorator, descriptors)
|
||||
|
||||
return Decorator
|
||||
}
|
||||
|
||||
@@ -1,49 +1,10 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint-env jest */
|
||||
|
||||
import {expect} from 'chai'
|
||||
import {debounce} from './decorators'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
import {autobind, debounce} from './decorators'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
describe('autobind', function () {
|
||||
class Foo {
|
||||
@autobind
|
||||
getFoo () {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
it('returns a bound instance for a method', function () {
|
||||
const foo = new Foo()
|
||||
const {getFoo} = foo
|
||||
|
||||
expect(getFoo()).to.equal(foo)
|
||||
})
|
||||
|
||||
it('returns the same bound instance each time', function () {
|
||||
const foo = new Foo()
|
||||
|
||||
expect(foo.getFoo).to.equal(foo.getFoo)
|
||||
})
|
||||
|
||||
it('works with multiple instances of the same class', function () {
|
||||
const foo1 = new Foo()
|
||||
const foo2 = new Foo()
|
||||
|
||||
const {getFoo: getFoo1} = foo1
|
||||
const {getFoo: getFoo2} = foo2
|
||||
|
||||
expect(getFoo1()).to.equal(foo1)
|
||||
expect(getFoo2()).to.equal(foo2)
|
||||
})
|
||||
})
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
describe('debounce', function () {
|
||||
describe('debounce()', () => {
|
||||
let i
|
||||
|
||||
class Foo {
|
||||
@@ -53,24 +14,24 @@ describe('debounce', function () {
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
i = 0
|
||||
})
|
||||
|
||||
it('works', function (done) {
|
||||
it('works', done => {
|
||||
const foo = new Foo()
|
||||
|
||||
expect(i).to.equal(0)
|
||||
expect(i).toBe(0)
|
||||
|
||||
foo.foo()
|
||||
expect(i).to.equal(1)
|
||||
expect(i).toBe(1)
|
||||
|
||||
foo.foo()
|
||||
expect(i).to.equal(1)
|
||||
expect(i).toBe(1)
|
||||
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
foo.foo()
|
||||
expect(i).to.equal(2)
|
||||
expect(i).toBe(2)
|
||||
|
||||
done()
|
||||
}, 2e1)
|
||||
|
||||
85
src/fatfs-buffer.js
Normal file
85
src/fatfs-buffer.js
Normal file
@@ -0,0 +1,85 @@
|
||||
// Buffer driver for [fatfs](https://github.com/natevw/fatfs).
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// ```js
|
||||
// import fatfs from 'fatfs'
|
||||
// import fatfsBuffer, { init as fatfsBufferInit } from './fatfs-buffer'
|
||||
//
|
||||
// const buffer = fatfsBufferinit()
|
||||
//
|
||||
// const fs = fatfs.createFileSystem(fatfsBuffer(buffer))
|
||||
//
|
||||
// fs.writeFile('/foo', 'content of foo', function (err, content) {
|
||||
// if (err) {
|
||||
// console.error(err)
|
||||
// }
|
||||
// })
|
||||
|
||||
import { boot16 as fat16 } from 'fatfs/structs'
|
||||
|
||||
const SECTOR_SIZE = 512
|
||||
|
||||
const TEN_MIB = 10 * 1024 * 1024
|
||||
|
||||
// Creates a 10MB buffer and initializes it as a FAT 16 volume.
|
||||
export function init () {
|
||||
const buf = Buffer.alloc(TEN_MIB)
|
||||
|
||||
// https://github.com/natevw/fatfs/blob/master/structs.js
|
||||
fat16.pack({
|
||||
jmpBoot: Buffer.from('eb3c90', 'hex'),
|
||||
OEMName: 'mkfs.fat',
|
||||
BytsPerSec: SECTOR_SIZE,
|
||||
SecPerClus: 4,
|
||||
ResvdSecCnt: 1,
|
||||
NumFATs: 2,
|
||||
RootEntCnt: 512,
|
||||
TotSec16: 20480,
|
||||
Media: 248,
|
||||
FATSz16: 20,
|
||||
SecPerTrk: 32,
|
||||
NumHeads: 64,
|
||||
HiddSec: 0,
|
||||
TotSec32: 0,
|
||||
DrvNum: 128,
|
||||
Reserved1: 0,
|
||||
BootSig: 41,
|
||||
VolID: 895111106,
|
||||
VolLab: 'NO NAME ',
|
||||
FilSysType: 'FAT16 '
|
||||
}, buf)
|
||||
|
||||
// End of sector.
|
||||
buf[0x1fe] = 0x55
|
||||
buf[0x1ff] = 0xaa
|
||||
|
||||
// Mark sector as reserved.
|
||||
buf[0x200] = 0xf8
|
||||
buf[0x201] = 0xff
|
||||
buf[0x202] = 0xff
|
||||
buf[0x203] = 0xff
|
||||
|
||||
// Mark sector as reserved.
|
||||
buf[0x2a00] = 0xf8
|
||||
buf[0x2a01] = 0xff
|
||||
buf[0x2a02] = 0xff
|
||||
buf[0x2a03] = 0xff
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
export default buffer => {
|
||||
return {
|
||||
sectorSize: SECTOR_SIZE,
|
||||
numSectors: Math.floor(buffer.length / SECTOR_SIZE),
|
||||
readSectors: (i, target, cb) => {
|
||||
buffer.copy(target, 0, i * SECTOR_SIZE)
|
||||
cb()
|
||||
},
|
||||
writeSectors: (i, source, cb) => {
|
||||
source.copy(buffer, i * SECTOR_SIZE, 0)
|
||||
cb()
|
||||
}
|
||||
}
|
||||
}
|
||||
54
src/glob-matcher.js
Normal file
54
src/glob-matcher.js
Normal file
@@ -0,0 +1,54 @@
|
||||
// See: https://gist.github.com/julien-f/5b9a3537eb82a34b04e2
|
||||
|
||||
var matcher = require('micromatch').matcher
|
||||
|
||||
module.exports = function globMatcher (patterns, opts) {
|
||||
if (!Array.isArray(patterns)) {
|
||||
if (patterns[0] === '!') {
|
||||
var m = matcher(patterns.slice(1), opts)
|
||||
return function (string) {
|
||||
return !m(string)
|
||||
}
|
||||
} else {
|
||||
return matcher(patterns, opts)
|
||||
}
|
||||
}
|
||||
|
||||
var noneMustMatch = []
|
||||
var anyMustMatch = []
|
||||
|
||||
// TODO: could probably be optimized by combining all positive patterns (and all negative patterns) as a single matcher.
|
||||
for (var i = 0, n = patterns.length; i < n; ++i) {
|
||||
var pattern = patterns[i]
|
||||
if (pattern[0] === '!') {
|
||||
noneMustMatch.push(matcher(pattern.slice(1), opts))
|
||||
} else {
|
||||
anyMustMatch.push(matcher(pattern, opts))
|
||||
}
|
||||
}
|
||||
|
||||
var nNone = noneMustMatch.length
|
||||
var nAny = anyMustMatch.length
|
||||
|
||||
return function (string) {
|
||||
var i
|
||||
|
||||
for (i = 0; i < nNone; ++i) {
|
||||
if (noneMustMatch[i](string)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (nAny === 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
for (i = 0; i < nAny; ++i) {
|
||||
if (anyMustMatch[i](string)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
13
src/http-proxy.js
Normal file
13
src/http-proxy.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import ProxyAgent from 'proxy-agent'
|
||||
|
||||
let agent
|
||||
export { agent as default }
|
||||
|
||||
export function setup (uri) {
|
||||
agent = uri != null
|
||||
? new ProxyAgent(uri)
|
||||
: undefined
|
||||
}
|
||||
|
||||
const { env } = process
|
||||
setup(env.http_proxy || env.HTTP_PROXY)
|
||||
144
src/http-request.js
Normal file
144
src/http-request.js
Normal file
@@ -0,0 +1,144 @@
|
||||
import isRedirect from 'is-redirect'
|
||||
import { assign, isString, startsWith } from 'lodash'
|
||||
import { cancellable } from 'promise-toolbox'
|
||||
import { request as httpRequest } from 'http'
|
||||
import { request as httpsRequest } from 'https'
|
||||
import { stringify as formatQueryString } from 'querystring'
|
||||
import {
|
||||
format as formatUrl,
|
||||
parse as parseUrl,
|
||||
resolve as resolveUrl
|
||||
} from 'url'
|
||||
|
||||
import { streamToBuffer } from './utils'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
const raw = opts => {
|
||||
let req
|
||||
|
||||
const pResponse = new Promise((resolve, reject) => {
|
||||
const {
|
||||
body,
|
||||
headers: { ...headers } = {},
|
||||
protocol,
|
||||
query,
|
||||
...rest
|
||||
} = opts
|
||||
|
||||
if (headers['content-length'] == null && body != null) {
|
||||
let tmp
|
||||
if (isString(body)) {
|
||||
headers['content-length'] = Buffer.byteLength(body)
|
||||
} else if (
|
||||
(
|
||||
(tmp = body.headers) &&
|
||||
(tmp = tmp['content-length']) != null
|
||||
) ||
|
||||
(tmp = body.length) != null
|
||||
) {
|
||||
headers['content-length'] = tmp
|
||||
}
|
||||
}
|
||||
|
||||
if (query) {
|
||||
rest.path = `${rest.pathname || rest.path || '/'}?${
|
||||
isString(query)
|
||||
? query
|
||||
: formatQueryString(query)
|
||||
}`
|
||||
}
|
||||
|
||||
// Some headers can be explicitly removed by setting them to null.
|
||||
const headersToRemove = []
|
||||
for (const header in headers) {
|
||||
if (headers[header] === null) {
|
||||
delete headers[header]
|
||||
headersToRemove.push(header)
|
||||
}
|
||||
}
|
||||
|
||||
const secure = protocol && startsWith(protocol.toLowerCase(), 'https')
|
||||
let requestFn
|
||||
if (secure) {
|
||||
requestFn = httpsRequest
|
||||
} else {
|
||||
requestFn = httpRequest
|
||||
delete rest.rejectUnauthorized
|
||||
}
|
||||
|
||||
req = requestFn({
|
||||
...rest,
|
||||
headers
|
||||
})
|
||||
|
||||
for (let i = 0, length = headersToRemove.length; i < length; ++i) {
|
||||
req.removeHeader(headersToRemove[i])
|
||||
}
|
||||
|
||||
if (body) {
|
||||
if (typeof body.pipe === 'function') {
|
||||
body.pipe(req)
|
||||
} else {
|
||||
req.end(body)
|
||||
}
|
||||
} else {
|
||||
req.end()
|
||||
}
|
||||
req.on('error', reject)
|
||||
req.once('response', resolve)
|
||||
}).then(response => {
|
||||
response.cancel = () => {
|
||||
req.abort()
|
||||
}
|
||||
response.readAll = () => streamToBuffer(response)
|
||||
|
||||
const length = response.headers['content-length']
|
||||
if (length) {
|
||||
response.length = length
|
||||
}
|
||||
|
||||
const code = response.statusCode
|
||||
const { location } = response.headers
|
||||
if (isRedirect(code) && location) {
|
||||
assign(opts, parseUrl(resolveUrl(formatUrl(opts), location)))
|
||||
return raw(opts)
|
||||
}
|
||||
if (code < 200 || code >= 300) {
|
||||
const error = new Error(response.statusMessage)
|
||||
error.code = code
|
||||
Object.defineProperty(error, 'response', {
|
||||
configurable: true,
|
||||
value: response,
|
||||
writable: true
|
||||
})
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
return response
|
||||
})
|
||||
pResponse.request = req
|
||||
|
||||
return pResponse
|
||||
}
|
||||
|
||||
const httpRequestPlus = ($cancelToken, ...args) => {
|
||||
const opts = {}
|
||||
for (let i = 0, length = args.length; i < length; ++i) {
|
||||
const arg = args[i]
|
||||
assign(opts, isString(arg) ? parseUrl(arg) : arg)
|
||||
}
|
||||
|
||||
const pResponse = raw(opts)
|
||||
|
||||
$cancelToken.promise.then(() => {
|
||||
const { request } = pResponse
|
||||
request.emit('error', new Error('HTTP request canceled!'))
|
||||
request.abort()
|
||||
})
|
||||
pResponse.readAll = () => pResponse.then(response => response.readAll())
|
||||
|
||||
return pResponse
|
||||
}
|
||||
export default cancellable(httpRequestPlus)
|
||||
656
src/index.js
656
src/index.js
@@ -1,44 +1,53 @@
|
||||
import createLogger from 'debug'
|
||||
const debug = createLogger('xo:main')
|
||||
|
||||
import Bluebird from 'bluebird'
|
||||
Bluebird.longStackTraces()
|
||||
|
||||
import appConf from 'app-conf'
|
||||
import assign from 'lodash.assign'
|
||||
import bind from 'lodash.bind'
|
||||
import bind from 'lodash/bind'
|
||||
import blocked from 'blocked'
|
||||
import createConnectApp from 'connect'
|
||||
import createExpress from 'express'
|
||||
import createLogger from 'debug'
|
||||
import eventToPromise from 'event-to-promise'
|
||||
import forEach from 'lodash.foreach'
|
||||
import has from 'lodash.has'
|
||||
import isArray from 'lodash.isarray'
|
||||
import isFunction from 'lodash.isfunction'
|
||||
import map from 'lodash.map'
|
||||
import pick from 'lodash.pick'
|
||||
import proxyRequest from 'proxy-http-request'
|
||||
import has from 'lodash/has'
|
||||
import helmet from 'helmet'
|
||||
import includes from 'lodash/includes'
|
||||
import proxyConsole from './proxy-console'
|
||||
import serveStatic from 'serve-static'
|
||||
import startsWith from 'lodash/startsWith'
|
||||
import WebSocket from 'ws'
|
||||
import {
|
||||
AlreadyAuthenticated,
|
||||
InvalidCredential,
|
||||
InvalidParameters,
|
||||
NoSuchObject,
|
||||
NotImplemented
|
||||
} from './api-errors'
|
||||
import JsonRpcPeer from 'json-rpc-peer'
|
||||
import {readFile} from 'fs-promise'
|
||||
import { compile as compilePug } from 'pug'
|
||||
import { createServer as createProxyServer } from 'http-proxy'
|
||||
import { join as joinPath } from 'path'
|
||||
|
||||
import JsonRpcPeer from 'json-rpc-peer'
|
||||
import { invalidCredentials } from 'xo-common/api-errors'
|
||||
import {
|
||||
ensureDir,
|
||||
readdir,
|
||||
readFile
|
||||
} from 'fs-promise'
|
||||
|
||||
import Api from './api'
|
||||
import WebServer from 'http-server-plus'
|
||||
import wsProxy from './ws-proxy'
|
||||
import Xo from './xo'
|
||||
import {
|
||||
setup as setupHttpProxy
|
||||
} from './http-proxy'
|
||||
import {
|
||||
createRawObject,
|
||||
forEach,
|
||||
isArray,
|
||||
isFunction,
|
||||
mapToArray,
|
||||
pFromCallback
|
||||
} from './utils'
|
||||
|
||||
import bodyParser from 'body-parser'
|
||||
import connectFlash from 'connect-flash'
|
||||
import cookieParser from 'cookie-parser'
|
||||
import expressSession from 'express-session'
|
||||
import passport from 'passport'
|
||||
import { parse as parseCookies } from 'cookie'
|
||||
import { Strategy as LocalStrategy } from 'passport-local'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const info = (...args) => {
|
||||
console.info('[Info]', ...args)
|
||||
}
|
||||
const debug = createLogger('xo:main')
|
||||
|
||||
const warn = (...args) => {
|
||||
console.warn('[Warn]', ...args)
|
||||
@@ -46,15 +55,6 @@ const warn = (...args) => {
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const DEFAULTS = {
|
||||
http: {
|
||||
listen: [
|
||||
{ port: 80 }
|
||||
],
|
||||
mounts: {}
|
||||
}
|
||||
}
|
||||
|
||||
const DEPRECATED_ENTRIES = [
|
||||
'users',
|
||||
'servers'
|
||||
@@ -62,7 +62,6 @@ const DEPRECATED_ENTRIES = [
|
||||
|
||||
async function loadConfiguration () {
|
||||
const config = await appConf.load('xo-server', {
|
||||
defaults: DEFAULTS,
|
||||
ignoreUnknownFormats: true
|
||||
})
|
||||
|
||||
@@ -80,42 +79,233 @@ async function loadConfiguration () {
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const debugPlugin = createLogger('xo:plugin')
|
||||
function createExpressApp () {
|
||||
const app = createExpress()
|
||||
|
||||
const loadPlugin = Bluebird.method(function (pluginConf, pluginName) {
|
||||
debugPlugin('loading %s', pluginName)
|
||||
app.use(helmet())
|
||||
|
||||
const pluginPath = (function (name) {
|
||||
try {
|
||||
return require.resolve('xo-server-' + name)
|
||||
} catch (e) {
|
||||
return require.resolve(name)
|
||||
// Registers the cookie-parser and express-session middlewares,
|
||||
// necessary for connect-flash.
|
||||
app.use(cookieParser())
|
||||
app.use(expressSession({
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
|
||||
// TODO: should be in the config file.
|
||||
secret: 'CLWguhRZAZIXZcbrMzHCYmefxgweItKnS'
|
||||
}))
|
||||
|
||||
// Registers the connect-flash middleware, necessary for Passport to
|
||||
// display error messages.
|
||||
app.use(connectFlash())
|
||||
|
||||
// Registers the body-parser middleware, necessary for Passport to
|
||||
// access the username and password from the sign in form.
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
|
||||
// Registers Passport's middlewares.
|
||||
app.use(passport.initialize())
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
async function setUpPassport (express, xo) {
|
||||
const strategies = createRawObject()
|
||||
xo.registerPassportStrategy = strategy => {
|
||||
passport.use(strategy)
|
||||
|
||||
const {name} = strategy
|
||||
if (name !== 'local') {
|
||||
strategies[name] = strategy.label || name
|
||||
}
|
||||
})(pluginName)
|
||||
|
||||
let plugin = require(pluginPath)
|
||||
|
||||
if (isFunction(plugin)) {
|
||||
plugin = plugin(pluginConf)
|
||||
}
|
||||
|
||||
return plugin.load(this)
|
||||
})
|
||||
|
||||
const loadPlugins = function (plugins, xo) {
|
||||
return Bluebird.all(map(plugins, loadPlugin, xo)).then(() => {
|
||||
debugPlugin('all plugins loaded')
|
||||
// Registers the sign in form.
|
||||
const signInPage = compilePug(
|
||||
await readFile(joinPath(__dirname, '..', 'signin.pug'))
|
||||
)
|
||||
express.get('/signin', (req, res, next) => {
|
||||
res.send(signInPage({
|
||||
error: req.flash('error')[0],
|
||||
strategies
|
||||
}))
|
||||
})
|
||||
|
||||
express.get('/signout', (req, res) => {
|
||||
res.clearCookie('token')
|
||||
res.redirect('/')
|
||||
})
|
||||
|
||||
const SIGNIN_STRATEGY_RE = /^\/signin\/([^/]+)(\/callback)?(:?\?.*)?$/
|
||||
express.use(async (req, res, next) => {
|
||||
const { url } = req
|
||||
const matches = url.match(SIGNIN_STRATEGY_RE)
|
||||
|
||||
if (matches) {
|
||||
return passport.authenticate(matches[1], async (err, user, info) => {
|
||||
if (err) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
req.flash('error', info ? info.message : 'Invalid credentials')
|
||||
return res.redirect('/signin')
|
||||
}
|
||||
|
||||
// The cookie will be set in via the next request because some
|
||||
// browsers do not save cookies on redirect.
|
||||
req.flash(
|
||||
'token',
|
||||
(await xo.createAuthenticationToken({userId: user.id})).id
|
||||
)
|
||||
|
||||
// The session is only persistent for internal provider and if 'Remember me' box is checked
|
||||
req.flash(
|
||||
'session-is-persistent',
|
||||
matches[1] === 'local' && req.body['remember-me'] === 'on'
|
||||
)
|
||||
|
||||
res.redirect(req.flash('return-url')[0] || '/')
|
||||
})(req, res, next)
|
||||
}
|
||||
|
||||
const token = req.flash('token')[0]
|
||||
|
||||
if (token) {
|
||||
const isPersistent = req.flash('session-is-persistent')[0]
|
||||
|
||||
if (isPersistent) {
|
||||
// Persistent cookie ? => 1 year
|
||||
res.cookie('token', token, { maxAge: 1000 * 60 * 60 * 24 * 365 })
|
||||
} else {
|
||||
// Non-persistent : external provider as Github, Twitter...
|
||||
res.cookie('token', token)
|
||||
}
|
||||
|
||||
next()
|
||||
} else if (req.cookies.token) {
|
||||
next()
|
||||
} else if (/favicon|fontawesome|images|styles|\.(?:css|jpg|png)$/.test(url)) {
|
||||
next()
|
||||
} else {
|
||||
req.flash('return-url', url)
|
||||
return res.redirect('/signin')
|
||||
}
|
||||
})
|
||||
|
||||
// Install the local strategy.
|
||||
xo.registerPassportStrategy(new LocalStrategy(
|
||||
async (username, password, done) => {
|
||||
try {
|
||||
const user = await xo.authenticateUser({username, password})
|
||||
done(null, user)
|
||||
} catch (error) {
|
||||
done(null, false, { message: error.message })
|
||||
}
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
async function makeWebServerListen (opts) {
|
||||
// Read certificate and key if necessary.
|
||||
const {certificate, key} = opts
|
||||
if (certificate && key) {
|
||||
[opts.certificate, opts.key] = await Bluebird.all([
|
||||
readFile(certificate),
|
||||
async function registerPlugin (pluginPath, pluginName) {
|
||||
const plugin = require(pluginPath)
|
||||
const { version = 'unknown' } = (() => {
|
||||
try {
|
||||
return require(pluginPath + '/package.json')
|
||||
} catch (_) {
|
||||
return {}
|
||||
}
|
||||
})()
|
||||
|
||||
// Supports both “normal” CommonJS and Babel's ES2015 modules.
|
||||
const {
|
||||
default: factory = plugin,
|
||||
configurationSchema,
|
||||
configurationPresets,
|
||||
testSchema
|
||||
} = plugin
|
||||
|
||||
// The default export can be either a factory or directly a plugin
|
||||
// instance.
|
||||
const instance = isFunction(factory)
|
||||
? factory({
|
||||
xo: this,
|
||||
getDataDir: () => {
|
||||
const dir = `${this._config.datadir}/${pluginName}`
|
||||
return ensureDir(dir).then(() => dir)
|
||||
}})
|
||||
: factory
|
||||
|
||||
await this.registerPlugin(
|
||||
pluginName,
|
||||
instance,
|
||||
configurationSchema,
|
||||
configurationPresets,
|
||||
testSchema,
|
||||
version
|
||||
)
|
||||
}
|
||||
|
||||
const debugPlugin = createLogger('xo:plugin')
|
||||
|
||||
function registerPluginWrapper (pluginPath, pluginName) {
|
||||
debugPlugin('register %s', pluginName)
|
||||
|
||||
return registerPlugin.call(this, pluginPath, pluginName).then(
|
||||
() => {
|
||||
debugPlugin(`successfully register ${pluginName}`)
|
||||
},
|
||||
error => {
|
||||
debugPlugin(`failed register ${pluginName}`)
|
||||
debugPlugin(error)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const PLUGIN_PREFIX = 'xo-server-'
|
||||
const PLUGIN_PREFIX_LENGTH = PLUGIN_PREFIX.length
|
||||
|
||||
async function registerPluginsInPath (path) {
|
||||
const files = await readdir(path).catch(error => {
|
||||
if (error.code === 'ENOENT') {
|
||||
return []
|
||||
}
|
||||
throw error
|
||||
})
|
||||
|
||||
await Promise.all(mapToArray(files, name => {
|
||||
if (startsWith(name, PLUGIN_PREFIX)) {
|
||||
return registerPluginWrapper.call(
|
||||
this,
|
||||
`${path}/${name}`,
|
||||
name.slice(PLUGIN_PREFIX_LENGTH)
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
async function registerPlugins (xo) {
|
||||
await Promise.all(mapToArray([
|
||||
`${__dirname}/../node_modules/`,
|
||||
'/usr/local/lib/node_modules/'
|
||||
], xo::registerPluginsInPath))
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
async function makeWebServerListen ({
|
||||
certificate,
|
||||
|
||||
// The properties was called `certificate` before.
|
||||
cert = certificate,
|
||||
|
||||
key,
|
||||
...opts
|
||||
}) {
|
||||
if (cert && key) {
|
||||
[opts.cert, opts.key] = await Promise.all([
|
||||
readFile(cert),
|
||||
readFile(key)
|
||||
])
|
||||
}
|
||||
@@ -124,55 +314,79 @@ async function makeWebServerListen (opts) {
|
||||
const niceAddress = await this.listen(opts)
|
||||
debug(`Web server listening on ${niceAddress}`)
|
||||
} catch (error) {
|
||||
warn(`Web server could not listen on ${error.niceAddress}`)
|
||||
if (error.niceAddress) {
|
||||
warn(`Web server could not listen on ${error.niceAddress}`)
|
||||
|
||||
const {code} = error
|
||||
if (code === 'EACCES') {
|
||||
warn(' Access denied.')
|
||||
warn(' Ports < 1024 are often reserved to privileges users.')
|
||||
} else if (code === 'EADDRINUSE') {
|
||||
warn(' Address already in use.')
|
||||
const {code} = error
|
||||
if (code === 'EACCES') {
|
||||
warn(' Access denied.')
|
||||
warn(' Ports < 1024 are often reserved to privileges users.')
|
||||
} else if (code === 'EADDRINUSE') {
|
||||
warn(' Address already in use.')
|
||||
}
|
||||
} else {
|
||||
warn('Web server could not listen:', error.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const createWebServer = opts => {
|
||||
async function createWebServer (opts) {
|
||||
const webServer = new WebServer()
|
||||
|
||||
return Bluebird
|
||||
.bind(webServer).return(opts).map(makeWebServerListen)
|
||||
.return(webServer)
|
||||
await Promise.all(mapToArray(opts, webServer::makeWebServerListen))
|
||||
|
||||
return webServer
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const setUpProxies = (connect, opts) => {
|
||||
const setUpProxies = (express, opts, xo) => {
|
||||
if (!opts) {
|
||||
return
|
||||
}
|
||||
|
||||
const proxy = createProxyServer({
|
||||
ignorePath: true
|
||||
}).on('error', (error) => console.error(error))
|
||||
|
||||
// TODO: sort proxies by descending prefix length.
|
||||
|
||||
// HTTP request proxy.
|
||||
forEach(opts, (target, url) => {
|
||||
connect.use(url, (req, res) => {
|
||||
proxyRequest(target + req.url, req, res)
|
||||
})
|
||||
express.use((req, res, next) => {
|
||||
const { url } = req
|
||||
|
||||
for (const prefix in opts) {
|
||||
if (startsWith(url, prefix)) {
|
||||
const target = opts[prefix]
|
||||
|
||||
proxy.web(req, res, {
|
||||
target: target + url.slice(prefix.length)
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
next()
|
||||
})
|
||||
|
||||
// WebSocket proxy.
|
||||
const webSocketServer = new WebSocket.Server({
|
||||
noServer: true
|
||||
})
|
||||
connect.on('upgrade', (req, socket, head) => {
|
||||
const {url} = req
|
||||
xo.on('stop', () => pFromCallback(cb => webSocketServer.close(cb)))
|
||||
|
||||
for (let prefix in opts) {
|
||||
if (url.lastIndexOf(prefix, 0) !== -1) {
|
||||
const target = opts[prefix] + url.slice(prefix.length)
|
||||
webSocketServer.handleUpgrade(req, socket, head, socket => {
|
||||
wsProxy(socket, target)
|
||||
express.on('upgrade', (req, socket, head) => {
|
||||
const { url } = req
|
||||
|
||||
for (const prefix in opts) {
|
||||
if (startsWith(url, prefix)) {
|
||||
const target = opts[prefix]
|
||||
|
||||
proxy.ws(req, socket, head, {
|
||||
target: target + url.slice(prefix.length)
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -181,7 +395,7 @@ const setUpProxies = (connect, opts) => {
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const setUpStaticFiles = (connect, opts) => {
|
||||
const setUpStaticFiles = (express, opts) => {
|
||||
forEach(opts, (paths, url) => {
|
||||
if (!isArray(paths)) {
|
||||
paths = [paths]
|
||||
@@ -190,62 +404,23 @@ const setUpStaticFiles = (connect, opts) => {
|
||||
forEach(paths, path => {
|
||||
debug('Setting up %s → %s', url, path)
|
||||
|
||||
connect.use(url, serveStatic(path))
|
||||
express.use(url, serveStatic(path))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const errorClasses = {
|
||||
ALREADY_AUTHENTICATED: AlreadyAuthenticated,
|
||||
INVALID_CREDENTIAL: InvalidCredential,
|
||||
INVALID_PARAMS: InvalidParameters,
|
||||
NO_SUCH_OBJECT: NoSuchObject,
|
||||
NOT_IMPLEMENTED: NotImplemented
|
||||
}
|
||||
|
||||
const apiHelpers = {
|
||||
getUserPublicProperties (user) {
|
||||
// Handles both properties and wrapped models.
|
||||
const properties = user.properties || user
|
||||
|
||||
return pick(properties, 'id', 'email', 'groups', 'permission')
|
||||
},
|
||||
|
||||
getServerPublicProperties (server) {
|
||||
// Handles both properties and wrapped models.
|
||||
const properties = server.properties || server
|
||||
|
||||
server = pick(properties, 'id', 'host', 'username')
|
||||
|
||||
// Injects connection status.
|
||||
const xapi = this._xapis[server.id]
|
||||
server.status = xapi ? xapi.status : 'disconnected'
|
||||
|
||||
return server
|
||||
},
|
||||
|
||||
throw (errorId, data) {
|
||||
throw new (errorClasses[errorId])(data)
|
||||
}
|
||||
}
|
||||
|
||||
const setUpApi = (webServer, xo) => {
|
||||
const context = Object.create(xo)
|
||||
assign(xo, apiHelpers)
|
||||
|
||||
const api = new Api({
|
||||
context
|
||||
})
|
||||
|
||||
const setUpApi = (webServer, xo, verboseLogsOnErrors) => {
|
||||
const webSocketServer = new WebSocket.Server({
|
||||
server: webServer,
|
||||
path: '/api/'
|
||||
noServer: true
|
||||
})
|
||||
xo.on('stop', () => pFromCallback(cb => webSocketServer.close(cb)))
|
||||
|
||||
webSocketServer.on('connection', socket => {
|
||||
debug('+ WebSocket connection')
|
||||
const onConnection = socket => {
|
||||
const { remoteAddress } = socket.upgradeReq.socket
|
||||
|
||||
debug('+ WebSocket connection (%s)', remoteAddress)
|
||||
|
||||
// Create the abstract XO object for this connection.
|
||||
const connection = xo.createUserConnection()
|
||||
@@ -256,14 +431,14 @@ const setUpApi = (webServer, xo) => {
|
||||
// Create the JSON-RPC server for this connection.
|
||||
const jsonRpc = new JsonRpcPeer(message => {
|
||||
if (message.type === 'request') {
|
||||
return api.call(connection, message.method, message.params)
|
||||
return xo.callApiMethod(connection, message.method, message.params)
|
||||
}
|
||||
})
|
||||
connection.notify = bind(jsonRpc.notify, jsonRpc)
|
||||
|
||||
// Close the XO connection with this WebSocket.
|
||||
socket.once('close', () => {
|
||||
debug('- WebSocket connection')
|
||||
debug('- WebSocket connection (%s)', remoteAddress)
|
||||
|
||||
connection.close()
|
||||
})
|
||||
@@ -285,6 +460,11 @@ const setUpApi = (webServer, xo) => {
|
||||
socket.send(data, onSend)
|
||||
}
|
||||
})
|
||||
}
|
||||
webServer.on('upgrade', (req, socket, head) => {
|
||||
if (req.url === '/api/') {
|
||||
webSocketServer.handleUpgrade(req, socket, head, onConnection)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -296,8 +476,9 @@ const setUpConsoleProxy = (webServer, xo) => {
|
||||
const webSocketServer = new WebSocket.Server({
|
||||
noServer: true
|
||||
})
|
||||
xo.on('stop', () => pFromCallback(cb => webSocketServer.close(cb)))
|
||||
|
||||
webServer.on('upgrade', (req, socket, head) => {
|
||||
webServer.on('upgrade', async (req, socket, head) => {
|
||||
const matches = CONSOLE_PROXY_PATH_RE.exec(req.url)
|
||||
if (!matches) {
|
||||
return
|
||||
@@ -305,74 +486,49 @@ const setUpConsoleProxy = (webServer, xo) => {
|
||||
|
||||
const [, id] = matches
|
||||
try {
|
||||
const url = xo.getXAPI(id, ['VM', 'VM-controller']).getVmConsoleUrl(id)
|
||||
// TODO: factorize permissions checking in an Express middleware.
|
||||
{
|
||||
const { token } = parseCookies(req.headers.cookie)
|
||||
|
||||
const user = await xo.authenticateUser({ token })
|
||||
if (!await xo.hasPermissions(user.id, [ [ id, 'operate' ] ])) {
|
||||
throw invalidCredentials()
|
||||
}
|
||||
|
||||
const { remoteAddress } = socket
|
||||
debug('+ Console proxy (%s - %s)', user.name, remoteAddress)
|
||||
socket.on('close', () => {
|
||||
debug('- Console proxy (%s - %s)', user.name, remoteAddress)
|
||||
})
|
||||
}
|
||||
|
||||
const xapi = xo.getXapi(id, ['VM', 'VM-controller'])
|
||||
const vmConsole = xapi.getVmConsole(id)
|
||||
|
||||
// FIXME: lost connection due to VM restart is not detected.
|
||||
webSocketServer.handleUpgrade(req, socket, head, connection => {
|
||||
wsProxy(connection, url, {
|
||||
rejectUnauthorized: false
|
||||
})
|
||||
proxyConsole(connection, vmConsole, xapi.sessionId)
|
||||
})
|
||||
} catch (_) {}
|
||||
} catch (error) {
|
||||
console.error((error && error.stack) || error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const registerPasswordAuthenticationProvider = (xo) => {
|
||||
async function passwordAuthenticationProvider ({
|
||||
email,
|
||||
password,
|
||||
}) {
|
||||
/* eslint no-throw-literal: 0 */
|
||||
const USAGE = (({
|
||||
name,
|
||||
version
|
||||
}) => `Usage: ${name} [--safe-mode]
|
||||
|
||||
if (email === undefined || password === undefined) {
|
||||
throw null
|
||||
}
|
||||
|
||||
// TODO: this is deprecated and should be removed.
|
||||
const user = await xo._users.first({email})
|
||||
if (!user || !(await user.checkPassword(password))) {
|
||||
throw null
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
xo.registerAuthenticationProvider(passwordAuthenticationProvider)
|
||||
}
|
||||
|
||||
const registerTokenAuthenticationProvider = (xo) => {
|
||||
async function tokenAuthenticationProvider ({
|
||||
token: tokenId,
|
||||
}) {
|
||||
/* eslint no-throw-literal: 0 */
|
||||
|
||||
if (!tokenId) {
|
||||
throw null
|
||||
}
|
||||
|
||||
try {
|
||||
return (await xo.getAuthenticationToken(tokenId)).user_id
|
||||
} catch (e) {
|
||||
// It is not an error if the token does not exists.
|
||||
throw null
|
||||
}
|
||||
}
|
||||
|
||||
xo.registerAuthenticationProvider(tokenAuthenticationProvider)
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const help = (function ({name, version}) {
|
||||
return () => `${name} v${version}`
|
||||
})(require('../package.json'))
|
||||
${name} v${version}`)(require('../package.json'))
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default async function main (args) {
|
||||
if (args.indexOf('--help') !== -1 || args.indexOf('-h') !== -1) {
|
||||
return help()
|
||||
if (includes(args, '--help') || includes(args, '-h')) {
|
||||
return USAGE
|
||||
}
|
||||
|
||||
{
|
||||
@@ -401,58 +557,94 @@ export default async function main (args) {
|
||||
warn('Failed to change user/group:', error)
|
||||
}
|
||||
|
||||
// Create the main object which will connects to Xen servers and
|
||||
// manages all the models.
|
||||
const xo = new Xo()
|
||||
await xo.start({
|
||||
redis: {
|
||||
uri: config.redis && config.redis.uri
|
||||
}
|
||||
})
|
||||
|
||||
// Loads default authentication providers.
|
||||
registerPasswordAuthenticationProvider(xo)
|
||||
registerTokenAuthenticationProvider(xo)
|
||||
|
||||
if (config.plugins) {
|
||||
await loadPlugins(config.plugins, xo)
|
||||
if (config.httpProxy) {
|
||||
setupHttpProxy(config.httpProxy)
|
||||
}
|
||||
|
||||
// Connect is used to manage non WebSocket connections.
|
||||
const connect = createConnectApp()
|
||||
webServer.on('request', connect)
|
||||
webServer.on('upgrade', (req, socket, head) => {
|
||||
connect.emit('upgrade', req, socket, head)
|
||||
})
|
||||
// Creates main object.
|
||||
const xo = new Xo(config)
|
||||
|
||||
// Register web server close on XO stop.
|
||||
xo.on('stop', () => pFromCallback(cb => webServer.close(cb)))
|
||||
|
||||
// Connects to all registered servers.
|
||||
await xo.start()
|
||||
|
||||
// Express is used to manage non WebSocket connections.
|
||||
const express = createExpressApp()
|
||||
|
||||
if (config.http.redirectToHttps) {
|
||||
let port
|
||||
forEach(config.http.listen, listen => {
|
||||
if (
|
||||
listen.port &&
|
||||
(listen.cert || listen.certificate)
|
||||
) {
|
||||
port = listen.port
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
if (port === undefined) {
|
||||
warn('Could not setup HTTPs redirection: no HTTPs port found')
|
||||
} else {
|
||||
express.use((req, res, next) => {
|
||||
if (req.secure) {
|
||||
return next()
|
||||
}
|
||||
|
||||
res.redirect(`https://${req.hostname}:${port}${req.originalUrl}`)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Must be set up before the API.
|
||||
setUpConsoleProxy(webServer, xo)
|
||||
|
||||
// Must be set up before the API.
|
||||
connect.use(bind(xo._handleHttpRequest, xo))
|
||||
express.use(bind(xo._handleHttpRequest, xo))
|
||||
|
||||
// TODO: remove when no longer necessary.
|
||||
connect.use(bind(xo._handleProxyRequest, xo))
|
||||
// Everything above is not protected by the sign in, allowing xo-cli
|
||||
// to work properly.
|
||||
await setUpPassport(express, xo)
|
||||
|
||||
// Attaches express to the web server.
|
||||
webServer.on('request', express)
|
||||
webServer.on('upgrade', (req, socket, head) => {
|
||||
express.emit('upgrade', req, socket, head)
|
||||
})
|
||||
|
||||
// Must be set up before the static files.
|
||||
setUpApi(webServer, xo)
|
||||
setUpApi(webServer, xo, config.verboseApiLogsOnErrors)
|
||||
|
||||
setUpProxies(connect, config.http.proxies)
|
||||
setUpProxies(express, config.http.proxies, xo)
|
||||
|
||||
setUpStaticFiles(connect, config.http.mounts)
|
||||
setUpStaticFiles(express, config.http.mounts)
|
||||
|
||||
if (!(await xo._users.exists())) {
|
||||
const email = 'admin@admin.net'
|
||||
const password = 'admin'
|
||||
|
||||
await xo.createUser({email, password, permission: 'admin'})
|
||||
info('Default user created:', email, ' with password', password)
|
||||
if (!includes(args, '--safe-mode')) {
|
||||
await registerPlugins(xo)
|
||||
}
|
||||
|
||||
// Handle gracefully shutdown.
|
||||
const closeWebServer = () => { webServer.close() }
|
||||
process.on('SIGINT', closeWebServer)
|
||||
process.on('SIGTERM', closeWebServer)
|
||||
// Gracefully shutdown on signals.
|
||||
//
|
||||
// TODO: implements a timeout? (or maybe it is the services launcher
|
||||
// responsibility?)
|
||||
forEach([ 'SIGINT', 'SIGTERM' ], signal => {
|
||||
let alreadyCalled = false
|
||||
|
||||
return eventToPromise(webServer, 'close')
|
||||
process.on(signal, () => {
|
||||
if (alreadyCalled) {
|
||||
warn('forced exit')
|
||||
process.exit(1)
|
||||
}
|
||||
alreadyCalled = true
|
||||
|
||||
debug('%s caught, closing…', signal)
|
||||
xo.stop()
|
||||
})
|
||||
})
|
||||
|
||||
await eventToPromise(xo, 'stopped')
|
||||
|
||||
debug('bye :-)')
|
||||
}
|
||||
|
||||
205
src/job-executor.js
Normal file
205
src/job-executor.js
Normal file
@@ -0,0 +1,205 @@
|
||||
import assign from 'lodash/assign'
|
||||
import Bluebird from 'bluebird'
|
||||
import every from 'lodash/every'
|
||||
import filter from 'lodash/filter'
|
||||
import isArray from 'lodash/isArray'
|
||||
import isPlainObject from 'lodash/isPlainObject'
|
||||
import map from 'lodash/map'
|
||||
import mapValues from 'lodash/mapValues'
|
||||
import size from 'lodash/size'
|
||||
import some from 'lodash/some'
|
||||
import { BaseError } from 'make-error'
|
||||
import { timeout } from 'promise-toolbox'
|
||||
|
||||
import { crossProduct } from './math'
|
||||
import {
|
||||
serializeError,
|
||||
thunkToArray
|
||||
} from './utils'
|
||||
|
||||
export class JobExecutorError extends BaseError {}
|
||||
export class UnsupportedJobType extends JobExecutorError {
|
||||
constructor (job) {
|
||||
super('Unknown job type: ' + job.type)
|
||||
}
|
||||
}
|
||||
export class UnsupportedVectorType extends JobExecutorError {
|
||||
constructor (vector) {
|
||||
super('Unknown vector type: ' + vector.type)
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const match = (pattern, value) => {
|
||||
if (isPlainObject(pattern)) {
|
||||
if (size(pattern) === 1) {
|
||||
if (pattern.__or) {
|
||||
return some(pattern.__or, subpattern => match(subpattern, value))
|
||||
}
|
||||
if (pattern.__not) {
|
||||
return !match(pattern.__not, value)
|
||||
}
|
||||
}
|
||||
|
||||
return isPlainObject(value) && every(pattern, (subpattern, key) => (
|
||||
value[key] !== undefined && match(subpattern, value[key])
|
||||
))
|
||||
}
|
||||
|
||||
if (isArray(pattern)) {
|
||||
return isArray(value) && every(pattern, subpattern =>
|
||||
some(value, subvalue => match(subpattern, subvalue))
|
||||
)
|
||||
}
|
||||
|
||||
return pattern === value
|
||||
}
|
||||
|
||||
const paramsVectorActionsMap = {
|
||||
extractProperties ({ mapping, value }) {
|
||||
return mapValues(mapping, key => value[key])
|
||||
},
|
||||
crossProduct ({ items }) {
|
||||
return thunkToArray(crossProduct(
|
||||
map(items, value => resolveParamsVector.call(this, value))
|
||||
))
|
||||
},
|
||||
fetchObjects ({ pattern }) {
|
||||
return filter(this.xo.getObjects(), object => match(pattern, object))
|
||||
},
|
||||
map ({ collection, iteratee, paramName = 'value' }) {
|
||||
return map(resolveParamsVector.call(this, collection), value => {
|
||||
return resolveParamsVector.call(this, {
|
||||
...iteratee,
|
||||
[paramName]: value
|
||||
})
|
||||
})
|
||||
},
|
||||
set: ({ values }) => values
|
||||
}
|
||||
|
||||
export function resolveParamsVector (paramsVector) {
|
||||
const visitor = paramsVectorActionsMap[paramsVector.type]
|
||||
if (!visitor) {
|
||||
throw new Error(`Unsupported function '${paramsVector.type}'.`)
|
||||
}
|
||||
|
||||
return visitor.call(this, paramsVector)
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class JobExecutor {
|
||||
constructor (xo) {
|
||||
this.xo = xo
|
||||
this._extractValueCb = {
|
||||
'set': items => items.values
|
||||
}
|
||||
|
||||
// The logger is not available until Xo has started.
|
||||
xo.on('start', () => xo.getLogger('jobs').then(logger => {
|
||||
this._logger = logger
|
||||
}))
|
||||
}
|
||||
|
||||
async exec (job) {
|
||||
const runJobId = this._logger.notice(`Starting execution of ${job.id}.`, {
|
||||
event: 'job.start',
|
||||
userId: job.userId,
|
||||
jobId: job.id,
|
||||
key: job.key
|
||||
})
|
||||
|
||||
try {
|
||||
if (job.type === 'call') {
|
||||
const execStatus = await this._execCall(job, runJobId)
|
||||
|
||||
this.xo.emit('job:terminated', execStatus)
|
||||
} else {
|
||||
throw new UnsupportedJobType(job)
|
||||
}
|
||||
|
||||
this._logger.notice(`Execution terminated for ${job.id}.`, {
|
||||
event: 'job.end',
|
||||
runJobId
|
||||
})
|
||||
} catch (error) {
|
||||
this._logger.error(`The execution of ${job.id} has failed.`, {
|
||||
event: 'job.end',
|
||||
runJobId,
|
||||
error: serializeError(error)
|
||||
})
|
||||
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async _execCall (job, runJobId) {
|
||||
const { paramsVector } = job
|
||||
const paramsFlatVector = paramsVector
|
||||
? resolveParamsVector.call(this, paramsVector)
|
||||
: [{}] // One call with no parameters
|
||||
|
||||
const connection = this.xo.createUserConnection()
|
||||
|
||||
connection.set('user_id', job.userId)
|
||||
|
||||
const execStatus = {
|
||||
runJobId,
|
||||
start: Date.now(),
|
||||
calls: {}
|
||||
}
|
||||
|
||||
await Bluebird.map(paramsFlatVector, params => {
|
||||
const runCallId = this._logger.notice(`Starting ${job.method} call. (${job.id})`, {
|
||||
event: 'jobCall.start',
|
||||
runJobId,
|
||||
method: job.method,
|
||||
params
|
||||
})
|
||||
|
||||
const call = execStatus.calls[runCallId] = {
|
||||
method: job.method,
|
||||
params,
|
||||
start: Date.now()
|
||||
}
|
||||
let promise = this.xo.callApiMethod(connection, job.method, assign({}, params))
|
||||
if (job.timeout) {
|
||||
promise = promise::timeout(job.timeout)
|
||||
}
|
||||
|
||||
return promise.then(
|
||||
value => {
|
||||
this._logger.notice(`Call ${job.method} (${runCallId}) is a success. (${job.id})`, {
|
||||
event: 'jobCall.end',
|
||||
runJobId,
|
||||
runCallId,
|
||||
returnedValue: value
|
||||
})
|
||||
|
||||
call.returnedValue = value
|
||||
call.end = Date.now()
|
||||
},
|
||||
reason => {
|
||||
this._logger.notice(`Call ${job.method} (${runCallId}) has failed. (${job.id})`, {
|
||||
event: 'jobCall.end',
|
||||
runJobId,
|
||||
runCallId,
|
||||
error: serializeError(reason)
|
||||
})
|
||||
|
||||
call.error = reason
|
||||
call.end = Date.now()
|
||||
}
|
||||
)
|
||||
}, {
|
||||
concurrency: 2
|
||||
})
|
||||
|
||||
connection.close()
|
||||
execStatus.end = Date.now()
|
||||
|
||||
return execStatus
|
||||
}
|
||||
}
|
||||
100
src/job-executor.spec.js
Normal file
100
src/job-executor.spec.js
Normal file
@@ -0,0 +1,100 @@
|
||||
/* eslint-env jest */
|
||||
|
||||
import { forEach } from 'lodash'
|
||||
import { resolveParamsVector } from './job-executor'
|
||||
|
||||
describe('resolveParamsVector', function () {
|
||||
forEach({
|
||||
'cross product with three sets': [
|
||||
// Expected result.
|
||||
[ { id: 3, value: 'foo', remote: 'local' },
|
||||
{ id: 7, value: 'foo', remote: 'local' },
|
||||
{ id: 10, value: 'foo', remote: 'local' },
|
||||
{ id: 3, value: 'bar', remote: 'local' },
|
||||
{ id: 7, value: 'bar', remote: 'local' },
|
||||
{ id: 10, value: 'bar', remote: 'local' } ],
|
||||
// Entry.
|
||||
{
|
||||
type: 'crossProduct',
|
||||
items: [{
|
||||
type: 'set',
|
||||
values: [ { id: 3 }, { id: 7 }, { id: 10 } ]
|
||||
}, {
|
||||
type: 'set',
|
||||
values: [ { value: 'foo' }, { value: 'bar' } ]
|
||||
}, {
|
||||
type: 'set',
|
||||
values: [ { remote: 'local' } ]
|
||||
}]
|
||||
}
|
||||
],
|
||||
'cross product with `set` and `map`': [
|
||||
// Expected result.
|
||||
[
|
||||
{ remote: 'local', id: 'vm:2' },
|
||||
{ remote: 'smb', id: 'vm:2' }
|
||||
],
|
||||
|
||||
// Entry.
|
||||
{
|
||||
type: 'crossProduct',
|
||||
items: [{
|
||||
type: 'set',
|
||||
values: [ { remote: 'local' }, { remote: 'smb' } ]
|
||||
}, {
|
||||
type: 'map',
|
||||
collection: {
|
||||
type: 'fetchObjects',
|
||||
pattern: {
|
||||
$pool: { __or: [ 'pool:1', 'pool:8', 'pool:12' ] },
|
||||
power_state: 'Running',
|
||||
tags: [ 'foo' ],
|
||||
type: 'VM'
|
||||
}
|
||||
},
|
||||
iteratee: {
|
||||
type: 'extractProperties',
|
||||
mapping: { id: 'id' }
|
||||
}
|
||||
}]
|
||||
},
|
||||
|
||||
// Context.
|
||||
{
|
||||
xo: {
|
||||
getObjects: function () {
|
||||
return [{
|
||||
id: 'vm:1',
|
||||
$pool: 'pool:1',
|
||||
tags: [],
|
||||
type: 'VM',
|
||||
power_state: 'Halted'
|
||||
}, {
|
||||
id: 'vm:2',
|
||||
$pool: 'pool:1',
|
||||
tags: [ 'foo' ],
|
||||
type: 'VM',
|
||||
power_state: 'Running'
|
||||
}, {
|
||||
id: 'host:1',
|
||||
type: 'host',
|
||||
power_state: 'Running'
|
||||
}, {
|
||||
id: 'vm:3',
|
||||
$pool: 'pool:8',
|
||||
tags: [ 'foo' ],
|
||||
type: 'VM',
|
||||
power_state: 'Halted'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}, ([ expectedResult, entry, context ], name) => {
|
||||
describe(`with ${name}`, () => {
|
||||
it('Resolves params vector', () => {
|
||||
expect(resolveParamsVector.call(context, entry)).toEqual(expectedResult)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
22
src/loggers/abstract.js
Normal file
22
src/loggers/abstract.js
Normal file
@@ -0,0 +1,22 @@
|
||||
export default class AbstractLogger {}
|
||||
|
||||
// See: https://en.wikipedia.org/wiki/Syslog#Severity_level
|
||||
const LEVELS = [
|
||||
'emergency',
|
||||
'alert',
|
||||
'critical',
|
||||
'error',
|
||||
'warning',
|
||||
'notice',
|
||||
'informational',
|
||||
'debug'
|
||||
]
|
||||
|
||||
// Create high level log methods.
|
||||
for (const level of LEVELS) {
|
||||
Object.defineProperty(AbstractLogger.prototype, level, {
|
||||
value (message, data) {
|
||||
return this._add(level, message, data)
|
||||
}
|
||||
})
|
||||
}
|
||||
59
src/loggers/leveldb.js
Normal file
59
src/loggers/leveldb.js
Normal file
@@ -0,0 +1,59 @@
|
||||
import highland from 'highland'
|
||||
|
||||
import AbstractLogger from './abstract'
|
||||
import { forEach, noop } from '../utils'
|
||||
|
||||
let lastDate = 0
|
||||
let increment = 0
|
||||
|
||||
function generateUniqueKey (date) {
|
||||
if (date === lastDate) {
|
||||
return `${date}:${increment++}`
|
||||
}
|
||||
|
||||
increment = 0
|
||||
return String(lastDate = date)
|
||||
}
|
||||
|
||||
export default class LevelDbLogger extends AbstractLogger {
|
||||
constructor (db, namespace) {
|
||||
super()
|
||||
|
||||
this._db = db
|
||||
this._namespace = namespace
|
||||
}
|
||||
|
||||
_add (level, message, data) {
|
||||
const time = Date.now()
|
||||
|
||||
const log = {
|
||||
level,
|
||||
message,
|
||||
data,
|
||||
namespace: this._namespace,
|
||||
time
|
||||
}
|
||||
|
||||
const key = generateUniqueKey(time)
|
||||
this._db.putSync(key, log)
|
||||
return key
|
||||
}
|
||||
|
||||
createReadStream () {
|
||||
return highland(this._db.createReadStream())
|
||||
.filter(({value}) => value.namespace === this._namespace)
|
||||
}
|
||||
|
||||
del (id) {
|
||||
if (!Array.isArray(id)) {
|
||||
id = [id]
|
||||
}
|
||||
forEach(id, id => {
|
||||
this._db.get(id).then(value => {
|
||||
if (value.namespace === this._namespace) {
|
||||
this._db.delSync(id, noop)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
202
src/logs-cli.js
Normal file
202
src/logs-cli.js
Normal file
@@ -0,0 +1,202 @@
|
||||
import appConf from 'app-conf'
|
||||
import get from 'lodash/get'
|
||||
import highland from 'highland'
|
||||
import levelup from 'level-party'
|
||||
import ndjson from 'ndjson'
|
||||
import parseArgs from 'minimist'
|
||||
import sublevel from 'level-sublevel'
|
||||
import util from 'util'
|
||||
import { repair as repairDb } from 'leveldown'
|
||||
|
||||
import {forEach} from './utils'
|
||||
import globMatcher from './glob-matcher'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
async function printLogs (db, args) {
|
||||
let stream = highland(db.createReadStream({reverse: true}))
|
||||
|
||||
if (args.since) {
|
||||
stream = stream.filter(({value}) => (value.time >= args.since))
|
||||
}
|
||||
|
||||
if (args.until) {
|
||||
stream = stream.filter(({value}) => (value.time <= args.until))
|
||||
}
|
||||
|
||||
const fields = Object.keys(args.matchers)
|
||||
|
||||
if (fields.length > 0) {
|
||||
stream = stream.filter(({value}) => {
|
||||
for (const field of fields) {
|
||||
const fieldValue = get(value, field)
|
||||
if (fieldValue === undefined || !args.matchers[field](fieldValue)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
stream = stream.take(args.limit)
|
||||
|
||||
if (args.json) {
|
||||
stream = highland(stream.pipe(ndjson.serialize()))
|
||||
.each(value => {
|
||||
process.stdout.write(value)
|
||||
})
|
||||
} else {
|
||||
stream = stream.each(value => {
|
||||
console.log(util.inspect(value, { depth: null }))
|
||||
})
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
stream.done(resolve)
|
||||
})
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
function helper () {
|
||||
console.error(`
|
||||
xo-server-logs --help, -h
|
||||
|
||||
Display this help message.
|
||||
|
||||
xo-server-logs [--json] [--limit=<limit>] [--since=<date>] [--until=<date>] [<pattern>...]
|
||||
|
||||
Prints the logs.
|
||||
|
||||
--json
|
||||
Display the results as new line delimited JSON for consumption
|
||||
by another program.
|
||||
|
||||
--limit=<limit>, -n <limit>
|
||||
Limit the number of results to be displayed (default 100)
|
||||
|
||||
--since=<date>, --until=<date>
|
||||
Start showing entries on or newer than the specified date, or on
|
||||
or older than the specified date.
|
||||
|
||||
<date> should use the format \`YYYY-MM-DD\`.
|
||||
|
||||
<pattern>
|
||||
Patterns can be used to filter the entries.
|
||||
|
||||
Patterns have the following format \`<field>=<value>\`/\`<field>\`.
|
||||
|
||||
xo-server-logs --repair
|
||||
|
||||
Repair/compact the database.
|
||||
|
||||
This is an advanced operation and should be used only when necessary and offline (xo-server should be stopped).
|
||||
`)
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
function getArgs () {
|
||||
const stringArgs = ['since', 'until', 'limit']
|
||||
const args = parseArgs(process.argv.slice(2), {
|
||||
string: stringArgs,
|
||||
boolean: ['help', 'json', 'repair'],
|
||||
default: {
|
||||
limit: 100,
|
||||
json: false,
|
||||
help: false
|
||||
},
|
||||
alias: {
|
||||
limit: 'n',
|
||||
help: 'h'
|
||||
}
|
||||
})
|
||||
|
||||
const patterns = {}
|
||||
|
||||
for (let value of args._) {
|
||||
value = String(value)
|
||||
|
||||
const i = value.indexOf('=')
|
||||
|
||||
if (i !== -1) {
|
||||
const field = value.slice(0, i)
|
||||
const pattern = value.slice(i + 1)
|
||||
|
||||
patterns[pattern]
|
||||
? patterns[field].push(pattern)
|
||||
: patterns[field] = [ pattern ]
|
||||
} else if (!patterns[value]) {
|
||||
patterns[value] = null
|
||||
}
|
||||
}
|
||||
|
||||
const trueFunction = () => true
|
||||
args.matchers = {}
|
||||
|
||||
for (const field in patterns) {
|
||||
const values = patterns[field]
|
||||
args.matchers[field] = (values === null) ? trueFunction : globMatcher(values)
|
||||
}
|
||||
|
||||
// Warning: minimist makes one array of values if the same option is used many times.
|
||||
// (But only for strings args, not boolean)
|
||||
forEach(stringArgs, arg => {
|
||||
if (args[arg] instanceof Array) {
|
||||
throw new Error(`error: too many values for ${arg} argument`)
|
||||
}
|
||||
})
|
||||
|
||||
;['since', 'until'].forEach(arg => {
|
||||
if (args[arg] !== undefined) {
|
||||
args[arg] = Date.parse(args[arg])
|
||||
|
||||
if (isNaN(args[arg])) {
|
||||
throw new Error(`error: bad ${arg} timestamp format`)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (isNaN(args.limit = +args.limit)) {
|
||||
throw new Error('error: limit is not a valid number')
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default async function main () {
|
||||
const args = getArgs()
|
||||
|
||||
if (args.help) {
|
||||
helper()
|
||||
return
|
||||
}
|
||||
|
||||
const config = await appConf.load('xo-server', {
|
||||
ignoreUnknownFormats: true
|
||||
})
|
||||
|
||||
if (args.repair) {
|
||||
await new Promise((resolve, reject) => {
|
||||
repairDb(`${config.datadir}/leveldb`, error => {
|
||||
if (error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const db = sublevel(levelup(
|
||||
`${config.datadir}/leveldb`,
|
||||
{ valueEncoding: 'json' }
|
||||
)).sublevel('logs')
|
||||
|
||||
return printLogs(db, args)
|
||||
}
|
||||
33
src/lvm.js
Normal file
33
src/lvm.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import execa from 'execa'
|
||||
import splitLines from 'split-lines'
|
||||
import { createParser } from 'parse-pairs'
|
||||
import { isArray, map } from 'lodash'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const parse = createParser({
|
||||
keyTransform: key => key.slice(5).toLowerCase()
|
||||
})
|
||||
const makeFunction = command => (fields, ...args) =>
|
||||
execa.stdout(command, [
|
||||
'--noheading',
|
||||
'--nosuffix',
|
||||
'--nameprefixes',
|
||||
'--unbuffered',
|
||||
'--units',
|
||||
'b',
|
||||
'-o',
|
||||
String(fields),
|
||||
...args
|
||||
]).then(stdout => map(
|
||||
splitLines(stdout),
|
||||
isArray(fields)
|
||||
? parse
|
||||
: line => {
|
||||
const data = parse(line)
|
||||
return data[fields]
|
||||
}
|
||||
))
|
||||
|
||||
export const lvs = makeFunction('lvs')
|
||||
export const pvs = makeFunction('pvs')
|
||||
48
src/math.js
Normal file
48
src/math.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import assign from 'lodash/assign'
|
||||
|
||||
const _combine = (vectors, n, cb) => {
|
||||
if (!n) {
|
||||
return
|
||||
}
|
||||
|
||||
const nLast = n - 1
|
||||
|
||||
const vector = vectors[nLast]
|
||||
const m = vector.length
|
||||
if (n === 1) {
|
||||
for (let i = 0; i < m; ++i) {
|
||||
cb([ vector[i] ]) // eslint-disable-line standard/no-callback-literal
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for (let i = 0; i < m; ++i) {
|
||||
const value = vector[i]
|
||||
|
||||
_combine(vectors, nLast, (vector) => {
|
||||
vector.push(value)
|
||||
cb(vector)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Compute all combinations from vectors.
|
||||
//
|
||||
// Ex: combine([[2, 3], [5, 7]])
|
||||
// => [ [ 2, 5 ], [ 3, 5 ], [ 2, 7 ], [ 3, 7 ] ]
|
||||
export const combine = vectors => cb => _combine(vectors, vectors.length, cb)
|
||||
|
||||
// Merge the properties of an objects set in one object.
|
||||
//
|
||||
// Ex: mergeObjects([ { a: 1 }, { b: 2 } ]) => { a: 1, b: 2 }
|
||||
export const mergeObjects = objects => assign({}, ...objects)
|
||||
|
||||
// Compute a cross product between vectors.
|
||||
//
|
||||
// Ex: crossProduct([ [ { a: 2 }, { b: 3 } ], [ { c: 5 }, { d: 7 } ] ] )
|
||||
// => [ { a: 2, c: 5 }, { b: 3, c: 5 }, { a: 2, d: 7 }, { b: 3, d: 7 } ]
|
||||
export const crossProduct = (vectors, mergeFn = mergeObjects) => cb => (
|
||||
combine(vectors)(vector => {
|
||||
cb(mergeFn(vector))
|
||||
})
|
||||
)
|
||||
74
src/math.spec.js
Normal file
74
src/math.spec.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/* eslint-env jest */
|
||||
|
||||
import { forEach } from 'lodash'
|
||||
import { thunkToArray } from './utils'
|
||||
import {
|
||||
crossProduct,
|
||||
mergeObjects
|
||||
} from './math'
|
||||
|
||||
describe('mergeObjects', function () {
|
||||
forEach({
|
||||
'Two sets of one': [
|
||||
{a: 1, b: 2}, {a: 1}, {b: 2}
|
||||
],
|
||||
'Two sets of two': [
|
||||
{a: 1, b: 2, c: 3, d: 4}, {a: 1, b: 2}, {c: 3, d: 4}
|
||||
],
|
||||
'Three sets': [
|
||||
{a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}, {a: 1}, {b: 2, c: 3}, {d: 4, e: 5, f: 6}
|
||||
],
|
||||
'One set': [
|
||||
{a: 1, b: 2}, {a: 1, b: 2}
|
||||
],
|
||||
'Empty set': [
|
||||
{a: 1}, {a: 1}, {}
|
||||
],
|
||||
'All empty': [
|
||||
{}, {}, {}
|
||||
],
|
||||
'No set': [
|
||||
{}
|
||||
]
|
||||
}, ([ resultSet, ...sets ], name) => {
|
||||
describe(`with ${name}`, () => {
|
||||
it('Assembles all given param sets in on set', function () {
|
||||
expect(mergeObjects(sets)).toEqual(resultSet)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('crossProduct', function () {
|
||||
// Gives the sum of all args
|
||||
const addTest = args => args.reduce((prev, curr) => prev + curr, 0)
|
||||
// Gives the product of all args
|
||||
const multiplyTest = args => args.reduce((prev, curr) => prev * curr, 1)
|
||||
|
||||
forEach({
|
||||
'2 sets of 2 items to multiply': [
|
||||
[10, 14, 15, 21], [[2, 3], [5, 7]], multiplyTest
|
||||
],
|
||||
'3 sets of 2 items to multiply': [
|
||||
[110, 130, 154, 182, 165, 195, 231, 273], [[2, 3], [5, 7], [11, 13]], multiplyTest
|
||||
],
|
||||
'2 sets of 3 items to multiply': [
|
||||
[14, 22, 26, 21, 33, 39, 35, 55, 65], [[2, 3, 5], [7, 11, 13]], multiplyTest
|
||||
],
|
||||
'2 sets of 2 items to add': [
|
||||
[7, 9, 8, 10], [[2, 3], [5, 7]], addTest
|
||||
],
|
||||
'3 sets of 2 items to add': [
|
||||
[18, 20, 20, 22, 19, 21, 21, 23], [[2, 3], [5, 7], [11, 13]], addTest
|
||||
],
|
||||
'2 sets of 3 items to add': [
|
||||
[9, 13, 15, 10, 14, 16, 12, 16, 18], [[2, 3, 5], [7, 11, 13]], addTest
|
||||
]
|
||||
}, ([ product, items, cb ], name) => {
|
||||
describe(`with ${name}`, () => {
|
||||
it('Crosses sets of values with a crossProduct callback', function () {
|
||||
expect(thunkToArray(crossProduct(items, cb)).sort()).toEqual(product.sort())
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
13
src/model.js
13
src/model.js
@@ -1,15 +1,18 @@
|
||||
import assign from 'lodash.assign'
|
||||
import forEach from 'lodash.foreach'
|
||||
import isEmpty from 'lodash.isempty'
|
||||
import {EventEmitter} from 'events'
|
||||
|
||||
import {
|
||||
forEach,
|
||||
isEmpty,
|
||||
isString
|
||||
} from './utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class Model extends EventEmitter {
|
||||
constructor (properties) {
|
||||
super()
|
||||
|
||||
this.properties = assign({}, this.default)
|
||||
this.properties = { ...this.default }
|
||||
|
||||
if (properties) {
|
||||
this.set(properties)
|
||||
@@ -39,7 +42,7 @@ export default class Model extends EventEmitter {
|
||||
set (properties, value) {
|
||||
// This method can also be used with two arguments to set a single
|
||||
// property.
|
||||
if (value !== undefined) {
|
||||
if (isString(properties)) {
|
||||
properties = { [properties]: value }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import forEach from 'lodash.foreach'
|
||||
import map from 'lodash.map'
|
||||
|
||||
import Collection from '../collection/redis'
|
||||
import Model from '../model'
|
||||
import {multiKeyHash} from '../utils'
|
||||
import {
|
||||
forEach,
|
||||
mapToArray,
|
||||
multiKeyHash
|
||||
} from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@@ -58,11 +59,11 @@ export class Acls extends Collection {
|
||||
})
|
||||
if (toUpdate.length) {
|
||||
// Removes all existing entries.
|
||||
await this.remove(map(toUpdate, 'id'))
|
||||
await this.remove(mapToArray(toUpdate, 'id'))
|
||||
|
||||
// Compute the new ids (new hashes).
|
||||
const {hash} = Acl
|
||||
await Promise.all(map(
|
||||
await Promise.all(mapToArray(
|
||||
toUpdate,
|
||||
(acl) => hash(acl.subject, acl.object, acl.action).then(id => {
|
||||
acl.id = id
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import forEach from 'lodash.foreach'
|
||||
import isEmpty from 'lodash/isEmpty'
|
||||
|
||||
import Collection from '../collection/redis'
|
||||
import Model from '../model'
|
||||
|
||||
import { forEach } from '../utils'
|
||||
|
||||
import { parseProp } from './utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class Group extends Model {}
|
||||
@@ -14,22 +18,18 @@ export class Groups extends Collection {
|
||||
return Group
|
||||
}
|
||||
|
||||
get idPrefix () {
|
||||
return 'group:'
|
||||
}
|
||||
|
||||
create (name) {
|
||||
return this.add(new Group({
|
||||
name,
|
||||
users: '[]'
|
||||
}))
|
||||
return this.add(new Group({ name }))
|
||||
}
|
||||
|
||||
async save (group) {
|
||||
// Serializes.
|
||||
group.users = JSON.stringify(group.users)
|
||||
let tmp
|
||||
group.users = isEmpty(tmp = group.users)
|
||||
? undefined
|
||||
: JSON.stringify(tmp)
|
||||
|
||||
return await this.update(group)
|
||||
return /* await */ this.update(group)
|
||||
}
|
||||
|
||||
async get (properties) {
|
||||
@@ -37,13 +37,7 @@ export class Groups extends Collection {
|
||||
|
||||
// Deserializes.
|
||||
forEach(groups, group => {
|
||||
const {users} = group
|
||||
try {
|
||||
group.users = JSON.parse(users)
|
||||
} catch (error) {
|
||||
console.warn('cannot parse group.users:', users)
|
||||
group.users = []
|
||||
}
|
||||
group.users = parseProp('group', group, 'users', [])
|
||||
})
|
||||
|
||||
return groups
|
||||
|
||||
42
src/models/job.js
Normal file
42
src/models/job.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import Collection from '../collection/redis'
|
||||
import Model from '../model'
|
||||
import { forEach } from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class Job extends Model {}
|
||||
|
||||
export class Jobs extends Collection {
|
||||
get Model () {
|
||||
return Job
|
||||
}
|
||||
|
||||
async create (job) {
|
||||
// Serializes.
|
||||
job.paramsVector = JSON.stringify(job.paramsVector)
|
||||
return /* await */ this.add(new Job(job))
|
||||
}
|
||||
|
||||
async save (job) {
|
||||
// Serializes.
|
||||
job.paramsVector = JSON.stringify(job.paramsVector)
|
||||
return /* await */ this.update(job)
|
||||
}
|
||||
|
||||
async get (properties) {
|
||||
const jobs = await super.get(properties)
|
||||
|
||||
// Deserializes.
|
||||
forEach(jobs, job => {
|
||||
const {paramsVector} = job
|
||||
try {
|
||||
job.paramsVector = JSON.parse(paramsVector)
|
||||
} catch (error) {
|
||||
console.warn('cannot parse job.paramsVector:', paramsVector) // FIXME this is a warning as I copy/paste acl.js, but...
|
||||
job.paramsVector = {}
|
||||
}
|
||||
})
|
||||
|
||||
return jobs
|
||||
}
|
||||
}
|
||||
53
src/models/plugin-metadata.js
Normal file
53
src/models/plugin-metadata.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import Collection from '../collection/redis'
|
||||
import Model from '../model'
|
||||
import { forEach } from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class PluginMetadata extends Model {}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export class PluginsMetadata extends Collection {
|
||||
get Model () {
|
||||
return PluginMetadata
|
||||
}
|
||||
|
||||
async save ({ id, autoload, configuration }) {
|
||||
return /* await */ this.update({
|
||||
id,
|
||||
autoload: autoload ? 'true' : 'false',
|
||||
configuration: configuration && JSON.stringify(configuration)
|
||||
})
|
||||
}
|
||||
|
||||
async merge (id, data) {
|
||||
const pluginMetadata = await this.first(id)
|
||||
if (!pluginMetadata) {
|
||||
throw new Error('no such plugin metadata')
|
||||
}
|
||||
|
||||
return /* await */ this.save({
|
||||
...pluginMetadata.properties,
|
||||
...data
|
||||
})
|
||||
}
|
||||
|
||||
async get (properties) {
|
||||
const pluginsMetadata = await super.get(properties)
|
||||
|
||||
// Deserializes.
|
||||
forEach(pluginsMetadata, pluginMetadata => {
|
||||
const { autoload, configuration } = pluginMetadata
|
||||
pluginMetadata.autoload = autoload === 'true'
|
||||
try {
|
||||
pluginMetadata.configuration = configuration && JSON.parse(configuration)
|
||||
} catch (error) {
|
||||
console.warn('cannot parse pluginMetadata.configuration:', configuration)
|
||||
pluginMetadata.configuration = []
|
||||
}
|
||||
})
|
||||
|
||||
return pluginsMetadata
|
||||
}
|
||||
}
|
||||
36
src/models/remote.js
Normal file
36
src/models/remote.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import Collection from '../collection/redis'
|
||||
import Model from '../model'
|
||||
import {
|
||||
forEach
|
||||
} from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class Remote extends Model {}
|
||||
|
||||
export class Remotes extends Collection {
|
||||
get Model () {
|
||||
return Remote
|
||||
}
|
||||
|
||||
create (name, url) {
|
||||
return this.add(new Remote({
|
||||
name,
|
||||
url,
|
||||
enabled: false,
|
||||
error: ''
|
||||
}))
|
||||
}
|
||||
|
||||
async save (remote) {
|
||||
return /* await */ this.update(remote)
|
||||
}
|
||||
|
||||
async get (properties) {
|
||||
const remotes = await super.get(properties)
|
||||
forEach(remotes, remote => {
|
||||
remote.enabled = (remote.enabled === 'true')
|
||||
})
|
||||
return remotes
|
||||
}
|
||||
}
|
||||
36
src/models/schedule.js
Normal file
36
src/models/schedule.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import Collection from '../collection/redis'
|
||||
import Model from '../model'
|
||||
import { forEach } from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class Schedule extends Model {}
|
||||
|
||||
export class Schedules extends Collection {
|
||||
get Model () {
|
||||
return Schedule
|
||||
}
|
||||
|
||||
create (userId, job, cron, enabled, name = undefined, timezone = undefined) {
|
||||
return this.add(new Schedule({
|
||||
userId,
|
||||
job,
|
||||
cron,
|
||||
enabled,
|
||||
name,
|
||||
timezone
|
||||
}))
|
||||
}
|
||||
|
||||
async save (schedule) {
|
||||
return /* await */ this.update(schedule)
|
||||
}
|
||||
|
||||
async get (properties) {
|
||||
const schedules = await super.get(properties)
|
||||
forEach(schedules, schedule => {
|
||||
schedule.enabled = (schedule.enabled === 'true')
|
||||
})
|
||||
return schedules
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import Collection from '../collection/redis'
|
||||
import Model from '../model'
|
||||
import { forEach } from '../utils'
|
||||
|
||||
import { parseProp } from './utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@@ -11,4 +14,27 @@ export class Servers extends Collection {
|
||||
get Model () {
|
||||
return Server
|
||||
}
|
||||
|
||||
async create ({label, host, username, password, readOnly}) {
|
||||
if (await this.exists({host})) {
|
||||
throw new Error('server already exists')
|
||||
}
|
||||
|
||||
return /* await */ this.add({label, host, username, password, readOnly})
|
||||
}
|
||||
|
||||
async get (properties) {
|
||||
const servers = await super.get(properties)
|
||||
|
||||
// Deserializes
|
||||
forEach(servers, server => {
|
||||
if (server.error) {
|
||||
server.error = parseProp('server', server, 'error', '')
|
||||
} else {
|
||||
delete server.error
|
||||
}
|
||||
})
|
||||
|
||||
return servers
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,10 @@
|
||||
import Collection from '../collection/redis'
|
||||
import Model from '../model'
|
||||
import {generateToken} from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class Token extends Model {}
|
||||
|
||||
Token.generate = (userId) => {
|
||||
return generateToken().then(token => new Token({
|
||||
id: token,
|
||||
user_id: userId
|
||||
}))
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export class Tokens extends Collection {
|
||||
get Model () {
|
||||
return Token
|
||||
}
|
||||
|
||||
generate (userId) {
|
||||
return Token.generate(userId).then(token => this.add(token))
|
||||
}
|
||||
}
|
||||
export class Tokens extends Collection {}
|
||||
|
||||
@@ -1,47 +1,14 @@
|
||||
import forEach from 'lodash.foreach'
|
||||
import {hash, needsRehash, verify} from 'hashy'
|
||||
import isEmpty from 'lodash/isEmpty'
|
||||
|
||||
import Collection from '../collection/redis'
|
||||
import Model from '../model'
|
||||
import { forEach } from '../utils'
|
||||
|
||||
import { parseProp } from './utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const PERMISSIONS = {
|
||||
none: 0,
|
||||
read: 1,
|
||||
write: 2,
|
||||
admin: 3
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default class User extends Model {
|
||||
async checkPassword (password) {
|
||||
const hash = this.get('pw_hash')
|
||||
|
||||
if (!(hash && await verify(password, hash))) {
|
||||
return false
|
||||
}
|
||||
|
||||
// There might be no hash if the user authenticate with another
|
||||
// method (e.g. LDAP).
|
||||
if (needsRehash(hash)) {
|
||||
await this.setPassword(password)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
hasPermission (permission) {
|
||||
return PERMISSIONS[this.get('permission')] >= PERMISSIONS[permission]
|
||||
}
|
||||
|
||||
setPassword (password) {
|
||||
return hash(password).then(hash => {
|
||||
return this.set('pw_hash', hash)
|
||||
})
|
||||
}
|
||||
}
|
||||
export default class User extends Model {}
|
||||
|
||||
User.prototype.default = {
|
||||
permission: 'none'
|
||||
@@ -54,24 +21,32 @@ export class Users extends Collection {
|
||||
return User
|
||||
}
|
||||
|
||||
async create (email, password, permission = 'none') {
|
||||
const user = new User({
|
||||
email,
|
||||
permission
|
||||
})
|
||||
async create (properties) {
|
||||
const { email } = properties
|
||||
|
||||
if (password != null) {
|
||||
await user.setPassword(password)
|
||||
// Avoid duplicates.
|
||||
if (await this.exists({email})) {
|
||||
throw new Error(`the user ${email} already exists`)
|
||||
}
|
||||
|
||||
return this.add(user)
|
||||
// Create the user object.
|
||||
const user = new User(properties)
|
||||
|
||||
// Adds the user to the collection.
|
||||
return /* await */ this.add(user)
|
||||
}
|
||||
|
||||
async save (user) {
|
||||
// Serializes.
|
||||
user.groups = JSON.stringify(user.groups)
|
||||
let tmp
|
||||
user.groups = isEmpty(tmp = user.groups)
|
||||
? undefined
|
||||
: JSON.stringify(tmp)
|
||||
user.preferences = isEmpty(tmp = user.preferences)
|
||||
? undefined
|
||||
: JSON.stringify(tmp)
|
||||
|
||||
return await this.update(user)
|
||||
return /* await */ this.update(user)
|
||||
}
|
||||
|
||||
async get (properties) {
|
||||
@@ -79,13 +54,8 @@ export class Users extends Collection {
|
||||
|
||||
// Deserializes
|
||||
forEach(users, user => {
|
||||
const {groups} = user
|
||||
try {
|
||||
user.groups = groups ? JSON.parse(groups) : []
|
||||
} catch (_) {
|
||||
console.warn('cannot parse user.groups:', groups)
|
||||
user.groups = []
|
||||
}
|
||||
user.groups = parseProp('user', user, 'groups', [])
|
||||
user.preferences = parseProp('user', user, 'preferences', {})
|
||||
})
|
||||
|
||||
return users
|
||||
|
||||
16
src/models/utils.js
Normal file
16
src/models/utils.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export const parseProp = (type, obj, name, defaultValue) => {
|
||||
const value = obj[name]
|
||||
if (
|
||||
value == null ||
|
||||
value === '' // do not warn on this trivial and minor error
|
||||
) {
|
||||
return defaultValue
|
||||
}
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
} catch (error) {
|
||||
// do not display the error because it can occurs a lot and fill
|
||||
// up log files
|
||||
return defaultValue
|
||||
}
|
||||
}
|
||||
42
src/node_modules/constant-stream.js
generated
vendored
Normal file
42
src/node_modules/constant-stream.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import from2 from 'from2'
|
||||
|
||||
const constantStream = (data, n = 1) => {
|
||||
if (!Buffer.isBuffer(data)) {
|
||||
data = Buffer.from(data)
|
||||
}
|
||||
|
||||
const { length } = data
|
||||
|
||||
if (!length) {
|
||||
throw new Error('data should not be empty')
|
||||
}
|
||||
|
||||
n *= length
|
||||
let currentLength = length
|
||||
|
||||
return from2((size, next) => {
|
||||
if (n <= 0) {
|
||||
return next(null, null)
|
||||
}
|
||||
|
||||
if (n < size) {
|
||||
size = n
|
||||
}
|
||||
|
||||
if (size < currentLength) {
|
||||
const m = Math.floor(size / length) * length || length
|
||||
n -= m
|
||||
return next(null, data.slice(0, m))
|
||||
}
|
||||
|
||||
// if more than twice the data length is requested, repeat the data
|
||||
if (size > currentLength * 2) {
|
||||
currentLength = Math.floor(size / length) * length
|
||||
data = Buffer.alloc(currentLength, data)
|
||||
}
|
||||
|
||||
n -= currentLength
|
||||
return next(null, data)
|
||||
})
|
||||
}
|
||||
export { constantStream as default }
|
||||
76
src/proxy-console.js
Normal file
76
src/proxy-console.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import createDebug from 'debug'
|
||||
import partialStream from 'partial-stream'
|
||||
import {connect} from 'tls'
|
||||
import {parse} from 'url'
|
||||
|
||||
const debug = createDebug('xo:proxy-console')
|
||||
|
||||
export default function proxyConsole (ws, vmConsole, sessionId) {
|
||||
const url = parse(vmConsole.location)
|
||||
|
||||
let closed = false
|
||||
|
||||
const socket = connect({
|
||||
host: url.host,
|
||||
port: url.port || 443,
|
||||
rejectUnauthorized: false
|
||||
}, () => {
|
||||
// Write headers.
|
||||
socket.write([
|
||||
`CONNECT ${url.path} HTTP/1.0`,
|
||||
`Host: ${url.hostname}`,
|
||||
`Cookie: session_id=${sessionId}`,
|
||||
'', ''
|
||||
].join('\r\n'))
|
||||
|
||||
const onSend = (error) => {
|
||||
if (error) {
|
||||
debug('error sending to the XO client: %s', error.stack || error.message || error)
|
||||
}
|
||||
}
|
||||
|
||||
socket.pipe(partialStream('\r\n\r\n', headers => {
|
||||
// TODO: check status code 200.
|
||||
debug('connected')
|
||||
})).on('data', data => {
|
||||
if (!closed) {
|
||||
// Encode to base 64.
|
||||
ws.send(data.toString('base64'), onSend)
|
||||
}
|
||||
}).on('end', () => {
|
||||
if (!closed) {
|
||||
closed = true
|
||||
debug('disconnected from the console')
|
||||
}
|
||||
|
||||
ws.close()
|
||||
})
|
||||
|
||||
ws
|
||||
.on('error', error => {
|
||||
closed = true
|
||||
debug('error from the XO client: %s', error.stack || error.message || error)
|
||||
|
||||
socket.close()
|
||||
})
|
||||
.on('message', data => {
|
||||
if (!closed) {
|
||||
// Decode from base 64.
|
||||
socket.write(Buffer.from(data, 'base64'))
|
||||
}
|
||||
})
|
||||
.on('close', () => {
|
||||
if (!closed) {
|
||||
closed = true
|
||||
debug('disconnected from the XO client')
|
||||
}
|
||||
|
||||
socket.end()
|
||||
})
|
||||
}).on('error', error => {
|
||||
closed = true
|
||||
debug('error from the console: %s', error.stack || error.message || error)
|
||||
|
||||
ws.close()
|
||||
})
|
||||
}
|
||||
226
src/remote-handlers/abstract.js
Normal file
226
src/remote-handlers/abstract.js
Normal file
@@ -0,0 +1,226 @@
|
||||
import eventToPromise from 'event-to-promise'
|
||||
import through2 from 'through2'
|
||||
|
||||
import {
|
||||
parse
|
||||
} from 'xo-remote-parser'
|
||||
|
||||
import {
|
||||
addChecksumToReadStream,
|
||||
getPseudoRandomBytes,
|
||||
noop,
|
||||
pCatch,
|
||||
streamToBuffer,
|
||||
validChecksumOfReadStream
|
||||
} from '../utils'
|
||||
|
||||
export default class RemoteHandlerAbstract {
|
||||
constructor (remote) {
|
||||
this._remote = {...remote, ...parse(remote.url)}
|
||||
if (this._remote.type !== this.type) {
|
||||
throw new Error('Incorrect remote type')
|
||||
}
|
||||
}
|
||||
|
||||
get type () {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the handler to sync the state of the effective remote with its' metadata
|
||||
*/
|
||||
async sync () {
|
||||
return this._sync()
|
||||
}
|
||||
|
||||
async _sync () {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the resources possibly dedicated to put the remote at work, when it is no more needed
|
||||
*/
|
||||
async forget () {
|
||||
return this._forget()
|
||||
}
|
||||
|
||||
async _forget () {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
async test () {
|
||||
const testFileName = `${Date.now()}.test`
|
||||
const data = getPseudoRandomBytes(1024 * 1024)
|
||||
let step = 'write'
|
||||
try {
|
||||
await this.outputFile(testFileName, data)
|
||||
step = 'read'
|
||||
const read = await this.readFile(testFileName)
|
||||
if (data.compare(read) !== 0) {
|
||||
throw new Error('output and input did not match')
|
||||
}
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
step,
|
||||
file: testFileName,
|
||||
error: error.message || String(error)
|
||||
}
|
||||
} finally {
|
||||
this.unlink(testFileName).catch(noop)
|
||||
}
|
||||
}
|
||||
|
||||
async outputFile (file, data, options) {
|
||||
return this._outputFile(file, data, {
|
||||
flags: 'wx',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
async _outputFile (file, data, options) {
|
||||
const stream = await this.createOutputStream(file, options)
|
||||
const promise = eventToPromise(stream, 'finish')
|
||||
stream.end(data)
|
||||
return promise
|
||||
}
|
||||
|
||||
async readFile (file, options) {
|
||||
return this._readFile(file, options)
|
||||
}
|
||||
|
||||
_readFile (file, options) {
|
||||
return this.createReadStream(file, options).then(streamToBuffer)
|
||||
}
|
||||
|
||||
async rename (oldPath, newPath) {
|
||||
return this._rename(oldPath, newPath)
|
||||
}
|
||||
|
||||
async _rename (oldPath, newPath) {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
async list (dir = '.') {
|
||||
return this._list(dir)
|
||||
}
|
||||
|
||||
async _list (dir) {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
createReadStream (file, {
|
||||
checksum = false,
|
||||
ignoreMissingChecksum = false,
|
||||
...options
|
||||
} = {}) {
|
||||
const streamP = this._createReadStream(file, options).then(stream => {
|
||||
// detect early errors
|
||||
let promise = eventToPromise(stream, 'readable')
|
||||
|
||||
// try to add the length prop if missing and not a range stream
|
||||
if (
|
||||
stream.length === undefined &&
|
||||
options.end === undefined &&
|
||||
options.start === undefined
|
||||
) {
|
||||
promise = Promise.all([ promise, this.getSize(file).then(size => {
|
||||
stream.length = size
|
||||
}, noop) ])
|
||||
}
|
||||
|
||||
return promise.then(() => stream)
|
||||
})
|
||||
|
||||
if (!checksum) {
|
||||
return streamP
|
||||
}
|
||||
|
||||
// avoid a unhandled rejection warning
|
||||
streamP.catch(noop)
|
||||
|
||||
return this.readFile(`${file}.checksum`).then(
|
||||
checksum => streamP.then(stream => {
|
||||
const { length } = stream
|
||||
stream = validChecksumOfReadStream(stream, String(checksum).trim())
|
||||
stream.length = length
|
||||
|
||||
return stream
|
||||
}),
|
||||
error => {
|
||||
if (ignoreMissingChecksum && error && error.code === 'ENOENT') {
|
||||
return streamP
|
||||
}
|
||||
throw error
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async _createReadStream (file, options) {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
async refreshChecksum (path) {
|
||||
const stream = addChecksumToReadStream(await this.createReadStream(path))
|
||||
stream.resume() // start reading the whole file
|
||||
const checksum = await stream.checksum
|
||||
await this.outputFile(`${path}.checksum`, checksum)
|
||||
}
|
||||
|
||||
async createOutputStream (file, {
|
||||
checksum = false,
|
||||
...options
|
||||
} = {}) {
|
||||
const streamP = this._createOutputStream(file, {
|
||||
flags: 'wx',
|
||||
...options
|
||||
})
|
||||
|
||||
if (!checksum) {
|
||||
return streamP
|
||||
}
|
||||
|
||||
const connectorStream = through2()
|
||||
const forwardError = error => {
|
||||
connectorStream.emit('error', error)
|
||||
}
|
||||
|
||||
const streamWithChecksum = addChecksumToReadStream(connectorStream)
|
||||
streamWithChecksum.pipe(await streamP)
|
||||
|
||||
streamWithChecksum.checksum
|
||||
.then(value => this.outputFile(`${file}.checksum`, value))
|
||||
.catch(forwardError)
|
||||
|
||||
return connectorStream
|
||||
}
|
||||
|
||||
async _createOutputStream (file, options) {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
async unlink (file, {
|
||||
checksum = false
|
||||
} = {}) {
|
||||
if (checksum) {
|
||||
this._unlink(`${file}.checksum`)::pCatch(noop)
|
||||
}
|
||||
|
||||
return this._unlink(file)
|
||||
}
|
||||
|
||||
async _unlink (file) {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
async getSize (file) {
|
||||
return this._getSize(file)
|
||||
}
|
||||
|
||||
async _getSize (file) {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
}
|
||||
89
src/remote-handlers/local.js
Normal file
89
src/remote-handlers/local.js
Normal file
@@ -0,0 +1,89 @@
|
||||
import fs from 'fs-promise'
|
||||
import startsWith from 'lodash/startsWith'
|
||||
import {
|
||||
dirname,
|
||||
resolve
|
||||
} from 'path'
|
||||
|
||||
import RemoteHandlerAbstract from './abstract'
|
||||
import {
|
||||
noop
|
||||
} from '../utils'
|
||||
|
||||
export default class LocalHandler extends RemoteHandlerAbstract {
|
||||
get type () {
|
||||
return 'file'
|
||||
}
|
||||
|
||||
_getRealPath () {
|
||||
return this._remote.path
|
||||
}
|
||||
|
||||
_getFilePath (file) {
|
||||
const realPath = this._getRealPath()
|
||||
const parts = [realPath]
|
||||
if (file) {
|
||||
parts.push(file)
|
||||
}
|
||||
const path = resolve.apply(null, parts)
|
||||
if (!startsWith(path, realPath)) {
|
||||
throw new Error('Remote path is unavailable')
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
async _sync () {
|
||||
if (this._remote.enabled) {
|
||||
try {
|
||||
const path = this._getRealPath()
|
||||
await fs.ensureDir(path)
|
||||
await fs.access(path, fs.R_OK | fs.W_OK)
|
||||
} catch (exc) {
|
||||
this._remote.enabled = false
|
||||
this._remote.error = exc.message
|
||||
}
|
||||
}
|
||||
return this._remote
|
||||
}
|
||||
|
||||
async _forget () {
|
||||
return noop()
|
||||
}
|
||||
|
||||
async _outputFile (file, data, options) {
|
||||
const path = this._getFilePath(file)
|
||||
await fs.ensureDir(dirname(path))
|
||||
await fs.writeFile(path, data, options)
|
||||
}
|
||||
|
||||
async _readFile (file, options) {
|
||||
return fs.readFile(this._getFilePath(file), options)
|
||||
}
|
||||
|
||||
async _rename (oldPath, newPath) {
|
||||
return fs.rename(this._getFilePath(oldPath), this._getFilePath(newPath))
|
||||
}
|
||||
|
||||
async _list (dir = '.') {
|
||||
return fs.readdir(this._getFilePath(dir))
|
||||
}
|
||||
|
||||
async _createReadStream (file, options) {
|
||||
return fs.createReadStream(this._getFilePath(file), options)
|
||||
}
|
||||
|
||||
async _createOutputStream (file, options) {
|
||||
const path = this._getFilePath(file)
|
||||
await fs.ensureDir(dirname(path))
|
||||
return fs.createWriteStream(path, options)
|
||||
}
|
||||
|
||||
async _unlink (file) {
|
||||
return fs.unlink(this._getFilePath(file))
|
||||
}
|
||||
|
||||
async _getSize (file) {
|
||||
const stats = await fs.stat(this._getFilePath(file))
|
||||
return stats.size
|
||||
}
|
||||
}
|
||||
84
src/remote-handlers/nfs.js
Normal file
84
src/remote-handlers/nfs.js
Normal file
@@ -0,0 +1,84 @@
|
||||
import execa from 'execa'
|
||||
import fs from 'fs-promise'
|
||||
|
||||
import LocalHandler from './local'
|
||||
import {
|
||||
forEach
|
||||
} from '../utils'
|
||||
|
||||
export default class NfsHandler extends LocalHandler {
|
||||
get type () {
|
||||
return 'nfs'
|
||||
}
|
||||
|
||||
_getRealPath () {
|
||||
return `/run/xo-server/mounts/${this._remote.id}`
|
||||
}
|
||||
|
||||
async _loadRealMounts () {
|
||||
let stdout
|
||||
const mounted = {}
|
||||
try {
|
||||
stdout = await execa.stdout('findmnt', ['-P', '-t', 'nfs,nfs4', '--output', 'SOURCE,TARGET', '--noheadings'])
|
||||
const regex = /^SOURCE="([^:]*):(.*)" TARGET="(.*)"$/
|
||||
forEach(stdout.split('\n'), m => {
|
||||
if (m) {
|
||||
const match = regex.exec(m)
|
||||
mounted[match[3]] = {
|
||||
host: match[1],
|
||||
share: match[2]
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (exc) {
|
||||
// When no mounts are found, the call pretends to fail...
|
||||
if (exc.stderr !== '') {
|
||||
throw exc
|
||||
}
|
||||
}
|
||||
|
||||
this._realMounts = mounted
|
||||
return mounted
|
||||
}
|
||||
|
||||
_matchesRealMount () {
|
||||
return this._getRealPath() in this._realMounts
|
||||
}
|
||||
|
||||
async _mount () {
|
||||
await fs.ensureDir(this._getRealPath())
|
||||
return execa('mount', ['-t', 'nfs', '-o', 'vers=3', `${this._remote.host}:${this._remote.path}`, this._getRealPath()])
|
||||
}
|
||||
|
||||
async _sync () {
|
||||
await this._loadRealMounts()
|
||||
if (this._matchesRealMount() && !this._remote.enabled) {
|
||||
try {
|
||||
await this._umount(this._remote)
|
||||
} catch (exc) {
|
||||
this._remote.enabled = true
|
||||
this._remote.error = exc.message
|
||||
}
|
||||
} else if (!this._matchesRealMount() && this._remote.enabled) {
|
||||
try {
|
||||
await this._mount()
|
||||
} catch (exc) {
|
||||
this._remote.enabled = false
|
||||
this._remote.error = exc.message
|
||||
}
|
||||
}
|
||||
return this._remote
|
||||
}
|
||||
|
||||
async _forget () {
|
||||
try {
|
||||
await this._umount(this._remote)
|
||||
} catch (_) {
|
||||
// We have to go on...
|
||||
}
|
||||
}
|
||||
|
||||
async _umount (remote) {
|
||||
await execa('umount', [this._getRealPath()])
|
||||
}
|
||||
}
|
||||
191
src/remote-handlers/smb.js
Normal file
191
src/remote-handlers/smb.js
Normal file
@@ -0,0 +1,191 @@
|
||||
import Smb2 from '@marsaud/smb2-promise'
|
||||
|
||||
import RemoteHandlerAbstract from './abstract'
|
||||
import {
|
||||
noop,
|
||||
pFinally
|
||||
} from '../utils'
|
||||
|
||||
// Normalize the error code for file not found.
|
||||
const normalizeError = error => {
|
||||
const { code } = error
|
||||
|
||||
return (
|
||||
code === 'STATUS_OBJECT_NAME_NOT_FOUND' ||
|
||||
code === 'STATUS_OBJECT_PATH_NOT_FOUND'
|
||||
)
|
||||
? Object.create(error, {
|
||||
code: {
|
||||
configurable: true,
|
||||
readable: true,
|
||||
value: 'ENOENT',
|
||||
writable: true
|
||||
}
|
||||
})
|
||||
: error
|
||||
}
|
||||
|
||||
export default class SmbHandler extends RemoteHandlerAbstract {
|
||||
constructor (remote) {
|
||||
super(remote)
|
||||
this._forget = noop
|
||||
}
|
||||
|
||||
get type () {
|
||||
return 'smb'
|
||||
}
|
||||
|
||||
_getClient (remote) {
|
||||
return new Smb2({
|
||||
share: `\\\\${remote.host}`,
|
||||
domain: remote.domain,
|
||||
username: remote.username,
|
||||
password: remote.password,
|
||||
autoCloseTimeout: 0
|
||||
})
|
||||
}
|
||||
|
||||
_getFilePath (file) {
|
||||
if (file === '.') {
|
||||
file = undefined
|
||||
}
|
||||
|
||||
let path = (this._remote.path !== '')
|
||||
? this._remote.path
|
||||
: ''
|
||||
|
||||
// Ensure remote path is a directory.
|
||||
if (path !== '' && path[path.length - 1] !== '\\') {
|
||||
path += '\\'
|
||||
}
|
||||
|
||||
if (file) {
|
||||
path += file.replace(/\//g, '\\')
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
_dirname (file) {
|
||||
const parts = file.split('\\')
|
||||
parts.pop()
|
||||
return parts.join('\\')
|
||||
}
|
||||
|
||||
async _sync () {
|
||||
if (this._remote.enabled) {
|
||||
try {
|
||||
// Check access (smb2 does not expose connect in public so far...)
|
||||
await this.list()
|
||||
} catch (error) {
|
||||
this._remote.enabled = false
|
||||
this._remote.error = error.message
|
||||
}
|
||||
}
|
||||
return this._remote
|
||||
}
|
||||
|
||||
async _outputFile (file, data, options = {}) {
|
||||
const client = this._getClient(this._remote)
|
||||
const path = this._getFilePath(file)
|
||||
const dir = this._dirname(path)
|
||||
|
||||
if (dir) {
|
||||
await client.ensureDir(dir)
|
||||
}
|
||||
|
||||
return client.writeFile(path, data, options)::pFinally(() => { client.close() })
|
||||
}
|
||||
|
||||
async _readFile (file, options = {}) {
|
||||
const client = this._getClient(this._remote)
|
||||
let content
|
||||
|
||||
try {
|
||||
content = await client.readFile(this._getFilePath(file), options)::pFinally(() => { client.close() })
|
||||
} catch (error) {
|
||||
throw normalizeError(error)
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
async _rename (oldPath, newPath) {
|
||||
const client = this._getClient(this._remote)
|
||||
|
||||
try {
|
||||
await client.rename(this._getFilePath(oldPath), this._getFilePath(newPath))::pFinally(() => { client.close() })
|
||||
} catch (error) {
|
||||
throw normalizeError(error)
|
||||
}
|
||||
}
|
||||
|
||||
async _list (dir = '.') {
|
||||
const client = this._getClient(this._remote)
|
||||
let list
|
||||
|
||||
try {
|
||||
list = await client.readdir(this._getFilePath(dir))::pFinally(() => { client.close() })
|
||||
} catch (error) {
|
||||
throw normalizeError(error)
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
async _createReadStream (file, options = {}) {
|
||||
const client = this._getClient(this._remote)
|
||||
let stream
|
||||
|
||||
try {
|
||||
// FIXME ensure that options are properly handled by @marsaud/smb2
|
||||
stream = await client.createReadStream(this._getFilePath(file), options)
|
||||
stream.on('end', () => client.close())
|
||||
} catch (error) {
|
||||
throw normalizeError(error)
|
||||
}
|
||||
|
||||
return stream
|
||||
}
|
||||
|
||||
async _createOutputStream (file, options = {}) {
|
||||
const client = this._getClient(this._remote)
|
||||
const path = this._getFilePath(file)
|
||||
const dir = this._dirname(path)
|
||||
let stream
|
||||
try {
|
||||
if (dir) {
|
||||
await client.ensureDir(dir)
|
||||
}
|
||||
stream = await client.createWriteStream(path, options) // FIXME ensure that options are properly handled by @marsaud/smb2
|
||||
} catch (err) {
|
||||
client.close()
|
||||
throw err
|
||||
}
|
||||
stream.on('finish', () => client.close())
|
||||
return stream
|
||||
}
|
||||
|
||||
async _unlink (file) {
|
||||
const client = this._getClient(this._remote)
|
||||
|
||||
try {
|
||||
await client.unlink(this._getFilePath(file))::pFinally(() => { client.close() })
|
||||
} catch (error) {
|
||||
throw normalizeError(error)
|
||||
}
|
||||
}
|
||||
|
||||
async _getSize (file) {
|
||||
const client = await this._getClient(this._remote)
|
||||
let size
|
||||
|
||||
try {
|
||||
size = await client.getSize(this._getFilePath(file))::pFinally(() => { client.close() })
|
||||
} catch (error) {
|
||||
throw normalizeError(error)
|
||||
}
|
||||
|
||||
return size
|
||||
}
|
||||
}
|
||||
28
src/schemas/acl.js
Normal file
28
src/schemas/acl.js
Normal file
@@ -0,0 +1,28 @@
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
description: 'unique identifier for this ACL'
|
||||
},
|
||||
action: {
|
||||
type: 'string',
|
||||
description: 'permission (or role)'
|
||||
},
|
||||
object: {
|
||||
type: 'string',
|
||||
description: 'item (or set)'
|
||||
},
|
||||
subject: {
|
||||
type: 'string',
|
||||
description: 'user (or group)'
|
||||
}
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'action',
|
||||
'object',
|
||||
'subject'
|
||||
]
|
||||
}
|
||||
43
src/schemas/job.js
Normal file
43
src/schemas/job.js
Normal file
@@ -0,0 +1,43 @@
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: {
|
||||
enum: ['call']
|
||||
},
|
||||
id: {
|
||||
type: 'string',
|
||||
description: 'job identifier'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
description: 'human readable name'
|
||||
},
|
||||
userId: {
|
||||
type: 'string',
|
||||
description: 'identifier of the user who have created the job (the permissions of the user are used by the job)'
|
||||
},
|
||||
key: {
|
||||
type: 'string'
|
||||
// TODO description
|
||||
},
|
||||
method: {
|
||||
type: 'string',
|
||||
description: 'called method'
|
||||
},
|
||||
paramsVector: {
|
||||
type: 'object'
|
||||
},
|
||||
timeout: {
|
||||
type: 'number',
|
||||
description: 'number of milliseconds after which the job is considered failed'
|
||||
}
|
||||
},
|
||||
required: [
|
||||
'type',
|
||||
'id',
|
||||
'userId',
|
||||
'key',
|
||||
'method'
|
||||
]
|
||||
}
|
||||
29
src/schemas/log.js
Normal file
29
src/schemas/log.js
Normal file
@@ -0,0 +1,29 @@
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
description: 'unique identifier for this log'
|
||||
},
|
||||
time: {
|
||||
type: 'string',
|
||||
description: 'timestamp (in milliseconds) of this log'
|
||||
},
|
||||
message: {
|
||||
type: 'string',
|
||||
description: 'human readable (short) description of this log'
|
||||
},
|
||||
namespace: {
|
||||
type: 'string',
|
||||
description: 'space to store logs'
|
||||
},
|
||||
data: {}
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'time',
|
||||
'message',
|
||||
'namespace'
|
||||
]
|
||||
}
|
||||
33
src/schemas/log/jobCallEnd.js
Normal file
33
src/schemas/log/jobCallEnd.js
Normal file
@@ -0,0 +1,33 @@
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||
type: 'object',
|
||||
properties: {
|
||||
event: {
|
||||
enum: ['jobCall.end']
|
||||
},
|
||||
runJobId: {
|
||||
type: 'string',
|
||||
description: 'instance id of this job'
|
||||
},
|
||||
runCallId: {
|
||||
type: 'string',
|
||||
description: 'instance id of this call'
|
||||
},
|
||||
error: {
|
||||
type: 'object',
|
||||
description: 'describe one failure, exists if the call has failed'
|
||||
},
|
||||
returnedValue: {
|
||||
description: 'call\'s result, exists if the call is a success'
|
||||
}
|
||||
},
|
||||
required: [
|
||||
'event',
|
||||
'runJobId',
|
||||
'runCallId'
|
||||
],
|
||||
oneOf: [
|
||||
{ required: ['error'] },
|
||||
{ required: ['returnedValue'] }
|
||||
]
|
||||
}
|
||||
27
src/schemas/log/jobCallStart.js
Normal file
27
src/schemas/log/jobCallStart.js
Normal file
@@ -0,0 +1,27 @@
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||
type: 'object',
|
||||
properties: {
|
||||
event: {
|
||||
enum: ['jobCall.start']
|
||||
},
|
||||
runJobId: {
|
||||
type: 'string',
|
||||
description: 'instance id of this job'
|
||||
},
|
||||
method: {
|
||||
type: 'string',
|
||||
description: 'method linked to this call'
|
||||
},
|
||||
params: {
|
||||
type: 'object',
|
||||
description: 'params of the called method'
|
||||
}
|
||||
},
|
||||
required: [
|
||||
'event',
|
||||
'runJobId',
|
||||
'method',
|
||||
'params'
|
||||
]
|
||||
}
|
||||
21
src/schemas/log/jobEnd.js
Normal file
21
src/schemas/log/jobEnd.js
Normal file
@@ -0,0 +1,21 @@
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||
type: 'object',
|
||||
properties: {
|
||||
event: {
|
||||
enum: ['job.end']
|
||||
},
|
||||
runJobId: {
|
||||
type: 'string',
|
||||
description: 'instance id of this job'
|
||||
},
|
||||
error: {
|
||||
type: 'object',
|
||||
description: 'describe one failure, exists if no call has been made'
|
||||
}
|
||||
},
|
||||
required: [
|
||||
'event',
|
||||
'runJobId'
|
||||
]
|
||||
}
|
||||
26
src/schemas/log/jobStart.js
Normal file
26
src/schemas/log/jobStart.js
Normal file
@@ -0,0 +1,26 @@
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||
type: 'object',
|
||||
properties: {
|
||||
event: {
|
||||
enum: ['job.start']
|
||||
},
|
||||
userId: {
|
||||
type: 'string',
|
||||
description: 'user who executes this job'
|
||||
},
|
||||
jobId: {
|
||||
type: 'string',
|
||||
description: 'identifier of this job'
|
||||
},
|
||||
key: {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
required: [
|
||||
'event',
|
||||
'userId',
|
||||
'jobId',
|
||||
'key'
|
||||
]
|
||||
}
|
||||
49
src/schemas/plugin.js
Normal file
49
src/schemas/plugin.js
Normal file
@@ -0,0 +1,49 @@
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
description: 'unique identifier for this plugin'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
description: 'unique human readable name for this plugin'
|
||||
},
|
||||
autoload: {
|
||||
type: 'boolean',
|
||||
description: 'whether this plugin is loaded on startup'
|
||||
},
|
||||
loaded: {
|
||||
type: 'boolean',
|
||||
description: 'whether or not this plugin is currently loaded'
|
||||
},
|
||||
unloadable: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'whether or not this plugin can be unloaded'
|
||||
},
|
||||
configuration: {
|
||||
type: 'object',
|
||||
description: 'current configuration of this plugin (not present if none)'
|
||||
},
|
||||
configurationSchema: {
|
||||
$ref: 'http://json-schema.org/draft-04/schema#',
|
||||
description: 'configuration schema for this plugin (not present if not configurable)'
|
||||
},
|
||||
testable: {
|
||||
type: 'boolean',
|
||||
description: 'whether or not this plugin can be tested'
|
||||
},
|
||||
testSchema: {
|
||||
$ref: 'http://json-schema.org/draft-04/schema#',
|
||||
description: 'test schema for this plugin'
|
||||
}
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'name',
|
||||
'autoload',
|
||||
'loaded'
|
||||
]
|
||||
}
|
||||
50
src/schemas/user.js
Normal file
50
src/schemas/user.js
Normal file
@@ -0,0 +1,50 @@
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
description: 'unique identifier for this user'
|
||||
},
|
||||
email: {
|
||||
type: 'string',
|
||||
description: 'email address of this user'
|
||||
},
|
||||
groups: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
description: 'identifier of groups this user belong to'
|
||||
},
|
||||
permission: {
|
||||
enum: ['none', 'read', 'write', 'admin'],
|
||||
description: 'root permission for this user, none and admin are the only significant ones'
|
||||
},
|
||||
preferences: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
lang: { type: 'string' },
|
||||
sshKeys: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
key: { type: 'string' },
|
||||
title: { type: 'string' }
|
||||
},
|
||||
required: [
|
||||
'key',
|
||||
'title'
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
description: 'various user preferences'
|
||||
}
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'email'
|
||||
]
|
||||
}
|
||||
44
src/stream-to-existing-buffer.js
Normal file
44
src/stream-to-existing-buffer.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import assert from 'assert'
|
||||
|
||||
const streamToExistingBuffer = (
|
||||
stream,
|
||||
buffer,
|
||||
offset = 0,
|
||||
end = buffer.length
|
||||
) => new Promise((resolve, reject) => {
|
||||
assert(offset >= 0)
|
||||
assert(end > offset)
|
||||
assert(end <= buffer.length)
|
||||
|
||||
let i = offset
|
||||
|
||||
const onData = chunk => {
|
||||
const prev = i
|
||||
i += chunk.length
|
||||
|
||||
if (i > end) {
|
||||
return onError(new Error('too much data'))
|
||||
}
|
||||
|
||||
chunk.copy(buffer, prev)
|
||||
}
|
||||
stream.on('data', onData)
|
||||
|
||||
const clean = () => {
|
||||
stream.removeListener('data', onData)
|
||||
stream.removeListener('end', onEnd)
|
||||
stream.removeListener('error', onError)
|
||||
}
|
||||
const onEnd = () => {
|
||||
resolve(i - offset)
|
||||
clean()
|
||||
}
|
||||
stream.on('end', onEnd)
|
||||
const onError = error => {
|
||||
reject(error)
|
||||
clean()
|
||||
}
|
||||
stream.on('error', onError)
|
||||
})
|
||||
|
||||
export { streamToExistingBuffer as default }
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user