diff --git a/.gitignore b/.gitignore index 18b6d4a9629..b465d22a73f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ override premium .metadata dist +*~ +*.bak diff --git a/agent/bindir/cloud-setup-agent.in b/agent/bindir/cloud-setup-agent.in index c9aeea6d146..4fabf7a3b22 100755 --- a/agent/bindir/cloud-setup-agent.in +++ b/agent/bindir/cloud-setup-agent.in @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import sys, os, subprocess, errno, re, traceback +import sys, os, subprocess, errno, re, traceback, getopt # ---- This snippet of code adds the sources path and the waf configured PYTHONDIR to the Python path ---- # ---- We do this so cloud_utils can be looked up in the following order: @@ -41,9 +41,30 @@ stderr("Welcome to the Cloud Agent setup") stderr("") try: - +# parse cmd line + opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "no-kvm"]) + host=None + zone=None + pod=None + stderr(str(opts)) + autoMode=False + do_check_kvm = True + for opt, arg in opts: + if opt == "--host": + if arg != "": + host = arg + elif opt == "--zone": + if arg != "": + zone = arg + elif opt == "--pod": + if arg != "": + pod = arg + elif opt == "--no-kvm": + do_check_kvm = False + elif opt == "-a": + autoMode=True + # pre-flight checks for things that the administrator must fix - do_check_kvm = not ( "--no-kvm" in sys.argv[1:] ) try: for f,n in cloud_utils.preflight_checks( do_check_kvm=do_check_kvm @@ -59,6 +80,8 @@ try: try: tasks = cloud_utils.config_tasks(brname) + for t in tasks: + t.setAutoMode(autoMode) if all( [ t.done() for t in tasks ] ): stderr("All configuration tasks have been performed already") @@ -83,7 +106,7 @@ try: stderr(str(e)) bail(cloud_utils.E_SETUPFAILED,"Cloud Agent setup failed") - setup_agent_config(configfile) + setup_agent_config(configfile, host, zone, pod) stderr("Enabling and starting the Cloud Agent") stop_service(servicename) enable_service(servicename) diff --git a/build.xml b/build.xml index 17fa54c3cbc..bf633f6cdf8 100755 --- a/build.xml +++ b/build.xml @@ -35,7 +35,7 @@ - + diff --git a/cloud.spec b/cloud.spec index 7f8ee77a47a..b164ab03b7e 100644 --- a/cloud.spec +++ b/cloud.spec @@ -44,6 +44,7 @@ intelligent cloud implementation. %package utils Summary: Cloud.com utility library Requires: java >= 1.6.0 +Requires: python Group: System Environment/Libraries Obsoletes: vmops-utils < %{version}-%{release} %description utils @@ -447,6 +448,8 @@ fi %defattr(0644,root,root,0755) %{_javadir}/%{name}-utils.jar %{_javadir}/%{name}-api.jar +%attr(755,root,root) %{_bindir}/cloud-sccs +%attr(755,root,root) %{_bindir}/cloud-gitrevs %doc %{_docdir}/%{name}-%{version}/sccs-info %doc %{_docdir}/%{name}-%{version}/version-info %doc %{_docdir}/%{name}-%{version}/configure-info diff --git a/console-proxy/bindir/cloud-setup-console-proxy.in b/console-proxy/bindir/cloud-setup-console-proxy.in index 9079c229ebb..b550407d593 100755 --- a/console-proxy/bindir/cloud-setup-console-proxy.in +++ b/console-proxy/bindir/cloud-setup-console-proxy.in @@ -1,6 +1,6 @@ #!/usr/bin/env python -import sys, os, subprocess, errno, re +import sys, os, subprocess, errno, re, getopt # ---- This snippet of code adds the sources path and the waf configured PYTHONDIR to the Python path ---- # ---- We do this so cloud_utils can be looked up in the following order: @@ -132,7 +132,22 @@ CentOS = os.path.exists("/etc/centos-release") or ( os.path.exists("/etc/redhat- #--------------- procedure starts here ------------ def main(): - + # parse cmd line + opts, args = getopt.getopt(sys.argv[1:], "", ["host=", "zone=", "pod="]) + host=None + zone=None + pod=None + do_check_kvm = True + for opt, arg in opts: + if opt == "--host": + if arg != "": + host = arg + elif opt == "--zone": + if arg != "": + zone = arg + elif opt == "--pod": + if arg != "": + pod = arg servicename = "@PACKAGE@-console-proxy" stderr("Welcome to the Cloud Console Proxy setup") @@ -176,7 +191,7 @@ def main(): print e.stdout+e.stderr bail(E_FWRECONFIGFAILED,"Firewall could not be enabled") - cloud_utils.setup_consoleproxy_config("@CPSYSCONFDIR@/agent.properties") + cloud_utils.setup_consoleproxy_config("@CPSYSCONFDIR@/agent.properties", host, zone, pod) stderr("Enabling and starting the Cloud Console Proxy") cloud_utils.enable_service(servicename) stderr("Cloud Console Proxy restarted") diff --git a/debian/cloud-utils.install b/debian/cloud-utils.install index 14204856b57..b552626efcd 100644 --- a/debian/cloud-utils.install +++ b/debian/cloud-utils.install @@ -3,3 +3,5 @@ /usr/share/doc/cloud/sccs-info /usr/share/doc/cloud/version-info /usr/share/doc/cloud/configure-info +/usr/bin/cloud-sccs +/usr/bin/cloud-gitrevs diff --git a/debian/control b/debian/control index ef4e379e20d..27e53bae905 100644 --- a/debian/control +++ b/debian/control @@ -22,7 +22,7 @@ Provides: vmops-utils Conflicts: vmops-utils Replaces: vmops-utils Architecture: any -Depends: openjdk-6-jre +Depends: openjdk-6-jre, python Description: Cloud.com utility library The Cloud.com utility libraries provide a set of Java classes used in the Cloud.com Cloud Stack. diff --git a/python/lib/cloud_utils.py b/python/lib/cloud_utils.py index a8d6cfbd72f..f638c55f6f8 100644 --- a/python/lib/cloud_utils.py +++ b/python/lib/cloud_utils.py @@ -325,6 +325,7 @@ class TaskFailed(Exception): pass class ConfigTask: name = "generic config task" + autoMode=False def __init__(self): pass def done(self): """Returns true if the config task has already been done in the past, false if it hasn't""" @@ -342,6 +343,10 @@ class ConfigTask: else: for msg in it: stderr(msg) stderr("Completed %s"%self.name) + def setAutoMode(self, autoMode): + self.autoMode = autoMode + def isAutoMode(self): + return self.autoMode # ============== these are some configuration tasks ================== @@ -551,7 +556,9 @@ save"""%(automatic,self.brname,inconfigfile,self.brname,inconfigfile,dev) raise TaskFailed("Network reconfiguration failed") yield "We are going to restart network services now, to make the network changes take effect. Hit ENTER when you are ready." - raw_input() + if self.isAutoMode(): pass + else: + raw_input() # if we reach here, then if something goes wrong we should attempt to revert the runinng state # if not, then no point @@ -900,7 +907,7 @@ def prompt_for_hostpods(zonespods): # this configures the agent -def setup_agent_config(configfile): +def setup_agent_config(configfile, host, zone, pod): stderr("Examining Agent configuration") fn = configfile text = file(fn).read(-1) @@ -912,23 +919,29 @@ def setup_agent_config(configfile): stderr("Generating GUID for this Agent") confopts['guid'] = uuidgen().stdout.strip() - try: host = confopts["host"] - except KeyError: host = "localhost" - stderr("Please enter the host name of the management server that this agent will connect to: (just hit ENTER to go with %s)",host) - newhost = raw_input().strip() - if newhost: host = newhost + if host == None: + try: host = confopts["host"] + except KeyError: host = "localhost" + stderr("Please enter the host name of the management server that this agent will connect to: (just hit ENTER to go with %s)",host) + newhost = raw_input().strip() + if newhost: host = newhost + confopts["host"] = host stderr("Querying %s for zones and pods",host) try: - x = list_zonespods(confopts['host']) - zoneandpod = prompt_for_hostpods(x) - if zoneandpod: - confopts["zone"],confopts["pod"] = zoneandpod - stderr("You selected zone %s pod %s",confopts["zone"],confopts["pod"]) + if zone == None or pod == None: + x = list_zonespods(confopts['host']) + zoneandpod = prompt_for_hostpods(x) + if zoneandpod: + confopts["zone"],confopts["pod"] = zoneandpod + stderr("You selected zone %s pod %s",confopts["zone"],confopts["pod"]) + else: + stderr("Skipped -- using the previous zone %s pod %s",confopts["zone"],confopts["pod"]) else: - stderr("Skipped -- using the previous zone %s pod %s",confopts["zone"],confopts["pod"]) + confopts["zone"] = zone + confopts["pod"] = pod except (urllib2.URLError,urllib2.HTTPError),e: stderr("Query failed: %s. Defaulting to zone %s pod %s",confopts["zone"],confopts["pod"]) @@ -940,7 +953,7 @@ def setup_agent_config(configfile): text = "\n".join(lines) file(fn,"w").write(text) -def setup_consoleproxy_config(configfile): +def setup_consoleproxy_config(configfile, host, zone, pod): stderr("Examining Console Proxy configuration") fn = configfile text = file(fn).read(-1) @@ -952,23 +965,28 @@ def setup_consoleproxy_config(configfile): stderr("Generating GUID for this Console Proxy") confopts['guid'] = uuidgen().stdout.strip() - try: host = confopts["host"] - except KeyError: host = "localhost" - stderr("Please enter the host name of the management server that this console-proxy will connect to: (just hit ENTER to go with %s)",host) - newhost = raw_input().strip() - if newhost: host = newhost + if host == None: + try: host = confopts["host"] + except KeyError: host = "localhost" + stderr("Please enter the host name of the management server that this console-proxy will connect to: (just hit ENTER to go with %s)",host) + newhost = raw_input().strip() + if newhost: host = newhost confopts["host"] = host stderr("Querying %s for zones and pods",host) try: - x = list_zonespods(confopts['host']) - zoneandpod = prompt_for_hostpods(x) - if zoneandpod: - confopts["zone"],confopts["pod"] = zoneandpod - stderr("You selected zone %s pod %s",confopts["zone"],confopts["pod"]) + if zone == None or pod == None: + x = list_zonespods(confopts['host']) + zoneandpod = prompt_for_hostpods(x) + if zoneandpod: + confopts["zone"],confopts["pod"] = zoneandpod + stderr("You selected zone %s pod %s",confopts["zone"],confopts["pod"]) + else: + stderr("Skipped -- using the previous zone %s pod %s",confopts["zone"],confopts["pod"]) else: - stderr("Skipped -- using the previous zone %s pod %s",confopts["zone"],confopts["pod"]) + confopts["zone"] = zone + confopts["pod"] = pod except (urllib2.URLError,urllib2.HTTPError),e: stderr("Query failed: %s. Defaulting to zone %s pod %s",e,confopts["zone"],confopts["pod"]) diff --git a/scripts/vm/hypervisor/kvm/setup_agent.sh b/scripts/vm/hypervisor/kvm/setup_agent.sh new file mode 100755 index 00000000000..5302e8f71f8 --- /dev/null +++ b/scripts/vm/hypervisor/kvm/setup_agent.sh @@ -0,0 +1,172 @@ +#! /bin/bash +# Did cloud-agent installed +set -x +install_cloud_agent() { + local dev=$1 + local retry=10 + which cloud-setup-agent + if [ $? -gt 0 ] + then + # download the repo + which wget + if [ $? -gt 0 ] + then + yum install wget -y + if [ $? -gt 0 ] + then + printf "failed to install wget" + exit 1 + fi + fi + wget -N -P /etc/yum.repos.d/ http://download.cloud.com/foss/fedora/cloud.repo + if [ $? -gt 0 ] + then + printf "Failed to download repo" + exit 1 + fi + if [ "$dev" == "1" ] + then + sed -i 's/\(baseurl\)\(.*\)/\1=http:\/\/yumrepo.lab.vmops.com\/repositories\/fedora\/vmdev\/oss\//' /etc/yum.repos.d/cloud.repo + fi + while [ "$retry" -gt "0" ] + do + yum clean all + yum install cloud-agent -y + if [ $? -gt 0 ] + then + let retry=retry-1 + else + break + fi + done + else + # is there update? + while [ "$retry" -gt "0" ] + do + yum clean all + yum update cloud-agent -y + if [ $? -gt 0 ] + then + let retry=retry-1 + else + break + fi + + done + fi + + if [ $? -gt 0 ] + then + printf "Failed to install agent" + exit 2 + fi +} + +install_cloud_consoleP() { + local dev=$1 + local retry=10 + which cloud-setup-console-proxy + if [ $? -gt 0 ] + then + # download the repo + which wget + if [ $? -gt 0 ] + then + yum install wget -y + if [ $? -gt 0 ] + then + printf "failed to install wget" + exit 1 + fi + fi + wget -N -P=/etc/yum.repos.d/ http://download.cloud.com/foss/fedora/cloud.repo + if [ $? -gt 0 ] + then + printf "Failed to download repo" + exit 1 + fi + if [ "$dev" == "1" ] + then + sed -i 's/\(baseurl\)\(.*\)/\1=http:\/\/yumrepo.lab.vmops.com\/repositories\/fedora\/vmdev\/oss\//' /etc/yum.repos.d/cloud.repo + fi + while [ "$retry" -gt "0" ] + do + yum clean all + yum install cloud-console-proxy -y + if [ $? -gt 0 ] + then + let retry=retry-1 + else + break + fi + done + else + # is there update? + while [ "$retry" -gt "0" ] + do + yum clean all + yum update cloud-console-proxy -y + if [ $? -gt 0 ] + then + let retry=retry-1 + else + break + fi + + done + fi + + if [ $? -gt 0 ] + then + printf "Failed to install console" + exit 2 + fi +} +cloud_agent_setup() { + local host=$1 + local zone=$2 + local pod=$3 + # disable selinux + selenabled=`cat /selinux/enforce` + if [ "$selenabled" == "1" ] + then + sed -i 's/\(SELINUX\)\(.*\)/\1=permissive/' /etc/selinux/config + setenforce 0 + fi + cloud-setup-agent --host=$host --zone=$zone --pod=$pod -a +} + +cloud_consoleP_setup() { + local host=$1 + local zone=$2 + local pod=$3 + cloud-setup-console-proxy --host=$host --zone=$zone --pod=$pod +} + +host= +zone= +pod= +dflag= +while getopts 'h:z:p:d' OPTION +do + case $OPTION in + h) + host="$OPTARG" + ;; + z) + zone="$OPTARG" + ;; + p) + pod="$OPTARG" + ;; + d) + dflag=1 + ;; + *) ;; + esac +done + +install_cloud_agent $dflag +install_cloud_consoleP $dflag +cloud_agent_setup $host $zone $pod +cloud_consoleP_setup $host $zone $pod diff --git a/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java b/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java new file mode 100644 index 00000000000..b16b57a85b4 --- /dev/null +++ b/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java @@ -0,0 +1,86 @@ +package com.cloud.hypervisor.kvm.discoverer; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +import com.cloud.agent.Listener; +import com.cloud.agent.api.AgentControlAnswer; +import com.cloud.agent.api.AgentControlCommand; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.StartupCommand; +import com.cloud.exception.DiscoveryException; +import com.cloud.host.HostVO; +import com.cloud.host.Status; +import com.cloud.resource.Discoverer; +import com.cloud.resource.DiscovererBase; +import com.cloud.resource.ServerResource; + +public class KvmServerDiscoverer extends DiscovererBase implements Discoverer, + Listener { + + @Override + public boolean processAnswer(long agentId, long seq, Answer[] answers) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean processCommand(long agentId, long seq, Command[] commands) { + // TODO Auto-generated method stub + return false; + } + + @Override + public AgentControlAnswer processControlCommand(long agentId, + AgentControlCommand cmd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean processConnect(HostVO host, StartupCommand cmd) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean processDisconnect(long agentId, Status state) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isRecurring() { + // TODO Auto-generated method stub + return false; + } + + @Override + public int getTimeout() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public boolean processTimeout(long agentId, long seq) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Map> find(long dcId, + Long podId, Long clusterId, URI uri, String username, + String password) throws DiscoveryException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void postDiscovery(List hosts, long msId) { + // TODO Auto-generated method stub + + } + +} diff --git a/utils/bindir/cloud-gitrevs.in b/utils/bindir/cloud-gitrevs.in new file mode 100644 index 00000000000..ffa17be9bf8 --- /dev/null +++ b/utils/bindir/cloud-gitrevs.in @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +import os, sys + +path = os.path.join("@DOCDIR@","sccs-info") +try: text = file(path).read(-1) +except IOError,e: + if e.errno == 2: + sys.stderr.write("error: SCCS info file %r cannot be found\n"%path) + sys.exit(1) + else: raise +lines = [ s.strip() for s in text.split("\n") if s.startswith('Git Revision: ') ] +print " ".join( [ s[14:] for s in lines ] ) \ No newline at end of file diff --git a/utils/bindir/cloud-sccs.in b/utils/bindir/cloud-sccs.in new file mode 100755 index 00000000000..cfd40d5fb58 --- /dev/null +++ b/utils/bindir/cloud-sccs.in @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import os, sys + +path = os.path.join("@DOCDIR@","sccs-info") +try: text = file(path).read(-1) +except IOError,e: + if e.errno == 2: + sys.stderr.write("error: SCCS info file %r cannot be found\n"%path) + sys.exit(1) + else: raise +print text \ No newline at end of file diff --git a/wscript b/wscript index 2d42fed035b..a84948cf57e 100644 --- a/wscript +++ b/wscript @@ -144,8 +144,9 @@ def svninfo(*args): else: url = "SVN " + url[0].strip() return rev + "\n" + url -def gitinfo(*args): - try: p = _Popen(['git','remote','show','-n','origin']+list(args),stdin=PIPE,stdout=PIPE,stderr=PIPE) +def gitinfo(dir=None): + if dir and not _isdir(dir): return '' + try: p = _Popen(['git','remote','show','-n','origin'],stdin=PIPE,stdout=PIPE,stderr=PIPE,cwd=dir) except OSError,e: if e.errno == 2: return '' # svn command is not installed raise @@ -158,7 +159,7 @@ def gitinfo(*args): except IndexError: url = [ s[5:] for s in stdout if s.startswith("URL") ][0] assert url - p = _Popen(['git','log','-1']+list(args),stdin=PIPE,stdout=PIPE,stderr=PIPE) + p = _Popen(['git','log','-1'],stdin=PIPE,stdout=PIPE,stderr=PIPE,cwd=dir) stdout,stderr = p.communicate('') retcode = p.wait() if retcode: return @@ -169,6 +170,15 @@ def gitinfo(*args): return "Git Revision: %s"%commitid + "\n" + "Git URL: %s"%url +def allgitinfo(): + t = gitinfo() + if not t: return t + + u = gitinfo(_join(pardir,"cloudstack-proprietary")) + if not u: return t + + return t + "\n\ncloustack-proprietary:\n" + u + def _getbuildnumber(): # FIXME implement for git n = Options.options.BUILDNUMBER if n: @@ -230,6 +240,7 @@ def discover_ant_targets_and_properties(files): propsinpropfiles = [ l.strip().split("=",1) for f in files if f.endswith(".properties") for l in file(f).readlines() if "=" in l and not l.startswith("#") ] props = dict( propsinxml + propsinpropfiles ) props["base.dir"] = '.' + props["p.base.dir"] = '.' result = [] for name,target in targets.items(): @@ -528,7 +539,7 @@ def dist_hook(): if Options.options.OSS: [ shutil.rmtree(f) for f in "cloudstack-proprietary".split() if _exists(f) ] - stdout = svninfo("..") or gitinfo() + stdout = svninfo("..") or allgitinfo() if stdout: f = file("sccs-info","w") f.write(stdout)