summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hicks <mhicks@localhost.localdomain>2008-07-15 17:50:30 -0400
committerMatt Hicks <mhicks@localhost.localdomain>2008-07-15 17:51:40 -0400
commit375a21de0519abccad612d46a11ea76f6d3e8352 (patch)
tree779d4a0b1fe682e38648dcd1f6f0f7e9b41da6f3
parent13bba6f39ab3ec6056dbd155048f92986bdcc11b (diff)
Adding the genome-func RPM
-rw-r--r--genome-func/Makefile36
-rw-r--r--genome-func/genome-func.spec44
-rw-r--r--genome-func/repo/find_resources.py105
-rwxr-xr-xgenome-func/repo/func-find-resources11
4 files changed, 196 insertions, 0 deletions
diff --git a/genome-func/Makefile b/genome-func/Makefile
new file mode 100644
index 0000000..c76d51f
--- /dev/null
+++ b/genome-func/Makefile
@@ -0,0 +1,36 @@
+NAME := genome-func
+SPECFILE = $(NAME).spec
+VERSION := $(shell rpm -q --qf "%{VERSION}\n" --specfile $(SPECFILE)| head -1)
+RELEASE := $(shell rpm -q --qf "%{RELEASE}\n" --specfile $(SPECFILE)| head -1)
+UPSTREAM_NAME = $(PROJECT)
+
+TAG = $(subst .,_,$(NAME)-$(VERSION)-$(RELEASE))
+
+CVS = cvs
+RPMBUILD = rpmbuild
+INSTALL = /usr/bin/install
+INSTALL_DIR = $(INSTALL) --verbose -d -m 755
+ARCHIVE = $(NAME)-bin.tar.gz
+
+RPM_TOPDIR = /tmp/$(NAME)-$(VERSION)-$(RELEASE)-build
+_RPM_OPTS = --define "_topdir $(RPM_TOPDIR)" \
+ --define "_builddir %{_topdir}" \
+ --define "_sourcedir $(shell pwd)" \
+ --define "_specdir $(shell pwd)" \
+ --define "_rpmdir $(shell pwd)" \
+ --define "_srcrpmdir $(shell pwd)" \
+ --define '_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm'
+RPM_OPTS = $(strip $(_RPM_OPTS))
+
+rpm: clean $(RPM_TOPDIR) $(SPECFILE) $(ARCHIVE)
+ $(RPMBUILD) --clean $(RPM_OPTS) -bs $(SPECFILE)
+ rm -f $(ARCHIVE)
+
+clean:
+ @rm -rfv *~ *.rpm $(RPM_TOPDIR) $(ARCHIVE)
+
+$(ARCHIVE):
+ cd repo; tar cvzf ../$(ARCHIVE) ./*; cd ..
+
+$(RPM_TOPDIR):
+ @$(INSTALL_DIR) $@
diff --git a/genome-func/genome-func.spec b/genome-func/genome-func.spec
new file mode 100644
index 0000000..c020287
--- /dev/null
+++ b/genome-func/genome-func.spec
@@ -0,0 +1,44 @@
+%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
+
+Summary: Genome Func Applications
+Name: genome-func
+Source: genome-func-bin.tar.gz
+Version: 1.0.0
+Release: 1%{?dist}
+BuildArch: noarch
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
+Group: Applications/System
+URL: https://fedorahosting.org/genome
+License: GPLv2
+
+%description
+Genome Func Applications to support the cloudmasterd functions
+
+%prep
+
+%setup -c
+
+%build
+
+%install
+# Cleaning up the build root
+rm -rf $RPM_BUILD_ROOT
+
+# Create the directory structure required to lay down our files
+mkdir -p $RPM_BUILD_ROOT/usr/bin
+mkdir -p $RPM_BUILD_ROOT/%{python_sitelib}/func/overlord
+
+cp -R func-find-resources $RPM_BUILD_ROOT/usr/bin
+cp -R find_resources.py $RPM_BUILD_ROOT/%{python_sitelib}/func/overlord
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root,-)
+/usr/bin/func-find-resources
+%{python_sitelib}/func/overlord/find_resources.py
+%{python_sitelib}/func/overlord/find_resources.pyo
+%{python_sitelib}/func/overlord/find_resources.pyc
+
+%doc
diff --git a/genome-func/repo/find_resources.py b/genome-func/repo/find_resources.py
new file mode 100644
index 0000000..e43bb85
--- /dev/null
+++ b/genome-func/repo/find_resources.py
@@ -0,0 +1,105 @@
+##
+## Func cloud availability application.
+## Given machine requirements, returns the best
+## location in the cloud to run koan.
+## Depends on the storage and virt modules.
+##
+## Copyright 2008, Red Hat, Inc
+## Matt Hicks <mhicks@redhat.com>
+## +AUTHORS
+##
+## This software may be freely redistributed under the terms of the GNU
+## general public license.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+##
+
+import os.path
+import optparse
+import sys
+import random
+import func.overlord.client as func_client
+import func.utils as utils
+
+class FindResources(object):
+
+ def __init__(self):
+ pass
+
+ def run(self,args):
+
+ p = optparse.OptionParser()
+ p.add_option("-v", "--verbose",
+ dest="verbose",
+ action="store_true",
+ help="provide extra output")
+ p.add_option("-s", "--server-spec",
+ dest="server_spec",
+ default="*",
+ help="run against specific servers, default: '*'")
+ p.add_option("-m", "--memory",
+ dest="memory",
+ default="512",
+ help="the memory requirements in megabytes, default: '512'")
+ p.add_option("-a", "--arch",
+ dest="arch",
+ default="i386",
+ help="the architecture requirements, default: 'i386'")
+
+ (options, args) = p.parse_args(args)
+ self.options = options
+
+ # convert the memory and storage to integers for later comparisons
+ memory = int(options.memory)
+ arch = options.arch
+
+ # see what hosts have enough RAM
+ avail_hosts = {}
+ host_freemem = func_client.Client(options.server_spec).virt.freemem()
+ for (host, freemem) in host_freemem.iteritems():
+ if utils.is_error(freemem):
+ print "-- connection refused: %s" % host
+ continue
+
+ # Take an additional 256M off the freemem to keep
+ # Domain-0 stable (shrinking it to 256M can cause
+ # it to crash under load)
+ if (freemem-256) >= memory:
+ avail_hosts[host] = {'memory': freemem}
+
+ # Default the dest_host to nothing
+ dest_host = None
+
+ # see what hosts have the right architecture
+ arch_hosts = {}
+ host_arch = func_client.Client(options.server_spec).command.run('uname -i')
+ for (host, output) in host_arch.iteritems():
+ if utils.is_error(output):
+ print "-- connection refused: %s" % host
+ continue
+
+ host_arch = output[1].rstrip()
+
+ # If the host_arch is 64 bit, allow 32 bit machines on it
+ if host_arch == arch or (host_arch == "x86_64" and arch == "i386"):
+ arch_hosts[host] = host
+
+ if len(avail_hosts) > 0:
+ # Find the host that is the closest memory match
+ # and matching architecture
+ for (host, attrs) in avail_hosts.iteritems():
+ if arch_hosts.has_key(host):
+ if not dest_host:
+ dest_host = [host, attrs['memory']]
+ else:
+ if attrs['memory'] < dest_host[1]:
+ # Use the better match
+ dest_host = [host, attrs['memory']]
+
+ return dest_host
+
+if __name__ == "__main__":
+ inv = FindResources()
+ inv.run(sys.argv)
diff --git a/genome-func/repo/func-find-resources b/genome-func/repo/func-find-resources
new file mode 100755
index 0000000..fc85ff7
--- /dev/null
+++ b/genome-func/repo/func-find-resources
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+
+import sys
+import distutils.sysconfig
+import func.overlord.find_resources as find_resources
+
+find_res = find_resources.FindResources()
+avail_host = find_res.run(sys.argv)
+
+if avail_host:
+ print "%s" % avail_host[0]