Add missing file.
authorDaniel Hokka Zakrisson <dhokka@cs.princeton.edu>
Fri, 30 Nov 2007 19:22:49 +0000 (19:22 +0000)
committerDaniel Hokka Zakrisson <dhokka@cs.princeton.edu>
Fri, 30 Nov 2007 19:22:49 +0000 (19:22 +0000)
Add generated spec-file so the build can work.

python/cpulimit.py [new file with mode: 0755]
util-vserver-pl.spec [new file with mode: 0644]
util-vserver-pl.spec.in

diff --git a/python/cpulimit.py b/python/cpulimit.py
new file mode 100755 (executable)
index 0000000..708f092
--- /dev/null
@@ -0,0 +1,117 @@
+#!/usr/bin/python2 -u
+
+import sys, os, re, string
+
+
+TCBASE="/rcfs/taskclass/"
+RULES="/rcfs/ce/rules/"
+
+SYSCLASS=TCBASE + "system"
+SYSRULE=RULES + "system"
+SYSCPUSHARE=100
+DEFAULTMAXCPUSHARE=8192
+
+def checkckrm():
+    checks = [ "/rcfs", TCBASE, RULES ]
+
+    for check in checks:
+        try:
+            answer = os.stat(check)
+        except:
+            print "%s does not exist" % check
+            return False
+    
+    return True
+
+def checkclass(tc):
+    try:
+        answer = os.stat(TCBASE + tc)
+        return True
+
+    except:
+        print "%s class does not exist" % tc
+        return False
+
+def getxid(name):
+    xid = -1
+    fp = open('/etc/passwd')
+    for line in fp.readlines():
+        rec = string.splitfields(line,':')
+        if rec[0] == name:
+            xid = int(rec[2])
+            break
+
+    fp.close()
+    
+    if xid == -1:
+        # raise an exception
+        pass
+
+    return xid
+
+def write(filename,s):
+    fp = os.open(filename,os.O_WRONLY|os.O_CREAT)
+    os.write(fp,s)
+    os.close(fp)
+
+def vs2ckrm_on(tc):
+    xid = getxid(tc)
+
+    try:
+        os.mkdir(TCBASE + tc)
+    except OSError:
+        pass # ignore oserror for file exists
+    
+    s = "xid=%d,class=%s" % (xid,TCBASE+tc)
+    fname = RULES + tc
+    write(fname, s)
+
+def vs2ckrm_off(tc):
+    fname = TCBASE + tc + "/members"
+    for i in range(1,15):
+        fp = open(fname)
+        lines = fp.readlines()
+        try:
+            lines.remove("No data to display\n")
+        except ValueError:
+            pass
+        if len(lines) == 0:
+            try:
+                answer = os.stat(RULES + tc)
+                os.unlink(RULES + tc)
+                answer = os.stat(TCBASE + tc)                
+                os.rmdir(TCBASE + tc)
+            except:
+                pass
+            break
+
+        else:
+            print "enter context 1 and kill processes", lines
+        
+
+def cpulimit(tc,limit):
+    global TCBASE
+
+    fname = TCBASE + tc + "/shares"
+    s = "res=cpu,guarantee=%d\n" % limit
+    write(fname,s)
+
+def cpuinit():
+    global TCBASE
+
+    fname = TCBASE + "shares"
+    s = "res=cpu,total_guarantee=%d\n" % DEFAULTMAXCPUSHARE
+    write(fname,s)
+
+if __name__ == "__main__":
+    try:
+        name = sys.argv[1]
+        limit = int(sys.argv[2])
+    except:
+        print "caught exception"
+
+    if checkckrm() is True:
+        cpuinit()
+        vs2ckrm_on(name)
+        cpulimit(name,limit)
+        vs2ckrm_off(name)
diff --git a/util-vserver-pl.spec b/util-vserver-pl.spec
new file mode 100644 (file)
index 0000000..c2bda9b
--- /dev/null
@@ -0,0 +1,95 @@
+%define name   util-vserver-pl
+%define version        0.1
+%define release        1%{?pldistro:.%{pldistro}}%{?date:.%{date}}
+
+%define python_sitearch %( python -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)" )
+
+Summary: PlanetLab extensions to util-vserver
+Name: %{name}
+Version: %{version}
+Release: %{release}
+License: GPL
+Group: System Environment/Base
+Source0: %{name}-%{version}.tar.bz2
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
+Requires: util-vserver util-vserver-core util-vserver-build util-vserver-sysv
+Obsoletes: util-vserver-py32 resman util-vserver-python
+BuildRequires: util-vserver-core util-vserver-devel
+BuildRequires: autoconf automake libtool
+
+%description
+This package contains all PlanetLab extensions to util-vserver.
+
+%prep
+%setup -q
+autoreconf -fi
+
+
+%build
+%configure
+make
+
+
+%install
+rm -fr %{buildroot}
+make DESTDIR=%{buildroot} install
+
+mkdir %{buildroot}/bin
+ln -s ..%{_sbindir}/vsh %{buildroot}/bin/vsh
+
+rm -f %{buildroot}%{python_sitearch}/vserverimpl.a
+rm -f %{buildroot}%{python_sitearch}/vserverimpl.la
+
+# Generate file list for python package
+find "%{buildroot}" -name '*.py' | { while read FILE; do
+       f="${FILE#%{buildroot}}"
+       echo "${f}"
+       # need to touch these files, as they are not produced on FC4 or below
+       touch ${FILE}c
+       touch ${FILE}o
+       echo %%ghost "${f}c"
+       echo %%ghost "${f}o"
+done } > %name-python.list
+
+
+%post
+# add /bin/vsh to list of secure shells
+if [ ! -f /etc/shells ] || ! grep -q '^/bin/vsh$' /etc/shells ; then
+       echo /bin/vsh >> /etc/shells
+fi
+
+
+%postun
+# 0 = erase, 1 = upgrade
+if [ "$1" = 0 ] ; then
+       perl -i -n -e 'next if /^\/bin\/vsh$/; print' /etc/shells
+fi
+
+
+%clean
+rm -fr %{buildroot}
+
+
+%files -f %name-python.list
+%defattr(-,root,root,-)
+%{_sbindir}/bwlimit
+%{_sbindir}/disklimit
+%{_sbindir}/vuseradd
+%{_sbindir}/vuserdel
+%{python_sitearch}/vserverimpl.so
+
+%{_sbindir}/vsh
+/bin/vsh
+%{_mandir}/man8/vsh.8*
+
+%{_sbindir}/vip6-autod
+%{_sysconfdir}/init.d/vip6-autod
+
+%{_sbindir}/vcached
+%{_sysconfdir}/cron.d/vcached.cron
+%{_sysconfdir}/logrotate.d/vcached.logrotate
+
+
+%changelog
+* Fri Nov 30 2007 Daniel Hokka Zakrisson <daniel@hozac.com> - 0.1-1
+- Initial release
index ee196cd..c760406 100644 (file)
@@ -1,5 +1,5 @@
 %define name   util-vserver-pl
-%define version        0.1
+%define version        @VERSION@
 %define release        1%{?pldistro:.%{pldistro}}%{?date:.%{date}}
 
 %define python_sitearch %( python -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)" )
@@ -34,6 +34,7 @@ make
 rm -fr %{buildroot}
 make DESTDIR=%{buildroot} install
 
+mkdir %{buildroot}/bin
 ln -s ..%{_sbindir}/vsh %{buildroot}/bin/vsh
 
 rm -f %{buildroot}%{python_sitearch}/vserverimpl.a
@@ -75,6 +76,7 @@ rm -fr %{buildroot}
 %{_sbindir}/disklimit
 %{_sbindir}/vuseradd
 %{_sbindir}/vuserdel
+%{python_sitearch}/vserverimpl.so
 
 %{_sbindir}/vsh
 /bin/vsh
@@ -85,7 +87,7 @@ rm -fr %{buildroot}
 
 %{_sbindir}/vcached
 %{_sysconfdir}/cron.d/vcached.cron
-%{_sysconfdir}/logrotate.d/vcached.logorate
+%{_sysconfdir}/logrotate.d/vcached.logrotate
 
 
 %changelog