Skip to content

Commit 53df26d

Browse files
committed
"Add host" for kvm:
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.
1 parent 59912c0 commit 53df26d

16 files changed

Lines changed: 278 additions & 39 deletions

File tree

agent/bindir/cloud-setup-agent.in

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ backupdir = "@SHAREDSTATEDIR@/@AGENTPATH@/etcbackup"
3737

3838
#=================== the magic happens here ====================
3939

40-
stderr("Welcome to the Cloud Agent setup")
41-
stderr("")
4240

4341
try:
4442
# parse cmd line
45-
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "no-kvm"])
43+
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "no-kvm", "guid="])
4644
host=None
4745
zone=None
4846
pod=None
49-
stderr(str(opts))
47+
guid=None
5048
autoMode=False
5149
do_check_kvm = True
5250
for opt, arg in opts:
@@ -59,11 +57,19 @@ try:
5957
elif opt == "--pod":
6058
if arg != "":
6159
pod = arg
60+
elif opt == "--guid":
61+
if arg != "":
62+
guid = arg
6263
elif opt == "--no-kvm":
6364
do_check_kvm = False
6465
elif opt == "-a":
6566
autoMode=True
6667

68+
if autoMode:
69+
cloud_utils.setLogFile("/var/log/cloud/setupAgent.log")
70+
71+
stderr("Welcome to the Cloud Agent setup")
72+
stderr("")
6773
# pre-flight checks for things that the administrator must fix
6874
try:
6975
for f,n in cloud_utils.preflight_checks(
@@ -106,7 +112,7 @@ try:
106112
stderr(str(e))
107113
bail(cloud_utils.E_SETUPFAILED,"Cloud Agent setup failed")
108114

109-
setup_agent_config(configfile, host, zone, pod)
115+
setup_agent_config(configfile, host, zone, pod, guid)
110116
stderr("Enabling and starting the Cloud Agent")
111117
stop_service(servicename)
112118
enable_service(servicename)

agent/src/com/cloud/agent/resource/DummyResource.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
@Local(value={ServerResource.class})
3434
public class DummyResource implements ServerResource {
35+
private boolean _isRemoteAgent = false;
3536
String _name;
3637
Host.Type _type;
3738
boolean _negative;
@@ -101,4 +102,12 @@ public IAgentControl getAgentControl() {
101102
public void setAgentControl(IAgentControl agentControl) {
102103
_agentControl = agentControl;
103104
}
105+
106+
public boolean IsRemoteAgent() {
107+
return _isRemoteAgent;
108+
}
109+
110+
public void setRemoteAgent(boolean remote) {
111+
_isRemoteAgent = remote;
112+
}
104113
}

client/tomcatconf/components.xml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149

150150
<adapters key="com.cloud.resource.Discoverer">
151151
<adapter name="SecondaryStorage" class="com.cloud.storage.secondary.SecondaryStorageDiscoverer"/>
152-
<adapter name="XenServer" class="com.cloud.hypervisor.xen.discoverer.XcpServerDiscoverer"/>
152+
<adapter name="KVM Agent" class="com.cloud.hypervisor.kvm.discoverer.KvmServerDiscoverer"/>
153153
</adapters>
154154

155155
<manager name="Cluster Manager" class="com.cloud.cluster.DummyClusterManagerImpl">

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ for pythonpath in (
1414
if os.path.isdir(pythonpath): sys.path.insert(0,pythonpath)
1515
# ---- End snippet of code ----
1616
import cloud_utils
17+
from cloud_utils import stderr
1718

1819
E_GENERIC= 1
1920
E_NOKVM = 2
@@ -27,13 +28,6 @@ E_CPRECONFIGFAILED = 9
2728
E_CPFAILEDTOSTART = 10
2829
E_NOFQDN = 11
2930

30-
31-
def stderr(msgfmt,*args):
32-
msgfmt += "\n"
33-
if args: sys.stderr.write(msgfmt%args)
34-
else: sys.stderr.write(msgfmt)
35-
sys.stderr.flush()
36-
3731
def bail(errno=E_GENERIC,message=None,*args):
3832
if message: stderr(message,*args)
3933
stderr("Cloud Console Proxy setup aborted")
@@ -133,10 +127,11 @@ CentOS = os.path.exists("/etc/centos-release") or ( os.path.exists("/etc/redhat-
133127

134128
def main():
135129
# parse cmd line
136-
opts, args = getopt.getopt(sys.argv[1:], "", ["host=", "zone=", "pod="])
130+
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod="])
137131
host=None
138132
zone=None
139133
pod=None
134+
autoMode=False
140135
do_check_kvm = True
141136
for opt, arg in opts:
142137
if opt == "--host":
@@ -148,8 +143,13 @@ def main():
148143
elif opt == "--pod":
149144
if arg != "":
150145
pod = arg
146+
elif opt == "-a":
147+
autoMode=True
151148
servicename = "@PACKAGE@-console-proxy"
152149

150+
if autoMode:
151+
cloud_utils.setLogFile("/var/log/cloud/setupConsoleProxy.log")
152+
153153
stderr("Welcome to the Cloud Console Proxy setup")
154154
stderr("")
155155

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.cloud.hypervisor.kvm.resource;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import javax.naming.ConfigurationException;
7+
8+
import com.cloud.agent.api.Answer;
9+
import com.cloud.agent.api.Command;
10+
import com.cloud.agent.api.PingCommand;
11+
import com.cloud.agent.api.StartupCommand;
12+
import com.cloud.agent.api.StartupRoutingCommand;
13+
import com.cloud.host.Host.Type;
14+
import com.cloud.hypervisor.Hypervisor;
15+
import com.cloud.hypervisor.xen.resource.CitrixResourceBase;
16+
import com.cloud.resource.ServerResource;
17+
import com.cloud.resource.ServerResourceBase;
18+
import com.cloud.vm.State;
19+
20+
public class KvmDummyResourceBase extends ServerResourceBase implements ServerResource {
21+
private String _zoneId;
22+
private String _podId;
23+
private String _guid;
24+
private String _agentIp;
25+
@Override
26+
public Type getType() {
27+
// TODO Auto-generated method stub
28+
return null;
29+
}
30+
31+
@Override
32+
public StartupCommand[] initialize() {
33+
StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.Type.KVM, new HashMap<String, String>(), new HashMap<String, State>());
34+
cmd.setDataCenter(_zoneId);
35+
cmd.setPod(_podId);
36+
cmd.setGuid(_guid);
37+
cmd.setName(_agentIp);
38+
cmd.setPrivateIpAddress(_agentIp);
39+
cmd.setStorageIpAddress(_agentIp);
40+
cmd.setVersion(KvmDummyResourceBase.class.getPackage().getImplementationVersion());
41+
return new StartupCommand[] { cmd };
42+
}
43+
44+
@Override
45+
public PingCommand getCurrentStatus(long id) {
46+
// TODO Auto-generated method stub
47+
return null;
48+
}
49+
50+
@Override
51+
public Answer executeRequest(Command cmd) {
52+
// TODO Auto-generated method stub
53+
return null;
54+
}
55+
56+
@Override
57+
protected String getDefaultScriptsDir() {
58+
// TODO Auto-generated method stub
59+
return null;
60+
}
61+
62+
@Override
63+
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
64+
_zoneId = (String)params.get("zone");
65+
_podId = (String)params.get("pod");
66+
_guid = (String)params.get("guid");
67+
_agentIp = (String)params.get("agentIp");
68+
return true;
69+
}
70+
}

core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.cloud.storage.resource.StoragePoolResource;
2424

2525
public class VmwareResource implements StoragePoolResource, ServerResource {
26-
26+
private boolean _isRemoteAgent = false;
2727
@Override
2828
public DownloadAnswer execute(PrimaryStorageDownloadCommand cmd) {
2929
// TODO Auto-generated method stub
@@ -119,4 +119,12 @@ public boolean stop() {
119119
// TODO Auto-generated method stub
120120
return false;
121121
}
122+
123+
public boolean IsRemoteAgent() {
124+
return _isRemoteAgent;
125+
}
126+
127+
public void setRemoteAgent(boolean remote) {
128+
_isRemoteAgent = remote;
129+
}
122130
}

core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
223223
protected String _guestNetworkName;
224224
protected int _wait;
225225
protected IAgentControl _agentControl;
226+
protected boolean _isRemoteAgent = false;
226227

227228
protected final XenServerHost _host = new XenServerHost();
228229

@@ -6072,6 +6073,13 @@ public void setAgentControl(IAgentControl agentControl) {
60726073
_agentControl = agentControl;
60736074
}
60746075

6076+
public boolean IsRemoteAgent() {
6077+
return _isRemoteAgent;
6078+
}
6079+
6080+
public void setRemoteAgent(boolean remote) {
6081+
_isRemoteAgent = remote;
6082+
}
60756083

60766084

60776085
protected Answer execute(PoolEjectCommand cmd) {

core/src/com/cloud/resource/ServerResource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ public interface ServerResource extends Manager {
7171
public IAgentControl getAgentControl();
7272

7373
public void setAgentControl(IAgentControl agentControl);
74+
75+
public boolean IsRemoteAgent();
76+
77+
public void setRemoteAgent(boolean remote);
7478
}

core/src/com/cloud/resource/ServerResourceBase.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract class ServerResourceBase implements ServerResource {
4848
protected NetworkInterface _storageNic;
4949
protected NetworkInterface _storageNic2;
5050
protected IAgentControl _agentControl;
51+
protected boolean _isRemoteAgent = false;
5152

5253
@Override
5354
public String getName() {
@@ -301,4 +302,12 @@ public boolean start() {
301302
public boolean stop() {
302303
return true;
303304
}
305+
306+
public boolean IsRemoteAgent() {
307+
return _isRemoteAgent;
308+
}
309+
310+
public void setRemoteAgent(boolean remote) {
311+
_isRemoteAgent = remote;
312+
}
304313
}

python/lib/cloud_utils.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
elif os.path.exists("/etc/legal") and "Ubuntu" in file("/etc/legal").read(-1): distro = Ubuntu
4646
else: distro = Unknown
4747

48-
48+
logFileName=None
4949
# ================== LIBRARY UTILITY CODE=============
50-
50+
def setLogFile(logFile):
51+
global logFileName
52+
logFileName=logFile
5153
def read_properties(propfile):
5254
if not hasattr(propfile,"read"): propfile = file(propfile)
5355
properties = propfile.read().splitlines()
@@ -63,9 +65,10 @@ def read_properties(propfile):
6365
def stderr(msgfmt,*args):
6466
"""Print a message to stderr, optionally interpolating the arguments into it"""
6567
msgfmt += "\n"
68+
if logFileName != None:
69+
sys.stderr = open(logFileName, 'a+')
6670
if args: sys.stderr.write(msgfmt%args)
6771
else: sys.stderr.write(msgfmt)
68-
sys.stderr.flush()
6972

7073
def exit(errno=E_GENERIC,message=None,*args):
7174
"""Exit with an error status code, printing a message to stderr if specified"""
@@ -907,17 +910,20 @@ def prompt_for_hostpods(zonespods):
907910

908911
# this configures the agent
909912

910-
def setup_agent_config(configfile, host, zone, pod):
913+
def setup_agent_config(configfile, host, zone, pod, guid):
911914
stderr("Examining Agent configuration")
912915
fn = configfile
913916
text = file(fn).read(-1)
914917
lines = [ s.strip() for s in text.splitlines() ]
915918
confopts = dict([ m.split("=",1) for m in lines if "=" in m and not m.startswith("#") ])
916919
confposes = dict([ (m.split("=",1)[0],n) for n,m in enumerate(lines) if "=" in m and not m.startswith("#") ])
917920

918-
if not "guid" in confopts:
919-
stderr("Generating GUID for this Agent")
920-
confopts['guid'] = uuidgen().stdout.strip()
921+
if guid != None:
922+
confopts['guid'] = guid
923+
else:
924+
if not "guid" in confopts:
925+
stderr("Generating GUID for this Agent")
926+
confopts['guid'] = uuidgen().stdout.strip()
921927

922928
if host == None:
923929
try: host = confopts["host"]

0 commit comments

Comments
 (0)