-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathapp.py
executable file
·58 lines (48 loc) · 2 KB
/
app.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
import unittest
class App(object):
'''
An app or application has a hostname,
cpu_shares, ram, port_list, volumes and a host_server
it runs on.
'''
def __init__(self, container_id, username, hostname,
cpu_shares, ram, host_server, docker_image, ssh_port, volume_list=None):
self.container_id = container_id
self.username = username
self.hostname = hostname
self.cpu_shares = int(cpu_shares)
self.ram = int(ram)
self.port_list = []
self.host_server = host_server
self.docker_image = docker_image
self.volume_list = volume_list
self.ssh_port = int(ssh_port)
def change_container_id(self, new_container_id):
self.container_id = new_container_id
def change_host_server(self, new_host_server):
self.host_server = new_host_server
def change_ram_limit(self, new_ram_limit):
self.ram = int(new_ram_limit)
def change_cpu_shares(self, new_cpu_shares):
self.cpu_shares = int(new_cpu_shares)
def change_docker_image(self, new_docker_image):
self.docker_image = new_docker_image
def add_port_mapping(self, host_port, container_port):
port_map = "{host_port}:{container_port}".format(host_port=host_port,
container_port=container_port)
self.port_list.append(port_map)
def get_json(self):
return {'container_id': self.container_id, 'username': self.username,
'hostname': self.hostname, 'cpu_shares': self.cpu_shares,
'ram': self.ram, 'port_list': self.port_list,
'host_server': self.host_server, 'volumes': self.volume_list,
'ssh_port': self.ssh_port}
class TestApp(unittest.TestCase):
def test_json_output(self):
expected_results = {'container_id': 'test',
'username': 'joe_user', 'hostname': 'test001', 'cpu_shares': 100,
'ram': 100, 'port_list': [], 'host_server': 'test_server',
'volumes': ['/mnt/vol/test_vol'], 'ssh_port': 22}
a = App('test', 'joe_user', 'test001', 100, 100, 'test_server', 22,
['/mnt/vol/test_vol'])
self.assertEqual(expected_results, a.get_json())