Package org.jclouds.cloudstack.domain

Examples of org.jclouds.cloudstack.domain.Network


    @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


      checkArgument(templateOptions.getSecurityGroupIds().isEmpty(), "security groups cannot be specified for locations (zones) that use advanced networking");
      if (templateOptions.getNetworkIds().size() > 0) {
         options.networkIds(templateOptions.getNetworkIds());
      } else if (templateOptions.getIpsToNetworks().isEmpty()) {
         checkArgument(!networks.isEmpty(), "please setup a network for zone: " + zoneId);
         Network defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), and(defaultNetworkInZone(zoneId), supportsStaticNAT())), null);
         if (defaultNetworkInZone == null) {
             defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), isIsolatedNetwork()), null);
         }
         if (defaultNetworkInZone == null) {
             throw new IllegalArgumentException("please choose a specific network in zone " + zoneId + ": " + networks);
         } else {
             options.networkId(defaultNetworkInZone.getId());
         }
      }
      return options;
   }
View Full Code Here

         return;
      }

      String group = prefix + "-vlan";
      String vlanId = "2";
      Network network = null;
      Set<? extends NodeMetadata> nodes = null;
      try {
         assert view.getComputeService().listAssignableLocations().size() > 0;

         Template template = view.getComputeService().templateBuilder().build();

         // get the zone we are launching into
         String zoneId = template.getLocation().getId();

         // cleanup before running the test
         deleteNetworksInZoneWithVlanId(zoneId, vlanId);

         // find a network offering that supports vlans in our zone
         String offeringId = get(
            cloudStackContext.getApi().getOfferingApi().listNetworkOfferings(specifyVLAN(true).zoneId(zoneId)), 0).getId();

         // create an arbitrary network
         network = domainAdminClient
            .getNetworkApi()
               // startIP/endIP/netmask/gateway must be specified together
            .createNetworkInZone(zoneId, offeringId, group, group,
               vlan(vlanId).startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1"));

         // set options to specify this network id
         template.getOptions().as(CloudStackTemplateOptions.class).networkId(network.getId());

         // launch the VM
         nodes = view.getComputeService().createNodesInGroup(group, 1, template);

         assert nodes.size() > 0;

      } catch (RunNodesException e) {
         Logger.getAnonymousLogger().log(Level.SEVERE, "error creating nodes", e);
         nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
      } finally {
         if (nodes != null)
            view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
         if (network != null)
            domainAdminClient.getNetworkApi().deleteNetwork(network.getId());
      }
   }
View Full Code Here

   @Test
   public void testAdvancedAutoDetectNetwork() {
      AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter();

      Network eligibleNetwork = Network.builder()
         .id("25").zoneId(ZONE_ID).isDefault(true).services(ImmutableSet.of(firewallServiceWithStaticNat))
         .build();
      DeployVirtualMachineOptions optionsActual = converter.apply(CloudStackTemplateOptions.NONE,
         ImmutableMap.of(eligibleNetwork.getId(), eligibleNetwork), ZONE_ID, DeployVirtualMachineOptions.NONE);
      DeployVirtualMachineOptions optionsExpected = DeployVirtualMachineOptions.Builder.networkId("25");
      assertEquals(optionsActual, optionsExpected);
   }
View Full Code Here

   }

   @Test
   public void testAdvancedWhenNoNetworkEligible() {
      AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter();
      Network unsuitableNetwork = Network.builder()
         .id("25").zoneId(ZONE_ID)
         .build();

      boolean exceptionThrown = false;
      try {
         converter.apply(CloudStackTemplateOptions.NONE, ImmutableMap.of(unsuitableNetwork.getId(), unsuitableNetwork), ZONE_ID, DeployVirtualMachineOptions.NONE);
      } catch (IllegalArgumentException e) {
         exceptionThrown = true;
      }
      assertTrue(exceptionThrown);
   }
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

*/
@Test(groups = "unit")
public class NetworkPredicatesTest {

   public void testHasLoadBalancerService() {
      Network network = Network.builder().id("204").services(ImmutableSet.of(NetworkService.builder().name("Lb").build())).build();

      assert hasLoadBalancerService().apply(network);
      assert !supportsStaticNAT().apply(network);
      assert !supportsPortForwarding().apply(network);

View Full Code Here

      assert !supportsPortForwarding().apply(network);

   }

   public void testSupportsStaticNATFindsWhenFirewallHasStaticNatFeature() {
      Network network = Network
            .builder()
            .id("204")
            .services(
                  ImmutableSet.of(NetworkService.builder().name("Firewall").capabilities(
                        ImmutableMap.<String, String> of("StaticNat", "true")).build()))
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.