mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 18:43:26 +01:00
The sequence: 1. add host in UI 2. scp setup_agent.sh to agent host, and execute it. This script receives hostip,zoneid, podid and guid, then runs "cloud-setup-agent" and "cloud-setup-console-proxy". Here, we assume that network/hostname and cloud-agent are already configed and installed. 3. Write a dummy kvm resource into the database, then wait for agent connects to server, by polling the database for every 1 minutes. If it finds the agent is in UP state in database, then return, or wait for at least 10 minutes.
139 lines
4.4 KiB
Python
Executable File
139 lines
4.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
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:
|
|
# ---- 1) Sources directory
|
|
# ---- 2) waf configured PYTHONDIR
|
|
# ---- 3) System Python path
|
|
for pythonpath in (
|
|
"@PYTHONDIR@",
|
|
os.path.join(os.path.dirname(__file__),os.path.pardir,os.path.pardir,"python","lib"),
|
|
):
|
|
if os.path.isdir(pythonpath): sys.path.insert(0,pythonpath)
|
|
# ---- End snippet of code ----
|
|
import cloud_utils
|
|
from cloud_utils import stderr,CheckFailed,TaskFailed,backup_etc,restore_etc
|
|
from cloud_utils import setup_agent_config,stop_service,enable_service
|
|
from cloud_utils import exit as bail
|
|
from cloud_utils import all, any
|
|
|
|
|
|
#--------------- procedure starts here ------------
|
|
|
|
# FÏXME for backup and restore: collect service state for all services so we can restore the system's runtime state back to what it was before
|
|
# possible exit states:
|
|
# a. system configuration needs administrator attention
|
|
# b. automatic reconfiguration failed
|
|
# c. process interrupted
|
|
# d. everything was configured properly (exit status 0)
|
|
|
|
brname = "@PACKAGE@br0"
|
|
servicename = "@PACKAGE@-agent"
|
|
configfile = "@AGENTSYSCONFDIR@/agent.properties"
|
|
backupdir = "@SHAREDSTATEDIR@/@AGENTPATH@/etcbackup"
|
|
|
|
#=================== the magic happens here ====================
|
|
|
|
|
|
try:
|
|
# parse cmd line
|
|
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "no-kvm", "guid="])
|
|
host=None
|
|
zone=None
|
|
pod=None
|
|
guid=None
|
|
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 == "--guid":
|
|
if arg != "":
|
|
guid = arg
|
|
elif opt == "--no-kvm":
|
|
do_check_kvm = False
|
|
elif opt == "-a":
|
|
autoMode=True
|
|
|
|
if autoMode:
|
|
cloud_utils.setLogFile("/var/log/cloud/setupAgent.log")
|
|
|
|
stderr("Welcome to the Cloud Agent setup")
|
|
stderr("")
|
|
# pre-flight checks for things that the administrator must fix
|
|
try:
|
|
for f,n in cloud_utils.preflight_checks(
|
|
do_check_kvm=do_check_kvm
|
|
):
|
|
stderr(n)
|
|
f()
|
|
except CheckFailed,e:
|
|
stderr(str(e))
|
|
bail(cloud_utils.E_NEEDSMANUALINTERVENTION,
|
|
"Cloud Agent setup cannot continue until these issues have been addressed")
|
|
|
|
# system configuration tasks that our Cloud Agent setup performs
|
|
|
|
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")
|
|
|
|
else:
|
|
|
|
backup_etc(backupdir)
|
|
try:
|
|
# run all tasks that have not been done
|
|
for t in [ n for n in tasks if not n.done() ]:
|
|
t.run()
|
|
except:
|
|
# oops, something wrong, restore system to earlier state and re-raise
|
|
stderr("A fatal issue has been detected -- restoring system configuration.\nPlease be patient; *do not* interrupt this process.")
|
|
restore_etc(backupdir)
|
|
for t in [ n for n in tasks if hasattr(n,"restore_state") ]:
|
|
t.restore_state()
|
|
raise
|
|
|
|
except (TaskFailed,CheckFailed),e:
|
|
# some configuration task or post-flight check failed, we exit right away
|
|
stderr(str(e))
|
|
bail(cloud_utils.E_SETUPFAILED,"Cloud Agent setup failed")
|
|
|
|
setup_agent_config(configfile, host, zone, pod, guid)
|
|
stderr("Enabling and starting the Cloud Agent")
|
|
stop_service(servicename)
|
|
enable_service(servicename)
|
|
stderr("Cloud Agent restarted")
|
|
|
|
except KeyboardInterrupt,e:
|
|
# user interrupted, we exit right away
|
|
bail(cloud_utils.E_INTERRUPTED,"Cloud Agent setup interrupted")
|
|
except SystemExit,e:
|
|
# process above handled a failure then called bail(), which raises a SystemExit on CentOS
|
|
sys.exit(e.code)
|
|
except Exception,e:
|
|
# at ths point, any exception has been dealt with cleanly by restoring system config from a backup
|
|
# we just inform the user that there was a problem
|
|
# and bail prematurely
|
|
stderr("Cloud Agent setup has experienced an unrecoverable error. Please report the following technical details to Cloud.com.")
|
|
traceback.print_exc()
|
|
bail(cloud_utils.E_UNHANDLEDEXCEPTION,"Cloud Agent setup ended prematurely")
|
|
|
|
stderr("")
|
|
stderr("Cloud Agent setup completed successfully")
|
|
|
|
# ========================= end program ========================
|