| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 1 | """ |
| 2 | Distributed Cloud Emulator (dcemulator) |
| 3 | (c) 2015 by Manuel Peuster <manuel.peuster@upb.de> |
| 4 | """ |
| 5 | import logging |
| 6 | |
| 7 | |
| 8 | DCDPID_BASE = 1000 # start of switch dpid's used for data center switches |
| 9 | |
| 10 | |
| 11 | class Datacenter(object): |
| 12 | """ |
| 13 | Represents a logical data center to which compute resources |
| 14 | (Docker containers) can be added at runtime. |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame^] | 15 | |
| 16 | Will also implement resource bookkeeping in later versions. |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 17 | """ |
| 18 | |
| 19 | def __init__(self, name): |
| 20 | self.net = None # DCNetwork to which we belong |
| 21 | self.name = name |
| 22 | self.switch = None # first prototype assumes one "bigswitch" per DC |
| 23 | |
| 24 | def _get_next_dc_dpid(self): |
| 25 | global DCDPID_BASE |
| 26 | DCDPID_BASE += 1 |
| 27 | return DCDPID_BASE |
| 28 | |
| 29 | def create(self): |
| 30 | """ |
| 31 | Each data center is represented by a single switch to which |
| 32 | compute resources can be connected at run time. |
| 33 | |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 34 | TODO: This will be changed in the future to support multiple networks |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 35 | per data center |
| 36 | """ |
| 37 | self.switch = self.net.mnet.addSwitch( |
| 38 | "%s.s1" % self.name, dpid=hex(self._get_next_dc_dpid())[2:]) |
| 39 | logging.debug("created data center switch: %s" % str(self.switch)) |
| 40 | |
| 41 | def start(self): |
| 42 | pass |
| 43 | |
| peusterm | 70baaf8 | 2016-01-06 17:14:40 +0100 | [diff] [blame] | 44 | def addCompute(self, name): |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame^] | 45 | """ |
| 46 | Create a new container as compute resource and connect it to this |
| 47 | data center. |
| 48 | """ |
| peusterm | 70baaf8 | 2016-01-06 17:14:40 +0100 | [diff] [blame] | 49 | #TODO remove mnet shortcut to have a clean API |
| 50 | #TODO connect container to DC's swtich |
| 51 | self.net.mnet.addDocker("%s.%s" % (self.name, name), dimage="ubuntu") |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 52 | |
| peusterm | 70baaf8 | 2016-01-06 17:14:40 +0100 | [diff] [blame] | 53 | def removeCompute(self, name): |
| 54 | #TODO remove mnet shortcut to have a clean API |
| 55 | #TODO disconnect container to DC's swtich |
| 56 | self.net.mnet.removeDocker("%s.%s" % (self.name, name)) |