/** * Manually create links to disk-attachments. * * Manual creation is necessary due to limitation in link generation infrastructure. * The infrastructure identifies a location in the API-tree by the combination: * entity-type, parent-type. * * In this particular case, the combination of disk-attachment under a VM exists * twice - once under root, once under Storage-Domain: * * .../api/vms/xxx/diskattachments * .../api/storagedomains/zzz/vms/xxx/diskattachments * * this causes a bug (https://bugzilla.redhat.com/1374323) * Until link-generation infrastructure will be able to handle this, link is * created manually * * @param attachment disk-attachment to add links to */ protected void addHref(DiskAttachment diskAttachment) { diskAttachment.getVm().setStorageDomain(new StorageDomain()); diskAttachment.getVm().getStorageDomain().setId(parent.parent.getStorageDomain().getId().toString()); addLinks(diskAttachment); //will successfully add the link to the VM String vmHref = diskAttachment.getVm().getHref(); String href = String.join("/", vmHref, "diskattachments", diskAttachment.getId()); diskAttachment.setHref(href); }
@Test public void testStorageDomainVmLinks() { Vm vm = new Vm(); vm.setId(VM_ID); vm.setStorageDomain(new StorageDomain()); vm.getStorageDomain().setId(STORAGE_DOMAIN_ID); vm = LinkHelper.addLinks(vm); assertEquals(STORAGE_DOMAIN_VM_HREF, vm.getHref()); assertEquals(STORAGE_DOMAIN_HREF, vm.getStorageDomain().getHref()); }
private void doTestVmLinks(boolean suggestParent) { Vm vm = new Vm(); vm.setId(VM_ID); vm.setCluster(new Cluster()); vm.getCluster().setId(CLUSTER_ID); vm.setTemplate(new Template()); vm.getTemplate().setId(TEMPLATE_ID); vm.setVmPool(new VmPool()); vm.getVmPool().setId(VM_POOL_ID); if (suggestParent) { LinkHelper.addLinks(vm, Vm.class); } else { LinkHelper.addLinks(vm); } assertEquals(VM_HREF, vm.getHref()); assertEquals(CLUSTER_HREF, vm.getCluster().getHref()); assertEquals(TEMPLATE_HREF, vm.getTemplate().getHref()); assertEquals(VM_POOL_HREF, vm.getVmPool().getHref()); }
to.setHref(from.getHref());