Skip to content

Commit

Permalink
sync to latest epu/launch-plan masters (!experiments)
Browse files Browse the repository at this point in the history
  • Loading branch information
timf committed May 12, 2011
1 parent b6d3db9 commit 321e801
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/python/epumgmt/defaults/cloudinitd_load.py
@@ -1,3 +1,4 @@
from random import random
from epumgmt.api import RunVM
from epumgmt.api.exceptions import *
import cloudinitd
Expand Down Expand Up @@ -81,6 +82,16 @@ def _load_host(p, c, m, run_name, instanceid, hostname, servicename):
"""Load a VM instance from cloudinit information
"""

# Account for
if not instanceid:
known_id = m.persistence.find_instanceid_byservice(run_name, servicename)
if known_id:
instanceid = known_id
else:
instanceid = "x-%d" % (int(random() * 100000000))
if m.persistence.check_new_instanceid(instanceid):
raise Exception("instance ID collision")

vm = RunVM()
vm.instanceid = instanceid
vm.hostname = hostname
Expand Down
3 changes: 2 additions & 1 deletion src/python/epumgmt/defaults/runlogs.py
@@ -1,5 +1,6 @@
from epumgmt.defaults.cloudinitd_load import get_cloudinitd_service
import os
import random

from epumgmt.api.exceptions import *
import epumgmt.main.em_args as em_args
Expand Down Expand Up @@ -55,7 +56,7 @@ def new_vm(self, newvm):
raise ProgrammingError("operation called without necessary validation")

if not newvm.instanceid:
return # Do this until we can distinguish services run on previously launched VMs
raise ProgrammingError("no instanceid")

thisvm_runlog_dir = os.path.join(self.thisrundir, newvm.instanceid)

Expand Down
21 changes: 21 additions & 0 deletions src/python/epumgmt/main/em_core_persistence.py
Expand Up @@ -76,6 +76,27 @@ def store_run_vms(self, run_name, run_vms):
self.cdb.add_cloudyvent(run_name, vm.instanceid, vm.nodeid, vm.hostname, vm.service_type, vm.parent, vm.runlogdir, vm.vmlogdir, e)
self.cdb.commit()

def find_instanceid_byservice(self, run_name, servicename):
"""Expects only zero or 1 result -- you cannot use the "piggybacking service" trick with a non-uniqe name
"""
if not self.cdb:
raise ProgrammingError("cannot persist anything without setup/validation")
cyvm_a = self.cdb.get_vms_by_type(run_name, servicename)
print cyvm_a
if len(cyvm_a) > 1:
raise ProgrammingError("cannot handle non-unique service names here")
if len(cyvm_a):
return cyvm_a[0].iaasid
return None

def check_new_instanceid(self, instanceid):
"""Return True if the VM instanceid has been seen before.
"""
cyvm = self.cdb.get_by_iaasid(instanceid)
if cyvm:
return True
return False

def get_run_vms_or_none(self, run_name):
"""Get list of VMs for a run name or return None"""

Expand Down

0 comments on commit 321e801

Please sign in to comment.