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
d073529a
Commit
d073529a
authored
8 years ago
by
Oceans
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update deployer
parent
e6985b1a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
181 additions
and
0 deletions
+181
-0
docker_kubernetes.py
drip-deployer/docker_kubernetes.py
+81
-0
docker_kubernetes.sh
drip-deployer/docker_kubernetes.sh
+6
-0
rpc_server.py
drip-deployer/rpc_server.py
+67
-0
vm_info.py
drip-deployer/vm_info.py
+27
-0
No files found.
drip-deployer/docker_kubernetes.py
0 → 100644
View file @
d073529a
#! /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 Kubernetes Master 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
()
file_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
sftp
.
chdir
(
'/tmp/'
)
install_script
=
file_path
+
"/"
+
"docker_kubernetes.sh"
sftp
.
put
(
install_script
,
"kubernetes_setup.sh"
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo hostname ip-
%
s"
%
(
vm
.
ip
.
replace
(
'.'
,
'-'
)))
stdout
.
read
()
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo sh /tmp/kubernetes_setup.sh"
)
stdout
.
read
()
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo kubeadm init --api-advertise-addresses=
%
s"
%
(
vm
.
ip
))
retstr
=
stdout
.
readlines
()
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo cp /etc/kubernetes/admin.conf /tmp/"
)
stdout
.
read
()
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo chown
%
s /tmp/admin.conf"
%
(
vm
.
user
))
stdout
.
read
()
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo chgrp
%
s /tmp/admin.conf"
%
(
vm
.
user
))
stdout
.
read
()
sftp
.
get
(
"/tmp/admin.conf"
,
file_path
+
"/admin.conf"
)
print
"
%
s: ========= Kubernetes Master Installed ========="
%
(
vm
.
ip
)
except
Exception
as
e
:
print
'
%
s:
%
s'
%
(
vm
.
ip
,
e
)
ssh
.
close
()
return
retstr
[
-
1
]
def
install_worker
(
join_cmd
,
vm
):
try
:
print
"
%
s: ====== Start Kubernetes Slave 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_kubernetes.sh"
sftp
.
put
(
install_script
,
"kubernetes_setup.sh"
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo hostname ip-
%
s"
%
(
vm
.
ip
.
replace
(
'.'
,
'-'
)))
stdout
.
read
()
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo sh /tmp/kubernetes_setup.sh"
)
stdout
.
read
()
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo
%
s"
%
(
join_cmd
))
stdout
.
read
()
print
"
%
s: ========= Kubernetes Slave Installed ========="
%
(
vm
.
ip
)
except
Exception
as
e
:
print
'
%
s:
%
s'
%
(
vm
.
ip
,
e
)
ssh
.
close
()
def
run
(
vm_list
):
for
i
in
vm_list
:
if
i
.
role
==
"master"
:
join_cmd
=
install_manager
(
i
)
join_cmd
=
join_cmd
.
encode
()
join_cmd
=
join_cmd
.
strip
()
for
i
in
vm_list
:
if
i
.
role
==
"slave"
:
install_worker
(
join_cmd
,
i
)
This diff is collapsed.
Click to expand it.
drip-deployer/docker_kubernetes.sh
0 → 100644
View file @
d073529a
#! /bin/bash
sudo
curl
-s
https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo
"deb http://apt.kubernetes.io/ kubernetes-xenial main"
|
sudo tee
/etc/apt/sources.list.d/kubernetes.list
sudo
apt-get update
sudo
apt-get
install
-y
docker.io
sudo
apt-get
install
-y
kubelet kubeadm kubectl kubernetes-cni
\ No newline at end of file
This diff is collapsed.
Click to expand it.
drip-deployer/rpc_server.py
0 → 100755
View file @
d073529a
#!/usr/bin/env python
import
pika
import
json
import
os
from
vm_info
import
VmInfo
import
docker_kubernetes
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
'172.17.0.2'
))
channel
=
connection
.
channel
()
channel
.
queue_declare
(
queue
=
'deployer_queue'
)
path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
"/"
def
handleDelivery
(
message
):
parsed_json
=
json
.
loads
(
message
)
params
=
parsed_json
[
"parameters"
]
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
)
docker_kubernetes
.
run
(
vm_list
)
def
on_request
(
ch
,
method
,
props
,
body
):
handleDelivery
(
body
)
print
(
" Message
%
s"
%
body
)
kuber_file
=
open
(
path
+
"admin.conf"
,
"r"
)
kuber_string
=
kuber_file
.
read
()
kuber_file
.
close
()
response
=
{}
response
[
"creationDate"
]
=
1487002029722
response
[
"parameters"
]
=
[]
par
=
{}
par
[
"url"
]
=
"null"
par
[
"encoding"
]
=
"UTF-8"
par
[
"name"
]
=
"credential"
par
[
"value"
]
=
kuber_string
par
[
"attributes"
]
=
"null"
response
[
"parameters"
]
.
append
(
par
)
ch
.
basic_publish
(
exchange
=
''
,
routing_key
=
props
.
reply_to
,
properties
=
pika
.
BasicProperties
(
correlation_id
=
\
props
.
correlation_id
),
body
=
str
(
response
))
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
channel
.
basic_qos
(
prefetch_count
=
1
)
channel
.
basic_consume
(
on_request
,
queue
=
'deployer_queue'
)
print
(
" [x] Awaiting RPC requests"
)
channel
.
start_consuming
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
drip-deployer/vm_info.py
0 → 100644
View file @
d073529a
#! /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.
class
VmInfo
:
def
__init__
(
self
,
ip
=
""
,
user
=
""
,
key
=
""
,
role
=
""
):
self
.
ip
=
ip
self
.
user
=
user
self
.
key
=
key
self
.
role
=
role
def
displayVm
(
self
):
print
"IP:"
,
self
.
ip
,
" USER:"
,
self
.
user
This diff is collapsed.
Click to expand it.
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