Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
fb608589
Commit
fb608589
authored
Mar 02, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Plain Diff
Merge origin/package into package
parents
1304b264
00a13b34
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
179 additions
and
29 deletions
+179
-29
docker_engine.py
drip-deployer/docker_engine.py
+46
-0
docker_engine.sh
drip-deployer/docker_engine.sh
+10
-0
docker_kubernetes.py
drip-deployer/docker_kubernetes.py
+18
-11
docker_swarm.py
drip-deployer/docker_swarm.py
+74
-0
rpc_server.py
drip-deployer/rpc_server.py
+31
-18
No files found.
drip-deployer/docker_engine.py
0 → 100644
View file @
fb608589
#! /usr/bin/env python
# Copyright 2017 --Yang Hu--
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__
=
'Yang Hu'
import
paramiko
,
os
import
threading
def
install_engine
(
vm
):
try
:
print
"
%
s: ====== Start Docker Engine Installing ======"
%
(
vm
.
ip
)
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
vm
.
ip
,
username
=
vm
.
user
,
key_filename
=
vm
.
key
)
sftp
=
ssh
.
open_sftp
()
sftp
.
chdir
(
'/tmp/'
)
file_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
install_script
=
file_path
+
"/"
+
"docker_engine.sh"
sftp
.
put
(
install_script
,
"engine_setup.sh"
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo sh /tmp/engine_setup.sh"
)
stdout
.
read
()
print
"
%
s: ========= Docker Engine Installed ========="
%
(
vm
.
ip
)
except
Exception
as
e
:
print
'
%
s:
%
s'
%
(
vm
.
ip
,
e
)
return
"ERROR:"
+
vm
.
ip
+
" "
+
str
(
e
)
ssh
.
close
()
return
"SUCCESS"
def
run
(
vm_list
):
for
i
in
vm_list
:
ret
=
install_engine
(
i
)
if
"ERROR"
in
ret
:
return
ret
return
"SUCCESS"
\ No newline at end of file
drip-deployer/docker_engine.sh
0 → 100644
View file @
fb608589
#! /bin/bash
sudo
apt-get remove docker docker-engine
sudo
apt-get update
sudo
apt-get
-y
install
linux-image-extra-
$(
uname
-r
)
linux-image-extra-virtual
sudo
apt-get
-y
install
apt-transport-https ca-certificates curl software-properties-common
sudo
curl
-fsSL
https://download.docker.com/linux/ubuntu/gpg |
sudo
apt-key add -
sudo
apt-key fingerprint 0EBFCD88
sudo
add-apt-repository
"deb [arch=amd64] https://download.docker.com/linux/ubuntu
$(
lsb_release
-cs
)
stable"
sudo
apt-get update
sudo
apt-get
-y
install
docker-ce
drip-deployer/docker_kubernetes.py
View file @
fb608589
...
...
@@ -71,19 +71,26 @@ def install_worker(join_cmd, vm):
print
'
%
s:
%
s'
%
(
vm
.
ip
,
e
)
return
"ERROR:"
+
vm
.
ip
+
" "
+
str
(
e
)
ssh
.
close
()
return
""
return
"
SUCCESS
"
def
run
(
vm_list
):
for
i
in
vm_list
:
if
i
.
role
==
"master"
:
join_cmd
=
install_manager
(
i
)
if
"ERROR"
in
join_cmd
:
return
join_cmd
else
:
join_cmd
=
join_cmd
.
encode
()
join_cmd
=
join_cmd
.
strip
()
if
i
.
role
==
"master"
:
join_cmd
=
install_manager
(
i
)
if
"ERROR"
in
join_cmd
:
return
join_cmd
else
:
join_cmd
=
join_cmd
.
encode
()
join_cmd
=
join_cmd
.
strip
()
break
for
i
in
vm_list
:
if
i
.
role
==
"slave"
:
worker_cmd
=
install_worker
(
join_cmd
,
i
)
if
"ERROR"
in
worker_cmd
:
return
worker_cmd
return
""
\ No newline at end of file
if
i
.
role
==
"slave"
:
worker_cmd
=
install_worker
(
join_cmd
,
i
)
if
"ERROR"
in
worker_cmd
:
return
worker_cmd
kuber_file
=
open
(
file_path
+
"/admin.conf"
,
"r"
)
kuber_string
=
kuber_file
.
read
()
kuber_file
.
close
()
return
kuber_string
\ No newline at end of file
drip-deployer/docker_swarm.py
0 → 100644
View file @
fb608589
#! /usr/bin/env python
# Copyright 2017 --Yang Hu--
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__
=
'Yang Hu'
import
paramiko
,
os
from
vm_info
import
VmInfo
def
install_manager
(
vm
):
try
:
print
"
%
s: ====== Start Swarm Manager Installing ======"
%
(
vm
.
ip
)
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
vm
.
ip
,
username
=
vm
.
user
,
key_filename
=
vm
.
key
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo docker swarm init --advertise-addr eth0"
)
retstr
=
stdout
.
readlines
()
print
"
%
s: ========= Swarm Manager Installed ========="
%
(
vm
.
ip
)
except
Exception
as
e
:
print
'
%
s:
%
s'
%
(
vm
.
ip
,
e
)
return
"ERROR:"
+
vm
.
ip
+
" "
+
str
(
e
)
ssh
.
close
()
return
retstr
[
4
]
+
retstr
[
5
]
+
retstr
[
6
]
def
install_worker
(
join_cmd
,
vm
):
try
:
print
"
%
s: ====== Start Swarm Worker Installing ======"
%
(
vm
.
ip
)
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
vm
.
ip
,
username
=
vm
.
user
,
key_filename
=
vm
.
key
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo
%
s"
%
(
join_cmd
))
stdout
.
read
()
print
"
%
s: ========= Swarm Worker Installed ========="
%
(
vm
.
ip
)
except
Exception
as
e
:
print
'
%
s:
%
s'
%
(
vm
.
ip
,
e
)
return
"ERROR:"
+
vm
.
ip
+
" "
+
str
(
e
)
ssh
.
close
()
return
"SUCCESS"
def
run
(
vm_list
):
for
i
in
vm_list
:
if
i
.
role
==
"master"
:
join_cmd
=
install_manager
(
i
)
if
"ERROR"
in
join_cmd
:
return
join_cmd
else
:
join_cmd
=
join_cmd
.
encode
()
join_cmd
=
join_cmd
.
replace
(
"
\n
"
,
""
)
join_cmd
=
join_cmd
.
replace
(
"
\\
"
,
""
)
join_cmd
=
join_cmd
.
strip
()
swarm_file
=
open
(
i
.
key
)
swarm_string
=
swarm_file
.
read
()
swarm_file
.
close
()
break
for
i
in
vm_list
:
if
i
.
role
==
"slave"
:
worker_cmd
=
install_worker
(
join_cmd
,
i
)
if
"ERROR"
in
worker_cmd
:
return
worker_cmd
return
swarm_string
\ No newline at end of file
drip-deployer/rpc_server.py
View file @
fb608589
...
...
@@ -6,6 +6,8 @@ import time
from
vm_info
import
VmInfo
import
docker_kubernetes
import
docker_engine
import
docker_swarm
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
'172.17.0.3'
))
channel
=
connection
.
channel
()
...
...
@@ -19,32 +21,43 @@ def handleDelivery(message):
node_num
=
0
vm_list
=
[]
for
param
in
params
:
value
=
param
[
"value"
]
ip
=
param
[
"attributes"
][
"IP"
]
user
=
param
[
"attributes"
][
"user"
]
role
=
param
[
"attributes"
][
"role"
]
node_num
+=
1
key
=
path
+
"
%
d.txt"
%
(
node_num
)
fo
=
open
(
key
,
"w"
)
fo
.
write
(
value
)
fo
.
close
()
vm
=
VmInfo
(
ip
,
user
,
key
,
role
)
vm_list
.
append
(
vm
)
return
docker_kubernetes
.
run
(
vm_list
)
name
=
param
[
"name"
]
if
name
==
"cluster"
:
cluster_type
=
param
[
"value"
]
else
:
value
=
param
[
"value"
]
ip
=
param
[
"attributes"
][
"IP"
]
user
=
param
[
"attributes"
][
"user"
]
role
=
param
[
"attributes"
][
"role"
]
node_num
+=
1
key
=
path
+
"
%
d.txt"
%
(
node_num
)
fo
=
open
(
key
,
"w"
)
fo
.
write
(
value
)
fo
.
close
()
vm
=
VmInfo
(
ip
,
user
,
key
,
role
)
vm_list
.
append
(
vm
)
if
cluster_type
==
"kubernetes"
:
ret
=
docker_kubernetes
.
run
(
vm_list
)
return
ret
elif
cluster_type
==
"swarm"
:
ret
=
docker_engine
.
run
(
vm_list
)
if
"ERROR"
in
ret
:
return
ret
ret
=
docker_swarm
.
run
(
vm_list
)
return
ret
else
:
return
"ERROR: invalid cluster"
def
on_request
(
ch
,
method
,
props
,
body
):
ret
=
handleDelivery
(
body
)
print
ret
if
"ERROR"
in
ret
:
kuber_string
=
ret
res_name
=
"error"
#print(" Message %s" % body)
else
:
res_name
=
"credential"
kuber_file
=
open
(
path
+
"admin.conf"
,
"r"
)
kuber_string
=
kuber_file
.
read
()
kuber_file
.
close
()
response
=
{}
outcontent
=
{}
...
...
@@ -55,7 +68,7 @@ def on_request(ch, method, props, body):
par
[
"url"
]
=
"null"
par
[
"encoding"
]
=
"UTF-8"
par
[
"name"
]
=
res_name
par
[
"value"
]
=
kuber_string
par
[
"value"
]
=
ret
par
[
"attributes"
]
=
"null"
response
[
"parameters"
]
.
append
(
par
)
...
...
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