Skip to content

Instantly share code, notes, and snippets.

@markmc
Created April 26, 2013 10:16
Show Gist options
  • Save markmc/5466295 to your computer and use it in GitHub Desktop.
Save markmc/5466295 to your computer and use it in GitHub Desktop.
Splitting baremetal
class BareMetalNode(object):
(SHUTDOWN, RUNNING) = range(2)
(BUILDING, ACTIVE, ERROR, DELETED) = range(1)
def __init__(self, **kwargs):
self._name = kwargs.get('name')
self._memory_mb = kwargs['memory_mb']
self._cpus_mb = kwargs['cpus']
...
self._state = None
@property
def name(self):
...
@property
def memory_mb(self):
...
@property
def cpus(self):
...
@property
def state(self):
return ...
@property
def power_state(self):
return self.RUNNING if ... else self.SHUTDOWN
class BareMetalConnection(object):
def __init__(self):
self.bmdb = ...
self.tftp_root = ..
def lookup_node_by_name(self, node_name):
node_ref = self.bmdb.get_node_by_name(node_name)
return BareMetalNode(**node_ref)
def list_nodes(self):
return [BareMetalNode(**node_ref)
for node_ref in self.bmdb.get_node_get_all()]
def update_node_state(self, node, state):
...
def allocate_node(self, node_name, memory_mb, cpus, disk_gb):
...
node_ref = self.bmdb.find_free_node()
if not node_ref:
raise NoNodeAvailable()
node_ref = self.bmdb.node_update(node_ref['id'],
{'name': node_name})
return BareMetalNode(node_ref)
def activate_bootloader(self, node, image_path, ...):
# set up bootloader to boot the given image
...
def deactivate_bootloader(self, node, ...):
...
def activate_node(self, node, ...):
# power on the node
# in the case of tilera, run tile monitor, sshd, etc.
# start console
...
def deactivate_node(self, node, ...):
...
def get_console_output(self, node, ...):
...
class BareMetalDriver(driver.ComputeDriver):
def __init__(self):
super(BareMetalDriver, self).__init__()
self.conn = BareMetalConnection(...)
self.image_root = ...
def get_info(self, instance):
node = self.conn.lookup_node_by_name(instance['name'])
return {'state': node.power_state,
'max_mem': node.memory_mb,
'mem': node.memory_mb,
'num_cpu': node.cpus,
'cpu_time': 0}
def list_instances(self):
# NOTE(markmc): node.name being set indicates node is provisioned
return [node.name for node in self.conn.list_nodes() if node.name]
def _create_image(self, node, network_info):
# download image, inject files
return image_path
def _cleanup_images(self):
...
def spawn(self, context, instance, *args, **kwargs):
local_gb = ... # root_gb + ephemeral_gb
try:
node = self.conn.allocate_node(instance['name'],
instance['memory_mb'],
instance['vcpus'],
local_gb)
except NoNodeAvailable, e:
raise ...
self.conn.update_node_state(node, node.BUILDING)
# FIXME(markmc): plug vifs, set up nw filters
image_path = self._create_image(node, network_info)
# FIXME(markmc): attach volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment