Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Aruba-Master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Aruba-Master
Commits
47ab20de
Commit
47ab20de
authored
Apr 17, 2020
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
17f328ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
28 deletions
+33
-28
app.js
app.js
+20
-13
aruba.js
aruba.js
+13
-15
No files found.
app.js
View file @
47ab20de
...
...
@@ -31,14 +31,17 @@ app.get('/ip/:ip/', (req, res) => {
})
async
function
addBaship
(
ip
)
{
return
shell
.
exec
(
'
ip addr add
'
+
ip
+
'
dev eth0
'
).
stderr
;
let
command
=
'
sudo ifconfig eth0:
'
+
randomInt
(
0
,
99999
)
+
'
'
+
ip
+
'
netmask 255.255.255.0 up
'
console
.
log
(
command
)
return
shell
.
exec
(
command
).
stderr
;
}
function
randomInt
(
low
,
high
)
{
return
Math
.
floor
(
Math
.
random
()
*
(
high
-
low
)
+
low
)
}
app
.
listen
(
port
,
()
=>
console
.
log
(
`Example app listening on port
${
port
}
!`
))
...
...
@@ -69,18 +72,25 @@ init()
async
function
init
()
{
await
initToken
()
// postRequest()
// postRequest()
checkIps
()
}
async
function
addIPs
(
ip
)
{
await
aruba
.
attachedToServerByIp
(
dc
,
ip
)
await
aruba
.
attachedToServerByIp
(
ip
)
addBaship
(
ip
)
await
postFloatingIps
([
ip
])
}
async
function
justDoIp
(
ip
)
{
addBaship
(
ip
)
await
postFloatingIps
([
ip
])
}
async
function
checkIps
()
{
let
ips
=
await
aruba
.
getAllIps
(
dc
)
let
ips
=
await
aruba
.
getAllIps
()
for
(
let
i
=
0
;
i
<
ips
.
length
;
i
++
)
{
let
status
=
await
getWorkFloating
(
ips
[
i
].
Value
)
...
...
@@ -94,10 +104,10 @@ async function checkIps() {
await
addIPs
(
ips
[
i
].
Value
)
break
case
0
:
await
aruba
.
RemovedByIp
(
ips
[
i
].
Value
)
await
aruba
.
RemovedByIp
(
ips
[
i
].
Value
)
break
case
1
:
// await addIPs
(ips[i].Value)
await
justDoIp
(
ips
[
i
].
Value
)
break
}
...
...
@@ -112,7 +122,6 @@ async function sleep(millis) {
async
function
initToken
()
{
await
aruba
.
init
()
dc
=
aruba
.
getDc
()
// remover()
...
...
@@ -121,7 +130,7 @@ async function initToken() {
async
function
addNewIp
(
req
,
res
)
{
res
.
send
(
'
Done
'
)
await
aruba
.
createFloatingIp
(
dc
)
await
aruba
.
createFloatingIp
()
checkIps
()
}
...
...
@@ -151,8 +160,6 @@ function postFloatingIps(data) {
}
function
getWork
()
{
const
request
=
require
(
'
request
'
);
let
url
=
'
http://admin.fcfglobal.co:3000/work/
'
...
...
aruba.js
View file @
47ab20de
...
...
@@ -92,7 +92,7 @@ async function getDetailsofServer(dc, id) {
return
d
}
async
function
createFloatingIp
(
dc
)
{
async
function
createFloatingIp
()
{
let
url
=
generateUrl
(
foundDc
,
'
SetPurchaseIpAddress
'
)
let
d
=
await
doRequest
(
url
,
auth
)
...
...
@@ -101,8 +101,8 @@ async function createFloatingIp(dc) {
return
d
}
async
function
getAllIps
(
dc
)
{
let
url
=
generateUrl
(
d
c
,
'
GetPurchasedIpAddresses
'
)
async
function
getAllIps
()
{
let
url
=
generateUrl
(
foundD
c
,
'
GetPurchasedIpAddresses
'
)
let
d
=
await
doRequest
(
url
,
auth
)
...
...
@@ -115,7 +115,9 @@ async function getAllIps(dc) {
return
arr
}
async
function
deleteAllIps
(
dc
)
{
async
function
deleteAllIps
()
{
masterIp
=
await
getIp
()
let
ips
=
await
getAllIps
(
foundDc
)
for
(
let
i
=
0
;
i
<
ips
.
length
;
i
++
)
{
if
(
ips
[
i
].
Value
!==
masterIp
)
{
...
...
@@ -130,7 +132,7 @@ async function deleteAllIps(dc) {
}
async
function
attachedToServer
(
dc
,
resourceId
)
{
async
function
attachedToServer
(
resourceId
)
{
let
url
=
generateUrl
(
foundDc
,
'
SetEnqueueAssociateIpAddress
'
)
let
body
=
auth
...
...
@@ -143,7 +145,7 @@ async function attachedToServer(dc, resourceId) {
}
async
function
unAttachedToServer
(
dc
,
resourceId
)
{
async
function
unAttachedToServer
(
resourceId
)
{
let
url
=
generateUrl
(
foundDc
,
'
SetEnqueueDeassociateIpAddress
'
)
let
body
=
auth
...
...
@@ -156,7 +158,7 @@ async function unAttachedToServer(dc, resourceId) {
}
async
function
attachedToServerByIp
(
dc
,
ip
)
{
async
function
attachedToServerByIp
(
ip
)
{
let
ips
=
await
getAllIps
(
foundDc
)
for
(
let
i
=
0
;
i
<
ips
.
length
;
i
++
)
{
...
...
@@ -173,9 +175,9 @@ async function attachedToServerByIp(dc, ip) {
}
async
function
RemovedByIp
(
dc
,
ip
)
{
let
ips
=
await
getAllIps
(
d
c
)
async
function
RemovedByIp
(
ip
)
{
let
ips
=
await
getAllIps
(
foundD
c
)
masterIp
=
await
getIp
()
for
(
let
i
=
0
;
i
<
ips
.
length
;
i
++
)
{
if
(
ips
[
i
].
Value
===
ip
&&
ip
!==
masterIp
)
{
await
deleteIp
(
foundDc
,
ips
[
i
].
ResourceId
)
...
...
@@ -189,7 +191,7 @@ async function RemovedByIp(dc, ip) {
}
async
function
deleteIp
(
dc
,
id
)
{
async
function
deleteIp
(
id
)
{
await
unAttachedToServer
(
foundDc
,
id
)
let
url
=
generateUrl
(
foundDc
,
'
SetRemoveIpAddress
'
)
let
body
=
auth
...
...
@@ -201,9 +203,6 @@ async function deleteIp(dc, id) {
}
function
getDc
()
{
return
foundDc
}
async
function
doRequest
(
url
,
body
)
{
...
...
@@ -302,7 +301,6 @@ module.exports =
{
init
:
init
,
getAllIps
:
getAllIps
,
getDc
:
getDc
,
attachedToServerByIp
:
attachedToServerByIp
,
RemovedByIp
:
RemovedByIp
,
createFloatingIp
:
createFloatingIp
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment