@Override public List<Server> query(BaseVimInstance vimInstance) throws VimException, PluginException { return vimBroker.getVim(vimInstance.getType()).queryResources(vimInstance); }
@Override public Set<BaseNfvImage> queryImagesDirectly(BaseVimInstance vimInstance) throws PluginException, VimException { return new HashSet<>(vimBroker.getVim(vimInstance.getType()).queryImages(vimInstance)); }
@Override public BaseNetwork update(BaseVimInstance vimInstance, Network updatingNetwork) throws VimException, PluginException { // Fetch Vim org.openbaton.nfvo.vim_interfaces.network_management.NetworkManagement vim; vim = vimBroker.getVim(vimInstance.getType()); // Update network on cloud environment return vim.update(vimInstance, updatingNetwork); }
@Override public Quota getAllQuota(String projectId) throws PluginException, VimException { Quota result = new Quota(); for (BaseVimInstance vimInstance : vimInstanceRepository.findByProjectId(projectId)) { if (vimInstance.getType().equals("test")) { continue; } Quota tmp = vimBroker.getVim(vimInstance.getType()).getQuota(vimInstance); result.setCores(result.getCores() + tmp.getCores()); result.setFloatingIps(result.getFloatingIps() + tmp.getFloatingIps()); result.setInstances(result.getInstances() + tmp.getInstances()); result.setRam(result.getRam() + tmp.getRam()); } return result; }
BaseVimInstance vimInstance = vimInstanceRepository.findByProjectIdAndName(projectId, vimName); Vim vim = vimBroker.getVim(vimInstance.getType()); if (vnfPackage.getImageLink() != null && virtualNetworkFunctionDescriptor.getVdu() != null) { log.debug("Uploading a new Image by using the image link"); image = vim.add(vimInstance, image, vnfPackage.getImageLink()); } else if (imageFile != null) { log.debug("Uploading a new Image by using the image file"); image = vim.add(vimInstance, image, imageFile);
throws VimException, ExecutionException, InterruptedException, PluginException { List<Future<VNFCInstance>> instances = new ArrayList<>(); org.openbaton.nfvo.vim_interfaces.vim.Vim vim = vimBroker.getVim(vimInstance.getType()); log.debug("Executing allocate with Vim: " + vim.getClass().getSimpleName()); log.debug("NAME: " + virtualNetworkFunctionRecord.getName()); vim.allocate( vimInstance, virtualDeploymentUnit,
Vim vim = getVim(vimInstance.getType()); Quota maximalQuota = vim.getQuota(vimInstance); List<Server> servers = vim.queryResources(vimInstance); log.debug("MaximalQuota is: " + maximalQuota);
@Test public void vnfLifecycleOperationGrantingTest() throws VimException, PluginException { VirtualNetworkFunctionRecord vnfr = createVirtualNetworkFunctionRecord(); when(vimInstanceRepository.findByProjectIdAndName(anyString(), anyString())) .thenReturn(createVimInstance()); when(vimBroker.getLeftQuota(any(BaseVimInstance.class))).thenReturn(createMaxQuota()); Map<String, BaseVimInstance> granted = vnfLifecycleOperationGranting.grantLifecycleOperation(vnfr); log.debug(granted.size() + " == " + vnfr.getVdu().size()); Assert.assertTrue(granted.size() == vnfr.getVdu().size()); when(vimBroker.getLeftQuota(any(BaseVimInstance.class))).thenReturn(createMinQuota()); granted = vnfLifecycleOperationGranting.grantLifecycleOperation(vnfr); Assert.assertFalse(granted.size() == vnfr.getVdu().size()); }
@Async @Override public Future<Void> deleteNetwork(VirtualLinkRecord vlr) throws PluginException, NotFoundException, VimException { BaseVimInstance vimInstance = this.query(vlr.getVim_id()); if (vimInstance == null) throw new NotFoundException( String.format("VimInstance with it %s not found", vlr.getVim_id())); vimBroker .getVim(vimInstance.getType()) .delete( vimInstance, vimInstance .getNetworks() .parallelStream() .filter(n -> n.getExtId().equals(vlr.getExtId())) .findFirst() .orElseThrow( () -> new NotFoundException( String.format("Network with it %s not found", vlr.getExtId())))); return new AsyncResult<>(null); }
private void initMocks() throws VimException, PluginException { Vim vim = mock(Vim.class); when(vim.queryImages(any(BaseVimInstance.class))).thenReturn(new ArrayList<>()); when(vimBroker.getVim(anyString())).thenReturn(vim); // try { // Future<Set<DeploymentFlavour>> futureFlavours = mock(AsyncResult.class); // Future<Set<BaseNetwork>> futureNetworks = mock(AsyncResult.class); // Future<Set<BaseNfvImage>> futureImages = mock(AsyncResult.class); // // when(asyncVimManagement.updateFlavors(any(BaseVimInstance.class))).thenReturn(futureFlavours); // when(asyncVimManagement.updateFlavors(any(BaseVimInstance.class)).get()) // .thenReturn(new HashSet<>()); // // when(asyncVimManagement.updateImages(any(BaseVimInstance.class))).thenReturn(futureImages); // when(asyncVimManagement.updateImages(any(BaseVimInstance.class)).get()) // .thenReturn(new HashSet<>()); // when(asyncVimManagement.updateNetworks(any(BaseVimInstance.class))) // .thenReturn(futureNetworks); // when(asyncVimManagement.updateNetworks(any(BaseVimInstance.class)).get()) // .thenReturn(new HashSet<>()); // } catch (InterruptedException | ExecutionException | BadRequestException e) { // e.printStackTrace(); // } doNothing().when(imageRepository).delete(any(NFVImage.class)); doNothing().when(networkRepository).delete(any(Network.class)); }
@Override public void delete(BaseVimInstance vimInstance, BaseNetwork network) throws VimException, PluginException { // Fetch Vim org.openbaton.nfvo.vim_interfaces.network_management.NetworkManagement vim; vim = vimBroker.getVim(vimInstance.getType()); // Delete network from cloud environment vim.delete(vimInstance, network); // Delete network from NetworkRepository networkRepository.delete(network); }
throws VimException, PluginException { org.openbaton.nfvo.vim_interfaces.vim.Vim vim = vimBroker.getVim(vimInstance.getType()); log.info( "Checking if Flavor " || vnfDeploymentFlavour.getRam() == 0 || vnfDeploymentFlavour.getVcpus() == 0)) { DeploymentFlavour flavor = vim.add(vimInstance, vnfDeploymentFlavour); ((OpenstackVimInstance) vimInstance).getFlavours().add(flavor); log.info("Created new Flavor -> " + flavor);
@Override public Quota getLeftQuota(String projectId) throws VimException, PluginException { Quota result = new Quota(); for (BaseVimInstance vimInstance : vimInstanceRepository.findByProjectId(projectId)) { if (vimInstance.getType().equals("test")) { continue; } Quota tmp = vimBroker.getLeftQuota(vimInstance); result.setCores(result.getCores() + tmp.getCores()); result.setFloatingIps(result.getFloatingIps() + tmp.getFloatingIps()); result.setInstances(result.getInstances() + tmp.getInstances()); result.setRam(result.getRam() + tmp.getRam()); } return result; } }
@Override @Async public Future<Void> release( VirtualDeploymentUnit virtualDeploymentUnit, VNFCInstance vnfcInstance) throws VimException, ExecutionException, InterruptedException, PluginException { BaseVimInstance vimInstance = vimInstanceRepository.findFirstById(vnfcInstance.getVim_id()); org.openbaton.nfvo.vim_interfaces.resource_management.ResourceManagement vim = vimBroker.getVim(vimInstance.getType()); log.debug("Removing vnfcInstance: " + vnfcInstance); vim.release(vnfcInstance, vimInstance).get(); virtualDeploymentUnit.getVnfc().remove(vnfcInstance.getVnfComponent()); return new AsyncResult<>(null); }
throws VimException, PluginException { if (vimInstance instanceof OpenstackVimInstance) { Quota leftQuota = vimBroker.getLeftQuota(vimInstance); log.debug("Left Quota on VimInstance " + vimInstance.getName() + " at start is " + leftQuota);
@Override @Async public Future<Void> operate(VirtualDeploymentUnit vdu, String operation) throws PluginException, ExecutionException, InterruptedException, VimException { for (VNFCInstance vnfcInstance : vdu.getVnfc_instance()) { BaseVimInstance vimInstance = vimInstanceRepository.findFirstById(vnfcInstance.getVim_id()); org.openbaton.nfvo.vim_interfaces.resource_management.ResourceManagement vim = vimBroker.getVim(vimInstance.getType()); log.info("rebuilding vnfcInstance: " + vnfcInstance.getHostname()); vim.operate(vimInstance, vdu, vnfcInstance, operation).get(); } return new AsyncResult<>(null); }
@Test public void networkManagementDeleteTest() throws VimException, PluginException { BaseNetwork network_exp = createNetwork(); when(vimBroker.getVim(anyString())).thenReturn(myVim); when(networkRepository.findOne(network_exp.getId())).thenReturn(network_exp); networkManagement.delete(createVimInstance(), network_exp); when(networkRepository.findOne(anyString())).thenReturn(null); BaseNetwork network_new = networkManagement.query(network_exp.getId()); Assert.assertNull(network_new); } }
@Test public void networkManagementAddTest() throws VimException, PluginException, BadRequestException, AlreadyExistingException, ExecutionException, InterruptedException, IOException { Network network_exp = createNetwork(); when(networkRepository.save(any(Network.class))).thenReturn(network_exp); when(vimBroker.getVim(anyString())).thenReturn(myVim); BaseNetwork network_new = networkManagement.add(createVimInstance(), network_exp); Assert.assertEquals(network_exp.getId(), network_new.getId()); Assert.assertEquals(network_exp.getName(), network_new.getName()); Assert.assertEquals(network_exp.getExtId(), network_new.getExtId()); }
@Test public void networkManagementUpdateTest() throws VimException, PluginException { when(vimBroker.getVim(anyString())).thenReturn(myVim); Network network = createNetwork(); network.setName("UpdatedName"); network.setExternal(true); // Vim vim = vimBroker.getVim("mocked_vim"); // when(vim.update(any(VimInstance.class), any(Network.class))).thenReturn(network); BaseNetwork updated_network = networkManagement.update(createVimInstance(), network); Assert.assertEquals(updated_network.getName(), network.getName()); Assert.assertEquals(updated_network.getExtId(), network.getExtId()); // Assert.assertEquals(updated_network.getExternal(), network.getExternal()); }