2 Distributed Cloud Emulator (dcemulator)
3 (c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
8 DCDPID_BASE
= 1000 # start of switch dpid's used for data center switches
11 class Datacenter(object):
13 Represents a logical data center to which compute resources
14 (Docker containers) can be added at runtime.
16 Will also implement resource bookkeeping in later versions.
19 def __init__(self
, name
):
20 self
.net
= None # DCNetwork to which we belong
22 self
.switch
= None # first prototype assumes one "bigswitch" per DC
23 self
.containers
= {} # keep track of running containers
25 def _get_next_dc_dpid(self
):
32 Each data center is represented by a single switch to which
33 compute resources can be connected at run time.
35 TODO: This will be changed in the future to support multiple networks
38 self
.switch
= self
.net
.mnet
.addSwitch(
39 "%s.s1" % self
.name
, dpid
=hex(self
._get
_next
_dc
_dpid
())[2:])
40 logging
.debug("created data center switch: %s" % str(self
.switch
))
45 def addCompute(self
, name
):
47 Create a new container as compute resource and connect it to this
51 d
= self
.net
.addDocker("%s.%s" % (self
.name
, name
), dimage
="ubuntu")
52 self
.net
.addLink(d
, self
.switch
, params1
={"ip": "10.0.0.254/8"})
53 self
.containers
[name
] = d
55 def removeCompute(self
, name
):
57 Stop and remove a container from this data center.
59 assert name
in self
.containers
61 link
=None, node1
=self
.containers
[name
], node2
=self
.switch
)
62 self
.net
.removeDocker("%s.%s" % (self
.name
, name
))
63 del self
.containers
[name
]