Commit af25290c authored by Ahmad Nemati's avatar Ahmad Nemati

init

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