use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class HypervisorGuruBase method toNicTO.
@Override
public NicTO toNicTO(NicProfile profile) {
NicTO to = new NicTO();
to.setDeviceId(profile.getDeviceId());
to.setBroadcastType(profile.getBroadcastType());
to.setType(profile.getTrafficType());
to.setIp(profile.getIPv4Address());
to.setNetmask(profile.getIPv4Netmask());
to.setMac(profile.getMacAddress());
to.setDns1(profile.getIPv4Dns1());
to.setDns2(profile.getIPv4Dns2());
to.setGateway(profile.getIPv4Gateway());
to.setDefaultNic(profile.isDefaultNic());
to.setBroadcastUri(profile.getBroadCastUri());
to.setIsolationuri(profile.getIsolationUri());
to.setNetworkRateMbps(profile.getNetworkRate());
to.setName(profile.getName());
to.setSecurityGroupEnabled(profile.isSecurityGroupEnabled());
to.setIp6Address(profile.getIPv6Address());
to.setIp6Cidr(profile.getIPv6Cidr());
NetworkVO network = _networkDao.findById(profile.getNetworkId());
to.setNetworkUuid(network.getUuid());
// Workaround to make sure the TO has the UUID we need for Nicira integration
NicVO nicVO = _nicDao.findById(profile.getId());
if (nicVO != null) {
to.setUuid(nicVO.getUuid());
// disable pxe on system vm nics to speed up boot time
if (nicVO.getVmType() != VirtualMachine.Type.User) {
to.setPxeDisable(true);
}
List<String> secIps = null;
if (nicVO.getSecondaryIp()) {
secIps = _nicSecIpDao.getSecondaryIpAddressesForNic(nicVO.getId());
}
to.setNicSecIps(secIps);
} else {
s_logger.warn("Unabled to load NicVO for NicProfile " + profile.getId());
//Workaround for dynamically created nics
//FixMe: uuid and secondary IPs can be made part of nic profile
to.setUuid(UUID.randomUUID().toString());
}
// configuration. Use full when vm stop/start
return to;
}
use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class OvmResourceBase method execute.
protected PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) {
VirtualMachineTO vm = cmd.getVirtualMachine();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Preparing host for migrating " + vm);
}
NicTO[] nics = vm.getNics();
try {
for (NicTO nic : nics) {
getNetwork(nic);
}
return new PrepareForMigrationAnswer(cmd);
} catch (Exception e) {
s_logger.warn("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to " + e.toString(), e);
return new PrepareForMigrationAnswer(cmd, e);
}
}
use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class OvmResourceBase method execute.
@Override
public synchronized StartAnswer execute(StartCommand cmd) {
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();
OvmVm.Details vmDetails = null;
try {
vmDetails = new OvmVm.Details();
applySpecToVm(vmDetails, vmSpec);
createVbds(vmDetails, vmSpec);
createVifs(vmDetails, vmSpec);
startVm(vmDetails);
// Add security group rules
NicTO[] nics = vmSpec.getNics();
for (NicTO nic : nics) {
if (nic.isSecurityGroupEnabled()) {
if (vmSpec.getType().equals(VirtualMachine.Type.User)) {
defaultNetworkRulesForUserVm(vmName, vmSpec.getId(), nic);
}
}
}
return new StartAnswer(cmd);
} catch (Exception e) {
s_logger.debug("Start vm " + vmName + " failed", e);
cleanup(vmDetails);
return new StartAnswer(cmd, e.getMessage());
}
}
use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class OvmResourceBase method createVifs.
protected void createVifs(OvmVm.Details vm, VirtualMachineTO spec) throws CloudRuntimeException, XmlRpcException {
NicTO[] nics = spec.getNics();
List<OvmVif.Details> vifs = new ArrayList<OvmVif.Details>(nics.length);
for (NicTO nic : nics) {
OvmVif.Details vif = createVif(nic);
vifs.add(nic.getDeviceId(), vif);
}
vm.vifs.addAll(vifs);
}
use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class VirtualMachineManagerImpl method orchestrateRemoveNicFromVm.
private boolean orchestrateRemoveNicFromVm(final VirtualMachine vm, final Nic nic) throws ConcurrentOperationException, ResourceUnavailableException {
final CallContext cctx = CallContext.current();
final VMInstanceVO vmVO = _vmDao.findById(vm.getId());
final NetworkVO network = _networkDao.findById(nic.getNetworkId());
final ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount());
final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null);
final DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
final Host host = _hostDao.findById(vm.getHostId());
final DeployDestination dest = new DeployDestination(dc, null, null, host);
final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
final VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()), _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
//1) Unplug the nic
if (vm.getState() == State.Running) {
final NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
s_logger.debug("Un-plugging nic " + nic + " for vm " + vm + " from network " + network);
final boolean result = unplugNic(network, nicTO, vmTO, context, dest);
if (result) {
s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network);
final long isDefault = nic.isDefaultNic() ? 1 : 0;
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
} else {
s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network);
return false;
}
} else if (vm.getState() != State.Stopped) {
s_logger.warn("Unable to remove vm " + vm + " from network " + network);
throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", DataCenter.class, vm.getDataCenterId());
}
//2) Release the nic
_networkMgr.releaseNic(vmProfile, nic);
s_logger.debug("Successfully released nic " + nic + "for vm " + vm);
//3) Remove the nic
_networkMgr.removeNic(vmProfile, nic);
_nicsDao.expunge(nic.getId());
return true;
}
Aggregations