Commit 548e061a authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent b5cf9f8e
......@@ -2,6 +2,7 @@ const HetznerCloud = require('hcloud-js')
let client
let _ = require('lodash')
let tokens
const words = require('an-array-of-english-words')
let oldG = '#!/bin/bash\n' +
'cd /root\n' +
......@@ -158,18 +159,27 @@ class Hetzner {
}
async getIp() {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/getIp/'
return new Promise(function (resolve, reject) {
request(url, {timeout: 15000}, function (error, res, body) {
resolve(body)
});
});
}
async getMasterServerId() {
try {
let ip = await this.getIp()
let servers = await this.getAllServers()
for (let i = 0; i < servers.length; i++) {
if (servers[i].name === 'master') {
if (servers[i].publicNet.server.publicNet.ipv4.ip === ip) {
return servers[i].id
}
......@@ -187,13 +197,13 @@ class Hetzner {
createServer(region, newGeneration) {
let rand = this.randomInt(0, 100000)
rand = 'Server' + rand
let rand = randomInt(0, words.length)
return new Promise(function (resolve, reject) {
let command = newG
let command = newG
command=command.replace('ahmad',tokens)
command = command.replace('ahmad', tokens)
client.servers.build(rand)
.serverType('cx51')
......
......@@ -154,6 +154,8 @@ async function init() {
}
async function checkServers() {
let servers = await het.getAllServers('fsn1')
console.log(servers)
......
......@@ -19,7 +19,13 @@ tesT()
async function tesT() {
await init()
// let masterid=await het.getMasterServerId()
let ips = await het.getAllFloatingIps()
for (let i = 0; i < ips.length; i++) {
console.log(typeof ips[i].server ==='number')
}
}
......
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