Skip to content

Commit 806faff

Browse files
Sivaram Mothikimboersma
authored andcommitted
feat(swarm): initial installation
feat(swarm): add init scripts and fleet templates for swarm node and manager feat(swarm): fix dockerfile and fleet templates feat(swarm): modify variable names feat(swarm): add swarm.py controller module fix(swarm): fix swarm init() fix(swarm): change error1 str to int feat(swarm): add docker tcp socket service rectify errors fix(builder): hardcode overlay storage driver feat(swarm): fix errors and fleet swarm template files
1 parent 87c22ff commit 806faff

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

conf.d/confd_settings.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ keys = [
1010
"/deis/registry",
1111
"/deis/domains",
1212
"/deis/platform",
13+
"/deis/scheduler/swarm/host",
1314
]
1415
reload_cmd = "/app/bin/reload"

scheduler/swarm.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import logging
2+
from docker import Client
3+
4+
from django.conf import settings
5+
6+
7+
8+
class SwarmClient(object):
9+
def __init__(self,target, auth, options, pkey):
10+
self.target = settings.SWARM_HOST
11+
# single global connection
12+
self.registry = settings.REGISTRY_HOST+":"+settings.REGISTRY_PORT
13+
self.docker_cli = Client(base_url='tcp://'+self.target+':'+"2395",timeout=1200)
14+
15+
def create(self, name, image, command='', template=None, **kwargs):
16+
"""Create a container"""
17+
cimage=self.registry+"/"+image
18+
cname=name
19+
ccommand=command
20+
# self.docker_cli.pull(cimage, stream=False,insecure_registry=True)
21+
self.docker_cli.create_container(image=cimage,name=cname,command=ccommand)#,hostname=self._get_hostname(cname),ports=self._get_ports(cimage))
22+
self.docker_cli.start(cname, port_bindings=self._get_portbindings(cimage),publish_all_ports=True)
23+
24+
def start(self, name):
25+
"""
26+
Start a container
27+
"""
28+
self.docker_cli.start(name)
29+
return
30+
31+
def stop(self, name):
32+
"""
33+
Stop a container
34+
"""
35+
self.docker_cli.stop(name)
36+
return
37+
def destroy(self, name):
38+
"""
39+
Destroy a container
40+
"""
41+
self.docker_cli.stop(name)
42+
self.docker_cli.remove_container(name)
43+
return
44+
45+
def run(self, name, image, entrypoint, command):
46+
"""
47+
Run a one-off command
48+
"""
49+
# dump input into a json object for testing purposes
50+
return 0, json.dumps({'name': name,
51+
'image': image,
52+
'entrypoint': entrypoint,
53+
'command': command})
54+
55+
def attach(self, name):
56+
"""
57+
Attach to a job's stdin, stdout and stderr
58+
"""
59+
return StringIO(), StringIO(), StringIO()
60+
61+
def _get_hostname(self, application_name):
62+
hostname = settings.UNIT_HOSTNAME
63+
if hostname == "default":
64+
return ''
65+
elif hostname == "application":
66+
# replace underscore with dots, since underscore is not valid in DNS hostnames
67+
dns_name = application_name.replace("_", ".")
68+
return dns_name
69+
elif hostname == "server":
70+
raise NotImplementedError
71+
else:
72+
raise RuntimeError('Unsupported hostname: ' + hostname)
73+
74+
def _get_portbindings(self,image):
75+
dictports=self.docker_cli.inspect_image(image)["ContainerConfig"]["ExposedPorts"]
76+
for port,mapping in dictports.items():
77+
dictports[port]=None
78+
return dictports
79+
80+
def _get_ports(self,image):
81+
ports=[]
82+
dictports=self.docker_cli.inspect_image(image)["ContainerConfig"]["ExposedPorts"]
83+
for port,mapping in dictports.items():
84+
ports.append(int(port.split('/')[0]))
85+
return ports
86+
87+
SchedulerClient = SwarmClient

templates/confd_settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
except:
1111
SCHEDULER_OPTIONS = {}
1212

13+
# scheduler swarm manager host
14+
SWARM_HOST = """{{ or (.deis_scheduler_swarm_host) "" }}"""
15+
1316
# base64-encoded SSH private key to facilitate current version of "deis run"
1417
SSH_PRIVATE_KEY = """{{ if exists "/deis/platform/sshPrivateKey" }}{{ getv "/deis/platform/sshPrivateKey" }}{{ else }}""{{end}}"""
1518

0 commit comments

Comments
 (0)