Commit 47ab20de authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 17f328ff
...@@ -31,14 +31,17 @@ app.get('/ip/:ip/', (req, res) => { ...@@ -31,14 +31,17 @@ app.get('/ip/:ip/', (req, res) => {
}) })
async function addBaship(ip) { async function addBaship(ip) {
return shell.exec(' ip addr add ' + ip + ' dev eth0').stderr; let command='sudo ifconfig eth0:' + randomInt(0, 99999) + ' ' + ip + ' netmask 255.255.255.0 up'
console.log(command)
return shell.exec(command).stderr;
} }
function randomInt(low, high) {
return Math.floor(Math.random() * (high - low) + low)
}
app.listen(port, () => console.log(`Example app listening on port ${port}!`)) app.listen(port, () => console.log(`Example app listening on port ${port}!`))
...@@ -74,13 +77,20 @@ async function init() { ...@@ -74,13 +77,20 @@ async function init() {
} }
async function addIPs(ip) { async function addIPs(ip) {
await aruba.attachedToServerByIp(dc, ip) await aruba.attachedToServerByIp( ip)
addBaship(ip)
await postFloatingIps([ip])
}
async function justDoIp(ip)
{
addBaship(ip) addBaship(ip)
await postFloatingIps([ip]) await postFloatingIps([ip])
} }
async function checkIps() { async function checkIps() {
let ips = await aruba.getAllIps(dc) let ips = await aruba.getAllIps()
for (let i = 0; i < ips.length; i++) { for (let i = 0; i < ips.length; i++) {
let status = await getWorkFloating(ips[i].Value) let status = await getWorkFloating(ips[i].Value)
...@@ -97,7 +107,7 @@ async function checkIps() { ...@@ -97,7 +107,7 @@ async function checkIps() {
await aruba.RemovedByIp(ips[i].Value) await aruba.RemovedByIp(ips[i].Value)
break break
case 1: case 1:
// await addIPs(ips[i].Value) await justDoIp(ips[i].Value)
break break
} }
...@@ -112,7 +122,6 @@ async function sleep(millis) { ...@@ -112,7 +122,6 @@ async function sleep(millis) {
async function initToken() { async function initToken() {
await aruba.init() await aruba.init()
dc = aruba.getDc()
// remover() // remover()
...@@ -121,7 +130,7 @@ async function initToken() { ...@@ -121,7 +130,7 @@ async function initToken() {
async function addNewIp(req, res) { async function addNewIp(req, res) {
res.send('Done') res.send('Done')
await aruba.createFloatingIp(dc) await aruba.createFloatingIp()
checkIps() checkIps()
} }
...@@ -151,8 +160,6 @@ function postFloatingIps(data) { ...@@ -151,8 +160,6 @@ function postFloatingIps(data) {
} }
function getWork() { function getWork() {
const request = require('request'); const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/work/' let url = 'http://admin.fcfglobal.co:3000/work/'
......
...@@ -92,7 +92,7 @@ async function getDetailsofServer(dc, id) { ...@@ -92,7 +92,7 @@ async function getDetailsofServer(dc, id) {
return d return d
} }
async function createFloatingIp(dc) { async function createFloatingIp() {
let url = generateUrl(foundDc, 'SetPurchaseIpAddress') let url = generateUrl(foundDc, 'SetPurchaseIpAddress')
let d = await doRequest(url, auth) let d = await doRequest(url, auth)
...@@ -101,8 +101,8 @@ async function createFloatingIp(dc) { ...@@ -101,8 +101,8 @@ async function createFloatingIp(dc) {
return d return d
} }
async function getAllIps(dc) { async function getAllIps() {
let url = generateUrl(dc, 'GetPurchasedIpAddresses') let url = generateUrl(foundDc, 'GetPurchasedIpAddresses')
let d = await doRequest(url, auth) let d = await doRequest(url, auth)
...@@ -115,7 +115,9 @@ async function getAllIps(dc) { ...@@ -115,7 +115,9 @@ async function getAllIps(dc) {
return arr return arr
} }
async function deleteAllIps(dc) {
async function deleteAllIps() {
masterIp=await getIp()
let ips = await getAllIps(foundDc) let ips = await getAllIps(foundDc)
for (let i = 0; i < ips.length; i++) { for (let i = 0; i < ips.length; i++) {
if (ips[i].Value !== masterIp) { if (ips[i].Value !== masterIp) {
...@@ -130,7 +132,7 @@ async function deleteAllIps(dc) { ...@@ -130,7 +132,7 @@ async function deleteAllIps(dc) {
} }
async function attachedToServer(dc, resourceId) { async function attachedToServer( resourceId) {
let url = generateUrl(foundDc, 'SetEnqueueAssociateIpAddress') let url = generateUrl(foundDc, 'SetEnqueueAssociateIpAddress')
let body = auth let body = auth
...@@ -143,7 +145,7 @@ async function attachedToServer(dc, resourceId) { ...@@ -143,7 +145,7 @@ async function attachedToServer(dc, resourceId) {
} }
async function unAttachedToServer(dc, resourceId) { async function unAttachedToServer( resourceId) {
let url = generateUrl(foundDc, 'SetEnqueueDeassociateIpAddress') let url = generateUrl(foundDc, 'SetEnqueueDeassociateIpAddress')
let body = auth let body = auth
...@@ -156,7 +158,7 @@ async function unAttachedToServer(dc, resourceId) { ...@@ -156,7 +158,7 @@ async function unAttachedToServer(dc, resourceId) {
} }
async function attachedToServerByIp(dc, ip) { async function attachedToServerByIp( ip) {
let ips = await getAllIps(foundDc) let ips = await getAllIps(foundDc)
for (let i = 0; i < ips.length; i++) { for (let i = 0; i < ips.length; i++) {
...@@ -173,9 +175,9 @@ async function attachedToServerByIp(dc, ip) { ...@@ -173,9 +175,9 @@ async function attachedToServerByIp(dc, ip) {
} }
async function RemovedByIp(dc, ip) { async function RemovedByIp( ip) {
let ips = await getAllIps(dc) let ips = await getAllIps(foundDc)
masterIp=await getIp()
for (let i = 0; i < ips.length; i++) { for (let i = 0; i < ips.length; i++) {
if (ips[i].Value === ip && ip !== masterIp) { if (ips[i].Value === ip && ip !== masterIp) {
await deleteIp(foundDc, ips[i].ResourceId) await deleteIp(foundDc, ips[i].ResourceId)
...@@ -189,7 +191,7 @@ async function RemovedByIp(dc, ip) { ...@@ -189,7 +191,7 @@ async function RemovedByIp(dc, ip) {
} }
async function deleteIp(dc, id) { async function deleteIp(id) {
await unAttachedToServer(foundDc, id) await unAttachedToServer(foundDc, id)
let url = generateUrl(foundDc, 'SetRemoveIpAddress') let url = generateUrl(foundDc, 'SetRemoveIpAddress')
let body = auth let body = auth
...@@ -201,9 +203,6 @@ async function deleteIp(dc, id) { ...@@ -201,9 +203,6 @@ async function deleteIp(dc, id) {
} }
function getDc() {
return foundDc
}
async function doRequest(url, body) { async function doRequest(url, body) {
...@@ -302,7 +301,6 @@ module.exports = ...@@ -302,7 +301,6 @@ module.exports =
{ {
init: init, init: init,
getAllIps: getAllIps, getAllIps: getAllIps,
getDc: getDc,
attachedToServerByIp: attachedToServerByIp, attachedToServerByIp: attachedToServerByIp,
RemovedByIp: RemovedByIp, RemovedByIp: RemovedByIp,
createFloatingIp: createFloatingIp createFloatingIp: createFloatingIp
......
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