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

init

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