mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Don't depend on static paths especially if we are already checking that
location using the getResource call.
This commit is contained in:
parent
ae4d49810e
commit
328599ae0b
@ -18,6 +18,25 @@
|
||||
// Automatically generated by addcopyright.py at 01/29/2013
|
||||
package com.cloud.baremetal.networkservice;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd;
|
||||
import org.apache.cloudstack.api.AddBaremetalPxeCmd;
|
||||
import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
|
||||
import com.cloud.agent.api.baremetal.IpmISetBootDevCommand.BootDev;
|
||||
@ -60,23 +79,6 @@ import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd;
|
||||
import org.apache.cloudstack.api.AddBaremetalPxeCmd;
|
||||
import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Local(value = BaremetalPxeService.class)
|
||||
public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase implements BaremetalPxeService {
|
||||
@ -163,12 +165,9 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple
|
||||
if (url != null) {
|
||||
keyFile = new File(url.getPath());
|
||||
}
|
||||
if (keyFile == null || !keyFile.exists()) {
|
||||
keyFile = new File("/usr/share/cloudstack-common/scripts/vm/systemvm/id_rsa.cloud");
|
||||
}
|
||||
assert (keyFile != null);
|
||||
if (!keyFile.exists()) {
|
||||
s_logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString());
|
||||
if (keyFile == null || !keyFile.canRead()) {
|
||||
s_logger.error("Unable to locate id_rsa.cloud");
|
||||
return null;
|
||||
}
|
||||
return keyFile;
|
||||
}
|
||||
@ -204,15 +203,6 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple
|
||||
return true;
|
||||
}
|
||||
|
||||
private URI buildUrl(String mgmtIp, String subPath) {
|
||||
UriComponentsBuilder ub = UriComponentsBuilder.newInstance();
|
||||
ub.scheme("http");
|
||||
ub.scheme(mgmtIp);
|
||||
ub.port(10086);
|
||||
ub.path(subPath);
|
||||
return ub.build().toUri();
|
||||
}
|
||||
|
||||
private boolean preparePxeInAdvancedZone(VirtualMachineProfile profile, NicProfile nic, Network network, DeployDestination dest, ReservationContext context) throws Exception {
|
||||
DomainRouterVO vr = getVirtualRouter(network);
|
||||
List<NicVO> nics = _nicDao.listByVmId(vr.getId());
|
||||
@ -232,7 +222,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple
|
||||
Pair<Boolean, String> ret = SshHelper.sshExecute(mgmtNic.getIp4Address(), 3922, "root", getSystemVMKeyFile(), null,
|
||||
String.format("/usr/bin/prepare_pxe.sh %s %s %s %s %s", tuple.get(1), tuple.get(2), profile.getTemplate().getUuid(),
|
||||
String.format("01-%s", nic.getMacAddress().replaceAll(":", "-")), tuple.get(0))
|
||||
);
|
||||
);
|
||||
if (!ret.first()) {
|
||||
throw new CloudRuntimeException(String.format("failed preparing PXE in virtual router[id:%s], because %s", vr.getId(), ret.second()));
|
||||
}
|
||||
@ -241,7 +231,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple
|
||||
String internalServerIp = "10.223.110.231";
|
||||
ret = SshHelper.sshExecute(mgmtNic.getIp4Address(), 3922, "root", getSystemVMKeyFile(), null,
|
||||
String.format("/usr/bin/baremetal_snat.sh %s %s", mgmtNic.getIp4Address(), internalServerIp)
|
||||
);
|
||||
);
|
||||
if (!ret.first()) {
|
||||
throw new CloudRuntimeException(String.format("failed preparing PXE in virtual router[id:%s], because %s", vr.getId(), ret.second()));
|
||||
}
|
||||
@ -299,13 +289,13 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple
|
||||
zoneId = pNetwork.getDataCenterId();
|
||||
|
||||
PhysicalNetworkServiceProviderVO ntwkSvcProvider =
|
||||
_physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(), BaremetalPxeManager.BAREMETAL_PXE_SERVICE_PROVIDER.getName());
|
||||
_physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(), BaremetalPxeManager.BAREMETAL_PXE_SERVICE_PROVIDER.getName());
|
||||
if (ntwkSvcProvider == null) {
|
||||
throw new CloudRuntimeException("Network Service Provider: " + BaremetalPxeManager.BAREMETAL_PXE_SERVICE_PROVIDER.getName() +
|
||||
" is not enabled in the physical network: " + cmd.getPhysicalNetworkId() + "to add this device");
|
||||
" is not enabled in the physical network: " + cmd.getPhysicalNetworkId() + "to add this device");
|
||||
} else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
|
||||
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " +
|
||||
cmd.getPhysicalNetworkId() + "to add this device");
|
||||
cmd.getPhysicalNetworkId() + "to add this device");
|
||||
}
|
||||
|
||||
List<HostVO> pxes = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.BaremetalPxe, zoneId);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user