trim capability prefix to allow setting single bit
authorStephen Soltesz <stephen.soltesz@gmail.com>
Sat, 9 Mar 2013 22:16:27 +0000 (17:16 -0500)
committerStephen Soltesz <stephen.soltesz@gmail.com>
Sat, 9 Mar 2013 22:16:27 +0000 (17:16 -0500)
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".

python/vserver.py

index c847072..b2ad6a8 100644 (file)
@@ -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_")