Commit 07875a82 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 9b582bdd
...@@ -79,7 +79,7 @@ cron.schedule('*/10 * * * * *', () => { ...@@ -79,7 +79,7 @@ cron.schedule('*/10 * * * * *', () => {
}); });
postRequest() postRequest()
cronRemover.schedule(' */1 * * * *', () => { cronRemover.schedule(' */5 * * * *', () => {
init() init()
}); });
......
...@@ -29,7 +29,6 @@ async function test() { ...@@ -29,7 +29,6 @@ async function test() {
} }
async function init() { async function init() {
ip = await getIp() ip = await getIp()
for (let i = 0; i < AvailDc.length; i++) { for (let i = 0; i < AvailDc.length; i++) {
...@@ -80,7 +79,7 @@ async function createFloatingIp(dc) { ...@@ -80,7 +79,7 @@ async function createFloatingIp(dc) {
let d = await doRequest(url, auth) let d = await doRequest(url, auth)
d = d.Value d = d.Value
await attachedToServer(foundDc, d.ResourceId) await attachedToServer(foundDc, d.ResourceId)
return d return d
} }
...@@ -89,16 +88,21 @@ async function getAllIps(dc) { ...@@ -89,16 +88,21 @@ async function getAllIps(dc) {
let d = await doRequest(url, auth) let d = await doRequest(url, auth)
return d.Value let arr = []
d = d.Value
for (let i = 0; i < d.length; i++) {
if (d[i].Value !== masterIp)
arr.push(d[i])
}
return arr
} }
async function deleteAllIps(dc) { async function deleteAllIps(dc) {
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) let d = await deleteIp(foundDc, ips[i].ResourceId)
{
let d=await deleteIp(foundDc,ips[i].ResourceId)
console.log(d) console.log(d)
} }
...@@ -109,8 +113,6 @@ async function deleteAllIps(dc) { ...@@ -109,8 +113,6 @@ async function deleteAllIps(dc) {
} }
async function attachedToServer(dc, resourceId) { async function attachedToServer(dc, resourceId) {
let url = generateUrl(foundDc, 'SetEnqueueAssociateIpAddress') let url = generateUrl(foundDc, 'SetEnqueueAssociateIpAddress')
...@@ -138,13 +140,11 @@ async function unAttachedToServer(dc, resourceId) { ...@@ -138,13 +140,11 @@ async function unAttachedToServer(dc, resourceId) {
async function attachedToServerByIp(dc, ip) { async function attachedToServerByIp(dc, 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++) {
{ if (ips[i].Value === ip) {
if (ips[i].Value === ip) await attachedToServer(foundDc, ips[i].ResourceId)
{
await attachedToServer(foundDc,ips[i].ResourceId)
break break
} }
} }
...@@ -157,13 +157,11 @@ async function attachedToServerByIp(dc, ip) { ...@@ -157,13 +157,11 @@ async function attachedToServerByIp(dc, ip) {
async function RemovedByIp(dc, ip) { async function RemovedByIp(dc, ip) {
let ips=await getAllIps(dc) let ips = await getAllIps(dc)
for(let i=0;i<ips.length ;i++) for (let i = 0; i < ips.length; i++) {
{ if (ips[i].Value === ip) {
if (ips[i].Value === ip) await deleteIp(foundDc, ips[i].ResourceId)
{
await deleteIp(foundDc,ips[i].ResourceId)
break break
} }
} }
...@@ -186,8 +184,7 @@ async function deleteIp(dc, id) { ...@@ -186,8 +184,7 @@ async function deleteIp(dc, id) {
} }
function getDc() function getDc() {
{
return foundDc return foundDc
} }
...@@ -213,7 +210,7 @@ async function doRequest(url, body) { ...@@ -213,7 +210,7 @@ async function doRequest(url, body) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
request(options, function (error, response, body) { request(options, function (error, response, body) {
if (error) reject('Problem ->'+options.url) if (error) reject('Problem ->' + options.url)
try { try {
...@@ -285,12 +282,12 @@ function getIp() { ...@@ -285,12 +282,12 @@ function getIp() {
module.exports = module.exports =
{ {
init:init, init: init,
getAllIps:getAllIps, getAllIps: getAllIps,
getDc:getDc, 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