use of com.xensource.xenapi.PIF in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method fillHostInfo.
protected void fillHostInfo(final Connection conn, final StartupRoutingCommand cmd) {
final StringBuilder caps = new StringBuilder();
try {
final Host host = Host.getByUuid(conn, _host.getUuid());
final Host.Record hr = host.getRecord(conn);
Map<String, String> details = cmd.getHostDetails();
if (details == null) {
details = new HashMap<>();
}
String productBrand = hr.softwareVersion.get("product_brand");
if (productBrand == null) {
productBrand = hr.softwareVersion.get("platform_name");
}
details.put("product_brand", productBrand);
details.put("product_version", _host.getProductVersion());
if (hr.softwareVersion.get("product_version_text_short") != null) {
details.put("product_version_text_short", hr.softwareVersion.get("product_version_text_short"));
cmd.setHypervisorVersion(hr.softwareVersion.get("product_version_text_short"));
cmd.setHypervisorVersion(_host.getProductVersion());
}
if (_privateNetworkName != null) {
details.put("private.network.device", _privateNetworkName);
}
cmd.setHostDetails(details);
cmd.setName(hr.nameLabel);
cmd.setGuid(_host.getUuid());
cmd.setPool(_host.getPool());
cmd.setDataCenter(Long.toString(_dcId));
for (final String cap : hr.capabilities) {
if (cap.length() > 0) {
caps.append(cap).append(" , ");
}
}
if (caps.length() > 0) {
caps.delete(caps.length() - 3, caps.length());
}
cmd.setCaps(caps.toString());
cmd.setCpuSockets(_host.getCpuSockets());
cmd.setCpus(_host.getCpus());
final HostMetrics hm = host.getMetrics(conn);
long ram = 0;
long dom0Ram = 0;
ram = hm.getMemoryTotal(conn);
final Set<VM> vms = host.getResidentVMs(conn);
for (final VM vm : vms) {
if (vm.getIsControlDomain(conn)) {
dom0Ram = vm.getMemoryStaticMax(conn);
break;
}
}
ram = (long) ((ram - dom0Ram - _xsMemoryUsed) * _xsVirtualizationFactor);
cmd.setMemory(ram);
cmd.setDom0MinMemory(dom0Ram);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Total Ram: " + ram + " dom0 Ram: " + dom0Ram);
}
PIF pif = PIF.getByUuid(conn, _host.getPrivatePif());
PIF.Record pifr = pif.getRecord(conn);
if (pifr.IP != null && pifr.IP.length() > 0) {
cmd.setPrivateIpAddress(pifr.IP);
cmd.setPrivateMacAddress(pifr.MAC);
cmd.setPrivateNetmask(pifr.netmask);
} else {
cmd.setPrivateIpAddress(_host.getIp());
cmd.setPrivateMacAddress(pifr.MAC);
cmd.setPrivateNetmask("255.255.255.0");
}
pif = PIF.getByUuid(conn, _host.getPublicPif());
pifr = pif.getRecord(conn);
if (pifr.IP != null && pifr.IP.length() > 0) {
cmd.setPublicIpAddress(pifr.IP);
cmd.setPublicMacAddress(pifr.MAC);
cmd.setPublicNetmask(pifr.netmask);
}
if (_host.getStoragePif1() != null) {
pif = PIF.getByUuid(conn, _host.getStoragePif1());
pifr = pif.getRecord(conn);
if (pifr.IP != null && pifr.IP.length() > 0) {
cmd.setStorageIpAddress(pifr.IP);
cmd.setStorageMacAddress(pifr.MAC);
cmd.setStorageNetmask(pifr.netmask);
}
}
if (_host.getStoragePif2() != null) {
pif = PIF.getByUuid(conn, _host.getStoragePif2());
pifr = pif.getRecord(conn);
if (pifr.IP != null && pifr.IP.length() > 0) {
cmd.setStorageIpAddressDeux(pifr.IP);
cmd.setStorageMacAddressDeux(pifr.MAC);
cmd.setStorageNetmaskDeux(pifr.netmask);
}
}
final Map<String, String> configs = hr.otherConfig;
cmd.setIqn(configs.get("iscsi_iqn"));
cmd.setPod(_pod);
cmd.setVersion(CitrixResourceBase.class.getPackage().getImplementationVersion());
} catch (final XmlRpcException e) {
throw new CloudRuntimeException("XML RPC Exception" + e.getMessage(), e);
} catch (final XenAPIException e) {
throw new CloudRuntimeException("XenAPIException" + e.toString(), e);
}
}
use of com.xensource.xenapi.PIF in project cosmic by MissionCriticalCloud.
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.PIF in project cosmic by MissionCriticalCloud.
the class CitrixSetupCommandWrapper method execute.
@Override
public Answer execute(final SetupCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
try {
final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
if (poolRecs.size() != 1) {
throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + citrixResourceBase.getHost().getUuid());
}
final Host master = poolRecs.values().iterator().next().master;
citrixResourceBase.setupServer(conn, master);
final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
citrixResourceBase.setupServer(conn, host);
if (!citrixResourceBase.setIptables(conn)) {
s_logger.warn("set xenserver Iptable failed");
return null;
}
final boolean r = citrixResourceBase.launchHeartBeat(conn);
if (!r) {
return null;
}
citrixResourceBase.cleanupTemplateSR(conn);
try {
if (command.useMultipath()) {
// the config value is set to true
host.addToOtherConfig(conn, "multipathing", "true");
host.addToOtherConfig(conn, "multipathhandle", "dmp");
}
} catch (final Types.MapDuplicateKey e) {
s_logger.debug("multipath is already set");
}
if (command.needSetup()) {
final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "setup_iscsi", "uuid", citrixResourceBase.getHost().getUuid());
if (!result.contains("> DONE <")) {
s_logger.warn("Unable to setup iscsi: " + result);
return new SetupAnswer(command, result);
}
Pair<PIF, PIF.Record> mgmtPif = null;
final Set<PIF> hostPifs = host.getPIFs(conn);
for (final PIF pif : hostPifs) {
final PIF.Record rec = pif.getRecord(conn);
if (rec.management) {
if (rec.VLAN != null && rec.VLAN != -1) {
final String msg = new StringBuilder("Unsupported configuration. Management network is on a VLAN. host=").append(citrixResourceBase.getHost().getUuid()).append("; pif=").append(rec.uuid).append("; vlan=").append(rec.VLAN).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Management network is on pif=" + rec.uuid);
}
mgmtPif = new Pair<>(pif, rec);
break;
}
}
if (mgmtPif == null) {
final String msg = "Unable to find management network for " + citrixResourceBase.getHost().getUuid();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
final Map<Network, Network.Record> networks = Network.getAllRecords(conn);
if (networks == null) {
final String msg = "Unable to setup as there are no networks in the host: " + citrixResourceBase.getHost().getUuid();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
for (final Network.Record network : networks.values()) {
if (network.nameLabel.equals("cloud-private")) {
for (final PIF pif : network.PIFs) {
final PIF.Record pr = pif.getRecord(conn);
if (citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found a network called cloud-private. host=" + citrixResourceBase.getHost().getUuid() + "; Network=" + network.uuid + "; " + "pif=" + pr.uuid);
}
if (pr.VLAN != null && pr.VLAN != -1) {
final String msg = new StringBuilder("Unsupported configuration. Network cloud-private is on a VLAN. Network=").append(network.uuid).append(" ; pif=").append(pr.uuid).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
if (!pr.management && pr.bondMasterOf != null && pr.bondMasterOf.size() > 0) {
if (pr.bondMasterOf.size() > 1) {
final String msg = new StringBuilder("Unsupported configuration. Network cloud-private has more than one bond. Network=").append(network.uuid).append("; pif=").append(pr.uuid).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
final Bond bond = pr.bondMasterOf.iterator().next();
final Set<PIF> slaves = bond.getSlaves(conn);
for (final PIF slave : slaves) {
final PIF.Record spr = slave.getRecord(conn);
if (spr.management) {
if (!citrixResourceBase.transferManagementNetwork(conn, host, slave, spr, pif)) {
final String msg = new StringBuilder("Unable to transfer management network. slave=" + spr.uuid + "; master=" + pr.uuid + "; host=" + citrixResourceBase.getHost().getUuid()).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
break;
}
}
}
}
}
}
}
}
return new SetupAnswer(command, false);
} catch (final XmlRpcException e) {
s_logger.warn("Unable to setup", e);
return new SetupAnswer(command, e.getMessage());
} catch (final XenAPIException e) {
s_logger.warn("Unable to setup", e);
return new SetupAnswer(command, e.getMessage());
} catch (final Exception e) {
s_logger.warn("Unable to setup", e);
return new SetupAnswer(command, e.getMessage());
}
}
use of com.xensource.xenapi.PIF in project cloudstack by apache.
the class CitrixResourceBase method fillHostInfo.
protected void fillHostInfo(final Connection conn, final StartupRoutingCommand cmd) {
final StringBuilder caps = new StringBuilder();
try {
final Host host = Host.getByUuid(conn, _host.getUuid());
final Host.Record hr = host.getRecord(conn);
Map<String, String> details = cmd.getHostDetails();
if (details == null) {
details = new HashMap<String, String>();
}
String productBrand = hr.softwareVersion.get("product_brand");
if (productBrand == null) {
productBrand = hr.softwareVersion.get("platform_name");
}
details.put("product_brand", productBrand);
details.put("product_version", _host.getProductVersion());
if (isUefiSupported(_host.getProductVersion())) {
details.put(com.cloud.host.Host.HOST_UEFI_ENABLE, Boolean.TRUE.toString());
}
if (hr.softwareVersion.get("product_version_text_short") != null) {
details.put("product_version_text_short", hr.softwareVersion.get("product_version_text_short"));
cmd.setHypervisorVersion(hr.softwareVersion.get("product_version_text_short"));
cmd.setHypervisorVersion(_host.getProductVersion());
}
if (_privateNetworkName != null) {
details.put("private.network.device", _privateNetworkName);
}
cmd.setHostDetails(details);
cmd.setName(hr.nameLabel);
cmd.setGuid(_host.getUuid());
cmd.setPool(_host.getPool());
cmd.setDataCenter(Long.toString(_dcId));
for (final String cap : hr.capabilities) {
if (cap.length() > 0) {
caps.append(cap).append(" , ");
}
}
if (caps.length() > 0) {
caps.delete(caps.length() - 3, caps.length());
}
cmd.setCaps(caps.toString());
cmd.setSpeed(_host.getSpeed());
cmd.setCpuSockets(_host.getCpuSockets());
cmd.setCpus(_host.getCpus());
final HostMetrics hm = host.getMetrics(conn);
long ram = 0;
long dom0Ram = 0;
ram = hm.getMemoryTotal(conn);
final Set<VM> vms = host.getResidentVMs(conn);
for (final VM vm : vms) {
if (vm.getIsControlDomain(conn)) {
dom0Ram = vm.getMemoryStaticMax(conn);
break;
}
}
ram = (long) ((ram - dom0Ram - _xsMemoryUsed) * _xsVirtualizationFactor);
cmd.setMemory(ram);
cmd.setDom0MinMemory(dom0Ram);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Total Ram: " + toHumanReadableSize(ram) + " dom0 Ram: " + toHumanReadableSize(dom0Ram));
}
PIF pif = PIF.getByUuid(conn, _host.getPrivatePif());
PIF.Record pifr = pif.getRecord(conn);
if (pifr.IP != null && pifr.IP.length() > 0) {
cmd.setPrivateIpAddress(pifr.IP);
cmd.setPrivateMacAddress(pifr.MAC);
cmd.setPrivateNetmask(pifr.netmask);
} else {
cmd.setPrivateIpAddress(_host.getIp());
cmd.setPrivateMacAddress(pifr.MAC);
cmd.setPrivateNetmask("255.255.255.0");
}
pif = PIF.getByUuid(conn, _host.getPublicPif());
pifr = pif.getRecord(conn);
if (pifr.IP != null && pifr.IP.length() > 0) {
cmd.setPublicIpAddress(pifr.IP);
cmd.setPublicMacAddress(pifr.MAC);
cmd.setPublicNetmask(pifr.netmask);
}
if (_host.getStoragePif1() != null) {
pif = PIF.getByUuid(conn, _host.getStoragePif1());
pifr = pif.getRecord(conn);
if (pifr.IP != null && pifr.IP.length() > 0) {
cmd.setStorageIpAddress(pifr.IP);
cmd.setStorageMacAddress(pifr.MAC);
cmd.setStorageNetmask(pifr.netmask);
}
}
if (_host.getStoragePif2() != null) {
pif = PIF.getByUuid(conn, _host.getStoragePif2());
pifr = pif.getRecord(conn);
if (pifr.IP != null && pifr.IP.length() > 0) {
cmd.setStorageIpAddressDeux(pifr.IP);
cmd.setStorageMacAddressDeux(pifr.MAC);
cmd.setStorageNetmaskDeux(pifr.netmask);
}
}
final Map<String, String> configs = hr.otherConfig;
cmd.setIqn(configs.get("iscsi_iqn"));
cmd.setPod(_pod);
cmd.setVersion(CitrixResourceBase.class.getPackage().getImplementationVersion());
try {
final String cmdLine = "xe sm-list | grep \"resigning of duplicates\"";
final XenServerUtilitiesHelper xenServerUtilitiesHelper = getXenServerUtilitiesHelper();
Pair<Boolean, String> result = xenServerUtilitiesHelper.executeSshWrapper(_host.getIp(), 22, _username, null, getPwdFromQueue(), cmdLine);
boolean supportsClonedVolumes = result != null && result.first() != null && result.first() && result.second() != null && result.second().length() > 0;
cmd.setSupportsClonedVolumes(supportsClonedVolumes);
} catch (NumberFormatException ex) {
s_logger.warn("Issue sending 'xe sm-list' via SSH to XenServer host: " + ex.getMessage());
}
} catch (final XmlRpcException e) {
throw new CloudRuntimeException("XML RPC Exception: " + e.getMessage(), e);
} catch (final XenAPIException e) {
throw new CloudRuntimeException("XenAPIException: " + e.toString(), e);
} catch (final Exception e) {
throw new CloudRuntimeException("Exception: " + e.toString(), e);
}
}
use of com.xensource.xenapi.PIF in project cloudstack by apache.
the class XsLocalNetwork method getPif.
public PIF getPif(final Connection conn) throws XenAPIException, XmlRpcException {
if (_p == null) {
final Network.Record nr = getNetworkRecord(conn);
for (final PIF pif : nr.PIFs) {
final PIF.Record pr = pif.getRecord(conn);
if (_citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found a network called " + nr.nameLabel + " on host=" + _citrixResourceBase.getHost().getIp() + "; Network=" + nr.uuid + "; pif=" + pr.uuid);
}
_p = pif;
_pr = pr;
break;
}
}
}
return _p;
}
Aggregations