- print "Unexpected error:", sys.exc_info()
-
- ''' PRIVATE/HELPER/STATIC METHODS '''
- @staticmethod
- def getConnection():
- ''' Helper method to get a connection to the LXC driver of Libvirt '''
- conn = libvirt.open('lxc:///')
- if conn == None:
- print 'Failed to open connection to LXC hypervisor'
- sys.exit(1)
- else: return conn
-
- @staticmethod
- def info(dom):
- ''' Helper method to get a "nice" output of the info struct for debug'''
- [state, maxmem, mem, ncpu, cputime] = dom.info()
- return '%s is %s, maxmem = %s, mem = %s, ncpu = %s, cputime = %s' % (dom.name(), states.get(state, state), maxmem, mem, ncpu, cputime)
+ logger.verbose('sliver_libvirt: UNEXPECTED ERROR in %s...\n%s'%(self.name, sys.exc_info[0]))
+ print 'sliver_libvirt: UNEXPECTED ERROR in %s...\n%s'%(self.name, sys.exc_info[0])
+
+ def configure(self, rec):
+
+ #sliver.[LXC/QEMU] tolower case
+ sliver_type = rec['type'].split('.')[1].lower()
+
+ BASE_DIR = '/cgroup/libvirt/%s/%s/'%(sliver_type, self.name)
+
+ # Disk allocation
+ # No way through cgroups... figure out how to do that with user/dir quotas.
+ # There is no way to do quota per directory. Chown-ing would create
+ # problems as username namespaces are not yet implemented (and thus, host
+ # and containers share the same name ids
+
+ # Btrfs support quota per volumes
+
+ # It will depend on the FS selection
+ if rec.has_key('disk_max'):
+ disk_max = rec['disk_max']
+ if disk_max == 0:
+ # unlimited
+ pass
+ else:
+ # limit to certain number
+ pass
+
+ # Memory allocation
+ if rec.has_key('memlock_hard'):
+ mem = rec['memlock_hard'] * 1024 # hard limit in bytes
+ with open(os.path.join(BASE_DIR, 'memory.limit_in_bytes'), 'w') as f:
+ print >>f, mem
+ if rec.has_key('memlock_soft'):
+ mem = rec['memlock_soft'] * 1024 # soft limit in bytes
+ with open(os.path.join(BASE_DIR, 'memory.soft_limit_in_bytes'), 'w') as f:
+ print >>f, mem
+
+ # CPU allocation
+ # Only cpu_shares until figure out how to provide limits and guarantees
+ # (RT_SCHED?)
+ if rec.has_key('cpu_share'):
+ cpu_share = rec['cpu_share']
+ with open(os.path.join(BASE_DIR, 'cpu.shares'), 'w') as f:
+ print >>f, cpu_share
+
+ # Call the upper configure method (ssh keys...)
+ accounts.Account.configure(self, rec)
+
+