Skip to content

Commit dc005b9

Browse files
committed
add setup_agent.sh, the first script running during add host
Make cloud-setup-agent/console-proxy in unattended mode
1 parent eb28cbc commit dc005b9

File tree

5 files changed

+346
-32
lines changed

5 files changed

+346
-32
lines changed

agent/bindir/cloud-setup-agent.in

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
import sys, os, subprocess, errno, re, traceback
4+
import sys, os, subprocess, errno, re, traceback, getopt
55

66
# ---- This snippet of code adds the sources path and the waf configured PYTHONDIR to the Python path ----
77
# ---- 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")
4141
stderr("")
4242

4343
try:
44-
44+
# parse cmd line
45+
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "no-kvm"])
46+
host=None
47+
zone=None
48+
pod=None
49+
stderr(str(opts))
50+
autoMode=False
51+
do_check_kvm = True
52+
for opt, arg in opts:
53+
if opt == "--host":
54+
if arg != "":
55+
host = arg
56+
elif opt == "--zone":
57+
if arg != "":
58+
zone = arg
59+
elif opt == "--pod":
60+
if arg != "":
61+
pod = arg
62+
elif opt == "--no-kvm":
63+
do_check_kvm = False
64+
elif opt == "-a":
65+
autoMode=True
66+
4567
# pre-flight checks for things that the administrator must fix
46-
do_check_kvm = not ( "--no-kvm" in sys.argv[1:] )
4768
try:
4869
for f,n in cloud_utils.preflight_checks(
4970
do_check_kvm=do_check_kvm
@@ -59,6 +80,8 @@ try:
5980

6081
try:
6182
tasks = cloud_utils.config_tasks(brname)
83+
for t in tasks:
84+
t.setAutoMode(autoMode)
6285
if all( [ t.done() for t in tasks ] ):
6386

6487
stderr("All configuration tasks have been performed already")
@@ -83,7 +106,7 @@ try:
83106
stderr(str(e))
84107
bail(cloud_utils.E_SETUPFAILED,"Cloud Agent setup failed")
85108

86-
setup_agent_config(configfile)
109+
setup_agent_config(configfile, host, zone, pod)
87110
stderr("Enabling and starting the Cloud Agent")
88111
stop_service(servicename)
89112
enable_service(servicename)

console-proxy/bindir/cloud-setup-console-proxy.in

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
import sys, os, subprocess, errno, re
3+
import sys, os, subprocess, errno, re, getopt
44

55
# ---- This snippet of code adds the sources path and the waf configured PYTHONDIR to the Python path ----
66
# ---- 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-
132132
#--------------- procedure starts here ------------
133133

134134
def main():
135-
135+
# parse cmd line
136+
opts, args = getopt.getopt(sys.argv[1:], "", ["host=", "zone=", "pod="])
137+
host=None
138+
zone=None
139+
pod=None
140+
do_check_kvm = True
141+
for opt, arg in opts:
142+
if opt == "--host":
143+
if arg != "":
144+
host = arg
145+
elif opt == "--zone":
146+
if arg != "":
147+
zone = arg
148+
elif opt == "--pod":
149+
if arg != "":
150+
pod = arg
136151
servicename = "@PACKAGE@-console-proxy"
137152

138153
stderr("Welcome to the Cloud Console Proxy setup")
@@ -176,7 +191,7 @@ def main():
176191
print e.stdout+e.stderr
177192
bail(E_FWRECONFIGFAILED,"Firewall could not be enabled")
178193

179-
cloud_utils.setup_consoleproxy_config("@CPSYSCONFDIR@/agent.properties")
194+
cloud_utils.setup_consoleproxy_config("@CPSYSCONFDIR@/agent.properties", host, zone, pod)
180195
stderr("Enabling and starting the Cloud Console Proxy")
181196
cloud_utils.enable_service(servicename)
182197
stderr("Cloud Console Proxy restarted")

python/lib/cloud_utils.py

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ class TaskFailed(Exception): pass
325325

326326
class ConfigTask:
327327
name = "generic config task"
328+
autoMode=False
328329
def __init__(self): pass
329330
def done(self):
330331
"""Returns true if the config task has already been done in the past, false if it hasn't"""
@@ -342,6 +343,10 @@ def run (self):
342343
else:
343344
for msg in it: stderr(msg)
344345
stderr("Completed %s"%self.name)
346+
def setAutoMode(self, autoMode):
347+
self.autoMode = autoMode
348+
def isAutoMode(self):
349+
return self.autoMode
345350

346351

347352
# ============== these are some configuration tasks ==================
@@ -551,7 +556,9 @@ def execute(self):
551556
raise TaskFailed("Network reconfiguration failed")
552557

553558
yield "We are going to restart network services now, to make the network changes take effect. Hit ENTER when you are ready."
554-
raw_input()
559+
if self.isAutoMode(): pass
560+
else:
561+
raw_input()
555562

556563
# if we reach here, then if something goes wrong we should attempt to revert the runinng state
557564
# if not, then no point
@@ -900,7 +907,7 @@ def prompt_for_hostpods(zonespods):
900907

901908
# this configures the agent
902909

903-
def setup_agent_config(configfile):
910+
def setup_agent_config(configfile, host, zone, pod):
904911
stderr("Examining Agent configuration")
905912
fn = configfile
906913
text = file(fn).read(-1)
@@ -912,23 +919,29 @@ def setup_agent_config(configfile):
912919
stderr("Generating GUID for this Agent")
913920
confopts['guid'] = uuidgen().stdout.strip()
914921

915-
try: host = confopts["host"]
916-
except KeyError: host = "localhost"
917-
stderr("Please enter the host name of the management server that this agent will connect to: (just hit ENTER to go with %s)",host)
918-
newhost = raw_input().strip()
919-
if newhost: host = newhost
922+
if host == None:
923+
try: host = confopts["host"]
924+
except KeyError: host = "localhost"
925+
stderr("Please enter the host name of the management server that this agent will connect to: (just hit ENTER to go with %s)",host)
926+
newhost = raw_input().strip()
927+
if newhost: host = newhost
928+
920929
confopts["host"] = host
921930

922931
stderr("Querying %s for zones and pods",host)
923932

924933
try:
925-
x = list_zonespods(confopts['host'])
926-
zoneandpod = prompt_for_hostpods(x)
927-
if zoneandpod:
928-
confopts["zone"],confopts["pod"] = zoneandpod
929-
stderr("You selected zone %s pod %s",confopts["zone"],confopts["pod"])
934+
if zone == None or pod == None:
935+
x = list_zonespods(confopts['host'])
936+
zoneandpod = prompt_for_hostpods(x)
937+
if zoneandpod:
938+
confopts["zone"],confopts["pod"] = zoneandpod
939+
stderr("You selected zone %s pod %s",confopts["zone"],confopts["pod"])
940+
else:
941+
stderr("Skipped -- using the previous zone %s pod %s",confopts["zone"],confopts["pod"])
930942
else:
931-
stderr("Skipped -- using the previous zone %s pod %s",confopts["zone"],confopts["pod"])
943+
confopts["zone"] = zone
944+
confopts["pod"] = pod
932945
except (urllib2.URLError,urllib2.HTTPError),e:
933946
stderr("Query failed: %s. Defaulting to zone %s pod %s",confopts["zone"],confopts["pod"])
934947

@@ -940,7 +953,7 @@ def setup_agent_config(configfile):
940953
text = "\n".join(lines)
941954
file(fn,"w").write(text)
942955

943-
def setup_consoleproxy_config(configfile):
956+
def setup_consoleproxy_config(configfile, host, zone, pod):
944957
stderr("Examining Console Proxy configuration")
945958
fn = configfile
946959
text = file(fn).read(-1)
@@ -952,23 +965,28 @@ def setup_consoleproxy_config(configfile):
952965
stderr("Generating GUID for this Console Proxy")
953966
confopts['guid'] = uuidgen().stdout.strip()
954967

955-
try: host = confopts["host"]
956-
except KeyError: host = "localhost"
957-
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)
958-
newhost = raw_input().strip()
959-
if newhost: host = newhost
968+
if host == None:
969+
try: host = confopts["host"]
970+
except KeyError: host = "localhost"
971+
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)
972+
newhost = raw_input().strip()
973+
if newhost: host = newhost
960974
confopts["host"] = host
961975

962976
stderr("Querying %s for zones and pods",host)
963977

964978
try:
965-
x = list_zonespods(confopts['host'])
966-
zoneandpod = prompt_for_hostpods(x)
967-
if zoneandpod:
968-
confopts["zone"],confopts["pod"] = zoneandpod
969-
stderr("You selected zone %s pod %s",confopts["zone"],confopts["pod"])
979+
if zone == None or pod == None:
980+
x = list_zonespods(confopts['host'])
981+
zoneandpod = prompt_for_hostpods(x)
982+
if zoneandpod:
983+
confopts["zone"],confopts["pod"] = zoneandpod
984+
stderr("You selected zone %s pod %s",confopts["zone"],confopts["pod"])
985+
else:
986+
stderr("Skipped -- using the previous zone %s pod %s",confopts["zone"],confopts["pod"])
970987
else:
971-
stderr("Skipped -- using the previous zone %s pod %s",confopts["zone"],confopts["pod"])
988+
confopts["zone"] = zone
989+
confopts["pod"] = pod
972990
except (urllib2.URLError,urllib2.HTTPError),e:
973991
stderr("Query failed: %s. Defaulting to zone %s pod %s",e,confopts["zone"],confopts["pod"])
974992

0 commit comments

Comments
 (0)