mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
add setup_agent.sh, the first script running during add host
Make cloud-setup-agent/console-proxy in unattended mode
This commit is contained in:
parent
eb28cbca63
commit
dc005b9b9c
@ -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)
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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,6 +556,8 @@ 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."
|
||||
if self.isAutoMode(): pass
|
||||
else:
|
||||
raw_input()
|
||||
|
||||
# if we reach here, then if something goes wrong we should attempt to revert the runinng state
|
||||
@ -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,16 +919,19 @@ def setup_agent_config(configfile):
|
||||
stderr("Generating GUID for this Agent")
|
||||
confopts['guid'] = uuidgen().stdout.strip()
|
||||
|
||||
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:
|
||||
if zone == None or pod == None:
|
||||
x = list_zonespods(confopts['host'])
|
||||
zoneandpod = prompt_for_hostpods(x)
|
||||
if zoneandpod:
|
||||
@ -929,6 +939,9 @@ def setup_agent_config(configfile):
|
||||
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:
|
||||
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,6 +965,7 @@ def setup_consoleproxy_config(configfile):
|
||||
stderr("Generating GUID for this Console Proxy")
|
||||
confopts['guid'] = uuidgen().stdout.strip()
|
||||
|
||||
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)
|
||||
@ -962,6 +976,7 @@ def setup_consoleproxy_config(configfile):
|
||||
stderr("Querying %s for zones and pods",host)
|
||||
|
||||
try:
|
||||
if zone == None or pod == None:
|
||||
x = list_zonespods(confopts['host'])
|
||||
zoneandpod = prompt_for_hostpods(x)
|
||||
if zoneandpod:
|
||||
@ -969,6 +984,9 @@ def setup_consoleproxy_config(configfile):
|
||||
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:
|
||||
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"])
|
||||
|
||||
|
||||
172
scripts/vm/hypervisor/kvm/setup_agent.sh
Executable file
172
scripts/vm/hypervisor/kvm/setup_agent.sh
Executable file
@ -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
|
||||
@ -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<? extends ServerResource, Map<String, String>> 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<HostVO> hosts, long msId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user