use of com.cloud.vm.NicVO in project cloudstack by apache.
the class BareMetalPingServiceImpl method prepareCreateTemplate.
@Override
public boolean prepareCreateTemplate(Long pxeServerId, UserVm vm, String templateUrl) {
List<NicVO> nics = _nicDao.listByVmId(vm.getId());
if (nics.size() != 1) {
throw new CloudRuntimeException("Wrong nic number " + nics.size() + " of vm " + vm.getId());
}
/* use last host id when VM stopped */
Long hostId = (vm.getHostId() == null ? vm.getLastHostId() : vm.getHostId());
HostVO host = _hostDao.findById(hostId);
DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
NicVO nic = nics.get(0);
String mask = nic.getIPv4Netmask();
String mac = nic.getMacAddress();
String ip = nic.getIPv4Address();
String gateway = nic.getIPv4Gateway();
String dns = dc.getDns1();
if (dns == null) {
dns = dc.getDns2();
}
try {
PrepareCreateTemplateCommand cmd = new PrepareCreateTemplateCommand(ip, mac, mask, gateway, dns, templateUrl);
Answer ans = _agentMgr.send(pxeServerId, cmd);
return ans.getResult();
} catch (Exception e) {
s_logger.debug("Prepare for creating baremetal template failed", e);
return false;
}
}
use of com.cloud.vm.NicVO in project cloudstack by apache.
the class NiciraNvpElement method release.
@Override
public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
if (!canHandle(network, Service.Connectivity)) {
return false;
}
if (network.getBroadcastUri() == null) {
s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
return false;
}
NicVO nicVO = nicDao.findById(nic.getId());
List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
NiciraNvpNicMappingVO nicMap = niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
if (nicMap == null) {
s_logger.error("No mapping for nic " + nic.getName());
return false;
}
DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(nicMap.getLogicalSwitchUuid(), nicMap.getLogicalSwitchPortUuid());
DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("DeleteLogicalSwitchPortCommand failed");
return false;
}
niciraNvpNicMappingDao.remove(nicMap.getId());
return true;
}
use of com.cloud.vm.NicVO in project cloudstack by apache.
the class NiciraNvpElement method prepare.
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
if (!canHandle(network, Service.Connectivity)) {
return false;
}
if (network.getBroadcastUri() == null) {
s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
return false;
}
NicVO nicVO = nicDao.findById(nic.getId());
List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
NiciraNvpNicMappingVO existingNicMap = niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
if (existingNicMap != null) {
FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchUuid(), existingNicMap.getLogicalSwitchPortUuid());
FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), findCmd);
if (answer.getResult()) {
s_logger.warn("Existing Logical Switchport found for nic " + nic.getName() + " with uuid " + existingNicMap.getLogicalSwitchPortUuid());
UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchPortUuid(), BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
agentMgr.easySend(niciraNvpHost.getId(), cmd);
return true;
} else {
s_logger.error("Stale entry found for nic " + nic.getName() + " with logical switchport uuid " + existingNicMap.getLogicalSwitchPortUuid());
niciraNvpNicMappingDao.remove(existingNicMap.getId());
}
}
CreateLogicalSwitchPortCommand cmd = new CreateLogicalSwitchPortCommand(BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("CreateLogicalSwitchPortCommand failed");
return false;
}
NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(BroadcastDomainType.getValue(network.getBroadcastUri()), answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
niciraNvpNicMappingDao.persist(nicMap);
return true;
}
use of com.cloud.vm.NicVO in project cloudstack by apache.
the class ApiResponseHelper method createNicResponse.
@Override
public NicResponse createNicResponse(Nic result) {
NicResponse response = new NicResponse();
NetworkVO network = _entityMgr.findById(NetworkVO.class, result.getNetworkId());
VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, result.getInstanceId());
UserVmJoinVO userVm = _entityMgr.findById(UserVmJoinVO.class, result.getInstanceId());
response.setId(result.getUuid());
response.setNetworkid(network.getUuid());
if (vm != null) {
response.setVmId(vm.getUuid());
}
if (userVm != null) {
if (userVm.getTrafficType() != null) {
response.setTrafficType(userVm.getTrafficType().toString());
}
if (userVm.getGuestType() != null) {
response.setType(userVm.getGuestType().toString());
}
}
response.setIpaddress(result.getIPv4Address());
if (result.getSecondaryIp()) {
List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(result.getId());
if (secondaryIps != null) {
List<NicSecondaryIpResponse> ipList = new ArrayList<NicSecondaryIpResponse>();
for (NicSecondaryIpVO ip : secondaryIps) {
NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
ipRes.setId(ip.getUuid());
ipRes.setIpAddr(ip.getIp4Address());
ipList.add(ipRes);
}
response.setSecondaryIps(ipList);
}
}
response.setGateway(result.getIPv4Gateway());
response.setNetmask(result.getIPv4Netmask());
response.setMacAddress(result.getMacAddress());
if (result.getIPv6Address() != null) {
response.setIp6Address(result.getIPv6Address());
}
if (result.getIPv6Cidr() != null) {
response.setIp6Cidr(result.getIPv6Cidr());
}
response.setDeviceId(String.valueOf(result.getDeviceId()));
response.setIsDefault(result.isDefaultNic());
if (result instanceof NicVO) {
if (((NicVO) result).getNsxLogicalSwitchUuid() != null) {
response.setNsxLogicalSwitch(((NicVO) result).getNsxLogicalSwitchUuid());
}
if (((NicVO) result).getNsxLogicalSwitchPortUuid() != null) {
response.setNsxLogicalSwitchPort(((NicVO) result).getNsxLogicalSwitchPortUuid());
}
}
return response;
}
use of com.cloud.vm.NicVO in project cloudstack by apache.
the class DirectNetworkGuru method trash.
@Override
@DB
public boolean trash(Network network, NetworkOffering offering) {
//Have to remove all placeholder nics
try {
long id = network.getId();
final List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkId(id);
if (nics != null) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
for (Nic nic : nics) {
if (nic.getIPv4Address() != null) {
s_logger.debug("Releasing ip " + nic.getIPv4Address() + " of placeholder nic " + nic);
IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIPv4Address());
if (ip != null) {
_ipAddrMgr.markIpAsUnavailable(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId());
s_logger.debug("Removing placeholder nic " + nic);
_nicDao.remove(nic.getId());
}
}
}
}
});
}
return true;
} catch (Exception e) {
s_logger.error("trash. Exception:" + e.getMessage());
throw new CloudRuntimeException("trash. Exception:" + e.getMessage(), e);
}
}
Aggregations