ia64/xen-unstable

changeset 15649:207582c8d88b

Add domain name check and UUID check to 'xm new' command.

Add a domain name check and a UUID check to xm new command. The check
logic is as follows:

- If the UUID is not specified
- If a VM with same name exists
=> Update the config for that existing VM
- Else no vm with same name exists
=> Define a brand new VM with auto-generated UUID
- Else UUID is specified
- If a VM with same UUID exists
- If name is different
=> Error
- Else if name is same
=> Update the config for that existing VM
- Else no VM with same UUID exists
- If name is different
=> Define a branch new VM with that name
- Else if name is same
=> Error

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author kfraser@localhost.localdomain
date Tue Jul 24 18:05:04 2007 +0100 (2007-07-24)
parents d9836851a2a4
children 68260372b6da
files tools/python/xen/xend/XendDomain.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Tue Jul 24 15:47:36 2007 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Tue Jul 24 18:05:04 2007 +0100
     1.3 @@ -51,6 +51,7 @@ from xen.xend.xenstore.xstransact import
     1.4  from xen.xend.xenstore.xswatch import xswatch
     1.5  from xen.util import mkdir
     1.6  from xen.xend import uuid
     1.7 +from xen.xend import sxp
     1.8  
     1.9  xc = xen.lowlevel.xc.xc()
    1.10  xoptions = XendOptions.instance() 
    1.11 @@ -968,6 +969,31 @@ class XendDomain:
    1.12          try:
    1.13              try:
    1.14                  domconfig = XendConfig.XendConfig(sxp_obj = config)
    1.15 +                
    1.16 +                domains = self.list('all')
    1.17 +                domains = map(lambda dom: dom.sxpr(), domains)
    1.18 +                for dom in domains:
    1.19 +                    if sxp.child_value(config, 'uuid', None):
    1.20 +                        if domconfig['uuid'] == sxp.child_value(dom, 'uuid'):
    1.21 +                            if domconfig['name_label'] != sxp.child_value(dom, 'name'):
    1.22 +                                raise XendError("Domain UUID '%s' is already used." % \
    1.23 +                                                domconfig['uuid'])
    1.24 +                            else:
    1.25 +                                # Update the config for that existing domain
    1.26 +                                # because it is same name and same UUID.
    1.27 +                                break
    1.28 +                        else:
    1.29 +                            if domconfig['name_label'] == sxp.child_value(dom, 'name'):
    1.30 +                                raise XendError("Domain name '%s' is already used." % \
    1.31 +                                                domconfig['name_label'])
    1.32 +                    else:
    1.33 +                        if domconfig['name_label'] == sxp.child_value(dom, 'name'):
    1.34 +                            # Overwrite the auto-generated UUID by the UUID
    1.35 +                            # of the existing domain. And update the config
    1.36 +                            # for that existing domain.
    1.37 +                            domconfig['uuid'] = sxp.child_value(dom, 'uuid')
    1.38 +                            break
    1.39 +                
    1.40                  dominfo = XendDomainInfo.createDormant(domconfig)
    1.41                  log.debug("Creating new managed domain: %s" %
    1.42                            dominfo.getName())