--- xen/xm/create.py 2008-04-14 23:48:49.000000000 +0200 +++ xen/xm/create.py 2008-04-27 02:42:44.000000000 +0200 @@ -28,6 +28,7 @@ import xmlrpclib from xen.xend import sxp +from xen.xend import XendOptions from xen.xend import PrettyPrint as SXPPrettyPrint from xen.xend import osdep import xen.xend.XendClient @@ -1045,7 +1046,6 @@ d[k] = v return d - def make_domain(opts, config): """Create, build and start a domain. @@ -1055,6 +1055,51 @@ @rtype: int """ + # This would be the right place to insert cluster awareness + # + # So let's do it[tm] + + # FIXME + # Most probably there is a much nicer way to get the name + # of the domain to be started. But hey, I'm new to python + # and got this idea from a friend. + def get_name_from_config (c_list): + for item in c_list: + try: + if item[0] == 'name': + return item[1] + except: + pass + return None + + # Should we do locking? + if XendOptions.instance().get_cluster_locking() == 'yes': + opts.info ("Cluster locking check activated.") + + cluster_locking_dir = XendOptions.instance().get_cluster_locking_dir() + domain_name = get_name_from_config (config) + + if not os.path.isdir (cluster_locking_dir): + err ("Cluster locking dir \"%s\" does not exist!\n" % cluster_locking_dir) + + # Where to look for/create the lockfile + lockfile_path = cluster_locking_dir + '/' + domain_name + '.lock' + + # If there already exists a lockfile, try to get the name + # of the Dom0 hosting the domain + if os.path.isfile (lockfile_path): + lockfile = open (lockfile_path, 'r') + other_node = lockfile.readline() + lockfile.close () + + err ("Sorry, domain \"%s\" seems to be already running on this cluster on node \"%s\".\n" % (domain_name, other_node)) + + # OK, no lockfile found, create it and proceed + lockfile = open (lockfile_path, 'w') + lockfile.write (str (socket.gethostname ())) + lockfile.close () + + # Normal startup try: dominfo = server.xend.domain.create(config) except xmlrpclib.Fault, ex: