[](https://travis-ci.org/cloudsigma/cgroupspy)
cgroupspy
=========
Python library for managing cgroups
The library provides a pythonic way to manage and represent cgroups. It provides interfaces that convert
python objects to cgroups compatible strings and vise versa.
Trees
-----
cgroupspy has a couple of ways to represent the cgroups filesystem
* As a tree - this is the most basic and generic way to represent them. You basically construct it from all
the directories in the cgroups root.
* A grouped tree - that has access to all cgroup partitions with the same name, on the same level. For example -
'machine' partition in memory, cpuset, cpus, etc cgroups. All these attributes are
accessed via machine.cpus, machine.cpuset, etc.
* A VMTree - a subclass of grouped tree with utilities for simple management of libvirt guests
Example usage
-------------
```python
#Import the trees module, which contains a tree representation of cgroups
>>> from cgroupspy import trees
# This is the most basic type of cgroup tree. It models the filesystem.
>>> t = trees.Tree()
# It has a root which is of type Node
>>> t.root
<Node />
# And the root has children
>>> print(t.root.children)
[<Node /hugetlb>, <Node /net_prio>, <Node /perf_event>, <Node /blkio>, <Node /net_cls>, <Node /freezer>, <Node /devices>, <Node /memory>, <Node /cpuacct>, <Node /cpu>, <Node /cpuset>, <Node /systemd>, <Node /cgmanager>]
# You can for example get the cpuset
>>> cset = t.get_node_by_path('/cpuset/')
>>> cset
<Node /cpuset>
# The controller used for this cgroup is a CpuSetController
>>> cset.controller
<cgroupspy.controllers.CpuSetController object at 0x7f63a3843050>
# Which can for example show you the cpu pinning
>>> cset.controller.cpus
set([0, 1])
# You can create a cgroup
>>> test = cset.create_cgroup('test')
<Node /cpuset/test>
# See its cpu restrictions
>>> test.controller.cpus
set([0, 1])
# And change them
>>> test.controller.cpus = [1]
# The tasks in this cgroup are now restricted to cpu 1
>>> test.controller.cpus
set([1])
```
Another example with the VMTree - for managing libvirt guests
```python
>>> from cgroupspy.trees import VMTree
>>> vmt = VMTree()
>>> print(vmt.vms)
{u'1ce10f47-fb4e-4b6a-8ee6-ba34940cdda7.libvirt-qemu': <NodeVM 1ce10f47-fb4e-4b6a-8ee6-ba34940cdda7.libvirt-qemu>,
u'3d5013b9-93ed-4ef1-b518-a2cea43f69ad.libvirt-qemu': <NodeVM 3d5013b9-93ed-4ef1-b518-a2cea43f69ad.libvirt-qemu>,
}
>>> vm = vmt.get_vm_node("1ce10f47-fb4e-4b6a-8ee6-ba34940cdda7")
>>> print(vm.cpu.shares)
1024
>>> print(vm.cpuset.cpus)
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
>>> print(vm.memory.limit_in_bytes)
25603080192
>>> print(vm.children)
[<NodeControlGroup vcpu1>,
<NodeControlGroup vcpu0>,
<NodeControlGroup emulator>]
>>> print(vm.path)
/machine/grey/1ce10f47-fb4e-4b6a-8ee6-ba34940cdda7.libvirt-qemu
>>> vcpu1 = vm.children[0]
>>> print(vcpu1.cpuset.cpus)
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
>>> vcpu1.cpuset.cpus = {1,2,3}
>>> print(vcpu1.cpuset.cpus)
{1, 2, 3}
```
License
-------
new BSD licence
Raw data
{
"_id": null,
"home_page": "https://github.com/cloudsigma/cgroupspy",
"name": "cgroupspy",
"maintainer": "Miguel Trujillo",
"docs_url": null,
"requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7",
"maintainer_email": "miguel@cloudsigma.com",
"keywords": "cgroups",
"author": "CloudSigma AG",
"author_email": "dev-support@cloudsigma.com",
"download_url": "https://files.pythonhosted.org/packages/7f/87/1861459dafe2bdb8cd590280896bb78084a90b4cb76b5425592518b78c3d/cgroupspy-0.2.3.tar.gz",
"platform": null,
"description": "[](https://travis-ci.org/cloudsigma/cgroupspy)\ncgroupspy\n=========\n\nPython library for managing cgroups\n\nThe library provides a pythonic way to manage and represent cgroups. It provides interfaces that convert\npython objects to cgroups compatible strings and vise versa.\n\n\nTrees\n-----\ncgroupspy has a couple of ways to represent the cgroups filesystem\n\n* As a tree - this is the most basic and generic way to represent them. You basically construct it from all\nthe directories in the cgroups root.\n\n* A grouped tree - that has access to all cgroup partitions with the same name, on the same level. For example -\n'machine' partition in memory, cpuset, cpus, etc cgroups. All these attributes are\naccessed via machine.cpus, machine.cpuset, etc.\n\n* A VMTree - a subclass of grouped tree with utilities for simple management of libvirt guests\n\nExample usage\n-------------\n```python\n#Import the trees module, which contains a tree representation of cgroups\n>>> from cgroupspy import trees\n\n# This is the most basic type of cgroup tree. It models the filesystem.\n>>> t = trees.Tree()\n\n# It has a root which is of type Node\n>>> t.root\n<Node />\n\n# And the root has children\n>>> print(t.root.children)\n[<Node /hugetlb>, <Node /net_prio>, <Node /perf_event>, <Node /blkio>, <Node /net_cls>, <Node /freezer>, <Node /devices>, <Node /memory>, <Node /cpuacct>, <Node /cpu>, <Node /cpuset>, <Node /systemd>, <Node /cgmanager>]\n\n# You can for example get the cpuset\n>>> cset = t.get_node_by_path('/cpuset/')\n>>> cset\n<Node /cpuset>\n\n# The controller used for this cgroup is a CpuSetController\n>>> cset.controller\n<cgroupspy.controllers.CpuSetController object at 0x7f63a3843050>\n\n# Which can for example show you the cpu pinning\n>>> cset.controller.cpus\nset([0, 1])\n\n# You can create a cgroup\n>>> test = cset.create_cgroup('test')\n<Node /cpuset/test>\n\n# See its cpu restrictions\n>>> test.controller.cpus\nset([0, 1])\n\n# And change them\n>>> test.controller.cpus = [1]\n\n# The tasks in this cgroup are now restricted to cpu 1\n>>> test.controller.cpus\nset([1])\n```\n\nAnother example with the VMTree - for managing libvirt guests\n\n```python\n>>> from cgroupspy.trees import VMTree\n>>> vmt = VMTree()\n>>> print(vmt.vms)\n{u'1ce10f47-fb4e-4b6a-8ee6-ba34940cdda7.libvirt-qemu': <NodeVM 1ce10f47-fb4e-4b6a-8ee6-ba34940cdda7.libvirt-qemu>,\n u'3d5013b9-93ed-4ef1-b518-a2cea43f69ad.libvirt-qemu': <NodeVM 3d5013b9-93ed-4ef1-b518-a2cea43f69ad.libvirt-qemu>,\n}\n\n>>> vm = vmt.get_vm_node(\"1ce10f47-fb4e-4b6a-8ee6-ba34940cdda7\")\n>>> print(vm.cpu.shares)\n1024\n>>> print(vm.cpuset.cpus)\n{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}\n>>> print(vm.memory.limit_in_bytes)\n25603080192\n>>> print(vm.children)\n[<NodeControlGroup vcpu1>,\n <NodeControlGroup vcpu0>,\n <NodeControlGroup emulator>]\n>>> print(vm.path)\n/machine/grey/1ce10f47-fb4e-4b6a-8ee6-ba34940cdda7.libvirt-qemu\n>>> vcpu1 = vm.children[0]\n>>> print(vcpu1.cpuset.cpus)\n{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}\n\n>>> vcpu1.cpuset.cpus = {1,2,3}\n\n>>> print(vcpu1.cpuset.cpus)\n{1, 2, 3}\n```\n\nLicense\n-------\nnew BSD licence",
"bugtrack_url": null,
"license": "New BSD",
"summary": "Python library for managing cgroups",
"version": "0.2.3",
"project_urls": {
"Homepage": "https://github.com/cloudsigma/cgroupspy"
},
"split_keywords": [
"cgroups"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7f871861459dafe2bdb8cd590280896bb78084a90b4cb76b5425592518b78c3d",
"md5": "fb5e9d5cfda7c57afe2197468e291a48",
"sha256": "8ee941c7ab9234a0b17a81b0b26487f7f1031f78b7a24cdd8eed1b5fa5970496"
},
"downloads": -1,
"filename": "cgroupspy-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "fb5e9d5cfda7c57afe2197468e291a48",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7",
"size": 16593,
"upload_time": "2024-03-19T23:34:39",
"upload_time_iso_8601": "2024-03-19T23:34:39.012590Z",
"url": "https://files.pythonhosted.org/packages/7f/87/1861459dafe2bdb8cd590280896bb78084a90b4cb76b5425592518b78c3d/cgroupspy-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-19 23:34:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cloudsigma",
"github_project": "cgroupspy",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "cgroupspy"
}