Commit 76b7dd44 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 6d03d0aa
Pipeline #24 canceled with stages
......@@ -35,13 +35,18 @@ app.get('/add/:num/', (req, res) => {
})
app.get('/test', (req, res) => {
app.get('/add/', (req, res) => {
// console.log(req.params.acc)
res.sendfile('jetmtp.png')
res.send('Done')
het.removeAllFloatingIps()
})
app.get('/test', (req, res) => {
// console.log(req.params.acc)
res.sendfile('jetmtp.png')
})
async function newFloatingIpsOrder(req, res) {
......@@ -54,7 +59,7 @@ async function newFloatingIpsOrder(req, res) {
let floatNum = 10 - ips.length
let location = order === 1 ? constant.nuremberg : constant.falkenstein
let newIps=[]
let newIps = []
for (let i = 1; i <= floatNum; i++) {
......@@ -69,7 +74,7 @@ async function newFloatingIpsOrder(req, res) {
}
async function addBaship(ip) {
return shell.exec(' ip addr add ' + ip + ' dev eth0').stderr;
return shell.exec(' ip addr add ' + ip + ' dev eth0').stderr;
}
......@@ -103,6 +108,36 @@ cronRemover.schedule(' */1 * * * *', () => {
async function init() {
await initToken()
postRequest()
checkIps()
}
async function checkIps() {
let ips = await het.getAllFloatingIps()
for (let i = 0; i < ips.length; i++) {
let status = await getWorkFloating(ips[i].ip)
status = parseInt(status)
switch (status) {
case 404:
await postFloatingIps([ips[i].ip])
break
case 400:
await postFloatingIps([ips[i].ip])
break
case 0:
await het.delFloatingIp(ips[i].id)
break
case 1:
break
}
if (ip === ips[i].ip) {
await this.delFloatingIp(ips[i].id)
}
}
}
async function initToken() {
......@@ -169,6 +204,19 @@ function getWork() {
}
function getWorkFloating(ip) {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/getIpDetail/' + ip
return new Promise(function (resolve, reject) {
request(url, {timeout: 15000}, function (error, res, body) {
resolve(body)
});
});
}
function addIp() {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/add/'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment