root / trunk / src / haizea / core / enact / simulated.py @ 641
1 |
# -------------------------------------------------------------------------- #
|
---|---|
2 |
# Copyright 2006-2009, University of Chicago #
|
3 |
# Copyright 2008-2009, Distributed Systems Architecture Group, Universidad #
|
4 |
# Complutense de Madrid (dsa-research.org) #
|
5 |
# #
|
6 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7 |
# not use this file except in compliance with the License. You may obtain #
|
8 |
# a copy of the License at #
|
9 |
# #
|
10 |
# http://www.apache.org/licenses/LICENSE-2.0 #
|
11 |
# #
|
12 |
# Unless required by applicable law or agreed to in writing, software #
|
13 |
# distributed under the License is distributed on an "AS IS" BASIS, #
|
14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
15 |
# See the License for the specific language governing permissions and #
|
16 |
# limitations under the License. #
|
17 |
# -------------------------------------------------------------------------- #
|
18 |
|
19 |
from haizea.core.leases import Capacity |
20 |
from haizea.core.scheduler.resourcepool import ResourcePoolNode |
21 |
from haizea.core.enact import ResourcePoolInfo, VMEnactment, DeploymentEnactment |
22 |
import haizea.common.constants as constants |
23 |
from haizea.common.utils import get_config |
24 |
import logging |
25 |
|
26 |
class SimulatedResourcePoolInfo(ResourcePoolInfo): |
27 |
def __init__(self, site): |
28 |
ResourcePoolInfo.__init__(self)
|
29 |
self.logger = logging.getLogger("ENACT.SIMUL.INFO") |
30 |
config = get_config() |
31 |
|
32 |
if not ("CPU" in site.resource_types and "Memory" in site.resource_types): |
33 |
# CPU and Memory must be specified
|
34 |
# TODO: raise something more meaningful
|
35 |
raise
|
36 |
|
37 |
# Disk and network should be specified but, if not, we can
|
38 |
# just add arbitrarily large values.
|
39 |
if not "Disk" in site.resource_types: |
40 |
site.add_resource("Disk", [1000000]) |
41 |
|
42 |
if not "Net-in" in site.resource_types: |
43 |
site.add_resource("Net-in", [1000000]) |
44 |
|
45 |
if not "Net-out" in site.resource_types: |
46 |
site.add_resource("Net-out", [1000000]) |
47 |
|
48 |
self.resource_types = site.get_resource_types()
|
49 |
|
50 |
nodes = site.nodes.get_all_nodes() |
51 |
|
52 |
self.nodes = dict([(id, ResourcePoolNode(id, "simul-%i" % id, capacity)) for (id, capacity) in nodes.items()]) |
53 |
for node in self.nodes.values(): |
54 |
node.enactment_info = node.id |
55 |
|
56 |
def get_nodes(self): |
57 |
return self.nodes |
58 |
|
59 |
def get_resource_types(self): |
60 |
return self.resource_types |
61 |
|
62 |
def get_migration_bandwidth(self): |
63 |
return 100 # TODO: Get from config file |
64 |
|
65 |
class SimulatedVMEnactment(VMEnactment): |
66 |
def __init__(self): |
67 |
VMEnactment.__init__(self)
|
68 |
self.logger = logging.getLogger("ENACT.SIMUL.VM") |
69 |
|
70 |
def start(self, action): |
71 |
for vnode in action.vnodes: |
72 |
# Unpack action
|
73 |
pnode = action.vnodes[vnode].pnode |
74 |
image = action.vnodes[vnode].diskimage |
75 |
cpu = 100 #action.vnodes[vnode].resources.get_by_type(constants.RES_CPU) |
76 |
memory = 1024 #action.vnodes[vnode].resources.get_by_type(constants.RES_MEM) |
77 |
self.logger.debug("Received request to start VM for L%iV%i on host %i, image=%s, cpu=%i, mem=%i" |
78 |
% (action.lease_haizea_id, vnode, pnode, image, cpu, memory)) |
79 |
|
80 |
def stop(self, action): |
81 |
for vnode in action.vnodes: |
82 |
self.logger.debug("Received request to stop VM for L%iV%i" |
83 |
% (action.lease_haizea_id, vnode)) |
84 |
|
85 |
def suspend(self, action): |
86 |
for vnode in action.vnodes: |
87 |
self.logger.debug("Received request to suspend VM for L%iV%i" |
88 |
% (action.lease_haizea_id, vnode)) |
89 |
|
90 |
def resume(self, action): |
91 |
for vnode in action.vnodes: |
92 |
self.logger.debug("Received request to resume VM for L%iV%i" |
93 |
% (action.lease_haizea_id, vnode)) |
94 |
|
95 |
def verify_suspend(self, action): |
96 |
return 0 |
97 |
|
98 |
def verify_resume(self, action): |
99 |
return 0 |
100 |
|
101 |
class SimulatedDeploymentEnactment(DeploymentEnactment): |
102 |
def __init__(self): |
103 |
DeploymentEnactment.__init__(self)
|
104 |
self.logger = logging.getLogger("ENACT.SIMUL.INFO") |
105 |
config = get_config() |
106 |
|
107 |
self.bandwidth = config.get("imagetransfer-bandwidth") |
108 |
|
109 |
imgcapacity = Capacity([constants.RES_NETOUT]) |
110 |
imgcapacity.set_quantity(constants.RES_NETOUT, self.bandwidth)
|
111 |
|
112 |
# TODO: Determine node number based on site
|
113 |
self.imagenode = ResourcePoolNode(1000, "image_node", imgcapacity) |
114 |
|
115 |
def get_imagenode(self): |
116 |
return self.imagenode |
117 |
|
118 |
def get_aux_nodes(self): |
119 |
return [self.imagenode] |
120 |
|
121 |
def get_bandwidth(self): |
122 |
return self.bandwidth |
123 |
|
124 |
def resolve_to_file(self, lease_id, vnode, diskimage_id): |
125 |
return "/var/haizea/images/%s-L%iV%i" % (diskimage_id, lease_id, vnode) |