From: Stephen Soltesz <stephen.soltesz@gmail.com>
Date: Sat, 9 Mar 2013 22:16:27 +0000 (-0500)
Subject: trim capability prefix to allow setting single bit
X-Git-Tag: util-vserver-pl-0.4-29~1
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=b3e6c1ed03bc50f25d03ca8f13aa5bca7419206f;p=util-vserver-pl.git

trim capability prefix to allow setting single bit

M-Lab has added a new ccapability to enable/disable web100 statistics
collection per vserver. vserverimpl.text2ccaps() recognizes strings such as
"raw_icmp", "vxc_raw_icmp", and "^28" to set a specific bit in the CCaps bit
field, but it does not recognize "vxc_^28".  All bcap and ccap names defined
by util-vserver are recognized with or without the cap_ and vxc_ prefixes.
So, this patch will allow an administrator to enable arbitrary bit fields in
the CCaps or BCaps of a vserver without harming compatibility with existing
capabilities.  The admin would add, for example vxc_^28 or cap_^28, to the
'capabililties' slice tag and the prefixes would be stripped before being
passed to text2*caps() as simply "^28".
---

diff --git a/python/vserver.py b/python/vserver.py
index c847072..b2ad6a8 100644
--- a/python/vserver.py
+++ b/python/vserver.py
@@ -194,7 +194,7 @@ class VServer:
 
     def get_prefix_from_capabilities(self, capabilities, prefix):
         split_caps = capabilities.split(',')
-        return ",".join(["%s" % (c) for c in split_caps if c.startswith(prefix.upper()) or c.startswith(prefix.lower())])
+        return ",".join(["%s" % (c[len(prefix):]) for c in split_caps if c.startswith(prefix.upper()) or c.startswith(prefix.lower())])
 
     def get_bcaps_from_capabilities(self, capabilities):
         return self.get_prefix_from_capabilities(capabilities, "cap_")