Package org.jclouds.cloudstack.domain

Examples of org.jclouds.cloudstack.domain.Network


   @Test
   public void testCreateVirtualMachineWithSpecificIp() throws Exception {
      skipIfNotGlobalAdmin();

      String defaultTemplate = template != null ? template.getImageId() : null;
      Network network = null;

      try {
         Template template = getOnlyElement(
            client.getTemplateApi().listTemplates(ListTemplatesOptions.Builder.id(defaultTemplate)));
         logger.info("Using template: " + template);

         Set<Network> allSafeNetworksInZone = adminClient.getNetworkApi().listNetworks(
            ListNetworksOptions.Builder.zoneId(template.getZoneId()).isSystem(false));
         for (Network net : allSafeNetworksInZone) {
            if (net.getName().equals(prefix + "-ip-network")) {
               logger.info("Deleting VMs in network: " + net);

               Set<VirtualMachine> machinesInNetwork = adminClient.getVirtualMachineApi().listVirtualMachines(
                  ListVirtualMachinesOptions.Builder.networkId(net.getId()));

               for (VirtualMachine machine : machinesInNetwork) {
                  if (machine.getState().equals(VirtualMachine.State.RUNNING)) {
                     logger.info("Deleting VM: " + machine);
                     destroyMachine(machine);
                  }
               }

               assertTrue(adminJobComplete.apply(
                  adminClient.getNetworkApi().deleteNetwork(net.getId())), net.toString());
            }
         }

         NetworkOffering offering = getFirst(
            client.getOfferingApi().listNetworkOfferings(
               ListNetworkOfferingsOptions.Builder.zoneId(template.getZoneId()).specifyVLAN(true)), null);
         checkNotNull(offering, "No network offering found");
         logger.info("Using network offering: " + offering);

         network = adminClient.getNetworkApi().createNetworkInZone(
            template.getZoneId(), offering.getId(), prefix + "-ip-network", "",
            CreateNetworkOptions.Builder.startIP("192.168.0.1").endIP("192.168.0.5")
               .netmask("255.255.255.0").gateway("192.168.0.1").vlan("21"));
         logger.info("Created network: " + network);

         Network requiredNetwork = getOnlyElement(filter(adminClient.getNetworkApi().listNetworks(
            ListNetworksOptions.Builder.zoneId(template.getZoneId())), new Predicate<Network>() {
            @Override
            public boolean apply(Network network) {
               return network.isDefault() &&
                  network.getGuestIPType() == GuestIPType.VIRTUAL;
View Full Code Here


   public static VirtualMachine createVirtualMachine(CloudStackApi client, String defaultTemplate,
         Predicate<String> jobComplete, Predicate<VirtualMachine> virtualMachineRunning) {
      Set<Network> networks = client.getNetworkApi().listNetworks(isDefault(true));
      if (!networks.isEmpty()) {
         Network network = get(filter(networks, new Predicate<Network>() {
            @Override
            public boolean apply(Network network) {
               return network != null && network.getState().equals("Implemented");
            }
         }), 0);
         return createVirtualMachineInNetwork(network,
               defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
               virtualMachineRunning);
      } else {
         String zoneId = find(client.getZoneApi().listZones(), new Predicate<Zone>() {

            @Override
View Full Code Here

         Logger.getAnonymousLogger().log(Level.SEVERE, "guest networks not supported, skipping test");
         return;
      }
      String name = prefix + "-virtual";

      Network network = null;
      try {
         network = client.getNetworkApi().createNetworkInZone(zone.getId(), offering.getId(), name, name);
         checkNetwork(network);
      } catch (IllegalStateException e) {
         Logger.getAnonymousLogger().log(Level.SEVERE, "couldn't create a network, skipping test", e);
      } finally {
         if (network != null) {
            String jobId = client.getNetworkApi().deleteNetwork(network.getId());
            if (jobId != null)
               jobComplete.apply(jobId);
         }
      }
   }
View Full Code Here

         Logger.getAnonymousLogger().log(Level.SEVERE, "VLAN networks not supported, skipping test");
         return;
      }
      String name = prefix + "-vlan";

      Network network = null;
      try {
         network = domainAdminClient
               .getNetworkApi()
               // startIP/endIP/netmask/gateway must be specified together
               .createNetworkInZone(zone.getId(), offering.getId(), name, name,
                     vlan("65").startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1"));
         checkNetwork(network);
      } catch (IllegalStateException e) {
         Logger.getAnonymousLogger().log(Level.SEVERE, "couldn't create a network, skipping test", e);
      } finally {
         if (network != null) {
            String jobId = adminClient.getNetworkApi().deleteNetwork(network.getId());
            if (jobId != null)
               adminJobComplete.apply(jobId);
         }
      }
   }
View Full Code Here

            accountInDomain(user.getAccount(), user.getDomainId()));
      assert null != response;
      long networkCount = response.size();
      assertTrue(networkCount >= 0);
      for (Network network : response) {
         Network newDetails = getOnlyElement(client.getNetworkApi().listNetworks(id(network.getId())));
         assertEquals(network, newDetails);
         assertEquals(network, client.getNetworkApi().getNetwork(network.getId()));
         checkNetwork(network);
      }
   }
View Full Code Here

        super.tearDown();
    }

    private void deleteNetworkIfExists() {
        try {
            Network network = Networks.getByName(context.getApi(), networkName);
            // this will not wait for the network to be deleted. operation will fail if network is used.
            context.getApi().getNetworkClient().deleteNetwork(network.getId());
        } catch (NoSuchElementException e) {
            LOG.info("Network {} does not exist", networkName);
        }
    }
View Full Code Here

    public void testEnsureNetworkExistsByCreatingTheNetwork() throws Exception {
        activity.execute(execution);

        assertThat(collector.getVariable(ProcessVariables.NETWORK_ID)).isNotNull();

        Network network = Networks.getByName(context.getApi(), networkName);
        assertThat(network.getName()).isEqualToIgnoringCase(networkName);
        String networkId = network.getId();
        // second run should not create a new network
        activity.execute(execution);

        when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);
        network = Networks.getByName(context.getApi(), networkName);
        assertThat(network.getId()).isEqualTo(networkId);
    }
View Full Code Here

    @Test
    public void testEnsureNetworkExistsWithProvidedExistingNetwork() throws Exception {
        final String networkId = "network-id-0123";
        final CloudStackClient mockClient = mock(CloudStackClient.class);
        final NetworkClient mockNetworkClient = mock(NetworkClient.class);
        final Network mockNetwork = mock(Network.class);
        final com.axemblr.provisionr.api.network.Network network = com.axemblr.provisionr.api.network.Network.builder()
            .option(NetworkOptions.EXISTING_NETWORK_ID, networkId).createNetwork();

        execution.setVariable(ProcessVariables.NETWORK_ID, networkId);

        when(pool.getNetwork()).thenReturn(network);
        when(mockClient.getNetworkClient()).thenReturn(mockNetworkClient);
        when(mockNetworkClient.getNetwork(networkId)).thenReturn(mockNetwork);
        when(mockNetwork.getId()).thenReturn(networkId);

        activity.execute(mockClient, pool, execution);
        assertThat(collector.getVariable(ProcessVariables.NETWORK_ID)).isEqualTo(networkId);
    }
View Full Code Here

    @Override
    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
        if (execution.getVariable(ProcessVariables.NETWORK_ID) != null) {
            LOG.warn("Network process variable ({}) will be overwritten!", ProcessVariables.NETWORK_ID);
        }
        Network network;
        final String existingNetwork = pool.getNetwork().getOption(NetworkOptions.EXISTING_NETWORK_ID);
        if (existingNetwork != null) {
            network = checkNotNull(cloudStackClient.getNetworkClient().getNetwork(existingNetwork),
                "Network with id " + existingNetwork + " does not exist");
        } else {
            final String networkName = Networks.formatNameFromBusinessKey(execution.getProcessBusinessKey());
            final String zoneId = pool.getProvider().getOption(ProviderOptions.ZONE_ID);
            final String networkOfferingId = pool.getProvider().getOption(ProviderOptions.NETWORK_OFFERING_ID);
            try {
                network = Networks.getByName(cloudStackClient, networkName);
                LOG.info("Network with name {} exists.", networkName);
            } catch (NoSuchElementException e) {
                LOG.info(String.format("Creating network %s in zone %s with offering %s",
                    networkName, zoneId, networkOfferingId));
                network = cloudStackClient.getNetworkClient().createNetworkInZone(zoneId, networkOfferingId, networkName,
                    networkName, CreateNetworkOptions.NONE);
            }
        }
        LOG.info("Storing network id {} in process variable {}", network.getId(), ProcessVariables.NETWORK_ID);
        execution.setVariable(ProcessVariables.NETWORK_ID, network.getId());
    }
View Full Code Here

TOP

Related Classes of org.jclouds.cloudstack.domain.Network

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.