use of com.xensource.xenapi.Host in project cloudstack by apache.
the class CitrixResourceBase method initializeLocalSR.
protected StartupStorageCommand initializeLocalSR(final Connection conn) {
final SR lvmsr = getLocalLVMSR(conn);
if (lvmsr != null) {
try {
_host.setLocalSRuuid(lvmsr.getUuid(conn));
final String lvmuuid = lvmsr.getUuid(conn);
final long cap = lvmsr.getPhysicalSize(conn);
if (cap > 0) {
final long avail = cap - lvmsr.getPhysicalUtilisation(conn);
lvmsr.setNameLabel(conn, lvmuuid);
final String name = "Cloud Stack Local LVM Storage Pool for " + _host.getUuid();
lvmsr.setNameDescription(conn, name);
final Host host = Host.getByUuid(conn, _host.getUuid());
final String address = host.getAddress(conn);
final StoragePoolInfo pInfo = new StoragePoolInfo(lvmuuid, address, SRType.LVM.toString(), SRType.LVM.toString(), StoragePoolType.LVM, cap, avail);
final StartupStorageCommand cmd = new StartupStorageCommand();
cmd.setPoolInfo(pInfo);
cmd.setGuid(_host.getUuid());
cmd.setDataCenter(Long.toString(_dcId));
cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
return cmd;
}
} catch (final XenAPIException e) {
final String msg = "build local LVM info err in host:" + _host.getUuid() + e.toString();
s_logger.warn(msg);
} catch (final XmlRpcException e) {
final String msg = "build local LVM info err in host:" + _host.getUuid() + e.getMessage();
s_logger.warn(msg);
}
}
final SR extsr = getLocalEXTSR(conn);
if (extsr != null) {
try {
final String extuuid = extsr.getUuid(conn);
_host.setLocalSRuuid(extuuid);
final long cap = extsr.getPhysicalSize(conn);
if (cap > 0) {
final long avail = cap - extsr.getPhysicalUtilisation(conn);
extsr.setNameLabel(conn, extuuid);
final String name = "Cloud Stack Local EXT Storage Pool for " + _host.getUuid();
extsr.setNameDescription(conn, name);
final Host host = Host.getByUuid(conn, _host.getUuid());
final String address = host.getAddress(conn);
final StoragePoolInfo pInfo = new StoragePoolInfo(extuuid, address, SRType.EXT.toString(), SRType.EXT.toString(), StoragePoolType.EXT, cap, avail);
final StartupStorageCommand cmd = new StartupStorageCommand();
cmd.setPoolInfo(pInfo);
cmd.setGuid(_host.getUuid());
cmd.setDataCenter(Long.toString(_dcId));
cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
return cmd;
}
} catch (final XenAPIException e) {
final String msg = "build local EXT info err in host:" + _host.getUuid() + e.toString();
s_logger.warn(msg);
} catch (final XmlRpcException e) {
final String msg = "build local EXT info err in host:" + _host.getUuid() + e.getMessage();
s_logger.warn(msg);
}
}
return null;
}
use of com.xensource.xenapi.Host in project cloudstack by apache.
the class CitrixResourceBase method createNfsSRbyURI.
protected SR createNfsSRbyURI(final Connection conn, final URI uri, final boolean shared) {
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating a " + (shared ? "shared SR for " : "not shared SR for ") + uri);
}
final Map<String, String> deviceConfig = new HashMap<String, String>();
String path = uri.getPath();
path = path.replace("//", "/");
deviceConfig.put("server", uri.getHost());
deviceConfig.put("serverpath", path);
final String name = UUID.nameUUIDFromBytes(new String(uri.getHost() + path).getBytes()).toString();
if (!shared) {
final Set<SR> srs = SR.getByNameLabel(conn, name);
for (final SR sr : srs) {
final SR.Record record = sr.getRecord(conn);
if (SRType.NFS.equals(record.type) && record.contentType.equals("user") && !record.shared) {
removeSRSync(conn, sr);
}
}
}
final Host host = Host.getByUuid(conn, _host.getUuid());
final Map<String, String> smConfig = new HashMap<String, String>();
smConfig.put("nosubdir", "true");
final SR sr = SR.create(conn, host, deviceConfig, new Long(0), name, uri.getHost() + uri.getPath(), SRType.NFS.toString(), "user", shared, smConfig);
if (!checkSR(conn, sr)) {
throw new Exception("no attached PBD");
}
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(sr, "Created a SR; UUID is " + sr.getUuid(conn) + " device config is " + deviceConfig));
}
sr.scan(conn);
return sr;
} catch (final XenAPIException e) {
final String msg = "Can not create second storage SR mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.toString();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
} catch (final Exception e) {
final String msg = "Can not create second storage SR mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.getMessage();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
}
}
use of com.xensource.xenapi.Host in project cloudstack by apache.
the class XenServer56Resource method disableVlanNetwork.
@Override
public void disableVlanNetwork(final Connection conn, final Network network) {
try {
final Network.Record networkr = network.getRecord(conn);
if (!networkr.nameLabel.startsWith("VLAN")) {
return;
}
final String bridge = networkr.bridge.trim();
for (final PIF pif : networkr.PIFs) {
final PIF.Record pifr = pif.getRecord(conn);
if (!pifr.host.getUuid(conn).equalsIgnoreCase(_host.getUuid())) {
continue;
}
final VLAN vlan = pifr.VLANMasterOf;
if (vlan != null) {
final String vlannum = pifr.VLAN.toString();
final String device = pifr.device.trim();
if (vlannum.equals("-1")) {
return;
}
try {
vlan.destroy(conn);
final Host host = Host.getByUuid(conn, _host.getUuid());
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_tx");
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_rx");
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx");
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx");
} catch (final XenAPIException e) {
s_logger.trace("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.getUuid() + " due to " + e.toString());
}
}
return;
}
} catch (final XenAPIException e) {
final String msg = "Unable to disable VLAN network due to " + e.toString();
s_logger.warn(msg, e);
} catch (final Exception e) {
final String msg = "Unable to disable VLAN network due to " + e.getMessage();
s_logger.warn(msg, e);
}
}
use of com.xensource.xenapi.Host in project cloudstack by apache.
the class XenServerStorageProcessor method getNfsSR.
protected SR getNfsSR(final Connection conn, final StorageFilerTO pool) {
final Map<String, String> deviceConfig = new HashMap<String, String>();
try {
final String server = pool.getHost();
String serverpath = pool.getPath();
serverpath = serverpath.replace("//", "/");
final Set<SR> srs = SR.getAll(conn);
for (final SR sr : srs) {
if (!SRType.NFS.equals(sr.getType(conn))) {
continue;
}
final Set<PBD> pbds = sr.getPBDs(conn);
if (pbds.isEmpty()) {
continue;
}
final PBD pbd = pbds.iterator().next();
final Map<String, String> dc = pbd.getDeviceConfig(conn);
if (dc == null) {
continue;
}
if (dc.get("server") == null) {
continue;
}
if (dc.get("serverpath") == null) {
continue;
}
if (server.equals(dc.get("server")) && serverpath.equals(dc.get("serverpath"))) {
throw new CloudRuntimeException("There is a SR using the same configuration server:" + dc.get("server") + ", serverpath:" + dc.get("serverpath") + " for pool " + pool.getUuid() + "on host:" + hypervisorResource.getHost().getUuid());
}
}
deviceConfig.put("server", server);
deviceConfig.put("serverpath", serverpath);
final Host host = Host.getByUuid(conn, hypervisorResource.getHost().getUuid());
final Map<String, String> smConfig = new HashMap<String, String>();
smConfig.put("nosubdir", "true");
final SR sr = SR.create(conn, host, deviceConfig, new Long(0), pool.getUuid(), Long.toString(pool.getId()), SRType.NFS.toString(), "user", true, smConfig);
sr.scan(conn);
return sr;
} catch (final XenAPIException e) {
throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
} catch (final XmlRpcException e) {
throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
}
}
use of com.xensource.xenapi.Host in project cloudstack by apache.
the class CitrixResourceBase method getLocalLVMSR.
protected SR getLocalLVMSR(final Connection conn) {
try {
final Map<SR, SR.Record> map = SR.getAllRecords(conn);
if (map != null && !map.isEmpty()) {
for (final Map.Entry<SR, SR.Record> entry : map.entrySet()) {
final SR.Record srRec = entry.getValue();
if (SRType.LVM.equals(srRec.type)) {
final Set<PBD> pbds = srRec.PBDs;
if (pbds == null) {
continue;
}
for (final PBD pbd : pbds) {
final Host host = pbd.getHost(conn);
if (!isRefNull(host) && host.getUuid(conn).equals(_host.getUuid())) {
if (!pbd.getCurrentlyAttached(conn)) {
pbd.plug(conn);
}
final SR sr = entry.getKey();
sr.scan(conn);
return sr;
}
}
}
}
}
} catch (final XenAPIException e) {
final String msg = "Unable to get local LVMSR in host:" + _host.getUuid() + e.toString();
s_logger.warn(msg);
} catch (final XmlRpcException e) {
final String msg = "Unable to get local LVMSR in host:" + _host.getUuid() + e.getCause();
s_logger.warn(msg);
}
return null;
}
Aggregations