public ForemanVM build() throws Exception {
		if (vmName==null) {
			throw new RuntimeException("must set vm name");
		}
		
		Host newHost = jsonHostTemplate == null ? HostFormBuilder.newTemplate(vmName) : HostFormBuilder.newTemplate(vmName, "/templates/"+ jsonHostTemplate);
		
		
		if (hostGroup!=null) {
			newHost.withHostGroup(hostGroup);
		}	
		
		if(memorySizeMB > 0){
			newHost.computeAttrs.memory = String.valueOf((long)memorySizeMB*1024*1024);
		}
		if(clusterId != null){
			newHost.computeAttrs.cluster = clusterId;
		}
		if(numberOfCpuCores > 0){
			newHost.computeAttrs.cores = String.valueOf(numberOfCpuCores);
		}
		
		setImage(newHost, this.imageId, this.computeResId);
		
		if(diskSizeGB > 0){
			Date now = new Date();
			Map<String, Volumes_Attributes> volumes = new HashMap<String, Volumes_Attributes>();
			
			volumes.put("new_"+now.getTime(), new Volumes_Attributes(storageId, String.valueOf(diskSizeGB), "", ""));
			newHost.computeAttrs.volumes_attributes = volumes;
		}
		if(ownedBy != null){
		    newHost.isOwnedBy = ownedBy;
		}
		
		logger.info("Creating a new VM with following parameters - name: {}, host group id: {}, ",newHost.name, newHost.hostGroup);
		
		// foreman expects wrapped host
		HostWrapper hostWrapped = new HostWrapper();
		hostWrapped.setHost(newHost);
		logger.debug("Sending following json to the foreman: {}",JSONHelper.toJson(hostWrapped));
		
		ForemanVM newVM = new ForemanVM(foremanClient.api().newHost(hostWrapped));
		newVM.setForemanClient(foremanClient);
		return newVM;
	}