use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.
the class BaremetalKickStartServiceImpl method addPxeServer.
@Override
@DB
public BaremetalPxeVO addPxeServer(AddBaremetalPxeCmd cmd) {
AddBaremetalKickStartPxeCmd kcmd = (AddBaremetalKickStartPxeCmd) cmd;
PhysicalNetworkVO pNetwork = null;
long zoneId;
if (cmd.getPhysicalNetworkId() == null || cmd.getUrl() == null || cmd.getUsername() == null || cmd.getPassword() == null) {
throw new IllegalArgumentException("At least one of the required parameters(physical network id, url, username, password) is null");
}
pNetwork = _physicalNetworkDao.findById(cmd.getPhysicalNetworkId());
if (pNetwork == null) {
throw new IllegalArgumentException("Could not find phyical network with ID: " + cmd.getPhysicalNetworkId());
}
zoneId = pNetwork.getDataCenterId();
PhysicalNetworkServiceProviderVO ntwkSvcProvider = _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");
} 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");
}
List<HostVO> pxes = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.BaremetalPxe, zoneId);
if (!pxes.isEmpty()) {
throw new IllegalArgumentException("Already had a PXE server zone: " + zoneId);
}
String tftpDir = kcmd.getTftpDir();
if (tftpDir == null) {
throw new IllegalArgumentException("No TFTP directory specified");
}
URI uri;
try {
uri = new URI(cmd.getUrl());
} catch (Exception e) {
s_logger.debug(e);
throw new IllegalArgumentException(e.getMessage());
}
String ipAddress = uri.getHost();
if (ipAddress == null) {
ipAddress = cmd.getUrl();
}
String guid = getPxeServerGuid(Long.toString(zoneId), BaremetalPxeType.KICK_START.toString(), ipAddress);
ServerResource resource = null;
Map params = new HashMap<String, String>();
params.put(BaremetalPxeService.PXE_PARAM_ZONE, Long.toString(zoneId));
params.put(BaremetalPxeService.PXE_PARAM_IP, ipAddress);
params.put(BaremetalPxeService.PXE_PARAM_USERNAME, cmd.getUsername());
params.put(BaremetalPxeService.PXE_PARAM_PASSWORD, cmd.getPassword());
params.put(BaremetalPxeService.PXE_PARAM_TFTP_DIR, tftpDir);
params.put(BaremetalPxeService.PXE_PARAM_GUID, guid);
resource = new BaremetalKickStartPxeResource();
try {
resource.configure("KickStart PXE resource", params);
} catch (Exception e) {
throw new CloudRuntimeException(e.getMessage(), e);
}
Host pxeServer = _resourceMgr.addHost(zoneId, resource, Host.Type.BaremetalPxe, params);
if (pxeServer == null) {
throw new CloudRuntimeException("Cannot add PXE server as a host");
}
BaremetalPxeVO vo = new BaremetalPxeVO();
vo.setHostId(pxeServer.getId());
vo.setNetworkServiceProviderId(ntwkSvcProvider.getId());
vo.setPhysicalNetworkId(kcmd.getPhysicalNetworkId());
vo.setDeviceType(BaremetalPxeType.KICK_START.toString());
_pxeDao.persist(vo);
return vo;
}
use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.
the class BaremetalPxeManagerImpl method addUserData.
@Override
public boolean addUserData(NicProfile nic, VirtualMachineProfile profile) {
UserVmVO vm = _vmDao.findById(profile.getVirtualMachine().getId());
_vmDao.loadDetails(vm);
String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText();
String zoneName = _dcDao.findById(vm.getDataCenterId()).getName();
NicVO nvo = _nicDao.findById(nic.getId());
VmDataCommand cmd = new VmDataCommand(nvo.getIPv4Address(), vm.getInstanceName(), _ntwkModel.getExecuteInSeqNtwkElmtCmd());
// if you add new metadata files, also edit systemvm/patches/debian/config/var/www/html/latest/.htaccess
cmd.addVmData("userdata", "user-data", vm.getUserData());
cmd.addVmData("metadata", "service-offering", StringUtils.unicodeEscape(serviceOffering));
cmd.addVmData("metadata", "availability-zone", StringUtils.unicodeEscape(zoneName));
cmd.addVmData("metadata", "local-ipv4", nic.getIPv4Address());
cmd.addVmData("metadata", "local-hostname", StringUtils.unicodeEscape(vm.getInstanceName()));
cmd.addVmData("metadata", "public-ipv4", nic.getIPv4Address());
cmd.addVmData("metadata", "public-hostname", StringUtils.unicodeEscape(vm.getInstanceName()));
cmd.addVmData("metadata", "instance-id", String.valueOf(vm.getUuid()));
cmd.addVmData("metadata", "vm-id", String.valueOf(vm.getInstanceName()));
cmd.addVmData("metadata", "public-keys", null);
String cloudIdentifier = _configDao.getValue("cloud.identifier");
if (cloudIdentifier == null) {
cloudIdentifier = "";
} else {
cloudIdentifier = "CloudStack-{" + cloudIdentifier + "}";
}
cmd.addVmData("metadata", "cloud-identifier", cloudIdentifier);
List<PhysicalNetworkVO> phys = _phynwDao.listByZone(vm.getDataCenterId());
if (phys.isEmpty()) {
throw new CloudRuntimeException(String.format("Cannot find physical network in zone %s", vm.getDataCenterId()));
}
if (phys.size() > 1) {
throw new CloudRuntimeException(String.format("Baremetal only supports one physical network in zone, but zone %s has %s physical networks", vm.getDataCenterId(), phys.size()));
}
PhysicalNetworkVO phy = phys.get(0);
QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
//TODO: handle both kickstart and PING
//sc.addAnd(sc.getEntity().getPodId(), Op.EQ, vm.getPodIdToDeployIn());
sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, phy.getId());
BaremetalPxeVO pxeVo = sc.find();
if (pxeVo == null) {
throw new CloudRuntimeException("No PXE server found in pod: " + vm.getPodIdToDeployIn() + ", you need to add it before starting VM");
}
try {
Answer ans = _agentMgr.send(pxeVo.getHostId(), cmd);
if (!ans.getResult()) {
s_logger.debug(String.format("Add userdata to vm:%s failed because %s", vm.getInstanceName(), ans.getDetails()));
return false;
} else {
return true;
}
} catch (Exception e) {
s_logger.debug(String.format("Add userdata to vm:%s failed", vm.getInstanceName()), e);
return false;
}
}
use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.
the class BaremetalKickStartServiceImpl method getApiResponse.
@Override
public BaremetalPxeResponse getApiResponse(BaremetalPxeVO vo) {
BaremetalPxeResponse response = new BaremetalPxeResponse();
response.setId(vo.getUuid());
HostVO host = _hostDao.findById(vo.getHostId());
response.setUrl(host.getPrivateIpAddress());
PhysicalNetworkServiceProviderVO providerVO = _physicalNetworkServiceProviderDao.findById(vo.getNetworkServiceProviderId());
response.setPhysicalNetworkId(providerVO.getUuid());
PhysicalNetworkVO nwVO = _physicalNetworkDao.findById(vo.getPhysicalNetworkId());
response.setPhysicalNetworkId(nwVO.getUuid());
response.setObjectName("baremetalpxeserver");
return response;
}
use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.
the class F5ExternalLoadBalancerElement method addExternalLoadBalancer.
@Override
@Deprecated
public Host addExternalLoadBalancer(AddExternalLoadBalancerCmd cmd) {
Long zoneId = cmd.getZoneId();
DataCenterVO zone = null;
PhysicalNetworkVO pNetwork = null;
ExternalLoadBalancerDeviceVO lbDeviceVO = null;
HostVO lbHost = null;
zone = _dcDao.findById(zoneId);
if (zone == null) {
throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
}
List<PhysicalNetworkVO> physicalNetworks = _physicalNetworkDao.listByZone(zoneId);
if ((physicalNetworks == null) || (physicalNetworks.size() > 1)) {
throw new InvalidParameterValueException("There are no physical networks or multiple physical networks configured in zone with ID: " + zoneId + " to add this device.");
}
pNetwork = physicalNetworks.get(0);
String deviceType = NetworkDevice.F5BigIpLoadBalancer.getName();
lbDeviceVO = addExternalLoadBalancer(pNetwork.getId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceType, new F5BigIpResource(), false, false, null, null);
if (lbDeviceVO != null) {
lbHost = _hostDao.findById(lbDeviceVO.getHostId());
}
return lbHost;
}
use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.
the class NiciraNvpGuestNetworkGuruTest method testDesignNoIsolationMethodSTT.
@Test
public void testDesignNoIsolationMethodSTT() {
final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VLAN" }));
when(physnet.getId()).thenReturn(NETWORK_ID);
mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NiciraNvpDeviceVO>emptyList());
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
final DeploymentPlan plan = mock(DeploymentPlan.class);
final Network network = mock(Network.class);
final Account account = mock(Account.class);
final Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
Aggregations