forked from cholcombe973/autodock
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathformation.py
executable file
·75 lines (66 loc) · 2.15 KB
/
formation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import json
import unittest
from app import App
class Formation(object):
'''
A formation represents a group of application servers that are
working together to serve a common goal
[ { "container_id": "61a6cb898d23",
"username": "cholcomb",
"hostname": "owncloud01",
"cpu-shares": 102,
"ram": 100,
"ports": [{"host_port":8080,"container_port":8080}],
"host-server": "dldocker01",
"mounts": [...]},
{...}]
'''
def __init__(self, username, name, url_to_serve=None):
self.application_list = []
self.name = name
self.username = username
# The url that should be added to the load balancer for the apps to serve up
self.url_to_serve = url_to_serve
def add_app(self,
container_id,
hostname,
cpu_shares,
ram,
port_list,
ssh_host_port,
ssh_container_port,
host_server,
docker_image,
volumes=None):
'''
NOTE - No support for volumes yet.
STRING container_id #The container this app runs in
STRING hostname
INTEGER cpu_shares
INTEGER ram
List of Ints port_list
INTEGER host_port
INTEGER container_port
STRING host_server
#LIST of [host-dir]:[container-dir]:[rw|ro]
'''
app = App(container_id, self.username, hostname, cpu_shares, ram,
host_server, docker_image, ssh_host_port, volumes)
#For each port in the port_list add it to the app
for port in port_list:
#Check to see if the host port is free first?
#Throw an error if it is or just increment it?
if ':' in port:
port_list = port.split(':')
app.add_port_mapping(port_list[0], port_list[1])
else:
app.add_port_mapping(port, port)
#Add the default SSH port mapping
app.add_port_mapping(ssh_host_port, ssh_container_port)
self.application_list.append(app)
def __str__(self):
json_list = [x.get_json() for x in self.application_list]
return json.dumps(json.dumps(json_list))
class TestFormation(unittest.TestCase):
def test_addApp(self):
self.assertEquals(1, 0)