Welcome, Guest
Username: Password: Remember me
Archived CloudStack Forums for reference purposes please direct all future inquiries to the Apache CloudStack mailing lists.

incubator.apache.org/cloudstack/mailing-lists.html

TOPIC: VM Allocation : Filter hosts according present VMs

VM Allocation : Filter hosts according present VMs 1 year 1 week ago #12809

  • nfo
  • nfo's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
  • Karma: 0
Hello,

First of all, sorry if my question is trivial, but this is my first day with cloudstak.

For my test, the goal is to install a new VM on a host if only a similar VM is not yet install on this host.
Consequently, at the end, I try to obtain severals hosts with differents (soft) VMs on them.


For that, I wrote the following code but, I don't know how to obtain from the host the VMs which are already installed and swited on on it. Is it possible or does it exist a workaround ?

I continue to look for ...
but feel free to give me a direction or documentation to solve this issue

Thanks in advance,
package fr.test.cloudstack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import com.cloud.agent.manager.allocator.HostAllocator;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.host.dao.HostDao;
import com.cloud.offering.ServiceOffering;
import com.cloud.resource.ResourceManager;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.host.HostVO;
@Local(value = { HostAllocator.class })
public class TestingAllocator implements HostAllocator {
	// Attributes
	private String _name;
	@Override
	public List<Host> allocateTo(
			VirtualMachineProfile<? extends VirtualMachine> vmProfile,
			DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) {
		return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true);
	}
	@Override
	public List<Host> allocateTo(
			VirtualMachineProfile<? extends VirtualMachine> vmProfile,
			DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo,
			boolean considerReservedCapacity) {
		// Information
		long dcId = plan.getDataCenterId();
		long podId = plan.getPodId();
		long clusterId = plan.getClusterId();
		ServiceOffering serviceOffering = vmProfile.getServiceOffering();
		if (type == Host.Type.Storage || type == Host.Type.Routing)
			return new ArrayList<Host>();
		// 2) Retrieve available hosts
		ComponentLocator _locator = ComponentLocator.getCurrentLocator();
		//ResourceManager manager = _locator.getManager(ResourceManager.class) ;
		HostDao _hostDao = _locator.getDao(HostDao.class);
		List<HostVO> allHosts = _hostDao.listAll(); // _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag) ;
		// 3) Filtering hosts
		List<Host> availableHostsForCassandra = new ArrayList<Host>();
		for (HostVO hostVO : allHosts) {
			boolean isAvailable = hostVO.isAvailable();
			String hostname = hostVO.getName();
			// long hostId = hostVO.getId() ;
			boolean hasAlreadyACassandraVM = false;
			// See if a VM has already Cassandra otherwise not take it
			Map<String, String> details = hostVO.getDetails();
			List<String> tags = hostVO.getHostTags();
			// hasAlreadyACassandraVM = true ;
			if (isAvailable && !hasAlreadyACassandraVM && hostname != null
					&& hostname.startsWith("Cassandra")) {
				availableHostsForCassandra.add(hostVO);
			}
		}
		return availableHostsForCassandra;
	}
	@Override // La méthode configure qui va être appelée en premier
	public boolean configure(String name, Map<String, Object> params) {
		this._name = name;
		return true;
	}
	@Override
	public String getName() {
		return this._name;
	}
	@Override
	public boolean start() {
		return true;
	}
	@Override
	public boolean stop() {
		return true;
	}
	@Override
	public boolean isVirtualMachineUpgradable(UserVm arg0, ServiceOffering arg1) {
		return true;
	}
}
The administrator has disabled public write access.
Time to create page: 0.262 seconds

Open@Citrix

Citrix supports the open source community via developer support and evangeslism. We have a number of developers and evangelists that participate actively in the open source community in Apache Cloudstack, OpenDaylight, Xen Project and XenServer. We also conduct educational activities via the Build A Cloud events held all over the world. 

Connect