Merge branch 'lxc_devel' of github.com:planetlab/NodeManager into lxc_devel
authorXavi Leon <xleon@ac.upc.edu>
Thu, 10 Nov 2011 15:42:10 +0000 (10:42 -0500)
committerXavi Leon <xleon@ac.upc.edu>
Thu, 10 Nov 2011 15:42:10 +0000 (10:42 -0500)
Conflicts:
sliver_libvirt.py

1  2 
sliver_libvirt.py

@@@ -50,27 -56,28 +56,32 @@@ class Sliver_LV(accounts.Account)
          # arch x86_64
          vref = rec['vref']
          if vref is None:
-             logger.log("sliver_libvirt: %s: WARNING - no vref attached defaults to lxc-debian"%(name))
+             logger.log('sliver_libvirt: %s: WARNING - no vref attached defaults to lxc-debian' % (name))
              vref = "lxc-squeeze-x86_64"
  
+         refImgDir    = os.path.join(REF_IMG_BASE_DIR, vref)
+         containerDir = os.path.join(CON_BASE_DIR, name)
          # check the template exists -- there's probably a better way..
-         if not os.path.isdir ("/vservers/.lvref/%s"%vref):
-             logger.log ("sliver_libvirt: %s: ERROR Could not create sliver - reference image %s not found"%(name,vref))
+         if not os.path.isdir(refImgDir):
+             logger.log('sliver_libvirt: %s: ERROR Could not create sliver - reference image %s not found' % (name,vref))
              return
-         
          # Copy the reference image fs
          # shutil.copytree("/vservers/.lvref/%s"%vref, "/vservers/%s"%name, symlinks=True)
-         command = ['cp', '-r', '/vservers/.lvref/%s'%vref, '/vservers/%s'%name]
+         command = ['cp', '-r', refImgDir, containerDir]
          logger.log_call(command, timeout=15*60)
  
-         # Set hostname
-         file('/vservers/%s/etc/hostname' % name, 'w').write(name)
-         
+         # Set hostname. A valid hostname cannot have '_'
+         with open(os.path.join(containerDir, 'etc/hostname'), 'w') as f:
+             print >>f, name.replace('_', '-')
 +        # Add slices group if not already present
 +        command = ['/usr/sbin/groupadd slices']
 +        logger.log_call(command, timeout=15*60)
++        
          # Add unix account
 -        command = ['/usr/sbin/useradd', '-s', '/bin/sh', name]
 +        command = ['/usr/sbin/useradd', '-g', 'slices', '-s', '/bin/sh', name, '-p', '*']
          logger.log_call(command, timeout=15*60)
  
          # Get a connection and lookup for the sliver before actually