Commit af25290c authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 3f1eb744
......@@ -32,7 +32,7 @@ app.get('/ip/:ip/', (req, res) => {
async function addBaship(ip) {
let command='sudo ifconfig eth0:' + randomInt(0, 99999) + ' ' + ip + ' netmask 255.255.255.0 up && /etc/init.d/networking restart'
let command = 'sudo ifconfig eth0:' + randomInt(0, 99999) + ' ' + ip + ' netmask 255.255.255.0 up && /etc/init.d/networking restart'
console.log(command)
return shell.exec(command).stderr;
......@@ -68,7 +68,7 @@ cronRemover.schedule(' */2 * * * *', () => {
init()
});
init()
async function init() {
await initToken()
......@@ -77,13 +77,12 @@ async function init() {
}
async function addIPs(ip) {
await aruba.attachedToServerByIp( ip)
await aruba.attachedToServerByIp(ip)
addBaship(ip)
await postFloatingIps([ip])
}
async function justDoIp(ip)
{
async function justDoIp(ip) {
addBaship(ip)
await postFloatingIps([ip])
......@@ -107,7 +106,7 @@ async function checkIps() {
await aruba.RemovedByIp(ips[i].Value)
break
case 1:
await justDoIp(ips[i].Value)
await justDoIp(ips[i].Value)
break
}
......@@ -121,7 +120,9 @@ async function sleep(millis) {
async function initToken() {
await aruba.init()
let d = aruba.getDc()
if (typeof d === "undefined")
await aruba.init()
// remover()
......
......@@ -105,7 +105,6 @@ async function getAllIps() {
let url = generateUrl(foundDc, 'GetPurchasedIpAddresses')
let d = await doRequest(url, auth)
masterIp = await getIp()
let arr = []
d = d.Value
for (let i = 0; i < d.length; i++) {
......@@ -118,7 +117,7 @@ async function getAllIps() {
async function deleteAllIps() {
masterIp = await getIp()
let ips = await getAllIps(foundDc)
for (let i = 0; i < ips.length; i++) {
if (ips[i].Value !== masterIp) {
......@@ -158,6 +157,10 @@ async function unAttachedToServer(resourceId) {
}
function getDc() {
return foundDc
}
async function attachedToServerByIp(ip) {
let ips = await getAllIps(foundDc)
......@@ -178,7 +181,7 @@ async function attachedToServerByIp(ip) {
async function RemovedByIp(ip) {
let ips = await getAllIps(foundDc)
masterIp = await getIp()
for (let i = 0; i < ips.length; i++) {
if (ips[i].Value === ip && ip !== masterIp) {
await deleteIp(foundDc, ips[i].ResourceId)
......@@ -302,6 +305,7 @@ module.exports =
getAllIps: getAllIps,
attachedToServerByIp: attachedToServerByIp,
RemovedByIp: RemovedByIp,
getDc: getDc,
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