Skip to content

Commit

Permalink
Push options to container cgroup on edit:
Browse files Browse the repository at this point in the history
- add function for lxc-cgroup
- push memory and cpu options to cgroup
  • Loading branch information
sergey-dryabzhinsky committed May 11, 2013
1 parent 0ae86e2 commit 2e8ff58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lwp.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def edit(container=None):
form['memlimit'] = ''
if form['memlimit'] != cfg['memlimit']:
lwp.push_config_value('lxc.cgroup.memory.limit_in_bytes', form['memlimit'], container=container)
lxc.push_cgroup_value(container, 'lxc.cgroup.memory.limit_in_bytes', form['memlimit'])
flash(u'Memory limit updated for %s!' % container, 'success')

if ( form['memlimit'] != cfg['memlimit'] or form['swlimit'] != cfg['swlimit'] ) and re.match('^[0-9]+$', form['swlimit']) and int(form['swlimit']) <= int(host_memory['total'] * 2):
Expand All @@ -133,14 +134,17 @@ def edit(container=None):

if form['swlimit'] != cfg['swlimit']:
lwp.push_config_value('lxc.cgroup.memory.memsw.limit_in_bytes', form['swlimit'], container=container)
lxc.push_cgroup_value(container, 'lxc.cgroup.memory.memsw.limit_in_bytes', form['swlimit'])
flash(u'Swap limit updated for %s!' % container, 'success')

if (not form['cpus'] and form['cpus'] != cfg['cpus']) or (form['cpus'] != cfg['cpus'] and re.match('^[0-9,-]+$', form['cpus'])):
lwp.push_config_value('lxc.cgroup.cpuset.cpus', form['cpus'], container=container)
lxc.push_cgroup_value(container, 'lxc.cgroup.cpuset.cpus', form['cpus'])
flash(u'CPUs updated for %s!' % container, 'success')

if (not form['shares'] and form['shares'] != cfg['shares']) or (form['shares'] != cfg['shares'] and re.match('^[0-9]+$', form['shares'])):
lwp.push_config_value('lxc.cgroup.cpu.shares', form['shares'], container=container)
lxc.push_cgroup_value(container, 'lxc.cgroup.cpu.shares', form['shares'])
flash(u'CPU shares updated for %s!' % container, 'success')

info = lxc.info(container)
Expand Down
9 changes: 9 additions & 0 deletions lxclite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def create(container, template='ubuntu', xargs=None, storage=None):

return _run(command)

def push_cgroup_value(container, key, value):
if not exists(container): raise ContainerDoesntExists('Container {} does not exist!'.format(container))

command = 'lxc-cgroup -n {}'.format(container)
command += ' {}'.format(key)
command += ' {}'.format(value)

return _run(command)

def info(container):
'''
Check info from lxc-info*
Expand Down

0 comments on commit 2e8ff58

Please sign in to comment.