Commit 6a28eeae authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 71914d0e
......@@ -3,18 +3,45 @@ let post = 'post'
let _ = require('lodash')
let auth = {Username: "AWI-236440", Password: "QVMUB653$H"}
let ip
let AvailDc = [1, 2, 3, 4, 6, 7, 8]
let AvailDc = [1, 2, 3, 4, 5, 6, 7, 8]
let foundDc
let masterIp
let masterIp = 0
let networkId
let serverId
//test()
async function test() {
ip = '94.177.244.45'
for (let i = 0; i < AvailDc.length; i++) {
let servers = await getAllServers(AvailDc[i])
servers = servers.Value
if (servers.length === 0)
continue
for (let j = 0; j < servers.length; j++) {
let server = await getDetailsofServer(AvailDc[i], servers[j].ServerId)
server = server.Value
console.log(server.NetworkAdapters[0].IPAddresses[0].Value)
console.log(ip)
if (ip === server.NetworkAdapters[0].IPAddresses[0].Value) {
masterIp = server.NetworkAdapters[0].IPAddresses[0].Value
networkId = server.NetworkAdapters[0].Id
serverId = server.ServerId
foundDc = AvailDc[i]
break
}
}
await deleteAllIps(1)
}
console.log('foundDc ->' + foundDc)
console.log('masterIp ->' + masterIp)
console.log('networkId ->' + networkId)
console.log('serverId ->' + serverId)
}
......@@ -75,14 +102,14 @@ async function createFloatingIp(dc) {
}
async function getAllIps(dc) {
let url = generateUrl(foundDc, 'GetPurchasedIpAddresses')
let url = generateUrl(dc, 'GetPurchasedIpAddresses')
let d = await doRequest(url, auth)
let arr = []
d = d.Value
for (let i = 0; i < d.length; i++) {
arr.push(d[i])
arr.push(d[i])
}
return arr
......@@ -150,7 +177,7 @@ async function RemovedByIp(dc, ip) {
let ips = await getAllIps(dc)
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)
break
}
......@@ -258,6 +285,7 @@ function generateUrl(dc, endpoint) {
return 'https://api.dc' + dc + '.computing.cloud.it/WsEndUser/v2.9/WsEndUser.svc/json/' + endpoint
}
function getIp() {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/getIp/'
......
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