localstorage uuid is generated by uuidgen, other than from hostip+localstoragepath

This commit is contained in:
Edison Su 2011-05-26 11:52:09 -04:00
parent 6256c88be6
commit 82ab4fcde4
4 changed files with 31 additions and 9 deletions

View File

@ -4,7 +4,7 @@ import logging
import sys
import socket
from cloudutils.cloudException import CloudRuntimeException, CloudInternalException
from cloudutils.utilities import initLoging
from cloudutils.utilities import initLoging, bash
from cloudutils.configFileOps import configFileOps
from cloudutils.globalEnv import globalEnv
from cloudutils.networkConfig import networkConfig
@ -13,7 +13,7 @@ from cloudutils.syscfg import sysConfigFactory
from optparse import OptionParser
def getUserInputs():
print "Welcome to myCloud Setup:"
print "Welcome to Cloud Agent Setup:"
cfo = configFileOps("/etc/cloud/agent/agent.properties")
oldMgt = cfo.getEntry("host")
@ -28,11 +28,22 @@ def getUserInputs():
exit(1)
oldToken = cfo.getEntry("zone")
zoneToken = raw_input("Please input the Zone Token:[%s]"%oldToken)
zoneToken = raw_input("Please input the Zone Id:[%s]"%oldToken)
if zoneToken == "":
zoneToken = oldToken
oldPod = cfo.getEntry("pod")
podId = raw_input("Please input the Pod Id:[%s]"%oldPod)
if podId == "":
podId = oldToken
oldCluster = cfo.getEntry("cluster")
clusterId = raw_input("Please input the Cluster Id:[%s]"%oldCluster)
if clusterId == "":
clusterId = oldCluster
try:
defaultNic = networkConfig.getDefaultNetwork()
except:
@ -48,7 +59,7 @@ def getUserInputs():
elif network == "":
network = defNic
return [mgtSvr, zoneToken, network]
return [mgtSvr, zoneToken, network, podId, clusterId]
if __name__ == '__main__':
initLoging("/var/log/cloud/setupAgent.log")
@ -73,6 +84,8 @@ if __name__ == '__main__':
glbEnv.mgtSvr = userInputs[0]
glbEnv.zone = userInputs[1]
glbEnv.defaultNic = userInputs[2]
glbEnv.pod = userInputs[3]
glbEnv.cluster = userInputs[4]
#generate UUID
glbEnv.uuid = configFileOps("/etc/cloud/agent/agent.properties").getEntry("guid")
if glbEnv.uuid == "":

View File

@ -294,6 +294,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
protected String _localGateway;
private boolean _can_bridge_firewall;
protected String _localStoragePath;
protected String _localStorageUUID;
private Pair<String, String> _pifs;
private final Map<String, vmStats> _vmStats = new ConcurrentHashMap<String, vmStats>();
@ -562,6 +563,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
_localStoragePath = "/var/lib/libvirt/images/";
}
_localStorageUUID = (String)params.get("local.storage.uuid");
if (_localStorageUUID == null) {
throw new ConfigurationException("Can't find local.storage.uuid");
}
value = (String)params.get("scripts.timeout");
_timeout = NumbersUtil.parseInt(value, 30*60) * 1000;
@ -2509,7 +2515,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
StartupStorageCommand sscmd = null;
try {
Connect conn = LibvirtConnection.getConnection();
com.cloud.agent.api.StoragePoolInfo pi = _storageResource.initializeLocalStorage(conn, _localStoragePath, cmd.getPrivateIpAddress());
com.cloud.agent.api.StoragePoolInfo pi = _storageResource.initializeLocalStorage(conn, _localStoragePath, cmd.getPrivateIpAddress(), _localStorageUUID);
sscmd = new StartupStorageCommand();
sscmd.setPoolInfo(pi);
sscmd.setGuid(pi.getUuid());

View File

@ -416,7 +416,8 @@ public class LibvirtStorageResource {
}
}
}
public com.cloud.agent.api.StoragePoolInfo initializeLocalStorage(Connect conn, String localStoragePath, String hostIp) {
public com.cloud.agent.api.StoragePoolInfo initializeLocalStorage(Connect conn, String localStoragePath, String hostIp, String uuid) {
if (!(_storageLayer.exists(localStoragePath) && _storageLayer.isDirectory(localStoragePath))) {
return null;
}
@ -425,8 +426,6 @@ public class LibvirtStorageResource {
if (!(path.canWrite() && path.canRead() && path.canExecute())) {
return null;
}
String lh = hostIp + localStoragePath;
String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
StoragePool pool = null;
try {
pool = conn.storagePoolLookupByUUIDString(uuid);

View File

@ -254,7 +254,7 @@ class networkConfigRedhat(serviceCfgBase, networkConfigBase):
self.syscfg.svo.disableService("NetworkManager")
if not bash("service network restart").success():
if not bash("service network restart").isSuccess():
raise CloudInternalException("Can't restart network")
self.syscfg.env.nics.append(self.brName)
@ -537,6 +537,8 @@ class cloudAgentConfig(serviceCfgBase):
cfo.addEntry("private.network.device", self.syscfg.env.nics[0])
cfo.addEntry("public.network.device", self.syscfg.env.nics[1])
cfo.addEntry("guest.network.device", self.syscfg.env.nics[2])
if cfo.getEntry("local.storage.uuid") == "":
cfo.addEntry("local.storage.uuid", str(bash("uuidgen").getStdout()))
cfo.addEntry("guid", str(self.syscfg.env.uuid))
cfo.addEntry("mount.path", "/mnt")
cfo.addEntry("resource", "com.cloud.storage.resource.LocalSecondaryStorageResource|com.cloud.agent.resource.computing.CloudZonesComputingResource")
@ -560,6 +562,8 @@ class cloudAgentConfig(serviceCfgBase):
cfo.addEntry("public.network.device", self.syscfg.env.nics[1])
cfo.addEntry("guest.network.device", self.syscfg.env.nics[2])
cfo.addEntry("guid", str(self.syscfg.env.uuid))
if cfo.getEntry("local.storage.uuid") == "":
cfo.addEntry("local.storage.uuid", str(bash("uuidgen").getStdout()))
cfo.addEntry("resource", "com.cloud.agent.resource.computing.LibvirtComputingResource")
cfo.save()