use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method finalizeDeployment.
@Override
public boolean finalizeDeployment(final Commands cmds, final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException {
final DomainRouterVO router = _routerDao.findById(profile.getId());
final List<NicProfile> nics = profile.getNics();
for (final NicProfile nic : nics) {
if (nic.getTrafficType() == TrafficType.Public) {
router.setPublicIpAddress(nic.getIPv4Address());
router.setPublicNetmask(nic.getIPv4Netmask());
router.setPublicMacAddress(nic.getMacAddress());
} else if (nic.getTrafficType() == TrafficType.Control) {
router.setPrivateIpAddress(nic.getIPv4Address());
router.setPrivateMacAddress(nic.getMacAddress());
}
}
_routerDao.update(router.getId(), router);
finalizeCommandsOnStart(cmds, profile);
return true;
}
use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class CommandSetupHelper method createSetupGuestNetworkCommand.
public SetupGuestNetworkCommand createSetupGuestNetworkCommand(final DomainRouterVO router, final boolean add, final NicProfile guestNic) {
final Network network = _networkModel.getNetwork(guestNic.getNetworkId());
String defaultDns1 = null;
String defaultDns2 = null;
final boolean dnsProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, Provider.VPCVirtualRouter);
final boolean dhcpProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, Provider.VPCVirtualRouter);
final boolean setupDns = dnsProvided || dhcpProvided;
if (setupDns) {
defaultDns1 = guestNic.getIPv4Dns1();
defaultDns2 = guestNic.getIPv4Dns2();
}
final Nic nic = _nicDao.findByNtwkIdAndInstanceId(network.getId(), router.getId());
final String networkDomain = network.getNetworkDomain();
final String dhcpRange = getGuestDhcpRange(guestNic, network, _entityMgr.findById(DataCenter.class, network.getDataCenterId()));
final NicProfile nicProfile = _networkModel.getNicProfile(router, nic.getNetworkId(), null);
final SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, router.getIsRedundantRouter(), defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType()));
final String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIPv4Address()) | ~NetUtils.ip2Long(guestNic.getIPv4Netmask()));
setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(network.getId(), router.getId()));
setupCmd.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY, network.getGateway());
setupCmd.setAccessDetail(NetworkElementCommand.GUEST_BRIDGE, brd);
setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
if (network.getBroadcastDomainType() == BroadcastDomainType.Vlan) {
final long guestVlanTag = Long.parseLong(BroadcastDomainType.Vlan.getValueFrom(network.getBroadcastUri()));
setupCmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag));
}
return setupCmd;
}
use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class ServiceManagerImpl method createServiceVM.
/**
* In the case of service instance the master object is in the contrail API server. This object stores the
* service instance parameters in the database.
*
* @param owner Used to determine the project.
* @param name Service instance name (user specified).
* @param template Image to execute.
* @param serviceOffering
* @param left Inside network.
* @param right Outside network.
* @return
*/
/**
* create a new ServiceVM object.
* @return
*/
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "createServiceInstance", create = true)
private ServiceVirtualMachine createServiceVM(DataCenter zone, Account owner, VirtualMachineTemplate template, ServiceOffering serviceOffering, String name, ServiceInstance siObj, Network left, Network right) {
long id = _vmDao.getNextInSequence(Long.class, "id");
DataCenterDeployment plan = new DataCenterDeployment(zone.getId());
LinkedHashMap<NetworkVO, List<? extends NicProfile>> networks = new LinkedHashMap<NetworkVO, List<? extends NicProfile>>();
NetworkVO linklocal = (NetworkVO) _networkModel.getSystemNetworkByZoneAndTrafficType(zone.getId(), TrafficType.Management);
networks.put(linklocal, new ArrayList<NicProfile>());
networks.put((NetworkVO) left, new ArrayList<NicProfile>());
networks.put((NetworkVO) right, new ArrayList<NicProfile>());
String instanceName = VirtualMachineName.getVmName(id, owner.getId(), "SRV");
long userId = CallContext.current().getCallingUserId();
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
if (!userVOs.isEmpty()) {
userId = userVOs.get(0).getId();
}
}
ServiceVirtualMachine svm = new ServiceVirtualMachine(id, instanceName, name, template.getId(), serviceOffering.getId(), template.getHypervisorType(), template.getGuestOSId(), zone.getId(), owner.getDomainId(), owner.getAccountId(), userId, false);
// database synchronization code must be able to distinguish service instance VMs.
Map<String, String> kvmap = new HashMap<String, String>();
kvmap.put("service-instance", siObj.getUuid());
Gson json = new Gson();
String userData = json.toJson(kvmap);
svm.setUserData(userData);
try {
_vmManager.allocate(instanceName, template, serviceOffering, networks, plan, template.getHypervisorType());
} catch (InsufficientCapacityException ex) {
throw new CloudRuntimeException("Insufficient capacity", ex);
}
CallContext.current().setEventDetails("Vm Id: " + svm.getId());
return svm;
}
use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class ManagementServerMock method createVM.
public UserVm createVM(String name, Network network) {
VMTemplateVO tmpl = getVMTemplate();
assertNotNull(tmpl);
ServiceOffering small = getServiceByName("Small Instance");
assertNotNull(small);
Answer<?> callback = new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
Commands cmds = (Commands) args[1];
if (cmds == null) {
return null;
}
PlugNicAnswer reply = new PlugNicAnswer(null, true, "PlugNic");
com.cloud.agent.api.Answer[] answers = { reply };
cmds.setAnswers(answers);
return null;
}
};
try {
Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenAnswer(callback);
} catch (AgentUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long id = _userVmDao.getNextInSequence(Long.class, "id");
UserVmVO vm = new UserVmVO(id, name, name, tmpl.getId(), HypervisorType.XenServer, tmpl.getGuestOSId(), false, false, _zone.getDomainId(), Account.ACCOUNT_ID_SYSTEM, 1, small.getId(), null, name, null);
vm.setState(com.cloud.vm.VirtualMachine.State.Running);
vm.setHostId(_hostId);
vm.setDataCenterId(network.getDataCenterId());
_userVmDao.persist(vm);
NicProfile profile = new NicProfile();
try {
_vmMgr.addVmToNetwork(vm, network, profile);
} catch (Exception ex) {
// TODO Auto-generated catch block
//ex.printStackTrace();
}
return vm;
}
use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class HypervisorGuruBase method toVirtualMachineTO.
protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) {
ServiceOffering offering = _serviceOfferingDao.findById(vmProfile.getId(), vmProfile.getServiceOfferingId());
VirtualMachine vm = vmProfile.getVirtualMachine();
Long minMemory = (long) (offering.getRamSize() / vmProfile.getMemoryOvercommitRatio());
int minspeed = (int) (offering.getSpeed() / vmProfile.getCpuOvercommitRatio());
int maxspeed = (offering.getSpeed());
VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), minspeed, maxspeed, minMemory * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled(), vm.limitCpuUse(), vm.getVncPassword());
to.setBootArgs(vmProfile.getBootArgs());
List<NicProfile> nicProfiles = vmProfile.getNics();
NicTO[] nics = new NicTO[nicProfiles.size()];
int i = 0;
for (NicProfile nicProfile : nicProfiles) {
nics[i++] = toNicTO(nicProfile);
}
to.setNics(nics);
to.setDisks(vmProfile.getDisks().toArray(new DiskTO[vmProfile.getDisks().size()]));
if (vmProfile.getTemplate().getBits() == 32) {
to.setArch("i686");
} else {
to.setArch("x86_64");
}
Map<String, String> detailsInVm = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
if (detailsInVm != null) {
to.setDetails(detailsInVm);
}
// Set GPU details
ServiceOfferingDetailsVO offeringDetail = null;
if ((offeringDetail = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString())) != null) {
ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.pciDevice.toString());
to.setGpuDevice(_resourceMgr.getGPUDevice(vm.getHostId(), groupName.getValue(), offeringDetail.getValue()));
}
// Workaround to make sure the TO has the UUID we need for Niciri integration
VMInstanceVO vmInstance = _virtualMachineDao.findById(to.getId());
// check if XStools/VMWare tools are present in the VM and dynamic scaling feature is enabled (per zone/global)
Boolean isDynamicallyScalable = vmInstance.isDynamicallyScalable() && UserVmManager.EnableDynamicallyScaleVm.valueIn(vm.getDataCenterId());
to.setEnableDynamicallyScaleVm(isDynamicallyScalable);
to.setUuid(vmInstance.getUuid());
to.setVmData(vmProfile.getVmData());
to.setConfigDriveLabel(vmProfile.getConfigDriveLabel());
to.setConfigDriveIsoRootFolder(vmProfile.getConfigDriveIsoRootFolder());
to.setConfigDriveIsoFile(vmProfile.getConfigDriveIsoFile());
return to;
}
Aggregations