use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class SecondaryStorageManagerImpl method generateFirewallConfiguration.
@Override
public boolean generateFirewallConfiguration(Long ssAHostId) {
if (ssAHostId == null) {
return true;
}
HostVO ssAHost = _hostDao.findById(ssAHostId);
String hostName = ssAHost.getName();
SecondaryStorageVmVO thisSecStorageVm = _secStorageVmDao.findByInstanceName(hostName);
if (thisSecStorageVm == null) {
s_logger.warn(String.format("Secondary storage VM [%s] does not exist.", hostName));
return false;
}
String copyPort = _useSSlCopy ? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand(true);
thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
sc.and(sc.entity().getStatus(), Op.IN, Status.Up, Status.Connecting);
List<HostVO> ssvms = sc.list();
for (HostVO ssvm : ssvms) {
if (ssvm.getId() == ssAHostId) {
continue;
}
hostName = ssvm.getName();
Answer answer = _agentMgr.easySend(ssvm.getId(), thiscpc);
if (answer != null && answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Successfully created firewall rules into secondary storage VM [%s].", hostName));
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Failed to create firewall rules into secondary storage VM [%s].", hostName));
}
return false;
}
}
SecStorageFirewallCfgCommand allSSVMIpList = new SecStorageFirewallCfgCommand(false);
for (HostVO ssvm : ssvms) {
if (ssvm.getId() == ssAHostId) {
continue;
}
allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
}
hostName = thisSecStorageVm.getHostName();
Answer answer = _agentMgr.easySend(ssAHostId, allSSVMIpList);
if (answer != null && answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Successfully created firewall rules into secondary storage VM [%s].", hostName));
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Failed to create firewall rules into secondary storage VM [%s] due to [%s].", hostName, answer == null ? "answer null" : answer.getDetails()));
}
return false;
}
return true;
}
use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class SecondaryStorageManagerImpl method startNew.
public SecondaryStorageVmVO startNew(long dataCenterId, SecondaryStorageVm.Role role) {
if (!isSecondaryStorageVmRequired(dataCenterId)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Secondary storage VM not required in zone [%s] account to zone config.", dataCenterId));
}
return null;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Assign secondary storage VM from a newly started instance for request from data center [%s].", dataCenterId));
}
Map<String, Object> context = createSecStorageVmInstance(dataCenterId, role);
long secStorageVmId = (Long) context.get("secStorageVmId");
if (secStorageVmId == 0) {
s_logger.debug(String.format("Creating secondary storage VM instance failed on data center [%s].", dataCenterId));
return null;
}
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
if (secStorageVm != null) {
SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATED, dataCenterId, secStorageVmId, secStorageVm, null));
return secStorageVm;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Unable to allocate secondary storage VM [%s] due to it was not found on database.", secStorageVmId));
}
SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, secStorageVmId, null, "Unable to allocate storage"));
}
return null;
}
use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class SecondaryStorageManagerImpl method finalizeVirtualMachineProfile.
@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
SecondaryStorageVmVO vm = _secStorageVmDao.findById(profile.getId());
Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(vm.getId());
vm.setDetails(details);
DataStore secStore = _dataStoreMgr.getImageStoreWithFreeCapacity(dest.getDataCenter().getId());
if (secStore == null) {
s_logger.warn(String.format("Unable to finalize virtual machine profile [%s] as it has no secondary storage available to satisfy storage needs for zone [%s].", profile.toString(), dest.getDataCenter().getUuid()));
return false;
}
StringBuilder buf = profile.getBootArgsBuilder();
buf.append(" template=domP type=secstorage");
buf.append(" host=").append(com.cloud.utils.StringUtils.toCSVList(indirectAgentLB.getManagementServerList(dest.getHost().getId(), dest.getDataCenter().getId(), null)));
buf.append(" port=").append(_mgmtPort);
buf.append(" name=").append(profile.getVirtualMachine().getHostName());
buf.append(" zone=").append(dest.getDataCenter().getId());
buf.append(" pod=").append(dest.getPod().getId());
buf.append(" guid=").append(profile.getVirtualMachine().getHostName());
buf.append(" workers=").append(_configDao.getValue("workers"));
String msPublicKey = _configDao.getValue("ssh.publickey");
buf.append(" authorized_key=").append(VirtualMachineGuru.getEncodedMsPublicKey(msPublicKey));
if (_configDao.isPremium()) {
s_logger.debug("VMWare hypervisor was configured, informing secondary storage VM to load the PremiumSecondaryStorageResource.");
buf.append(" resource=com.cloud.storage.resource.PremiumSecondaryStorageResource");
} else {
buf.append(" resource=org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource");
}
buf.append(" instance=SecStorage");
buf.append(" sslcopy=").append(Boolean.toString(_useSSlCopy));
buf.append(" role=").append(vm.getRole().toString());
buf.append(" mtu=").append(_secStorageVmMtuSize);
boolean externalDhcp = false;
String externalDhcpStr = _configDao.getValue("direct.attach.network.externalIpAllocator.enabled");
if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) {
externalDhcp = true;
}
if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) {
buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password"));
}
if (NTPServerConfig.value() != null) {
buf.append(" ntpserverlist=").append(NTPServerConfig.value().replaceAll("\\s+", ""));
}
for (NicProfile nic : profile.getNics()) {
int deviceId = nic.getDeviceId();
if (nic.getIPv4Address() == null) {
buf.append(" eth").append(deviceId).append("mask=").append("0.0.0.0");
buf.append(" eth").append(deviceId).append("ip=").append("0.0.0.0");
} else {
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIPv4Address());
buf.append(" eth").append(deviceId).append("mask=").append(nic.getIPv4Netmask());
}
if (nic.isDefaultNic()) {
buf.append(" gateway=").append(nic.getIPv4Gateway());
}
if (nic.getTrafficType() == TrafficType.Management) {
String mgmt_cidr = _configDao.getValue(Config.ManagementNetwork.key());
if (NetUtils.isValidCidrList(mgmt_cidr)) {
s_logger.debug("Management server cidr list is " + mgmt_cidr);
buf.append(" mgmtcidr=").append(mgmt_cidr);
} else {
s_logger.error("Inavlid management server cidr list: " + mgmt_cidr);
}
buf.append(" localgw=").append(dest.getPod().getGateway());
buf.append(" private.network.device=").append("eth").append(deviceId);
} else if (nic.getTrafficType() == TrafficType.Public) {
buf.append(" public.network.device=").append("eth").append(deviceId);
} else if (nic.getTrafficType() == TrafficType.Storage) {
buf.append(" storageip=").append(nic.getIPv4Address());
buf.append(" storagenetmask=").append(nic.getIPv4Netmask());
buf.append(" storagegateway=").append(nic.getIPv4Gateway());
}
}
if (externalDhcp) {
buf.append(" bootproto=dhcp");
}
DataCenterVO dc = _dcDao.findById(profile.getVirtualMachine().getDataCenterId());
buf.append(" internaldns1=").append(dc.getInternalDns1());
if (dc.getInternalDns2() != null) {
buf.append(" internaldns2=").append(dc.getInternalDns2());
}
buf.append(" dns1=").append(dc.getDns1());
if (dc.getDns2() != null) {
buf.append(" dns2=").append(dc.getDns2());
}
String nfsVersion = imageStoreDetailsUtil != null ? imageStoreDetailsUtil.getNfsVersion(secStore.getId()) : null;
buf.append(" nfsVersion=").append(nfsVersion);
String bootArgs = buf.toString();
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Boot args for machine profile [%s]: [%s].", profile.toString(), bootArgs));
}
return true;
}
use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class SecondaryStorageManagerImpl method finalizeExpunge.
@Override
public void finalizeExpunge(VirtualMachine vm) {
SecondaryStorageVmVO ssvm = _secStorageVmDao.findByUuid(vm.getUuid());
ssvm.setPublicIpAddress(null);
ssvm.setPublicMacAddress(null);
ssvm.setPublicNetmask(null);
_secStorageVmDao.update(ssvm.getId(), ssvm);
}
use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class SecondaryStorageManagerImpl method finalizeDeployment.
@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
finalizeCommandsOnStart(cmds, profile);
SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId());
DataCenter dc = dest.getDataCenter();
List<NicProfile> nics = profile.getNics();
for (NicProfile nic : nics) {
if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) {
secVm.setPublicIpAddress(nic.getIPv4Address());
secVm.setPublicNetmask(nic.getIPv4Netmask());
secVm.setPublicMacAddress(nic.getMacAddress());
} else if (nic.getTrafficType() == TrafficType.Management) {
secVm.setPrivateIpAddress(nic.getIPv4Address());
secVm.setPrivateMacAddress(nic.getMacAddress());
}
}
_secStorageVmDao.update(secVm.getId(), secVm);
return true;
}
Aggregations