root / trunk / src / haizea / core / enact / simulated.py @ 676
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 |
import logging |
24 |
|
25 |
class SimulatedResourcePoolInfo(ResourcePoolInfo): |
26 |
def __init__(self, site): |
27 |
ResourcePoolInfo.__init__(self)
|
28 |
self.logger = logging.getLogger("ENACT.SIMUL.INFO") |
29 |
|
30 |
if not ("CPU" in site.resource_types and "Memory" in site.resource_types): |
31 |
# CPU and Memory must be specified
|
32 |
# TODO: raise something more meaningful
|
33 |
raise
|
34 |
|
35 |
# Disk and network should be specified but, if not, we can
|
36 |
# just add arbitrarily large values.
|
37 |
if not "Disk" in site.resource_types: |
38 |
site.add_resource("Disk", [1000000]) |
39 |
|
40 |
if not "Net-in" in site.resource_types: |
41 |
site.add_resource("Net-in", [1000000]) |
42 |
|
43 |
if not "Net-out" in site.resource_types: |
44 |
site.add_resource("Net-out", [1000000]) |
45 |
|
46 |
self.resource_types = site.get_resource_types()
|
47 |
|
48 |
nodes = site.nodes.get_all_nodes() |
49 |
|
50 |
self.nodes = dict([(id, ResourcePoolNode(id, "simul-%i" % id, capacity)) for (id, capacity) in nodes.items()]) |
51 |
for node in self.nodes.values(): |
52 |
node.enactment_info = node.id |
53 |
|
54 |
def get_nodes(self): |
55 |
return self.nodes |
56 |
|
57 |
def refresh(self): |
58 |
return []
|
59 |
|
60 |
def get_resource_types(self): |
61 |
return self.resource_types |
62 |
|
63 |
def get_migration_bandwidth(self): |
64 |
return 100 # TODO: Get from config file |
65 |
|
66 |
class SimulatedVMEnactment(VMEnactment): |
67 |
def __init__(self): |
68 |
VMEnactment.__init__(self)
|
69 |
self.logger = logging.getLogger("ENACT.SIMUL.VM") |
70 |
|
71 |
def start(self, action): |
72 |
for vnode in action.vnodes: |
73 |
# Unpack action
|
74 |
pnode = action.vnodes[vnode].pnode |
75 |
image = action.vnodes[vnode].diskimage |
76 |
cpu = 100 #action.vnodes[vnode].resources.get_by_type(constants.RES_CPU) |
77 |
memory = 1024 #action.vnodes[vnode].resources.get_by_type(constants.RES_MEM) |
78 |
self.logger.debug("Received request to start VM for L%iV%i on host %i, image=%s, cpu=%i, mem=%i" |
79 |
% (action.lease_haizea_id, vnode, pnode, image, cpu, memory)) |
80 |
|
81 |
def stop(self, action): |
82 |
for vnode in action.vnodes: |
83 |
self.logger.debug("Received request to stop VM for L%iV%i" |
84 |
% (action.lease_haizea_id, vnode)) |
85 |
|
86 |
def suspend(self, action): |
87 |
for vnode in action.vnodes: |
88 |
self.logger.debug("Received request to suspend VM for L%iV%i" |
89 |
% (action.lease_haizea_id, vnode)) |
90 |
|
91 |
def resume(self, action): |
92 |
for vnode in action.vnodes: |
93 |
self.logger.debug("Received request to resume VM for L%iV%i" |
94 |
% (action.lease_haizea_id, vnode)) |
95 |
|
96 |
def verify_suspend(self, action): |
97 |
return 0 |
98 |
|
99 |
def verify_resume(self, action): |
100 |
return 0 |
101 |
|
102 |
class SimulatedDeploymentEnactment(DeploymentEnactment): |
103 |
def __init__(self, bandwidth): |
104 |
DeploymentEnactment.__init__(self)
|
105 |
self.logger = logging.getLogger("ENACT.SIMUL.INFO") |
106 |
|
107 |
self.bandwidth = 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) |